From 96255e17ce745b66f1b1e04a26dd1aa8f858fca5 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sat, 27 Mar 2021 09:56:25 -0500 Subject: [PATCH 1/4] yup, this is broken --- pom.xml | 2 +- src/main/resources/plugin.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 31fe891..994e3ab 100644 --- a/pom.xml +++ b/pom.xml @@ -82,7 +82,7 @@ org.spigotmc spigot-api - 1.10.2-R0.1-SNAPSHOT + 1.13.2-R0.1-SNAPSHOT provided diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a94d149..3434728 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: Movecraft-Warfare depend: [Movecraft, Movecraft-Repair, WorldGuard, WorldEdit] version: ${project.version} -api-version: 1.10 +api-version: 1.13 description: Movecraft Warfare Addon authors: [TylerS1066, cccm5, eirik1996, BaccaYarro] website: https://github.com/APDevTeam/Movecraft-Warfare From 6cb9881a1203f14ad8f987d13646d7c5e72d6a0a Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sat, 27 Mar 2021 13:31:58 -0500 Subject: [PATCH 2/4] Update maven.yml --- .github/workflows/maven.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index d6b1a3c..1094be8 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -15,9 +15,8 @@ jobs: - name: Checkout Movecraft uses: actions/checkout@v2 with: - repository: 'TylerS1066/Movecraft' + repository: 'APDevTeam/Movecraft' path: Movecraft - ref: 'wg2' - name: Checkout Movecraft-Repair uses: actions/checkout@v2 with: From 2c6a8b4fde0036d93aaffce89fe1f4363af9fb6d Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 28 Mar 2021 04:51:33 -0500 Subject: [PATCH 3/4] Experimental 1.13+ support --- pom.xml | 2 +- .../warfare/listener/BlockListener.java | 80 +++++++++++++++---- 2 files changed, 64 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 994e3ab..737bbf4 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.countercraft.movecraft.warfare Movecraft-Warfare - 0.5.2 + 0.5.3 jar Movecraft-Warfare diff --git a/src/main/java/net/countercraft/movecraft/warfare/listener/BlockListener.java b/src/main/java/net/countercraft/movecraft/warfare/listener/BlockListener.java index 0e31a80..c0b6631 100644 --- a/src/main/java/net/countercraft/movecraft/warfare/listener/BlockListener.java +++ b/src/main/java/net/countercraft/movecraft/warfare/listener/BlockListener.java @@ -16,51 +16,77 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.scheduler.BukkitRunnable; +import org.jetbrains.annotations.NotNull; -import java.util.Arrays; +import java.util.HashSet; import java.util.Iterator; import java.util.List; public class BlockListener implements Listener { - final int[] fragileBlocks = new int[]{26, 34, 50, 55, 63, 64, 65, 68, 69, 70, 71, 72, 75, 76, 77, 93, 94, 96, 131, 132, 143, 147, 148, 149, 150, 151, 171, 323, 324, 330, 331, 356, 404}; + private final HashSet fragileBlocks; private long lastDamagesUpdate = 0; + public BlockListener() { + fragileBlocks = new HashSet<>(); + for(Material m : Material.values()) { + String name = m.name(); + if(name.contains("SIGN") || + name.contains("DOOR") || + name.contains("PRESSURE_PLATE") || + name.contains("CARPET") || + name.contains("BED") || + name.contains("BUTTON") || + name.contains("TORCH") || + name.contains("TRIPWIRE") || + name.contains("PISTON_HEAD") || + name.contains("LEVER") || + name.contains("LADDER") || + name.contains("REDSTONE") || + name.contains("REPEATER") || + name.contains("COMPARATOR") || + name.contains("DAYLIGHT_DETECTOR")) { + fragileBlocks.add(m); + } + } + + fragileBlocks.remove(Material.REDSTONE_BLOCK); + } + @EventHandler(priority = EventPriority.NORMAL) public void explodeEvent(EntityExplodeEvent e) { List assaults = MovecraftWarfare.getInstance().getAssaultManager() != null ? MovecraftWarfare.getInstance().getAssaultManager().getAssaults() : null; - if (assaults == null || assaults.size() == 0) { + if (assaults == null || assaults.size() == 0) return; - } for (final Assault assault : assaults) { + if(e.getLocation().getWorld() != assault.getWorld()) + continue; + Iterator i = e.blockList().iterator(); while (i.hasNext()) { Block b = i.next(); - if (b.getWorld() != assault.getWorld()) - continue; - + // first see if it is outside the region area Location l = b.getLocation(); if (!MovecraftWorldGuard.getInstance().getWGUtils().regionContains(assault.getRegionName(), l)) continue; - // first see if it is outside the destroyable area MovecraftLocation min = assault.getMinPos(); MovecraftLocation max = assault.getMaxPos(); + // remove it outside assault area if (l.getBlockX() < min.getX() || l.getBlockX() > max.getX() || l.getBlockZ() < min.getZ() || - l.getBlockZ() > max.getZ() || - !Config.AssaultDestroyableBlocks.contains(b.getType()) || - Arrays.binarySearch(fragileBlocks, b.getRelative(BlockFace.SOUTH).getTypeId()) >= 0 || - Arrays.binarySearch(fragileBlocks, b.getRelative(BlockFace.DOWN).getTypeId()) >= 0 || - Arrays.binarySearch(fragileBlocks, b.getRelative(BlockFace.UP).getTypeId()) >= 0 || - Arrays.binarySearch(fragileBlocks, b.getRelative(BlockFace.EAST).getTypeId()) >= 0 || - Arrays.binarySearch(fragileBlocks, b.getRelative(BlockFace.WEST).getTypeId()) >= 0 || - Arrays.binarySearch(fragileBlocks, b.getRelative(BlockFace.NORTH).getTypeId()) >= 0) { + l.getBlockZ() > max.getZ()) i.remove(); - } + // remove if not destroyable + if(!Config.AssaultDestroyableBlocks.contains(b.getType())) + i.remove(); + + // remove if fragile + if(isFragile(b)) + i.remove(); // whether or not you actually destroyed the block, add to damages long damages = assault.getDamages() + Config.AssaultDamagesPerBlock; @@ -88,4 +114,24 @@ public void run() { } } } + + private boolean isFragile(@NotNull Block base) { + for(Block b : getNearbyBlocks(base)) { + if(fragileBlocks.contains(b.getType())) + return true; + } + return false; + } + + @NotNull + private HashSet getNearbyBlocks(@NotNull Block b) { + HashSet blocks = new HashSet<>(); + blocks.add(b.getRelative(BlockFace.SOUTH)); + blocks.add(b.getRelative(BlockFace.DOWN)); + blocks.add(b.getRelative(BlockFace.UP)); + blocks.add(b.getRelative(BlockFace.EAST)); + blocks.add(b.getRelative(BlockFace.WEST)); + blocks.add(b.getRelative(BlockFace.NORTH)); + return blocks; + } } \ No newline at end of file From d915978d4b6f01885a4c19955f512c4cf042473d Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 28 Mar 2021 05:05:23 -0500 Subject: [PATCH 4/4] Fix some issues with logging out --- .../warfare/siege/SiegeProgressTask.java | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/countercraft/movecraft/warfare/siege/SiegeProgressTask.java b/src/main/java/net/countercraft/movecraft/warfare/siege/SiegeProgressTask.java index 13c1093..718d3ac 100644 --- a/src/main/java/net/countercraft/movecraft/warfare/siege/SiegeProgressTask.java +++ b/src/main/java/net/countercraft/movecraft/warfare/siege/SiegeProgressTask.java @@ -30,7 +30,7 @@ public void run() { return; } siege.setJustCommenced(false); - @NotNull Player siegeLeader = Movecraft.getInstance().getServer().getPlayer(siege.getPlayerUUID()); + @Nullable Player siegeLeader = Movecraft.getInstance().getServer().getPlayer(siege.getPlayerUUID()); @Nullable Craft siegeCraft = CraftManager.getInstance().getCraftByPlayer(siegeLeader); if(timeLeft > 10) { @@ -47,7 +47,7 @@ public void run() { else { Bukkit.getServer().broadcastMessage(String.format( I18nSupport.getInternationalisedString("Siege - Flagship Not In Box"), - siege.getName(), siegeLeader.getDisplayName()) + siege.getName(), getSiegeLeaderName(siegeLeader)) + formatMinutes(timeLeft)); } } @@ -61,9 +61,9 @@ public void run() { } } - private void endSiege(@Nullable Craft siegeCraft, @NotNull Player siegeLeader) { - if (leaderPilotingShip(siegeCraft)) { - if(MovecraftWorldGuard.getInstance().getWGUtils().craftFullyInRegion(siege.getAttackRegion(), siegeLeader.getWorld(), siegeCraft)) { + private void endSiege(@Nullable Craft siegeCraft, @Nullable Player siegeLeader) { + if (leaderPilotingShip(siegeCraft) && siegeLeader != null) { + if(MovecraftWorldGuard.getInstance().getWGUtils().craftFullyInRegion(siege.getAttackRegion(), siegeCraft.getW(), siegeCraft)) { Bukkit.getServer().broadcastMessage(String.format(I18nSupport.getInternationalisedString("Siege - Siege Success"), siege.getName(), siegeLeader.getDisplayName())); winSiege(siegeLeader); @@ -81,24 +81,25 @@ private void endSiege(@Nullable Craft siegeCraft, @NotNull Player siegeLeader) { private void winSiege(@NotNull Player siegeLeader) { Bukkit.getPluginManager().callEvent(new SiegeWinEvent(siege)); MovecraftWorldGuard.getInstance().getWGUtils().clearAndSetOwnership(siege.getCaptureRegion(), siegeLeader.getWorld(), siege.getPlayerUUID()); - processCommands(siegeLeader, true); + processCommands(siegeLeader.getName(), true); } - private void failSiege(@NotNull Player siegeLeader) { + private void failSiege(@Nullable Player siegeLeader) { Bukkit.getPluginManager().callEvent(new SiegeLoseEvent(siege)); + String name = getSiegeLeaderName(siegeLeader); Bukkit.getServer().broadcastMessage(String.format(I18nSupport.getInternationalisedString("Siege - Siege Failure"), - siege.getName(), siegeLeader.getDisplayName())); + siege.getName(), name)); - processCommands(siegeLeader, false); + processCommands(name, false); } - private void processCommands(@NotNull Player siegeLeader, boolean win) { + private void processCommands(@NotNull String siegeLeader, boolean win) { List commands = win ? siege.getCommandsOnWin() : siege.getCommandsOnLose(); for (String command : commands) { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command .replaceAll("%r", siege.getCaptureRegion()) .replaceAll("%c", "" + siege.getCost()) - .replaceAll("%l", siegeLeader.getName())); + .replaceAll("%l", siegeLeader)); } } @@ -108,4 +109,18 @@ private boolean leaderPilotingShip(@Nullable Craft siegeCraft) { else return siege.getCraftsToWin().contains(siegeCraft.getType().getCraftName()); } + + private String getSiegeLeaderName(@Nullable Player siegeLeader) { + String name; + if(siegeLeader == null) { + name = Bukkit.getOfflinePlayer(siege.getPlayerUUID()).getName(); + + if(name == null) + name = "null"; // Note, there's not a better way to deal with this sadly + } + else + name = siegeLeader.getDisplayName(); + + return name; + } }