mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 14:38:55 +00:00
Command changes & greater tp restrictions
This commit is contained in:
1 parent
a0d44d19e9
commit
c658158cf5
6 files changed
+243
-63
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@@ -9,6 +10,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Helper
|
||||
{
|
||||
public static String color(final String input) {
|
||||
@@ -137,4 +140,67 @@ public class Helper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param worldCoord worldCoord
|
||||
* @return List of connected chunks
|
||||
* @author NinjaMandalorian
|
||||
*/
|
||||
private static ArrayList<WorldCoord> getAdjCells(WorldCoord worldCoord) {
|
||||
ArrayList<WorldCoord> ReturnList = new ArrayList<>();
|
||||
|
||||
int[][] XZarray = new int[][]{
|
||||
{-1, 0},
|
||||
{1, 0},
|
||||
{0, -1},
|
||||
{0, 1}
|
||||
}; // Array that contains relative orthogonal shifts from origin
|
||||
for ( int[] pair: XZarray) {
|
||||
// Constructs new WorldCoord for comparison
|
||||
WorldCoord tCoord = new WorldCoord(worldCoord.getWorldName(), worldCoord.getX() + pair[0], worldCoord.getZ() + pair[1]);
|
||||
if (tCoord.getTownOrNull() != null && tCoord.getTownOrNull() == worldCoord.getTownOrNull()) {
|
||||
// If in town, and in same town, adds to return list
|
||||
ReturnList.add(tCoord);
|
||||
}
|
||||
}
|
||||
return ReturnList;
|
||||
}
|
||||
|
||||
/** Gets all adjacently connected townblocks
|
||||
* @param chunkCoord - WorldCoord to check at
|
||||
* @return List of WorldCoords
|
||||
* @author NinjaMandalorian
|
||||
*/
|
||||
public static ArrayList<WorldCoord> getCluster(WorldCoord chunkCoord){
|
||||
// WCoordList is the returning array, SearchList is the to-search list.
|
||||
ArrayList<WorldCoord> WCoordList = new ArrayList<>();
|
||||
ArrayList<WorldCoord> SearchList = new ArrayList<>();
|
||||
SearchList.add(chunkCoord); // Adds 1st chunk to list
|
||||
|
||||
// Iterates through SearchList, to create a full list of every adjacent cell.
|
||||
while (SearchList.size() > 0) {
|
||||
// Gets WorldCoord
|
||||
WorldCoord toSearch = SearchList.get(0);
|
||||
// Gets adjacent cells
|
||||
ArrayList<WorldCoord> adjCells = getAdjCells(toSearch);
|
||||
for (WorldCoord cell : adjCells) {
|
||||
// If in final list, ignore.
|
||||
if (WCoordList.contains(cell)) {
|
||||
continue;
|
||||
// If in to-search list, ignore
|
||||
} else if (SearchList.contains(cell)) {
|
||||
continue;
|
||||
// Otherwise, add to search-list.
|
||||
} else {
|
||||
SearchList.add(cell);
|
||||
}
|
||||
}
|
||||
// Removes from search list and adds to finished list. After checking all adjacent chunks.
|
||||
SearchList.remove(toSearch);
|
||||
WCoordList.add(toSearch);
|
||||
}
|
||||
|
||||
return WCoordList; // Returns list
|
||||
}
|
||||
}
|
||||
@@ -191,16 +191,18 @@ public class Raid {
|
||||
for (String playerName : getActiveRaiders()) {
|
||||
try {
|
||||
Player p = Bukkit.getPlayer(playerName);
|
||||
if(!WorldCoord.parseWorldCoord(p).getTownBlock().getTown().equals(Raid.this.getGatherTown())) {
|
||||
ArrayList<WorldCoord> cluster = Helper.getCluster(Raid.this.getGatherTown().getHomeBlock().getWorldCoord());
|
||||
if(!cluster.contains(WorldCoord.parseWorldCoord(p))) {
|
||||
Raid.this.removeActiveRaider(p.getName());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "By leaving the gathering town you have left the raid on " + Raid.this.getRaidedTown().getName() + "!");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "To rejoin, do /raid join [war] [town]");
|
||||
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NotRegisteredException e) {
|
||||
e.printStackTrace();
|
||||
} catch (TownyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,12 +338,8 @@ public class Raid {
|
||||
//tp to raid town spawn
|
||||
final Player killed = event.getEntity();
|
||||
if(this.getActiveRaiders().contains(killed.getName())) {
|
||||
try {
|
||||
killed.teleport(this.getGatherTown().getSpawn());
|
||||
killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died raiding and have been teleported back to your town's spawn.");
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// killed.teleport(this.getGatherTown().getSpawn());
|
||||
// killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died raiding and have been teleported back to your town's spawn.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,12 +394,8 @@ public class Raid {
|
||||
//tp to raid town spawn
|
||||
final Player killed = event.getEntity();
|
||||
if(this.getActiveRaiders().contains(killed.getName())) {
|
||||
try {
|
||||
killed.teleport(this.getGatherTown().getSpawn());
|
||||
killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died before being raided and have been teleported back to your town's spawn.");
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// killed.teleport(this.getGatherTown().getSpawn());
|
||||
// killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died before being raided and have been teleported back to your town's spawn.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -422,6 +422,15 @@ public class Siege {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getSiegeTicks() {
|
||||
return this.siegeTicks;
|
||||
}
|
||||
|
||||
public void setSiegeTicks(final int siegeTicks) {
|
||||
this.siegeTicks = siegeTicks;
|
||||
}
|
||||
|
||||
|
||||
public War getWar() {
|
||||
return this.war;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,8 @@ package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.TownyWorld;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import com.palmergames.bukkit.towny.object.*;
|
||||
import me.ShermansWorld.AlathraWar.*;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -294,11 +292,17 @@ public class RaidCommands implements CommandExecutor
|
||||
if(raidFound) {
|
||||
//check if gather phase
|
||||
if(raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START) {
|
||||
if(raid.getGatherTown().hasTownBlock(WorldCoord.parseWorldCoord(p))) {
|
||||
raid.addActiveRaider(p.getName());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
|
||||
try {
|
||||
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
|
||||
if(cluster.contains(WorldCoord.parseWorldCoord(p))) {
|
||||
raid.addActiveRaider(p.getName());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
|
||||
}
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot join the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ public class RaidTabCompletion implements TabCompleter {
|
||||
completions.add("abandon");
|
||||
completions.add("list");
|
||||
completions.add("help");
|
||||
completions.add("join");
|
||||
completions.add("leave");
|
||||
return completions;
|
||||
} else if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("start")) {
|
||||
@@ -43,6 +45,20 @@ public class RaidTabCompletion implements TabCompleter {
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("join")) {
|
||||
if (!WarCommands.wars.isEmpty()) {
|
||||
for (War war : WarCommands.wars) {
|
||||
completions.add(war.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("leave")) {
|
||||
if (!WarCommands.wars.isEmpty()) {
|
||||
for (War war : WarCommands.wars) {
|
||||
completions.add(war.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
} else if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("start")) {
|
||||
@@ -52,8 +68,24 @@ public class RaidTabCompletion implements TabCompleter {
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("join")) {
|
||||
if (!TownyAPI.getInstance().getTowns().isEmpty()) {
|
||||
for (Town town : TownyAPI.getInstance().getTowns()) {
|
||||
completions.add(town.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("leave")) {
|
||||
if (!TownyAPI.getInstance().getTowns().isEmpty()) {
|
||||
for (Town town : TownyAPI.getInstance().getTowns()) {
|
||||
completions.add(town.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,9 @@ package me.ShermansWorld.AlathraWar.listeners;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Helper;
|
||||
import me.ShermansWorld.AlathraWar.Raid;
|
||||
import me.ShermansWorld.AlathraWar.Siege;
|
||||
import me.ShermansWorld.AlathraWar.commands.RaidCommands;
|
||||
import me.ShermansWorld.AlathraWar.commands.SiegeCommands;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -11,67 +13,140 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandsListener implements Listener
|
||||
{
|
||||
|
||||
final static String[] prefixes = new String[] {
|
||||
"", "towny", "essentials", "wild", "minecraft"
|
||||
};
|
||||
final static String[] blacklistedLong = new String[] {
|
||||
"n spawn", "nat spawn", "nation spawn",
|
||||
"t spawn", "town spawn"
|
||||
};
|
||||
final static String[] blacklistedShort = new String[] {
|
||||
"home", "homes", "warp", "warps",
|
||||
"wild", "rtp", "spawn", "wilderness", "wildtp",
|
||||
"tpa", "tpahere", "tpaccept", "tpacancel",
|
||||
"etpa", "etpahere", "etpaccept", "etpacancel",
|
||||
"ehome", "ehomes", "ewarp", "ewarps"
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onCommandSend(final PlayerCommandPreprocessEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
String[] args = event.getMessage().split(" ");
|
||||
|
||||
Player p = event.getPlayer();
|
||||
|
||||
//if player is admin, ignore this behavior
|
||||
if (p.hasPermission("!AlathraWar.admin")) return;
|
||||
|
||||
String[] args = event.getMessage().split(" ");
|
||||
/*
|
||||
Prevent any teleport command events from occuring
|
||||
If using PlayerTeleportEvent, it breaks the death logic
|
||||
|
||||
allow n spawn and t spawn for defenders trapped in spawn
|
||||
*/
|
||||
for(Raid raid : RaidCommands.raids) {
|
||||
//Only do this during regular phases, start and end ignored in case something breaks
|
||||
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) {
|
||||
if (args[0].equalsIgnoreCase("/n") || args[0].equalsIgnoreCase("/nat") || args[0].equalsIgnoreCase("/nation")) {
|
||||
if (args[1].equalsIgnoreCase("spawn")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("/t") || args[0].equalsIgnoreCase("/town")) {
|
||||
if (args[1].equalsIgnoreCase("spawn")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
//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) {
|
||||
for (String cmd : blacklistedLong) {
|
||||
//check for each prefix
|
||||
if(parse.equals(prefix + ":" + 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!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//else
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (args.length >= 1) {
|
||||
if (args[0].equalsIgnoreCase("/home")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
//parse what we have, remove the starting slash
|
||||
String parse = args[0].charAt(0) == '/' ? args[0].substring(1, args[0].length() - 1): args[0];
|
||||
for (String prefix : prefixes) {
|
||||
for (String cmd : blacklistedLong) {
|
||||
//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!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("/spawn")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Prevent players from teleporting during a siege
|
||||
*/
|
||||
for(Siege siege : SiegeCommands.sieges) {
|
||||
//Only do this during regular phases, start and end ignored in case something breaks
|
||||
if (siege.getSiegeTicks() > 0) {
|
||||
//only do for active raiders and any defenders
|
||||
if (siege.getAttackerPlayers().contains(p.getName()) || siege.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) {
|
||||
for (String cmd : blacklistedLong) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + ":" + 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!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//else
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("/tpa")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("/tpahere")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("/wild")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("/rtp")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else 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];
|
||||
for (String prefix : prefixes) {
|
||||
for (String cmd : blacklistedLong) {
|
||||
//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!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user