mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 14:38:55 +00:00
fix and complete teleportation and withdrawal during raid/siege
This commit is contained in:
1 parent
6586d92046
commit
63bf909b0c
2 files changed
+108
-39
No files matched your search
@@ -852,14 +852,16 @@ public class Raid {
|
||||
final int homeBlockXCoordRaided = Raid.this.getRaidedTown().getHomeBlock().getCoord().getX() * 16;
|
||||
final int homeBlockZCoordRaided = Raid.this.getRaidedTown().getHomeBlock().getCoord().getZ() * 16;
|
||||
Player p = Bukkit.getPlayer(player);
|
||||
//Carryover from sieges
|
||||
if (Math.abs(p.getLocation().getBlockX() - homeBlockXCoordRaided) <= 200 && Math.abs(p.getLocation().getBlockZ() - homeBlockZCoordRaided) <= 200) {
|
||||
playerCloseToHomeBlockRaid = true;
|
||||
}
|
||||
if(p != null) {
|
||||
//Carryover from sieges
|
||||
if (Math.abs(p.getLocation().getBlockX() - homeBlockXCoordRaided) <= 200 && Math.abs(p.getLocation().getBlockZ() - homeBlockZCoordRaided) <= 200) {
|
||||
playerCloseToHomeBlockRaid = true;
|
||||
}
|
||||
|
||||
WorldCoord playercoord = WorldCoord.parseWorldCoord(Bukkit.getPlayer(player));
|
||||
if (Raid.this.getRaidedTown().hasTownBlock(playercoord) || playerCloseToHomeBlockRaid) {
|
||||
startCombat();
|
||||
WorldCoord playercoord = WorldCoord.parseWorldCoord(Bukkit.getPlayer(player));
|
||||
if (Raid.this.getRaidedTown().hasTownBlock(playercoord) || playerCloseToHomeBlockRaid) {
|
||||
startCombat();
|
||||
}
|
||||
}
|
||||
} catch (TownyException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -6,6 +6,7 @@ import me.ShermansWorld.AlathraWar.Siege;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -17,9 +18,19 @@ public class CommandsListener implements Listener {
|
||||
final static String[] prefixes = new String[]{
|
||||
"", "towny", "essentials", "wild", "minecraft"
|
||||
};
|
||||
final static String[] prefixesTowny = new String[]{
|
||||
"", "towny"
|
||||
};
|
||||
final static String[] blacklistedXLong = new String[]{
|
||||
"n set spawn", "nat set spawn", "nation set spawn",
|
||||
"t set spawn", "town set spawn",
|
||||
"t set homeblock", "town set homeblock",
|
||||
"t set name", "town set name"
|
||||
};
|
||||
final static String[] blacklistedLong = new String[]{
|
||||
"n spawn", "nat spawn", "nation spawn",
|
||||
"t spawn", "town spawn"
|
||||
"t spawn", "town spawn",
|
||||
"t outpost", "town outpost"
|
||||
};
|
||||
final static String[] payment = new String[]{
|
||||
"n withdraw", "nat withdraw", "nation withdraw",
|
||||
@@ -35,17 +46,18 @@ public class CommandsListener implements Listener {
|
||||
};
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onCommandSend(final PlayerCommandPreprocessEvent event) {
|
||||
|
||||
Player p = event.getPlayer();
|
||||
|
||||
//if player is admin, ignore this behavior
|
||||
if (p.hasPermission("!AlathraWar.admin")) return;
|
||||
// if (p.hasPermission("!AlathraWar.admin")) return;
|
||||
|
||||
String[] args = event.getMessage().split(" ");
|
||||
|
||||
/*
|
||||
Prevent any teleport command events from occuring
|
||||
Prevent any teleport command events from occurring
|
||||
If using PlayerTeleportEvent, it breaks the death logic
|
||||
|
||||
allow n spawn and t spawn for defenders trapped in spawn
|
||||
@@ -56,52 +68,78 @@ public class CommandsListener implements Listener {
|
||||
if (raid.getPhase() == RaidPhase.COMBAT || raid.getPhase() == RaidPhase.TRAVEL || raid.getPhase() == RaidPhase.GATHER) {
|
||||
//only do for active raiders and any defenders
|
||||
if (raid.getActiveRaiders().contains(p.getName()) || raid.getDefenders().contains(p.getName())) {
|
||||
//n spawn and t spawn
|
||||
if (args.length >= 2) {
|
||||
//parse what we have, remove the starting sslash
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1, args[0].length() - 1) : args[0]) + " " + args[1];
|
||||
for (String prefix : prefixes) {
|
||||
//set spawn and properties
|
||||
if (args.length >= 3) {
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1] + " " + args[2];
|
||||
for (String prefix : prefixesTowny) {
|
||||
//payment check
|
||||
for (String cmd : payment) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + ":" + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot withdraw money during a raid!");
|
||||
for (String cmd : blacklistedXLong) {
|
||||
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot modify this property during a raid!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//n spawn and t spawn
|
||||
if (args.length >= 2) {
|
||||
//parse what we have, remove the starting sslash
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1];
|
||||
for (String prefix : prefixesTowny) {
|
||||
//payment check
|
||||
for (String cmd : payment) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot withdraw money whilst in a raid!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (String cmd : blacklistedLong) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + ":" + cmd)) {
|
||||
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
//check if in spawn
|
||||
if (p.getWorld().getName().equals("world")) {
|
||||
if (parse.equals("n spawn") || parse.equals("nat spawn") || parse.equals("nation spawn")
|
||||
|| parse.equals("t spawn") || parse.equals("town spawn")
|
||||
|| parse.equals("towny:n spawn") || parse.equals("towny:nat spawn") || parse.equals("towny:nation spawn")
|
||||
|| parse.equals("towny:t spawn") || parse.equals("towny:town spawn")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are stuck in spawn and are allowed to teleport to your town or nation.");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
return;
|
||||
}
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are stuck in spawn and are allowed to teleport to your town or nation.");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eUse /t spawn, or /n spawn"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
//else
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot teleport whilst in a raid!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (args.length >= 1) {
|
||||
}
|
||||
//random tp commands
|
||||
if (args.length >= 1) {
|
||||
//parse what we have, remove the starting slash
|
||||
String parse = args[0].charAt(0) == '/' ? args[0].substring(1, args[0].length() - 1) : args[0];
|
||||
String parse = args[0].charAt(0) == '/' ? args[0].substring(1) : args[0];
|
||||
for (String prefix : prefixes) {
|
||||
for (String cmd : blacklistedShort) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + ":" + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
//spawn world check
|
||||
if (p.getWorld().getName().equals("world")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eUse /t spawn, or /n spawn"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot teleport whilst in a raid!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -120,15 +158,30 @@ public class CommandsListener implements Listener {
|
||||
if (siege.getSiegeTicks() > 0) {
|
||||
//only do for active raiders and any defenders
|
||||
if (siege.getAttackerPlayers().contains(p.getName()) || siege.getDefenders().contains(p.getName())) {
|
||||
//set spawn and properties
|
||||
if (args.length >= 3) {
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1] + " " + args[2];
|
||||
for (String prefix : prefixesTowny) {
|
||||
//payment check
|
||||
for (String cmd : blacklistedXLong) {
|
||||
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot modify this property during a siege!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//n spawn and t spawn
|
||||
if (args.length >= 2) {
|
||||
//parse what we have, remove the starting sslash
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1, args[0].length() - 1) : args[0]) + " " + args[1];
|
||||
for (String prefix : prefixes) {
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1];
|
||||
for (String prefix : prefixesTowny) {
|
||||
//payment check
|
||||
for (String cmd : payment) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + ":" + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot withdraw money during a siege!");
|
||||
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot withdraw money whilst in a siege!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -136,33 +189,47 @@ public class CommandsListener implements Listener {
|
||||
|
||||
for (String cmd : blacklistedLong) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + ":" + cmd)) {
|
||||
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
//check if in spawn
|
||||
if (p.getWorld().getName().equals("world")) {
|
||||
if (parse.equals("n spawn") || parse.equals("nat spawn") || parse.equals("nation spawn")
|
||||
|| parse.equals("t spawn") || parse.equals("town spawn")
|
||||
|| parse.equals("towny:n spawn") || parse.equals("towny:nat spawn") || parse.equals("towny:nation spawn")
|
||||
|| parse.equals("towny:t spawn") || parse.equals("towny:town spawn")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are stuck in spawn and allowed to teleport to your town or nation!");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
return;
|
||||
}
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eUse /t spawn, or /n spawn"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
//else
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot teleport whilst in a siege!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (args.length >= 1) {
|
||||
}
|
||||
//random tp commands
|
||||
if (args.length >= 1) {
|
||||
//parse what we have, remove the starting slash
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1, args[0].length() - 1) : args[0]) + " " + args[1];
|
||||
String parse = args[0].charAt(0) == '/' ? args[0].substring(1) : args[0];
|
||||
for (String prefix : prefixes) {
|
||||
for (String cmd : blacklistedShort) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + ":" + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
//spawn world check
|
||||
if (p.getWorld().getName().equals("world")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eUse /t spawn, or /n spawn"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot teleport whilst in a siege!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user