diff --git a/Minigames/pom.xml b/Minigames/pom.xml index a85004187..6a95d8cbf 100644 --- a/Minigames/pom.xml +++ b/Minigames/pom.xml @@ -71,7 +71,7 @@ io.papermc paperlib - 1.0.7 + 1.0.5 compile @@ -132,16 +132,6 @@ config.yml *.properties presets/*.yml - - - - - . - false - src/main/resources - resourcepack/*.zip @@ -162,7 +152,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.5.1 + 3.4.0 @@ -210,7 +200,7 @@ org.apache.maven.plugins maven-source-plugin - 3.3.0 + 3.2.1 attach-sources @@ -224,7 +214,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.2.1 + 3.0.0-M6 true 1 @@ -234,12 +224,12 @@ org.apache.maven.plugins maven-dependency-plugin - 3.6.1 + 3.5.0 org.codehaus.mojo versions-maven-plugin - 2.16.1 + 2.8.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 cc63a3a78..23f52c84f 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/Events.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/Events.java @@ -34,7 +34,6 @@ 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; @@ -49,7 +48,7 @@ public class Events implements Listener { private final MinigameManager mdata = plugin.getMinigameManager(); @EventHandler(priority = EventPriority.NORMAL) - public void onPlayerResourcePack(PlayerResourcePackStatusEvent event) { //todo 1.20.3 + add ressource pack not set + public void onPlayerResourcePack(PlayerResourcePackStatusEvent event) { final MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer()); List required = plugin.getPlayerManager().getApplyingPack(); if (ply.isInMinigame()) { @@ -178,7 +177,7 @@ public void onPlayerDisconnect(PlayerQuitEvent event) { MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer()); if (ply.isInMinigame()) { if (ply.getPlayer().isDead()) { - ply.getOfflineMinigamePlayer().setLoginLocation(ply.getMinigame().getQuitLocation()); + ply.getOfflineMinigamePlayer().setLoginLocation(ply.getMinigame().getQuitPosition()); ply.getOfflineMinigamePlayer().savePlayerData(); } pdata.quitMinigame(pdata.getMinigamePlayer(event.getPlayer()), false); @@ -244,7 +243,7 @@ public void onPlayerConnect(PlayerJoinEvent event) { } @EventHandler - public void playerInteract(PlayerInteractEvent event) { + public void playerInterract(PlayerInteractEvent event) { MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer()); if (ply.isInMinigame() && !ply.canInteract()) { @@ -253,11 +252,11 @@ public void playerInteract(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) { @@ -272,7 +271,6 @@ public void playerInteract(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)); @@ -382,6 +380,7 @@ public void playerInteract(PlayerInteractEvent event) { } } + //Spectator disables: if (ply.isInMinigame() && pdata.getMinigamePlayer(event.getPlayer()).getMinigame().isSpectator(pdata.getMinigamePlayer(event.getPlayer()))) { event.setCancelled(true); @@ -459,11 +458,7 @@ 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); @@ -632,14 +627,13 @@ private void spectatorAttack(EntityDamageByEntityEvent event) { @EventHandler(ignoreCancelled = true) private void clickMenu(InventoryClickEvent event) { - 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())) { + 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())) event.setCancelled(true); - } - MenuItem item = mgPlayer.getMenu().getClicked(event.getRawSlot()); + MenuItem item = ply.getMenu().getClicked(event.getRawSlot()); if (item != null) { ItemStack disItem = null; switch (event.getClick()) { @@ -657,38 +651,12 @@ 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 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 - default -> { - } // do nothing for any other action - } } - - } else if (mgPlayer.isInMinigame()) { - if (!mgPlayer.getLoadout().allowOffHand() && event.getSlot() == 40) { + } else if (ply.isInMinigame()) { + if (!ply.getLoadout().allowOffHand() && event.getSlot() == 40) { event.setCancelled(true); - } else if ((mgPlayer.getLoadout().isArmourLocked() && event.getSlot() >= 36 && event.getSlot() <= 39) || - (mgPlayer.getLoadout().isInventoryLocked() && event.getSlot() >= 0 && event.getSlot() <= 35)) { + } else if ((ply.getLoadout().isArmourLocked() && event.getSlot() >= 36 && event.getSlot() <= 39) || + (ply.getLoadout().isInventoryLocked() && event.getSlot() >= 0 && event.getSlot() <= 35)) { event.setCancelled(true); } } @@ -747,6 +715,7 @@ 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 43e98aedc..5e524db10 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/MinigameMessageType.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/MinigameMessageType.java @@ -2,7 +2,6 @@ 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 557d3fad9..956cb7bfa 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/MinigameUtils.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/MinigameUtils.java @@ -278,9 +278,10 @@ 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 && - i.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Minigame Tool")) { - return true; + if (i != null && i.getItemMeta() != null) { + if (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 f1d787a3e..2eb85ad38 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/Minigames.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/Minigames.java @@ -1,6 +1,7 @@ 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; @@ -13,7 +14,6 @@ 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/recorder/BasicRecorder.java b/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/BasicRecorder.java similarity index 81% rename from Minigames/src/main/java/au/com/mineauz/minigames/recorder/BasicRecorder.java rename to Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/BasicRecorder.java index 95360e73a..f1e12668d 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/recorder/BasicRecorder.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/BasicRecorder.java @@ -1,4 +1,4 @@ -package au.com.mineauz.minigames.recorder; +package au.com.mineauz.minigames.blockRecorder; import au.com.mineauz.minigames.Minigames; import au.com.mineauz.minigames.managers.MinigamePlayerManager; @@ -35,20 +35,13 @@ /** * 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 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 - */ + //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 private boolean handleBlockBreak(BlockBreakEvent event, MinigamePlayer mgPlayer) { Block eBlock = event.getBlock(); Minigame mgm = mgPlayer.getMinigame(); @@ -68,11 +61,7 @@ private boolean handleBlockBreak(BlockBreakEvent event, MinigamePlayer mgPlayer) } } - if (mgm.getActivatePlayerRecorder()) { - recData.addBlock(event.getBlock(), mgPlayer); - } - - // signs are safe. Now check for block drops + recData.addBlock(event.getBlock(), mgPlayer); if (!mgm.canBlocksdrop()) { event.getBlock().setType(Material.AIR); return true; @@ -81,9 +70,7 @@ private boolean handleBlockBreak(BlockBreakEvent event, MinigamePlayer mgPlayer) return false; } - /** - * record blocks broken by players (and stop breaking of blocks the player is not allowed to) - */ + //replace broken blocks (and stop breaking of blocks the player is not allowed to) <-- todo move this stopping into another more fitting class @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) private void blockBreak(BlockBreakEvent event) { MinigamePlayer mgPlayer = playerManager.getMinigamePlayer(event.getPlayer()); @@ -122,9 +109,7 @@ private void blockBreak(BlockBreakEvent event) { } } - /** - * record placed blocks (and stop placing ones the players are not allowed to) - */ + //remove placed blocks (and stop placing ones the player is not allowed to) <-- todo move this stopping into another more fitting class @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) private void blockPlace(BlockPlaceEvent event) { MinigamePlayer mgPlayer = playerManager.getMinigamePlayer(event.getPlayer()); @@ -139,20 +124,15 @@ 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())) { - if (mgm.getActivatePlayerRecorder()) { - recData.addBlock(event.getBlockReplacedState(), mgPlayer); - } - } else { - event.setCancelled(true); + recData.addBlock(event.getBlockReplacedState(), mgPlayer); } //black list --> blocks that are not allowed to be placed - } else if (recData.getWBBlocks().contains(event.getBlock().getType())) { - event.setCancelled(true); - } else if (mgm.getActivatePlayerRecorder()) { + } else if (!recData.getWBBlocks().contains(event.getBlock().getType())) { recData.addBlock(event.getBlockReplacedState(), mgPlayer); } } else { @@ -161,9 +141,7 @@ private void blockPlace(BlockPlaceEvent event) { } } - /** - * record inventories changed by players - */ + //reset changed inventories @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) private void changeAnotherInventory(PlayerInteractEvent event) { MinigamePlayer mgPlayer = playerManager.getMinigamePlayer(event.getPlayer()); @@ -174,15 +152,38 @@ private void changeAnotherInventory(PlayerInteractEvent event) { Minigame mgm = mgPlayer.getMinigame(); RecorderData recData = mgm.getRecorderData(); - if (event.getClickedBlock().getState() instanceof InventoryHolder && mgm.getActivatePlayerRecorder()) { + if (event.getClickedBlock().getState() instanceof InventoryHolder) { recData.addBlock(event.getClickedBlock().getLocation().getBlock(), mgPlayer); } } } - /** - * record fire lighted by players - */ + //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 @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void igniteBlock(BlockIgniteEvent event) { if (event.getPlayer() != null) { @@ -196,13 +197,11 @@ 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()) - && mgm.getActivatePlayerRecorder()) { + if (recData.getWBBlocks().contains(event.getBlock().getType())) { 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()) - && mgm.getActivatePlayerRecorder()) { + } else if (!recData.getWBBlocks().contains(event.getBlock().getType())) { recData.addBlock(event.getBlock(), playerManager.getMinigamePlayer(event.getPlayer())); } } else { @@ -212,9 +211,7 @@ public void igniteBlock(BlockIgniteEvent event) { } } - /** - * record hanging entities like item frames placed by players - */ + //remove placed hanging entities @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) private void hangingPlace(HangingPlaceEvent event) { if (event.getPlayer() != null) { @@ -236,14 +233,15 @@ 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) && mgm.getActivatePlayerRecorder()) { + if (recData.getWBBlocks().contains(usedMaterial)) { recData.addEntity(event.getEntity(), mgPlayer, true); return; } //black list --> blocks that are not allowed to be broken - } else if (!recData.getWBBlocks().contains(usedMaterial) && mgm.getActivatePlayerRecorder()) { + } else if (!recData.getWBBlocks().contains(usedMaterial)) { recData.addEntity(event.getEntity(), mgPlayer, true); return; } @@ -253,12 +251,10 @@ private void hangingPlace(HangingPlaceEvent event) { } } - /** - * record animals killed by players - * Note: entities like monsters or armor stands getting recorded only if regen regions are getting used - */ + //revive killed animals + //entities like monsters or armor stands are reset if restore regions is turned on. @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - private void animalHurt(EntityDamageByEntityEvent event) { + private void animalHurt(EntityDamageByEntityEvent event) { //todo check for spawn to not revive animals spawned while the minigame was running. if (event.getEntity() instanceof Animals animal) { //did the player kill the animal? if (animal.getHealth() <= event.getDamage()) { @@ -273,7 +269,7 @@ private void animalHurt(EntityDamageByEntityEvent event) { } if (mgPlayer != null) { - if (mgPlayer.isInMinigame() && mgPlayer.getMinigame().getActivatePlayerRecorder()) { + if (mgPlayer.isInMinigame()) { mgPlayer.getMinigame().getRecorderData().addEntity(animal, mgPlayer, false); } } @@ -281,9 +277,7 @@ private void animalHurt(EntityDamageByEntityEvent event) { } } - /** - * record hanging entities getting removed by a player - */ + //revive hanging entities @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) private void hangingBreak(HangingBreakByEntityEvent event) { MinigamePlayer mgPlayer = null; @@ -296,71 +290,38 @@ private void hangingBreak(HangingBreakByEntityEvent event) { } if (mgPlayer != null) { - if (mgPlayer.isInMinigame() && mgPlayer.getMinigame().getActivatePlayerRecorder()) { + if (mgPlayer.isInMinigame()) { mgPlayer.getMinigame().getRecorderData().addEntity(event.getEntity(), mgPlayer, false); } } } - /** - * record arrows shot by players - */ + //remove arrow entities @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() && mgPlayer.getMinigame().getActivatePlayerRecorder()) { + if (mgPlayer.isInMinigame()) { mgPlayer.getMinigame().getRecorderData().addEntity(event.getProjectile(), mgPlayer, true); } } } - /** - * record ender perl entities (important if somewhere caught in bubble columns) - */ + //remove ender perl entities (important if some where 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() && mgPlayer.getMinigame().getActivatePlayerRecorder()) { + if (mgPlayer.isInMinigame()) { mgPlayer.getMinigame().getRecorderData().addEntity(event.getEntity(), mgPlayer, true); } } } - /** - * 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 - */ + //remove liquid source + //todo this doesn't handle changed blocks of flowing liquids, as well as new created water sources @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) private void bucketEmpty(PlayerBucketEmptyEvent event) { MinigamePlayer mgPlayer = playerManager.getMinigamePlayer(event.getPlayer()); @@ -372,7 +333,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()) && mgm.getActivatePlayerRecorder()) { + if (recData.getWBBlocks().contains(event.getBlock().getType())) { Location loc = new Location(event.getBlockClicked().getWorld(), event.getBlockFace().getModX() + event.getBlockClicked().getX(), event.getBlockFace().getModY() + event.getBlockClicked().getY(), @@ -380,8 +341,7 @@ 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()) - && mgm.getActivatePlayerRecorder()) { + } else if (!recData.getWBBlocks().contains(event.getBlock().getType())) { Location loc = new Location(event.getBlockClicked().getWorld(), event.getBlockFace().getModX() + event.getBlockClicked().getX(), event.getBlockFace().getModY() + event.getBlockClicked().getY(), @@ -394,9 +354,7 @@ private void bucketEmpty(PlayerBucketEmptyEvent event) { } } - /** - * record vehicles broken by players - */ + //revive vehicles @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) private void vehicleDestroy(VehicleDestroyEvent event) { if (event.getAttacker() != null) { @@ -404,7 +362,7 @@ private void vehicleDestroy(VehicleDestroyEvent event) { MinigamePlayer mgPlayer = playerManager.getMinigamePlayer(player); Minigame mg = mgPlayer.getMinigame(); - if (mgPlayer.isInMinigame() && mg.getActivatePlayerRecorder()) { + if (mgPlayer.isInMinigame()) { mg.getRecorderData().addEntity(event.getVehicle(), mgPlayer, false); } } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/recorder/EntityData.java b/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/EntityData.java similarity index 51% rename from Minigames/src/main/java/au/com/mineauz/minigames/recorder/EntityData.java rename to Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/EntityData.java index b4ce580ab..32b5615d3 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/recorder/EntityData.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/EntityData.java @@ -1,19 +1,14 @@ -package au.com.mineauz.minigames.recorder; +package au.com.mineauz.minigames.blockRecorder; 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; @@ -26,15 +21,8 @@ public class EntityData { // was this entity created and needs to removed or was it changed / killed? private final 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) { + //todo save metadata like armor + public EntityData(Entity entity, @Nullable MinigamePlayer modifier, boolean created) { this.uuid = entity.getUniqueId(); this.entType = entity.getType(); this.entLocation = entity.getLocation(); @@ -42,20 +30,10 @@ public EntityData(@NotNull Entity entity, @Nullable MinigamePlayer modifier, boo 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; } @@ -64,16 +42,10 @@ 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/recorder/MgBlockData.java b/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/MgBlockData.java similarity index 92% rename from Minigames/src/main/java/au/com/mineauz/minigames/recorder/MgBlockData.java rename to Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/MgBlockData.java index 5e28e81b4..aced3402e 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/recorder/MgBlockData.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/MgBlockData.java @@ -1,4 +1,4 @@ -package au.com.mineauz.minigames.recorder; +package au.com.mineauz.minigames.blockRecorder; import au.com.mineauz.minigames.Minigames; import au.com.mineauz.minigames.objects.MinigamePlayer; @@ -50,22 +50,14 @@ public MgBlockData(@NotNull Block original, @Nullable MinigamePlayer modifier) { location = original.getLocation(); state = original.getState(); blockData = original.getBlockData().getAsString(); - if (modifier != null) { - playerUUID = modifier.getUUID(); - } else { - playerUUID = null; - } + if (modifier != null) playerUUID = modifier.getUUID(); } public MgBlockData(@NotNull BlockState original, @Nullable MinigamePlayer modifier) { location = original.getLocation(); state = original; blockData = state.getBlockData().getAsString(); - if (modifier != null) { - playerUUID = modifier.getUUID(); - } else { - playerUUID = null; - } + if (modifier != null) playerUUID = modifier.getUUID(); } public @NotNull Location getLocation() { @@ -77,11 +69,7 @@ public MgBlockData(@NotNull BlockState original, @Nullable MinigamePlayer modifi } public @Nullable MinigamePlayer getModifier() { - if (playerUUID == null) { - return null; - } else { - return Minigames.getPlugin().getPlayerManager().getMinigamePlayer(playerUUID); - } + return Minigames.getPlugin().getPlayerManager().getMinigamePlayer(playerUUID); } public void setModifier(@Nullable MinigamePlayer modifier) { diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/recorder/RecorderData.java b/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RecorderData.java similarity index 97% rename from Minigames/src/main/java/au/com/mineauz/minigames/recorder/RecorderData.java rename to Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RecorderData.java index a19259593..33fb218d6 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/recorder/RecorderData.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RecorderData.java @@ -1,4 +1,4 @@ -package au.com.mineauz.minigames.recorder; +package au.com.mineauz.minigames.blockRecorder; 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(@NotNull Block block, @Nullable MinigamePlayer modifier) { - BlockStateSnapshotResult blockState = PaperLib.getBlockState(block, true); - return addBlock(blockState.getState(), modifier); + public MgBlockData addBlock(Block block, MinigamePlayer modifier) { + BlockStateSnapshotResult blockstate = PaperLib.getBlockState(block, true); + return addBlock(blockstate.getState(), modifier); } - public MgBlockData addBlock(@NotNull BlockState block, @Nullable MinigamePlayer modifier) { + public MgBlockData addBlock(BlockState block, 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 @Nullable MinigamePlayer modifier) { + public void restoreBlocks(final 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/recorder/RegenRecorder.java b/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RegenRecorder.java similarity index 99% rename from Minigames/src/main/java/au/com/mineauz/minigames/recorder/RegenRecorder.java rename to Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RegenRecorder.java index 6618f7e4c..eb7cc53f6 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/recorder/RegenRecorder.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RegenRecorder.java @@ -1,4 +1,4 @@ -package au.com.mineauz.minigames.recorder; +package au.com.mineauz.minigames.blockRecorder; 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/RollbackScheduler.java b/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RollbackScheduler.java similarity index 97% rename from Minigames/src/main/java/au/com/mineauz/minigames/recorder/RollbackScheduler.java rename to Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RollbackScheduler.java index f0d1093cf..260f3a26f 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/recorder/RollbackScheduler.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/RollbackScheduler.java @@ -1,4 +1,4 @@ -package au.com.mineauz.minigames.recorder; +package au.com.mineauz.minigames.blockRecorder; 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/package-info.java b/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/package-info.java new file mode 100644 index 000000000..c30f8f478 --- /dev/null +++ b/Minigames/src/main/java/au/com/mineauz/minigames/blockRecorder/package-info.java @@ -0,0 +1,4 @@ +/** + * 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 8f283e790..9dfdb1fcf 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().isEmpty()) { + if (minigame.getPlayers().size() == 0) { 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 a7ff36cc4..5eaf373f6 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 player) { - ply = player; + if (sender instanceof Player) { + ply = (Player) sender; } if (args != null && args.length > 0) { @@ -222,10 +222,11 @@ 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 9aed73276..1bc30955c 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,32 +7,16 @@ 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 9351482be..6d152781d 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,8 +7,6 @@ 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; @@ -59,8 +57,8 @@ public String getPermission() { } @Override - public boolean onCommand(@NotNull CommandSender sender, Minigame minigame, - String label, @NotNull String @Nullable [] args) { + public boolean onCommand(CommandSender sender, Minigame minigame, + String label, String[] args) { if (args == null && sender instanceof Player) { MinigamePlayer player = plugin.getPlayerManager().getMinigamePlayer((Player) sender); if (player.isInMinigame()) { @@ -70,7 +68,13 @@ public boolean onCommand(@NotNull CommandSender sender, Minigame minigame, } return true; } else if (args != null) { - if (sender.hasPermission("minigame.quit.other")) { + 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 (args[0].equals("ALL")) { if (args.length > 1) { if (plugin.getMinigameManager().hasMinigame(args[1])) { @@ -92,23 +96,18 @@ public boolean onCommand(@NotNull 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 { - MinigamePlayer ply; - List players = plugin.getServer().matchPlayer(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)); - } + 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])); - } + 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 b15db076f..30763f0b4 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,12 +9,9 @@ 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 { @@ -62,38 +59,39 @@ public String getPermission() { } @Override - public boolean onCommand(@NotNull CommandSender sender, @Nullable Minigame minigame, - @Nullable String label, @NotNull String @Nullable [] args) { - if (args != null && args.length >= 3) { + public boolean onCommand(CommandSender sender, Minigame minigame, + String label, String[] args) { + if (args != null && args.length >= 2) { MinigamePlayer ply = null; - TeamColor color = TeamColor.matchColor(args[2]); - Minigame mg = plugin.getMinigameManager().getMinigame(args[1]); + TeamColor color = TeamColor.matchColor(args[1]); if (color == null) { - List plys = plugin.getServer().matchPlayer(args[2]); + List plys = plugin.getServer().matchPlayer(args[1]); if (!plys.isEmpty()) { ply = plugin.getPlayerManager().getMinigamePlayer(plys.get(0)); } else { - sender.sendMessage(ChatColor.RED + "No player or team found by the name " + args[2]); + sender.sendMessage(ChatColor.RED + "No player or team found by the name " + args[1]); return true; } } - 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()); + 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]); } else { - sender.sendMessage(ChatColor.RED + ply.getName() + " is not playing a Minigame!"); + sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + args[2]); + return true; } - } else { + TeamsModule tmod = TeamsModule.getMinigameModule(mg); if (mg.isTeamGame()) { @@ -108,184 +106,170 @@ public boolean onCommand(@NotNull CommandSender sender, @Nullable Minigame minig 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; + } + return true; + } else if (args[0].equalsIgnoreCase("set") && args.length >= 3) { - } // end case + int score; - case "set" -> { - if (args.length >= 4) { - if (args[3].matches("^[+\\-]?[0-9]+$")) { - int score = Integer.parseInt(args[2]); + 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); + 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 (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 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 { - sender.sendMessage(ChatColor.RED + args[2] + " is not a valid number!"); + if (ply.getMinigame().getMaxScore() != 0 && score >= ply.getMinigame().getMaxScorePerPlayer()) { + plugin.getPlayerManager().endMinigame(ply); } } else { - sender.sendMessage(ChatColor.RED + "Not enough arguments!"); + sender.sendMessage(ChatColor.RED + ply.getName() + " is not playing a Minigame!"); } - - return true; - } // end case - - case "add" -> { + } else { if (args.length >= 4) { - if (args[3].matches("^[+\\-]?[0-9]+$")) { - int score = Integer.parseInt(args[2]); + 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; + } - 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()); + TeamsModule tmod = TeamsModule.getMinigameModule(mg); - 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."); + 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 (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()); } - } 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!"); + 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 + args[2] + " is not a valid number!"); + sender.sendMessage(ChatColor.RED + mg.getName(false) + " is not a team Minigame!"); } } else { - sender.sendMessage(ChatColor.RED + "Not enough arguments!"); + sender.sendMessage(ChatColor.RED + "This command requires a Minigame name as the last argument!"); } - - return true; - } // end case - default -> { - sender.sendMessage(ChatColor.RED + "Invalid argument!"); } - } // end switch - } else { - sender.sendMessage(ChatColor.RED + "Not enough arguments!"); - } - return false; - } + return true; + } else if (args[0].equalsIgnoreCase("add") && args.length >= 3) { + int score; - @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]); + if (args[2].matches("-?[0-9]+")) { + score = Integer.parseInt(args[2]); + } else { + score = 1; } - case 3 -> { - List pt = new ArrayList<>(plugin.getServer().getOnlinePlayers().size()); - for (Player pl : plugin.getServer().getOnlinePlayers()) { - pt.add(pl.getName()); + + 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 { + Minigame mg; + String mgName; - Minigame mgm = plugin.getMinigameManager().getMinigame(args[1]); + if (args.length == 4) { + mgName = args[3]; + } else { + mgName = args[2]; + } - if (mgm != null && mgm.isTeamGame()) { - pt.addAll(TeamsModule.getMinigameModule(mgm).getTeams().stream().map(t -> t.getColor().name()).toList()); + + if (plugin.getMinigameManager().hasMinigame(mgName)) { + mg = plugin.getMinigameManager().getMinigame(mgName); + } else { + sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + mgName); + 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); + TeamsModule tmod = TeamsModule.getMinigameModule(mg); - for (int i = 0; i < 10; i++) { - numbers.add(args[3] + i); - } + 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(numbers, args[3]); - } // not a number - } // not add / set - } // more than 4 arguments - default -> { - } // do nothing - } // end switch - } // args == null + 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()); + } + } + 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 null; + return MinigameUtils.tabCompleteMatch(pt, args[1]); + } + List mgs = new ArrayList<>(plugin.getMinigameManager().getAllMinigames().keySet()); + return MinigameUtils.tabCompleteMatch(mgs, args[args.length - 1]); } } 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 a43b718be..9d5547bb0 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,28 +61,22 @@ public boolean onCommand(CommandSender sender, Minigame minigame, Minigame mgm = plugin.getMinigameManager().getMinigame(args[0]); if (mgm != null) { - 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.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.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 fa0e5bf73..0d8bd0a81 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.setEndLocation(((Player) sender).getLocation()); + minigame.setEndPosition(((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 dc88e01eb..5c6565685 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.setLobbyLocation(((Player) sender).getLocation()); + minigame.setLobbyPosition(((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 a562d0baf..e947874d8 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.setQuitLocation(player.getLocation()); + minigame.setQuitPosition(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 8da97d18e..4da3c354f 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 false; + return true; } if (position >= 1) { @@ -95,28 +95,21 @@ public boolean onCommand(CommandSender sender, Minigame minigame, String label, } return true; } else if (args[0].equalsIgnoreCase("clear")) { - 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 { + if (args.length >= 2 && 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; + return true; } + + 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; } @@ -125,8 +118,10 @@ 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 deleted file mode 100644 index f41d2a902..000000000 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/AbstractCancellableMinigameEvent.java +++ /dev/null @@ -1,37 +0,0 @@ -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 c13fc67cf..11d2508cf 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,13 +1,15 @@ 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 { +public class AbstractMinigameEvent extends Event implements Cancellable { private static final HandlerList HANDLERS = new HandlerList(); private final Minigame mgm; + private boolean cancelled = false; /** * Instantiates a new Abstract minigame event. @@ -23,6 +25,26 @@ 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 ccd70dc6c..bda355442 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 AbstractCancellableMinigameEvent { +public class DropFlagEvent extends AbstractMinigameEvent { 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 new file mode 100644 index 000000000..e1c5c14c2 --- /dev/null +++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/EndMinigameEvent.java @@ -0,0 +1,28 @@ +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 deleted file mode 100644 index c514e7c2c..000000000 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/EndPhaseMinigameEvent.java +++ /dev/null @@ -1,37 +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; - -/** - * 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 deleted file mode 100644 index 6cf1254fe..000000000 --- a/Minigames/src/main/java/au/com/mineauz/minigames/events/EndedMinigameEvent.java +++ /dev/null @@ -1,12 +0,0 @@ -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 f8e56a225..6cd341071 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 AbstractCancellableMinigameEvent { +public class FlagCaptureEvent extends AbstractMinigameEvent { 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 7da259c51..84b71eb4b 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 AbstractCancellableMinigameEvent { +public class JoinMinigameEvent extends AbstractMinigameEvent { 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 e02e430a1..50d8bcae7 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 AbstractCancellableMinigameEvent { +public class MinigameTimerTickEvent extends AbstractMinigameEvent { 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 1f38b7473..c5195e2e9 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 AbstractCancellableMinigameEvent { +public class MinigamesBroadcastEvent extends AbstractMinigameEvent { 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 c87c42756..48f9a9c6d 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 AbstractCancellableMinigameEvent { +public class QuitMinigameEvent extends AbstractMinigameEvent { 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 75ae902ea..a0c3424b3 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 AbstractCancellableMinigameEvent { +public class RevertCheckpointEvent extends AbstractMinigameEvent { 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 0d6f08245..691fcecdb 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 AbstractCancellableMinigameEvent { +public class SpectateMinigameEvent extends AbstractMinigameEvent { private final MinigamePlayer player; public SpectateMinigameEvent(MinigamePlayer player, Minigame minigame) { @@ -19,4 +19,6 @@ 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 23f39f261..78c5f9d77 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 AbstractCancellableMinigameEvent { +public class StartGlobalMinigameEvent extends AbstractMinigameEvent { private final String mechanic; private final MinigamePlayer caller; @@ -14,6 +14,7 @@ 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 7b6dbd641..aaebcca6d 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 AbstractCancellableMinigameEvent { +public class StartMinigameEvent extends AbstractMinigameEvent { 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 0ffb47ff0..5ecf6f97b 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 AbstractCancellableMinigameEvent { +public class StopGlobalMinigameEvent extends AbstractMinigameEvent { 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 84342ebac..9eefee23c 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 AbstractCancellableMinigameEvent { +public class TakeFlagEvent extends AbstractMinigameEvent { 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 c489467ab..94f37ed9b 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,7 +3,9 @@ import au.com.mineauz.minigames.minigame.Minigame; import au.com.mineauz.minigames.minigame.MinigameState; -public class TimerExpireEvent extends AbstractCancellableMinigameEvent { +public class TimerExpireEvent extends AbstractMinigameEvent { + + 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 856495e2e..8062d50ab 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.getQuitLocation().getWorld() && player.getPlayer().hasPermission("minigame.set.quit") && plugin.getConfig().getBoolean("warnings")) { + if (player.getPlayer().getWorld() != minigame.getQuitPosition().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.getQuitLocation()); + player.teleport(minigame.getQuitPosition()); } else { - player.setQuitPos(minigame.getQuitLocation()); + player.setQuitPos(minigame.getQuitPosition()); 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 de830740f..a1e425eba 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.getLobbyLocation() == null; + cannotStart = mgm.getLobbyPosition() == 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.getLobbyLocation(); + Location location = mgm.getLobbyPosition(); 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().isEmpty()) + if (t.getPlayers().size() > 0) 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().isEmpty()) { + if (t.getPlayers().size() > 0) { winner = t; break; } @@ -262,7 +262,7 @@ public void playerRespawn(PlayerRespawnEvent event) { } ply.getLoadout().equiptLoadout(ply); } else { - respawnPos = mg.getLobbyLocation(); + respawnPos = mg.getLobbyPosition(); } } else { if (mg.hasStarted() && !ply.isLatejoining()) { @@ -276,7 +276,7 @@ public void playerRespawn(PlayerRespawnEvent event) { ply.getLoadout().equiptLoadout(ply); } else { - respawnPos = mg.getLobbyLocation(); + respawnPos = mg.getLobbyPosition(); } } 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 662cd4be2..26fc94834 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,7 +14,6 @@ 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; @@ -40,11 +39,6 @@ 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() && @@ -57,7 +51,8 @@ public boolean teleportOnJoin(MinigamePlayer player, Minigame mgm) { @Override public boolean joinMinigame(MinigamePlayer player, Minigame mgm) { - if (mgm.getLives() > 0 && Math.abs(mgm.getLives()) < Integer.MAX_VALUE) { + + if (mgm.getLives() > 0 && !Float.isFinite(mgm.getLives())) { player.sendInfoMessage(MessageManager.getMinigamesMessage("minigame.livesLeft", mgm.getLives())); } if (!mgm.isAllowedFlight()) { @@ -122,7 +117,7 @@ public void endMinigame(List winners, List loser } @Override - public void quitMinigame(final @NotNull MinigamePlayer player, final @NotNull Minigame mgm, boolean forced) { + public void quitMinigame(final MinigamePlayer player, final 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 c0f92ea01..b2c6e2ba3 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 = Locale.forLanguageTag(tag.replace("_", "-")); - - // fall back if locale is undefined - if (locale.getLanguage().isEmpty()) { - locale = Locale.getDefault(); - } - + locale = Locale.forLanguageTag(tag); 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); + registerCoreLanguage(file, Locale.getDefault()); } 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 3ca9da771..1987defa8 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,6 +4,7 @@ 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; @@ -18,13 +19,11 @@ 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.*; @@ -137,9 +136,10 @@ public void addMinigame(final Minigame game) { if (Minigames.getPlugin().includesPapi()) { Minigames.getPlugin().getPlaceHolderManager().addGameIdentifiers(game); } + } - public @Nullable Minigame getMinigame(final String minigame) { + public Minigame getMinigame(final String minigame) { if (this.minigames.containsKey(minigame)) { return this.minigames.get(minigame); } @@ -230,6 +230,7 @@ public Set getMinigameTypes() { return this.minigameTypes.keySet(); } + public void addLoadout(final String name) { this.globalLoadouts.put(name, new PlayerLoadout(name)); } @@ -314,11 +315,11 @@ private void sendBroadcastMessage(Minigame minigame, String message, MinigameMes type = MinigameMessageType.INFO; } finalMessage += message; - final Set sendto = new HashSet<>(); + final List sendto = new ArrayList<>(); sendto.addAll(minigame.getPlayers()); sendto.addAll(minigame.getSpectators()); if (exclude != null) { - exclude.forEach(sendto::remove); + sendto.removeAll(exclude); } for (final MinigamePlayer pl : sendto) { pl.sendMessage(finalMessage, type); @@ -444,10 +445,10 @@ public boolean minigameStartStateCheck(final Minigame minigame, final MinigamePl } public boolean minigameStartSetupCheck(final Minigame minigame, final MinigamePlayer player) { - if (minigame.getEndLocation() == null) { + if (minigame.getEndPosition() == null) { player.sendMessage(MinigameUtils.getLang("minigame.error.noEnd"), MinigameMessageType.ERROR); return false; - } else if (minigame.getQuitLocation() == null) { + } else if (minigame.getQuitPosition() == 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. @@ -466,7 +467,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("minigame.error.invalidType") + " : " + minigame.getName(true)); + Minigames.log().warning(MessageManager.getMinigamesMessage("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 2d46cb01d..8959238de 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,6 +4,7 @@ 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; @@ -14,7 +15,6 @@ 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,7 +34,6 @@ 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.*; @@ -257,9 +256,7 @@ public void spectateMinigame(MinigamePlayer player, Minigame minigame) { pl.getPlayer().hidePlayer(plugin, player.getPlayer()); } - if (minigame.canDisplayScoreboard()) { - player.getPlayer().setScoreboard(minigame.getScoreboardManager()); - } + player.getPlayer().setScoreboard(minigame.getScoreboardManager()); for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) { player.getPlayer().removePotionEffect(potion.getType()); @@ -448,6 +445,7 @@ public void getStartLocations(List players, Minigame game) { } public void revertToCheckpoint(MinigamePlayer player) { + RevertCheckpointEvent event = new RevertCheckpointEvent(player); Bukkit.getServer().getPluginManager().callEvent(event); @@ -471,7 +469,7 @@ public void revertToCheckpoint(MinigamePlayer player) { } } - public void quitMinigame(@NotNull MinigamePlayer player, boolean forced) { + public void quitMinigame(MinigamePlayer player, boolean forced) { Minigame minigame = player.getMinigame(); boolean isWinner = GameOverModule.getMinigameModule(minigame).getWinners().contains(player); @@ -479,48 +477,7 @@ public void quitMinigame(@NotNull 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 (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 (!minigame.isSpectator(player)) { if (player.getEndTime() == 0) player.setEndTime(System.currentTimeMillis()); @@ -531,9 +488,8 @@ public void quitMinigame(@NotNull 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()) { @@ -583,29 +539,28 @@ public void quitMinigame(@NotNull MinigamePlayer player, boolean forced) { player.restorePlayerData(); Location loc; if (!isWinner) { - if (minigame.getQuitLocation() != null) { - loc = minigame.getQuitLocation(); + if (minigame.getQuitPosition() != null) { + loc = minigame.getQuitPosition(); } else { - loc = minigame.getEndLocation(); + loc = minigame.getEndPosition(); } } else { - if (minigame.getEndLocation() != null) { - loc = minigame.getEndLocation(); + if (minigame.getEndPosition() != null) { + loc = minigame.getEndPosition(); } else { - loc = minigame.getQuitLocation(); + loc = minigame.getQuitPosition(); } } if (loc != null) { player.teleport(loc); } else { - Minigames.log.warning("Minigame " + minigame.getName(true) + " has no end location set! (Player: " + player.getName() + ")"); + Minigames.log.warning("Minigame " + minigame.getName(true) + " has no end position set! (Player: " + player.getName() + ")"); } } else { - if (!isWinner) { - player.setQuitPos(minigame.getQuitLocation()); - } else { - player.setQuitPos(minigame.getEndLocation()); - } + if (!isWinner) + player.setQuitPos(minigame.getQuitPosition()); + else + player.setQuitPos(minigame.getEndPosition()); player.setRequiredQuit(true); } player.setStartPos(null); @@ -617,10 +572,7 @@ public void quitMinigame(@NotNull MinigamePlayer player, boolean forced) { player.claimRewards(); //Reset Minigame - 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.getPlayers().size() == 0) { if (minigame.getMinigameTimer() != null) { minigame.getMinigameTimer().stopTimer(); minigame.setMinigameTimer(null); @@ -650,17 +602,15 @@ public void quitMinigame(@NotNull 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()); @@ -679,6 +629,34 @@ public void quitMinigame(@NotNull 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"))) { @@ -703,10 +681,11 @@ 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); - EndPhaseMinigameEvent event = new EndPhaseMinigameEvent(winners, losers, minigame); + EndMinigameEvent event = new EndMinigameEvent(winners, losers, minigame); Bukkit.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { @@ -756,7 +735,7 @@ public void endMinigame(Minigame minigame, List winners, List winners, Minigame minigame) { } } + @Deprecated public boolean playerInMinigame(Player player) { return minigamePlayers.get(player.getName()).isInMinigame(); @@ -937,9 +917,8 @@ 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)); @@ -1044,4 +1023,15 @@ 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 902c2d279..129bf6141 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(sign, oTeam, mgm); + CTFFlag flag = new CTFFlag(event.getClickedBlock().getLocation(), 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 73cda201c..0216340a4 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 (Math.abs(minigame.getLives()) < Integer.MAX_VALUE) { - int lives = minigame.getLives(); - player.setScore(lives); - minigame.setScore(player, lives); - } else { + if (!Float.isFinite(minigame.getLives())) { player.setScore(Integer.MAX_VALUE); minigame.setScore(player, Integer.MAX_VALUE); + } else { + int lives = Float.floatToIntBits(minigame.getLives()); + player.setScore(lives); + minigame.setScore(player, lives); } } } 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 d15486a71..d7849da18 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,7 +18,6 @@ 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; @@ -69,7 +68,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(); @@ -90,41 +89,40 @@ public static void spawnTreasure(final Minigame mgm) { //Add a new Chest //TODO: Improve so no invalid spawns (Not over void, Strict containment) - 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); - } - 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) { + 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); + } + 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); } } - Bukkit.getScheduler().runTaskLater(plugin, () -> rpos.getBlock().setType(Material.CHEST), 1L); - - //Fill new container + //Fill new chest Bukkit.getScheduler().runTaskLater(plugin, () -> { - if (rpos.getBlock().getState() instanceof Container container) { + if (rpos.getBlock().getState() instanceof Chest chest) { // 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.min(container.getInventory().getSize(), Math.round(Math.random() * (thm.getMaxTreasure() - thm.getMinTreasure())) + thm.getMinTreasure()); + int numitems = (int) 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)); - container.getInventory().setContents(items); + chest.getInventory().setContents(items); } } } @@ -164,14 +162,13 @@ public void startMinigame(Minigame minigame, MinigamePlayer caller) { if (thm.getLocation() != null) { spawnTreasure(minigame); - if (Bukkit.getOnlinePlayers().isEmpty()) + if (Bukkit.getOnlinePlayers().size() == 0) 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); - } } } @@ -346,4 +343,5 @@ 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 83ad857fa..a422fda0d 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,37 +42,24 @@ public ItemStack onClick() { @Override public void checkValidEntry(String 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! + entry = entry.toUpperCase(); + if (Material.getMaterial(entry) != null) { + Material mat = Material.getMaterial(entry); 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 e8d8d7302..af8052e25 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 dataCallback; + private Callback data; public MenuItemBlockData(String name, Material displayItem) { super(name, displayItem); - dataCallback.setValue(displayItem.createBlockData()); - setDescription(createDescription(dataCallback.getValue())); + data.setValue(displayItem.createBlockData()); + setDescription(createDescription(data.getValue())); } public MenuItemBlockData(String name, Material displayItem, Callback callback) { super(name, displayItem); - this.dataCallback = callback; - setDescription(createDescription(dataCallback.getValue())); + this.data = callback; + setDescription(createDescription(data.getValue())); } @Override public void update() { - setDescription(createDescription(this.dataCallback.getValue())); + setDescription(createDescription(this.data.getValue())); } /** @@ -61,12 +61,7 @@ private List createDescription(BlockData data) { public ItemStack onClickWithItem(@Nullable ItemStack item) { try { BlockData data = item.getType().createBlockData(); - this.dataCallback.setValue(data); - - // update the display item - ItemStack stackUpdate = getItem(); - stackUpdate.setType(item.getType()); - setItem(stackUpdate); + this.data.setValue(data); } catch (IllegalArgumentException | NullPointerException e) { String name = "unknown"; if (item != null) { @@ -82,16 +77,8 @@ public void checkValidEntry(String entry) { String err = "No MgBlockData detected"; try { BlockData d = Bukkit.createBlockData(entry); - dataCallback.setValue(d); - - // update the display item - setDescription(createDescription(dataCallback.getValue())); - if (d.getMaterial().isItem()) { - ItemStack stackUpdate = getItem(); - stackUpdate.setType(d.getMaterial()); - setItem(stackUpdate); - } - + data.setValue(d); + setDescription(createDescription(data.getValue())); 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 b04188bdc..40e6c0b42 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,11 +72,10 @@ 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 fe580feea..3267939f9 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,6 +1,7 @@ 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; @@ -14,7 +15,6 @@ 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,7 +32,10 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.scoreboard.*; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.ScoreboardManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -63,9 +66,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 endLocation = new LocationFlag(null, "endpos"); - private final LocationFlag quitLocation = new LocationFlag(null, "quitpos"); - private final LocationFlag lobbyLocation = new LocationFlag(null, "lobbypos"); + 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 spectatorPosition = new LocationFlag(null, "spectatorpos"); private final BooleanFlag usePermissions = new BooleanFlag(false, "usepermissions"); @@ -99,7 +102,6 @@ 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"); @@ -120,7 +122,6 @@ 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<>(); @@ -169,19 +170,19 @@ private void setup(MinigameType type, Location start) { if (start != null) startLocations.getFlag().add(start); if (sbManager != null) { - sbManager.registerNewObjective(this.name, Criteria.DUMMY, this.name).setDisplaySlot(DisplaySlot.SIDEBAR); + sbManager.registerNewObjective(this.name, "dummy", this.name); + sbManager.getObjective(this.name).setDisplaySlot(DisplaySlot.SIDEBAR); } for (Class mod : Minigames.getPlugin().getMinigameManager().getModules()) { try { addModule(mod.getDeclaredConstructor(Minigame.class).newInstance(this)); } catch (Exception e) { - Minigames.getPlugin().getLogger().log(Level.WARNING, "Couldn't construct Module.", e); + e.printStackTrace(); } } flags.setFlag(new ArrayList<>()); - addConfigFlag(activatePlayerRecorder); addConfigFlag(allowEnderPearls); addConfigFlag(allowFlight); addConfigFlag(allowMPCheckpoints); @@ -196,7 +197,7 @@ private void setup(MinigameType type, Location start) { addConfigFlag(displayName); addConfigFlag(enableFlight); addConfigFlag(enabled); - addConfigFlag(endLocation); + addConfigFlag(endPosition); addConfigFlag(flags); addConfigFlag(floorDegen); addConfigFlag(floorDegenTime); @@ -205,7 +206,7 @@ private void setup(MinigameType type, Location start) { addConfigFlag(itemPickup); addConfigFlag(lateJoin); addConfigFlag(lives); - addConfigFlag(lobbyLocation); + addConfigFlag(lobbyPosition); addConfigFlag(maxChestRandom); addConfigFlag(maxPlayers); addConfigFlag(maxScore); @@ -221,7 +222,7 @@ private void setup(MinigameType type, Location start) { addConfigFlag(objective); addConfigFlag(paintBallDamage); addConfigFlag(paintBallMode); - addConfigFlag(quitLocation); + addConfigFlag(quitPosition); addConfigFlag(randomizeChests); addConfigFlag(regenRegions); addConfigFlag(regenDelay); @@ -308,11 +309,7 @@ public boolean removeFlag(String flag) { } public void setStartLocation(Location loc) { - if (startLocations.getFlag().isEmpty()) { - startLocations.getFlag().add(loc); - } else { - startLocations.getFlag().set(0, loc); - } + startLocations.getFlag().set(0, loc); } public void addStartLocation(Location loc) { @@ -455,28 +452,28 @@ public void setDegenRandomChance(int degenRandomChance) { this.degenRandomChance.setFlag(degenRandomChance); } - public @Nullable Location getEndLocation() { - return endLocation.getFlag(); + public Location getEndPosition() { + return endPosition.getFlag(); } - public void setEndLocation(Location endLocation) { - this.endLocation.setFlag(endLocation); + public void setEndPosition(Location endPosition) { + this.endPosition.setFlag(endPosition); } - public @Nullable Location getQuitLocation() { - return quitLocation.getFlag(); + public Location getQuitPosition() { + return quitPosition.getFlag(); } - public void setQuitLocation(Location quitLocation) { - this.quitLocation.setFlag(quitLocation); + public void setQuitPosition(Location quitPosition) { + this.quitPosition.setFlag(quitPosition); } - public @Nullable Location getLobbyLocation() { - return lobbyLocation.getFlag(); + public Location getLobbyPosition() { + return lobbyPosition.getFlag(); } - public void setLobbyLocation(Location lobbyLocation) { - this.lobbyLocation.setFlag(lobbyLocation); + public void setLobbyPosition(Location lobbyPosisiton) { + this.lobbyPosition.setFlag(lobbyPosisiton); } public String getName(boolean useDisplay) { @@ -900,14 +897,6 @@ 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(); } @@ -973,12 +962,12 @@ public void setRegenDelay(int regenDelay) { this.regenDelay.setFlag(regenDelay); } - public int getLives() { - return lives.getFlag().intValue(); + public float getLives() { + return lives.getFlag(); } - public void setLives(int lives) { - this.lives.setFlag((float) lives); + public void setLives(float lives) { + this.lives.setFlag(lives); } public int getFloorDegenTime() { @@ -1131,10 +1120,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_SIGN); + obj = (MenuItemString) gameTypeName.getMenuItem("Gametype Description", Material.OAK_WALL_SIGN); obj.setAllowNull(true); itemsMain.add(obj); - obj = (MenuItemString) displayName.getMenuItem("Display Name", Material.OAK_SIGN); + obj = (MenuItemString) displayName.getMenuItem("Display Name", Material.OAK_WALL_SIGN); obj.setAllowNull(true); itemsMain.add(obj); itemsMain.add(new MenuItemNewLine()); @@ -1228,7 +1217,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)); @@ -1248,7 +1237,6 @@ 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()); //--------------// @@ -1314,7 +1302,7 @@ public void setValue(Integer value) { //--------------// List itemsFlags = new ArrayList<>(getFlags().size()); for (String flag : getFlags()) { - itemsFlags.add(new MenuItemFlag(Material.OAK_SIGN, flag, getFlags())); + itemsFlags.add(new MenuItemFlag(Material.OAK_WALL_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 1c500392a..ce6069e4e 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,20 +115,16 @@ 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(); @@ -138,9 +134,8 @@ 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 814f7b5a1..0aaed6cf9 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,6 +17,7 @@ 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 8b1907e77..fc289d9d4 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,63 +5,49 @@ 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.*; -import org.bukkit.block.data.Directional; +import org.bukkit.block.BlockState; +import org.bukkit.block.Container; +import org.bukkit.block.Sign; 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 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 Location spawnLocation = null; + private Location currentLocation = null; + private BlockState spawnData = 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(@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(); + 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(); this.team = team; - 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; - } + this.setMinigame(minigame); + respawnTime = Minigames.getPlugin().getConfig().getInt("multiplayer.ctf.flagrespawntime"); } - public @NotNull Location getSpawnLocation() { + public Location getSpawnLocation() { return spawnLocation; } - public @Nullable Location getCurrentLocation() { + public void setSpawnLocation(Location spawnLocation) { + this.spawnLocation = spawnLocation; + } + + public Location getCurrentLocation() { return currentLocation; } @@ -77,12 +63,17 @@ public void setAtHome(boolean atHome) { this.atHome = atHome; } - public @Nullable Team getTeam() { + public 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) { @@ -113,7 +104,7 @@ public Location spawnFlag(Location location) { blockBelow.setY(blockBelow.getY() + 1); } - Location newLocation = blockBelow.clone(); + newLocation = blockBelow.clone(); newLocation.setY(newLocation.getY() + 1); // Converting wall signs to normal signs, if necessary @@ -132,7 +123,7 @@ public Location spawnFlag(Location location) { atHome = false; for (int i = 0; i < 4; i++) { - sign.getSide(Side.FRONT).line(i, signText.get(i)); + sign.getSide(Side.FRONT).setLine(i, signText[i]); } sign.update(); currentLocation = newLocation.clone(); @@ -169,7 +160,7 @@ public void respawnFlag() { sign.setWaxed(true); for (int i = 0; i < 4; i++) { - sign.getSide(Side.FRONT).line(i, signText.get(i)); + sign.getSide(Side.FRONT).setLine(i, signText[i]); } sign.update(); } @@ -180,10 +171,14 @@ public void stopTimer() { } } - public @NotNull Minigame getMinigame() { + public 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(), () -> { @@ -216,8 +211,4 @@ 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 b58eeaf73..f6442dfb5 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 (1 + Math.abs(pos1.x() - pos2.x())) * (1 + Math.abs(pos1.z() - pos2.z())); + return Math.min(1, Math.abs(pos1.x() - pos2.x())) * Math.min(1, Math.abs(pos1.z() - pos2.z())); } public double getVolume() { - return getBaseArea() * (1 + Math.abs(pos1.y() - pos2.y())); + return getBaseArea() * Math.min(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 f2b24e304..f40ad5552 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 offlineMinigamePlayer; + private OfflineMinigamePlayer oply; private final StoredPlayerCheckpoints spc; private List claimedRewards = new ArrayList<>(); private int lateJoinTimer = -1; @@ -177,11 +177,10 @@ 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))); @@ -210,7 +209,7 @@ public void storePlayerData() { this.player.setLevel(0); this.player.setExp(0); - this.offlineMinigamePlayer = new OfflineMinigamePlayer(this.getPlayer().getUniqueId(), storedItems, storedArmour, food, + this.oply = new OfflineMinigamePlayer(this.getPlayer().getUniqueId(), storedItems, storedArmour, food, health, saturation, lastGM, exp, level, this.getPlayer().getLocation()); this.player.updateInventory(); } @@ -219,35 +218,35 @@ public void restorePlayerData() { this.player.getInventory().clear(); this.player.getInventory().setArmorContents(null); - 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.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.setHealth(20); else - this.player.setHealth(this.offlineMinigamePlayer.getHealth()); - this.player.setSaturation(this.offlineMinigamePlayer.getSaturation()); + this.player.setHealth(this.oply.getHealth()); + this.player.setSaturation(this.oply.getSaturation()); this.player.setScoreboard(Objects.requireNonNullElseGet(this.lastScoreboard, () -> this.player.getServer().getScoreboardManager().getMainScoreboard())); - if (this.offlineMinigamePlayer.getExp() >= 0) { - this.player.setExp(this.offlineMinigamePlayer.getExp()); - this.player.setLevel(this.offlineMinigamePlayer.getLevel()); + if (this.oply.getExp() >= 0) { + this.player.setExp(this.oply.getExp()); + this.player.setLevel(this.oply.getLevel()); } this.startPos = null; this.player.resetPlayerWeather(); this.player.resetPlayerTime(); this.allowGMChange = true; this.allowTP = true; - this.player.setGameMode(this.offlineMinigamePlayer.getLastGamemode()); + this.player.setGameMode(this.oply.getLastGamemode()); - this.offlineMinigamePlayer.deletePlayerData(); - this.offlineMinigamePlayer = null; + this.oply.deletePlayerData(); + this.oply = null; this.player.updateInventory(); } public boolean hasStoredData() { - return this.offlineMinigamePlayer != null; + return this.oply != null; } public boolean getAllowTeleport() { @@ -643,11 +642,11 @@ public void showSelection(final boolean clear) { } public OfflineMinigamePlayer getOfflineMinigamePlayer() { - return this.offlineMinigamePlayer; + return this.oply; } public void setOfflineMinigamePlayer(final OfflineMinigamePlayer oply) { - this.offlineMinigamePlayer = oply; + this.oply = oply; } public StoredPlayerCheckpoints getStoredPlayerCheckpoints() { 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 deleted file mode 100644 index 619166eb9..000000000 --- a/Minigames/src/main/java/au/com/mineauz/minigames/recorder/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * 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 69206136a..eaf681fa1 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,12 +2,7 @@ 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; @@ -19,15 +14,12 @@ 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()); @@ -53,13 +45,6 @@ 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]; @@ -135,27 +120,6 @@ 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 967ab0c99..d708a0df2 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,8 +12,6 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; -import java.util.List; - public class DegenAreaMode implements ToolMode { @Override @@ -27,8 +25,8 @@ public String getDisplayName() { } @Override - public List getDescription() { - return List.of("Selects the degeneration", "area with right click", "finalise with left"); + public String getDescription() { + return "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 7dbdaadae..845b5e0af 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,8 +9,6 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; -import java.util.List; - public class EndPositionMode implements ToolMode { @Override @@ -24,8 +22,8 @@ public String getDisplayName() { } @Override - public List getDescription() { - return List.of("Sets the end", "position"); + public String getDescription() { + return "Sets the end;position"; } @Override @@ -42,7 +40,7 @@ public void onLeftClick(MinigamePlayer player, Minigame minigame, @Override public void onRightClick(MinigamePlayer player, Minigame minigame, Team team, PlayerInteractEvent event) { - minigame.setEndLocation(player.getLocation()); + minigame.setEndPosition(player.getLocation()); player.sendInfoMessage("Set end position."); } @@ -58,8 +56,8 @@ public void onEntityRightClick(MinigamePlayer player, Minigame minigame, Team te @Override public void select(MinigamePlayer player, Minigame minigame, Team team) { - if (minigame.getEndLocation() != null) { - player.getPlayer().sendBlockChange(minigame.getEndLocation(), + if (minigame.getEndPosition() != null) { + player.getPlayer().sendBlockChange(minigame.getEndPosition(), Material.SKELETON_SKULL.createBlockData()); player.sendInfoMessage("Selected end position (marked with skull)"); } else { @@ -69,9 +67,9 @@ public void select(MinigamePlayer player, Minigame minigame, Team team) { @Override public void deselect(MinigamePlayer player, Minigame minigame, Team team) { - if (minigame.getEndLocation() != null) { - player.getPlayer().sendBlockChange(minigame.getEndLocation(), - minigame.getEndLocation().getBlock().getBlockData()); + if (minigame.getEndPosition() != null) { + player.getPlayer().sendBlockChange(minigame.getEndPosition(), + minigame.getEndPosition().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 f29cb55f6..f2e38ab95 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,8 +9,6 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; -import java.util.List; - public class LobbyPositionMode implements ToolMode { @Override @@ -24,8 +22,8 @@ public String getDisplayName() { } @Override - public List getDescription() { - return List.of("Sets the lobby", "position"); + public String getDescription() { + return "Sets the lobby;position"; } @Override @@ -42,7 +40,7 @@ public void onLeftClick(MinigamePlayer player, Minigame minigame, @Override public void onRightClick(MinigamePlayer player, Minigame minigame, Team team, PlayerInteractEvent event) { - minigame.setLobbyLocation(player.getLocation()); + minigame.setLobbyPosition(player.getLocation()); player.sendInfoMessage("Set lobby position."); } @@ -58,8 +56,8 @@ public void onEntityRightClick(MinigamePlayer player, Minigame minigame, Team te @Override public void select(MinigamePlayer player, Minigame minigame, Team team) { - if (minigame.getLobbyLocation() != null) { - player.getPlayer().sendBlockChange(minigame.getLobbyLocation(), Material.SKELETON_SKULL.createBlockData()); + if (minigame.getLobbyPosition() != null) { + player.getPlayer().sendBlockChange(minigame.getLobbyPosition(), Material.SKELETON_SKULL.createBlockData()); player.sendInfoMessage("Selected lobby position (marked with skull)"); } else { player.sendMessage("No lobby position set!", MinigameMessageType.ERROR); @@ -68,9 +66,9 @@ public void select(MinigamePlayer player, Minigame minigame, Team team) { @Override public void deselect(MinigamePlayer player, Minigame minigame, Team team) { - if (minigame.getLobbyLocation() != null) { - player.getPlayer().sendBlockChange(minigame.getLobbyLocation(), - minigame.getLobbyLocation().getBlock().getBlockData()); + if (minigame.getLobbyPosition() != null) { + player.getPlayer().sendBlockChange(minigame.getLobbyPosition(), + minigame.getLobbyPosition().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 58571807c..cb41fe60e 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 toolMode : ToolModes.getToolModes()) { - men.addItem(new MenuItemToolMode(toolMode.getDisplayName(), toolMode.getDescription(), toolMode.getIcon(), toolMode)); + for (ToolMode m : ToolModes.getToolModes()) { + men.addItem(new MenuItemToolMode(m.getDisplayName(), List.of(m.getDescription()), m.getIcon(), m)); } 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 e86d20a05..8a2eb585f 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,8 +9,6 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; -import java.util.List; - public class QuitPositionMode implements ToolMode { @Override @@ -24,8 +22,8 @@ public String getDisplayName() { } @Override - public List getDescription() { - return List.of("Sets the quit", "position"); + public String getDescription() { + return "Sets the quit;position"; } @Override @@ -42,7 +40,7 @@ public void onLeftClick(MinigamePlayer player, Minigame minigame, @Override public void onRightClick(MinigamePlayer player, Minigame minigame, Team team, PlayerInteractEvent event) { - minigame.setQuitLocation(player.getLocation()); + minigame.setQuitPosition(player.getLocation()); player.sendInfoMessage("Set quit position."); } @@ -58,8 +56,8 @@ public void onEntityRightClick(MinigamePlayer player, Minigame minigame, Team te @Override public void select(MinigamePlayer player, Minigame minigame, Team team) { - if (minigame.getQuitLocation() != null) { - player.getPlayer().sendBlockChange(minigame.getQuitLocation(), Material.SKELETON_SKULL.createBlockData()); + if (minigame.getQuitPosition() != null) { + player.getPlayer().sendBlockChange(minigame.getQuitPosition(), Material.SKELETON_SKULL.createBlockData()); player.sendInfoMessage("Selected quit position (marked with skull)"); } else { player.sendMessage("No quit position set!", MinigameMessageType.ERROR); @@ -68,9 +66,9 @@ public void select(MinigamePlayer player, Minigame minigame, Team team) { @Override public void deselect(MinigamePlayer player, Minigame minigame, Team team) { - if (minigame.getQuitLocation() != null) { - player.getPlayer().sendBlockChange(minigame.getQuitLocation(), - minigame.getQuitLocation().getBlock().getBlockData()); + if (minigame.getQuitPosition() != null) { + player.getPlayer().sendBlockChange(minigame.getQuitPosition(), + minigame.getQuitPosition().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 34608b3a7..5f7be1457 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 List getDescription() { - return List.of("Selects an area", "for a regen region.", "Create via left click"); + public String getDescription() { + return "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 77386a514..a0b1c1fb8 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,8 +9,6 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; -import java.util.List; - public class SpectatorPositionMode implements ToolMode { @Override @@ -24,8 +22,8 @@ public String getDisplayName() { } @Override - public List getDescription() { - return List.of("Sets the spectator", "join position"); + public String getDescription() { + return "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 1bff95f82..09e2457d3 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,8 +12,6 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; -import java.util.List; - public class StartPositionMode implements ToolMode { @Override @@ -27,8 +25,8 @@ public String getDisplayName() { } @Override - public List getDescription() { - return List.of("Sets the starting", "positions for a team", "or player"); + public String getDescription() { + return "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 742f03e8d..30ce5b249 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,19 +8,13 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; -import java.util.List; - public interface ToolMode { String getName(); String getDisplayName(); - /** - * 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(); + String getDescription(); Material getIcon(); diff --git a/Minigames/src/main/resources/config.yml b/Minigames/src/main/resources/config.yml index 006d0a290..d049fb9a4 100644 --- a/Minigames/src/main/resources/config.yml +++ b/Minigames/src/main/resources/config.yml @@ -40,6 +40,9 @@ 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 7a639ed38..e70a2e368 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 (multiplayer) / starting (singleplayer) position! +minigame.error.noLobby=This Minigame has no lobby 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,7 +191,6 @@ 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 @@ -269,4 +268,3 @@ 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 9ff68547a..7a06bf109 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 (multiplayer) / starting (singleplayer) position! +minigame.error.noLobby=This Minigame has no lobby 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,5 +328,4 @@ 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 -minigame.resource.command.description="" \ No newline at end of file +minigame.resourcepack.command.invalidpack=The information could not be used to create a pack \ 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 e941f82ec..44051823e 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 (multiplayer) / starting (singleplayer) position! +minigame.error.noLobby=This Minigame has no lobby 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 0be5d68dd..87039add6 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 GreenSurvivors +author: _Razz_ Schmoller Addstar Narimm 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 438ff1543..d2228f301 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 2adebcc89..03670c075 100644 --- a/Minigames/src/main/resources/resourcepack/pack.mcmeta +++ b/Minigames/src/main/resources/resourcepack/pack.mcmeta @@ -1,6 +1,6 @@ { "pack": { - "pack_format": 18, + "pack_format": 4, "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 32f26bbe5..eac1252ad 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.getLobbyLocation()); + Assertions.assertNotSame(player.getLocation(), game.getLobbyPosition()); 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 1c5335244..4ffa2058d 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.setQuitLocation(quit); + game.setQuitPosition(quit); Location lobby = new Location(world, 0, 5., 0); - game.setLobbyLocation(lobby); + game.setLobbyPosition(lobby); Location end = new Location(world, 0, 25, 0); - game.setEndLocation(end); + game.setEndPosition(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 e280edd4d..d8d86d03b 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); - setQuitLocation(quit); - setLobbyLocation(lobby); - setEndLocation(end); + setQuitPosition(quit); + setLobbyPosition(lobby); + setEndPosition(end); setEnabled(true); setStartWaitTime(5); setTimer(5); diff --git a/Regions/pom.xml b/Regions/pom.xml index 5bc3638e4..abd93cfca 100644 --- a/Regions/pom.xml +++ b/Regions/pom.xml @@ -38,7 +38,7 @@ org.apache.maven.plugins maven-source-plugin - 3.3.0 + 3.2.1 attach-sources @@ -63,7 +63,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.3.0 + 3.2.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 f93e0d480..d62b7a1ec 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 List getDescription() { - return List.of("Creates a node where", "you are standing", "on right click"); + public String getDescription() { + return "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 bd094eab9..77b4b3474 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 e2fd26ea0..c7b827911 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionEvents.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionEvents.java @@ -202,44 +202,26 @@ private void playerQuit(QuitMinigameEvent event) { } @EventHandler(ignoreCancelled = true) - private void playersEndPhase(EndPhaseMinigameEvent event) { + private void playersEnd(EndMinigameEvent 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_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()) { + node.execute(Triggers.getTrigger("GAME_END"), 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 59b5d0561..48431a8bf 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionModule.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionModule.java @@ -26,6 +26,7 @@ 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 d2a393e1d..98340bdad 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionNodeEditToolMode.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/RegionNodeEditToolMode.java @@ -20,7 +20,6 @@ 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; @@ -38,8 +37,8 @@ public String getDisplayName() { } @Override - public List getDescription() { - return List.of("Allows you to simply", "edit regions and nodes", "with right click"); + public String getDescription() { + return "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 1a3c7de27..778d35f2d 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 List getDescription() { - return List.of("Selects an area", "for a region.", "Create via left click"); + public String getDescription() { + return "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 36c609e29..fd8ec805d 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,6 +154,7 @@ 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); @@ -211,6 +212,7 @@ private ArrayList cleanUpBlockPool() { return output; } + @Override public String getName() { return "MEMORY_SWAP_BLOCK"; @@ -229,6 +231,7 @@ public void describe(Map out) { out.put("White/Blacklist", wbList.getFlag()); } + @Override public boolean useInRegions() { return true; @@ -319,6 +322,7 @@ 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 a6ae3954d..d98ad0953 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,20 +60,15 @@ public void executeRegionAction(MinigamePlayer player, public void executeNodeAction(MinigamePlayer player, Node node) { debug(player, node); - BlockData bdata; + BlockData bdata = Material.REDSTONE_BLOCK.createBlockData(); if (torch.getFlag()) { bdata = Material.REDSTONE_TORCH.createBlockData(); - - if (bdata instanceof Lightable lightable) { - lightable.setLit(true); - } - } else { - bdata = Material.REDSTONE_BLOCK.createBlockData(); + if (bdata instanceof Lightable) + ((Lightable) bdata).setLit(true); } 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 fd7115af6..23c1dc62c 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 c1a0b1da6..f03077108 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,6 +1,7 @@ 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; @@ -9,7 +10,6 @@ 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 239f55d30..7df57d3fb 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,10 +1,11 @@ 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 e1ffac82d..7a2f71a34 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,12 +60,7 @@ public void executeNodeAction(MinigamePlayer player, Node node) { } private void execute(MinigamePlayer player) { - Material mat = Material.getMaterial(type.getFlag()); - - if (mat == null) { - return; - } - ItemStack match = new ItemStack(mat, count.getFlag()); + ItemStack match = new ItemStack(Material.getMaterial(type.getFlag()), count.getFlag()); ItemStack matched = null; boolean remove = false; int slot = 0; @@ -85,9 +80,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 6af8d72ec..e696cdb9c 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,6 +25,7 @@ * @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"); @@ -81,7 +82,12 @@ 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(), () -> toExecute.execute(Triggers.getTrigger("TIMED_REMOTE"), player), delay.getFlag()); + Bukkit.getScheduler().runTaskLater(Main.getPlugin(), new Runnable() { + @Override + public void run() { + 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 45778367c..0f7708ae9 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,11 +55,10 @@ 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 e6641a06d..44d723e82 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,11 +112,7 @@ 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 bfbe706b8..c7edc0ed1 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,6 +1,5 @@ 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; @@ -57,18 +56,12 @@ public boolean checkNodeCondition(MinigamePlayer player, Node node) { } private boolean check(Minigame mg) { - 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; - } + int timeLeft = mg.getMinigameTimer().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 deleted file mode 100644 index 47e67e5c0..000000000 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/GameEndPhaseTrigger.java +++ /dev/null @@ -1,24 +0,0 @@ -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/GameEndedTrigger.java b/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/GameEndTrigger.java similarity index 81% rename from Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/GameEndedTrigger.java rename to Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/GameEndTrigger.java index d68be2c36..7a4e89213 100644 --- a/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/GameEndedTrigger.java +++ b/Regions/src/main/java/au/com/mineauz/minigamesregions/triggers/GameEndTrigger.java @@ -1,10 +1,10 @@ package au.com.mineauz.minigamesregions.triggers; -public class GameEndedTrigger implements Trigger { +public class GameEndTrigger implements Trigger { @Override public String getName() { - return "GAME_ENDED"; + return "GAME_END"; } @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 2a851adf3..013569e4c 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 true; + return false; } } 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 0301de60f..7c0d306a8 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,9 +8,6 @@ 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()); @@ -19,8 +16,7 @@ public class Triggers { addTrigger(new PlayerKilledTrigger()); addTrigger(new EnterTrigger()); addTrigger(new MoveInRegionTrigger()); - addTrigger(new GameEndPhaseTrigger()); - addTrigger(new GameEndedTrigger()); + addTrigger(new GameEndTrigger()); addTrigger(new GameJoinTrigger()); addTrigger(new GameQuitTrigger()); addTrigger(new GameStartTrigger()); @@ -46,10 +42,6 @@ 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!"); @@ -57,18 +49,8 @@ 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) { - trigger = trigger.toUpperCase(); - String renamedTrigger = renamedTriggers.get(trigger); - - if (renamedTrigger != null) { - return triggers.get(renamedTrigger.toUpperCase()); - } else { - return triggers.get(trigger); - } + return triggers.get(trigger.toUpperCase()); } 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 ef80203e8..6365a298f 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 @NotNull Component name() { - return Component.text("Null"); + public Component name() { + return null; } @Override diff --git a/Regions/src/main/resources/plugin.yml b/Regions/src/main/resources/plugin.yml index d0845e1dd..e57e361b0 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 GreenSurvivors +author: _Razz_ AddstarMC 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 6eef63548..5f9ffc885 100644 --- a/minigamesdistribution/src/assembly/bin.xml +++ b/minigamesdistribution/src/assembly/bin.xml @@ -18,10 +18,7 @@ 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 5c7a5c21f..8bea563f0 100644 --- a/pom.xml +++ b/pom.xml @@ -135,7 +135,7 @@ 4.13.2 test - @@ -165,32 +165,49 @@ maven-assembly-plugin - 3.6.0 + 3.5.0 org.apache.maven.plugins maven-javadoc-plugin - 3.6.0 + 3.5.0 + + + org.apache.maven.plugins + maven-source-plugin + 3.2.1 + + + attach-sources + + jar + + package + + + + false + org.apache.maven.plugins maven-release-plugin - 3.0.1 + 3.0.0 org.apache.maven.plugins maven-dependency-plugin - 3.6.1 + 3.5.0 org.apache.maven.plugins maven-project-info-reports-plugin - 3.4.5 + 3.1.1 org.apache.maven.plugins maven-surefire-plugin - 3.2.1 + 3.0.0-M6 @@ -198,7 +215,7 @@ org.jacoco jacoco-maven-plugin - 0.8.11 + 0.8.5 prepare @@ -217,7 +234,7 @@ org.codehaus.mojo versions-maven-plugin - 2.16.1 + 2.15.0 org.apache.maven.plugins