refactor: cleanup

This commit is contained in:
darksaid98 committed 2023-06-25 04:39:38 +02:00
1 parent 9e5908fecc
commit 75e5aefd3d
27 files changed
+904 -880

No files matched your search

@@ -1,19 +1,15 @@
package me.ShermansWorld.AlathraWar;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.bukkit.Bukkit;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
public class AlathraWarLogger {
File logsFolder;
File log;
final File logsFolder;
final File log;
PrintWriter output = null;
public AlathraWarLogger() {
@@ -46,7 +42,6 @@ public class AlathraWarLogger {
output = new PrintWriter(bw);
} catch (IOException e1) {
Bukkit.getLogger().warning("[AlathraWar] Error in AlathraWarLogger - could not initialize file writer");
return;
}
}
@@ -9,11 +9,11 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
public class Helper
{
public class Helper {
public static String color(final String input) {
return ChatColor.translateAlternateColorCodes('&', input);
}
@@ -37,41 +37,23 @@ public class Helper
for (int i = 0; i < inv.getSize(); ++i) {
final ItemStack is = inv.getItem(i);
if (is != null && (is.getType() == Material.NETHERITE_AXE || is.getType() == Material.NETHERITE_SWORD || is.getType() == Material.DIAMOND_AXE || is.getType() == Material.DIAMOND_SWORD || is.getType() == Material.IRON_AXE || is.getType() == Material.IRON_SWORD)) {
ItemMeta meta = is.getItemMeta();
final Damageable damageable = (Damageable)meta;
if (is.getType() == Material.NETHERITE_SWORD || is.getType() == Material.NETHERITE_AXE) {
damageable.setDamage(damageable.getDamage() + 507);
if (damageable.getDamage() > 2000) {
damageable.setDamage(2030);
}
}
else if (is.getType() == Material.DIAMOND_SWORD || is.getType() == Material.DIAMOND_AXE) {
damageable.setDamage(damageable.getDamage() + 390);
if (damageable.getDamage() > 1500) {
damageable.setDamage(1560);
}
}
else if (is.getType() == Material.IRON_SWORD || is.getType() == Material.IRON_AXE) {
damageable.setDamage(damageable.getDamage() + 62);
if (damageable.getDamage() > 200) {
damageable.setDamage(249);
}
}
else if (is.getType() == Material.TRIDENT) {
damageable.setDamage(damageable.getDamage() + 62);
if (damageable.getDamage() > 200) {
damageable.setDamage(249);
}
}
meta = (ItemMeta)damageable;
final ItemMeta meta = getItemMeta(is);
is.setItemMeta(meta);
}
}
final ItemStack[] armor = p.getInventory().getArmorContents();
for (int j = 0; j < armor.length; ++j) {
if (armor[j] != null) {
final ItemStack is2 = armor[j];
if (is2.getType() == Material.NETHERITE_HELMET || is2.getType() == Material.NETHERITE_CHESTPLATE || is2.getType() == Material.NETHERITE_LEGGINGS || is2.getType() == Material.NETHERITE_BOOTS || is2.getType() == Material.DIAMOND_HELMET || is2.getType() == Material.DIAMOND_CHESTPLATE || is2.getType() == Material.DIAMOND_LEGGINGS || is2.getType() == Material.NETHERITE_BOOTS || is2.getType() == Material.IRON_HELMET || is2.getType() == Material.IRON_CHESTPLATE || is2.getType() == Material.IRON_LEGGINGS || is2.getType() == Material.IRON_BOOTS) {
for (ItemStack itemStack : armor) {
if (itemStack != null) {
if (itemStack.getType() == Material.NETHERITE_HELMET || itemStack.getType() == Material.NETHERITE_CHESTPLATE || itemStack.getType() == Material.NETHERITE_LEGGINGS || itemStack.getType() == Material.NETHERITE_BOOTS || itemStack.getType() == Material.DIAMOND_HELMET || itemStack.getType() == Material.DIAMOND_CHESTPLATE || itemStack.getType() == Material.DIAMOND_LEGGINGS || itemStack.getType() == Material.NETHERITE_BOOTS || itemStack.getType() == Material.IRON_HELMET || itemStack.getType() == Material.IRON_CHESTPLATE || itemStack.getType() == Material.IRON_LEGGINGS || itemStack.getType() == Material.IRON_BOOTS) {
final ItemMeta meta2 = getItemMeta2(itemStack);
itemStack.setItemMeta(meta2);
}
}
}
}
@Nullable
private static ItemMeta getItemMeta2(ItemStack is2) {
ItemMeta meta2 = is2.getItemMeta();
final Damageable damageable2 = (Damageable) meta2;
if (is2.getType() == Material.NETHERITE_HELMET) {
@@ -146,15 +128,40 @@ public class Helper
damageable2.setDamage(194);
}
}
meta2 = (ItemMeta)damageable2;
is2.setItemMeta(meta2);
meta2 = damageable2;
return meta2;
}
@Nullable
private static ItemMeta getItemMeta(ItemStack is) {
ItemMeta meta = is.getItemMeta();
final Damageable damageable = (Damageable) meta;
if (is.getType() == Material.NETHERITE_SWORD || is.getType() == Material.NETHERITE_AXE) {
damageable.setDamage(damageable.getDamage() + 507);
if (damageable.getDamage() > 2000) {
damageable.setDamage(2030);
}
} else if (is.getType() == Material.DIAMOND_SWORD || is.getType() == Material.DIAMOND_AXE) {
damageable.setDamage(damageable.getDamage() + 390);
if (damageable.getDamage() > 1500) {
damageable.setDamage(1560);
}
} else if (is.getType() == Material.IRON_SWORD || is.getType() == Material.IRON_AXE) {
damageable.setDamage(damageable.getDamage() + 62);
if (damageable.getDamage() > 200) {
damageable.setDamage(249);
}
} else if (is.getType() == Material.TRIDENT) {
damageable.setDamage(damageable.getDamage() + 62);
if (damageable.getDamage() > 200) {
damageable.setDamage(249);
}
}
meta = damageable;
return meta;
}
/**
*
* @param worldCoord worldCoord
* @return List of connected chunks
* @author NinjaMandalorian
@@ -179,7 +186,9 @@ public class Helper
return ReturnList;
}
/** Gets all adjacently connected townblocks
/**
* Gets all adjacently connected townblocks
*
* @param chunkCoord - WorldCoord to check at
* @return List of WorldCoords
* @author NinjaMandalorian
@@ -191,7 +200,7 @@ public class Helper
SearchList.add(chunkCoord); // Adds 1st chunk to list
// Iterates through SearchList, to create a full list of every adjacent cell.
while (SearchList.size() > 0) {
while (!SearchList.isEmpty()) {
// Gets WorldCoord
WorldCoord toSearch = SearchList.get(0);
// Gets adjacent cells
@@ -199,10 +208,8 @@ public class Helper
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);
@@ -1,18 +1,17 @@
package me.ShermansWorld.AlathraWar;
import me.ShermansWorld.AlathraWar.commands.*;
import me.ShermansWorld.AlathraWar.items.WarItemRegistry;
import me.ShermansWorld.AlathraWar.listeners.*;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.Plugin;
import me.ShermansWorld.AlathraWar.data.WarData;
import me.ShermansWorld.AlathraWar.hooks.TABHook;
import me.ShermansWorld.AlathraWar.items.WarItemRegistry;
import me.ShermansWorld.AlathraWar.listeners.*;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import org.bukkit.Bukkit;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
public static Main instance;
@@ -36,21 +35,6 @@ public class Main extends JavaPlugin {
WarData.setWars(WarData.createWars());
}
@SuppressWarnings("rawtypes")
private boolean setupEconomy() {
if (this.getServer().getPluginManager().getPlugin("Vault") == null) {
return false;
}
@SuppressWarnings("unchecked")
final RegisteredServiceProvider<Economy> rsp = (RegisteredServiceProvider<Economy>) this.getServer()
.getServicesManager().getRegistration((Class) Economy.class);
if (rsp == null) {
return false;
}
econ = (Economy) rsp.getProvider();
return econ != null;
}
public static Main getInstance() {
return instance;
}
@@ -76,6 +60,20 @@ public class Main extends JavaPlugin {
TABHook.init();
}
@SuppressWarnings("rawtypes")
private boolean setupEconomy() {
if (this.getServer().getPluginManager().getPlugin("Vault") == null) {
return false;
}
@SuppressWarnings("unchecked") final RegisteredServiceProvider<Economy> rsp = (RegisteredServiceProvider<Economy>) this.getServer()
.getServicesManager().getRegistration((Class) Economy.class);
if (rsp == null) {
return false;
}
econ = rsp.getProvider();
return econ != null;
}
public void onEnable() {
instance = this;
this.saveDefaultConfig();
@@ -91,10 +89,10 @@ public class Main extends JavaPlugin {
getCommand("siege").setTabCompleter(new SiegeTabCompletion());
getCommand("raid").setTabCompleter(new RaidTabCompletion());
getCommand("alathrawaradmin").setTabCompleter(new AdminTabCompletion());
getServer().getPluginManager().registerEvents(new KillsListener(), (Plugin) this);
getServer().getPluginManager().registerEvents(new CommandsListener(), (Plugin) this);
getServer().getPluginManager().registerEvents(new JoinListener(), (Plugin) this);
getServer().getPluginManager().registerEvents(new BlockBreakListener(), (Plugin) this);
getServer().getPluginManager().registerEvents(new KillsListener(), this);
getServer().getPluginManager().registerEvents(new CommandsListener(), this);
getServer().getPluginManager().registerEvents(new JoinListener(), this);
getServer().getPluginManager().registerEvents(new BlockBreakListener(), this);
getServer().getPluginManager().registerEvents(new PlayerInteractListener(), this);
// //run first
@@ -16,7 +16,6 @@ import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@@ -69,12 +68,18 @@ public class Raid {
//Ticks between activity, this is lower than siege because more activity is occuring in a raid
private static final int incremental = 40;
private War war;
private final String name;
public final NamespacedKey bossBarKey = new NamespacedKey(Main.getInstance(), "raidBar." + Raid.this.getName());
public ArrayList<String> activeRaiders = new ArrayList<>();
public ArrayList<String> raiderPlayers = new ArrayList<>();
public ArrayList<String> defenderPlayers = new ArrayList<>();
public Map<WorldCoord, LootBlock> lootedChunks;
final int[] bukkitId;
private War war;
private Town raidedTown;
private Town gatherTown;
private String raiders;
private String defenders;
private final String defenders;
private boolean side1AreRaiders;
private int raiderScore;
private int defenderScore;
@@ -85,12 +90,6 @@ public class Raid {
private RaidPhase phase;
private Location townSpawnRaided;
private Location townSpawnGather;
int[] bukkitId;
public ArrayList<String> activeRaiders = new ArrayList<>();
public ArrayList<String> raiderPlayers = new ArrayList<>();
public ArrayList<String> defenderPlayers = new ArrayList<>();
public Map<WorldCoord, LootBlock> lootedChunks;
public final NamespacedKey bossBarKey = new NamespacedKey(Main.getInstance(), "raidBar." + Raid.this.getName());
/**
* Constructs raid for staging phase
@@ -168,6 +167,10 @@ public class Raid {
this.lootedChunks = new HashMap<>();
}
static /* synthetic */ void access$7(final Raid raid, final int raidTicks) {
raid.raidTicks = raidTicks;
}
/**
* Run when raid starts
*/
@@ -200,15 +203,13 @@ public class Raid {
war.setLastRaidTimeSide1((int) (System.currentTimeMillis() / 1000));
} else if (war.getSide2Players().contains(owner.getName())) {
war.setLastRaidTimeSide2((int) (System.currentTimeMillis() / 1000));
} else {
}
setupDisplayBar();
// Creates 10 second looping function for Raid
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) Main.getInstance(),
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(),
getTickLoop(), 0L, incremental);
this.getWar().addRaid(this);
@@ -216,7 +217,6 @@ public class Raid {
}
/**
* Resumes a Raid (after a server restart e.t.c.)
*/
@@ -242,12 +242,11 @@ public class Raid {
setupDisplayBar();
// Creates 2 second looping function for Raid, restarting this!
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) Main.getInstance(),
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(),
getTickLoop(), 0L, incremental);
}
/**
* End of raid
*/
@@ -258,7 +257,6 @@ public class Raid {
RaidData.removeRaid(this);
}
/**
* Do loot logic for a chunk, synchronized in case multiple players are looting at once and something breaks
*
@@ -286,11 +284,13 @@ public class Raid {
//Broadcast to the whole raid
for (String s : activeRaiders) {
Player pl = Bukkit.getPlayer(s);
if(pl != null) pl.sendMessage(Helper.chatLabel() + String.format("A townblock has been looted for $%.2f and +10 points. (Added to pool)", lb.value));
if (pl != null)
pl.sendMessage(Helper.chatLabel() + String.format("A townblock has been looted for $%.2f and +10 points. (Added to pool)", lb.value));
}
for (String s : defenderPlayers) {
Player pl = Bukkit.getPlayer(s);
if(pl != null) pl.sendMessage(Helper.chatLabel() + String.format("A townblock has been looted for $%.2f and +10 points. (Added to pool)", lb.value));
if (pl != null)
pl.sendMessage(Helper.chatLabel() + String.format("A townblock has been looted for $%.2f and +10 points. (Added to pool)", lb.value));
}
this.save();
@@ -300,11 +300,13 @@ public class Raid {
this.addLootedChunk(wc);
for (String s : activeRaiders) {
Player pl = Bukkit.getPlayer(s);
if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Raiders have started looting a town block!");
if (pl != null)
pl.sendMessage(Helper.chatLabel() + "Raiders have started looting a town block!");
}
for (String s : defenderPlayers) {
Player pl = Bukkit.getPlayer(s);
if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Raiders have started looting a town block!");
if (pl != null)
pl.sendMessage(Helper.chatLabel() + "Raiders have started looting a town block!");
}
}
@@ -322,7 +324,7 @@ public class Raid {
*/
private void startTravel() {
Raid.this.phase = RaidPhase.TRAVEL;
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The Raiders of "
Bukkit.broadcastMessage(Helper.chatLabel() + "The Raiders of "
+ (side1AreRaiders ? Raid.this.war.getSide1() : Raid.this.war.getSide2())
+ " are coming to raid "
+ Raid.this.getRaidedTown().getName() + "!");
@@ -335,7 +337,7 @@ public class Raid {
*/
private void startCombat() {
Raid.this.phase = RaidPhase.COMBAT;
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The Raiders of "
Bukkit.broadcastMessage(Helper.chatLabel() + "The Raiders of "
+ (side1AreRaiders ? Raid.this.war.getSide1() : Raid.this.war.getSide2())
+ " have arrived at "
+ Raid.this.getRaidedTown().getName() + " and the fighting has begun!");
@@ -352,11 +354,11 @@ public class Raid {
this.addPointsToDefenderScore(40);
for (final String playerName : this.getActiveRaiders()) {
Player pl = Bukkit.getPlayer(playerName);
if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Raider killed! -40 Raid Score");
if (pl != null) pl.sendMessage(Helper.chatLabel() + "Raider killed! -40 Raid Score");
}
for (final String playerName : this.getDefenderPlayers()) {
Player pl = Bukkit.getPlayer(playerName);
if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Raider killed! -40 Raid Score");
if (pl != null) pl.sendMessage(Helper.chatLabel() + "Raider killed! -40 Raid Score");
}
}
@@ -367,11 +369,11 @@ public class Raid {
this.addPointsToRaiderScore(20);
for (final String playerName : this.getActiveRaiders()) {
Player pl = Bukkit.getPlayer(playerName);
if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Defender killed! +20 Raid Score");
if (pl != null) pl.sendMessage(Helper.chatLabel() + "Defender killed! +20 Raid Score");
}
for (final String playerName : this.getDefenderPlayers()) {
Player pl = Bukkit.getPlayer(playerName);
if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Defender killed! +20 Raid Score");
if (pl != null) pl.sendMessage(Helper.chatLabel() + "Defender killed! +20 Raid Score");
}
// //tp to raid town spawn
@@ -390,11 +392,13 @@ public class Raid {
//award negative score
for (final String playerName : this.getActiveRaiders()) {
Player pl = Bukkit.getPlayer(playerName);
if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Raider killed before combat, no points awarded and death treated normally.");
if (pl != null)
pl.sendMessage(Helper.chatLabel() + "Raider killed before combat, no points awarded and death treated normally.");
}
for (final String playerName : this.getDefenderPlayers()) {
Player pl = Bukkit.getPlayer(playerName);
if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Raider killed before combat, no points awarded and death treated normally.");
if (pl != null)
pl.sendMessage(Helper.chatLabel() + "Raider killed before combat, no points awarded and death treated normally.");
}
//
// //tp to gather town spawn
@@ -411,7 +415,7 @@ public class Raid {
if (this.getDefenderSide().contains(killed.getKiller().getName())) {
try {
killed.getKiller().teleport(this.getRaidedTown().getSpawn());
killed.getKiller().sendMessage(String.valueOf(Helper.chatLabel()) + "You killed a raider before the raid began and have been teleported back to the defending town.");
killed.getKiller().sendMessage(Helper.chatLabel() + "You killed a raider before the raid began and have been teleported back to the defending town.");
} catch (TownyException e) {
throw new RuntimeException(e);
}
@@ -425,11 +429,13 @@ public class Raid {
public void defenderKilledOutofCombat(PlayerDeathEvent event) {
for (final String playerName : this.getActiveRaiders()) {
Player pl = Bukkit.getPlayer(playerName);
if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Defender killed before combat, no points awarded and death treated normally.");
if (pl != null)
pl.sendMessage(Helper.chatLabel() + "Defender killed before combat, no points awarded and death treated normally.");
}
for (final String playerName : this.getDefenderPlayers()) {
Player pl = Bukkit.getPlayer(playerName);
if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Defender killed before combat, no points awarded and death treated normally.");
if (pl != null)
pl.sendMessage(Helper.chatLabel() + "Defender killed before combat, no points awarded and death treated normally.");
}
//tp to raid town spawn
@@ -444,7 +450,7 @@ public class Raid {
if (this.getActiveRaiders().contains(killed.getKiller().getName())) {
try {
killed.getKiller().teleport(this.getGatherTown().getSpawn());
killed.getKiller().sendMessage(String.valueOf(Helper.chatLabel()) + "You killed a defender before the raid began and have been teleported back to the gather town.");
killed.getKiller().sendMessage(Helper.chatLabel() + "You killed a defender before the raid began and have been teleported back to the gather town.");
} catch (TownyException e) {
throw new RuntimeException(e);
}
@@ -454,7 +460,6 @@ public class Raid {
/**
* Raiders win, give payout and finalize raid
*
*/
public void raidersWin(final OfflinePlayer owner, int raiderScore, int defenderScore) {
//TODO finalize payout
@@ -467,7 +472,7 @@ public class Raid {
if (factor > 3.0) factor = 3.0;
if (factor < 0) factor = 0.0;
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The raiders from " + this.raiders
Bukkit.broadcastMessage(Helper.chatLabel() + "The raiders from " + this.raiders
+ " have successfully raided " + this.raidedTown.getName() + "!");
/*
@@ -537,7 +542,6 @@ public class Raid {
/**
* Defenders win, payout, and finalize raid
*
*/
public void defendersWin(int raiderScore, int defenderScore) {
//TODO finalize payout
@@ -595,7 +599,7 @@ public class Raid {
public void noWinner() {
//TODO finalize payout
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The defenders from " + this.defenders
Bukkit.broadcastMessage(Helper.chatLabel() + "The defenders from " + this.defenders
+ " didn't push back the raiders of " + this.raiders + ". Yet no loot was taken, raid considered a draw.");
Main.warLogger
.log("No one won the raid of " + this.raidedTown.getName() + "!");
@@ -642,7 +646,6 @@ public class Raid {
return this.name;
}
public War getWar() {
return this.war;
}
@@ -739,14 +742,21 @@ public class Raid {
this.raidTicks = ticks;
}
static /* synthetic */ void access$7(final Raid raid, final int raidTicks) {
raid.raidTicks = raidTicks;
}
public RaidPhase getPhase() {
return this.phase;
}
public void setPhase(RaidPhase phase) {
this.phase = phase;
if (phase == RaidPhase.GATHER) {
startGather();
} else if (phase == RaidPhase.TRAVEL) {
startTravel();
} else if (phase == RaidPhase.COMBAT) {
startCombat();
}
}
public void setRaidPhase(final RaidPhase phase) {
this.phase = phase;
}
@@ -783,10 +793,7 @@ public class Raid {
}
private Runnable getTickLoop() {
return (Runnable) new Runnable() {
@Override
public void run() {
return () -> {
if (homeBlockRaided != null) {
raidedTown.setHomeBlock(homeBlockRaided);
raidedTown.setSpawn(townSpawnRaided);
@@ -838,8 +845,8 @@ public class Raid {
if (Raid.this.phase == RaidPhase.GATHER) {
//Broadcast
if (raidTicks % 6000 == 0) {
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The raid of "
+ Raid.this.getRaidedTown().getName() + " will begin in " + (int) ((RaidPhase.TRAVEL.startTick - raidTicks) / 20 / 60) + " minutes!");
Bukkit.broadcastMessage(Helper.chatLabel() + "The raid of "
+ Raid.this.getRaidedTown().getName() + " will begin in " + ((RaidPhase.TRAVEL.startTick - raidTicks) / 20 / 60) + " minutes!");
Bukkit.broadcastMessage(
"The Raiders are gathering at " + getGatherTown().getName() + " before making the journey over!");
}
@@ -854,12 +861,12 @@ public class Raid {
if (!cluster.contains(WorldCoord.parseWorldCoord(p))) {
if (p.equals(owner)) {
p.teleport(gatherTown.getSpawn());
p.sendMessage(String.valueOf(Helper.chatLabel()) + "You cannot leave the gather town. As raid party leader, you have remained in the party. To stop the raid type /raid abandon");
p.sendMessage(String.valueOf(Helper.chatLabel()) + "You have been teleported to the gather town's spawn.");
p.sendMessage(Helper.chatLabel() + "You cannot leave the gather town. As raid party leader, you have remained in the party. To stop the raid type /raid abandon");
p.sendMessage(Helper.chatLabel() + "You have been teleported to the gather town's spawn.");
} else {
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]");
p.sendMessage(Helper.chatLabel() + "By leaving the gathering town you have left the raid on " + Raid.this.getRaidedTown().getName() + "!");
p.sendMessage(Helper.chatLabel() + "To rejoin, do /raid join [war] [town]");
}
}
}
@@ -874,7 +881,7 @@ public class Raid {
//Report
if (raidTicks % 2400 == 0) {
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The Raiders of "
Bukkit.broadcastMessage(Helper.chatLabel() + "The Raiders of "
+ (side1AreRaiders ? Raid.this.war.getSide1() : Raid.this.war.getSide2())
+ " are on their way to raid "
+ Raid.this.getRaidedTown().getName() + "!");
@@ -947,7 +954,6 @@ public class Raid {
//refresh the existing display bar
refreshDisplayBar();
}
}
};
}
@@ -956,7 +962,7 @@ public class Raid {
if (bossBar == null) bossBar = createNewDisplayBar();
bossBar.setTitle(String.format("%d -- Raiders -Raid Score- Defenders -- %d", Raid.this.raiderScore, Raid.this.defenderScore));
bossBar.setProgress((double) (Raid.this.raiderScore + 0.5D) / ((Raid.this.raiderScore + Raid.this.defenderScore) + 1.0D));
bossBar.setProgress((Raid.this.raiderScore + 0.5D) / ((Raid.this.raiderScore + Raid.this.defenderScore) + 1.0D));
for (String s : Raid.this.getActiveRaiders()) {
Player p = Bukkit.getPlayer(s);
@@ -1023,17 +1029,6 @@ public class Raid {
this.homeBlockGather = homeBlockGather;
}
public void setPhase(RaidPhase phase) {
this.phase = phase;
if(phase == RaidPhase.GATHER) {
startGather();
} else if(phase == RaidPhase.TRAVEL) {
startTravel();
} else if(phase == RaidPhase.COMBAT) {
startCombat();
}
}
public Location getTownSpawnRaided() {
return townSpawnRaided;
}
@@ -1052,7 +1047,7 @@ public class Raid {
public static class LootBlock {
public WorldCoord worldCoord;
public final WorldCoord worldCoord;
public int ticks;
public double value;
public boolean finished;
@@ -1,30 +1,27 @@
package me.ShermansWorld.AlathraWar;
import com.palmergames.bukkit.towny.exceptions.TownyException;
import org.bukkit.*;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.object.*;
import me.ShermansWorld.AlathraWar.data.SiegeData;
import org.bukkit.*;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.WorldCoord;
import me.ShermansWorld.AlathraWar.data.SiegeData;
import java.util.ArrayList;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock;
public class Siege {
public static final int maxSiegeTicks = 72000; // 60 minute tick constant
public final NamespacedKey bossBarKey;
public ArrayList<String> attackerPlayers;
public ArrayList<String> defenderPlayers;
public ArrayList<Location> beaconLocs;
int[] bukkitId;
private War war; // War which siege belongs to
private Town town; // Town of the siege
private boolean side1AreAttackers; // bool of if side1 being attacker
@@ -34,30 +31,26 @@ public class Siege {
private int siegeTicks;
private TownBlock homeBlock;
private Location townSpawn;
int[] bukkitId;
public ArrayList<String> attackerPlayers;
public ArrayList<String> defenderPlayers;
public ArrayList<Location> beaconLocs;
public final NamespacedKey bossBarKey;
public Siege(final War war, final Town town, OfflinePlayer siegeLeader) {
this.siegeTicks = 0;
this.bukkitId = new int[1];
this.attackerPlayers = new ArrayList<String>();
this.defenderPlayers = new ArrayList<String>();
this.beaconLocs = new ArrayList<Location>();
this.attackerPlayers = new ArrayList<>();
this.defenderPlayers = new ArrayList<>();
this.beaconLocs = new ArrayList<>();
this.war = war;
this.town = town;
this.siegeLeader = siegeLeader;
bossBarKey = new NamespacedKey(Main.getInstance(), "siegeBar." + this.getName());
if (war.getSide(town.getName()) == 2) side1AreAttackers = true;
else side1AreAttackers = false;
side1AreAttackers = war.getSide(town.getName()) == 2;
}
/** Starts a siege */
/**
* Starts a siege
*/
public void start() {
attackerPoints = 0;
defenderPoints = 0;
@@ -65,12 +58,14 @@ public class Siege {
homeBlock = town.getHomeBlockOrNull();
townSpawn = town.getSpawnOrNull();
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) Main.getInstance(), getTickLoop(), 0L, 200L);
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), getTickLoop(), 0L, 200L);
setupDisplayBar();
}
/** Resumes a siege (after a server restart e.t.c.)*/
/**
* Resumes a siege (after a server restart e.t.c.)
*/
public void resume(int resumeTick) {
siegeTicks = resumeTick;
@@ -78,12 +73,14 @@ public class Siege {
homeBlock = town.getHomeBlockOrNull();
townSpawn = town.getSpawnOrNull();
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) Main.getInstance(), getTickLoop(), 0L, 200L);
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), getTickLoop(), 0L, 200L);
setupDisplayBar();
}
/** Stops a siege */
/**
* Stops a siege
*/
public void stop() {
deleteDisplayBar();
Bukkit.getScheduler().cancelTask(this.bukkitId[0]);
@@ -140,7 +137,7 @@ public class Siege {
}
}
} catch (NotRegisteredException ignored) {
Main.warLogger.log(Helper.chatLabel() + "Attempting to look for town at " + WorldCoord.parseWorldCoord(pl).toString());
Main.warLogger.log(Helper.chatLabel() + "Attempting to look for town at " + WorldCoord.parseWorldCoord(pl));
}
}
for (final String playerName : Siege.this.defenderPlayers) {
@@ -162,21 +159,21 @@ public class Siege {
}
}
} catch (NotRegisteredException ignored) {
Main.warLogger.log(Helper.chatLabel() + "Attempting to look for town at " + WorldCoord.parseWorldCoord(pl).toString());
Main.warLogger.log(Helper.chatLabel() + "Attempting to look for town at " + WorldCoord.parseWorldCoord(pl));
}
}
if (attackersAreOnHomeBlock && defendersAreOnHomeBlock) { // Contested
if (this.homeBlockControl != 1) {
for (final String playerName : Siege.this.attackerPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.chatLabel())
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
+ "HomeBlock at " + Siege.this.town.getName() + " contested!");
} catch (NullPointerException ex5) {
}
}
for (final String playerName : Siege.this.defenderPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.chatLabel())
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
+ "HomeBlock at " + Siege.this.town.getName() + " contested!");
} catch (NullPointerException ex6) {
}
@@ -187,7 +184,7 @@ public class Siege {
if (this.homeBlockControl != 2) {
for (final String playerName : Siege.this.attackerPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.chatLabel())
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
+ "Attackers have captured the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Attacker Points per second");
} catch (NullPointerException ex7) {
@@ -195,7 +192,7 @@ public class Siege {
}
for (final String playerName : Siege.this.defenderPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.chatLabel())
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
+ "Attackers have captured the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Attacker Points per second");
} catch (NullPointerException ex8) {
@@ -208,7 +205,7 @@ public class Siege {
if (this.homeBlockControl != 3) {
for (final String playerName : Siege.this.attackerPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.chatLabel())
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
+ "Defenders retain control of the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Defender Points per second");
} catch (NullPointerException ex9) {
@@ -216,7 +213,7 @@ public class Siege {
}
for (final String playerName : Siege.this.defenderPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.chatLabel())
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
+ "Defenders retain control of the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Defender Points per second");
} catch (NullPointerException ex10) {
@@ -227,12 +224,12 @@ public class Siege {
this.homeBlockControl = 3;
}
if (Siege.this.siegeTicks % 6000 == 0) { // Updates every 5 minutes
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "Report on the siege of "
Bukkit.broadcastMessage(Helper.chatLabel() + "Report on the siege of "
+ Siege.this.town.getName() + ":");
Bukkit.broadcastMessage(
"Attacker Points - " + String.valueOf(Siege.this.attackerPoints));
"Attacker Points - " + Siege.this.attackerPoints);
Bukkit.broadcastMessage(
"Defender Points - " + String.valueOf(Siege.this.defenderPoints));
"Defender Points - " + Siege.this.defenderPoints);
}
if (siegeTicks % 1200 == 0) { // Saves every minute
save();
@@ -243,19 +240,19 @@ public class Siege {
}
};
}
public void attackersWin(final OfflinePlayer siegeLeader) {
final Resident resident = TownyAPI.getInstance().getResident(siegeLeader.getUniqueId());
Nation nation = null;
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The attackers have won the siege of " + this.town.getName() + "!");
Bukkit.broadcastMessage(Helper.chatLabel() + "The attackers have won the siege of " + this.town.getName() + "!");
try {
nation = resident.getTown().getNation();
} catch (Exception e) {}
} catch (Exception e) {
}
if (nation != null) {
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The town of " + this.town.getName()
Bukkit.broadcastMessage(Helper.chatLabel() + "The town of " + this.town.getName()
+ " has been placed under occupation by " + nation.getName() + "!");
}
Main.econ.depositPlayer(siegeLeader, 2500.0);
@@ -266,7 +263,7 @@ public class Siege {
} else {
if (this.town.getAccount().getHoldingBalance() < 2500.0) {
amt = this.town.getAccount().getHoldingBalance();
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The town of " + this.town.getName()
Bukkit.broadcastMessage(Helper.chatLabel() + "The town of " + this.town.getName()
+ " has been destroyed by " + this.getAttackerSide() + "!");
TownyUniverse.getInstance().getDataSource().deleteTown(this.town);
Main.econ.depositPlayer(siegeLeader, amt);
@@ -276,9 +273,9 @@ public class Siege {
amt = 2500.0;
}
Bukkit.broadcastMessage("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide()
+ ", valuing $" + String.valueOf(amt));
+ ", valuing $" + amt);
Main.warLogger.log("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide()
+ ", valuing $" + String.valueOf(amt));
+ ", valuing $" + amt);
Main.econ.depositPlayer(siegeLeader, amt);
if (side1AreAttackers) {
@@ -293,8 +290,8 @@ public class Siege {
public void defendersWin() {
this.town.getAccount().deposit(2500.0, "War chest");
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The defenders have won the siege of " + this.town.getName() + "!");
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + this.town.getName()
Bukkit.broadcastMessage(Helper.chatLabel() + "The defenders have won the siege of " + this.town.getName() + "!");
Bukkit.broadcastMessage(Helper.chatLabel() + this.town.getName()
+ " has recovered the attackers' war chest, valued at $2,500");
Main.warLogger
.log(war.getName() + ": The defenders have won the siege of " + this.town.getName() + "!");
@@ -313,8 +310,8 @@ public class Siege {
* No winnder declared
*/
public void noWinner() {
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The siege of " + this.town.getName() + " was a draw!");
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "No money has been recovered.");
Bukkit.broadcastMessage(Helper.chatLabel() + "The siege of " + this.town.getName() + " was a draw!");
Bukkit.broadcastMessage(Helper.chatLabel() + "No money has been recovered.");
Main.warLogger
.log(war.getName() + ": No one won the siege of " + this.town.getName() + "!");
stop();
@@ -339,34 +336,34 @@ public class Siege {
homeBlockZ += 8;
}
int homeBlockY = 253;
final Location beaconLoc = new Location(this.town.getWorld(), (double) homeBlockX,
(double) (homeBlockY - 2), (double) homeBlockZ);
while (beaconLoc.getBlock().getType().equals((Object) Material.AIR)) {
final Location beaconLoc = new Location(this.town.getWorld(), homeBlockX,
homeBlockY - 2, homeBlockZ);
while (beaconLoc.getBlock().getType().equals(Material.AIR)) {
--homeBlockY;
beaconLoc.setY((double) homeBlockY);
beaconLoc.setY(homeBlockY);
}
homeBlockY += 2;
this.beaconLocs.add(new Location(world, (double) homeBlockX, (double) homeBlockY, (double) homeBlockZ));
this.beaconLocs.add(new Location(world, homeBlockX, homeBlockY, homeBlockZ));
this.beaconLocs
.add(new Location(world, (double) homeBlockX, (double) (homeBlockY + 1), (double) homeBlockZ));
.add(new Location(world, homeBlockX, homeBlockY + 1, homeBlockZ));
this.beaconLocs
.add(new Location(world, (double) homeBlockX, (double) (homeBlockY - 1), (double) homeBlockZ));
.add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ));
this.beaconLocs.add(
new Location(world, (double) (homeBlockX + 1), (double) (homeBlockY - 1), (double) homeBlockZ));
new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ));
this.beaconLocs.add(
new Location(world, (double) (homeBlockX - 1), (double) (homeBlockY - 1), (double) homeBlockZ));
new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ));
this.beaconLocs.add(
new Location(world, (double) homeBlockX, (double) (homeBlockY - 1), (double) (homeBlockZ + 1)));
new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ + 1));
this.beaconLocs.add(
new Location(world, (double) homeBlockX, (double) (homeBlockY - 1), (double) (homeBlockZ - 1)));
this.beaconLocs.add(new Location(world, (double) (homeBlockX + 1), (double) (homeBlockY - 1),
(double) (homeBlockZ + 1)));
this.beaconLocs.add(new Location(world, (double) (homeBlockX + 1), (double) (homeBlockY - 1),
(double) (homeBlockZ - 1)));
this.beaconLocs.add(new Location(world, (double) (homeBlockX - 1), (double) (homeBlockY - 1),
(double) (homeBlockZ + 1)));
this.beaconLocs.add(new Location(world, (double) (homeBlockX - 1), (double) (homeBlockY - 1),
(double) (homeBlockZ - 1)));
new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ - 1));
this.beaconLocs.add(new Location(world, homeBlockX + 1, homeBlockY - 1,
homeBlockZ + 1));
this.beaconLocs.add(new Location(world, homeBlockX + 1, homeBlockY - 1,
homeBlockZ - 1));
this.beaconLocs.add(new Location(world, homeBlockX - 1, homeBlockY - 1,
homeBlockZ + 1));
this.beaconLocs.add(new Location(world, homeBlockX - 1, homeBlockY - 1,
homeBlockZ - 1));
for (int i = 2; i < this.beaconLocs.size(); ++i) {
if (this.beaconLocs.get(i).getBlock().getType() != Material.AIR) {
i = 1;
@@ -387,25 +384,25 @@ public class Siege {
}
public void resetBeacon(World world, int homeBlockX, int homeBlockY, int homeBlockZ) {
this.beaconLocs.add(new Location(world, (double) homeBlockX, (double) homeBlockY, (double) homeBlockZ));
this.beaconLocs.add(new Location(world, (double) homeBlockX, (double) (homeBlockY + 1), (double) homeBlockZ));
this.beaconLocs.add(new Location(world, (double) homeBlockX, (double) (homeBlockY - 1), (double) homeBlockZ));
this.beaconLocs.add(new Location(world, homeBlockX, homeBlockY, homeBlockZ));
this.beaconLocs.add(new Location(world, homeBlockX, homeBlockY + 1, homeBlockZ));
this.beaconLocs.add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ));
this.beaconLocs
.add(new Location(world, (double) (homeBlockX + 1), (double) (homeBlockY - 1), (double) homeBlockZ));
.add(new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ));
this.beaconLocs
.add(new Location(world, (double) (homeBlockX - 1), (double) (homeBlockY - 1), (double) homeBlockZ));
.add(new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ));
this.beaconLocs
.add(new Location(world, (double) homeBlockX, (double) (homeBlockY - 1), (double) (homeBlockZ + 1)));
.add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ + 1));
this.beaconLocs
.add(new Location(world, (double) homeBlockX, (double) (homeBlockY - 1), (double) (homeBlockZ - 1)));
.add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ - 1));
this.beaconLocs.add(
new Location(world, (double) (homeBlockX + 1), (double) (homeBlockY - 1), (double) (homeBlockZ + 1)));
new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ + 1));
this.beaconLocs.add(
new Location(world, (double) (homeBlockX + 1), (double) (homeBlockY - 1), (double) (homeBlockZ - 1)));
new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ - 1));
this.beaconLocs.add(
new Location(world, (double) (homeBlockX - 1), (double) (homeBlockY - 1), (double) (homeBlockZ + 1)));
new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ + 1));
this.beaconLocs.add(
new Location(world, (double) (homeBlockX - 1), (double) (homeBlockY - 1), (double) (homeBlockZ - 1)));
new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ - 1));
}
public void clearBeacon() {
@@ -446,7 +443,9 @@ public class Siege {
this.siegeLeader = siegeOwner;
}
/** Gets attacker name string */
/**
* Gets attacker name string
*/
public String getAttackerSide() {
if (side1AreAttackers) {
return war.getSide1();
@@ -455,7 +454,9 @@ public class Siege {
}
}
/** Gets defender name string */
/**
* Gets defender name string
*/
public String getDefenderSide() {
if (side1AreAttackers) {
return war.getSide2();
@@ -469,7 +470,7 @@ public class Siege {
if (bossBar == null) bossBar = createNewDisplayBar();
bossBar.setTitle(String.format("%d -- Attackers -Siege Score- Defenders -- %d", this.attackerPoints, this.defenderPoints));
bossBar.setProgress((double) (this.attackerPoints + 0.5D) / ((this.attackerPoints + this.defenderPoints) + 1.0D));
bossBar.setProgress((this.attackerPoints + 0.5D) / ((this.attackerPoints + this.defenderPoints) + 1.0D));
for (String s : this.getAttackerPlayers()) {
Player p = Bukkit.getPlayer(s);
@@ -521,16 +522,20 @@ public class Siege {
return this.attackerPoints;
}
public void setAttackerPoints(int points) {
this.attackerPoints = points;
}
public int getDefenderPoints() {
return this.defenderPoints;
}
public int getMaxSiegeTicks() {
return maxSiegeTicks;
public void setDefenderPoints(int points) {
this.defenderPoints = points;
}
public void setSiegeTicks(int siegeTicks) {
this.siegeTicks = siegeTicks;
public int getMaxSiegeTicks() {
return maxSiegeTicks;
}
public TownBlock getHomeBlock() {
@@ -549,14 +554,6 @@ public class Siege {
this.townSpawn = townSpawn;
}
public void setAttackerPoints(int points) {
this.attackerPoints = points;
}
public void setDefenderPoints(int points) {
this.defenderPoints = points;
}
public boolean getSide1AreAttackers() {
return this.side1AreAttackers;
}
@@ -585,6 +582,10 @@ public class Siege {
return siegeTicks;
}
public void setSiegeTicks(int siegeTicks) {
this.siegeTicks = siegeTicks;
}
public OfflinePlayer getSiegeLeader() {
return siegeLeader;
}
@@ -1,37 +1,37 @@
package me.ShermansWorld.AlathraWar;
import java.io.File;
import java.util.ArrayList;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import me.ShermansWorld.AlathraWar.commands.CommandHelper;
import me.ShermansWorld.AlathraWar.data.DataManager;
import me.ShermansWorld.AlathraWar.data.WarData;
import java.io.File;
import java.util.ArrayList;
public class War {
// Object Fields
private String name;
private String side1;
private String side2;
private ArrayList<String> side1Towns = new ArrayList<String>();
private ArrayList<String> side2Towns = new ArrayList<String>();
private ArrayList<String> surrenderedTowns = new ArrayList<String>();
private ArrayList<String> side1Towns = new ArrayList<>();
private ArrayList<String> side2Towns = new ArrayList<>();
private ArrayList<String> surrenderedTowns = new ArrayList<>();
private int side1Points = 0;
private int side2Points = 0;
// References
private ArrayList<Siege> sieges = new ArrayList<Siege>();
private ArrayList<Raid> raids = new ArrayList<Raid>();
private final ArrayList<Siege> sieges = new ArrayList<>();
private final ArrayList<Raid> raids = new ArrayList<>();
private int lastRaidTimeSide1 = 0;
private int lastRaidTimeSide2 = 0;
/**
* War Constructor
*
* @param name - Name of war
* @param side1 - Side 1 name
* @param side2 - Side 2 name
@@ -42,8 +42,25 @@ public class War {
this.side2 = side2;
}
private static ArrayList<String> townListToPlayers(ArrayList<String> townList) {
ArrayList<String> returnList = new ArrayList<>();
for (String townString : townList) {
Town town = TownyAPI.getInstance().getTown(townString);
if (town != null) {
for (Resident res : town.getResidents()) {
//Minuteman countermeasure! if they are they get skipped
if (CommandHelper.isPlayerMinuteman(res.getName()) == 0) {
returnList.add(res.getName());
}
}
}
}
return returnList;
}
/**
* Add a nation to a side of the war
*
* @param nation - Nation object
* @param side - Side name
*/
@@ -55,6 +72,7 @@ public class War {
/**
* Add a town to a side of the war
*
* @param town - Town object
* @param side - Side name
*/
@@ -64,6 +82,7 @@ public class War {
/**
* Add a town to a side of the war
*
* @param town - Town object
* @param side - Side name
*/
@@ -86,6 +105,7 @@ public class War {
/**
* Surrenders town
*
* @param nation - Nation to surrender
*/
public void surrenderNation(Nation nation) {
@@ -98,6 +118,7 @@ public class War {
/**
* Surrenders town
*
* @param town - Town to surrender
*/
public void surrenderTown(String town) {
@@ -108,6 +129,7 @@ public class War {
/**
* unsurrender town, perfidy time
*
* @param nation - Nation to unsurrender
*/
public void unSurrenderNation(Nation nation) {
@@ -118,6 +140,7 @@ public class War {
/**
* unsurrender town, perfidy time
*
* @param town - Town to unsurrender
*/
public void unSurrenderTown(String town) {
@@ -130,6 +153,7 @@ public class War {
* 0 - None
* 1 - Side 1
* 2 - Side 2
*
* @param string town
* @return result
*/
@@ -156,14 +180,28 @@ public class War {
return this.name;
}
public void setName(String name) {
DataManager.deleteFile("wars" + File.separator + this.getName() + ".yml");
this.name = name;
this.save();
}
public String getSide1() {
return this.side1;
}
public void setSide1(String side1) {
this.side1 = side1;
}
public String getSide2() {
return this.side2;
}
public void setSide2(String side2) {
this.side2 = side2;
}
public ArrayList<String> getSide1Towns() {
return this.side1Towns;
}
@@ -204,20 +242,6 @@ public class War {
raids.add(raid);
}
public void setName(String name) {
DataManager.deleteFile("wars" + File.separator + this.getName() + ".yml");
this.name = name;
this.save();
}
public void setSide1(String side1) {
this.side1 = side1;
}
public void setSide2(String side2) {
this.side2 = side2;
}
/**
* Saves the war into .yml file folders.
*/
@@ -239,46 +263,38 @@ public class War {
return townListToPlayers(side2Towns);
}
private static ArrayList<String> townListToPlayers(ArrayList<String> townList) {
ArrayList<String> returnList = new ArrayList<String>();
for (String townString : townList) {
Town town = TownyAPI.getInstance().getTown(townString);
if (town != null) {
for (Resident res : town.getResidents()) {
//Minuteman countermeasure! if they are they get skipped
if (CommandHelper.isPlayerMinuteman(res.getName()) == 0) {
returnList.add(res.getName());
}
}
}
}
return returnList;
public int getLastRaidTimeSide1() {
return this.lastRaidTimeSide1;
}
public void setLastRaidTimeSide1(int lastRaidTime) {
this.lastRaidTimeSide1 = lastRaidTime;
}
public int getLastRaidTimeSide1() {
return this.lastRaidTimeSide1;
public int getLastRaidTimeSide2() {
return this.lastRaidTimeSide2;
}
public void setLastRaidTimeSide2(int lastRaidTime) {
this.lastRaidTimeSide2 = lastRaidTime;
}
public int getLastRaidTimeSide2() {
return this.lastRaidTimeSide2;
}
public int getSide1Points() {
return this.side1Points;
}
public void setSide1Points(int side1Points) {
this.side1Points = side1Points;
}
public int getSide2Points() {
return this.side2Points;
}
public void setSide2Points(int side2Points) {
this.side2Points = side2Points;
}
public void addSide1Points(int points) {
side1Points += points;
}
@@ -286,12 +302,4 @@ public class War {
public void addSide2Points(int points) {
side2Points += points;
}
public void setSide1Points(int side1Points) {
this.side1Points = side1Points;
}
public void setSide2Points(int side2Points) {
this.side2Points = side2Points;
}
}
@@ -21,6 +21,7 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.sql.Timestamp;
import java.util.ArrayList;
@@ -35,122 +36,10 @@ public class AdminCommands implements CommandExecutor {
plugin.getCommand("awa").setExecutor(this);
}
/**
* //done
* //edit war/event in real time, side can be "both" to effect both
* -modify raid score [war] [town] [value]
* -modify raid townspawn [war] [town] (x) (Z)
* -modify raid gather [war] [town] [town]
* -modify raid phase [war] [town] [phase] //"next" to move to next phase
* -modify raid loot [war] [town] (x) (z) [value,looted,ticks,reset] [amt] //no coords just does current chunk, reset deletes it from the list
* -modify raid time [war] [town] [add/set] [value]
* -modify raid owner [war] [town] [add/set] [value]
* -modify raid move [war] [town] [newWar] //low priority, moves raid to other war
* -modify raid clearActive [war] [town] //low priority
* <p>
* -modify siege score [war] [town] [side] [amt]
* -modify siege homeblock [war] [town] (x) (Z)
* -modify siege time [war] [town] [add/set/max] [value] //max modified the max length
* -modify siege owner [war] [town] [add/set] [value]
* -modify siege move [war] [town] [newWar] //low priority, moves siege to other war
* <p>
* -modify war score [war] [side] [amt]
* -modify war side [war] [side] [name]
* -modify war name [war] [name]
* -modify war add town [war] [town]
* -modify war add nation [war] [nation]
* -modify war surrender town [war] [town] //adds town to surrender list
* -modify war surrender nation [war] [town] //adds all towns to surrender list
* -modify war raidTime [add,set,reset] [war] [town] [amt] //set when last raid was
* <p>
* // low priority idea
* -info war score [war]
* -info war surrenderedTowns [war]
* -info war raids [war]
* -info war sieges [war]
* -info war towns [war]
* -info war lastRaidTime [war]
* <p>
* -info raid homeblock [war] [town]
* -info raid lootedTownBlocks [war] [town]
* -info raid timeSinceLastRaid [town]
* <p>
* -info siege homeblock [war] [town]
* <p>
* //done
* //force make event or war, if owner isnt defined, idk havent decided
* -create siege [war] [town] (owner)
* -create raid [war] [raidTown] (gatherTown) (owner)
* -create war [name] [side1] [side2]
* <p>
* //force end a war/event, can declare winner side, or no winner
* -force end war [war] (side/victor)
* -force end siege [war] [town] (side/victor)
* -force end raid [war] [town] (side/victor)
* <p>
* //done
* //force player into or out of a war/event
* -force join war [player] [war] [side]
* -force join siege [player] [war] [town] (side)
* -force join raid [player] [war] [town] (side)
* <p>
* //done
* -force leave raid [war] [player] (timeout) //kicks from raid party
* <p>
* // Ultra low priority idea
* -rule raidersRespawnAtGatherTown [true/false]
* -rule siegersRespawnAtTown [true/false]
* -rule anyoneCanJoinRaid [true/false]
*
* @param sender Source of the command
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args Passed command arguments
* @return Valid command
*/
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
CommandHelper.logCommand(sender, label, args);
if (!sender.hasPermission("AlathraWar.admin")) {
return fail(sender, args, "permissions");
}
if (args.length == 0) {
return fail(sender, args, "syntax");
} else if (args.length >= 1) {
if (args[0].equalsIgnoreCase("create")) {
return create(sender, args);
} else if (args[0].equalsIgnoreCase("force")) {
return force(sender, args);
} else if (args[0].equalsIgnoreCase("help")) {
return help(sender, args);
} else if (args[0].equalsIgnoreCase("info")) {
return info(sender, args);
} else if (args[0].equalsIgnoreCase("modify")) {
return modify(sender, args);
} else if (args[0].equalsIgnoreCase("awa")) {
return awa(sender, args);
} else if (args[0].equalsIgnoreCase("purgebars")) {
return purgebars(sender, args);
} else if (args[0].equalsIgnoreCase("save")) {
return save(sender, args);
} else if (args[0].equalsIgnoreCase("save-all")) {
return saveAll(sender, args);
} else if (args[0].equalsIgnoreCase("load")) {
return load(sender, args);
} else if (args[0].equalsIgnoreCase("load-all")) {
return loadAll(sender, args);
} else if (args[0].equalsIgnoreCase("item")) {
return item(sender, args);
}
}
return true;
}
private static boolean item(CommandSender sender, String[] args) {
if (args.length >= 2) {
//find item
ItemStack stack = null;
ItemStack stack;
if (args[1].contains(Main.getInstance().getName().toLowerCase())) {
stack = WarItemRegistry.getInstance().getOrNullNamespace(args[1]);
} else {
@@ -175,7 +64,7 @@ public class AdminCommands implements CommandExecutor {
stack.setAmount(amt);
//determine who gets the item
Player reciever = null;
Player reciever;
if (args.length >= 4) {
reciever = Bukkit.getPlayer(args[3]);
} else {
@@ -301,7 +190,6 @@ public class AdminCommands implements CommandExecutor {
return true;
}
/**
* //force make event or war, if owner isn't defined, idk haven't decided
* -create siege [war] [town] (owner)
@@ -316,12 +204,11 @@ public class AdminCommands implements CommandExecutor {
//using same method so that this doesnt get fucked up if we go back and change original implementation
RaidCommands.startRaid(p, args, true);
p.sendMessage(Helper.color("&cForcefully started raid from the console."));
return true;
} else {
//defaultCode will bypass the custom gather town to force set owner
p.sendMessage(Helper.color("&cUsage: /alathrawaradmin create raid [war] [raidTown] (gatherTown/\"defaultCode\") (owner) (override)"));
return true;
}
return true;
} else if (args[1].equalsIgnoreCase("siege")) {
//this exists to force a seige with a new owner
if (args.length >= 4) {
@@ -334,11 +221,10 @@ public class AdminCommands implements CommandExecutor {
SiegeCommands.siegeStart(p, l.toArray(new String[]{}), true);
// p.sendMessage(Helper.Chatlabel() + "Try again later!");
p.sendMessage(Helper.color("&cForcefully started siege from the console."));
return true;
} else {
p.sendMessage(Helper.color("&cUsage: /alathrawaradmin create siege [war] [town] (owner) (force)"));
return true;
}
return true;
} else if (args[1].equalsIgnoreCase("war")) {
//this command basically is a copy or /war create
if (args.length == 5) {
@@ -351,11 +237,10 @@ public class AdminCommands implements CommandExecutor {
};
WarCommands.warCreate(p, adjusted);
p.sendMessage(Helper.color("&cForcefully started war from the console."));
return true;
} else {
p.sendMessage(Helper.color("&cUsage: /alathrawaradmin create war [name] [side1] [side2]"));
return true;
}
return true;
}
} else {
return fail(p, args, "syntax");
@@ -541,11 +426,10 @@ public class AdminCommands implements CommandExecutor {
WarCommands.warJoin(p, adjusted, true);
p.sendMessage(Helper.color("&cForced " + args[3] + " to join the war " + args[4] + " on side " + args[5]));
Main.warLogger.log("Forced " + args[3] + " to join the war " + args[4] + " on side " + args[5]);
return true;
} else {
p.sendMessage(Helper.color("&cUsage: /alathrawaradmin force join war [player] [war] [side]"));
return true;
}
return true;
} else {
p.sendMessage(Helper.color("&cUsage: /alathrawaradmin force join [raid/siege/war]"));
return true;
@@ -658,8 +542,10 @@ public class AdminCommands implements CommandExecutor {
side1Players.append(", ");
}
//cut off last two characters
if(side1Towns.length() > 2) side1Towns = new StringBuilder(side1Towns.substring(0, side1Towns.length() - 2));
if(side1Players.length() > 2) side1Players = new StringBuilder(side1Players.substring(0, side1Players.length() - 2));
if (side1Towns.length() > 2)
side1Towns = new StringBuilder(side1Towns.substring(0, side1Towns.length() - 2));
if (side1Players.length() > 2)
side1Players = new StringBuilder(side1Players.substring(0, side1Players.length() - 2));
p.sendMessage(Helper.chatLabel() + w.getSide1() + " Towns: " + side1Towns);
p.sendMessage(Helper.chatLabel() + w.getSide1() + " Players: " + side1Players);
@@ -675,19 +561,15 @@ public class AdminCommands implements CommandExecutor {
side2Players.append(", ");
}
//cut off last two characters
if(side2Towns.length() > 2) side2Towns = new StringBuilder(side2Towns.substring(0, side2Towns.length() - 2));
if(side2Players.length() > 2) side2Players = new StringBuilder(side2Players.substring(0, side2Players.length() - 2));
if (side2Towns.length() > 2)
side2Towns = new StringBuilder(side2Towns.substring(0, side2Towns.length() - 2));
if (side2Players.length() > 2)
side2Players = new StringBuilder(side2Players.substring(0, side2Players.length() - 2));
p.sendMessage(Helper.chatLabel() + w.getSide2() + " Towns: " + side2Towns);
p.sendMessage(Helper.chatLabel() + w.getSide2() + " Players: " + side2Players);
p.sendMessage(Helper.chatLabel() + "oOo------------===------------oOo");
StringBuilder surrenderedTowns = new StringBuilder();
for (String t : w.getSurrenderedTowns()) {
surrenderedTowns.append(t);
surrenderedTowns.append(", ");
}
//cut off last two characters
if(surrenderedTowns.length() > 2) surrenderedTowns = new StringBuilder(surrenderedTowns.substring(0, surrenderedTowns.length() - 2));
final StringBuilder surrenderedTowns = getSurrenderedTowns(w);
p.sendMessage(Helper.chatLabel() + "Surrendered Towns: " + surrenderedTowns);
return true;
}
@@ -718,23 +600,11 @@ public class AdminCommands implements CommandExecutor {
p.sendMessage(Helper.chatLabel() + "Gather Homeblock: " + (r.getHomeBlockGather() == null ? "NONE" : r.getHomeBlockGather().toString()));
p.sendMessage(Helper.chatLabel() + "Raided Homeblock: " + (r.getHomeBlockRaided() == null ? "NONE" : r.getHomeBlockRaided().toString()));
p.sendMessage(Helper.chatLabel() + "oOo------------===------------oOo");
StringBuilder activeRaiders = new StringBuilder();
for (String pl : r.getActiveRaiders()) {
activeRaiders.append(pl);
activeRaiders.append(", ");
}
//cut off last two characters
if(activeRaiders.length() > 2) activeRaiders = new StringBuilder(activeRaiders.substring(0, activeRaiders.length() - 2));
final StringBuilder activeRaiders = getActiveRaiders(r);
p.sendMessage(Helper.chatLabel() + "Raiding Players: " + activeRaiders);
p.sendMessage(Helper.chatLabel() + "oOo------------===------------oOo");
StringBuilder defenderPlayers = new StringBuilder();
for (String pl : r.getDefenderPlayers()) {
defenderPlayers.append(pl);
defenderPlayers.append(", ");
}
//cut off last two characters
if(defenderPlayers.length() > 2) defenderPlayers = new StringBuilder(defenderPlayers.substring(0, defenderPlayers.length() - 2));
final StringBuilder defenderPlayers = getDefenderPlayers(r);
p.sendMessage(Helper.chatLabel() + "Defending Players: " + defenderPlayers);
return true;
}
@@ -768,7 +638,8 @@ public class AdminCommands implements CommandExecutor {
attackers.append(", ");
}
//cut off last two characters
if(attackers.length() > 2) attackers = new StringBuilder(attackers.substring(0, attackers.length() - 2));
if (attackers.length() > 2)
attackers = new StringBuilder(attackers.substring(0, attackers.length() - 2));
p.sendMessage(Helper.chatLabel() + "Attacking Players: " + attackers);
StringBuilder defenders = new StringBuilder();
for (String pl : s.getDefenderPlayers()) {
@@ -776,7 +647,8 @@ public class AdminCommands implements CommandExecutor {
defenders.append(", ");
}
//cut off last two characters
if(defenders.length() > 2) defenders = new StringBuilder(defenders.substring(0, defenders.length() - 2));
if (defenders.length() > 2)
defenders = new StringBuilder(defenders.substring(0, defenders.length() - 2));
p.sendMessage(Helper.chatLabel() + "Defending Players: " + defenders);
return true;
}
@@ -793,6 +665,45 @@ public class AdminCommands implements CommandExecutor {
return fail(p, args, "syntax");
}
@NotNull
private static StringBuilder getDefenderPlayers(Raid r) {
StringBuilder defenderPlayers = new StringBuilder();
for (String pl : r.getDefenderPlayers()) {
defenderPlayers.append(pl);
defenderPlayers.append(", ");
}
//cut off last two characters
if (defenderPlayers.length() > 2)
defenderPlayers = new StringBuilder(defenderPlayers.substring(0, defenderPlayers.length() - 2));
return defenderPlayers;
}
@NotNull
private static StringBuilder getActiveRaiders(Raid r) {
StringBuilder activeRaiders = new StringBuilder();
for (String pl : r.getActiveRaiders()) {
activeRaiders.append(pl);
activeRaiders.append(", ");
}
//cut off last two characters
if (activeRaiders.length() > 2)
activeRaiders = new StringBuilder(activeRaiders.substring(0, activeRaiders.length() - 2));
return activeRaiders;
}
@NotNull
private static StringBuilder getSurrenderedTowns(War w) {
StringBuilder surrenderedTowns = new StringBuilder();
for (String t : w.getSurrenderedTowns()) {
surrenderedTowns.append(t);
surrenderedTowns.append(", ");
}
//cut off last two characters
if (surrenderedTowns.length() > 2)
surrenderedTowns = new StringBuilder(surrenderedTowns.substring(0, surrenderedTowns.length() - 2));
return surrenderedTowns;
}
/**
* //edit war/event in real time, side can be "both" to effect both
* -modify raid score [add/set] [war] [town] [value]
@@ -949,7 +860,7 @@ public class AdminCommands implements CommandExecutor {
t.setSpawn(new Location(runner.getWorld(), Double.parseDouble(args[5]), Double.parseDouble(args[6]), Double.parseDouble(args[7])));
r.setHomeBlockRaided(tb.getTownBlock());
r.setTownSpawnRaided(t.getSpawn());
p.sendMessage(Helper.chatLabel() + "Set town spawn for raided town " + args[4] + " in war " + args[3] + " to " + runner.getLocation().toString());
p.sendMessage(Helper.chatLabel() + "Set town spawn for raided town " + args[4] + " in war " + args[3] + " to " + runner.getLocation());
Main.warLogger.log("Set town spawn for raided town " + args[4] + " in war " + args[3] + " to [" + args[5] + "," + args[6] + "," + args[7] + "]");
return finalizeRaid(r);
} else {
@@ -980,8 +891,8 @@ public class AdminCommands implements CommandExecutor {
t.setSpawn(runner.getLocation());
r.setHomeBlockRaided(tb.getTownBlock());
r.setTownSpawnRaided(t.getSpawn());
p.sendMessage(Helper.chatLabel() + "Set town spawn for raided town " + args[4] + " in war " + args[3] + " to " + runner.getLocation().toString());
Main.warLogger.log("Set town spawn for raided town " + args[4] + " in war " + args[3] + " to " + runner.getLocation().toString());
p.sendMessage(Helper.chatLabel() + "Set town spawn for raided town " + args[4] + " in war " + args[3] + " to " + runner.getLocation());
Main.warLogger.log("Set town spawn for raided town " + args[4] + " in war " + args[3] + " to " + runner.getLocation());
return finalizeRaid(r);
} else {
p.sendMessage(Helper.color("&cTown does not contain town block at your location [" + (int) runner.getLocation().getX() + "," + (int) runner.getLocation().getZ() + "]"));
@@ -1329,7 +1240,7 @@ public class AdminCommands implements CommandExecutor {
t.setSpawn(new Location(runner.getWorld(), (int) Double.parseDouble(args[5]), (int) Double.parseDouble(args[6]), (int) Double.parseDouble(args[7])));
s.setHomeBlock(tb.getTownBlock());
s.setTownSpawn(t.getSpawn());
p.sendMessage(Helper.chatLabel() + "Set town spawn for sieged town " + args[4] + " in war " + args[3] + " to " + runner.getLocation().toString());
p.sendMessage(Helper.chatLabel() + "Set town spawn for sieged town " + args[4] + " in war " + args[3] + " to " + runner.getLocation());
Main.warLogger.log("Set town spawn for sieged town " + args[4] + " in war " + args[3] + " to [" + args[5] + "," + args[6] + "," + args[7] + "]");
return finalizeSiege(s);
} else {
@@ -1361,8 +1272,8 @@ public class AdminCommands implements CommandExecutor {
t.setSpawn(runner.getLocation());
s.setHomeBlock(tb.getTownBlock());
s.setTownSpawn(t.getSpawn());
p.sendMessage(Helper.chatLabel() + "Set town spawn for sieged town " + args[4] + " in war " + args[3] + " to " + runner.getLocation().toString());
Main.warLogger.log("Set town spawn for sieged town " + args[4] + " in war " + args[3] + " to " + runner.getLocation().toString());
p.sendMessage(Helper.chatLabel() + "Set town spawn for sieged town " + args[4] + " in war " + args[3] + " to " + runner.getLocation());
Main.warLogger.log("Set town spawn for sieged town " + args[4] + " in war " + args[3] + " to " + runner.getLocation());
return finalizeSiege(s);
} else {
p.sendMessage(Helper.color("&cTown does not contain town block at your location [" + (int) runner.getLocation().getX() + "," + (int) runner.getLocation().getZ() + "]"));
@@ -1948,7 +1859,7 @@ public class AdminCommands implements CommandExecutor {
private static boolean fail(CommandSender p, String[] args, String type) {
switch (type) {
case "permissions" -> {
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou do not have permission to do this."));
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou do not have permission to do this."));
return true;
}
case "syntax" -> {
@@ -1977,4 +1888,116 @@ public class AdminCommands implements CommandExecutor {
return true;
}
/**
* //done
* //edit war/event in real time, side can be "both" to effect both
* -modify raid score [war] [town] [value]
* -modify raid townspawn [war] [town] (x) (Z)
* -modify raid gather [war] [town] [town]
* -modify raid phase [war] [town] [phase] //"next" to move to next phase
* -modify raid loot [war] [town] (x) (z) [value,looted,ticks,reset] [amt] //no coords just does current chunk, reset deletes it from the list
* -modify raid time [war] [town] [add/set] [value]
* -modify raid owner [war] [town] [add/set] [value]
* -modify raid move [war] [town] [newWar] //low priority, moves raid to other war
* -modify raid clearActive [war] [town] //low priority
* <p>
* -modify siege score [war] [town] [side] [amt]
* -modify siege homeblock [war] [town] (x) (Z)
* -modify siege time [war] [town] [add/set/max] [value] //max modified the max length
* -modify siege owner [war] [town] [add/set] [value]
* -modify siege move [war] [town] [newWar] //low priority, moves siege to other war
* <p>
* -modify war score [war] [side] [amt]
* -modify war side [war] [side] [name]
* -modify war name [war] [name]
* -modify war add town [war] [town]
* -modify war add nation [war] [nation]
* -modify war surrender town [war] [town] //adds town to surrender list
* -modify war surrender nation [war] [town] //adds all towns to surrender list
* -modify war raidTime [add,set,reset] [war] [town] [amt] //set when last raid was
* <p>
* // low priority idea
* -info war score [war]
* -info war surrenderedTowns [war]
* -info war raids [war]
* -info war sieges [war]
* -info war towns [war]
* -info war lastRaidTime [war]
* <p>
* -info raid homeblock [war] [town]
* -info raid lootedTownBlocks [war] [town]
* -info raid timeSinceLastRaid [town]
* <p>
* -info siege homeblock [war] [town]
* <p>
* //done
* //force make event or war, if owner isnt defined, idk havent decided
* -create siege [war] [town] (owner)
* -create raid [war] [raidTown] (gatherTown) (owner)
* -create war [name] [side1] [side2]
* <p>
* //force end a war/event, can declare winner side, or no winner
* -force end war [war] (side/victor)
* -force end siege [war] [town] (side/victor)
* -force end raid [war] [town] (side/victor)
* <p>
* //done
* //force player into or out of a war/event
* -force join war [player] [war] [side]
* -force join siege [player] [war] [town] (side)
* -force join raid [player] [war] [town] (side)
* <p>
* //done
* -force leave raid [war] [player] (timeout) //kicks from raid party
* <p>
* // Ultra low priority idea
* -rule raidersRespawnAtGatherTown [true/false]
* -rule siegersRespawnAtTown [true/false]
* -rule anyoneCanJoinRaid [true/false]
*
* @param sender Source of the command
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args Passed command arguments
* @return Valid command
*/
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
CommandHelper.logCommand(sender, label, args);
if (!sender.hasPermission("AlathraWar.admin")) {
return fail(sender, args, "permissions");
}
if (args.length == 0) {
return fail(sender, args, "syntax");
} else {
if (args[0].equalsIgnoreCase("create")) {
return create(sender, args);
} else if (args[0].equalsIgnoreCase("force")) {
return force(sender, args);
} else if (args[0].equalsIgnoreCase("help")) {
return help(sender, args);
} else if (args[0].equalsIgnoreCase("info")) {
return info(sender, args);
} else if (args[0].equalsIgnoreCase("modify")) {
return modify(sender, args);
} else if (args[0].equalsIgnoreCase("awa")) {
return awa(sender, args);
} else if (args[0].equalsIgnoreCase("purgebars")) {
return purgebars(sender, args);
} else if (args[0].equalsIgnoreCase("save")) {
return save(sender, args);
} else if (args[0].equalsIgnoreCase("save-all")) {
return saveAll(sender, args);
} else if (args[0].equalsIgnoreCase("load")) {
return load(sender, args);
} else if (args[0].equalsIgnoreCase("load-all")) {
return loadAll(sender, args);
} else if (args[0].equalsIgnoreCase("item")) {
return item(sender, args);
}
}
return true;
}
}
@@ -11,8 +11,7 @@ import java.util.List;
public class AdminTabCompletion implements TabCompleter {
List<String> base = List.of(new String[]{
"create",
List<String> base = List.of("create",
"force",
"help",
"info",
@@ -22,8 +21,7 @@ public class AdminTabCompletion implements TabCompleter {
"load-all",
"save",
"save-all",
"item"
});
"item");
List<String> type = List.of(new String[]{
"raid",
@@ -25,6 +25,7 @@ public class CommandHelper {
/**
* Grabs list of all war names
*
* @return list of wars
*/
public static List<String> getWarNames() {
@@ -37,6 +38,7 @@ public class CommandHelper {
/**
* Grabs first matching war and lists the sides
*
* @param name name of war
* @return side of war
*/
@@ -130,6 +132,7 @@ public class CommandHelper {
/**
* return list of all towns in a raid
*
* @return list of all towns involved in a raid
*/
public static List<String> getRaidTowns() {
@@ -142,6 +145,7 @@ public class CommandHelper {
/**
* return list of all towns in a siege
*
* @return list of towns involved in a siege
*/
public static List<String> getSiegeTowns() {
@@ -172,6 +176,7 @@ public class CommandHelper {
/**
* get a list of all online players
*
* @return list of all players online
*/
public static List<String> getPlayers() {
@@ -185,6 +190,7 @@ public class CommandHelper {
/**
* get a list of all raid phases
*
* @return list of all raid phases
*/
public static List<String> getRaidPhases() {
@@ -196,7 +202,6 @@ public class CommandHelper {
}
/**
*
* @param player player to check
* @return 0, 1, 2 (good to go, insufficient join, insufficient playtime)
*/
@@ -209,7 +214,8 @@ public class CommandHelper {
int out = 0;
if (Main.getInstance().getConfig().getInt("minimumPlayerAge") > 0) {
//compare the join date, if they joined less that min age ago it is true
if ((System.currentTimeMillis() - regTime) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge")) out = 1;
if ((System.currentTimeMillis() - regTime) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge"))
out = 1;
}
if (Main.getInstance().getConfig().getInt("minimumPlayTime") > 0) {
//check playtime, if its less than min its true
@@ -224,6 +230,7 @@ public class CommandHelper {
/**
* log the command
*
* @param sender sender
* @param label command
* @param args command args
@@ -234,11 +241,12 @@ public class CommandHelper {
for (String s : args) {
log.append(" ").append(s);
}
Main.warLogger.log(Helper.chatLabel() + sender.getName() + " ran command: " + log.toString());
Main.warLogger.log(Helper.chatLabel() + sender.getName() + " ran command: " + log);
}
/**
* return list of all alathrawar items with namespace
*
* @return list of all alathrawar items namespaced
*/
public static List<String> getWarItems() {
@@ -3,12 +3,14 @@ package me.ShermansWorld.AlathraWar.commands;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.object.*;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownyWorld;
import com.palmergames.bukkit.towny.object.WorldCoord;
import me.ShermansWorld.AlathraWar.*;
import me.ShermansWorld.AlathraWar.data.RaidData;
import me.ShermansWorld.AlathraWar.data.RaidPhase;
import me.ShermansWorld.AlathraWar.data.SiegeData;
import me.ShermansWorld.AlathraWar.data.WarData;
import me.ShermansWorld.AlathraWar.data.RaidData;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
@@ -22,40 +24,7 @@ import java.util.ArrayList;
public class RaidCommands implements CommandExecutor {
public RaidCommands(final Main plugin) {
plugin.getCommand("raid").setExecutor((CommandExecutor)this);
}
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
// final Player p = (Player) sender;
CommandHelper.logCommand(sender, label, args);
if (args.length == 0) {
fail(sender, args, "syntax");
} else if (args.length == 1) {
if (args[0].equalsIgnoreCase("list")) {
listRaids(sender, args);
} else if (args[0].equalsIgnoreCase("help")) {
raidHelp(sender, args);
} else {
fail(sender, args, "syntax");
}
}else if (args.length == 3) {
if (args[0].equalsIgnoreCase("start")) {
startRaid(sender, args, false);
} else if (args[0].equalsIgnoreCase("stop")) {
stopRaid(sender, args);
} else if (args[0].equalsIgnoreCase("join")) {
joinRaid(sender, args, false);
} else if (args[0].equalsIgnoreCase("leave")) {
leaveRaid(sender, args, false);
} else if (args[0].equalsIgnoreCase("abandon")) {
abandonRaid(sender, args);
} else {
fail(sender, args, "syntax");
}
} else {
fail(sender, args, "syntax");
}
return true;
plugin.getCommand("raid").setExecutor(this);
}
/**
@@ -92,13 +61,13 @@ public class RaidCommands implements CommandExecutor {
TownyWorld townyWorld;
townyWorld = WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownyWorld();
String side = "";
String side;
if (war.getSide1Players().contains(raidOwner.getName())) {
side = war.getSide1();
} else if (war.getSide2Players().contains(raidOwner.getName())) {
side = war.getSide2();
} else {
p.sendMessage(String.valueOf(Helper.chatLabel()) + "You are not in this war! Type /war join [war] [side]");
p.sendMessage(Helper.chatLabel() + "You are not in this war! Type /war join [war] [side]");
return;
}
@@ -119,12 +88,14 @@ public class RaidCommands implements CommandExecutor {
if (minuteman != 0) {
if (minuteman == 1) {
//player has joined to recently
if (admin) p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
if (admin)
p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
raidOwner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
return;
} else if (minuteman == 2) {
//player has played too little
if (admin) p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
if (admin)
p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
raidOwner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
return;
}
@@ -133,7 +104,7 @@ public class RaidCommands implements CommandExecutor {
//check if in a town
//takes the command runners town as the gather point
Town gatherTown = null;
Town gatherTown;
try {
//if admin, and we have a gather town argument, use it
if (admin && args.length >= 5) {
@@ -143,21 +114,24 @@ public class RaidCommands implements CommandExecutor {
} else if (TownyAPI.getInstance().getTown(args[4]) != null) {
gatherTown = TownyAPI.getInstance().getTown(args[4]);
} else {
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "No valid town set for gather town, defaulting to current location");
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "No valid town set for gather town, defaulting to current location");
if (admin)
p.sendMessage(Helper.chatLabel() + "No valid town set for gather town, defaulting to current location");
raidOwner.sendMessage(Helper.chatLabel() + "No valid town set for gather town, defaulting to current location");
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock());
}
} else {
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock());
}
} catch (NotRegisteredException e2) {
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
if (admin)
p.sendMessage(Helper.chatLabel() + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
raidOwner.sendMessage(Helper.chatLabel() + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
return;
}
if (gatherTown == null) {
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
if (admin)
p.sendMessage(Helper.chatLabel() + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
raidOwner.sendMessage(Helper.chatLabel() + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
return;
}
@@ -187,20 +161,23 @@ public class RaidCommands implements CommandExecutor {
//check if the town were attempting to raid is in the war
if (!war.getSide1Towns().contains(raidedTown.getName().toLowerCase()) && !war.getSide2Towns().contains(raidedTown.getName().toLowerCase())) {
if (war.getSurrenderedTowns().contains(raidedTown.getName().toLowerCase())) {
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "The town you are trying to raid has already surrendered!");
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "The town you are trying to raid has already surrendered!");
if (admin)
p.sendMessage(Helper.chatLabel() + "The town you are trying to raid has already surrendered!");
raidOwner.sendMessage(Helper.chatLabel() + "The town you are trying to raid has already surrendered!");
return;
}
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "The town you are trying to raid is not part of the war!");
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "The town you are trying to raid is not part of the war!");
if (admin)
p.sendMessage(Helper.chatLabel() + "The town you are trying to raid is not part of the war!");
raidOwner.sendMessage(Helper.chatLabel() + "The town you are trying to raid is not part of the war!");
return;
}
// Is being sieged check
for (Siege s : SiegeData.getSieges()) {
if (s.getTown().getName().equalsIgnoreCase(raidedTown.getName())) {
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "That town is already currently being sieged! Cannot raid at this time!");
if(admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "That town is already currently being sieged! Cannot raid at this time!");
raidOwner.sendMessage(Helper.chatLabel() + "That town is already currently being sieged! Cannot raid at this time!");
if (admin)
p.sendMessage(Helper.chatLabel() + "That town is already currently being sieged! Cannot raid at this time!");
}
}
@@ -214,20 +191,24 @@ public class RaidCommands implements CommandExecutor {
//if were admin, see if an owner arg exists, and if so then use it
raid2 = new Raid(war, raidedTown, gatherTown, true, raidOwner);
} else if (c == 1) {
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "This town is already being raided at this time!");
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "This town is already being raided at this time!");
if (admin)
p.sendMessage(Helper.chatLabel() + "This town is already being raided at this time!");
raidOwner.sendMessage(Helper.chatLabel() + "This town is already being raided at this time!");
return;
} else if (c == 0) {
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Your side has raided too recently!");
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "Your side has raided too recently!");
if (admin)
p.sendMessage(Helper.chatLabel() + "Your side has raided too recently!");
raidOwner.sendMessage(Helper.chatLabel() + "Your side has raided too recently!");
return;
} else if (c == -1) {
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "This town was raided too recently!");
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "This town was raided too recently!");
if (admin)
p.sendMessage(Helper.chatLabel() + "This town was raided too recently!");
raidOwner.sendMessage(Helper.chatLabel() + "This town was raided too recently!");
return;
} else if (c == -2) {
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "At least on member of the raided town must be online to defend it!");
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "At least on member of the raided town must be online to defend it!");
if (admin)
p.sendMessage(Helper.chatLabel() + "At least on member of the raided town must be online to defend it!");
raidOwner.sendMessage(Helper.chatLabel() + "At least on member of the raided town must be online to defend it!");
return;
} else {
throw new IllegalArgumentException();
@@ -243,20 +224,24 @@ public class RaidCommands implements CommandExecutor {
if (c == 2) {
raid2 = new Raid(war, raidedTown, gatherTown, false, raidOwner);
} else if (c == 1) {
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "This town is already being raided at this time!");
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "This town is already being raided at this time!");
if (admin)
p.sendMessage(Helper.chatLabel() + "This town is already being raided at this time!");
raidOwner.sendMessage(Helper.chatLabel() + "This town is already being raided at this time!");
return;
} else if (c == 0) {
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Your side has raided too recently!");
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "Your side has raided too recently!");
if (admin)
p.sendMessage(Helper.chatLabel() + "Your side has raided too recently!");
raidOwner.sendMessage(Helper.chatLabel() + "Your side has raided too recently!");
return;
} else if (c == -1) {
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "This town was raided too recently!");
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "This town was raided too recently!");
if (admin)
p.sendMessage(Helper.chatLabel() + "This town was raided too recently!");
raidOwner.sendMessage(Helper.chatLabel() + "This town was raided too recently!");
return;
} else if (c == -2) {
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "At least on member of the raided town must be online to defend it!");
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "At least on member of the raided town must be online to defend it!");
if (admin)
p.sendMessage(Helper.chatLabel() + "At least on member of the raided town must be online to defend it!");
raidOwner.sendMessage(Helper.chatLabel() + "At least on member of the raided town must be online to defend it!");
return;
} else {
throw new IllegalArgumentException();
@@ -286,8 +271,9 @@ public class RaidCommands implements CommandExecutor {
//check player balance
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(raidOwner.getUniqueId());
if (Main.econ.getBalance(offlinePlayer) <= 1000.0) {
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "You must have at least $1000 to put up to start a raid.");
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "You must have at least $1000 to put up to start a raid.");
if (admin)
p.sendMessage(Helper.chatLabel() + "You must have at least $1000 to put up to start a raid.");
raidOwner.sendMessage(Helper.chatLabel() + "You must have at least $1000 to put up to start a raid.");
return;
}
@@ -299,10 +285,10 @@ public class RaidCommands implements CommandExecutor {
WarData.saveWar(raid2.getWar());
//broadcast
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "As part of " + war.getName() + ", forces from " + raid2.getRaiderSide() + " are gathering to raid the town of " + raidedTown.getName() + "!");
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "All players from the defending side have been drafted for the town's defense.");
Bukkit.broadcastMessage(Helper.chatLabel() + "As part of " + war.getName() + ", forces from " + raid2.getRaiderSide() + " are gathering to raid the town of " + raidedTown.getName() + "!");
Bukkit.broadcastMessage(Helper.chatLabel() + "All players from the defending side have been drafted for the town's defense.");
Bukkit.broadcastMessage(Helper.chatLabel() + "The raid of "
+ raidedTown.getName() + " will begin in " + (int) (RaidPhase.TRAVEL.startTick / 20 / 60) + " minutes!");
+ raidedTown.getName() + " will begin in " + (RaidPhase.TRAVEL.startTick / 20 / 60) + " minutes!");
Bukkit.broadcastMessage(Helper.chatLabel() +
"The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!");
@@ -346,8 +332,8 @@ public class RaidCommands implements CommandExecutor {
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
if (raid != null) {
p.sendMessage(String.valueOf(Helper.chatLabel()) + "raid cancelled");
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The raid of " + raid.getRaidedTown().getName() + " has been cancelled by an admin");
p.sendMessage(Helper.chatLabel() + "raid cancelled");
Bukkit.broadcastMessage(Helper.chatLabel() + "The raid of " + raid.getRaidedTown().getName() + " has been cancelled by an admin");
raid.stop(); //this purges itself from raids
} else {
fail(p, args, "badName");
@@ -372,31 +358,31 @@ public class RaidCommands implements CommandExecutor {
if (args[4].equalsIgnoreCase(raid.getDefenderSide())) {
if (!raid.getDefenderPlayers().contains(joiner.getName()))
raid.getDefenderPlayers().add(joiner.getName());
p.sendMessage(String.valueOf(Helper.chatLabel()) + "Player " + joiner.getName() + " added to defender side.");
p.sendMessage(Helper.chatLabel() + "Player " + joiner.getName() + " added to defender side.");
Main.warLogger.log("Player " + joiner.getName() + " added to defender side.");
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You were forcefully added to the defender side against the raid party on " + raid.getRaidedTown() + " by an admin.");
joiner.sendMessage(Helper.chatLabel() + "You were forcefully added to the defender side against the raid party on " + raid.getRaidedTown() + " by an admin.");
return;
} else {
if (!raid.getRaiderPlayers().contains(joiner.getName()))
raid.getRaiderPlayers().add(joiner.getName());
p.sendMessage(String.valueOf(Helper.chatLabel()) + "Player " + joiner.getName() + " added to raider side.");
p.sendMessage(Helper.chatLabel() + "Player " + joiner.getName() + " added to raider side.");
Main.warLogger.log("Player " + joiner.getName() + " added to raider side.");
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You were forcefully added to the raid party on " + raid.getRaidedTown() + " by an admin. Leaving the gather town will remove you from the raid party.");
joiner.sendMessage(Helper.chatLabel() + "You were forcefully added to the raid party on " + raid.getRaidedTown() + " by an admin. Leaving the gather town will remove you from the raid party.");
}
}
} else {
p.sendMessage(String.valueOf(Helper.chatLabel()) + "Player " + args[3] + " not found!");
p.sendMessage(Helper.chatLabel() + "Player " + args[3] + " not found!");
return;
}
}
if (joiner == null) {
p.sendMessage(String.valueOf(Helper.chatLabel()) + "Player not found! Is something broken?");
p.sendMessage(Helper.chatLabel() + "Player not found! Is something broken?");
return;
}
if (!raid.getWar().getSide1Players().contains(joiner.getName()) && !raid.getWar().getSide2Players().contains(joiner.getName())) {
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You are not in this war! Type /war join [war] [side]");
joiner.sendMessage(Helper.chatLabel() + "You are not in this war! Type /war join [war] [side]");
}
//Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime
@@ -416,12 +402,14 @@ public class RaidCommands implements CommandExecutor {
if (minuteman != 0) {
if (minuteman == 1) {
//player has joined to recently
if (admin) p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
if (admin)
p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
joiner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
return;
} else if (minuteman == 2) {
//player has played too little
if (admin) p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
if (admin)
p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
joiner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
return;
}
@@ -436,16 +424,16 @@ public class RaidCommands implements CommandExecutor {
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
if (cluster.contains(WorldCoord.parseWorldCoord(joiner))) {
raid.addActiveRaider(joiner.getName());
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
joiner.sendMessage(Helper.chatLabel() + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
joiner.sendMessage(Helper.chatLabel() + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
} else {
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be in the gathering town to join the raid on " + raid.getRaidedTown().getName() + ".");
joiner.sendMessage(Helper.chatLabel() + "You must be in the gathering town to join the raid on " + raid.getRaidedTown().getName() + ".");
}
} catch (TownyException e) {
throw new RuntimeException(e);
}
} else {
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You cannot join the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
joiner.sendMessage(Helper.chatLabel() + "You cannot join the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
}
} else {
try {
@@ -453,10 +441,10 @@ public class RaidCommands implements CommandExecutor {
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
if (cluster.contains(WorldCoord.parseWorldCoord(joiner))) {
raid.addActiveRaider(joiner.getName());
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
joiner.sendMessage(Helper.chatLabel() + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
joiner.sendMessage(Helper.chatLabel() + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
} else {
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be in the gathering town to join the raid on " + raid.getRaidedTown().getName() + ".");
joiner.sendMessage(Helper.chatLabel() + "You must be in the gathering town to join the raid on " + raid.getRaidedTown().getName() + ".");
}
} catch (TownyException e) {
throw new RuntimeException(e);
@@ -466,7 +454,7 @@ public class RaidCommands implements CommandExecutor {
raid.save();
}
} else {
p.sendMessage(String.valueOf(Helper.chatLabel()) + "No raid is gathering in this town or this town does not exist!");
p.sendMessage(Helper.chatLabel() + "No raid is gathering in this town or this town does not exist!");
}
}
@@ -476,7 +464,7 @@ public class RaidCommands implements CommandExecutor {
if (admin) {
p = Bukkit.getPlayer(args[3]);
if (p == null) {
player.sendMessage(String.valueOf(Helper.chatLabel()) + "Error: player not found!");
player.sendMessage(Helper.chatLabel() + "Error: player not found!");
return;
}
}
@@ -488,8 +476,9 @@ public class RaidCommands implements CommandExecutor {
if (raid != null) {
if (raid.getWar().getName().equalsIgnoreCase(args[1])) {
if (!raid.getWar().getSide1Players().contains(p.getName()) && !raid.getWar().getSide2Players().contains(p.getName())) {
p.sendMessage(String.valueOf(Helper.chatLabel()) + "You are not in this war! Type /war join [war] [side]");
if (admin) player.sendMessage(String.valueOf(Helper.chatLabel()) + "You are not in this war! Type /war join [war] [side]");
p.sendMessage(Helper.chatLabel() + "You are not in this war! Type /war join [war] [side]");
if (admin)
player.sendMessage(Helper.chatLabel() + "You are not in this war! Type /war join [war] [side]");
}
//check if gather phase
@@ -499,12 +488,14 @@ public class RaidCommands implements CommandExecutor {
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
if (cluster.contains(WorldCoord.parseWorldCoord(p))) {
raid.removeActiveRaider(p.getName());
p.sendMessage(String.valueOf(Helper.chatLabel()) + "You have left the raid on " + raid.getRaidedTown().getName() + "!");
if (admin) player.sendMessage(String.valueOf(Helper.chatLabel()) + "You have left the raid on " + raid.getRaidedTown().getName() + "!");
p.sendMessage(Helper.chatLabel() + "You have left the raid on " + raid.getRaidedTown().getName() + "!");
if (admin)
player.sendMessage(Helper.chatLabel() + "You have left the raid on " + raid.getRaidedTown().getName() + "!");
} else {
p.sendMessage(String.valueOf(Helper.chatLabel()) + "You cannot leave the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
if (admin) player.sendMessage(String.valueOf(Helper.chatLabel()) + "You cannot leave the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
p.sendMessage(Helper.chatLabel() + "You cannot leave the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
if (admin)
player.sendMessage(Helper.chatLabel() + "You cannot leave the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
}
} catch (TownyException e) {
throw new RuntimeException(e);
@@ -514,8 +505,9 @@ public class RaidCommands implements CommandExecutor {
raid.save();
} else {
p.sendMessage(String.valueOf(Helper.chatLabel()) + "No raid is gathering in this town or this town does not exist!");
if (admin) player.sendMessage(String.valueOf(Helper.chatLabel()) + "No raid is gathering in this town or this town does not exist!");
p.sendMessage(Helper.chatLabel() + "No raid is gathering in this town or this town does not exist!");
if (admin)
player.sendMessage(Helper.chatLabel() + "No raid is gathering in this town or this town does not exist!");
}
}
@@ -531,7 +523,7 @@ public class RaidCommands implements CommandExecutor {
if (raid != null) {
if (raid.getWar().getName().equalsIgnoreCase(args[1])) {
if (!raid.getWar().getSide1Players().contains(p.getName()) && !raid.getWar().getSide2Players().contains(p.getName())) {
p.sendMessage(String.valueOf(Helper.chatLabel()) + "You are not in this war! Type /war join [war] [side]");
p.sendMessage(Helper.chatLabel() + "You are not in this war! Type /war join [war] [side]");
return;
}
@@ -539,11 +531,11 @@ public class RaidCommands implements CommandExecutor {
//check if gather phase
if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START || raid.getPhase() == RaidPhase.TRAVEL || raid.getPhase() == RaidPhase.COMBAT) {
//force defender victory
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The raid on " + raid.getRaidedTown().getName() + " has been abandoned by " + raid.getRaiderSide());
Bukkit.broadcastMessage(Helper.chatLabel() + "The raid on " + raid.getRaidedTown().getName() + " has been abandoned by " + raid.getRaiderSide());
Main.warLogger.log(p.getName() + " abandoned the raid on " + raid.getRaidedTown().getName() + " they started at " + raid.getGatherTown().getName());
raid.defendersWin(raid.getRaiderScore(), raid.getDefenderScore());
} else {
p.sendMessage(String.valueOf(Helper.chatLabel()) + "You cannot abandon the raid on " + raid.getRaidedTown().getName() + "! It has a problem!");
p.sendMessage(Helper.chatLabel() + "You cannot abandon the raid on " + raid.getRaidedTown().getName() + "! It has a problem!");
}
} else {
fail(p, args, "owner");
@@ -551,15 +543,15 @@ public class RaidCommands implements CommandExecutor {
}
}
p.sendMessage(String.valueOf(Helper.chatLabel()) + "This raid does not exist!");
p.sendMessage(Helper.chatLabel() + "This raid does not exist!");
}
private static void listRaids(CommandSender p, String[] args) {
if (RaidData.getRaids().isEmpty()) {
p.sendMessage(String.valueOf(Helper.chatLabel()) + "There are currently no Raids in progress");
p.sendMessage(Helper.chatLabel() + "There are currently no Raids in progress");
return;
}
p.sendMessage(String.valueOf(Helper.chatLabel()) + "Raids currently in progress:");
p.sendMessage(Helper.chatLabel() + "Raids currently in progress:");
for (final Raid raid : RaidData.getRaids()) {
p.sendMessage("Name: " + raid.getName());
p.sendMessage("War: " + raid.getWar().getName());
@@ -589,12 +581,49 @@ public class RaidCommands implements CommandExecutor {
private static void fail(CommandSender p, String[] args, String type) {
switch (type) {
case "permissions" -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "&cYou do not have permission to do this");
case "syntax" -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "Invalid Syntax. /raid help");
case "noRaids" -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "There are currently no Raids in progress");
case "badName" -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "A raid could not be found with this Name! Type /raid list to view current raids");
case "owner" -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "Only the player who started the raid can abandon it.");
default -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "Invalid Arguments. /raid help");
case "permissions" ->
p.sendMessage(Helper.chatLabel() + "&cYou do not have permission to do this");
case "syntax" -> p.sendMessage(Helper.chatLabel() + "Invalid Syntax. /raid help");
case "noRaids" ->
p.sendMessage(Helper.chatLabel() + "There are currently no Raids in progress");
case "badName" ->
p.sendMessage(Helper.chatLabel() + "A raid could not be found with this Name! Type /raid list to view current raids");
case "owner" ->
p.sendMessage(Helper.chatLabel() + "Only the player who started the raid can abandon it.");
default -> p.sendMessage(Helper.chatLabel() + "Invalid Arguments. /raid help");
}
}
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
// final Player p = (Player) sender;
CommandHelper.logCommand(sender, label, args);
if (args.length == 0) {
fail(sender, args, "syntax");
} else if (args.length == 1) {
if (args[0].equalsIgnoreCase("list")) {
listRaids(sender, args);
} else if (args[0].equalsIgnoreCase("help")) {
raidHelp(sender, args);
} else {
fail(sender, args, "syntax");
}
} else if (args.length == 3) {
if (args[0].equalsIgnoreCase("start")) {
startRaid(sender, args, false);
} else if (args[0].equalsIgnoreCase("stop")) {
stopRaid(sender, args);
} else if (args[0].equalsIgnoreCase("join")) {
joinRaid(sender, args, false);
} else if (args[0].equalsIgnoreCase("leave")) {
leaveRaid(sender, args, false);
} else if (args[0].equalsIgnoreCase("abandon")) {
abandonRaid(sender, args);
} else {
fail(sender, args, "syntax");
}
} else {
fail(sender, args, "syntax");
}
return true;
}
}
@@ -1,63 +1,24 @@
package me.ShermansWorld.AlathraWar.commands;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.Town;
import me.ShermansWorld.AlathraWar.*;
import me.ShermansWorld.AlathraWar.data.RaidData;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.OfflinePlayer;
import com.palmergames.bukkit.towny.TownyAPI;
import me.ShermansWorld.AlathraWar.data.SiegeData;
import me.ShermansWorld.AlathraWar.data.WarData;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.palmergames.bukkit.towny.object.Town;
import org.bukkit.entity.Player;
import java.util.HashSet;
import org.bukkit.command.CommandExecutor;
public class SiegeCommands implements CommandExecutor {
public SiegeCommands(final Main plugin) {
plugin.getCommand("siege").setExecutor((CommandExecutor) this);
}
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
CommandHelper.logCommand(sender, label, args);
if (args.length == 0) {
sender.sendMessage(String.valueOf(Helper.chatLabel()) + "Invalid Arguments. /siege help");
return true;
}
// Start
// Stop
// Abandon
// List
// Help
switch (args[0].toLowerCase()) {
case "start" -> {
siegeStart(sender, args, false);
return true;
}
case "stop" -> {
siegeStop(sender, args);
return true;
}
case "abandon" -> {
siegeAbandon(sender, args);
return true;
}
case "list" -> {
siegeList(sender, args);
return true;
}
case "help" -> {
siegeHelp(sender, args);
return true;
}
}
return false;
plugin.getCommand("siege").setExecutor(this);
}
protected static void siegeStart(CommandSender sender, String[] args, boolean admin) {
@@ -89,8 +50,9 @@ public class SiegeCommands implements CommandExecutor {
// War check
War war = WarData.getWar(args[1]);
if (war == null) {
siegeOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "That war does not exist! /siege start [war] [town]");
if(admin) sender.sendMessage(String.valueOf(Helper.chatLabel()) + "That war does not exist! /siege start [war] [town]");
siegeOwner.sendMessage(Helper.chatLabel() + "That war does not exist! /siege start [war] [town]");
if (admin)
sender.sendMessage(Helper.chatLabel() + "That war does not exist! /siege start [war] [town]");
return;
}
@@ -142,12 +104,14 @@ public class SiegeCommands implements CommandExecutor {
if (minuteman != 0) {
if (minuteman == 1) {
//player has joined to recently
if (admin) sender.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
if (admin)
sender.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
siegeOwner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
return;
} else if (minuteman == 2) {
//player has played too little
if (admin) sender.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
if (admin)
sender.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
siegeOwner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
return;
}
@@ -157,8 +121,9 @@ public class SiegeCommands implements CommandExecutor {
// Town check
Town town = TownyAPI.getInstance().getTown(args[2]);
if (town == null) {
siegeOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "That town does not exist! /siege start [war] [town]");
if(admin) sender.sendMessage(String.valueOf(Helper.chatLabel()) + "That town does not exist! /siege start [war] [town]");
siegeOwner.sendMessage(Helper.chatLabel() + "That town does not exist! /siege start [war] [town]");
if (admin)
sender.sendMessage(Helper.chatLabel() + "That town does not exist! /siege start [war] [town]");
return;
}
Main.warLogger.log("Attacked Town: " + town.getName().toLowerCase());
@@ -167,8 +132,9 @@ public class SiegeCommands implements CommandExecutor {
// Is being raided check
for (Raid r : RaidData.getRaids()) {
if (r.getRaidedTown().getName().equalsIgnoreCase(town.getName())) {
siegeOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "That town is already currently being raided! Cannot siege at this time!");
if(admin) sender.sendMessage(String.valueOf(Helper.chatLabel()) + "That town is already currently being raided! Cannot siege at this time!");
siegeOwner.sendMessage(Helper.chatLabel() + "That town is already currently being raided! Cannot siege at this time!");
if (admin)
sender.sendMessage(Helper.chatLabel() + "That town is already currently being raided! Cannot siege at this time!");
return;
}
}
@@ -192,12 +158,12 @@ public class SiegeCommands implements CommandExecutor {
private static void siegeStop(CommandSender sender, String[] args) {
if (!sender.hasPermission("AlathraWar.admin")) {
sender.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou do not have permission to do this"));
sender.sendMessage(Helper.chatLabel() + Helper.color("&cYou do not have permission to do this"));
return;
}
HashSet<Siege> sieges = SiegeData.getSieges();
if (sieges.isEmpty()) {
sender.sendMessage(String.valueOf(Helper.chatLabel()) + "There are currently no sieges in progress");
sender.sendMessage(Helper.chatLabel() + "There are currently no sieges in progress");
return;
}
@@ -209,25 +175,24 @@ public class SiegeCommands implements CommandExecutor {
// War check
War war = WarData.getWar(args[1]);
if (war == null) {
sender.sendMessage(String.valueOf(Helper.chatLabel()) + "That war does not exist! /siege stop [war] [town]");
sender.sendMessage(Helper.chatLabel() + "That war does not exist! /siege stop [war] [town]");
return;
}
for (Siege siege : sieges) {
if (siege.getTown().getName().equalsIgnoreCase(args[2])) {
sender.sendMessage(String.valueOf(Helper.chatLabel()) + "siege cancelled");
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The siege at " + siege.getTown().getName() + " has been cancelled by an admin");
sender.sendMessage(Helper.chatLabel() + "siege cancelled");
Bukkit.broadcastMessage(Helper.chatLabel() + "The siege at " + siege.getTown().getName() + " has been cancelled by an admin");
//siege.clearBeacon();
siege.stop();
return;
}
}
sender.sendMessage(String.valueOf(Helper.chatLabel()) + "A siege could not be found with this town name! Type /siege list to view current sieges");
sender.sendMessage(Helper.chatLabel() + "A siege could not be found with this town name! Type /siege list to view current sieges");
}
private static void siegeAbandon(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) return;
final Player p = (Player) sender;
if (!(sender instanceof Player p)) return;
if (args.length < 3) {
sender.sendMessage(Helper.chatLabel() + "/siege abandon [town]");
@@ -237,7 +202,7 @@ public class SiegeCommands implements CommandExecutor {
// War check
War war = WarData.getWar(args[1]);
if (war == null) {
p.sendMessage(String.valueOf(Helper.chatLabel()) + "That war does not exist! /siege abandon [war] [town]");
p.sendMessage(Helper.chatLabel() + "That war does not exist! /siege abandon [war] [town]");
return;
}
@@ -248,12 +213,12 @@ public class SiegeCommands implements CommandExecutor {
}
OfflinePlayer oPlayer = siege.getSiegeLeader();
if (oPlayer != (OfflinePlayer) p) {
if (oPlayer != p) {
p.sendMessage(Helper.chatLabel() + "You are not the leader of this siege.");
return;
}
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The siege at " + siege.getTown().getName() + " has been abandoned.");
Bukkit.broadcastMessage(Helper.chatLabel() + "The siege at " + siege.getTown().getName() + " has been abandoned.");
Main.warLogger.log(p.getName() + " abandoned the siege they started at " + siege.getTown().getName());
siege.defendersWin();
@@ -262,11 +227,11 @@ public class SiegeCommands implements CommandExecutor {
private static void siegeList(CommandSender sender, String[] args) {
HashSet<Siege> sieges = SiegeData.getSieges();
if (sieges.isEmpty()) {
sender.sendMessage(String.valueOf(Helper.chatLabel()) + "There are currently no sieges in progress");
sender.sendMessage(Helper.chatLabel() + "There are currently no sieges in progress");
return;
}
sender.sendMessage(String.valueOf(Helper.chatLabel()) + "Sieges currently in progress:");
sender.sendMessage(Helper.chatLabel() + "Sieges currently in progress:");
for (Siege siege : sieges) {
War war = siege.getWar();
String color = (siege.getSide1AreAttackers() && (war.getSide(siege.getTown().getName().toLowerCase()) == 1)) ? "§c" : "§9";
@@ -287,4 +252,42 @@ public class SiegeCommands implements CommandExecutor {
sender.sendMessage(Helper.chatLabel() + "/siege abandon [war] [town]");
sender.sendMessage(Helper.chatLabel() + "/siege list");
}
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
CommandHelper.logCommand(sender, label, args);
if (args.length == 0) {
sender.sendMessage(Helper.chatLabel() + "Invalid Arguments. /siege help");
return true;
}
// Start
// Stop
// Abandon
// List
// Help
switch (args[0].toLowerCase()) {
case "start" -> {
siegeStart(sender, args, false);
return true;
}
case "stop" -> {
siegeStop(sender, args);
return true;
}
case "abandon" -> {
siegeAbandon(sender, args);
return true;
}
case "list" -> {
siegeList(sender, args);
return true;
}
case "help" -> {
siegeHelp(sender, args);
return true;
}
}
return false;
}
}
@@ -1,69 +1,23 @@
package me.ShermansWorld.AlathraWar.commands;
import me.ShermansWorld.AlathraWar.*;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import me.ShermansWorld.AlathraWar.*;
import me.ShermansWorld.AlathraWar.data.WarData;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
public class WarCommands implements CommandExecutor {
public WarCommands(final Main plugin) {
plugin.getCommand("war").setExecutor((CommandExecutor) this);
}
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
CommandHelper.logCommand(sender, label, args);
if (!(sender instanceof Player)) {
consoleCommand(sender, args);
return true;
}
final Player p = (Player) sender;
if (args.length == 0) {
p.sendMessage(String.valueOf(Helper.chatLabel()) + "Invalid Arguments. /war help");
return true;
} else if (args.length >= 1) {
switch(args[0].toLowerCase()) {
case "create":
warCreate(p, args);
return true;
case "delete":
warDelete(p, args);
return true;
case "join":
warJoin(p, args, false);
return true;
case "surrender":
warSurrender(p, args, false);
return true;
case "list":
warList(p, args);
return true;
case "info":
warInfo(p, args);
return true;
case "help":
warHelp(p, args);
return true;
default:
p.sendMessage(String.valueOf(Helper.chatLabel()) + "Invalid Arguments. /war help");
return true;
}
}
return false;
plugin.getCommand("war").setExecutor(this);
}
protected static void warCreate(CommandSender p, String[] args) {
@@ -76,13 +30,12 @@ public class WarCommands implements CommandExecutor {
WarData.addWar(war);
war.save();
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "War created with the name " + args[1] + ", "
Bukkit.broadcastMessage(Helper.chatLabel() + "War created with the name " + args[1] + ", "
+ args[2] + " vs. " + args[3]);
Main.warLogger.log(p.getName() + " created a new war with the name " + args[1] + ", " + args[2]
+ " vs. " + args[3]);
return;
} else {
p.sendMessage(String.valueOf(Helper.chatLabel())
p.sendMessage(Helper.chatLabel()
+ "Invalid Arguments. /war create [name] [side1] [side2]");
}
@@ -113,17 +66,15 @@ public class WarCommands implements CommandExecutor {
WarData.removeWar(war);
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "War " + args[1] + " deleted.");
Bukkit.broadcastMessage(Helper.chatLabel() + "War " + args[1] + " deleted.");
Main.warLogger.log(p.getName() + " deleted " + args[1]);
return;
} else {
p.sendMessage(String.valueOf(Helper.chatLabel())
p.sendMessage(Helper.chatLabel()
+ "Invalid Arguments. /war delete [name]");
}
}
/**
*
* @param p - executor
* @param args
* @param admin - admin behavior
@@ -184,12 +135,14 @@ public class WarCommands implements CommandExecutor {
if (minuteman != 0) {
if (minuteman == 1) {
//player has joined to recently
if (admin) p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
if (admin)
p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
player.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
return;
} else if (minuteman == 2) {
//player has played too little
if (admin) p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
if (admin)
p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
player.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
return;
}
@@ -214,11 +167,9 @@ public class WarCommands implements CommandExecutor {
p.sendMessage(Helper.chatLabel() + "You have joined the war for " + res.getNationOrNull().getName());
Bukkit.broadcastMessage(Helper.chatLabel() + "The nation of " + res.getNationOrNull().getName() + " has joined the war on the side of " + args[2] + "!");
war.save();
return;
} else {
// Cannot declare nation involvement
p.sendMessage(Helper.chatLabel() + "You cannot declare war for your nation.");
return;
}
} else if (res.hasTown()) {
if (res.getPlayer().hasPermission("AlathraWar.townjoin") || res.isMayor()) {
@@ -228,11 +179,9 @@ public class WarCommands implements CommandExecutor {
p.sendMessage(Helper.chatLabel() + "You have joined the war for " + res.getTownOrNull().getName());
Bukkit.broadcastMessage(Helper.chatLabel() + "The town of " + res.getTownOrNull().getName() + " has joined the war on the side of " + args[2] + "!");
war.save();
return;
} else {
// No perms
p.sendMessage(Helper.chatLabel() + "You cannot declare war for your town.");
return;
}
}
}
@@ -270,11 +219,9 @@ public class WarCommands implements CommandExecutor {
p.sendMessage(Helper.chatLabel() + "You have surrendered the war for " + res.getNationOrNull().getName());
Bukkit.broadcastMessage(Helper.chatLabel() + "The nation of " + res.getNationOrNull().getName() + " has surrendered! They were fighting for " + args[2] + ".");
war.save();
return;
} else {
// Cannot surrender nation involvement
p.sendMessage(Helper.chatLabel() + "You cannot surrender war for your nation.");
return;
}
} else if (res.hasTown()) {
if (p.hasPermission("AlathraWar.townsurrender") || res.isMayor()) {
@@ -283,11 +230,9 @@ public class WarCommands implements CommandExecutor {
p.sendMessage(Helper.chatLabel() + "You have surrendered the war for " + res.getTownOrNull().getName());
Bukkit.broadcastMessage(Helper.chatLabel() + "The town of " + res.getTownOrNull().getName() + " has surrendered! They were fighting for " + args[2] + ".");
war.save();
return;
} else {
// No perms
p.sendMessage(Helper.chatLabel() + "You cannot surrender war for your town.");
return;
}
}
@@ -296,7 +241,7 @@ public class WarCommands implements CommandExecutor {
private static void warList(Player p, String[] args) {
p.sendMessage(Helper.chatLabel() + "Wars:");
ArrayList<War> wars = WarData.getWars();
if (wars.size() < 1) {
if (wars.isEmpty()) {
p.sendMessage("There are no current wars.");
} else {
for (War war : wars) {
@@ -336,6 +281,7 @@ public class WarCommands implements CommandExecutor {
/**
* Method for console access
*
* @param sender
* @param args
*/
@@ -351,4 +297,30 @@ public class WarCommands implements CommandExecutor {
}
}
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
CommandHelper.logCommand(sender, label, args);
if (!(sender instanceof Player p)) {
consoleCommand(sender, args);
return true;
}
if (args.length == 0) {
p.sendMessage(Helper.chatLabel() + "Invalid Arguments. /war help");
} else {
switch (args[0].toLowerCase()) {
case "create" -> warCreate(p, args);
case "delete" -> warDelete(p, args);
case "join" -> warJoin(p, args, false);
case "surrender" -> warSurrender(p, args, false);
case "list" -> warList(p, args);
case "info" -> warInfo(p, args);
case "help" -> warHelp(p, args);
default -> p.sendMessage(Helper.chatLabel() + "Invalid Arguments. /war help");
}
}
return true;
}
}
@@ -1,35 +1,29 @@
package me.ShermansWorld.AlathraWar.data;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.logging.Level;
import me.ShermansWorld.AlathraWar.Main;
import org.bukkit.Bukkit;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import me.ShermansWorld.AlathraWar.Main;
import java.io.*;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.logging.Level;
/**
* Manages file IO & Deletion for other data classes.
*/
public class DataManager {
private static DumperOptions options;
private static final String dataFolder = "plugins" + File.separator + "AlathraWar" + File.separator + "data";
public DataManager() {
}
private static String dataFolder = "plugins" + File.separator + "AlathraWar" + File.separator + "data";
/**
* Saves data into a .yml format
*
* @param filePath - File's path after <PLUGIN>/Data/
* @param map - Map to be saved
*/
@@ -45,7 +39,7 @@ public class DataManager {
Bukkit.getLogger().log(Level.WARNING, "Error Print canRead: " + (file == null ? "" : file.canRead()));
Bukkit.getLogger().log(Level.WARNING, "Error Print isHidden: " + (file == null ? "" : file.isHidden()));
Bukkit.getLogger().log(Level.WARNING, "Error Print path: " + (file == null ? "" : file.getPath()));
PrintWriter writer = null;
PrintWriter writer;
try {
file.setWritable(true);
writer = new PrintWriter(file);
@@ -74,6 +68,7 @@ public class DataManager {
/**
* Gets the data back as a HashMap
*
* @param filePath - FilePath of data
* @return HashMap of data or null
*/
@@ -84,6 +79,7 @@ public class DataManager {
/**
* Gets the data back as a HashMap
*
* @param file - Data file
* @return HashMap of data or null
*/
@@ -93,7 +89,7 @@ public class DataManager {
return null;
}
InputStream inputStream = null;
InputStream inputStream;
try {
inputStream = new FileInputStream(file);
} catch (FileNotFoundException e) {
@@ -113,6 +109,7 @@ public class DataManager {
/**
* Deletes the specified file
*
* @param filePath - FilePath of deletion
* @return Boolean of success
*/
@@ -135,6 +132,7 @@ public class DataManager {
/**
* Converts filePath into File
*
* @param path - File's path within data folder
* @return File or null
*/
@@ -11,21 +11,25 @@ import me.ShermansWorld.AlathraWar.Raid;
import me.ShermansWorld.AlathraWar.War;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import java.util.*;
public class RaidData {
// Static Raid list for all active raids
private static ArrayList<Raid> raids = new ArrayList<Raid>();
private static final ArrayList<Raid> raids = new ArrayList<>();
public static ArrayList<Raid> getRaids() {
return raids;
}
public static void setRaids(ArrayList<Raid> raids) {
for (Raid raid : raids) {
addRaid(raid);
}
}
/**
* Gets a raid with a specific name
@@ -40,12 +44,6 @@ public class RaidData {
return null;
}
public static void setRaids(ArrayList<Raid> raids) {
for (Raid raid : raids) {
addRaid(raid);
}
}
public static void addRaid(Raid raid) {
if (raid == null) {
Main.warLogger.log("Attempted to add NULL to raid list.");
@@ -119,7 +117,7 @@ public class RaidData {
}
public static ArrayList<Raid> createRaids(War war, Collection<HashMap<String, Object>> raidMaps) {
ArrayList<Raid> returnList = new ArrayList<Raid>();
ArrayList<Raid> returnList = new ArrayList<>();
for (HashMap<String, Object> map : raidMaps) {
Town town = TownyAPI.getInstance().getTown((String) map.get("raidedTown"));
if (town == null) continue;
@@ -143,9 +141,9 @@ public class RaidData {
war.save();
}
/**
* deletes raid, unused
*/
// /**
// * deletes raid, unused
// */
// private static void deleteRaid(War war) {
// File[] files = new File(dataFolderPath + File.separator + "wars").listFiles(ymlFilter);
//
@@ -163,7 +161,7 @@ public class RaidData {
* @return Map
*/
public static HashMap<String, Object> raidToMap(Raid raid) {
HashMap<String, Object> returnMap = new HashMap<String, Object>();
HashMap<String, Object> returnMap = new HashMap<>();
// Shoves everything into a map.
returnMap.put("name", raid.getName());
returnMap.put("raidedTown", raid.getRaidedTown().getName());
@@ -178,11 +176,20 @@ public class RaidData {
returnMap.put("owner", raid.getOwner().getUniqueId().toString());
//create a list from the looted chunks
List<Object> chunkList = new ArrayList<Object>();
final List<Object> chunkList = getChunkList(raid);
returnMap.put("lootedChunks", chunkList);
return returnMap;
}
@NotNull
private static List<Object> getChunkList(Raid raid) {
List<Object> chunkList = new ArrayList<>();
for (Raid.LootBlock b : raid.getLootedChunks().values()) {
HashMap<String, Object> blockMap = new HashMap<String, Object>();
HashMap<String, Object> blockMap = new HashMap<>();
//worldcoord
HashMap<String, Object> wcMap = new HashMap<String, Object>();
HashMap<String, Object> wcMap = new HashMap<>();
wcMap.put("world", b.worldCoord.getWorldName());
wcMap.put("x", b.worldCoord.getCoord().getX());
wcMap.put("z", b.worldCoord.getCoord().getZ());
@@ -193,10 +200,7 @@ public class RaidData {
blockMap.put("finished", b.finished);
chunkList.add(blockMap);
}
returnMap.put("lootedChunks", chunkList);
return returnMap;
return chunkList;
}
/**
@@ -206,7 +210,7 @@ public class RaidData {
* @return Map of Maps
*/
public static HashMap<String, Object> getRaidMap(War war) {
HashMap<String, Object> returnMap = new HashMap<String, Object>();
HashMap<String, Object> returnMap = new HashMap<>();
for (Raid raid : war.getRaids()) {
returnMap.put(raid.getRaidedTown().getName(), raidToMap(raid));
}
@@ -16,13 +16,14 @@ public enum RaidPhase {
public final int id;
public final int startTick;
private RaidPhase(int id, int startTick) {
RaidPhase(int id, int startTick) {
this.id = id;
this.startTick = startTick;
}
/**
* Grabs the phase by name, ignores case
*
* @param name
* @return
*/
@@ -35,6 +36,7 @@ public enum RaidPhase {
/**
* Grabs phase by id number for easy storage reading
*
* @param id
* @return
*/
@@ -47,19 +49,19 @@ public enum RaidPhase {
public static RaidPhase getNext(RaidPhase phase) {
switch (phase) {
case START: {
case START -> {
return GATHER;
}
case GATHER: {
case GATHER -> {
return TRAVEL;
}
case TRAVEL: {
case TRAVEL -> {
return COMBAT;
}
case COMBAT: {
case COMBAT -> {
return END;
}
default: {
default -> {
return null;
}
}
@@ -1,31 +1,33 @@
package me.ShermansWorld.AlathraWar.data;
import java.util.*;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.Town;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.War;
import me.ShermansWorld.AlathraWar.Siege;
import me.ShermansWorld.AlathraWar.War;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
public class SiegeData
{
import java.util.*;
public class SiegeData {
// Static Siege list for all active sieges
private static HashSet<Siege> sieges = new HashSet<Siege>();
private static final HashSet<Siege> sieges = new HashSet<>();
public static HashSet<Siege> getSieges() {
return sieges;
}
public static void setSieges(ArrayList<Siege> sieges) {
for (Siege siege : sieges) {
addSiege(siege);
}
}
/**
* Gets a siege with a specific name
*
* @param name - Name to check
* @return Siege or Null
*/
@@ -36,12 +38,6 @@ public class SiegeData
return null;
}
public static void setSieges(ArrayList<Siege> sieges) {
for (Siege siege : sieges) {
addSiege(siege);
}
}
public static void addSiege(Siege siege) {
if (siege == null) {
Main.warLogger.log("Attempted to add NULL to siege list.");
@@ -57,6 +53,7 @@ public class SiegeData
/**
* Creates a siege object from a provided HashMap
*
* @param fileData data
* @return Siege object
*/
@@ -69,14 +66,12 @@ public class SiegeData
Town town = TownyAPI.getInstance().getTown((String) fileData.get("town"));
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString((String) fileData.get("siegeLeader")));
Siege siege = new Siege(war, town, offlinePlayer);
return siege;
return new Siege(war, town, offlinePlayer);
}
/**
* Saves the war into files.
*
* @param siege - Siege to be saved.
*/
public static void saveSiege(Siege siege) {
@@ -86,11 +81,12 @@ public class SiegeData
/**
* Turns a siege into a map
*
* @param siege - Siege
* @return Map
*/
public static HashMap<String, Object> siegeToMap(Siege siege) {
HashMap<String, Object> returnMap = new HashMap<String, Object>();
HashMap<String, Object> returnMap = new HashMap<>();
// Shoves everything into a map.
returnMap.put("town", siege.getTown().getName());
returnMap.put("siegeTicks", siege.getSiegeTicks());
@@ -104,11 +100,12 @@ public class SiegeData
/**
* Creates a map of siege maps
*
* @param war - War to map
* @return Map of Maps
*/
public static HashMap<String, Object> getSiegeMap(War war) {
HashMap<String, Object> returnMap = new HashMap<String, Object>();
HashMap<String, Object> returnMap = new HashMap<>();
for (Siege siege : war.getSieges()) {
returnMap.put(siege.getTown().getName(), siegeToMap(siege));
}
@@ -116,7 +113,7 @@ public class SiegeData
}
public static ArrayList<Siege> createSieges(War war, Collection<HashMap<String, Object>> siegeMaps) {
ArrayList<Siege> returnList = new ArrayList<Siege>();
ArrayList<Siege> returnList = new ArrayList<>();
for (HashMap<String, Object> map : siegeMaps) {
Town town = TownyAPI.getInstance().getTown((String) map.get("town"));
if (town == null) continue;
@@ -1,9 +1,5 @@
package me.ShermansWorld.AlathraWar.data;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.Raid;
import me.ShermansWorld.AlathraWar.Siege;
@@ -11,21 +7,17 @@ import me.ShermansWorld.AlathraWar.War;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
public class WarData
{
public class WarData {
// Static War list for all active wars
private static ArrayList<War> wars = new ArrayList<War>();
private final static String dataFolderPath = "plugins" + File.separator + "AlathraWar" + File.separator + "data";
// Static War list for all active wars
private static ArrayList<War> wars = new ArrayList<>();
// Filter for only accessing yml files
private static FilenameFilter ymlFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".yml");
}
};
private static final FilenameFilter ymlFilter = (dir, name) -> name.endsWith(".yml");
// Constructor used to initialise folder.
public WarData(final Main plugin) {
@@ -39,8 +31,13 @@ public class WarData
return wars;
}
public static void setWars(ArrayList<War> wars) {
WarData.wars = wars;
}
/**
* Gets a war with a specific name
*
* @param name - Name to check
* @return War or Null
*/
@@ -51,10 +48,6 @@ public class WarData
return null;
}
public static void setWars(ArrayList<War> wars) {
WarData.wars = wars;
}
public static void addWar(War war) {
if (war == null) {
Main.warLogger.log("Attempted to add NULL to war list.");
@@ -70,12 +63,13 @@ public class WarData
/**
* Gets the wars currently saved in files as an ArrayList of War Objects
*
* @return War Object ArrayList
*/
public static ArrayList<War> createWars() {
File[] files = new File(dataFolderPath + File.separator + "wars").listFiles(ymlFilter);
ArrayList<War> returnList = new ArrayList<War>();
ArrayList<War> returnList = new ArrayList<>();
for (File file : files) {
try {
HashMap<String, Object> fileData = DataManager.getData(file);
@@ -92,6 +86,7 @@ public class WarData
/**
* Creates a war object from a provided HashMap
*
* @param fileData
* @return War object
*/
@@ -136,18 +131,19 @@ public class WarData
/**
* Saves the war into files.
*
* @param war - War to be saved.
*/
public static void saveWar(War war) {
HashMap<String, Object> sHashMap = new HashMap<String,Object>();
HashMap<String, Object> sHashMap = new HashMap<>();
// Shoves everything into a map.
sHashMap.put("name", war.getName());
sHashMap.put("side1", war.getSide1());
sHashMap.put("side2", war.getSide2());
sHashMap.put("side1Towns", (List<String>) war.getSide1Towns());
sHashMap.put("side2Towns", (List<String>) war.getSide2Towns());
sHashMap.put("surrenderedTowns", (List<String>) war.getSurrenderedTowns());
sHashMap.put("side1Towns", war.getSide1Towns());
sHashMap.put("side2Towns", war.getSide2Towns());
sHashMap.put("surrenderedTowns", war.getSurrenderedTowns());
sHashMap.put("side1Points", war.getSide1Points());
sHashMap.put("side2Points", war.getSide2Points());
@@ -1,13 +1,12 @@
package me.ShermansWorld.AlathraWar.hooks;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import me.ShermansWorld.AlathraWar.Helper;
import me.ShermansWorld.AlathraWar.War;
import me.neznamy.tab.api.TabAPI;
import me.neznamy.tab.api.TabPlayer;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
public class TABHook {
@@ -57,7 +56,6 @@ public class TABHook {
tabAPI.getTablistFormatManager().resetSuffix(tabPlayer);
}
} catch (NullPointerException e) {
return;
}
}
@@ -75,7 +73,6 @@ public class TABHook {
tabAPI.getTablistFormatManager().resetPrefix(tabPlayer);
}
} catch (NullPointerException e) {
return;
}
}
@@ -83,8 +80,7 @@ public class TABHook {
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
if (prefix.length() > 2) {
prefix = prefix.substring(0, prefix.length() - 2);
}
else{
} else {
Bukkit.getLogger().info("There is an error when removing a color prefix, prefix not long enough:");
Bukkit.getLogger().info("Player: " + p.getDisplayName());
Bukkit.getLogger().info("Prefix: " + prefix);
@@ -5,8 +5,8 @@ import org.bukkit.inventory.Recipe;
public interface IWarItem {
public ItemStack getItemStack();
ItemStack getItemStack();
public Recipe getRecipe();
Recipe getRecipe();
}
@@ -4,17 +4,16 @@ import me.ShermansWorld.AlathraWar.Helper;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.items.item.RamItem;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class WarItemRegistry {
private static WarItemRegistry instance;
private static final HashMap<String, IWarItem> itemRegistry = new HashMap<>();
public static final String namespace = Main.getInstance().getName().toLowerCase();
private static final HashMap<String, IWarItem> itemRegistry = new HashMap<>();
private static WarItemRegistry instance;
/**
* loads all items into the plugin registry list
@@ -37,6 +36,7 @@ public class WarItemRegistry {
/**
* generate a registry name
*
* @param item
* @return
*/
@@ -55,6 +55,7 @@ public class WarItemRegistry {
/**
* returns the associated itemstack with the item key, use for finding without namespace
*
* @param registryName
* @return
*/
@@ -65,6 +66,7 @@ public class WarItemRegistry {
/**
* returns the associated itemstack with the item key, use for finding with namespace
*
* @param registryName
* @return
*/
@@ -74,6 +76,7 @@ public class WarItemRegistry {
/**
* returns the associated IWarItem with the item key, use for finding with namespace
*
* @param registryName
* @return
*/
@@ -9,9 +9,8 @@ import java.util.Set;
public class WarRecipeRegistry {
private static WarRecipeRegistry instance;
private static final HashMap<String, Recipe> recipeRegistry = new HashMap<>();
private static WarRecipeRegistry instance;
public WarRecipeRegistry() {
instance = this;
@@ -23,6 +22,10 @@ public class WarRecipeRegistry {
Main.warLogger.log(Helper.chatLabel() + "Registered AlathraWar recipes.");
}
public static WarRecipeRegistry getInstance() {
return instance;
}
public void register(String name, Set<Recipe> recipes) {
for (Recipe recipe : recipes) {
// Bukkit.getServer().addRecipe(recipe);
@@ -30,16 +33,13 @@ public class WarRecipeRegistry {
}
}
public static WarRecipeRegistry getInstance() {
return instance;
}
public HashMap<String, Recipe> getRecipeRegistry() {
return recipeRegistry;
}
/**
* returns the associated itemstack with the item key, use for finding without namespace
*
* @param registryName recipe name without namespace
* @return recipe
*/
@@ -50,6 +50,7 @@ public class WarRecipeRegistry {
/**
* returns the associated itemstack with the item key, use for finding with namespace
*
* @param registryName registry name including namespace
* @return recipe
*/
@@ -22,7 +22,7 @@ public class RamItem implements IWarItem {
ItemMeta meta = ram.getItemMeta();
meta.setDisplayName("Door Ram");
ArrayList<String> lore = new ArrayList<String>();
ArrayList<String> lore = new ArrayList<>();
meta.setLore(lore);
meta.setCustomModelData(14700);
@@ -1,25 +1,21 @@
package me.ShermansWorld.AlathraWar.listeners;
import com.palmergames.bukkit.towny.object.WorldCoord;
import me.ShermansWorld.AlathraWar.Helper;
import me.ShermansWorld.AlathraWar.Raid;
import me.ShermansWorld.AlathraWar.Siege;
import me.ShermansWorld.AlathraWar.data.RaidData;
import org.bukkit.event.EventHandler;
import java.util.HashSet;
import java.util.Set;
import me.ShermansWorld.AlathraWar.data.SiegeData;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import com.palmergames.bukkit.towny.object.WorldCoord;
import me.ShermansWorld.AlathraWar.Helper;
import me.ShermansWorld.AlathraWar.Siege;
import me.ShermansWorld.AlathraWar.data.SiegeData;
import org.bukkit.event.Listener;
import java.util.HashSet;
import java.util.Set;
public class BlockBreakListener implements Listener {
@@ -73,7 +73,7 @@ public class CommandsListener implements Listener {
//payment check
for (String cmd : blacklistedXLong) {
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot modify this property during a raid!"));
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou cannot modify this property during a raid!"));
event.setCancelled(true);
return;
}
@@ -89,7 +89,7 @@ public class CommandsListener implements Listener {
for (String cmd : payment) {
//check for each prefix
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot withdraw money whilst in a raid!"));
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou cannot withdraw money whilst in a raid!"));
event.setCancelled(true);
return;
}
@@ -104,17 +104,17 @@ public class CommandsListener implements Listener {
|| parse.equalsIgnoreCase("t spawn") || parse.equalsIgnoreCase("town spawn")
|| parse.equalsIgnoreCase("towny:n spawn") || parse.equalsIgnoreCase("towny:nat spawn") || parse.equalsIgnoreCase("towny:nation spawn")
|| parse.equalsIgnoreCase("towny:t spawn") || parse.equalsIgnoreCase("towny:town spawn")) {
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(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"));
p.sendMessage(Helper.chatLabel() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
p.sendMessage(Helper.chatLabel() + Helper.color("&eUse /t spawn, or /n spawn"));
event.setCancelled(true);
return;
}
//else
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot teleport whilst in a raid!"));
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou cannot teleport whilst in a raid!"));
event.setCancelled(true);
return;
}
@@ -131,13 +131,13 @@ public class CommandsListener implements Listener {
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
//spawn world check
if (p.getWorld().getName().equalsIgnoreCase("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"));
p.sendMessage(Helper.chatLabel() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
p.sendMessage(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!"));
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou cannot teleport whilst in a raid!"));
event.setCancelled(true);
return;
}
@@ -163,7 +163,7 @@ public class CommandsListener implements Listener {
//payment check
for (String cmd : blacklistedXLong) {
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot modify this property during a siege!"));
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou cannot modify this property during a siege!"));
event.setCancelled(true);
return;
}
@@ -221,13 +221,13 @@ public class CommandsListener implements Listener {
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
//spawn world check
if (p.getWorld().getName().equalsIgnoreCase("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"));
p.sendMessage(Helper.chatLabel() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
p.sendMessage(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!"));
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou cannot teleport whilst in a siege!"));
event.setCancelled(true);
return;
}
@@ -1,27 +1,18 @@
package me.ShermansWorld.AlathraWar.listeners;
import org.bukkit.event.EventHandler;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.Town;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.War;
import me.ShermansWorld.AlathraWar.data.WarData;
import me.ShermansWorld.AlathraWar.hooks.TABHook;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class JoinListener implements Listener {
@EventHandler
public void onPlayerJoin(final PlayerJoinEvent event) {
final Player p = event.getPlayer();
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> checkPlayer(p), 60L); // 20 Tick (1 Second) delay before run() is called
}
public static void checkPlayer(Player p) {
Town town = TownyAPI.getInstance().getResident(p).getTownOrNull();
if (town == null) return;
@@ -40,4 +31,10 @@ public class JoinListener implements Listener {
TABHook.resetPrefix(p);
}
}
@EventHandler
public void onPlayerJoin(final PlayerJoinEvent event) {
final Player p = event.getPlayer();
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> checkPlayer(p), 60L); // 20 Tick (1 Second) delay before run() is called
}
}
@@ -21,8 +21,7 @@ import org.bukkit.event.player.PlayerRespawnEvent;
import java.util.HashMap;
import java.util.UUID;
public final class KillsListener implements Listener
{
public final class KillsListener implements Listener {
public static final HashMap<UUID, Raid> respawnqueue = new HashMap<>();
@@ -34,8 +33,7 @@ public final class KillsListener implements Listener
Town town = null;
try {
town = WorldCoord.parseWorldCoord(killed).getTownBlock().getTown();
}
catch (NotRegisteredException ex2) {
} catch (NotRegisteredException ex2) {
ex2.printStackTrace();
}
boolean playerCloseToHomeBlockSiege = false;
@@ -110,18 +108,18 @@ public final class KillsListener implements Listener
for (final String playerName : siege.getAttackerPlayers()) {
try {
Player p = Bukkit.getPlayer(playerName);
if (p != null) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Defender killed! + 20 Attacker Points");
}
catch (NullPointerException ignored) {
if (p != null)
p.sendMessage(Helper.chatLabel() + "Defender killed! + 20 Attacker Points");
} catch (NullPointerException ignored) {
ignored.printStackTrace();
}
}
for (final String playerName : siege.getDefenderPlayers()) {
try {
Player p = Bukkit.getPlayer(playerName);
if (p != null) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Defender killed! + 20 Attacker Points");
}
catch (NullPointerException ignored) {
if (p != null)
p.sendMessage(Helper.chatLabel() + "Defender killed! + 20 Attacker Points");
} catch (NullPointerException ignored) {
ignored.printStackTrace();
}
}
@@ -135,18 +133,18 @@ public final class KillsListener implements Listener
for (final String playerName : siege.getAttackerPlayers()) {
try {
Player p = Bukkit.getPlayer(playerName);
if (p != null) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Attacker killed! + 20 Defender Points");
}
catch (NullPointerException ex3) {
if (p != null)
p.sendMessage(Helper.chatLabel() + "Attacker killed! + 20 Defender Points");
} catch (NullPointerException ex3) {
ex3.printStackTrace();
}
}
for (final String playerName : siege.getDefenderPlayers()) {
try {
Player p = Bukkit.getPlayer(playerName);
if (p != null) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Attacker killed! + 20 Defender Points");
}
catch (NullPointerException ex4) {
if (p != null)
p.sendMessage(Helper.chatLabel() + "Attacker killed! + 20 Defender Points");
} catch (NullPointerException ex4) {
ex4.printStackTrace();
}
}
@@ -159,8 +157,7 @@ public final class KillsListener implements Listener
}
}
}
catch (NullPointerException | TownyException ignored) {
} catch (NullPointerException | TownyException ignored) {
ignored.printStackTrace();
}
}
@@ -179,7 +176,7 @@ public final class KillsListener implements Listener
//do raider respawn
try {
event.setRespawnLocation(raid.getGatherTown().getSpawn());
event.getPlayer().sendMessage(String.valueOf(Helper.chatLabel()) + "You died " + (raid.getPhase().equals(RaidPhase.COMBAT) ? "raiding" : "before combat") + " and have been teleported back to the gather point.");
event.getPlayer().sendMessage(Helper.chatLabel() + "You died " + (raid.getPhase().equals(RaidPhase.COMBAT) ? "raiding" : "before combat") + " and have been teleported back to the gather point.");
} catch (TownyException e) {
throw new RuntimeException(e);
}
@@ -196,6 +193,7 @@ public final class KillsListener implements Listener
/**
* Damage all gear held by the player (and then send them to spawn?)
* They don't lose items from death.
*
* @param killed killed player
* @param event event
*/
@@ -32,7 +32,7 @@ import java.util.Set;
public class PlayerInteractListener implements Listener {
//predefined foor materials
private static Set<Material> doors = new HashSet<Material>();
private static final Set<Material> doors = new HashSet<>();
static {
doors.add(Material.ACACIA_DOOR);
@@ -48,7 +48,7 @@ public class PlayerInteractListener implements Listener {
}
//map of broken doors
public Map<Location, Long> brokenDoors = new HashMap<Location, Long>();
public Map<Location, Long> brokenDoors = new HashMap<>();
/**
* @param event event
@@ -106,17 +106,17 @@ public class PlayerInteractListener implements Listener {
door.setOpen(!door.isOpen());
clicked.setBlockData(door);
player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1);
Main.warLogger.log("User " + player.getName() + " has broken down door" + clicked.getLocation().toString());
Main.warLogger.log("User " + player.getName() + " has broken down door" + clicked.getLocation());
} else {
player.sendMessage(Helper.chatLabel() + Helper.color("&cThis item can only be used in a siege or raid!"));
}
event.setCancelled(true);
return;
}
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRClick(final PlayerItemDamageEvent event) {
ItemStack item = event.getItem();
@@ -158,7 +158,6 @@ public class PlayerInteractListener implements Listener {
|| clicked.getType().name().equals("ROOTED_DIRT")
|| clicked.getType().name().equals("DIRT_PATH")) {
event.setCancelled(true);
return;
}
}
}