diff --git a/Minigames/pom.xml b/Minigames/pom.xml index 6a95d8cbf..a85004187 100644 --- a/Minigames/pom.xml +++ b/Minigames/pom.xml @@ -71,7 +71,7 @@ io.papermc paperlib - 1.0.5 + 1.0.7 compile @@ -132,6 +132,16 @@ config.yml *.properties presets/*.yml + + + + + . + false + src/main/resources + resourcepack/*.zip @@ -152,7 +162,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.4.0 + 3.5.1 @@ -200,7 +210,7 @@ org.apache.maven.plugins maven-source-plugin - 3.2.1 + 3.3.0 attach-sources @@ -214,7 +224,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M6 + 3.2.1 true 1 @@ -224,12 +234,12 @@ org.apache.maven.plugins maven-dependency-plugin - 3.5.0 + 3.6.1 org.codehaus.mojo versions-maven-plugin - 2.8.1 + 2.16.1 org.apache.maven.plugins diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/Events.java b/Minigames/src/main/java/au/com/mineauz/minigames/Events.java index 23f52c84f..048106043 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/Events.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/Events.java @@ -34,6 +34,7 @@ import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.player.*; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; @@ -48,7 +49,7 @@ public class Events implements Listener { private final MinigameManager mdata = plugin.getMinigameManager(); @EventHandler(priority = EventPriority.NORMAL) - public void onPlayerResourcePack(PlayerResourcePackStatusEvent event) { + public void onPlayerResourcePack(PlayerResourcePackStatusEvent event) { //todo 1.20.3 + add ressource pack not set final MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer()); List required = plugin.getPlayerManager().getApplyingPack(); if (ply.isInMinigame()) { @@ -177,7 +178,7 @@ public void onPlayerDisconnect(PlayerQuitEvent event) { MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer()); if (ply.isInMinigame()) { if (ply.getPlayer().isDead()) { - ply.getOfflineMinigamePlayer().setLoginLocation(ply.getMinigame().getQuitPosition()); + ply.getOfflineMinigamePlayer().setLoginLocation(ply.getMinigame().getQuitLocation()); ply.getOfflineMinigamePlayer().savePlayerData(); } pdata.quitMinigame(pdata.getMinigamePlayer(event.getPlayer()), false); @@ -243,7 +244,7 @@ public void onPlayerConnect(PlayerJoinEvent event) { } @EventHandler - public void playerInterract(PlayerInteractEvent event) { + public void playerInteract(PlayerInteractEvent event) { MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer()); if (ply.isInMinigame() && !ply.canInteract()) { @@ -252,11 +253,11 @@ public void playerInterract(PlayerInteractEvent event) { } if (ply.isInMenu() && ply.getNoClose() && ply.getManualEntry() != null) { event.setCancelled(true); - ply.setNoClose(false); if (event.getClickedBlock() != null) { + ply.setNoClose(false); ply.getManualEntry().checkValidEntry(event.getClickedBlock().getBlockData().getAsString()); + ply.setManualEntry(null); } - ply.setManualEntry(null); return; } if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.DRAGON_EGG) { @@ -271,6 +272,7 @@ public void playerInterract(PlayerInteractEvent event) { if (cblock.getState() instanceof Sign sign && sign.getSide(Side.FRONT).getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[Minigame]")) { // wax signs automatically sign.setWaxed(true); + sign.update(); if (event.getPlayer().hasPermission("minigame.sign.use.details")) { if ((sign.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "Join") || sign.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "Bet")) && !ply.isInMinigame()) { Minigame mgm = mdata.getMinigame(sign.getLine(2)); @@ -380,7 +382,6 @@ public void playerInterract(PlayerInteractEvent event) { } } - //Spectator disables: if (ply.isInMinigame() && pdata.getMinigamePlayer(event.getPlayer()).getMinigame().isSpectator(pdata.getMinigamePlayer(event.getPlayer()))) { event.setCancelled(true); @@ -458,7 +459,11 @@ private void entityDamageEntity(EntityDamageByEntityEvent event) { if (sb.getShooter() instanceof Player player) { MinigamePlayer shooter = pdata.getMinigamePlayer(player); Minigame mgm = ply.getMinigame(); - if (shooter == null) return; + + if (shooter == null) { + return; + } + if (shooter.isInMinigame() && shooter.getMinigame().equals(ply.getMinigame())) { if (!shooter.canPvP()) { event.setCancelled(true); @@ -627,13 +632,14 @@ private void spectatorAttack(EntityDamageByEntityEvent event) { @EventHandler(ignoreCancelled = true) private void clickMenu(InventoryClickEvent event) { - MinigamePlayer ply = pdata.getMinigamePlayer((Player) event.getWhoClicked()); - if (ply.isInMenu()) { - if (event.getRawSlot() < ply.getMenu().getSize()) { - if (!ply.getMenu().getAllowModify() || ply.getMenu().hasMenuItem(event.getRawSlot())) + MinigamePlayer mgPlayer = pdata.getMinigamePlayer(((Player) event.getWhoClicked())); + if (mgPlayer.isInMenu()) { + if (event.getRawSlot() < mgPlayer.getMenu().getSize()) { + if (!mgPlayer.getMenu().getAllowModify() || mgPlayer.getMenu().hasMenuItem(event.getRawSlot())) { event.setCancelled(true); + } - MenuItem item = ply.getMenu().getClicked(event.getRawSlot()); + MenuItem item = mgPlayer.getMenu().getClicked(event.getRawSlot()); if (item != null) { ItemStack disItem = null; switch (event.getClick()) { @@ -651,12 +657,38 @@ private void clickMenu(InventoryClickEvent event) { event.setCurrentItem(disItem); } + /* + * Cancel special cases, where event.getRawSlot() is not in the Menu inventory, + * but the event modifies it anyway + */ + } else if (!mgPlayer.getMenu().getAllowModify()) { + Inventory topInv = event.getView().getTopInventory(); + switch (event.getAction()) { + case NOTHING, DROP_ALL_CURSOR, DROP_ONE_CURSOR, UNKNOWN -> { + } // nothing + case PICKUP_ALL, PICKUP_SOME, PICKUP_HALF, PICKUP_ONE, DROP_ALL_SLOT, DROP_ONE_SLOT, HOTBAR_MOVE_AND_READD, // may take + PLACE_ALL, PLACE_SOME, PLACE_ONE, /*may place*/ + SWAP_WITH_CURSOR, HOTBAR_SWAP /*may give and take*/ -> { + if (event.getClickedInventory() == topInv) { + event.setCancelled(true); + } + } + case COLLECT_TO_CURSOR -> { // may take complex + if (topInv.contains(event.getCursor().getType())) { + event.setCancelled(true); + } + } + case MOVE_TO_OTHER_INVENTORY -> { + event.setCancelled(true); + } // definitely one or the other + } } - } else if (ply.isInMinigame()) { - if (!ply.getLoadout().allowOffHand() && event.getSlot() == 40) { + + } else if (mgPlayer.isInMinigame()) { + if (!mgPlayer.getLoadout().allowOffHand() && event.getSlot() == 40) { event.setCancelled(true); - } else if ((ply.getLoadout().isArmourLocked() && event.getSlot() >= 36 && event.getSlot() <= 39) || - (ply.getLoadout().isInventoryLocked() && event.getSlot() >= 0 && event.getSlot() <= 35)) { + } else if ((mgPlayer.getLoadout().isArmourLocked() && event.getSlot() >= 36 && event.getSlot() <= 39) || + (mgPlayer.getLoadout().isInventoryLocked() && event.getSlot() >= 0 && event.getSlot() <= 35)) { event.setCancelled(true); } } @@ -715,7 +747,6 @@ private void manualItemEntry(AsyncPlayerChatEvent event) { ply.getManualEntry().checkValidEntry(event.getMessage()); ply.setManualEntry(null); } - } @EventHandler(ignoreCancelled = true) diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/MinigameMessageType.java b/Minigames/src/main/java/au/com/mineauz/minigames/MinigameMessageType.java index 5e524db10..43e98aedc 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/MinigameMessageType.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/MinigameMessageType.java @@ -2,6 +2,7 @@ public enum MinigameMessageType { INFO, + WARN, ERROR, WIN, LOSS, diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/MinigameUtils.java b/Minigames/src/main/java/au/com/mineauz/minigames/MinigameUtils.java index 956cb7bfa..557d3fad9 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/MinigameUtils.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/MinigameUtils.java @@ -278,10 +278,9 @@ public static MinigameTool giveMinigameTool(MinigamePlayer player) { */ public static boolean hasMinigameTool(MinigamePlayer player) { for (ItemStack i : player.getPlayer().getInventory().getContents()) { - if (i != null && i.getItemMeta() != null) { - if (i.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Minigame Tool")) { - return true; - } + if (i != null && i.getItemMeta() != null && + i.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Minigame Tool")) { + return true; } } return false; diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/Minigames.java b/Minigames/src/main/java/au/com/mineauz/minigames/Minigames.java index 2eb85ad38..f1d787a3e 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/Minigames.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/Minigames.java @@ -1,7 +1,6 @@ package au.com.mineauz.minigames; import au.com.mineauz.minigames.backend.BackendManager; -import au.com.mineauz.minigames.blockRecorder.BasicRecorder; import au.com.mineauz.minigames.commands.CommandDispatcher; import au.com.mineauz.minigames.config.MinigameSave; import au.com.mineauz.minigames.display.DisplayManager; @@ -14,6 +13,7 @@ import au.com.mineauz.minigames.minigame.reward.RewardsModule; import au.com.mineauz.minigames.objects.MinigamePlayer; import au.com.mineauz.minigames.objects.ResourcePack; +import au.com.mineauz.minigames.recorder.BasicRecorder; import au.com.mineauz.minigames.signs.SignBase; import au.com.mineauz.minigames.stats.MinigameStats; import au.com.mineauz.minigames.stats.StatValueField; diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/package-info.java b/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/package-info.java deleted file mode 100644 index c30f8f478..000000000 --- a/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * BlockRecorder is the system for recording block / entity changes in a game and rolling them back afterward. - */ -package au.com.mineauz.minigames.blockRecorder; \ No newline at end of file diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/commands/BackupCommand.java b/Minigames/src/main/java/au/com/mineauz/minigames/commands/BackupCommand.java index 9dfdb1fcf..8f283e790 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/commands/BackupCommand.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/commands/BackupCommand.java @@ -2,9 +2,9 @@ import au.com.mineauz.minigames.MinigameUtils; import au.com.mineauz.minigames.Minigames; -import au.com.mineauz.minigames.blockRecorder.RecorderData; import au.com.mineauz.minigames.minigame.Minigame; import au.com.mineauz.minigames.minigame.MinigameState; +import au.com.mineauz.minigames.recorder.RecorderData; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -64,7 +64,7 @@ public boolean onCommand(CommandSender sender, Minigame minigame, minigame = Minigames.getPlugin().getMinigameManager().getMinigame(args[0]); if (!minigame.getRegenRegions().isEmpty()) { if (args.length == 1) { - if (minigame.getPlayers().size() == 0) { + if (minigame.getPlayers().isEmpty()) { minigame.setState(MinigameState.REGENERATING); Minigames.getPlugin().getMinigameManager().addRegenDataToRecorder(minigame); RecorderData d = minigame.getRecorderData(); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/commands/CommandDispatcher.java b/Minigames/src/main/java/au/com/mineauz/minigames/commands/CommandDispatcher.java index 5eaf373f6..a7ff36cc4 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/commands/CommandDispatcher.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/commands/CommandDispatcher.java @@ -139,8 +139,8 @@ public static void registerCommand(ICommand command) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { Player ply = null; - if (sender instanceof Player) { - ply = (Player) sender; + if (sender instanceof Player player) { + ply = player; } if (args != null && args.length > 0) { @@ -222,11 +222,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command sender.sendMessage(ChatColor.RED + comd.getPermissionMessage()); sender.sendMessage(ChatColor.RED + comd.getPermission()); } - return true; } else { sender.sendMessage(ChatColor.RED + "You must be a player to execute this command!"); - return true; } + return true; } } else { sender.sendMessage(ChatColor.GREEN + "Minigames"); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/commands/ICommand.java b/Minigames/src/main/java/au/com/mineauz/minigames/commands/ICommand.java index 1bc30955c..9aed73276 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/commands/ICommand.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/commands/ICommand.java @@ -7,16 +7,32 @@ import java.util.List; public interface ICommand { - // public MinigamePlayerManager playerManager = Minigames.plugin.getPlayerData(); -// public MinigameManager minigameManager = Minigames.plugin.getMinigameData(); Minigames plugin = Minigames.getPlugin(); + /** + * get the name of this (sub) command + * the name get used as it's first parameter + * in case of the command /mg the set subcommand /mg set implements this interface, + * as well as every sub-subcommand of it. set is the name of this specific subcommand + * and the name of all the ones one layer down are its parameters. + */ String getName(); + /** + * Get the aliases to the name of this command. + * An alias is an alternative name that should also show up as a parameter + * but calls the same command. + */ String[] getAliases(); + /** + * If the command can be called from the console or if it is strictly only callable by a player + */ boolean canBeConsole(); + /** + * Used in help command to describe what this (sub)command does. + */ String getDescription(); String[] getParameters(); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/commands/QuitCommand.java b/Minigames/src/main/java/au/com/mineauz/minigames/commands/QuitCommand.java index 6d152781d..9351482be 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/commands/QuitCommand.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/commands/QuitCommand.java @@ -7,6 +7,8 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -57,8 +59,8 @@ public String getPermission() { } @Override - public boolean onCommand(CommandSender sender, Minigame minigame, - String label, String[] args) { + public boolean onCommand(@NotNull CommandSender sender, Minigame minigame, + String label, @NotNull String @Nullable [] args) { if (args == null && sender instanceof Player) { MinigamePlayer player = plugin.getPlayerManager().getMinigamePlayer((Player) sender); if (player.isInMinigame()) { @@ -68,13 +70,7 @@ public boolean onCommand(CommandSender sender, Minigame minigame, } return true; } else if (args != null) { - Player player = null; - if (sender instanceof Player) { - player = (Player) sender; - } - if (player == null || player.hasPermission("minigame.quit.other")) { - List players = plugin.getServer().matchPlayer(args[0]); - MinigamePlayer ply; + if (sender.hasPermission("minigame.quit.other")) { if (args[0].equals("ALL")) { if (args.length > 1) { if (plugin.getMinigameManager().hasMinigame(args[1])) { @@ -96,18 +92,23 @@ public boolean onCommand(CommandSender sender, Minigame minigame, sender.sendMessage(ChatColor.GRAY + MinigameUtils.getLang("command.quit.quitAll")); } return true; - } else if (players.isEmpty()) { - sender.sendMessage(ChatColor.RED + MessageManager.getMinigamesMessage("command.quit.invalidPlayer", args[0])); - return true; } else { - ply = plugin.getPlayerManager().getMinigamePlayer(players.get(0)); - } + MinigamePlayer ply; + List players = plugin.getServer().matchPlayer(args[0]); - if (ply.isInMinigame()) { - plugin.getPlayerManager().quitMinigame(ply, false); - sender.sendMessage(ChatColor.GRAY + MessageManager.getMinigamesMessage("command.quit.quitOther", ply.getName())); - } else { - sender.sendMessage(ChatColor.RED + MessageManager.getMinigamesMessage("command.quit.invalidPlayer", args[0])); + if (players.isEmpty()) { + sender.sendMessage(ChatColor.RED + MessageManager.getMinigamesMessage("command.quit.invalidPlayer", args[0])); + return true; + } else { + ply = plugin.getPlayerManager().getMinigamePlayer(players.get(0)); + } + + if (ply.isInMinigame()) { + plugin.getPlayerManager().quitMinigame(ply, false); + sender.sendMessage(ChatColor.GRAY + MessageManager.getMinigamesMessage("command.quit.quitOther", ply.getName())); + } else { + sender.sendMessage(ChatColor.RED + MessageManager.getMinigamesMessage("command.quit.invalidPlayer", args[0])); + } } } else { sender.sendMessage(ChatColor.RED + MinigameUtils.getLang("command.quit.noPermissionOther")); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/commands/ScoreCommand.java b/Minigames/src/main/java/au/com/mineauz/minigames/commands/ScoreCommand.java index 30763f0b4..bca014fa8 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/commands/ScoreCommand.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/commands/ScoreCommand.java @@ -9,9 +9,12 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.Locale; public class ScoreCommand implements ICommand { @@ -59,39 +62,38 @@ public String getPermission() { } @Override - public boolean onCommand(CommandSender sender, Minigame minigame, - String label, String[] args) { - if (args != null && args.length >= 2) { + public boolean onCommand(@NotNull CommandSender sender, @Nullable Minigame minigame, + @Nullable String label, @NotNull String @Nullable [] args) { + if (args != null && args.length >= 3) { MinigamePlayer ply = null; - TeamColor color = TeamColor.matchColor(args[1]); + TeamColor color = TeamColor.matchColor(args[2]); + Minigame mg = plugin.getMinigameManager().getMinigame(args[1]); if (color == null) { - List plys = plugin.getServer().matchPlayer(args[1]); + List plys = plugin.getServer().matchPlayer(args[2]); if (!plys.isEmpty()) { ply = plugin.getPlayerManager().getMinigamePlayer(plys.get(0)); } else { - sender.sendMessage(ChatColor.RED + "No player or team found by the name " + args[1]); + sender.sendMessage(ChatColor.RED + "No player or team found by the name " + args[2]); return true; } } - if (args[0].equalsIgnoreCase("get")) { - if (ply != null) { - if (ply.isInMinigame()) { - sender.sendMessage(ChatColor.GRAY + ply.getName() + "'s Score: " + ChatColor.GREEN + ply.getScore()); - } else { - sender.sendMessage(ChatColor.RED + ply.getName() + " is not playing a Minigame!"); - } - } else { - if (args.length >= 3) { - Minigame mg; - if (plugin.getMinigameManager().hasMinigame(args[2])) { - mg = plugin.getMinigameManager().getMinigame(args[2]); + if (mg == null) { + sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + args[2]); + return true; + } + + + switch (args[0].toLowerCase(Locale.ENGLISH)) { + case "get" -> { + if (ply != null) { + if (ply.isInMinigame()) { + sender.sendMessage(ChatColor.GRAY + ply.getName() + "'s Score: " + ChatColor.GREEN + ply.getScore()); } else { - sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + args[2]); - return true; + sender.sendMessage(ChatColor.RED + ply.getName() + " is not playing a Minigame!"); } - + } else { TeamsModule tmod = TeamsModule.getMinigameModule(mg); if (mg.isTeamGame()) { @@ -106,170 +108,179 @@ public boolean onCommand(CommandSender sender, Minigame minigame, sender.sendMessage(ChatColor.RED + mg.getName(false) + " is not a team Minigame!"); return true; } - } else { - sender.sendMessage(ChatColor.RED + "This command requires a Minigame name as the last argument!"); } - } - return true; - } else if (args[0].equalsIgnoreCase("set") && args.length >= 3) { - - int score; - - if (args[2].matches("-?[0-9]+")) { - score = Integer.parseInt(args[2]); - } else { - sender.sendMessage(ChatColor.RED + args[2] + " is not a valid number!"); return true; - } - if (ply != null) { - if (ply.isInMinigame()) { - ply.setScore(score); - ply.getMinigame().setScore(ply, ply.getScore()); - sender.sendMessage(ChatColor.GRAY + ply.getName() + "'s score has been set to " + score); + } // end case - if (ply.getMinigame().getMaxScore() != 0 && score >= ply.getMinigame().getMaxScorePerPlayer()) { - plugin.getPlayerManager().endMinigame(ply); - } - } else { - sender.sendMessage(ChatColor.RED + ply.getName() + " is not playing a Minigame!"); - } - } else { + case "set" -> { if (args.length >= 4) { - Minigame mg; - if (plugin.getMinigameManager().hasMinigame(args[3])) { - mg = plugin.getMinigameManager().getMinigame(args[3]); - } else { - sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + args[2]); - return true; - } - - TeamsModule tmod = TeamsModule.getMinigameModule(mg); + if (args[3].matches("^[+\\-]?[0-9]+$")) { + int score = Integer.parseInt(args[2]); - if (mg.isTeamGame() && mg.hasPlayers()) { - Team t; - if (tmod.hasTeam(color)) { - t = tmod.getTeam(color); - t.setScore(score); - sender.sendMessage(t.getChatColor() + t.getDisplayName() + ChatColor.GRAY + " score has been set to " + score); - } else { - sender.sendMessage(ChatColor.RED + mg.getName(false) + " does not have a " + color.toString().toLowerCase() + " team."); - return true; - } + if (ply != null) { + if (ply.isInMinigame()) { + ply.setScore(score); + ply.getMinigame().setScore(ply, ply.getScore()); + sender.sendMessage(ChatColor.GRAY + ply.getName() + "'s score has been set to " + score); - if (mg.getMaxScore() != 0 && score >= mg.getMaxScorePerPlayer()) { - List w = new ArrayList<>(t.getPlayers()); - List l = new ArrayList<>(mg.getPlayers().size() - t.getPlayers().size()); - for (Team te : tmod.getTeams()) { - if (te != t) { - l.addAll(te.getPlayers()); + if (ply.getMinigame().getMaxScore() != 0 && score >= ply.getMinigame().getMaxScorePerPlayer()) { + plugin.getPlayerManager().endMinigame(ply); } + } else { + sender.sendMessage(ChatColor.RED + ply.getName() + " is not playing a Minigame!"); } - plugin.getPlayerManager().endMinigame(mg, w, l); + } else if (mg.isTeamGame()) { + TeamsModule tmod = TeamsModule.getMinigameModule(mg); + if (mg.hasPlayers()) { + Team changedTeam; + + if (tmod.hasTeam(color)) { + changedTeam = tmod.getTeam(color); + changedTeam.setScore(score); + sender.sendMessage(changedTeam.getChatColor() + changedTeam.getDisplayName() + ChatColor.GRAY + " score has been set to " + score); + + // check new score + if (mg.getMaxScore() != 0 && score >= mg.getMaxScorePerPlayer()) { + List winners = new ArrayList<>(changedTeam.getPlayers()); + List losers = new ArrayList<>(mg.getPlayers().size() - changedTeam.getPlayers().size()); + for (Team team : tmod.getTeams()) { + if (team != changedTeam) { + losers.addAll(team.getPlayers()); + } + } + + plugin.getPlayerManager().endMinigame(mg, winners, losers); + } + } else { + sender.sendMessage(ChatColor.RED + mg.getName(false) + " does not have a " + color.toString().toLowerCase() + " team."); + } + } else { + sender.sendMessage(ChatColor.RED + mg.getName(false) + " has no players playing!"); + } + } else { + sender.sendMessage(ChatColor.RED + mg.getName(false) + " is not a team Minigame!"); } - } else if (!mg.hasPlayers()) { - sender.sendMessage(ChatColor.RED + mg.getName(false) + " has no players playing!"); } else { - sender.sendMessage(ChatColor.RED + mg.getName(false) + " is not a team Minigame!"); + sender.sendMessage(ChatColor.RED + args[2] + " is not a valid number!"); } } else { - sender.sendMessage(ChatColor.RED + "This command requires a Minigame name as the last argument!"); + sender.sendMessage(ChatColor.RED + "Not enough arguments!"); } - } - return true; - } else if (args[0].equalsIgnoreCase("add") && args.length >= 3) { - int score; - if (args[2].matches("-?[0-9]+")) { - score = Integer.parseInt(args[2]); - } else { - score = 1; - } + return true; + } // end case - if (ply != null) { - if (ply.isInMinigame()) { - ply.addScore(score); - ply.getMinigame().setScore(ply, ply.getScore()); - sender.sendMessage(ChatColor.GRAY + "Added " + score + " to " + ply.getName() + "'s score, new score: " + ply.getScore()); + case "add" -> { + if (args.length >= 4) { + if (args[3].matches("^[+\\-]?[0-9]+$")) { + int score = Integer.parseInt(args[2]); - if (ply.getMinigame().getMaxScore() != 0 && ply.getScore() >= ply.getMinigame().getMaxScorePerPlayer()) { - plugin.getPlayerManager().endMinigame(ply); + if (ply != null) { + if (ply.isInMinigame()) { + ply.addScore(score); + ply.getMinigame().setScore(ply, ply.getScore()); + sender.sendMessage(ChatColor.GRAY + "Added " + score + " to " + ply.getName() + "'s score, new score: " + ply.getScore()); + + if (ply.getMinigame().getMaxScore() != 0 && ply.getScore() >= ply.getMinigame().getMaxScorePerPlayer()) { + plugin.getPlayerManager().endMinigame(ply); + } + } else { + sender.sendMessage(ChatColor.RED + ply.getName() + " is not playing a Minigame!"); + } + } else if (mg.isTeamGame()) { + TeamsModule tmod = TeamsModule.getMinigameModule(mg); + if (mg.hasPlayers()) { + if (tmod.hasTeam(color)) { + Team changedTeam = tmod.getTeam(color); + if (changedTeam != null) { + changedTeam.addScore(score); + sender.sendMessage(ChatColor.GRAY + "Added " + score + " to " + changedTeam.getChatColor() + changedTeam.getDisplayName() + + ChatColor.GRAY + " score, new score: " + changedTeam.getScore()); + } else { + sender.sendMessage(ChatColor.RED + mg.getName(false) + " does not have a " + color.toString().toLowerCase() + " team."); + return true; + } + + if (mg.getMaxScore() != 0 && changedTeam.getScore() >= mg.getMaxScorePerPlayer()) { + List winners = new ArrayList<>(changedTeam.getPlayers()); + List losers = new ArrayList<>(mg.getPlayers().size() - changedTeam.getPlayers().size()); + for (Team team : tmod.getTeams()) { + if (team != changedTeam) { + losers.addAll(team.getPlayers()); + } + } + plugin.getPlayerManager().endMinigame(mg, winners, losers); + } + } else { + sender.sendMessage(ChatColor.RED + mg.getName(false) + " does not have a " + color.toString().toLowerCase() + " team."); + } + } else { + sender.sendMessage(ChatColor.RED + mg.getName(false) + " has no players playing!"); + } + } else { + sender.sendMessage(ChatColor.RED + mg.getName(false) + " is not a team Minigame!"); + } + } else { + sender.sendMessage(ChatColor.RED + args[2] + " is not a valid number!"); } } else { - sender.sendMessage(ChatColor.RED + ply.getName() + " is not playing a Minigame!"); + sender.sendMessage(ChatColor.RED + "Not enough arguments!"); } - } else { - Minigame mg; - String mgName; - if (args.length == 4) { - mgName = args[3]; - } else { - mgName = args[2]; + return true; + } // end case + } // end switch + } else { + sender.sendMessage(ChatColor.RED + "Not enough arguments!"); + } + return false; + } + + @Override + public List onTabComplete(@NotNull CommandSender sender, @Nullable Minigame minigame, + @NotNull String alias, @NotNull String @Nullable [] args) { + if (args != null) { + switch (args.length) { + case 1 -> { + return MinigameUtils.tabCompleteMatch(List.of("get", "set", "add"), args[0]); + } + case 2 -> { + List mgs = new ArrayList<>(plugin.getMinigameManager().getAllMinigames().keySet()); + return MinigameUtils.tabCompleteMatch(mgs, args[1]); + } + case 3 -> { + List pt = new ArrayList<>(plugin.getServer().getOnlinePlayers().size()); + for (Player pl : plugin.getServer().getOnlinePlayers()) { + pt.add(pl.getName()); } + Minigame mgm = plugin.getMinigameManager().getMinigame(args[1]); - if (plugin.getMinigameManager().hasMinigame(mgName)) { - mg = plugin.getMinigameManager().getMinigame(mgName); - } else { - sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + mgName); - return true; + if (mgm != null && mgm.isTeamGame()) { + pt.addAll(TeamsModule.getMinigameModule(mgm).getTeams().stream().map(t -> t.getColor().name()).toList()); } - TeamsModule tmod = TeamsModule.getMinigameModule(mg); - - if (mg.isTeamGame() && mg.hasPlayers()) { - Team team; - if (tmod.hasTeam(color)) { - team = tmod.getTeam(color); - team.addScore(score); - sender.sendMessage(ChatColor.GRAY + "Added " + score + " to " + team.getChatColor() + team.getDisplayName() + - ChatColor.GRAY + " score, new score: " + team.getScore()); - } else { - sender.sendMessage(ChatColor.RED + mg.getName(false) + " does not have a " + color.toString().toLowerCase() + " team."); - return true; - } + return MinigameUtils.tabCompleteMatch(pt, args[2]); + } + case 4 -> { + if (args[0].equalsIgnoreCase("set") || args[0].equalsIgnoreCase("add")) { + if (args[3].matches("^[+\\-]?[0-9]+$")) { + List numbers = new ArrayList<>(10); - if (mg.getMaxScore() != 0 && team.getScore() >= mg.getMaxScorePerPlayer()) { - List w = new ArrayList<>(team.getPlayers()); - List l = new ArrayList<>(mg.getPlayers().size() - team.getPlayers().size()); - for (Team te : tmod.getTeams()) { - if (te != team) { - l.addAll(te.getPlayers()); - } + for (int i = 0; i < 10; i++) { + numbers.add(args[3] + i); } - plugin.getPlayerManager().endMinigame(mg, w, l); - } - } else if (!mg.hasPlayers()) { - sender.sendMessage(ChatColor.RED + mg.getName(false) + " has no players playing!"); - } else { - sender.sendMessage(ChatColor.RED + mg.getName(false) + " is not a team Minigame!"); - } - } - return true; - } - } - return false; - } - @Override - public List onTabComplete(CommandSender sender, Minigame minigame, - String alias, String[] args) { - if (args.length == 1) { - return MinigameUtils.tabCompleteMatch(List.of("get", "set", "add"), args[0]); - } else if (args.length == 2) { - - List pt = new ArrayList<>(plugin.getServer().getOnlinePlayers().size() + 2); - for (Player pl : plugin.getServer().getOnlinePlayers()) { - pt.add(pl.getName()); - } - pt.add("red"); - pt.add("blue"); + return MinigameUtils.tabCompleteMatch(numbers, args[3]); + } // not a number + } // not add / set + } // more than 4 arguments + } // end switch + } // args == null - return MinigameUtils.tabCompleteMatch(pt, args[1]); - } - List mgs = new ArrayList<>(plugin.getMinigameManager().getAllMinigames().keySet()); - return MinigameUtils.tabCompleteMatch(mgs, args[args.length - 1]); + + return null; } } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/commands/StartCommand.java b/Minigames/src/main/java/au/com/mineauz/minigames/commands/StartCommand.java index 9d5547bb0..a43b718be 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/commands/StartCommand.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/commands/StartCommand.java @@ -61,22 +61,28 @@ public boolean onCommand(CommandSender sender, Minigame minigame, Minigame mgm = plugin.getMinigameManager().getMinigame(args[0]); if (mgm != null) { - if (!mgm.isEnabled() && mgm.getType() == MinigameType.GLOBAL) { - MinigamePlayer caller = null; - if (sender instanceof Player) - caller = plugin.getPlayerManager().getMinigamePlayer((Player) sender); - plugin.getMinigameManager().startGlobalMinigame(mgm, caller); - } else if (mgm.getType() != MinigameType.GLOBAL && mgm.getType() != MinigameType.SINGLEPLAYER && mgm.hasPlayers()) { + if (mgm.getType() == MinigameType.GLOBAL) { + if (mgm.isEnabled()) { + sender.sendMessage(ChatColor.RED + mgm.getName(false) + " is already running!"); + } else { + MinigamePlayer caller = null; + if (sender instanceof Player) { + caller = plugin.getPlayerManager().getMinigamePlayer((Player) sender); + } + + plugin.getMinigameManager().startGlobalMinigame(mgm, caller); + } + } else if (mgm.getType() != MinigameType.SINGLEPLAYER && mgm.hasPlayers()) { if (mgm.getMpTimer() == null || mgm.getMpTimer().getPlayerWaitTimeLeft() != 0) { if (mgm.getMpTimer() == null) { mgm.setMpTimer(new MultiplayerTimer(mgm)); } + mgm.getMpTimer().setCurrentLobbyWaitTime(0); mgm.getMpTimer().startTimer(); - } else + } else { sender.sendMessage(ChatColor.RED + mgm.getName(false) + " has already started."); - } else if (mgm.isEnabled() && mgm.getType() == MinigameType.GLOBAL) { - sender.sendMessage(ChatColor.RED + mgm.getName(false) + " is already running!"); + } } } else { sender.sendMessage(ChatColor.RED + "No Global or Multiplayer Minigame found by the name " + args[0]); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetEndCommand.java b/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetEndCommand.java index 0d8bd0a81..fa0e5bf73 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetEndCommand.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetEndCommand.java @@ -53,7 +53,7 @@ public String getPermission() { @Override public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) { - minigame.setEndPosition(((Player) sender).getLocation()); + minigame.setEndLocation(((Player) sender).getLocation()); sender.sendMessage(ChatColor.GRAY + "Ending position has been set for " + minigame); return true; } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetLobbyCommand.java b/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetLobbyCommand.java index 5c6565685..dc88e01eb 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetLobbyCommand.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetLobbyCommand.java @@ -58,7 +58,7 @@ public String getPermission() { public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) { if (args == null) { - minigame.setLobbyPosition(((Player) sender).getLocation()); + minigame.setLobbyLocation(((Player) sender).getLocation()); sender.sendMessage(ChatColor.GRAY + "Lobby position has been set for " + minigame); } else { LobbySettingsModule lobby = LobbySettingsModule.getMinigameModule(minigame); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetQuitCommand.java b/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetQuitCommand.java index e947874d8..a562d0baf 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetQuitCommand.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetQuitCommand.java @@ -54,7 +54,7 @@ public String getPermission() { public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) { Player player = (Player) sender; - minigame.setQuitPosition(player.getLocation()); + minigame.setQuitLocation(player.getLocation()); sender.sendMessage(ChatColor.GRAY + "Quit position has been set for " + minigame); return true; } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetStartCommand.java b/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetStartCommand.java index 4da3c354f..8da97d18e 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetStartCommand.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetStartCommand.java @@ -82,7 +82,7 @@ public boolean onCommand(CommandSender sender, Minigame minigame, String label, Team team = TeamsModule.getMinigameModule(minigame).getTeam(TeamColor.matchColor(args[0])); if (team == null) { sender.sendMessage(ChatColor.RED + "No team color found by the name: " + args[0]); - return true; + return false; } if (position >= 1) { @@ -95,21 +95,28 @@ public boolean onCommand(CommandSender sender, Minigame minigame, String label, } return true; } else if (args[0].equalsIgnoreCase("clear")) { - if (args.length >= 2 && TeamColor.matchColor(args[1]) != null) { - Team team = TeamsModule.getMinigameModule(minigame).getTeam(TeamColor.matchColor(args[1])); - if (team == null) { + if (args.length >= 2) { + //check for team + if (TeamColor.matchColor(args[1]) != null) { + Team team = TeamsModule.getMinigameModule(minigame).getTeam(TeamColor.matchColor(args[1])); + if (team == null) { + sender.sendMessage(ChatColor.RED + "No team color found by the name: " + args[1]); + return false; + } + + team.getStartLocations().clear(); + sender.sendMessage(ChatColor.GRAY + "Starting positions for " + team.getChatColor() + team.getDisplayName() + ChatColor.GRAY + + " have been cleared in " + minigame); + } else { sender.sendMessage(ChatColor.RED + "No team color found by the name: " + args[1]); - return true; + return false; } - - team.getStartLocations().clear(); - sender.sendMessage(ChatColor.GRAY + "Starting positions for " + team.getChatColor() + team.getDisplayName() + ChatColor.GRAY + - " have been cleared in " + minigame); - } else { minigame.getStartLocations().clear(); sender.sendMessage(ChatColor.GRAY + "Starting positions have been cleared in " + minigame); } + + return true; } return false; } @@ -118,10 +125,8 @@ public boolean onCommand(CommandSender sender, Minigame minigame, String label, public List onTabComplete(CommandSender sender, Minigame minigame, String alias, String[] args) { List teams = new ArrayList<>(TeamsModule.getMinigameModule(minigame).getTeamsNameMap().size() + 1); - for (String t : TeamsModule.getMinigameModule(minigame).getTeamsNameMap().keySet()) { - teams.add(WordUtils.capitalize(t.replace("_", " "))); - } if (args.length == 1) { + TeamsModule.getMinigameModule(minigame).getTeamsNameMap().keySet().forEach(teamName -> teams.add(WordUtils.capitalize(teamName))); teams.add("Clear"); return MinigameUtils.tabCompleteMatch(teams, args[0]); } else if (args.length == 2 && args[0].equalsIgnoreCase("clear")) { diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/AbstractCancellableMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/AbstractCancellableMinigameEvent.java new file mode 100644 index 000000000..f41d2a902 --- /dev/null +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/AbstractCancellableMinigameEvent.java @@ -0,0 +1,37 @@ +package au.com.mineauz.minigames.events; + +import au.com.mineauz.minigames.minigame.Minigame; +import org.bukkit.event.Cancellable; + +public class AbstractCancellableMinigameEvent extends AbstractMinigameEvent implements Cancellable { + private boolean cancelled = false; + + /** + * Instantiates a new Abstract minigame event. + * + * @param game the mgm + */ + public AbstractCancellableMinigameEvent(final Minigame game) { + super(game); + } + + /** + * True if cancelled. + * + * @return boolean + */ + @Override + public boolean isCancelled() { + return this.cancelled; + } + + /** + * Sets the cancel status of the event. + * + * @param b boolean + */ + @Override + public void setCancelled(final boolean b) { + this.cancelled = b; + } +} \ No newline at end of file diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/AbstractMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/AbstractMinigameEvent.java index 11d2508cf..c13fc67cf 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/AbstractMinigameEvent.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/AbstractMinigameEvent.java @@ -1,15 +1,13 @@ package au.com.mineauz.minigames.events; import au.com.mineauz.minigames.minigame.Minigame; -import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; -public class AbstractMinigameEvent extends Event implements Cancellable { +public class AbstractMinigameEvent extends Event { private static final HandlerList HANDLERS = new HandlerList(); private final Minigame mgm; - private boolean cancelled = false; /** * Instantiates a new Abstract minigame event. @@ -25,26 +23,6 @@ public static HandlerList getHandlerList() { return HANDLERS; } - /** - * True if cancelled. - * - * @return boolean - */ - @Override - public boolean isCancelled() { - return this.cancelled; - } - - /** - * Sets the cancel status of the event. - * - * @param b boolean - */ - @Override - public void setCancelled(final boolean b) { - this.cancelled = b; - } - /** * Get minigame minigame. * diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/DropFlagEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/DropFlagEvent.java index bda355442..ccd70dc6c 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/DropFlagEvent.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/DropFlagEvent.java @@ -4,7 +4,7 @@ import au.com.mineauz.minigames.objects.CTFFlag; import au.com.mineauz.minigames.objects.MinigamePlayer; -public class DropFlagEvent extends AbstractMinigameEvent { +public class DropFlagEvent extends AbstractCancellableMinigameEvent { private final CTFFlag flag; private final MinigamePlayer player; private boolean displayMessage = true; diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/EndMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/EndMinigameEvent.java deleted file mode 100644 index e1c5c14c2..000000000 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/EndMinigameEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -package au.com.mineauz.minigames.events; - -import au.com.mineauz.minigames.minigame.Minigame; -import au.com.mineauz.minigames.objects.MinigamePlayer; - -import java.util.List; - -public class EndMinigameEvent extends AbstractMinigameEvent { - private final List winners; - private final List losers; - - - public EndMinigameEvent(List winners, List losers, Minigame minigame) { - super(minigame); - this.winners = winners; - this.losers = losers; - } - - public List getWinners() { - return winners; - } - - public List getLosers() { - return losers; - } -} - - diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/EndPhaseMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/EndPhaseMinigameEvent.java new file mode 100644 index 000000000..c514e7c2c --- /dev/null +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/EndPhaseMinigameEvent.java @@ -0,0 +1,37 @@ +package au.com.mineauz.minigames.events; + +import au.com.mineauz.minigames.minigame.Minigame; +import au.com.mineauz.minigames.objects.MinigamePlayer; + +import java.util.List; + +/** + * This event is called whenever a minigame enters it's endphase. + * This happens amongst others if a team wins or a finished sign was used. + * However, this is NOT a guaranteed indicator that a minigame is about to end. + * While the Endphase will lead to the end of a minigame, this event will NOT be called if certain circumstances happen, + * like if the /mg quit command was called. + *

+ * if you need an event for cleanup use {@link EndedMinigameEvent} + */ +public class EndPhaseMinigameEvent extends AbstractCancellableMinigameEvent { + private final List winners; + private final List losers; + + + public EndPhaseMinigameEvent(List winners, List losers, Minigame minigame) { + super(minigame); + this.winners = winners; + this.losers = losers; + } + + public List getWinners() { + return winners; + } + + public List getLosers() { + return losers; + } +} + + diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/EndedMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/EndedMinigameEvent.java new file mode 100644 index 000000000..6cf1254fe --- /dev/null +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/EndedMinigameEvent.java @@ -0,0 +1,12 @@ +package au.com.mineauz.minigames.events; + +import au.com.mineauz.minigames.minigame.Minigame; + +/** + * this event indicates the minigame has definitely ended now and is in the process of clearing up + */ +public class EndedMinigameEvent extends AbstractMinigameEvent { + public EndedMinigameEvent(Minigame minigame) { + super(minigame); + } +} \ No newline at end of file diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/FlagCaptureEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/FlagCaptureEvent.java index 6cd341071..f8e56a225 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/FlagCaptureEvent.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/FlagCaptureEvent.java @@ -4,7 +4,7 @@ import au.com.mineauz.minigames.objects.CTFFlag; import au.com.mineauz.minigames.objects.MinigamePlayer; -public class FlagCaptureEvent extends AbstractMinigameEvent { +public class FlagCaptureEvent extends AbstractCancellableMinigameEvent { private final MinigamePlayer player; private final CTFFlag flag; diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/JoinMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/JoinMinigameEvent.java index 84b71eb4b..7da259c51 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/JoinMinigameEvent.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/JoinMinigameEvent.java @@ -4,7 +4,7 @@ import au.com.mineauz.minigames.objects.MinigamePlayer; import org.bukkit.entity.Player; -public class JoinMinigameEvent extends AbstractMinigameEvent { +public class JoinMinigameEvent extends AbstractCancellableMinigameEvent { private final MinigamePlayer player; private final boolean betting; diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/MinigameTimerTickEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/MinigameTimerTickEvent.java index 50d8bcae7..e02e430a1 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/MinigameTimerTickEvent.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/MinigameTimerTickEvent.java @@ -3,7 +3,7 @@ import au.com.mineauz.minigames.MinigameTimer; import au.com.mineauz.minigames.minigame.Minigame; -public class MinigameTimerTickEvent extends AbstractMinigameEvent { +public class MinigameTimerTickEvent extends AbstractCancellableMinigameEvent { private final MinigameTimer timer; diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/MinigamesBroadcastEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/MinigamesBroadcastEvent.java index c5195e2e9..1f38b7473 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/MinigamesBroadcastEvent.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/MinigamesBroadcastEvent.java @@ -2,7 +2,7 @@ import au.com.mineauz.minigames.minigame.Minigame; -public class MinigamesBroadcastEvent extends AbstractMinigameEvent { +public class MinigamesBroadcastEvent extends AbstractCancellableMinigameEvent { private String message; private final String prefix; private boolean cancelled = false; diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/QuitMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/QuitMinigameEvent.java index 48f9a9c6d..c87c42756 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/QuitMinigameEvent.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/QuitMinigameEvent.java @@ -4,7 +4,7 @@ import au.com.mineauz.minigames.objects.MinigamePlayer; import org.bukkit.entity.Player; -public class QuitMinigameEvent extends AbstractMinigameEvent { +public class QuitMinigameEvent extends AbstractCancellableMinigameEvent { private final MinigamePlayer player; private final boolean isForced; private final boolean isWinner; diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/RevertCheckpointEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/RevertCheckpointEvent.java index a0c3424b3..75ae902ea 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/RevertCheckpointEvent.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/RevertCheckpointEvent.java @@ -3,7 +3,7 @@ import au.com.mineauz.minigames.objects.MinigamePlayer; import org.bukkit.entity.Player; -public class RevertCheckpointEvent extends AbstractMinigameEvent { +public class RevertCheckpointEvent extends AbstractCancellableMinigameEvent { private final MinigamePlayer player; public RevertCheckpointEvent(MinigamePlayer player) { diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/SpectateMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/SpectateMinigameEvent.java index 691fcecdb..0d6f08245 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/SpectateMinigameEvent.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/SpectateMinigameEvent.java @@ -4,7 +4,7 @@ import au.com.mineauz.minigames.objects.MinigamePlayer; import org.bukkit.entity.Player; -public class SpectateMinigameEvent extends AbstractMinigameEvent { +public class SpectateMinigameEvent extends AbstractCancellableMinigameEvent { private final MinigamePlayer player; public SpectateMinigameEvent(MinigamePlayer player, Minigame minigame) { @@ -19,6 +19,4 @@ public MinigamePlayer getMinigamePlayer() { public Player getPlayer() { return player.getPlayer(); } - - } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/StartGlobalMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/StartGlobalMinigameEvent.java index 78c5f9d77..23f39f261 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/StartGlobalMinigameEvent.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/StartGlobalMinigameEvent.java @@ -3,7 +3,7 @@ import au.com.mineauz.minigames.minigame.Minigame; import au.com.mineauz.minigames.objects.MinigamePlayer; -public class StartGlobalMinigameEvent extends AbstractMinigameEvent { +public class StartGlobalMinigameEvent extends AbstractCancellableMinigameEvent { private final String mechanic; private final MinigamePlayer caller; @@ -14,7 +14,6 @@ public StartGlobalMinigameEvent(Minigame mgm, MinigamePlayer caller) { this.caller = caller; } - public String getMechanic() { return mechanic; } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/StartMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/StartMinigameEvent.java index aaebcca6d..7b6dbd641 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/StartMinigameEvent.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/StartMinigameEvent.java @@ -9,7 +9,7 @@ /** * You cannot cancel this event */ -public class StartMinigameEvent extends AbstractMinigameEvent { +public class StartMinigameEvent extends AbstractCancellableMinigameEvent { private final boolean willTeleport; private final List players; diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/StopGlobalMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/StopGlobalMinigameEvent.java index 5ecf6f97b..0ffb47ff0 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/StopGlobalMinigameEvent.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/StopGlobalMinigameEvent.java @@ -3,7 +3,7 @@ import au.com.mineauz.minigames.minigame.Minigame; import au.com.mineauz.minigames.objects.MinigamePlayer; -public class StopGlobalMinigameEvent extends AbstractMinigameEvent { +public class StopGlobalMinigameEvent extends AbstractCancellableMinigameEvent { private final String mechanic; private final MinigamePlayer caller; diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/TakeFlagEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/TakeFlagEvent.java index 9eefee23c..84342ebac 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/TakeFlagEvent.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/TakeFlagEvent.java @@ -4,7 +4,7 @@ import au.com.mineauz.minigames.objects.CTFFlag; import au.com.mineauz.minigames.objects.MinigamePlayer; -public class TakeFlagEvent extends AbstractMinigameEvent { +public class TakeFlagEvent extends AbstractCancellableMinigameEvent { private final CTFFlag flag; private final String flagName; private boolean displayMessage = true; diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/TimerExpireEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/TimerExpireEvent.java index 94f37ed9b..c489467ab 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/TimerExpireEvent.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/TimerExpireEvent.java @@ -3,9 +3,7 @@ import au.com.mineauz.minigames.minigame.Minigame; import au.com.mineauz.minigames.minigame.MinigameState; -public class TimerExpireEvent extends AbstractMinigameEvent { - - +public class TimerExpireEvent extends AbstractCancellableMinigameEvent { public TimerExpireEvent(Minigame minigame) { super(minigame); } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/MinigameTypeBase.java b/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/MinigameTypeBase.java index 8062d50ab..856495e2e 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/MinigameTypeBase.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/MinigameTypeBase.java @@ -45,12 +45,12 @@ public void setType(MinigameType type) { public void callGeneralQuit(MinigamePlayer player, Minigame minigame) { if (!player.getPlayer().isDead()) { - if (player.getPlayer().getWorld() != minigame.getQuitPosition().getWorld() && player.getPlayer().hasPermission("minigame.set.quit") && plugin.getConfig().getBoolean("warnings")) { + if (player.getPlayer().getWorld() != minigame.getQuitLocation().getWorld() && player.getPlayer().hasPermission("minigame.set.quit") && plugin.getConfig().getBoolean("warnings")) { player.sendMessage(ChatColor.RED + "WARNING: " + ChatColor.WHITE + "Quit location is across worlds! This may cause some server performance issues!", MinigameMessageType.ERROR); } - player.teleport(minigame.getQuitPosition()); + player.teleport(minigame.getQuitLocation()); } else { - player.setQuitPos(minigame.getQuitPosition()); + player.setQuitPos(minigame.getQuitLocation()); player.setRequiredQuit(true); } } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/MultiplayerType.java b/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/MultiplayerType.java index a1e425eba..de830740f 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/MultiplayerType.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/MultiplayerType.java @@ -47,7 +47,7 @@ public boolean cannotStart(Minigame mgm, MinigamePlayer player) { boolean cannotStart; cannotStart = mgm.getPlayers().size() >= mgm.getMaxPlayers(); if (cannotStart) message = MinigameUtils.getLang("minigame.full"); - cannotStart = mgm.getLobbyPosition() == null; + cannotStart = mgm.getLobbyLocation() == null; if (cannotStart) message = MinigameUtils.getLang("minigame.error.noLobby"); if (cannotStart) player.sendMessage(message, MinigameMessageType.ERROR); return cannotStart; @@ -55,7 +55,7 @@ public boolean cannotStart(Minigame mgm, MinigamePlayer player) { @Override public boolean teleportOnJoin(MinigamePlayer player, Minigame mgm) { - Location location = mgm.getLobbyPosition(); + Location location = mgm.getLobbyLocation(); boolean result = false; if (location == null) { plugin.getLogger().warning("Game has no lobby set and it was expected:" + mgm.getName(true)); @@ -151,7 +151,7 @@ public void quitMinigame(MinigamePlayer player, Minigame mgm, boolean forced) { if (mgm.isTeamGame()) { player.removeTeam(); for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) { - if (t.getPlayers().size() > 0) + if (!t.getPlayers().isEmpty()) teamsWithPlayers++; } @@ -179,7 +179,7 @@ public void quitMinigame(MinigamePlayer player, Minigame mgm, boolean forced) { if (TeamsModule.getMinigameModule(mgm).getTeams().size() != 1) { Team winner = null; for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) { - if (t.getPlayers().size() > 0) { + if (!t.getPlayers().isEmpty()) { winner = t; break; } @@ -262,7 +262,7 @@ public void playerRespawn(PlayerRespawnEvent event) { } ply.getLoadout().equiptLoadout(ply); } else { - respawnPos = mg.getLobbyPosition(); + respawnPos = mg.getLobbyLocation(); } } else { if (mg.hasStarted() && !ply.isLatejoining()) { @@ -276,7 +276,7 @@ public void playerRespawn(PlayerRespawnEvent event) { ply.getLoadout().equiptLoadout(ply); } else { - respawnPos = mg.getLobbyPosition(); + respawnPos = mg.getLobbyLocation(); } } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/SingleplayerType.java b/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/SingleplayerType.java index 26fc94834..662cd4be2 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/SingleplayerType.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/SingleplayerType.java @@ -14,6 +14,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerRespawnEvent; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Calendar; @@ -39,6 +40,11 @@ public boolean cannotStart(Minigame mgm, MinigamePlayer player) { @Override public boolean teleportOnJoin(MinigamePlayer player, Minigame mgm) { List locs = new ArrayList<>(mgm.getStartLocations()); + + if (locs.isEmpty()) { + return false; + } + Collections.shuffle(locs); boolean result = player.teleport(locs.get(0)); if (plugin.getConfig().getBoolean("warnings") && player.getPlayer().getWorld() != locs.get(0).getWorld() && @@ -51,8 +57,7 @@ public boolean teleportOnJoin(MinigamePlayer player, Minigame mgm) { @Override public boolean joinMinigame(MinigamePlayer player, Minigame mgm) { - - if (mgm.getLives() > 0 && !Float.isFinite(mgm.getLives())) { + if (mgm.getLives() > 0 && Math.abs(mgm.getLives()) < Integer.MAX_VALUE) { player.sendInfoMessage(MessageManager.getMinigamesMessage("minigame.livesLeft", mgm.getLives())); } if (!mgm.isAllowedFlight()) { @@ -117,7 +122,7 @@ public void endMinigame(List winners, List loser } @Override - public void quitMinigame(final MinigamePlayer player, final Minigame mgm, boolean forced) { + public void quitMinigame(final @NotNull MinigamePlayer player, final @NotNull Minigame mgm, boolean forced) { if (mgm.canSaveCheckpoint()) { StoredPlayerCheckpoints spc = player.getStoredPlayerCheckpoints(); spc.addCheckpoint(mgm.getName(false), player.getCheckpoint()); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/managers/MessageManager.java b/Minigames/src/main/java/au/com/mineauz/minigames/managers/MessageManager.java index b2c6e2ba3..c0f92ea01 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/managers/MessageManager.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/managers/MessageManager.java @@ -32,27 +32,27 @@ public class MessageManager { * Stores each prop file with an identifier */ private static final Hashtable propertiesHashMap = new Hashtable<>(); - private static Locale locale = Locale.getDefault(); private static Logger logger = null; - public static void setLocale(Locale locale) { - MessageManager.locale = locale; - } - public static void setLogger(Logger logger) { MessageManager.logger = logger; } public static void registerCoreLanguage() { String tag = Minigames.getPlugin().getConfig().getString("lang", Locale.getDefault().toLanguageTag()); - locale = Locale.forLanguageTag(tag); + Locale locale = Locale.forLanguageTag(tag.replace("_", "-")); + + // fall back if locale is undefined + if (locale.getLanguage().isEmpty()) { + locale = Locale.getDefault(); + } + Minigames.log().info("MessageManager set locale for language:" + locale.toLanguageTag()); File file = new File(new File(Minigames.getPlugin().getDataFolder(), "lang"), "minigames.properties"); - registerCoreLanguage(file, Locale.getDefault()); + registerCoreLanguage(file, locale); } public static void registerCoreLanguage(File file, Locale locale) { - MessageManager.setLocale(locale); ResourceBundle minigames = null; if (file.exists()) { try { diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigameManager.java b/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigameManager.java index 1987defa8..3ca9da771 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigameManager.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigameManager.java @@ -4,7 +4,6 @@ import au.com.mineauz.minigames.MinigameUtils; import au.com.mineauz.minigames.Minigames; import au.com.mineauz.minigames.PlayerLoadout; -import au.com.mineauz.minigames.blockRecorder.RecorderData; import au.com.mineauz.minigames.config.MinigameSave; import au.com.mineauz.minigames.config.RewardsFlag; import au.com.mineauz.minigames.events.StartGlobalMinigameEvent; @@ -19,11 +18,13 @@ import au.com.mineauz.minigames.objects.MgRegion; import au.com.mineauz.minigames.objects.MinigamePlayer; import au.com.mineauz.minigames.objects.ResourcePack; +import au.com.mineauz.minigames.recorder.RecorderData; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.configuration.Configuration; import org.bukkit.configuration.file.FileConfiguration; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.*; @@ -136,10 +137,9 @@ public void addMinigame(final Minigame game) { if (Minigames.getPlugin().includesPapi()) { Minigames.getPlugin().getPlaceHolderManager().addGameIdentifiers(game); } - } - public Minigame getMinigame(final String minigame) { + public @Nullable Minigame getMinigame(final String minigame) { if (this.minigames.containsKey(minigame)) { return this.minigames.get(minigame); } @@ -230,7 +230,6 @@ public Set getMinigameTypes() { return this.minigameTypes.keySet(); } - public void addLoadout(final String name) { this.globalLoadouts.put(name, new PlayerLoadout(name)); } @@ -315,11 +314,11 @@ private void sendBroadcastMessage(Minigame minigame, String message, MinigameMes type = MinigameMessageType.INFO; } finalMessage += message; - final List sendto = new ArrayList<>(); + final Set sendto = new HashSet<>(); sendto.addAll(minigame.getPlayers()); sendto.addAll(minigame.getSpectators()); if (exclude != null) { - sendto.removeAll(exclude); + exclude.forEach(sendto::remove); } for (final MinigamePlayer pl : sendto) { pl.sendMessage(finalMessage, type); @@ -445,10 +444,10 @@ public boolean minigameStartStateCheck(final Minigame minigame, final MinigamePl } public boolean minigameStartSetupCheck(final Minigame minigame, final MinigamePlayer player) { - if (minigame.getEndPosition() == null) { + if (minigame.getEndLocation() == null) { player.sendMessage(MinigameUtils.getLang("minigame.error.noEnd"), MinigameMessageType.ERROR); return false; - } else if (minigame.getQuitPosition() == null) { + } else if (minigame.getQuitLocation() == null) { player.sendMessage(MinigameUtils.getLang("minigame.error.noQuit"), MinigameMessageType.ERROR); return false; } else if (minigame.getType() == null || this.minigameType(minigame.getType()).cannotStart(minigame, player)) { //type specific reasons we cannot start. @@ -467,7 +466,7 @@ public boolean minigameStartSetupCheck(final Minigame minigame, final MinigamePl public boolean teleportPlayerOnJoin(@NotNull final Minigame minigame, final MinigamePlayer player) { if (this.minigameType(minigame.getType()) == null) { - Minigames.log().warning(MessageManager.getMinigamesMessage("error.invalidType") + " : " + minigame.getName(true)); + Minigames.log().warning(MessageManager.getMinigamesMessage("minigame.error.invalidType") + " : " + minigame.getName(true)); } return this.minigameType(minigame.getType()).teleportOnJoin(player, minigame); } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigamePlayerManager.java b/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigamePlayerManager.java index 8959238de..2d46cb01d 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigamePlayerManager.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigamePlayerManager.java @@ -4,7 +4,6 @@ import au.com.mineauz.minigames.MinigameUtils; import au.com.mineauz.minigames.Minigames; import au.com.mineauz.minigames.MultiplayerBets; -import au.com.mineauz.minigames.blockRecorder.RegenRecorder; import au.com.mineauz.minigames.events.*; import au.com.mineauz.minigames.gametypes.MinigameType; import au.com.mineauz.minigames.mechanics.GameMechanicBase; @@ -15,6 +14,7 @@ import au.com.mineauz.minigames.minigame.modules.*; import au.com.mineauz.minigames.objects.MinigamePlayer; import au.com.mineauz.minigames.objects.ResourcePack; +import au.com.mineauz.minigames.recorder.RegenRecorder; import au.com.mineauz.minigames.sounds.MGSounds; import au.com.mineauz.minigames.sounds.PlayMGSound; import au.com.mineauz.minigames.stats.DynamicMinigameStat; @@ -34,6 +34,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.potion.PotionEffect; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.*; @@ -256,7 +257,9 @@ public void spectateMinigame(MinigamePlayer player, Minigame minigame) { pl.getPlayer().hidePlayer(plugin, player.getPlayer()); } - player.getPlayer().setScoreboard(minigame.getScoreboardManager()); + if (minigame.canDisplayScoreboard()) { + player.getPlayer().setScoreboard(minigame.getScoreboardManager()); + } for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) { player.getPlayer().removePotionEffect(potion.getType()); @@ -445,7 +448,6 @@ public void getStartLocations(List players, Minigame game) { } public void revertToCheckpoint(MinigamePlayer player) { - RevertCheckpointEvent event = new RevertCheckpointEvent(player); Bukkit.getServer().getPluginManager().callEvent(event); @@ -469,7 +471,7 @@ public void revertToCheckpoint(MinigamePlayer player) { } } - public void quitMinigame(MinigamePlayer player, boolean forced) { + public void quitMinigame(@NotNull MinigamePlayer player, boolean forced) { Minigame minigame = player.getMinigame(); boolean isWinner = GameOverModule.getMinigameModule(minigame).getWinners().contains(player); @@ -477,7 +479,48 @@ public void quitMinigame(MinigamePlayer player, boolean forced) { QuitMinigameEvent event = new QuitMinigameEvent(player, minigame, forced, isWinner); Bukkit.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { - if (!minigame.isSpectator(player)) { + if (minigame.isSpectator(player)) { + if (player.getPlayer().getVehicle() != null) { + Vehicle vehicle = (Vehicle) player.getPlayer().getVehicle(); + vehicle.eject(); + } + player.getPlayer().setFallDistance(0); + player.getPlayer().setNoDamageTicks(60); + final Player fplayer = player.getPlayer(); + for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) { + player.getPlayer().removePotionEffect(potion.getType()); + } + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> fplayer.setFireTicks(0)); + + player.getPlayer().closeInventory(); + if (player.isLiving()) { + player.restorePlayerData(); + } + + Location loc; + if (minigame.getEndLocation() != null) { + loc = minigame.getEndLocation(); + } else { + loc = minigame.getQuitLocation(); + } + + if (loc != null) { + player.teleport(loc); + } else { + Minigames.log.warning("Minigame " + minigame.getName(true) + " has no end location set! (Player: " + player.getName() + ")"); + } + + player.setStartPos(null); + player.removeMinigame(); + minigame.removeSpectator(player); + + for (MinigamePlayer pl : minigame.getPlayers()) { + pl.getPlayer().showPlayer(plugin, player.getPlayer()); + } + + player.sendMessage(MessageManager.getMinigamesMessage("player.spectate.quit.plyMsg", minigame.getName(true)), MinigameMessageType.ERROR); + mgManager.sendMinigameMessage(minigame, MessageManager.getMinigamesMessage("player.spectate.quit.minigameMsg", player.getName(), minigame.getName(true)), MinigameMessageType.ERROR, player); + } else { if (player.getEndTime() == 0) player.setEndTime(System.currentTimeMillis()); @@ -488,8 +531,9 @@ public void quitMinigame(MinigamePlayer player, boolean forced) { player.setCompleteTime(player.getEndTime() - player.getStartTime() + player.getStoredTime()); } - } else + } else { GameOverModule.getMinigameModule(minigame).getLosers().remove(player); + } if (!isWinner) { if (!minigame.canSaveCheckpoint() && minigame.isEnabled()) { @@ -539,28 +583,29 @@ public void quitMinigame(MinigamePlayer player, boolean forced) { player.restorePlayerData(); Location loc; if (!isWinner) { - if (minigame.getQuitPosition() != null) { - loc = minigame.getQuitPosition(); + if (minigame.getQuitLocation() != null) { + loc = minigame.getQuitLocation(); } else { - loc = minigame.getEndPosition(); + loc = minigame.getEndLocation(); } } else { - if (minigame.getEndPosition() != null) { - loc = minigame.getEndPosition(); + if (minigame.getEndLocation() != null) { + loc = minigame.getEndLocation(); } else { - loc = minigame.getQuitPosition(); + loc = minigame.getQuitLocation(); } } if (loc != null) { player.teleport(loc); } else { - Minigames.log.warning("Minigame " + minigame.getName(true) + " has no end position set! (Player: " + player.getName() + ")"); + Minigames.log.warning("Minigame " + minigame.getName(true) + " has no end location set! (Player: " + player.getName() + ")"); } } else { - if (!isWinner) - player.setQuitPos(minigame.getQuitPosition()); - else - player.setQuitPos(minigame.getEndPosition()); + if (!isWinner) { + player.setQuitPos(minigame.getQuitLocation()); + } else { + player.setQuitPos(minigame.getEndLocation()); + } player.setRequiredQuit(true); } player.setStartPos(null); @@ -572,7 +617,10 @@ public void quitMinigame(MinigamePlayer player, boolean forced) { player.claimRewards(); //Reset Minigame - if (minigame.getPlayers().size() == 0) { + if (minigame.getPlayers().isEmpty()) { + //call event about this minigame has come to an end (and therefor is past an optional end phase) + Bukkit.getServer().getPluginManager().callEvent(new EndedMinigameEvent(minigame)); + if (minigame.getMinigameTimer() != null) { minigame.getMinigameTimer().stopTimer(); minigame.setMinigameTimer(null); @@ -602,15 +650,17 @@ public void quitMinigame(MinigamePlayer player, boolean forced) { } mgManager.clearClaimedScore(minigame); + WeatherTimeModule mod = WeatherTimeModule.getMinigameModule(minigame); if (mod != null) { mod.stopTimeLoop(); } + GameOverModule.getMinigameModule(minigame).stopEndGameTimer(); + for (Team team : TeamsModule.getMinigameModule(minigame).getTeams()) { team.setScore(0); } - } minigame.getScoreboardManager().resetScores(player.getName()); @@ -629,34 +679,6 @@ public void quitMinigame(MinigamePlayer player, boolean forced) { } plugin.getLogger().info(player.getName() + " quit " + minigame); player.updateInventory(); - } else { - if (player.getPlayer().getVehicle() != null) { - Vehicle vehicle = (Vehicle) player.getPlayer().getVehicle(); - vehicle.eject(); - } - player.getPlayer().setFallDistance(0); - player.getPlayer().setNoDamageTicks(60); - final Player fplayer = player.getPlayer(); - for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) { - player.getPlayer().removePotionEffect(potion.getType()); - } - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> fplayer.setFireTicks(0)); - - player.getPlayer().closeInventory(); - if (player.isLiving()) { - player.restorePlayerData(); - } - player.teleport(minigame.getQuitPosition()); - player.setStartPos(null); - player.removeMinigame(); - minigame.removeSpectator(player); - - for (MinigamePlayer pl : minigame.getPlayers()) { - pl.getPlayer().showPlayer(plugin, player.getPlayer()); - } - - player.sendMessage(MessageManager.getMinigamesMessage("player.spectate.quit.plyMsg", minigame.getName(true)), MinigameMessageType.ERROR); - mgManager.sendMinigameMessage(minigame, MessageManager.getMinigamesMessage("player.spectate.quit.minigameMsg", player.getName(), minigame.getName(true)), MinigameMessageType.ERROR, player); } if (ResourcePackModule.getMinigameModule(minigame).isEnabled()) { if (player.applyResourcePack(plugin.getResourceManager().getResourcePack("empty"))) { @@ -681,11 +703,10 @@ public void endMinigame(MinigamePlayer player) { endMinigame(player.getMinigame(), w, l); } - public void endMinigame(Minigame minigame, List winners, List losers) { //When the minigame ends, the flag for recognizing the start teleportation needs to be resetted minigame.setPlayersAtStart(false); - EndMinigameEvent event = new EndMinigameEvent(winners, losers, minigame); + EndPhaseMinigameEvent event = new EndPhaseMinigameEvent(winners, losers, minigame); Bukkit.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { @@ -735,7 +756,7 @@ public void endMinigame(Minigame minigame, List winners, List winners, Minigame minigame) { } } - @Deprecated public boolean playerInMinigame(Player player) { return minigamePlayers.get(player.getName()).isInMinigame(); @@ -917,8 +937,9 @@ public void removeMinigamePlayer(Player player) { public @Nullable MinigamePlayer getMinigamePlayer(UUID uuid) { for (MinigamePlayer p : minigamePlayers.values()) { - if (p.getUUID() == uuid) + if (p.getUUID() == uuid) { return p; + } } return getMinigamePlayer(Bukkit.getPlayer(uuid)); @@ -1023,15 +1044,4 @@ public void saveDeniedCommands() { public void loadDeniedCommands() { setDeniedCommands(plugin.getConfig().getStringList("disabledCommands")); } - - private class PlayerLocation { - final Location location; - final Integer position; - - public PlayerLocation(int pos) { - location = null; - this.position = pos; - } - } - } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/CTFMechanic.java b/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/CTFMechanic.java index 129bf6141..902c2d279 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/CTFMechanic.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/CTFMechanic.java @@ -125,7 +125,7 @@ public void takeFlag(PlayerInteractEvent event) { (TeamsModule.getMinigameModule(mgm).hasTeam(TeamColor.matchColor(ChatColor.stripColor(sign.getLine(2)))) || sign.getLine(2).equalsIgnoreCase(ChatColor.GRAY + "Neutral"))) { Team oTeam = TeamsModule.getMinigameModule(mgm).getTeam(TeamColor.matchColor(ChatColor.stripColor(sign.getLine(2)))); - CTFFlag flag = new CTFFlag(event.getClickedBlock().getLocation(), oTeam, mgm); + CTFFlag flag = new CTFFlag(sign, oTeam, mgm); ev = new TakeFlagEvent(mgm, ply, flag); Bukkit.getPluginManager().callEvent(ev); if (!ev.isCancelled()) { diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/LivesMechanic.java b/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/LivesMechanic.java index 0216340a4..73cda201c 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/LivesMechanic.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/LivesMechanic.java @@ -67,13 +67,13 @@ private void minigameStart(StartMinigameEvent event) { final List players = event.getPlayers(); final Minigame minigame = event.getMinigame(); for (MinigamePlayer player : players) { - if (!Float.isFinite(minigame.getLives())) { - player.setScore(Integer.MAX_VALUE); - minigame.setScore(player, Integer.MAX_VALUE); - } else { - int lives = Float.floatToIntBits(minigame.getLives()); + if (Math.abs(minigame.getLives()) < Integer.MAX_VALUE) { + int lives = minigame.getLives(); player.setScore(lives); minigame.setScore(player, lives); + } else { + player.setScore(Integer.MAX_VALUE); + minigame.setScore(player, Integer.MAX_VALUE); } } } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/TreasureHuntMechanic.java b/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/TreasureHuntMechanic.java index d7849da18..d15486a71 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/TreasureHuntMechanic.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/TreasureHuntMechanic.java @@ -18,6 +18,7 @@ import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.Chest; +import org.bukkit.block.Container; import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; @@ -68,7 +69,7 @@ public static void spawnTreasure(final Minigame mgm) { double ry; double rz; final int maxradius; - if (thm.getMaxRadius() == 0) { + if (thm.getMaxRadius() <= 0) { maxradius = 1000; } else { maxradius = thm.getMaxRadius(); @@ -89,40 +90,41 @@ public static void spawnTreasure(final Minigame mgm) { //Add a new Chest //TODO: Improve so no invalid spawns (Not over void, Strict containment) - switch (rpos.getBlock().getType()) { - case AIR, CAVE_AIR, VOID_AIR -> { - while (rpos.getBlock().getType() == Material.AIR && rpos.getY() > 1) { - rpos.setY(rpos.getY() - 1); - } - rpos.setY(rpos.getY() + 1); - Bukkit.getScheduler().runTaskLater(plugin, () -> rpos.getBlock().setType(Material.CHEST), 1L); + if (rpos.getBlock().getType().isAir()) { + int minWorldHeight = rpos.getWorld().getMinHeight(); + // find first block below that is not air anymore to spawn on top of + while (rpos.getBlock().getType().isAir() && rpos.getY() > minWorldHeight) { + rpos.setY(rpos.getY() - 1); } - default -> { - while (rpos.getBlock().getType() != Material.AIR && rpos.getY() < 255) { - rpos.setY(rpos.getY() + 1); - } - Bukkit.getScheduler().runTaskLater(plugin, () -> rpos.getBlock().setType(Material.CHEST), 1L); + rpos.setY(rpos.getY() + 1); + } else { + int maxWorldHeight = rpos.getWorld().getMaxHeight(); + // find first block above that is air to spawn into + while (!rpos.getBlock().getType().isAir() && rpos.getY() < maxWorldHeight) { + rpos.setY(rpos.getY() + 1); } } - //Fill new chest + Bukkit.getScheduler().runTaskLater(plugin, () -> rpos.getBlock().setType(Material.CHEST), 1L); + + //Fill new container Bukkit.getScheduler().runTaskLater(plugin, () -> { - if (rpos.getBlock().getState() instanceof Chest chest) { + if (rpos.getBlock().getState() instanceof Container container) { // TODO: Treasure hunt needs own rewards specification RewardsModule rewards = RewardsModule.getModule(mgm); if (rewards.getScheme() instanceof StandardRewardScheme) { if (!((StandardRewardScheme) rewards.getScheme()).getPrimaryReward().getRewards().isEmpty()) { - int numitems = (int) Math.round(Math.random() * (thm.getMaxTreasure() - thm.getMinTreasure())) + thm.getMinTreasure(); + int numItems = (int) Math.min(container.getInventory().getSize(), Math.round(Math.random() * (thm.getMaxTreasure() - thm.getMinTreasure())) + thm.getMinTreasure()); final ItemStack[] items = new ItemStack[27]; - for (int i = 0; i < numitems; i++) { + for (int i = 0; i < numItems; i++) { RewardType rew = ((StandardRewardScheme) rewards.getScheme()).getPrimaryReward().getReward().get(0); if (rew instanceof ItemReward irew) { items[i] = irew.getRewardItem(); } } Collections.shuffle(Arrays.asList(items)); - chest.getInventory().setContents(items); + container.getInventory().setContents(items); } } } @@ -162,13 +164,14 @@ public void startMinigame(Minigame minigame, MinigamePlayer caller) { if (thm.getLocation() != null) { spawnTreasure(minigame); - if (Bukkit.getOnlinePlayers().size() == 0) + if (Bukkit.getOnlinePlayers().isEmpty()) minigame.getMinigameTimer().stopTimer(); } else { - if (caller == null) + if (caller == null) { Bukkit.getLogger().info("Treasure Hunt requires a location name to run!"); - else + } else { caller.sendMessage("Treasure Hunt requires a location name to run!", MinigameMessageType.ERROR); + } } } @@ -343,5 +346,4 @@ private void interactEvent(PlayerInteractEvent event) { } } } - } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemAddWhitelistBlock.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemAddWhitelistBlock.java index a422fda0d..83ad857fa 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemAddWhitelistBlock.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemAddWhitelistBlock.java @@ -2,13 +2,13 @@ import au.com.mineauz.minigames.MinigameMessageType; import au.com.mineauz.minigames.objects.MinigamePlayer; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import java.util.List; public class MenuItemAddWhitelistBlock extends MenuItem { - private final List whitelist; public MenuItemAddWhitelistBlock(String name, List whitelist) { @@ -42,24 +42,37 @@ public ItemStack onClick() { @Override public void checkValidEntry(String entry) { - entry = entry.toUpperCase(); - if (Material.getMaterial(entry) != null) { - Material mat = Material.getMaterial(entry); + // try a direct match in case of a chat input + Material mat = Material.matchMaterial(entry); + + // didn't work, now try the input as a block data, as we get when a block was clicked + if (mat == null) { + try { + mat = Bukkit.createBlockData(entry).getMaterial(); + + } catch (IllegalArgumentException ignored) { + } + } + + if (mat == null) { + // still didn't work. + getContainer().getViewer().sendMessage("No material with BlockData \"" + entry + "\" was found!", MinigameMessageType.ERROR); + } else { + // nice we got a Material! try to add it! if (!whitelist.contains(mat)) { + // intern whitelist.add(mat); + + // visual getContainer().addItem(new MenuItemWhitelistBlock(mat, whitelist)); + } else { getContainer().getViewer().sendMessage("Whitelist/Blacklist already contains this material", MinigameMessageType.ERROR); } - - getContainer().cancelReopenTimer(); - getContainer().displayMenu(getContainer().getViewer()); - return; } + /* cancel automatic reopening and reopen {@link MenuItemDisplayWhitelist}*/ getContainer().cancelReopenTimer(); getContainer().displayMenu(getContainer().getViewer()); - - getContainer().getViewer().sendMessage("No material by the name \"" + entry + "\" was found!", MinigameMessageType.ERROR); } } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemBlockData.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemBlockData.java index af8052e25..e8d8d7302 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemBlockData.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemBlockData.java @@ -14,23 +14,23 @@ import java.util.List; public class MenuItemBlockData extends MenuItem { - private Callback data; + private Callback dataCallback; public MenuItemBlockData(String name, Material displayItem) { super(name, displayItem); - data.setValue(displayItem.createBlockData()); - setDescription(createDescription(data.getValue())); + dataCallback.setValue(displayItem.createBlockData()); + setDescription(createDescription(dataCallback.getValue())); } public MenuItemBlockData(String name, Material displayItem, Callback callback) { super(name, displayItem); - this.data = callback; - setDescription(createDescription(data.getValue())); + this.dataCallback = callback; + setDescription(createDescription(dataCallback.getValue())); } @Override public void update() { - setDescription(createDescription(this.data.getValue())); + setDescription(createDescription(this.dataCallback.getValue())); } /** @@ -61,7 +61,12 @@ private List createDescription(BlockData data) { public ItemStack onClickWithItem(@Nullable ItemStack item) { try { BlockData data = item.getType().createBlockData(); - this.data.setValue(data); + this.dataCallback.setValue(data); + + // update the display item + ItemStack stackUpdate = getItem(); + stackUpdate.setType(item.getType()); + setItem(stackUpdate); } catch (IllegalArgumentException | NullPointerException e) { String name = "unknown"; if (item != null) { @@ -77,8 +82,16 @@ public void checkValidEntry(String entry) { String err = "No MgBlockData detected"; try { BlockData d = Bukkit.createBlockData(entry); - data.setValue(d); - setDescription(createDescription(data.getValue())); + dataCallback.setValue(d); + + // update the display item + setDescription(createDescription(dataCallback.getValue())); + if (d.getMaterial().isItem()) { + ItemStack stackUpdate = getItem(); + stackUpdate.setType(d.getMaterial()); + setItem(stackUpdate); + } + getContainer().cancelReopenTimer(); getContainer().displayMenu(getContainer().getViewer()); return; diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemString.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemString.java index 40e6c0b42..b04188bdc 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemString.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemString.java @@ -72,10 +72,11 @@ public ItemStack onDoubleClick() { @Override public void checkValidEntry(String entry) { - if (entry.equals("null") && allowNull) + if (entry.equals("null") && allowNull) { str.setValue(null); - else + } else { str.setValue(entry); + } updateDescription(); getContainer().cancelReopenTimer(); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/Minigame.java b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/Minigame.java index 3267939f9..fe580feea 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/Minigame.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/Minigame.java @@ -1,7 +1,6 @@ package au.com.mineauz.minigames.minigame; import au.com.mineauz.minigames.*; -import au.com.mineauz.minigames.blockRecorder.RecorderData; import au.com.mineauz.minigames.config.*; import au.com.mineauz.minigames.gametypes.MinigameType; import au.com.mineauz.minigames.mechanics.GameMechanicBase; @@ -15,6 +14,7 @@ import au.com.mineauz.minigames.objects.MgRegion; import au.com.mineauz.minigames.objects.MinigamePlayer; import au.com.mineauz.minigames.objects.RegenRegionSetResult; +import au.com.mineauz.minigames.recorder.RecorderData; import au.com.mineauz.minigames.script.ScriptCollection; import au.com.mineauz.minigames.script.ScriptObject; import au.com.mineauz.minigames.script.ScriptReference; @@ -32,10 +32,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.ScoreboardManager; +import org.bukkit.scoreboard.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -66,9 +63,9 @@ public class Minigame implements ScriptObject { private final BooleanFlag respawn = new BooleanFlag(Minigames.getPlugin().getConfig().getBoolean("has-respawn"), "respawn"); private final LocationListFlag startLocations = new LocationListFlag(null, "startpos"); private final BooleanFlag randomizeStart = new BooleanFlag(false, "ranndomizeStart"); - private final LocationFlag endPosition = new LocationFlag(null, "endpos"); - private final LocationFlag quitPosition = new LocationFlag(null, "quitpos"); - private final LocationFlag lobbyPosition = new LocationFlag(null, "lobbypos"); + private final LocationFlag endLocation = new LocationFlag(null, "endpos"); + private final LocationFlag quitLocation = new LocationFlag(null, "quitpos"); + private final LocationFlag lobbyLocation = new LocationFlag(null, "lobbypos"); private final LocationFlag spectatorPosition = new LocationFlag(null, "spectatorpos"); private final BooleanFlag usePermissions = new BooleanFlag(false, "usepermissions"); @@ -102,6 +99,7 @@ public class Minigame implements ScriptObject { private final BooleanFlag unlimitedAmmo = new BooleanFlag(false, "unlimitedammo"); private final BooleanFlag saveCheckpoints = new BooleanFlag(false, "saveCheckpoints"); private final BooleanFlag lateJoin = new BooleanFlag(false, "latejoin"); + // just to stay backwards compatible we have private final FloatFlag lives = new FloatFlag(0F, "lives"); private final RegionMapFlag regenRegions = new RegionMapFlag(new HashMap<>(), "regenRegions", "regenarea.1", "regenarea.2"); @@ -122,6 +120,7 @@ public class Minigame implements ScriptObject { @NotNull private final ScoreboardData sbData = new ScoreboardData(); private final Map statSettings = Maps.newHashMap(); + private final BooleanFlag activatePlayerRecorder = new BooleanFlag(true, "activatePlayerRecorder"); //Unsaved data private final List players = new ArrayList<>(); @@ -170,19 +169,19 @@ private void setup(MinigameType type, Location start) { if (start != null) startLocations.getFlag().add(start); if (sbManager != null) { - sbManager.registerNewObjective(this.name, "dummy", this.name); - sbManager.getObjective(this.name).setDisplaySlot(DisplaySlot.SIDEBAR); + sbManager.registerNewObjective(this.name, Criteria.DUMMY, this.name).setDisplaySlot(DisplaySlot.SIDEBAR); } for (Class mod : Minigames.getPlugin().getMinigameManager().getModules()) { try { addModule(mod.getDeclaredConstructor(Minigame.class).newInstance(this)); } catch (Exception e) { - e.printStackTrace(); + Minigames.getPlugin().getLogger().log(Level.WARNING, "Couldn't construct Module.", e); } } flags.setFlag(new ArrayList<>()); + addConfigFlag(activatePlayerRecorder); addConfigFlag(allowEnderPearls); addConfigFlag(allowFlight); addConfigFlag(allowMPCheckpoints); @@ -197,7 +196,7 @@ private void setup(MinigameType type, Location start) { addConfigFlag(displayName); addConfigFlag(enableFlight); addConfigFlag(enabled); - addConfigFlag(endPosition); + addConfigFlag(endLocation); addConfigFlag(flags); addConfigFlag(floorDegen); addConfigFlag(floorDegenTime); @@ -206,7 +205,7 @@ private void setup(MinigameType type, Location start) { addConfigFlag(itemPickup); addConfigFlag(lateJoin); addConfigFlag(lives); - addConfigFlag(lobbyPosition); + addConfigFlag(lobbyLocation); addConfigFlag(maxChestRandom); addConfigFlag(maxPlayers); addConfigFlag(maxScore); @@ -222,7 +221,7 @@ private void setup(MinigameType type, Location start) { addConfigFlag(objective); addConfigFlag(paintBallDamage); addConfigFlag(paintBallMode); - addConfigFlag(quitPosition); + addConfigFlag(quitLocation); addConfigFlag(randomizeChests); addConfigFlag(regenRegions); addConfigFlag(regenDelay); @@ -309,7 +308,11 @@ public boolean removeFlag(String flag) { } public void setStartLocation(Location loc) { - startLocations.getFlag().set(0, loc); + if (startLocations.getFlag().isEmpty()) { + startLocations.getFlag().add(loc); + } else { + startLocations.getFlag().set(0, loc); + } } public void addStartLocation(Location loc) { @@ -452,28 +455,28 @@ public void setDegenRandomChance(int degenRandomChance) { this.degenRandomChance.setFlag(degenRandomChance); } - public Location getEndPosition() { - return endPosition.getFlag(); + public @Nullable Location getEndLocation() { + return endLocation.getFlag(); } - public void setEndPosition(Location endPosition) { - this.endPosition.setFlag(endPosition); + public void setEndLocation(Location endLocation) { + this.endLocation.setFlag(endLocation); } - public Location getQuitPosition() { - return quitPosition.getFlag(); + public @Nullable Location getQuitLocation() { + return quitLocation.getFlag(); } - public void setQuitPosition(Location quitPosition) { - this.quitPosition.setFlag(quitPosition); + public void setQuitLocation(Location quitLocation) { + this.quitLocation.setFlag(quitLocation); } - public Location getLobbyPosition() { - return lobbyPosition.getFlag(); + public @Nullable Location getLobbyLocation() { + return lobbyLocation.getFlag(); } - public void setLobbyPosition(Location lobbyPosisiton) { - this.lobbyPosition.setFlag(lobbyPosisiton); + public void setLobbyLocation(Location lobbyLocation) { + this.lobbyLocation.setFlag(lobbyLocation); } public String getName(boolean useDisplay) { @@ -897,6 +900,14 @@ public void setMaxChestRandom(int maxChestRandom) { this.maxChestRandom.setFlag(maxChestRandom); } + public boolean getActivatePlayerRecorder() { + return activatePlayerRecorder.getFlag(); + } + + public void setActivatePlayerRecorder(boolean activatePlayerRecorder) { + this.activatePlayerRecorder.setFlag(activatePlayerRecorder); + } + public Collection getRegenRegions() { return regenRegions.getFlag().values(); } @@ -962,12 +973,12 @@ public void setRegenDelay(int regenDelay) { this.regenDelay.setFlag(regenDelay); } - public float getLives() { - return lives.getFlag(); + public int getLives() { + return lives.getFlag().intValue(); } - public void setLives(float lives) { - this.lives.setFlag(lives); + public void setLives(int lives) { + this.lives.setFlag((float) lives); } public int getFloorDegenTime() { @@ -1120,10 +1131,10 @@ public void setValue(String value) { MenuItemString obj = (MenuItemString) objective.getMenuItem("Objective Description", Material.DIAMOND); obj.setAllowNull(true); itemsMain.add(obj); - obj = (MenuItemString) gameTypeName.getMenuItem("Gametype Description", Material.OAK_WALL_SIGN); + obj = (MenuItemString) gameTypeName.getMenuItem("Gametype Description", Material.OAK_SIGN); obj.setAllowNull(true); itemsMain.add(obj); - obj = (MenuItemString) displayName.getMenuItem("Display Name", Material.OAK_WALL_SIGN); + obj = (MenuItemString) displayName.getMenuItem("Display Name", Material.OAK_SIGN); obj.setAllowNull(true); itemsMain.add(obj); itemsMain.add(new MenuItemNewLine()); @@ -1217,7 +1228,7 @@ public void setValue(Integer value) { }, 0, null)); itemsMain.add(new MenuItemNewLine()); itemsMain.add(new MenuItemPage("Player Settings", Material.SKELETON_SKULL, playerMenu)); -// List thDes = new ArrayList<>(); +// List thDes = new ArrayList<>(); // thDes.add("Treasure hunt related"); // thDes.add("settings."); // itemsMain.add(new MenuItemPage("Treasure Hunt Settings", thDes, Material.CHEST, treasureHunt)); @@ -1237,6 +1248,7 @@ public void setValue(Integer value) { rndChstDes.add("Max. item randomization"); itemsMain.add(maxChestRandom.getMenuItem("Max. Chest Random", Material.STONE, rndChstDes, 0, null)); itemsMain.add(new MenuItemStatisticsSettings(this, "Stat Settings", Material.WRITABLE_BOOK)); + itemsMain.add(activatePlayerRecorder.getMenuItem("Activate Player Block Recorder", Material.COMMAND_BLOCK)); itemsMain.add(new MenuItemNewLine()); //--------------// @@ -1302,7 +1314,7 @@ public void setValue(Integer value) { //--------------// List itemsFlags = new ArrayList<>(getFlags().size()); for (String flag : getFlags()) { - itemsFlags.add(new MenuItemFlag(Material.OAK_WALL_SIGN, flag, getFlags())); + itemsFlags.add(new MenuItemFlag(Material.OAK_SIGN, flag, getFlags())); } flags.addItem(new MenuItemPage("Back", MenuUtility.getBackMaterial(), playerMenu), flags.getSize() - 9); flags.addItem(new MenuItemAddFlag("Add Flag", MenuUtility.getCreateMaterial(), this), flags.getSize() - 1); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/modules/GameOverModule.java b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/modules/GameOverModule.java index ce6069e4e..1c500392a 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/modules/GameOverModule.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/modules/GameOverModule.java @@ -115,16 +115,20 @@ public void startEndGameTimer() { } if (timer.getFlag() > 0) { - if (task != -1) + if (task != -1) { stopEndGameTimer(); + } + task = Bukkit.getScheduler().scheduleSyncDelayedTask(Minigames.getPlugin(), () -> { for (MinigamePlayer loser : new ArrayList<>(losers)) { - if (loser.isInMinigame()) + if (loser.isInMinigame()) { Minigames.getPlugin().getPlayerManager().quitMinigame(loser, true); + } } for (MinigamePlayer winner : new ArrayList<>(winners)) { - if (winner.isInMinigame()) + if (winner.isInMinigame()) { Minigames.getPlugin().getPlayerManager().quitMinigame(winner, true); + } } clearLosers(); @@ -134,8 +138,9 @@ public void startEndGameTimer() { } public void stopEndGameTimer() { - if (task != -1) + if (task != -1) { Bukkit.getScheduler().cancelTask(task); + } } public void clearWinners() { diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/modules/InfectionModule.java b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/modules/InfectionModule.java index 0aaed6cf9..814f7b5a1 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/modules/InfectionModule.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/modules/InfectionModule.java @@ -17,7 +17,6 @@ import java.util.Map; public class InfectionModule extends MinigameModule { - private final IntegerFlag infectedPercent = new IntegerFlag(18, "infectedPercent"); private final StringFlag infectedTeam = new StringFlag("red", "infectedTeam"); private final StringFlag survivorTeam = new StringFlag("blue", "survivorTeam"); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/objects/CTFFlag.java b/Minigames/src/main/java/au/com/mineauz/minigames/objects/CTFFlag.java index fc289d9d4..8b1907e77 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/objects/CTFFlag.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/objects/CTFFlag.java @@ -5,49 +5,63 @@ import au.com.mineauz.minigames.managers.MessageManager; import au.com.mineauz.minigames.minigame.Minigame; import au.com.mineauz.minigames.minigame.Team; +import net.kyori.adventure.text.Component; import org.bukkit.*; -import org.bukkit.block.BlockState; -import org.bukkit.block.Container; -import org.bukkit.block.Sign; +import org.bukkit.block.*; +import org.bukkit.block.data.Directional; import org.bukkit.block.sign.Side; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; /** * Flag of Capture the Flag. * Technical background for au.com.mineauz.minigames.signs.FlagSign */ public class CTFFlag { - private Location spawnLocation = null; - private Location currentLocation = null; - private BlockState spawnData = null; + private final @NotNull BlockState spawnData; + private final @NotNull List<@NotNull Component> signText; + private final @NotNull Minigame minigame; + private final @NotNull Location spawnLocation; + private final @Nullable Location attachedToLocation; + private final @Nullable Team team; + private @Nullable Location currentLocation = null; private BlockState originalBlock = null; - private String[] signText = null; private boolean atHome = true; - private Team team = null; private int respawnTime = 60; private int taskID = -1; - private Minigame minigame = null; private int cParticleID = -1; - public CTFFlag(Location spawn, Team team, Minigame minigame) { - spawnLocation = spawn; - ((Sign) spawnLocation.getBlock().getState()).setWaxed(true); - spawnData = spawnLocation.getBlock().getState(); - signText = ((Sign) spawnLocation.getBlock().getState()).getSide(Side.FRONT).getLines(); + public CTFFlag(@NotNull Sign sign, @Nullable Team team, @NotNull Minigame minigame) { + sign.setWaxed(true); + + this.spawnLocation = sign.getLocation().toBlockLocation(); + this.spawnData = spawnLocation.getBlock().getState(); + this.signText = sign.getSide(Side.FRONT).lines(); this.team = team; - this.setMinigame(minigame); - respawnTime = Minigames.getPlugin().getConfig().getInt("multiplayer.ctf.flagrespawntime"); + this.minigame = minigame; + this.respawnTime = Minigames.getPlugin().getConfig().getInt("multiplayer.ctf.flagrespawntime"); + + // get the location the sign was attached to + Block signBlock = sign.getBlock(); + if (Tag.WALL_SIGNS.isTagged(signBlock.getType())) { + this.attachedToLocation = signBlock.getRelative( + ((Directional) sign.getBlockData()).getFacing().getOppositeFace()). + getLocation().toBlockLocation(); + } else if (Tag.STANDING_SIGNS.isTagged(signBlock.getType())) { + this.attachedToLocation = signBlock.getRelative(BlockFace.DOWN).getLocation().toBlockLocation(); + } else { // is hanging sign and therefor not depending on a block + attachedToLocation = null; + } } - public Location getSpawnLocation() { + public @NotNull Location getSpawnLocation() { return spawnLocation; } - public void setSpawnLocation(Location spawnLocation) { - this.spawnLocation = spawnLocation; - } - - public Location getCurrentLocation() { + public @Nullable Location getCurrentLocation() { return currentLocation; } @@ -63,17 +77,12 @@ public void setAtHome(boolean atHome) { this.atHome = atHome; } - public Team getTeam() { + public @Nullable Team getTeam() { return team; } - public void setTeam(Team team) { - this.team = team; - } - public Location spawnFlag(Location location) { Location blockBelow = location.clone(); - Location newLocation = location.clone(); blockBelow.setY(blockBelow.getBlockY() - 1); if (blockBelow.getBlock().getType() == Material.AIR) { @@ -104,7 +113,7 @@ public Location spawnFlag(Location location) { blockBelow.setY(blockBelow.getY() + 1); } - newLocation = blockBelow.clone(); + Location newLocation = blockBelow.clone(); newLocation.setY(newLocation.getY() + 1); // Converting wall signs to normal signs, if necessary @@ -123,7 +132,7 @@ public Location spawnFlag(Location location) { atHome = false; for (int i = 0; i < 4; i++) { - sign.getSide(Side.FRONT).setLine(i, signText[i]); + sign.getSide(Side.FRONT).line(i, signText.get(i)); } sign.update(); currentLocation = newLocation.clone(); @@ -160,7 +169,7 @@ public void respawnFlag() { sign.setWaxed(true); for (int i = 0; i < 4; i++) { - sign.getSide(Side.FRONT).setLine(i, signText[i]); + sign.getSide(Side.FRONT).line(i, signText.get(i)); } sign.update(); } @@ -171,14 +180,10 @@ public void stopTimer() { } } - public Minigame getMinigame() { + public @NotNull Minigame getMinigame() { return minigame; } - public void setMinigame(Minigame minigame) { - this.minigame = minigame; - } - public void startReturnTimer() { final CTFFlag self = this; taskID = Bukkit.getScheduler().scheduleSyncDelayedTask(Minigames.getPlugin(), () -> { @@ -211,4 +216,8 @@ public void stopCarrierParticleEffect() { cParticleID = -1; } } + + public @Nullable Location getAttachedToLocation() { + return attachedToLocation; + } } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/objects/MgRegion.java b/Minigames/src/main/java/au/com/mineauz/minigames/objects/MgRegion.java index f6442dfb5..b58eeaf73 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/objects/MgRegion.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/objects/MgRegion.java @@ -127,11 +127,11 @@ public boolean isInRegen(Location location) { } public double getBaseArea() { - return Math.min(1, Math.abs(pos1.x() - pos2.x())) * Math.min(1, Math.abs(pos1.z() - pos2.z())); + return (1 + Math.abs(pos1.x() - pos2.x())) * (1 + Math.abs(pos1.z() - pos2.z())); } public double getVolume() { - return getBaseArea() * Math.min(1, Math.abs(pos1.y() - pos2.y())); + return getBaseArea() * (1 + Math.abs(pos1.y() - pos2.y())); } @Override diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/objects/MinigamePlayer.java b/Minigames/src/main/java/au/com/mineauz/minigames/objects/MinigamePlayer.java index f40ad5552..f2b24e304 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/objects/MinigamePlayer.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/objects/MinigamePlayer.java @@ -66,7 +66,7 @@ public class MinigamePlayer implements ScriptObject { private Location selection1; private Location selection2; private IDisplayCuboid selectionDisplay; - private OfflineMinigamePlayer oply; + private OfflineMinigamePlayer offlineMinigamePlayer; private final StoredPlayerCheckpoints spc; private List claimedRewards = new ArrayList<>(); private int lateJoinTimer = -1; @@ -177,10 +177,11 @@ public void sendMessage(final Component msg, final @NotNull MinigameMessageType Component init; init = switch (type) { case ERROR -> Component.text("[Minigames] ", NamedTextColor.RED); + case WARN -> Component.text("[Minigames]", NamedTextColor.GOLD); case WIN -> Component.text("[Minigames] ", NamedTextColor.GREEN); - case LOSS -> Component.text("[Minigames]", NamedTextColor.DARK_RED); + case LOSS -> Component.text("[Minigames] ", NamedTextColor.DARK_RED); case NONE -> Component.text(""); - default -> Component.text("[Minigames]", NamedTextColor.AQUA); //also info + default -> Component.text("[Minigames] ", NamedTextColor.AQUA); //also info }; this.sendMessage(init.append(msg.colorIfAbsent(NamedTextColor.WHITE))); @@ -209,7 +210,7 @@ public void storePlayerData() { this.player.setLevel(0); this.player.setExp(0); - this.oply = new OfflineMinigamePlayer(this.getPlayer().getUniqueId(), storedItems, storedArmour, food, + this.offlineMinigamePlayer = new OfflineMinigamePlayer(this.getPlayer().getUniqueId(), storedItems, storedArmour, food, health, saturation, lastGM, exp, level, this.getPlayer().getLocation()); this.player.updateInventory(); } @@ -218,35 +219,35 @@ public void restorePlayerData() { this.player.getInventory().clear(); this.player.getInventory().setArmorContents(null); - this.player.getInventory().setContents(this.oply.getStoredItems()); - this.player.getInventory().setArmorContents(this.oply.getStoredArmour()); - this.player.setFoodLevel(this.oply.getFood()); - if (this.oply.getHealth() > 20) + this.player.getInventory().setContents(this.offlineMinigamePlayer.getStoredItems()); + this.player.getInventory().setArmorContents(this.offlineMinigamePlayer.getStoredArmour()); + this.player.setFoodLevel(this.offlineMinigamePlayer.getFood()); + if (this.offlineMinigamePlayer.getHealth() > 20) this.player.setHealth(20); else - this.player.setHealth(this.oply.getHealth()); - this.player.setSaturation(this.oply.getSaturation()); + this.player.setHealth(this.offlineMinigamePlayer.getHealth()); + this.player.setSaturation(this.offlineMinigamePlayer.getSaturation()); this.player.setScoreboard(Objects.requireNonNullElseGet(this.lastScoreboard, () -> this.player.getServer().getScoreboardManager().getMainScoreboard())); - if (this.oply.getExp() >= 0) { - this.player.setExp(this.oply.getExp()); - this.player.setLevel(this.oply.getLevel()); + if (this.offlineMinigamePlayer.getExp() >= 0) { + this.player.setExp(this.offlineMinigamePlayer.getExp()); + this.player.setLevel(this.offlineMinigamePlayer.getLevel()); } this.startPos = null; this.player.resetPlayerWeather(); this.player.resetPlayerTime(); this.allowGMChange = true; this.allowTP = true; - this.player.setGameMode(this.oply.getLastGamemode()); + this.player.setGameMode(this.offlineMinigamePlayer.getLastGamemode()); - this.oply.deletePlayerData(); - this.oply = null; + this.offlineMinigamePlayer.deletePlayerData(); + this.offlineMinigamePlayer = null; this.player.updateInventory(); } public boolean hasStoredData() { - return this.oply != null; + return this.offlineMinigamePlayer != null; } public boolean getAllowTeleport() { @@ -642,11 +643,11 @@ public void showSelection(final boolean clear) { } public OfflineMinigamePlayer getOfflineMinigamePlayer() { - return this.oply; + return this.offlineMinigamePlayer; } public void setOfflineMinigamePlayer(final OfflineMinigamePlayer oply) { - this.oply = oply; + this.offlineMinigamePlayer = oply; } public StoredPlayerCheckpoints getStoredPlayerCheckpoints() { diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/BasicRecorder.java b/Minigames/src/main/java/au/com/mineauz/minigames/recorder/BasicRecorder.java similarity index 81% rename from Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/BasicRecorder.java rename to Minigames/src/main/java/au/com/mineauz/minigames/recorder/BasicRecorder.java index f1e12668d..95360e73a 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/BasicRecorder.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/recorder/BasicRecorder.java @@ -1,4 +1,4 @@ -package au.com.mineauz.minigames.blockRecorder; +package au.com.mineauz.minigames.recorder; import au.com.mineauz.minigames.Minigames; import au.com.mineauz.minigames.managers.MinigamePlayerManager; @@ -35,13 +35,20 @@ /** * This class records all relevant changes the player does in the world while in a minigame + * After the minigame ends (or the player leaves it) this changes will be reverted. + * Shot arrows will be removed, blocks will be placed again, etc. */ public class BasicRecorder implements Listener { - private final MinigamePlayerManager playerManager = Minigames.getPlugin().getPlayerManager(); - //helper methode to not write code double - //this checks for Minigame signs and cancels the event, adds the block to the block recorder and handles block drops + /** + * helper methode for blockBreak event to not write code double + * this checks for Minigame signs and cancels the event, adds the block to the block recorder and handles block drops + * + * @param event the fired block break event + * @param mgPlayer the minigame representation of a player who broke the block + * @return true if the BlockBreakEvent should be canceled - aka if a minigame sign would get broken or if block drops are not allowed + */ private boolean handleBlockBreak(BlockBreakEvent event, MinigamePlayer mgPlayer) { Block eBlock = event.getBlock(); Minigame mgm = mgPlayer.getMinigame(); @@ -61,7 +68,11 @@ private boolean handleBlockBreak(BlockBreakEvent event, MinigamePlayer mgPlayer) } } - recData.addBlock(event.getBlock(), mgPlayer); + if (mgm.getActivatePlayerRecorder()) { + recData.addBlock(event.getBlock(), mgPlayer); + } + + // signs are safe. Now check for block drops if (!mgm.canBlocksdrop()) { event.getBlock().setType(Material.AIR); return true; @@ -70,7 +81,9 @@ private boolean handleBlockBreak(BlockBreakEvent event, MinigamePlayer mgPlayer) return false; } - //replace broken blocks (and stop breaking of blocks the player is not allowed to) <-- todo move this stopping into another more fitting class + /** + * record blocks broken by players (and stop breaking of blocks the player is not allowed to) + */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) private void blockBreak(BlockBreakEvent event) { MinigamePlayer mgPlayer = playerManager.getMinigamePlayer(event.getPlayer()); @@ -109,7 +122,9 @@ private void blockBreak(BlockBreakEvent event) { } } - //remove placed blocks (and stop placing ones the player is not allowed to) <-- todo move this stopping into another more fitting class + /** + * record placed blocks (and stop placing ones the players are not allowed to) + */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) private void blockPlace(BlockPlaceEvent event) { MinigamePlayer mgPlayer = playerManager.getMinigamePlayer(event.getPlayer()); @@ -124,15 +139,20 @@ private void blockPlace(BlockPlaceEvent event) { Minigame mgm = mgPlayer.getMinigame(); RecorderData recData = mgm.getRecorderData(); - if (mgm.canBlockPlace()) { if (recData.getWhitelistMode()) { //white list --> blocks that are allowed to be placed if (recData.getWBBlocks().contains(event.getBlock().getType())) { - recData.addBlock(event.getBlockReplacedState(), mgPlayer); + if (mgm.getActivatePlayerRecorder()) { + recData.addBlock(event.getBlockReplacedState(), mgPlayer); + } + } else { + event.setCancelled(true); } //black list --> blocks that are not allowed to be placed - } else if (!recData.getWBBlocks().contains(event.getBlock().getType())) { + } else if (recData.getWBBlocks().contains(event.getBlock().getType())) { + event.setCancelled(true); + } else if (mgm.getActivatePlayerRecorder()) { recData.addBlock(event.getBlockReplacedState(), mgPlayer); } } else { @@ -141,7 +161,9 @@ private void blockPlace(BlockPlaceEvent event) { } } - //reset changed inventories + /** + * record inventories changed by players + */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) private void changeAnotherInventory(PlayerInteractEvent event) { MinigamePlayer mgPlayer = playerManager.getMinigamePlayer(event.getPlayer()); @@ -152,38 +174,15 @@ private void changeAnotherInventory(PlayerInteractEvent event) { Minigame mgm = mgPlayer.getMinigame(); RecorderData recData = mgm.getRecorderData(); - if (event.getClickedBlock().getState() instanceof InventoryHolder) { + if (event.getClickedBlock().getState() instanceof InventoryHolder && mgm.getActivatePlayerRecorder()) { recData.addBlock(event.getClickedBlock().getLocation().getBlock(), mgPlayer); } } } - //re-add drained liquid - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - private void bucketFill(PlayerBucketFillEvent event) { - MinigamePlayer mgPlayer = playerManager.getMinigamePlayer(event.getPlayer()); - - if (mgPlayer.isInMinigame()) { - Minigame mgm = mgPlayer.getMinigame(); - RecorderData recData = mgm.getRecorderData(); - - if (mgm.canBlockBreak()) { - if (recData.getWhitelistMode()) { - //white list --> blocks that are allowed to be broken - if (recData.getWBBlocks().contains(event.getBlock().getType())) { - recData.addBlock(event.getBlockClicked(), playerManager.getMinigamePlayer(event.getPlayer())); - } - //black list --> blocks that are not allowed to be broken - } else if (!recData.getWBBlocks().contains(event.getBlock().getType())) { - recData.addBlock(event.getBlockClicked(), playerManager.getMinigamePlayer(event.getPlayer())); - } - } else { - event.setCancelled(true); - } - } - } - - //remove lighted fire + /** + * record fire lighted by players + */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void igniteBlock(BlockIgniteEvent event) { if (event.getPlayer() != null) { @@ -197,11 +196,13 @@ public void igniteBlock(BlockIgniteEvent event) { if (mgm.canBlockPlace()) { if (recData.getWhitelistMode()) { //white list --> blocks that are allowed to be broken - if (recData.getWBBlocks().contains(event.getBlock().getType())) { + if (recData.getWBBlocks().contains(event.getBlock().getType()) + && mgm.getActivatePlayerRecorder()) { recData.addBlock(event.getBlock(), playerManager.getMinigamePlayer(event.getPlayer())); } //black list --> blocks that are not allowed to be broken - } else if (!recData.getWBBlocks().contains(event.getBlock().getType())) { + } else if (!recData.getWBBlocks().contains(event.getBlock().getType()) + && mgm.getActivatePlayerRecorder()) { recData.addBlock(event.getBlock(), playerManager.getMinigamePlayer(event.getPlayer())); } } else { @@ -211,7 +212,9 @@ public void igniteBlock(BlockIgniteEvent event) { } } - //remove placed hanging entities + /** + * record hanging entities like item frames placed by players + */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) private void hangingPlace(HangingPlaceEvent event) { if (event.getPlayer() != null) { @@ -233,15 +236,14 @@ private void hangingPlace(HangingPlaceEvent event) { usedMaterial = event.getItemStack().getType(); } - //todo we might want a flag parallel to BlockPlace/break for entities spawn / hurt if (recData.getWhitelistMode()) { //white list --> blocks that are allowed to be broken - if (recData.getWBBlocks().contains(usedMaterial)) { + if (recData.getWBBlocks().contains(usedMaterial) && mgm.getActivatePlayerRecorder()) { recData.addEntity(event.getEntity(), mgPlayer, true); return; } //black list --> blocks that are not allowed to be broken - } else if (!recData.getWBBlocks().contains(usedMaterial)) { + } else if (!recData.getWBBlocks().contains(usedMaterial) && mgm.getActivatePlayerRecorder()) { recData.addEntity(event.getEntity(), mgPlayer, true); return; } @@ -251,10 +253,12 @@ private void hangingPlace(HangingPlaceEvent event) { } } - //revive killed animals - //entities like monsters or armor stands are reset if restore regions is turned on. + /** + * record animals killed by players + * Note: entities like monsters or armor stands getting recorded only if regen regions are getting used + */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - private void animalHurt(EntityDamageByEntityEvent event) { //todo check for spawn to not revive animals spawned while the minigame was running. + private void animalHurt(EntityDamageByEntityEvent event) { if (event.getEntity() instanceof Animals animal) { //did the player kill the animal? if (animal.getHealth() <= event.getDamage()) { @@ -269,7 +273,7 @@ private void animalHurt(EntityDamageByEntityEvent event) { //todo check for spaw } if (mgPlayer != null) { - if (mgPlayer.isInMinigame()) { + if (mgPlayer.isInMinigame() && mgPlayer.getMinigame().getActivatePlayerRecorder()) { mgPlayer.getMinigame().getRecorderData().addEntity(animal, mgPlayer, false); } } @@ -277,7 +281,9 @@ private void animalHurt(EntityDamageByEntityEvent event) { //todo check for spaw } } - //revive hanging entities + /** + * record hanging entities getting removed by a player + */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) private void hangingBreak(HangingBreakByEntityEvent event) { MinigamePlayer mgPlayer = null; @@ -290,38 +296,71 @@ private void hangingBreak(HangingBreakByEntityEvent event) { } if (mgPlayer != null) { - if (mgPlayer.isInMinigame()) { + if (mgPlayer.isInMinigame() && mgPlayer.getMinigame().getActivatePlayerRecorder()) { mgPlayer.getMinigame().getRecorderData().addEntity(event.getEntity(), mgPlayer, false); } } } - //remove arrow entities + /** + * record arrows shot by players + */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) private void arrowShoot(EntityShootBowEvent event) { if (event.getEntity() instanceof Player player) { MinigamePlayer mgPlayer = playerManager.getMinigamePlayer(player); - if (mgPlayer.isInMinigame()) { + if (mgPlayer.isInMinigame() && mgPlayer.getMinigame().getActivatePlayerRecorder()) { mgPlayer.getMinigame().getRecorderData().addEntity(event.getProjectile(), mgPlayer, true); } } } - //remove ender perl entities (important if some where caught in bubble columns) + /** + * record ender perl entities (important if somewhere caught in bubble columns) + */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) private void throwEnderPearl(ProjectileLaunchEvent event) { if (event.getEntity().getShooter() instanceof Player player) { MinigamePlayer mgPlayer = playerManager.getMinigamePlayer(player); - if (mgPlayer.isInMinigame()) { + if (mgPlayer.isInMinigame() && mgPlayer.getMinigame().getActivatePlayerRecorder()) { mgPlayer.getMinigame().getRecorderData().addEntity(event.getEntity(), mgPlayer, true); } } } - //remove liquid source - //todo this doesn't handle changed blocks of flowing liquids, as well as new created water sources + /** + * record liquid drained by players via bucket fill + */ + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + private void bucketFill(PlayerBucketFillEvent event) { + MinigamePlayer mgPlayer = playerManager.getMinigamePlayer(event.getPlayer()); + + if (mgPlayer.isInMinigame()) { + Minigame mgm = mgPlayer.getMinigame(); + RecorderData recData = mgm.getRecorderData(); + + if (mgm.canBlockBreak()) { + if (recData.getWhitelistMode()) { + //white list --> blocks that are allowed to be broken + if (recData.getWBBlocks().contains(event.getBlock().getType()) && mgm.getActivatePlayerRecorder()) { + recData.addBlock(event.getBlockClicked(), playerManager.getMinigamePlayer(event.getPlayer())); + } + //black list --> blocks that are not allowed to be broken + } else if (!recData.getWBBlocks().contains(event.getBlock().getType()) + && mgm.getActivatePlayerRecorder()) { + recData.addBlock(event.getBlockClicked(), playerManager.getMinigamePlayer(event.getPlayer())); + } + } else { + event.setCancelled(true); + } + } + } + + /** + * record liquid placed by players via bukkit empty + */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) private void bucketEmpty(PlayerBucketEmptyEvent event) { MinigamePlayer mgPlayer = playerManager.getMinigamePlayer(event.getPlayer()); @@ -333,7 +372,7 @@ private void bucketEmpty(PlayerBucketEmptyEvent event) { if (mgm.canBlockPlace()) { if (recData.getWhitelistMode()) { //white list --> blocks that are allowed to be broken - if (recData.getWBBlocks().contains(event.getBlock().getType())) { + if (recData.getWBBlocks().contains(event.getBlock().getType()) && mgm.getActivatePlayerRecorder()) { Location loc = new Location(event.getBlockClicked().getWorld(), event.getBlockFace().getModX() + event.getBlockClicked().getX(), event.getBlockFace().getModY() + event.getBlockClicked().getY(), @@ -341,7 +380,8 @@ private void bucketEmpty(PlayerBucketEmptyEvent event) { recData.addBlock(loc.getBlock(), playerManager.getMinigamePlayer(event.getPlayer())); } //black list --> blocks that are not allowed to be broken - } else if (!recData.getWBBlocks().contains(event.getBlock().getType())) { + } else if (!recData.getWBBlocks().contains(event.getBlock().getType()) + && mgm.getActivatePlayerRecorder()) { Location loc = new Location(event.getBlockClicked().getWorld(), event.getBlockFace().getModX() + event.getBlockClicked().getX(), event.getBlockFace().getModY() + event.getBlockClicked().getY(), @@ -354,7 +394,9 @@ private void bucketEmpty(PlayerBucketEmptyEvent event) { } } - //revive vehicles + /** + * record vehicles broken by players + */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) private void vehicleDestroy(VehicleDestroyEvent event) { if (event.getAttacker() != null) { @@ -362,7 +404,7 @@ private void vehicleDestroy(VehicleDestroyEvent event) { MinigamePlayer mgPlayer = playerManager.getMinigamePlayer(player); Minigame mg = mgPlayer.getMinigame(); - if (mgPlayer.isInMinigame()) { + if (mgPlayer.isInMinigame() && mg.getActivatePlayerRecorder()) { mg.getRecorderData().addEntity(event.getVehicle(), mgPlayer, false); } } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/EntityData.java b/Minigames/src/main/java/au/com/mineauz/minigames/recorder/EntityData.java similarity index 51% rename from Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/EntityData.java rename to Minigames/src/main/java/au/com/mineauz/minigames/recorder/EntityData.java index 32b5615d3..b4ce580ab 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/EntityData.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/recorder/EntityData.java @@ -1,14 +1,19 @@ -package au.com.mineauz.minigames.blockRecorder; +package au.com.mineauz.minigames.recorder; import au.com.mineauz.minigames.objects.MinigamePlayer; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; import java.util.UUID; +/** + * This class encodes the data of an entity had. + * Therefore, it stores the data in case the entity dies or gets changed doing a minigame + */ public class EntityData { //uuid of the entity private final UUID uuid; @@ -21,8 +26,15 @@ public class EntityData { // was this entity created and needs to removed or was it changed / killed? private final boolean created; - //todo save metadata like armor - public EntityData(Entity entity, @Nullable MinigamePlayer modifier, boolean created) { + /** + * @param entity the entity to store data of + * @param modifier the player who was the first one to change this entity, + * might be null in case there was no player, or the minigame will be reset at the end, + * regardless if players are joining / leaving it + * @param created if the entity was created and therefor has to be killed to reset the minigame + * or if it was changed / killed + */ + public EntityData(@NotNull Entity entity, @Nullable MinigamePlayer modifier, boolean created) { this.uuid = entity.getUniqueId(); this.entType = entity.getType(); this.entLocation = entity.getLocation(); @@ -30,10 +42,20 @@ public EntityData(Entity entity, @Nullable MinigamePlayer modifier, boolean crea this.created = created; } + /** + * get the entity on the server, + * might be null if the entity was killed + */ public @Nullable Entity getEntity() { return Bukkit.getEntity(uuid); } + /** + * get the player who first changed the entity, + * might be null if it wasn't a player, + * or the minigame will be reset at the end, + * regardless if players are joining / leaving it + */ public @Nullable MinigamePlayer getModifier() { return player; } @@ -42,10 +64,16 @@ public boolean wasCreated() { return created; } + /** + * get the EntityType the entity had when it was recorded + */ public EntityType getEntityType() { return entType; } + /** + * get the location the entity had when it was recorded + */ public Location getEntityLocation() { return entLocation; } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/MgBlockData.java b/Minigames/src/main/java/au/com/mineauz/minigames/recorder/MgBlockData.java similarity index 92% rename from Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/MgBlockData.java rename to Minigames/src/main/java/au/com/mineauz/minigames/recorder/MgBlockData.java index aced3402e..5e28e81b4 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/MgBlockData.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/recorder/MgBlockData.java @@ -1,4 +1,4 @@ -package au.com.mineauz.minigames.blockRecorder; +package au.com.mineauz.minigames.recorder; import au.com.mineauz.minigames.Minigames; import au.com.mineauz.minigames.objects.MinigamePlayer; @@ -50,14 +50,22 @@ public MgBlockData(@NotNull Block original, @Nullable MinigamePlayer modifier) { location = original.getLocation(); state = original.getState(); blockData = original.getBlockData().getAsString(); - if (modifier != null) playerUUID = modifier.getUUID(); + if (modifier != null) { + playerUUID = modifier.getUUID(); + } else { + playerUUID = null; + } } public MgBlockData(@NotNull BlockState original, @Nullable MinigamePlayer modifier) { location = original.getLocation(); state = original; blockData = state.getBlockData().getAsString(); - if (modifier != null) playerUUID = modifier.getUUID(); + if (modifier != null) { + playerUUID = modifier.getUUID(); + } else { + playerUUID = null; + } } public @NotNull Location getLocation() { @@ -69,7 +77,11 @@ public MgBlockData(@NotNull BlockState original, @Nullable MinigamePlayer modifi } public @Nullable MinigamePlayer getModifier() { - return Minigames.getPlugin().getPlayerManager().getMinigamePlayer(playerUUID); + if (playerUUID == null) { + return null; + } else { + return Minigames.getPlugin().getPlayerManager().getMinigamePlayer(playerUUID); + } } public void setModifier(@Nullable MinigamePlayer modifier) { diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RecorderData.java b/Minigames/src/main/java/au/com/mineauz/minigames/recorder/RecorderData.java similarity index 97% rename from Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RecorderData.java rename to Minigames/src/main/java/au/com/mineauz/minigames/recorder/RecorderData.java index 33fb218d6..a19259593 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RecorderData.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/recorder/RecorderData.java @@ -1,4 +1,4 @@ -package au.com.mineauz.minigames.blockRecorder; +package au.com.mineauz.minigames.recorder; import au.com.mineauz.minigames.Minigames; import au.com.mineauz.minigames.menu.Callback; @@ -146,12 +146,12 @@ public Minigame getMinigame() { return minigame; } - public MgBlockData addBlock(Block block, MinigamePlayer modifier) { - BlockStateSnapshotResult blockstate = PaperLib.getBlockState(block, true); - return addBlock(blockstate.getState(), modifier); + public MgBlockData addBlock(@NotNull Block block, @Nullable MinigamePlayer modifier) { + BlockStateSnapshotResult blockState = PaperLib.getBlockState(block, true); + return addBlock(blockState.getState(), modifier); } - public MgBlockData addBlock(BlockState block, MinigamePlayer modifier) { + public MgBlockData addBlock(@NotNull BlockState block, @Nullable MinigamePlayer modifier) { MgBlockData bdata = new MgBlockData(block, modifier); Position pos = Position.block(block.getLocation()); @@ -241,7 +241,7 @@ public void restoreEntities() { entityData.clear(); } - public void restoreBlocks(final MinigamePlayer modifier) { + public void restoreBlocks(final @Nullable MinigamePlayer modifier) { // When rolling back a single player's changes don't change the overall games state if (modifier == null) { minigame.setState(MinigameState.REGENERATING); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RegenRecorder.java b/Minigames/src/main/java/au/com/mineauz/minigames/recorder/RegenRecorder.java similarity index 99% rename from Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RegenRecorder.java rename to Minigames/src/main/java/au/com/mineauz/minigames/recorder/RegenRecorder.java index eb7cc53f6..6618f7e4c 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RegenRecorder.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/recorder/RegenRecorder.java @@ -1,4 +1,4 @@ -package au.com.mineauz.minigames.blockRecorder; +package au.com.mineauz.minigames.recorder; import au.com.mineauz.minigames.Minigames; import au.com.mineauz.minigames.minigame.Minigame; diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RollbackScheduler.java b/Minigames/src/main/java/au/com/mineauz/minigames/recorder/RollbackScheduler.java similarity index 97% rename from Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RollbackScheduler.java rename to Minigames/src/main/java/au/com/mineauz/minigames/recorder/RollbackScheduler.java index 260f3a26f..f0d1093cf 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RollbackScheduler.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/recorder/RollbackScheduler.java @@ -1,4 +1,4 @@ -package au.com.mineauz.minigames.blockRecorder; +package au.com.mineauz.minigames.recorder; import au.com.mineauz.minigames.Minigames; import au.com.mineauz.minigames.minigame.Minigame; diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/recorder/package-info.java b/Minigames/src/main/java/au/com/mineauz/minigames/recorder/package-info.java new file mode 100644 index 000000000..619166eb9 --- /dev/null +++ b/Minigames/src/main/java/au/com/mineauz/minigames/recorder/package-info.java @@ -0,0 +1,4 @@ +/** + * recorder is the system for recording block / entity changes in a game and rolling them back afterward. + */ +package au.com.mineauz.minigames.recorder; \ No newline at end of file diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/signs/SignBase.java b/Minigames/src/main/java/au/com/mineauz/minigames/signs/SignBase.java index eaf681fa1..69206136a 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/signs/SignBase.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/signs/SignBase.java @@ -2,7 +2,12 @@ import au.com.mineauz.minigames.MinigameMessageType; import au.com.mineauz.minigames.Minigames; +import au.com.mineauz.minigames.events.TakeFlagEvent; +import au.com.mineauz.minigames.managers.MessageManager; +import au.com.mineauz.minigames.minigame.MinigameState; +import au.com.mineauz.minigames.objects.CTFFlag; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.Tag; import org.bukkit.block.Block; import org.bukkit.block.Sign; @@ -14,12 +19,15 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; public class SignBase implements Listener { private static final Map minigameSigns = new HashMap<>(); + private final HashSet takenFlags = new HashSet<>(); static { registerMinigameSign(new FinishSign()); @@ -45,6 +53,13 @@ public static void registerMinigameSign(MinigameSign mgSign) { minigameSigns.put(mgSign.getName().toLowerCase(), mgSign); } + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + private void takeFlag(@NotNull TakeFlagEvent event) { + if (event.getFlag().getAttachedToLocation() != null) { + this.takenFlags.add(event.getFlag()); + } + } + @EventHandler private void signPlace(SignChangeEvent event) { String[] signinfo = new String[4]; @@ -120,6 +135,27 @@ private void signBreak(BlockBreakEvent event) { } mgSign.signBreak(sign, Minigames.getPlugin().getPlayerManager().getMinigamePlayer(event.getPlayer())); } + } else { + Location blockLocation = event.getBlock().getLocation().toBlockLocation(); + + for (CTFFlag ctfFlag : takenFlags) { + if (ctfFlag.getAttachedToLocation().equals(blockLocation)) { + MinigameSign mgSign = minigameSigns.get("Flag"); + + if (mgSign.getCreatePermission() != null && !event.getPlayer().hasPermission(mgSign.getCreatePermission())) { + event.setCancelled(true); + return; + } else { + MessageManager.sendMessage(Minigames.getPlugin().getPlayerManager().getMinigamePlayer(event.getPlayer()), + MinigameMessageType.WARN, null, "sign.flag.broken.support"); + takenFlags.remove(ctfFlag); + } + + break; + } else if (ctfFlag.getMinigame().getState() != MinigameState.STARTED) { + takenFlags.remove(ctfFlag); + } + } } } } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/tool/DegenAreaMode.java b/Minigames/src/main/java/au/com/mineauz/minigames/tool/DegenAreaMode.java index d708a0df2..967ab0c99 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/tool/DegenAreaMode.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/tool/DegenAreaMode.java @@ -12,6 +12,8 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; +import java.util.List; + public class DegenAreaMode implements ToolMode { @Override @@ -25,8 +27,8 @@ public String getDisplayName() { } @Override - public String getDescription() { - return "Selects the degeneration;area with right click;finalise with left"; + public List getDescription() { + return List.of("Selects the degeneration", "area with right click", "finalise with left"); } @Override diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/tool/EndPositionMode.java b/Minigames/src/main/java/au/com/mineauz/minigames/tool/EndPositionMode.java index 845b5e0af..7dbdaadae 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/tool/EndPositionMode.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/tool/EndPositionMode.java @@ -9,6 +9,8 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; +import java.util.List; + public class EndPositionMode implements ToolMode { @Override @@ -22,8 +24,8 @@ public String getDisplayName() { } @Override - public String getDescription() { - return "Sets the end;position"; + public List getDescription() { + return List.of("Sets the end", "position"); } @Override @@ -40,7 +42,7 @@ public void onLeftClick(MinigamePlayer player, Minigame minigame, @Override public void onRightClick(MinigamePlayer player, Minigame minigame, Team team, PlayerInteractEvent event) { - minigame.setEndPosition(player.getLocation()); + minigame.setEndLocation(player.getLocation()); player.sendInfoMessage("Set end position."); } @@ -56,8 +58,8 @@ public void onEntityRightClick(MinigamePlayer player, Minigame minigame, Team te @Override public void select(MinigamePlayer player, Minigame minigame, Team team) { - if (minigame.getEndPosition() != null) { - player.getPlayer().sendBlockChange(minigame.getEndPosition(), + if (minigame.getEndLocation() != null) { + player.getPlayer().sendBlockChange(minigame.getEndLocation(), Material.SKELETON_SKULL.createBlockData()); player.sendInfoMessage("Selected end position (marked with skull)"); } else { @@ -67,9 +69,9 @@ public void select(MinigamePlayer player, Minigame minigame, Team team) { @Override public void deselect(MinigamePlayer player, Minigame minigame, Team team) { - if (minigame.getEndPosition() != null) { - player.getPlayer().sendBlockChange(minigame.getEndPosition(), - minigame.getEndPosition().getBlock().getBlockData()); + if (minigame.getEndLocation() != null) { + player.getPlayer().sendBlockChange(minigame.getEndLocation(), + minigame.getEndLocation().getBlock().getBlockData()); player.sendInfoMessage("Deselected end position"); } else { player.sendMessage("No end position set!", MinigameMessageType.ERROR); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/tool/LobbyPositionMode.java b/Minigames/src/main/java/au/com/mineauz/minigames/tool/LobbyPositionMode.java index f2e38ab95..f29cb55f6 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/tool/LobbyPositionMode.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/tool/LobbyPositionMode.java @@ -9,6 +9,8 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; +import java.util.List; + public class LobbyPositionMode implements ToolMode { @Override @@ -22,8 +24,8 @@ public String getDisplayName() { } @Override - public String getDescription() { - return "Sets the lobby;position"; + public List getDescription() { + return List.of("Sets the lobby", "position"); } @Override @@ -40,7 +42,7 @@ public void onLeftClick(MinigamePlayer player, Minigame minigame, @Override public void onRightClick(MinigamePlayer player, Minigame minigame, Team team, PlayerInteractEvent event) { - minigame.setLobbyPosition(player.getLocation()); + minigame.setLobbyLocation(player.getLocation()); player.sendInfoMessage("Set lobby position."); } @@ -56,8 +58,8 @@ public void onEntityRightClick(MinigamePlayer player, Minigame minigame, Team te @Override public void select(MinigamePlayer player, Minigame minigame, Team team) { - if (minigame.getLobbyPosition() != null) { - player.getPlayer().sendBlockChange(minigame.getLobbyPosition(), Material.SKELETON_SKULL.createBlockData()); + if (minigame.getLobbyLocation() != null) { + player.getPlayer().sendBlockChange(minigame.getLobbyLocation(), Material.SKELETON_SKULL.createBlockData()); player.sendInfoMessage("Selected lobby position (marked with skull)"); } else { player.sendMessage("No lobby position set!", MinigameMessageType.ERROR); @@ -66,9 +68,9 @@ public void select(MinigamePlayer player, Minigame minigame, Team team) { @Override public void deselect(MinigamePlayer player, Minigame minigame, Team team) { - if (minigame.getLobbyPosition() != null) { - player.getPlayer().sendBlockChange(minigame.getLobbyPosition(), - minigame.getLobbyPosition().getBlock().getBlockData()); + if (minigame.getLobbyLocation() != null) { + player.getPlayer().sendBlockChange(minigame.getLobbyLocation(), + minigame.getLobbyLocation().getBlock().getBlockData()); player.sendInfoMessage("Deselected lobby position"); } else { player.sendMessage("No lobby position set!", MinigameMessageType.ERROR); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/tool/MinigameTool.java b/Minigames/src/main/java/au/com/mineauz/minigames/tool/MinigameTool.java index cb41fe60e..58571807c 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/tool/MinigameTool.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/tool/MinigameTool.java @@ -172,8 +172,8 @@ public void setValue(String value) { } }, teams), men.getSize() - 3); - for (ToolMode m : ToolModes.getToolModes()) { - men.addItem(new MenuItemToolMode(m.getDisplayName(), List.of(m.getDescription()), m.getIcon(), m)); + for (ToolMode toolMode : ToolModes.getToolModes()) { + men.addItem(new MenuItemToolMode(toolMode.getDisplayName(), toolMode.getDescription(), toolMode.getIcon(), toolMode)); } men.displayMenu(player); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/tool/QuitPositionMode.java b/Minigames/src/main/java/au/com/mineauz/minigames/tool/QuitPositionMode.java index 8a2eb585f..e86d20a05 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/tool/QuitPositionMode.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/tool/QuitPositionMode.java @@ -9,6 +9,8 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; +import java.util.List; + public class QuitPositionMode implements ToolMode { @Override @@ -22,8 +24,8 @@ public String getDisplayName() { } @Override - public String getDescription() { - return "Sets the quit;position"; + public List getDescription() { + return List.of("Sets the quit", "position"); } @Override @@ -40,7 +42,7 @@ public void onLeftClick(MinigamePlayer player, Minigame minigame, @Override public void onRightClick(MinigamePlayer player, Minigame minigame, Team team, PlayerInteractEvent event) { - minigame.setQuitPosition(player.getLocation()); + minigame.setQuitLocation(player.getLocation()); player.sendInfoMessage("Set quit position."); } @@ -56,8 +58,8 @@ public void onEntityRightClick(MinigamePlayer player, Minigame minigame, Team te @Override public void select(MinigamePlayer player, Minigame minigame, Team team) { - if (minigame.getQuitPosition() != null) { - player.getPlayer().sendBlockChange(minigame.getQuitPosition(), Material.SKELETON_SKULL.createBlockData()); + if (minigame.getQuitLocation() != null) { + player.getPlayer().sendBlockChange(minigame.getQuitLocation(), Material.SKELETON_SKULL.createBlockData()); player.sendInfoMessage("Selected quit position (marked with skull)"); } else { player.sendMessage("No quit position set!", MinigameMessageType.ERROR); @@ -66,9 +68,9 @@ public void select(MinigamePlayer player, Minigame minigame, Team team) { @Override public void deselect(MinigamePlayer player, Minigame minigame, Team team) { - if (minigame.getQuitPosition() != null) { - player.getPlayer().sendBlockChange(minigame.getQuitPosition(), - minigame.getQuitPosition().getBlock().getBlockData()); + if (minigame.getQuitLocation() != null) { + player.getPlayer().sendBlockChange(minigame.getQuitLocation(), + minigame.getQuitLocation().getBlock().getBlockData()); player.sendInfoMessage("Deselected quit position"); } else { player.sendMessage("No quit position set!", MinigameMessageType.ERROR); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/tool/RegenAreaMode.java b/Minigames/src/main/java/au/com/mineauz/minigames/tool/RegenAreaMode.java index 5f7be1457..34608b3a7 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/tool/RegenAreaMode.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/tool/RegenAreaMode.java @@ -37,8 +37,8 @@ public String getDisplayName() { } @Override - public String getDescription() { - return "Selects an area;for a regen region.;Create via left click"; + public List getDescription() { + return List.of("Selects an area", "for a regen region.", "Create via left click"); } @Override diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/tool/SpectatorPositionMode.java b/Minigames/src/main/java/au/com/mineauz/minigames/tool/SpectatorPositionMode.java index a0b1c1fb8..77386a514 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/tool/SpectatorPositionMode.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/tool/SpectatorPositionMode.java @@ -9,6 +9,8 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; +import java.util.List; + public class SpectatorPositionMode implements ToolMode { @Override @@ -22,8 +24,8 @@ public String getDisplayName() { } @Override - public String getDescription() { - return "Sets the spectator;join position"; + public List getDescription() { + return List.of("Sets the spectator", "join position"); } @Override diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/tool/StartPositionMode.java b/Minigames/src/main/java/au/com/mineauz/minigames/tool/StartPositionMode.java index 09e2457d3..1bff95f82 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/tool/StartPositionMode.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/tool/StartPositionMode.java @@ -12,6 +12,8 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; +import java.util.List; + public class StartPositionMode implements ToolMode { @Override @@ -25,8 +27,8 @@ public String getDisplayName() { } @Override - public String getDescription() { - return "Sets the starting;positions for a team;or player"; + public List getDescription() { + return List.of("Sets the starting", "positions for a team", "or player"); } @Override diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/tool/ToolMode.java b/Minigames/src/main/java/au/com/mineauz/minigames/tool/ToolMode.java index 30ce5b249..742f03e8d 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/tool/ToolMode.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/tool/ToolMode.java @@ -8,13 +8,19 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; +import java.util.List; + public interface ToolMode { String getName(); String getDisplayName(); - String getDescription(); + /** + * Returns the description of the tool mode with lines separated into list elements, + * so it is compatible with lore of a (menu) item + */ + List getDescription(); Material getIcon(); diff --git a/Minigames/src/main/resources/config.yml b/Minigames/src/main/resources/config.yml index d049fb9a4..006d0a290 100644 --- a/Minigames/src/main/resources/config.yml +++ b/Minigames/src/main/resources/config.yml @@ -40,9 +40,6 @@ playSounds: true regeneration: maxDelay: 10 - -updateChecker: false -# Whether the plugin should check for updates lang: 'en_AU' # Select language diff --git a/Minigames/src/main/resources/messages.properties b/Minigames/src/main/resources/messages.properties index e70a2e368..7a639ed38 100644 --- a/Minigames/src/main/resources/messages.properties +++ b/Minigames/src/main/resources/messages.properties @@ -67,7 +67,7 @@ minigame.error.noGametype=That gametype does not exist! minigame.error.noStart=This Minigame has no start position! minigame.error.noQuit=This Minigame has no quit position! minigame.error.noEnd=This Minigame has no end position! -minigame.error.noLobby=This Minigame has no lobby position! +minigame.error.noLobby=This Minigame has no lobby (multiplayer) / starting (singleplayer) position! minigame.error.incorrectStart=Starting positions are incorrectly configured! minigame.error.notEnabled=This Minigame is currently not enabled. minigame.error.noMinigame=This Minigame does not exist! @@ -191,6 +191,7 @@ sign.score.alreadyUsed=You have already used this score sign! sign.score.alreadyUsedTeam=Your team has already used this score sign! sign.score.addScore=Added %s to your score. New Score: %s sign.score.addScoreTeam=Added %s to your teams score. New Score: %s +sign.flag.broken.support=You broke the support block of a flag! It won't be able to respawn! team.add=Enter the color of the team you wish to add. All colors available below: team.alreadyUsedColor=A team already exists using that color! team.invalidColor=There is no team color by the name of %s @@ -268,3 +269,4 @@ command.info.output.teamData=%s Score: %s Color: %s command.treasures.setMaxHeight.set=Maximum height variance for %s has been set to %s command.treasures.setMaxHeight.noPerm=You don't have permission to modify the treasures spawn height! command.treasures.setMaxHeight.desc=Sets the maximum Y height from the start location for a treasure chest to pick its random, however, if there are blocks in the way, it can still move above this height. (Default: 20) +minigame.resource.command.description="" diff --git a/Minigames/src/main/resources/messages_en_AU.properties b/Minigames/src/main/resources/messages_en_AU.properties index 7a06bf109..9ff68547a 100644 --- a/Minigames/src/main/resources/messages_en_AU.properties +++ b/Minigames/src/main/resources/messages_en_AU.properties @@ -84,7 +84,7 @@ minigame.error.noGametype=That gametype does not exist! minigame.error.noStart=This Minigame has no start position! minigame.error.noQuit=This Minigame has no quit position! minigame.error.noEnd=This Minigame has no end position! -minigame.error.noLobby=This Minigame has no lobby position! +minigame.error.noLobby=This Minigame has no lobby (multiplayer) / starting (singleplayer) position! minigame.error.incorrectStart=Starting positions are incorrectly configured! minigame.error.notEnabled=This Minigame is currently not enabled. minigame.error.noMinigame=This Minigame does not exist! @@ -328,4 +328,5 @@ command.enable.noPerm=You don't have permission to enable all Minigames! command.treasures.setMaxHeight.set=Maximum height variance for %s has been set to %s command.treasures.setMaxHeight.noPerm=You don't have permission to modify the treasures spawn height! command.treasures.setMaxHeight.desc=Sets the maximum Y height from the start location for a treasure chest to pick its random, however, if there are blocks in the way, it can still move above this height. (Default: 20) -minigame.resourcepack.command.invalidpack=The information could not be used to create a pack \ No newline at end of file +minigame.resourcepack.command.invalidpack=The information could not be used to create a pack +minigame.resource.command.description="" \ No newline at end of file diff --git a/Minigames/src/main/resources/messages_en_US.properties b/Minigames/src/main/resources/messages_en_US.properties index 44051823e..e941f82ec 100644 --- a/Minigames/src/main/resources/messages_en_US.properties +++ b/Minigames/src/main/resources/messages_en_US.properties @@ -69,7 +69,7 @@ minigame.error.noGametype=That gametype does not exist! minigame.error.noStart=This Minigame has no start position! minigame.error.noQuit=This Minigame has no quit position! minigame.error.noEnd=This Minigame has no end position! -minigame.error.noLobby=This Minigame has no lobby position! +minigame.error.noLobby=This Minigame has no lobby (multiplayer) / starting (singleplayer) position! minigame.error.incorrectStart=Starting positions are incorrectly configured! minigame.error.notEnabled=This Minigame is currently not enabled. minigame.error.noMinigame=This Minigame does not exist! diff --git a/Minigames/src/main/resources/plugin.yml b/Minigames/src/main/resources/plugin.yml index 87039add6..0be5d68dd 100644 --- a/Minigames/src/main/resources/plugin.yml +++ b/Minigames/src/main/resources/plugin.yml @@ -2,7 +2,7 @@ name: Minigames main: au.com.mineauz.minigames.Minigames version: ${plugin.version} api-version: "${spigot.api.version}" -author: _Razz_ Schmoller Addstar Narimm +author: _Razz_ Schmoller Addstar Narimm GreenSurvivors softdepend: [ 'Multiverse-Core' ] description: ${project.description} diff --git a/Minigames/src/main/resources/resourcepack/emptyResourcePack.zip b/Minigames/src/main/resources/resourcepack/emptyResourcePack.zip index d2228f301..438ff1543 100644 Binary files a/Minigames/src/main/resources/resourcepack/emptyResourcePack.zip and b/Minigames/src/main/resources/resourcepack/emptyResourcePack.zip differ diff --git a/Minigames/src/main/resources/resourcepack/pack.mcmeta b/Minigames/src/main/resources/resourcepack/pack.mcmeta index 03670c075..2adebcc89 100644 --- a/Minigames/src/main/resources/resourcepack/pack.mcmeta +++ b/Minigames/src/main/resources/resourcepack/pack.mcmeta @@ -1,6 +1,6 @@ { "pack": { - "pack_format": 4, + "pack_format": 18, "description": "Minigames Empty Resource Pack" } } \ No newline at end of file diff --git a/Minigames/src/test/java/au/com/mineauz/minigames/MinigamesTest.java b/Minigames/src/test/java/au/com/mineauz/minigames/MinigamesTest.java index eac1252ad..32f26bbe5 100644 --- a/Minigames/src/test/java/au/com/mineauz/minigames/MinigamesTest.java +++ b/Minigames/src/test/java/au/com/mineauz/minigames/MinigamesTest.java @@ -64,7 +64,7 @@ public void Setup() { @Test public void onJoinMinigame() { - Assertions.assertNotSame(player.getLocation(), game.getLobbyPosition()); + Assertions.assertNotSame(player.getLocation(), game.getLobbyLocation()); plugin.getPlayerManager().addMinigamePlayer(player); MinigamePlayer mplayer = plugin.getPlayerManager().getMinigamePlayer(player.getUniqueId()); plugin.getPlayerManager().joinMinigame(mplayer, game, false, 0.0); diff --git a/Minigames/src/test/java/au/com/mineauz/minigames/helpers/TestHelper.java b/Minigames/src/test/java/au/com/mineauz/minigames/helpers/TestHelper.java index 4ffa2058d..1c5335244 100644 --- a/Minigames/src/test/java/au/com/mineauz/minigames/helpers/TestHelper.java +++ b/Minigames/src/test/java/au/com/mineauz/minigames/helpers/TestHelper.java @@ -31,11 +31,11 @@ public static Minigame createMinigame(Minigames plugin, WorldMock world, Minigam game.setMechanic(mechanic.toString()); game.setDeathDrops(true); Location quit = new Location(world, 0, 20, 0); - game.setQuitPosition(quit); + game.setQuitLocation(quit); Location lobby = new Location(world, 0, 5., 0); - game.setLobbyPosition(lobby); + game.setLobbyLocation(lobby); Location end = new Location(world, 0, 25, 0); - game.setEndPosition(end); + game.setEndLocation(end); game.setEnabled(true); game.setStartWaitTime(5); game.setTimer(5); diff --git a/Minigames/src/test/java/au/com/mineauz/minigames/objects/TestMinigame.java b/Minigames/src/test/java/au/com/mineauz/minigames/objects/TestMinigame.java index d8d86d03b..e280edd4d 100644 --- a/Minigames/src/test/java/au/com/mineauz/minigames/objects/TestMinigame.java +++ b/Minigames/src/test/java/au/com/mineauz/minigames/objects/TestMinigame.java @@ -19,9 +19,9 @@ public TestMinigame(String name, MinigameType type, Location start, World world, setType(MinigameType.MULTIPLAYER); setMechanic(GameMechanics.MECHANIC_NAME.CTF.toString()); setDeathDrops(true); - setQuitPosition(quit); - setLobbyPosition(lobby); - setEndPosition(end); + setQuitLocation(quit); + setLobbyLocation(lobby); + setEndLocation(end); setEnabled(true); setStartWaitTime(5); setTimer(5); diff --git a/Regions/pom.xml b/Regions/pom.xml index abd93cfca..5bc3638e4 100644 --- a/Regions/pom.xml +++ b/Regions/pom.xml @@ -38,7 +38,7 @@ org.apache.maven.plugins maven-source-plugin - 3.2.1 + 3.3.0 attach-sources @@ -63,7 +63,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.2.0 + 3.3.0 diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/NodeToolMode.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/NodeToolMode.java index d62b7a1ec..f93e0d480 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/NodeToolMode.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/NodeToolMode.java @@ -30,8 +30,8 @@ public String getDisplayName() { } @Override - public String getDescription() { - return "Creates a node where;you are standing;on right click"; + public List getDescription() { + return List.of("Creates a node where", "you are standing", "on right click"); } @Override diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionDisplayManager.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionDisplayManager.java index 77b4b3474..bd094eab9 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionDisplayManager.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionDisplayManager.java @@ -50,7 +50,7 @@ private void showInfo(Region region, MinigamePlayer player) { "Region: " + ChatColor.WHITE + region.getName() + - "Enabled: " + region.getEnabled(); + " Enabled: " + region.getEnabled(); stand.setCustomName(info); } diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionEvents.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionEvents.java index c7b827911..e2fd26ea0 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionEvents.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionEvents.java @@ -202,26 +202,44 @@ private void playerQuit(QuitMinigameEvent event) { } @EventHandler(ignoreCancelled = true) - private void playersEnd(EndMinigameEvent event) { + private void playersEndPhase(EndPhaseMinigameEvent event) { if (RegionModule.getMinigameModule(event.getMinigame()) == null) { Minigames.debugMessage(event.getMinigame() + " called region event with no RegionModule loaded... was this intended?"); return; } + for (MinigamePlayer ply : event.getWinners()) { Minigame mg = ply.getMinigame(); + for (Region r : RegionModule.getMinigameModule(mg).getRegions()) { - if (r.hasPlayer(ply)) + if (r.hasPlayer(ply)) { r.removePlayer(ply); + } } } + for (Node node : RegionModule.getMinigameModule(event.getMinigame()).getNodes()) { - node.execute(Triggers.getTrigger("GAME_END"), null); - for (NodeExecutor exec : node.getExecutors()) + node.execute(Triggers.getTrigger("GAME_ENDPHASE"), null); + } + } + + @EventHandler(ignoreCancelled = true) + private void playersEnded(EndedMinigameEvent event) { + if (RegionModule.getMinigameModule(event.getMinigame()) == null) { + Minigames.debugMessage(event.getMinigame() + " called region event with no RegionModule loaded... was this intended?"); + return; + } + for (Node node : RegionModule.getMinigameModule(event.getMinigame()).getNodes()) { + node.execute(Triggers.getTrigger("GAME_ENDED"), null); + + for (NodeExecutor exec : node.getExecutors()) { exec.clearTriggers(); + } } for (Region region : RegionModule.getMinigameModule(event.getMinigame()).getRegions()) { - for (RegionExecutor exec : region.getExecutors()) + for (RegionExecutor exec : region.getExecutors()) { exec.clearTriggers(); + } } } diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionModule.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionModule.java index 48431a8bf..59b5d0561 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionModule.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionModule.java @@ -26,7 +26,6 @@ import java.util.*; public class RegionModule extends MinigameModule { - private final Map regions = new HashMap<>(); private final Map nodes = new HashMap<>(); diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionNodeEditToolMode.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionNodeEditToolMode.java index 98340bdad..d2a393e1d 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionNodeEditToolMode.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionNodeEditToolMode.java @@ -20,6 +20,7 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.util.Vector; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -37,8 +38,8 @@ public String getDisplayName() { } @Override - public String getDescription() { - return "Allows you to simply;edit regions and nodes;with right click"; + public List getDescription() { + return List.of("Allows you to simply", "edit regions and nodes", "with right click"); } @Override diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionToolMode.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionToolMode.java index 778d35f2d..1a3c7de27 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionToolMode.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionToolMode.java @@ -30,8 +30,8 @@ public String getDisplayName() { } @Override - public String getDescription() { - return "Selects an area;for a region.;Create via left click"; + public List getDescription() { + return List.of("Selects an area", "for a region.", "Create via left click"); } @Override diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/MemorySwapBlockAction.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/MemorySwapBlockAction.java index fd8ec805d..36c609e29 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/MemorySwapBlockAction.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/MemorySwapBlockAction.java @@ -1,12 +1,12 @@ package au.com.mineauz.minigamesregions.actions; import au.com.mineauz.minigames.MinigameMessageType; -import au.com.mineauz.minigames.blockRecorder.RecorderData; import au.com.mineauz.minigames.config.BooleanFlag; import au.com.mineauz.minigames.config.MaterialFlag; import au.com.mineauz.minigames.config.MaterialListFlag; import au.com.mineauz.minigames.menu.*; import au.com.mineauz.minigames.objects.MinigamePlayer; +import au.com.mineauz.minigames.recorder.RecorderData; import au.com.mineauz.minigamesregions.Node; import au.com.mineauz.minigamesregions.Region; import org.bukkit.Material; @@ -93,9 +93,9 @@ public class MemorySwapBlockAction extends AbstractAction { blockPool.add(Material.STRIPPED_JUNGLE_LOG); blockPool.add(Material.ACACIA_LOG); blockPool.add(Material.STRIPPED_ACACIA_LOG); - blockPool.add(Material.DARK_OAK_LOG); blockPool.add(Material.MANGROVE_LOG); blockPool.add(Material.STRIPPED_MANGROVE_LOG); + blockPool.add(Material.DARK_OAK_LOG); blockPool.add(Material.STRIPPED_DARK_OAK_LOG); blockPool.add(Material.CRIMSON_STEM); blockPool.add(Material.STRIPPED_CRIMSON_STEM); @@ -154,7 +154,6 @@ public class MemorySwapBlockAction extends AbstractAction { //kinda living blockPool.add(Material.SCULK); - blockPool.add(Material.SCULK_CATALYST); blockPool.add(Material.BONE_BLOCK); blockPool.add(Material.NETHER_WART_BLOCK); blockPool.add(Material.WARPED_WART_BLOCK); @@ -212,7 +211,6 @@ private ArrayList cleanUpBlockPool() { return output; } - @Override public String getName() { return "MEMORY_SWAP_BLOCK"; @@ -231,7 +229,6 @@ public void describe(Map out) { out.put("White/Blacklist", wbList.getFlag()); } - @Override public boolean useInRegions() { return true; @@ -322,7 +319,6 @@ public void executeNodeAction(MinigamePlayer player, debug(player, node); } - @Override public void saveArguments(FileConfiguration config, String path) { matchType.saveValue(path, config); diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/PulseRedstoneAction.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/PulseRedstoneAction.java index d98ad0953..a6ae3954d 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/PulseRedstoneAction.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/PulseRedstoneAction.java @@ -60,15 +60,20 @@ public void executeRegionAction(MinigamePlayer player, public void executeNodeAction(MinigamePlayer player, Node node) { debug(player, node); - BlockData bdata = Material.REDSTONE_BLOCK.createBlockData(); + BlockData bdata; if (torch.getFlag()) { bdata = Material.REDSTONE_TORCH.createBlockData(); - if (bdata instanceof Lightable) - ((Lightable) bdata).setLit(true); + + if (bdata instanceof Lightable lightable) { + lightable.setLit(true); + } + } else { + bdata = Material.REDSTONE_BLOCK.createBlockData(); } final BlockState last = node.getLocation().getBlock().getState(); node.getLocation().getBlock().setBlockData(bdata); - Bukkit.getScheduler().scheduleSyncDelayedTask(Minigames.getPlugin(), () -> last.update(true), 20L * time.getFlag()); + Bukkit.getScheduler().scheduleSyncDelayedTask(Minigames.getPlugin(), () -> + last.update(true), 20L * time.getFlag()); } @Override diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/RandomFillingAction.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/RandomFillingAction.java index 23c1dc62c..fd7115af6 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/RandomFillingAction.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/RandomFillingAction.java @@ -1,12 +1,12 @@ package au.com.mineauz.minigamesregions.actions; import au.com.mineauz.minigames.MinigameMessageType; -import au.com.mineauz.minigames.blockRecorder.RecorderData; import au.com.mineauz.minigames.config.BooleanFlag; import au.com.mineauz.minigames.config.IntegerFlag; import au.com.mineauz.minigames.config.StringFlag; import au.com.mineauz.minigames.menu.*; import au.com.mineauz.minigames.objects.MinigamePlayer; +import au.com.mineauz.minigames.recorder.RecorderData; import au.com.mineauz.minigamesregions.Node; import au.com.mineauz.minigamesregions.Region; import org.bukkit.Location; diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/RegionSwapAction.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/RegionSwapAction.java index f03077108..c1a0b1da6 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/RegionSwapAction.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/RegionSwapAction.java @@ -1,7 +1,6 @@ package au.com.mineauz.minigamesregions.actions; import au.com.mineauz.minigames.MinigameMessageType; -import au.com.mineauz.minigames.blockRecorder.RecorderData; import au.com.mineauz.minigames.config.BooleanFlag; import au.com.mineauz.minigames.config.StringFlag; import au.com.mineauz.minigames.menu.Menu; @@ -10,6 +9,7 @@ import au.com.mineauz.minigames.menu.MenuUtility; import au.com.mineauz.minigames.minigame.Minigame; import au.com.mineauz.minigames.objects.MinigamePlayer; +import au.com.mineauz.minigames.recorder.RecorderData; import au.com.mineauz.minigamesregions.Node; import au.com.mineauz.minigamesregions.Region; import au.com.mineauz.minigamesregions.RegionModule; diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/SwapBlockAction.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/SwapBlockAction.java index 7df57d3fb..239f55d30 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/SwapBlockAction.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/SwapBlockAction.java @@ -1,11 +1,10 @@ package au.com.mineauz.minigamesregions.actions; -//import au.com.mineauz.minigames.MinigameUtils; -import au.com.mineauz.minigames.blockRecorder.RecorderData; import au.com.mineauz.minigames.config.BlockDataFlag; import au.com.mineauz.minigames.config.BooleanFlag; import au.com.mineauz.minigames.menu.*; import au.com.mineauz.minigames.objects.MinigamePlayer; +import au.com.mineauz.minigames.recorder.RecorderData; import au.com.mineauz.minigamesregions.Node; import au.com.mineauz.minigamesregions.Region; import org.bukkit.Material; diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/TakeItemAction.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/TakeItemAction.java index 7a2f71a34..e1ffac82d 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/TakeItemAction.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/TakeItemAction.java @@ -60,7 +60,12 @@ public void executeNodeAction(MinigamePlayer player, Node node) { } private void execute(MinigamePlayer player) { - ItemStack match = new ItemStack(Material.getMaterial(type.getFlag()), count.getFlag()); + Material mat = Material.getMaterial(type.getFlag()); + + if (mat == null) { + return; + } + ItemStack match = new ItemStack(mat, count.getFlag()); ItemStack matched = null; boolean remove = false; int slot = 0; @@ -80,9 +85,9 @@ private void execute(MinigamePlayer player) { slot++; } - if (remove) + if (remove) { player.getPlayer().getInventory().removeItem(matched); - else { + } else { player.getPlayer().getInventory().getItem(slot).setAmount(matched.getAmount()); } } diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/TimedTriggerAction.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/TimedTriggerAction.java index e696cdb9c..6af8d72ec 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/TimedTriggerAction.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/actions/TimedTriggerAction.java @@ -25,7 +25,6 @@ * @author Turidus */ public class TimedTriggerAction extends AbstractAction { - private final StringFlag toTrigger = new StringFlag("None", "toTrigger"); private final BooleanFlag isRegion = new BooleanFlag(false, "isRegion"); private final IntegerFlag delay = new IntegerFlag(20, "delay"); @@ -82,12 +81,7 @@ private void execute(MinigamePlayer player, ScriptObject obj) { return; } ExecutableScriptObject toExecute = isRegion.getFlag() ? rMod.getRegion(toTrigger.getFlag()) : rMod.getNode(toTrigger.getFlag()); - Bukkit.getScheduler().runTaskLater(Main.getPlugin(), new Runnable() { - @Override - public void run() { - toExecute.execute(Triggers.getTrigger("TIMED_REMOTE"), player); - } - }, delay.getFlag()); + Bukkit.getScheduler().runTaskLater(Main.getPlugin(), () -> toExecute.execute(Triggers.getTrigger("TIMED_REMOTE"), player), delay.getFlag()); } @Override diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/conditions/BlockOnAndHeldCondition.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/conditions/BlockOnAndHeldCondition.java index 0f7708ae9..45778367c 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/conditions/BlockOnAndHeldCondition.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/conditions/BlockOnAndHeldCondition.java @@ -55,10 +55,11 @@ public boolean checkNodeCondition(MinigamePlayer player, Node node) { return check(player); } - private boolean check(MinigamePlayer player) { + if (player == null) { + return false; + } - if (player == null) return false; ItemStack heldItem = player.getPlayer().getInventory().getItemInMainHand(); Location plyLoc = player.getPlayer().getLocation(); diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/conditions/MatchTeamCondition.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/conditions/MatchTeamCondition.java index 44d723e82..e6641a06d 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/conditions/MatchTeamCondition.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/conditions/MatchTeamCondition.java @@ -112,7 +112,11 @@ private Material getTeamMaterial() { case "DARK_BLUE" -> Material.BLUE_CONCRETE; case "DARK_GREEN" -> Material.GREEN_CONCRETE; case "DARK_PURPLE" -> Material.PURPLE_CONCRETE; + case "DARK_GRAY" -> Material.GRAY_CONCRETE; case "GRAY" -> Material.GRAY_WOOL; + case "ORANGE" -> Material.ORANGE_WOOL; + case "CYAN" -> Material.CYAN_WOOL; + case "LIGHT_BLUE" -> Material.LIGHT_BLUE_WOOL; default -> Material.WHITE_WOOL; }; } diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/conditions/MinigameTimerCondition.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/conditions/MinigameTimerCondition.java index c7edc0ed1..bfbe706b8 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/conditions/MinigameTimerCondition.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/conditions/MinigameTimerCondition.java @@ -1,5 +1,6 @@ package au.com.mineauz.minigamesregions.conditions; +import au.com.mineauz.minigames.MinigameTimer; import au.com.mineauz.minigames.MinigameUtils; import au.com.mineauz.minigames.config.IntegerFlag; import au.com.mineauz.minigames.menu.Menu; @@ -56,12 +57,18 @@ public boolean checkNodeCondition(MinigamePlayer player, Node node) { } private boolean check(Minigame mg) { - int timeLeft = mg.getMinigameTimer().getTimeLeft(); - int min = minTime.getFlag(); - int max = maxTime.getFlag(); - debug(mg); - return timeLeft >= min && - timeLeft <= max; + MinigameTimer timer = mg.getMinigameTimer(); + + if (timer == null) { + return false; + } else { + int timeLeft = timer.getTimeLeft(); + int min = minTime.getFlag(); + int max = maxTime.getFlag(); + debug(mg); + return timeLeft >= min && + timeLeft <= max; + } } @Override diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/GameEndPhaseTrigger.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/GameEndPhaseTrigger.java new file mode 100644 index 000000000..47e67e5c0 --- /dev/null +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/GameEndPhaseTrigger.java @@ -0,0 +1,24 @@ +package au.com.mineauz.minigamesregions.triggers; + +public class GameEndPhaseTrigger implements Trigger { + + @Override + public String getName() { + return "GAME_ENDPHASE"; + } + + @Override + public boolean useInRegions() { + return false; + } + + @Override + public boolean useInNodes() { + return true; + } + + @Override + public boolean triggerOnPlayerAvailable() { + return true; + } +} diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/GameEndTrigger.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/GameEndedTrigger.java similarity index 81% rename from Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/GameEndTrigger.java rename to Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/GameEndedTrigger.java index 7a4e89213..d68be2c36 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/GameEndTrigger.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/GameEndedTrigger.java @@ -1,10 +1,10 @@ package au.com.mineauz.minigamesregions.triggers; -public class GameEndTrigger implements Trigger { +public class GameEndedTrigger implements Trigger { @Override public String getName() { - return "GAME_END"; + return "GAME_ENDED"; } @Override diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/TimedRemoteTrigger.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/TimedRemoteTrigger.java index 013569e4c..2a851adf3 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/TimedRemoteTrigger.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/TimedRemoteTrigger.java @@ -22,6 +22,6 @@ public boolean useInNodes() { @Override public boolean triggerOnPlayerAvailable() { - return false; + return true; } } diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/Triggers.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/Triggers.java index 7c0d306a8..0301de60f 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/Triggers.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/Triggers.java @@ -8,6 +8,9 @@ public class Triggers { private static final Map triggers = new HashMap<>(); + //this maps from legacy to updated trigger names + private static final Map renamedTriggers = new HashMap<>(); + static { addTrigger(new BlockBreakTrigger()); addTrigger(new BlockPlaceTrigger()); @@ -16,7 +19,8 @@ public class Triggers { addTrigger(new PlayerKilledTrigger()); addTrigger(new EnterTrigger()); addTrigger(new MoveInRegionTrigger()); - addTrigger(new GameEndTrigger()); + addTrigger(new GameEndPhaseTrigger()); + addTrigger(new GameEndedTrigger()); addTrigger(new GameJoinTrigger()); addTrigger(new GameQuitTrigger()); addTrigger(new GameStartTrigger()); @@ -42,6 +46,10 @@ public class Triggers { addTrigger(new TimedRemoteTrigger()); } + static { + renamedTriggers.put("GAME_END", "GAME_ENDPHASE"); + } + public static void addTrigger(Trigger trigger) { if (triggers.containsKey(trigger.getName())) throw new InvalidTriggerException("A trigger already exists by that name!"); @@ -49,8 +57,18 @@ public static void addTrigger(Trigger trigger) { triggers.put(trigger.getName(), trigger); } + /** + * gets a trigger by its name and translates legacy names if needed + */ public static Trigger getTrigger(String trigger) { - return triggers.get(trigger.toUpperCase()); + trigger = trigger.toUpperCase(); + String renamedTrigger = renamedTriggers.get(trigger); + + if (renamedTrigger != null) { + return triggers.get(renamedTrigger.toUpperCase()); + } else { + return triggers.get(trigger); + } } public static List getAllTriggers() { diff --git a/Regions/src/main/java/au/com/mineauz/minigamesregions/util/NullCommandSender.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/util/NullCommandSender.java index 6365a298f..ef80203e8 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/util/NullCommandSender.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/util/NullCommandSender.java @@ -70,8 +70,8 @@ public void sendRawMessage(@Nullable UUID uuid, @NotNull String s) { } @Override - public Component name() { - return null; + public @NotNull Component name() { + return Component.text("Null"); } @Override diff --git a/Regions/src/main/resources/plugin.yml b/Regions/src/main/resources/plugin.yml index e57e361b0..d0845e1dd 100644 --- a/Regions/src/main/resources/plugin.yml +++ b/Regions/src/main/resources/plugin.yml @@ -2,6 +2,6 @@ name: Minigames-Regions main: au.com.mineauz.minigamesregions.Main version: ${plugin.version} api-version: "${spigot.api.version}" -author: _Razz_ AddstarMC +author: _Razz_ AddstarMC GreenSurvivors depend: [ 'Minigames' ] description: ${project.description} \ No newline at end of file diff --git a/minigamesdistribution/src/assembly/bin.xml b/minigamesdistribution/src/assembly/bin.xml index 5f9ffc885..6eef63548 100644 --- a/minigamesdistribution/src/assembly/bin.xml +++ b/minigamesdistribution/src/assembly/bin.xml @@ -18,7 +18,10 @@ true org.bstats:bstats-bukkit:jar + org.bstats:bstats-base:jar io.papermc:paperlib:jar + org.apache.commons:commons-text:jar + org.apache.commons:commons-lang3:jar false diff --git a/pom.xml b/pom.xml index 8bea563f0..5c7a5c21f 100644 --- a/pom.xml +++ b/pom.xml @@ -135,7 +135,7 @@ 4.13.2 test - @@ -165,49 +165,32 @@ maven-assembly-plugin - 3.5.0 + 3.6.0 org.apache.maven.plugins maven-javadoc-plugin - 3.5.0 - - - org.apache.maven.plugins - maven-source-plugin - 3.2.1 - - - attach-sources - - jar - - package - - - - false - + 3.6.0 org.apache.maven.plugins maven-release-plugin - 3.0.0 + 3.0.1 org.apache.maven.plugins maven-dependency-plugin - 3.5.0 + 3.6.1 org.apache.maven.plugins maven-project-info-reports-plugin - 3.1.1 + 3.4.5 org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M6 + 3.2.1 @@ -215,7 +198,7 @@ org.jacoco jacoco-maven-plugin - 0.8.5 + 0.8.11 prepare @@ -234,7 +217,7 @@ org.codehaus.mojo versions-maven-plugin - 2.15.0 + 2.16.1 org.apache.maven.plugins