diff --git a/src/main/java/me/liamgiraldo/litebridge/Litebridge.java b/src/main/java/me/liamgiraldo/litebridge/Litebridge.java index a99384a..06db040 100644 --- a/src/main/java/me/liamgiraldo/litebridge/Litebridge.java +++ b/src/main/java/me/liamgiraldo/litebridge/Litebridge.java @@ -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"); @@ -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); @@ -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; - } } diff --git a/src/main/java/me/liamgiraldo/litebridge/controllers/GameController.java b/src/main/java/me/liamgiraldo/litebridge/controllers/GameController.java index 0dccf35..7af618f 100644 --- a/src/main/java/me/liamgiraldo/litebridge/controllers/GameController.java +++ b/src/main/java/me/liamgiraldo/litebridge/controllers/GameController.java @@ -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); } } @@ -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); @@ -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; } } @@ -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); @@ -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); } } @@ -1764,7 +1769,6 @@ 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!"); @@ -1772,6 +1776,7 @@ private void handleRedGoal(Player player, GameModel game) { //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])); @@ -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 + ") "; } /** @@ -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])); diff --git a/src/main/java/me/liamgiraldo/litebridge/controllers/LobbyManager.java b/src/main/java/me/liamgiraldo/litebridge/controllers/LobbyManager.java index 39eac88..6a0e1f6 100644 --- a/src/main/java/me/liamgiraldo/litebridge/controllers/LobbyManager.java +++ b/src/main/java/me/liamgiraldo/litebridge/controllers/LobbyManager.java @@ -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); @@ -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; } diff --git a/src/main/java/me/liamgiraldo/litebridge/controllers/MapCreator.java b/src/main/java/me/liamgiraldo/litebridge/controllers/MapCreator.java index afac12a..a07eb9c 100644 --- a/src/main/java/me/liamgiraldo/litebridge/controllers/MapCreator.java +++ b/src/main/java/me/liamgiraldo/litebridge/controllers/MapCreator.java @@ -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; @@ -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())) { @@ -512,7 +513,7 @@ public ArrayList 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); @@ -523,7 +524,7 @@ public ArrayList 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)); } diff --git a/src/main/java/me/liamgiraldo/litebridge/controllers/SpectatorController.java b/src/main/java/me/liamgiraldo/litebridge/controllers/SpectatorController.java index ac04ff1..b0da5db 100644 --- a/src/main/java/me/liamgiraldo/litebridge/controllers/SpectatorController.java +++ b/src/main/java/me/liamgiraldo/litebridge/controllers/SpectatorController.java @@ -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(){ @@ -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() { diff --git a/src/main/java/me/liamgiraldo/litebridge/listeners/PlayerJoinListener.java b/src/main/java/me/liamgiraldo/litebridge/listeners/PlayerJoinListener.java index 33adad2..3794770 100644 --- a/src/main/java/me/liamgiraldo/litebridge/listeners/PlayerJoinListener.java +++ b/src/main/java/me/liamgiraldo/litebridge/listeners/PlayerJoinListener.java @@ -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(); diff --git a/src/main/java/me/liamgiraldo/litebridge/models/GUIModel.java b/src/main/java/me/liamgiraldo/litebridge/models/GUIModel.java index b57e000..32ba901 100644 --- a/src/main/java/me/liamgiraldo/litebridge/models/GUIModel.java +++ b/src/main/java/me/liamgiraldo/litebridge/models/GUIModel.java @@ -28,10 +28,11 @@ public class GUIModel { SGMenu mapmenu; ArrayList games; + ArrayList queues; HashMap lastSelectedMode = new HashMap<>(); - public GUIModel(Litebridge plugin, ArrayList games){ + public GUIModel(Litebridge plugin, ArrayList games, ArrayList queues){ this.plugin = plugin; this.bridgemainmenu = plugin.getSpiGUI().create("Bridge Main Menu", 3); this.bridgeselectmode = plugin.getSpiGUI().create("Bridge Mode Selection", 3); @@ -39,6 +40,7 @@ public GUIModel(Litebridge plugin, ArrayList games){ 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"); @@ -261,9 +263,18 @@ public GUIModel(Litebridge plugin, ArrayList 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); @@ -308,6 +319,10 @@ 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); @@ -315,10 +330,26 @@ private void generateMapButtons(Player player){ 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 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){ @@ -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; + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 951ae5b..3df66fb 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -17,6 +17,8 @@ commands: feed: description: Sets hunger to full usage: / + permission: litebridge.feed + permission-message: You don't have permission to feed yourself repeat: description: Repeats the arguments provided to this command usage: / @@ -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 \ No newline at end of file diff --git a/target/classes/me/liamgiraldo/litebridge/Litebridge.class b/target/classes/me/liamgiraldo/litebridge/Litebridge.class index 342ada6..68972fb 100644 Binary files a/target/classes/me/liamgiraldo/litebridge/Litebridge.class and b/target/classes/me/liamgiraldo/litebridge/Litebridge.class differ diff --git a/target/classes/me/liamgiraldo/litebridge/controllers/GameController.class b/target/classes/me/liamgiraldo/litebridge/controllers/GameController.class index 97c83d9..25a4b88 100644 Binary files a/target/classes/me/liamgiraldo/litebridge/controllers/GameController.class and b/target/classes/me/liamgiraldo/litebridge/controllers/GameController.class differ diff --git a/target/classes/me/liamgiraldo/litebridge/controllers/LobbyManager.class b/target/classes/me/liamgiraldo/litebridge/controllers/LobbyManager.class index 06ff08b..644f178 100644 Binary files a/target/classes/me/liamgiraldo/litebridge/controllers/LobbyManager.class and b/target/classes/me/liamgiraldo/litebridge/controllers/LobbyManager.class differ diff --git a/target/classes/me/liamgiraldo/litebridge/controllers/MapCreator.class b/target/classes/me/liamgiraldo/litebridge/controllers/MapCreator.class index f1bf128..d2fb761 100644 Binary files a/target/classes/me/liamgiraldo/litebridge/controllers/MapCreator.class and b/target/classes/me/liamgiraldo/litebridge/controllers/MapCreator.class differ diff --git a/target/classes/me/liamgiraldo/litebridge/controllers/SpectatorController$2.class b/target/classes/me/liamgiraldo/litebridge/controllers/SpectatorController$2.class index c471961..6788578 100644 Binary files a/target/classes/me/liamgiraldo/litebridge/controllers/SpectatorController$2.class and b/target/classes/me/liamgiraldo/litebridge/controllers/SpectatorController$2.class differ diff --git a/target/classes/me/liamgiraldo/litebridge/controllers/SpectatorController$3.class b/target/classes/me/liamgiraldo/litebridge/controllers/SpectatorController$3.class index f3d3e63..7f12e2d 100644 Binary files a/target/classes/me/liamgiraldo/litebridge/controllers/SpectatorController$3.class and b/target/classes/me/liamgiraldo/litebridge/controllers/SpectatorController$3.class differ diff --git a/target/classes/me/liamgiraldo/litebridge/controllers/SpectatorController.class b/target/classes/me/liamgiraldo/litebridge/controllers/SpectatorController.class index 1d6b1b4..d5c243c 100644 Binary files a/target/classes/me/liamgiraldo/litebridge/controllers/SpectatorController.class and b/target/classes/me/liamgiraldo/litebridge/controllers/SpectatorController.class differ diff --git a/target/classes/me/liamgiraldo/litebridge/listeners/PlayerJoinListener.class b/target/classes/me/liamgiraldo/litebridge/listeners/PlayerJoinListener.class index 54d8bac..e4e1cf7 100644 Binary files a/target/classes/me/liamgiraldo/litebridge/listeners/PlayerJoinListener.class and b/target/classes/me/liamgiraldo/litebridge/listeners/PlayerJoinListener.class differ diff --git a/target/classes/me/liamgiraldo/litebridge/models/GUIModel.class b/target/classes/me/liamgiraldo/litebridge/models/GUIModel.class index 790ac25..886fd1f 100644 Binary files a/target/classes/me/liamgiraldo/litebridge/models/GUIModel.class and b/target/classes/me/liamgiraldo/litebridge/models/GUIModel.class differ diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml index 01020b7..b93679e 100644 --- a/target/classes/plugin.yml +++ b/target/classes/plugin.yml @@ -17,6 +17,8 @@ commands: feed: description: Sets hunger to full usage: / + permission: litebridge.feed + permission-message: You don't have permission to feed yourself repeat: description: Repeats the arguments provided to this command usage: / @@ -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 \ No newline at end of file diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties index a57f39a..1e48044 100644 --- a/target/maven-archiver/pom.properties +++ b/target/maven-archiver/pom.properties @@ -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 diff --git a/target/original-litebridge-0.0.1-SNAPSHOT.jar b/target/original-litebridge-0.0.1-SNAPSHOT.jar index 365277d..ea80af9 100644 Binary files a/target/original-litebridge-0.0.1-SNAPSHOT.jar and b/target/original-litebridge-0.0.1-SNAPSHOT.jar differ