From 890d5f8253e796a37497bad33e034664e7439592 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 28 Jul 2024 14:12:53 -0500 Subject: [PATCH] Disable piloting and repair in assaulted regions (#39) --- .../movecraft/warfare/MovecraftWarfare.java | 4 ++ .../assault/listener/CraftDetectListener.java | 38 +++++++++++++++++++ .../assault/listener/CraftRepairListener.java | 35 +++++++++++++++++ .../localisation/mcwlang_en.properties | 2 + 4 files changed, 79 insertions(+) create mode 100644 src/main/java/net/countercraft/movecraft/warfare/features/assault/listener/CraftDetectListener.java create mode 100644 src/main/java/net/countercraft/movecraft/warfare/features/assault/listener/CraftRepairListener.java diff --git a/src/main/java/net/countercraft/movecraft/warfare/MovecraftWarfare.java b/src/main/java/net/countercraft/movecraft/warfare/MovecraftWarfare.java index d99bdbf..ac85b9d 100644 --- a/src/main/java/net/countercraft/movecraft/warfare/MovecraftWarfare.java +++ b/src/main/java/net/countercraft/movecraft/warfare/MovecraftWarfare.java @@ -10,6 +10,8 @@ import net.countercraft.movecraft.warfare.features.assault.AssaultManager; import net.countercraft.movecraft.warfare.features.assault.RegionDamagedSign; import net.countercraft.movecraft.warfare.features.assault.listener.AssaultExplosionListener; +import net.countercraft.movecraft.warfare.features.assault.listener.CraftDetectListener; +import net.countercraft.movecraft.warfare.features.assault.listener.CraftRepairListener; import net.countercraft.movecraft.warfare.features.siege.SiegeLeaderListener; import net.countercraft.movecraft.warfare.features.siege.SiegeManager; import net.countercraft.movecraft.warfare.localisation.I18nSupport; @@ -100,6 +102,8 @@ public void onEnable() { getServer().getPluginManager().registerEvents(assaultBarManager, this); getServer().getPluginManager().registerEvents(new AssaultExplosionListener(), this); + getServer().getPluginManager().registerEvents(new CraftDetectListener(), this); + getServer().getPluginManager().registerEvents(new CraftRepairListener(), this); getServer().getPluginManager().registerEvents(new RegionDamagedSign(), this); } diff --git a/src/main/java/net/countercraft/movecraft/warfare/features/assault/listener/CraftDetectListener.java b/src/main/java/net/countercraft/movecraft/warfare/features/assault/listener/CraftDetectListener.java new file mode 100644 index 0000000..1aeae3f --- /dev/null +++ b/src/main/java/net/countercraft/movecraft/warfare/features/assault/listener/CraftDetectListener.java @@ -0,0 +1,38 @@ +package net.countercraft.movecraft.warfare.features.assault.listener; + +import net.countercraft.movecraft.craft.Craft; +import net.countercraft.movecraft.events.CraftDetectEvent; +import net.countercraft.movecraft.util.hitboxes.HitBox; +import net.countercraft.movecraft.warfare.localisation.I18nSupport; +import net.countercraft.movecraft.worldguard.MovecraftWorldGuard; +import net.countercraft.movecraft.worldguard.utils.WorldGuardUtils; +import org.bukkit.World; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.jetbrains.annotations.NotNull; + +import java.util.HashSet; +import java.util.Set; + +public class CraftDetectListener implements Listener { + @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) + public void onCraftDetect(@NotNull CraftDetectEvent e) { + Craft craft = e.getCraft(); + HitBox hitBox = craft.getHitBox(); + if (hitBox.isEmpty()) + return; + + WorldGuardUtils wgUtils = MovecraftWorldGuard.getInstance().getWGUtils(); + World w = craft.getWorld(); + for (String regionName : wgUtils.getRegions(hitBox, w)) { + // Detect an assaulted region by one without owners and with TNT denied + if (!wgUtils.isTNTDenied(regionName, w) || !wgUtils.getUUIDOwners(regionName, w).isEmpty()) + continue; + + e.setCancelled(true); + e.setFailMessage(I18nSupport.getInternationalisedString("Assault Detection - Not Permitted")); + return; + } + } +} diff --git a/src/main/java/net/countercraft/movecraft/warfare/features/assault/listener/CraftRepairListener.java b/src/main/java/net/countercraft/movecraft/warfare/features/assault/listener/CraftRepairListener.java new file mode 100644 index 0000000..a6e38dd --- /dev/null +++ b/src/main/java/net/countercraft/movecraft/warfare/features/assault/listener/CraftRepairListener.java @@ -0,0 +1,35 @@ +package net.countercraft.movecraft.warfare.features.assault.listener; + +import net.countercraft.movecraft.repair.events.ProtoRepairCreateEvent; +import net.countercraft.movecraft.util.hitboxes.HitBox; +import net.countercraft.movecraft.warfare.localisation.I18nSupport; +import net.countercraft.movecraft.worldguard.MovecraftWorldGuard; +import net.countercraft.movecraft.worldguard.utils.WorldGuardUtils; +import org.bukkit.World; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.jetbrains.annotations.NotNull; + +import java.util.Set; + +public class CraftRepairListener implements Listener { + @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) + public void onProtoRepairCreate(@NotNull ProtoRepairCreateEvent e) { + HitBox hitBox = e.getProtoRepair().getHitBox(); + if (hitBox.isEmpty()) + return; + + WorldGuardUtils wgUtils = MovecraftWorldGuard.getInstance().getWGUtils(); + World w = e.getProtoRepair().getWorld(); + for (String regionName : wgUtils.getRegions(hitBox, w)) { + // Detect an assaulted region by one without owners and with TNT denied + if (!wgUtils.isTNTDenied(regionName, w) || !wgUtils.getUUIDOwners(regionName, w).isEmpty()) + continue; + + e.setCancelled(true); + e.setFailMessage(I18nSupport.getInternationalisedString("Assault Repair - Not Permitted")); + return; + } + } +} diff --git a/src/main/resources/localisation/mcwlang_en.properties b/src/main/resources/localisation/mcwlang_en.properties index ad311d5..f6c9075 100644 --- a/src/main/resources/localisation/mcwlang_en.properties +++ b/src/main/resources/localisation/mcwlang_en.properties @@ -18,6 +18,8 @@ Assault\ -\ Beacon\ Placement\ Failed=BEACON PLACEMENT FOR %s FAILED, CONTACT AN AssaultInfo\ -\ Must\ Be\ Player=Only Players may get Assault Info AssaultInfo\ -\ No\ Region\ Found=No Assault eligible regions found Assault\ -\ Bar\ Set=Assault Bar now set to +Assault\ Detection\ -\ Not\ Permitted=Detection Failed - Player is not permitted to pilot in this damaged Assault region +Assault\ Repair\ -\ Not\ Permitted=Repair Failed - Player is not permitted to repair in this damaged Assault region Region\ Name=REGION NAME Damages=DAMAGES AssaultInfo\ -\ Cap=MAX DAMAGES