Skip to content

Commit

Permalink
let me be free
Browse files Browse the repository at this point in the history
  • Loading branch information
liamgiraldo committed Jul 22, 2024
1 parent 7e5cdd7 commit 770b397
Show file tree
Hide file tree
Showing 20 changed files with 101 additions and 55 deletions.
15 changes: 2 additions & 13 deletions src/main/java/me/liamgiraldo/litebridge/Litebridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void onEnable() {

constructQueues(this.models, queues, spectatorQueues);

this.spectatorController = new SpectatorController(spectatorQueues, this.getServer().getWorld("lobby").getSpawnLocation(), this);
this.spectatorController = new SpectatorController(spectatorQueues, lobby, this);

this.queueController = new QueueController(queues, spectatorQueues);
System.out.println("All queue's max players upon constructor load");
Expand Down Expand Up @@ -134,7 +134,7 @@ public void onEnable() {
//TODO: Change the location to be a variable in the config file


this.guiModel = new GUIModel(this, models);
this.guiModel = new GUIModel(this, models, queues);
this.guiController = new GUIController(guiModel, models);

lobbyManager = new LobbyManager(lobby, this, queues, this.gameController, spectatorQueues);
Expand Down Expand Up @@ -289,15 +289,4 @@ public void removeMapFromConfig(String mapName){
this.getConfig().set(mapName, null);
}

public JavaPlugin getLitecoin(){
if(litecoin == null){
System.out.println("Litebridge could not find the LiteCoin plugin, continuing without it.");
return null;
}
return litecoin;
}

public LiteCosmetics getLiteCosmetics() {
return this.liteCosmetics;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,11 @@ public void onPlayerDamageAnotherPlayer(EntityDamageByEntityEvent e){

int arrowDistance = (int) Math.round(player.getLocation().distance(damager.getLocation()));
if(arrowDistance >= 15){
String message = getChatColorBasedOnTeam(damager, game) + damager.getDisplayName() + ChatColor.GRAY + " shot " + getChatColorBasedOnTeam(player, game) + player.getDisplayName() + ChatColor.GRAY + " from " + ChatColor.WHITE + arrowDistance + ChatColor.GRAY + " blocks away!";
String message = getChatColorBasedOnTeam(damager, game) + damager.getDisplayName() + ChatColor.GRAY + " shot " + getChatColorBasedOnTeam(player, game) + player.getDisplayName() + getFormattedHealthOfPlayer(player) + ChatColor.GRAY + " from " + ChatColor.WHITE + arrowDistance + ChatColor.GRAY + " blocks away!";
sendMessageToAllPlayersOnPlayerTeam(game, damager, message);
}
else{
String message = getChatColorBasedOnTeam(damager, game) + damager.getDisplayName() + ChatColor.GRAY + " shot " + getChatColorBasedOnTeam(player, game) + player.getDisplayName() + getFormattedHealthOfPlayer(player);
sendMessageToAllPlayersOnPlayerTeam(game, damager, message);
}
}
Expand Down Expand Up @@ -1443,7 +1447,6 @@ public void onNearDeathEvent(EntityDamageEvent e) //Listens to EntityDamageEvent
}

e.setCancelled(true);
player.setHealth(20);
resetPlayerInventory(player);
teleportPlayerBasedOnTeam(player, game);
// player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1, 1);
Expand All @@ -1454,6 +1457,7 @@ public void onNearDeathEvent(EntityDamageEvent e) //Listens to EntityDamageEvent
game.incrementPlayerKillCount(damager);
}
player.playSound(player.getLocation(), Sound.CHICKEN_HURT, 1, 1);
player.setHealth(20);
return;
}
}
Expand All @@ -1476,7 +1480,6 @@ public void onNearDeathEvent(EntityDamageEvent e) //Listens to EntityDamageEvent
}

e.setCancelled(true);
player.setHealth(20);
resetPlayerInventory(player);
teleportPlayerBasedOnTeam(player, game);
player.playSound(player.getLocation(), Sound.CHICKEN_HURT, 1, 1);
Expand All @@ -1486,6 +1489,8 @@ public void onNearDeathEvent(EntityDamageEvent e) //Listens to EntityDamageEvent
playSoundForSpecificPlayersTeam(game, damager, Sound.ORB_PICKUP);
game.incrementPlayerKillCount(damager);
}

