Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable piloting and repair in assaulted regions #39

Merged
merged 1 commit into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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