Skip to content

Commit

Permalink
Disable piloting and repair in assaulted regions (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerS1066 authored Jul 28, 2024
1 parent 04a850d commit 890d5f8
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/localisation/mcwlang_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 890d5f8

Please sign in to comment.