player.setHealth(20);
// player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1, 1);
}
}
Expand Down Expand Up @@ -1764,14 +1769,14 @@ private void handleRedGoal(Player player, GameModel game) {
if(p == null)
continue;
teleportPlayerBasedOnTeam(p, game);
p.setHealth(20);
resetPlayerInventory(p);

p.sendMessage(getChatColorBasedOnTeam(player, game) + player.getName() + getFormattedHealthOfPlayer(player) + ChatColor.GRAY + " scored a goal for the blue team!");
p.playSound(p.getLocation(), Sound.FIREWORK_LAUNCH, 1, 1);

//we also need to reset all potion effects
p.getActivePotionEffects().forEach(potionEffect -> p.removePotionEffect(potionEffect.getType()));
p.setHealth(20);
}
// player.teleport(new Location(game.getWorld(), game.getBlueSpawnPoint()[0], game.getBlueSpawnPoint()[1], game.getBlueSpawnPoint()[2]));

Expand All @@ -1798,28 +1803,19 @@ private void handleRedGoal(Player player, GameModel game) {

private String getFormattedHealthOfPlayer(Player p){
double health = p.getHealth();
double maxHealth = p.getMaxHealth();
double healthPercentage = (health / maxHealth) * 100;
//round this to the nearest hundredth decimal point
healthPercentage = Math.round(healthPercentage * 100.0) / 100.0;
//round the health to the nearest whole number
health = Math.round(health * 100.0) / 100.0;

return ChatColor.GRAY + " (" + ChatColor.RED + healthPercentage + "%" + ChatColor.GRAY + ") ";
return ChatColor.GRAY + " (" + ChatColor.RED + health + " ❤"+ ChatColor.GRAY + ") ";
}

private String getFormattedHealthOfPlayerMinusDamage(Player p, double damage){
double health = p.getHealth() - damage;
double maxHealth = p.getMaxHealth();
double healthPercentage = (health / maxHealth) * 100;
healthPercentage = Math.round(healthPercentage * 100.0) / 100.0;
//if it's equal to 50% exactly, set healthPercentage to 0 (hotfix)

if(healthPercentage < 0){
healthPercentage = 0;
}
//round the health to the second decimal place
health = Math.round(health * 100.0) / 100.0;

//get the health percentage rounded to the nearest whole number
healthPercentage = Math.round(healthPercentage);
return ChatColor.GRAY + " (" + ChatColor.RED + healthPercentage + "%" + ChatColor.GRAY + " ❤) ";
return ChatColor.GRAY + " (" + ChatColor.RED + health + " ❤" + ChatColor.GRAY + ") ";
}

/**
Expand Down Expand Up @@ -1870,13 +1866,13 @@ private void handleBlueGoal(Player player, GameModel game) {
if(p == null)
continue;
resetPlayerInventory(p);
p.setHealth(20);
teleportPlayerBasedOnTeam(p, game);

p.sendMessage(getChatColorBasedOnTeam(player, game) + player.getName() + getFormattedHealthOfPlayer(p) + ChatColor.GRAY + " scored a goal for the red team!");
p.playSound(p.getLocation(), Sound.FIREWORK_LAUNCH, 1, 1);

p.getActivePotionEffects().forEach(potionEffect -> p.removePotionEffect(potionEffect.getType()));
p.setHealth(20);
}
// player.teleport(new Location(game.getWorld(), game.getRedSpawnPoint()[0], game.getRedSpawnPoint()[1], game.getRedSpawnPoint()[2]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if(queue.isPlayerInQueue(p)){
if(queue.getAssociatedGame().getGameState() == GameModel.GameState.ENDING){
p.sendMessage("Your game is about to end, please wait.");
return false;
return true;
}
GameModel game = queue.getAssociatedGame();
game.removePlayer(p);
Expand All @@ -166,6 +166,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
p.getInventory().clear();
p.getInventory().setArmorContents(null);
p.sendMessage("Sending you the bridge lobby.");

return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public void onStickRightClick(PlayerInteractEvent e) {
//TODO save all these parameters to config.
//Before the first stick click, the case is 0, but...
//immediately gets set to 1.

if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
Block blockClicked = e.getClickedBlock();
boolean airClicked = true;
Expand All @@ -135,7 +136,7 @@ public void onStickRightClick(PlayerInteractEvent e) {
ItemStack itemUsed = e.getItem();
Player player = e.getPlayer();
//TODO get this to work specifically for the bridge stick
if (itemUsed != null && itemUsed.getType() == Material.STICK) {
if (itemUsed != null && itemUsed.getType() == Material.STICK && itemUsed.getItemMeta().getLore().get(0).equals("Used for making bridge maps.")) {
this.worldName = player.getWorld().getName();
//if the config for this world doesn't exist make one
if(!litebridge.getConfig().isConfigurationSection(player.getWorld().getName())) {
Expand Down Expand Up @@ -512,7 +513,7 @@ public ArrayList<GameModel> constructGameModels() {
float blueSpawnYaw = (float)litebridge.getConfig().getLong(worldName + ".blue-spawn-yaw");
float redSpawnYaw = (float)litebridge.getConfig().getLong(worldName + ".red-spawn-yaw");

printSingleArray(blueSpawnPoint);
/*printSingleArray(blueSpawnPoint);
printSingleArray(redSpawnPoint);
printDoubleArray(redGoalBounds);
printDoubleArray(blueGoalBounds);
Expand All @@ -523,7 +524,7 @@ public ArrayList<GameModel> constructGameModels() {
System.out.println(maxPlayers);
System.out.println(killPlane);
System.out.println(blueSpawnYaw);
System.out.println(redSpawnYaw);
System.out.println(redSpawnYaw);*/

models.add(new GameModel(world, blueSpawnPoint, redSpawnPoint, blueGoalBounds, redGoalBounds, blueCageBounds, redCageBounds, worldBounds, killPlane, goalsToWin, maxPlayers, litebridge, blueSpawnYaw, redSpawnYaw));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public void run() {
}
queue.addSpectator(p);
p.teleport(queue.getWorld().getSpawnLocation());
p.getInventory().clear();

//Use a bukkit runnable to set their gamemode to spectator after they have been teleported
new BukkitRunnable(){
Expand All @@ -123,6 +124,7 @@ public void run() {
}
queue.addSpectator(p);
p.teleport(queue.getWorld().getSpawnLocation());
p.getInventory().clear();

//Use a bukkit runnable to set their gamemode to spectator after they have been teleported
new BukkitRunnable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
import org.bukkit.event.player.PlayerRespawnEvent;

public class PlayerJoinListener implements Listener {
@EventHandler
public void onJoinEven(PlayerJoinEvent e){
Player player = e.getPlayer();
String joinMessage = Litebridge.getPlugin().getConfig().getString("join-message");
if(joinMessage != null){
joinMessage = joinMessage.replace("%player%", player.getDisplayName());
player.sendMessage(ChatColor.translateAlternateColorCodes('&', joinMessage));
}
Location spawnLocation = (Location) Litebridge.getPlugin().getConfig().get("spawn");
if (spawnLocation == null || spawnLocation.getWorld() == null) {
player.sendMessage("The spawn location is invalid. Ensure the world exists and the coordinates are correct.");
}
else if(!player.hasPlayedBefore()){
player.teleport(spawnLocation);
}
}
// @EventHandler
// public void onJoinEven(PlayerJoinEvent e){
// Player player = e.getPlayer();
// String joinMessage = Litebridge.getPlugin().getConfig().getString("join-message");
// if(joinMessage != null){
// joinMessage = joinMessage.replace("%player%", player.getDisplayName());
// player.sendMessage(ChatColor.translateAlternateColorCodes('&', joinMessage));
// }
// Location spawnLocation = (Location) Litebridge.getPlugin().getConfig().get("spawn");
// if (spawnLocation == null || spawnLocation.getWorld() == null) {
// player.sendMessage("The spawn location is invalid. Ensure the world exists and the coordinates are correct.");
// }
// else if(!player.hasPlayedBefore()){
// player.teleport(spawnLocation);
// }
// }

public void onPlayerRespawn(PlayerRespawnEvent e){
Player player = e.getPlayer();
Expand Down
42 changes: 41 additions & 1 deletion src/main/java/me/liamgiraldo/litebridge/models/GUIModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ public class GUIModel {
SGMenu mapmenu;

ArrayList<GameModel> games;
ArrayList<QueueModel> queues;

HashMap<Player, Integer> lastSelectedMode = new HashMap<>();

public GUIModel(Litebridge plugin, ArrayList<GameModel> games){
public GUIModel(Litebridge plugin, ArrayList<GameModel> games, ArrayList<QueueModel> queues){
this.plugin = plugin;
this.bridgemainmenu = plugin.getSpiGUI().create("Bridge Main Menu", 3);
this.bridgeselectmode = plugin.getSpiGUI().create("Bridge Mode Selection", 3);
this.hotbareditor = plugin.getSpiGUI().create("Hotbar Editor", 3);
this.customizemenu = plugin.getSpiGUI().create("Customize", 3);
this.mapmenu = plugin.getSpiGUI().create("Map Menu", 6);
this.games = games;
this.queues = queues;

ItemBuilder closeitem = new ItemBuilder(Material.BARRIER);
closeitem.lore("Click here to close the menu");
Expand Down Expand Up @@ -261,9 +263,18 @@ public GUIModel(Litebridge plugin, ArrayList<GameModel> games){
event.getWhoClicked().closeInventory();
});

ItemBuilder refreshitem = new ItemBuilder(XMaterial.EMERALD.parseMaterial());
refreshitem.lore("Click to refresh the map list");
refreshitem.amount(1);
refreshitem.name("Refresh");
SGButton refreshbutton = new SGButton(refreshitem.build()).withListener((InventoryClickEvent event) -> {
generateMapButtons((Player) event.getWhoClicked());
});

mapmenu.setButton(0, 49, closebutton);
mapmenu.setButton(0, 45, mainmenubutton);
mapmenu.setButton(0, 53, randomq);
mapmenu.setButton(0, 51, refreshbutton);

//TODO: There has to be a better way to do this
plugin.getSpiGUI().setBlockDefaultInteractions(false);
Expand Down Expand Up @@ -308,17 +319,37 @@ private void generateMapButtons(Player player){
int i = 0;

this.getMapmenu().clearAllButStickiedSlots();
//clear all slots except the last 10
// for(int j = 0; j < 45; j++){
// this.getMapmenu().setButton(j, null);
// }

int lastSelectedMode = this.getLastSelectedMode(player);

for(GameModel game: games){
if((game.getMaxPlayers()/2) != lastSelectedMode){
continue;
}
QueueModel queue = findQueueCoorespondingToGame(game);

ItemStack item = new ItemStack(Material.MAP);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName((game.getWorld().getName()));
ArrayList<String> lore = new ArrayList<>();
lore.add(ChatColor.GOLD + "In-Queue:");
if(queue != null){
for(Player p: queue.getQueue()){
if(p == null){
lore.add(ChatColor.GRAY + "Empty");
continue;
}
ChatColor color = ChatColor.WHITE;
lore.add(color + p.getName());
}
} else {
lore.add(ChatColor.GRAY + "Empty");
}

lore.add(ChatColor.GOLD + "In-Game:");
for(Player p: game.getPlayers()){
if(p == null){
Expand Down Expand Up @@ -370,4 +401,13 @@ private String removeNumbers(String str) {
private boolean hasNumber(String s) {
return s.matches(".*\\d.*");
}

private QueueModel findQueueCoorespondingToGame(GameModel game){
for(QueueModel queue: queues){
if(queue.getAssociatedGame().equals(game)){
return queue;
}
}
return null;
}
}
8 changes: 8 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ commands:
feed:
description: Sets hunger to full
usage: /<command>
permission: litebridge.feed
permission-message: You don't have permission to feed yourself
repeat:
description: Repeats the arguments provided to this command
usage: /<command>
Expand Down Expand Up @@ -128,6 +130,12 @@ permissions:
litebridge.litebridgespectator:
description: Allows someone to spectate games
default: op
litebridge.feed:
description: Allows someone to feed themselves
default: op
feed:
description: Allows someone to feed themselves
default: op
softdepend:
- LiteCoin
- LiteCosmetics
Binary file modified target/classes/me/liamgiraldo/litebridge/Litebridge.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified target/classes/me/liamgiraldo/litebridge/models/GUIModel.class
Binary file not shown.
8 changes: 8 additions & 0 deletions target/classes/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ commands:
feed:
description: Sets hunger to full
usage: /<command>
permission: litebridge.feed
permission-message: You don't have permission to feed yourself
repeat:
description: Repeats the arguments provided to this command
usage: /<command>
Expand Down Expand Up @@ -128,6 +130,12 @@ permissions:
litebridge.litebridgespectator:
description: Allows someone to spectate games
default: op
litebridge.feed:
description: Allows someone to feed themselves
default: op
feed:
description: Allows someone to feed themselves
default: op
softdepend:
- LiteCoin
- LiteCosmetics
2 changes: 1 addition & 1 deletion target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven
#Thu Jul 18 22:22:50 PDT 2024
#Sun Jul 21 20:43:05 PDT 2024
groupId=me.liamgiraldo
artifactId=litebridge
version=0.0.1-SNAPSHOT
Binary file modified target/original-litebridge-0.0.1-SNAPSHOT.jar
Binary file not shown.

0 comments on commit 770b397

Please sign in to comment.