Add files via upload

This commit is contained in:
ShermansWorld authored and GitHub committed 2022-07-19 17:58:41 -04:00
1 parent 7531109868
commit a7df676b77
9 files changed
+630 -461

No files matched your search

@@ -0,0 +1,66 @@
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;
public class AlathraWarLogger {
File logsFolder;
File log;
PrintWriter output = null;
public AlathraWarLogger() {
logsFolder = new File("plugins" + File.separator + "AlathraWar" + File.separator + "logs");
log = new File(
"plugins" + File.separator + "AlathraWar" + File.separator + "logs" + File.separator + "log.txt");
}
public boolean checkFiles() {
if (!logsFolder.exists()) {
Bukkit.getLogger().warning("[AlathraWar] Error in AlathraWarLogger - could not find logs directory");
return false;
}
if (!log.exists()) {
Bukkit.getLogger().warning("[AlathraWar] Error in AlathraWarLogger - could not find log.txt");
return false;
}
return true;
}
private void initFileWriter() {
// init file writer
try {
FileWriter fw = new FileWriter(
"plugins" + File.separator + "AlathraWar" + File.separator + "logs" + File.separator + "log.txt",
true);
BufferedWriter bw = new BufferedWriter(fw);
output = new PrintWriter(bw);
} catch (IOException e1) {
Bukkit.getLogger().warning("[AlathraWar] Error in AlathraWarLogger - could not initialize file writer");
return;
}
}
public void log(String msg) {
// check for null files
if (!checkFiles()) {
return;
}
initFileWriter();
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
String logMsg = "[" + format.format(date) + "] " + msg;
output.println(logMsg);
output.close();
}
}
@@ -18,7 +18,7 @@ public class BlockBreakListener implements Listener
return;
}
for (final Siege siege : SiegeCommands.sieges) {
if (siege.beaconLocs.contains(event.getBlock().getLocation())) {
if (siege.beaconLocs.contains(block.getLocation())) {
event.setCancelled(true);
return;
}
@@ -5,26 +5,33 @@
package me.ShermansWorld.AlathraWar;
import org.bukkit.event.EventHandler;
import java.util.Iterator;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent;
import me.neznamy.tab.api.TabAPI;
import me.neznamy.tab.api.TabPlayer;
import org.bukkit.event.Listener;
public class JoinListener implements Listener
{
public class JoinListener implements Listener {
@EventHandler
public void onPlayerJoin(final PlayerJoinEvent event) {
final Player p = event.getPlayer();
for (final War war : WarCommands.wars) {
if (war.getSide1Players().contains(p.getName())) {
p.setPlayerListName(String.valueOf(Helper.color(new StringBuilder("&c[").append(war.getSide1()).append("]&r").toString())) + p.getName());
}
else {
if (!war.getSide2Players().contains(p.getName())) {
continue;
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
@Override
public void run() {
for (final War war : WarCommands.wars) {
if (war.getSide1Players().contains(p.getName())) {
TabPlayer tabPlayer = TabAPI.getInstance().getPlayer(p.getUniqueId());
TabAPI.getInstance().getTablistFormatManager().setSuffix(tabPlayer, Helper.color(new StringBuilder("&c[").append(war.getSide1()).append("]&r").toString()));
//p.setPlayerListName(String.valueOf(Helper.color(new StringBuilder("&c[").append(war.getSide1()).append("]&r").toString())) + p.getName());
} else if (war.getSide2Players().contains(p.getName())) {
TabPlayer tabPlayer = TabAPI.getInstance().getPlayer(p.getUniqueId());
TabAPI.getInstance().getTablistFormatManager().setSuffix(tabPlayer, Helper.color(new StringBuilder("&9[").append(war.getSide2()).append("]&r").toString()));
}
}
p.setPlayerListName(String.valueOf(Helper.color(new StringBuilder("&9[").append(war.getSide2()).append("]&r").toString())) + p.getName());
}
}
}, 60L); //20 Tick (1 Second) delay before run() is called
}
}
@@ -11,7 +11,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import java.util.Iterator;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.exceptions.TownyException;
import org.bukkit.Bukkit;
@@ -88,7 +87,6 @@ public final class KillsListener implements Listener
}
}
catch (NullPointerException | TownyException ex7) {
final Exception ex;
}
}
@@ -13,6 +13,9 @@ import java.util.Set;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.TownyUniverse;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.bukkit.Bukkit;
import net.milkbowl.vault.economy.Economy;
@@ -24,6 +27,7 @@ public class Main extends JavaPlugin
public static SiegeData data2;
public static Main instance;
public static Economy econ;
public static AlathraWarLogger warLogger;
static {
Main.instance = null;
@@ -32,7 +36,8 @@ public class Main extends JavaPlugin
private static void initData() {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask((Plugin)getInstance(), (Runnable)new Runnable() {
@Override
@SuppressWarnings("unchecked")
@Override
public void run() {
try {
final Set<String> warsSet = (Set<String>)Main.data.getConfig().getConfigurationSection("Wars").getKeys(false);
@@ -101,11 +106,13 @@ public class Main extends JavaPlugin
}, 0L);
}
@SuppressWarnings("rawtypes")
private boolean setupEconomy() {
if (this.getServer().getPluginManager().getPlugin("Vault") == null) {
return false;
}
final RegisteredServiceProvider<Economy> rsp = (RegisteredServiceProvider<Economy>)this.getServer().getServicesManager().getRegistration((Class)Economy.class);
@SuppressWarnings("unchecked")
final RegisteredServiceProvider<Economy> rsp = (RegisteredServiceProvider<Economy>)this.getServer().getServicesManager().getRegistration((Class)Economy.class);
if (rsp == null) {
return false;
}
@@ -117,19 +124,36 @@ public class Main extends JavaPlugin
return Main.instance;
}
public static void initLogs() {
File logsFolder = new File("plugins" + File.separator + "AlathraWar" + File.separator + "logs");
if (!logsFolder.exists()) {
logsFolder.mkdirs();
}
File log = new File("plugins" + File.separator + "AlathraWar" + File.separator + "logs" + File.separator + "log.txt");
if (!log.exists()) {
try {
log.createNewFile();
} catch (IOException e) {
Bukkit.getLogger().warning("[AlathraWar] Encountered error when creating log file!");
}
}
warLogger = new AlathraWarLogger();
}
public void onEnable() {
Main.instance = this;
Main.data = new WarData(this);
Main.data2 = new SiegeData(this);
new WarCommands(this);
new SiegeCommands(this);
this.getCommand("war").setTabCompleter(new WarTabCompletion());
this.getCommand("siege").setTabCompleter(new SiegeTabCompletion());
this.getServer().getPluginManager().registerEvents((Listener)new KillsListener(), (Plugin)this);
this.getServer().getPluginManager().registerEvents((Listener)new JoinListener(), (Plugin)this);
this.getServer().getPluginManager().registerEvents((Listener)new BlockBreakListener(), (Plugin)this);
getCommand("war").setTabCompleter(new WarTabCompletion());
getCommand("siege").setTabCompleter(new SiegeTabCompletion());
getServer().getPluginManager().registerEvents((Listener)new KillsListener(), (Plugin)this);
getServer().getPluginManager().registerEvents((Listener)new JoinListener(), (Plugin)this);
getServer().getPluginManager().registerEvents((Listener)new BlockBreakListener(), (Plugin)this);
initData();
this.setupEconomy();
setupEconomy();
initLogs();
}
public void onDisable() {
@@ -15,9 +15,7 @@ import com.palmergames.bukkit.towny.TownyUniverse;
import com.gmail.goosius.siegewar.TownOccupationController;
import com.palmergames.bukkit.towny.TownyAPI;
import org.bukkit.plugin.Plugin;
import java.util.Iterator;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import org.bukkit.entity.Entity;
import com.palmergames.bukkit.towny.object.WorldCoord;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -26,423 +24,486 @@ import org.bukkit.entity.Player;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock;
public class Siege
{
private War war;
private Town town;
private String attackers;
private String defenders;
private boolean side1AreAttackers;
private boolean side2AreAttackers;
private int id;
private int attackerPoints;
private int defenderPoints;
private int MAXSIEGETICKS;
private Player owner;
private int siegeTicks;
private TownBlock homeBlock;
private Location townSpawn;
int[] bukkitId;
public ArrayList<String> attackerPlayers;
public ArrayList<String> defenderPlayers;
public ArrayList<Location> beaconLocs;
public Siege(final int id, final War war, final Town town, final String attackers, final String defenders, final boolean side1AreAttackers, final boolean side2AreAttackers) {
this.siegeTicks = 0;
this.bukkitId = new int[1];
this.attackerPlayers = new ArrayList<String>();
this.defenderPlayers = new ArrayList<String>();
this.beaconLocs = new ArrayList<Location>();
this.war = war;
this.town = town;
this.attackers = attackers;
this.defenders = defenders;
this.side1AreAttackers = side1AreAttackers;
this.side2AreAttackers = side2AreAttackers;
this.id = id;
}
public void start() {
this.attackerPoints = Main.data2.getConfig().getInt("Sieges." + String.valueOf(this.id) + ".attackerpoints");
this.defenderPoints = Main.data2.getConfig().getInt("Sieges." + String.valueOf(this.id) + ".defenderpoints");
this.side1AreAttackers = Main.data2.getConfig().getBoolean("Sieges." + String.valueOf(this.id) + ".side1areattackers");
this.side2AreAttackers = Main.data2.getConfig().getBoolean("Sieges." + String.valueOf(this.id) + ".side2areattackers");
this.MAXSIEGETICKS = 108000;
this.siegeTicks = Main.data2.getConfig().getInt("Sieges." + String.valueOf(this.id) + ".siegeticks");
this.owner = Bukkit.getPlayer(Main.data2.getConfig().getString("Sieges." + String.valueOf(this.id) + ".owner"));
if (this.side1AreAttackers) {
this.attackerPlayers = this.war.getSide1Players();
this.defenderPlayers = this.war.getSide2Players();
}
else {
this.attackerPlayers = this.war.getSide2Players();
this.defenderPlayers = this.war.getSide1Players();
}
try {
public class Siege {
private War war;
private Town town;
private String attackers;
private String defenders;
private boolean side1AreAttackers;
private boolean side2AreAttackers;
private int id;
private int attackerPoints;
private int defenderPoints;
private int MAXSIEGETICKS;
private Player owner;
private int siegeTicks;
private TownBlock homeBlock;
private Location townSpawn;
int[] bukkitId;
public ArrayList<String> attackerPlayers;
public ArrayList<String> defenderPlayers;
public ArrayList<Location> beaconLocs;
public Siege(final int id, final War war, final Town town, final String attackers, final String defenders,
final boolean side1AreAttackers, final boolean side2AreAttackers) {
this.siegeTicks = 0;
this.bukkitId = new int[1];
this.attackerPlayers = new ArrayList<String>();
this.defenderPlayers = new ArrayList<String>();
this.beaconLocs = new ArrayList<Location>();
this.war = war;
this.town = town;
this.attackers = attackers;
this.defenders = defenders;
this.side1AreAttackers = side1AreAttackers;
this.side2AreAttackers = side2AreAttackers;
this.id = id;
}
public void start() {
this.attackerPoints = Main.data2.getConfig().getInt("Sieges." + String.valueOf(this.id) + ".attackerpoints");
this.defenderPoints = Main.data2.getConfig().getInt("Sieges." + String.valueOf(this.id) + ".defenderpoints");
this.side1AreAttackers = Main.data2.getConfig()
.getBoolean("Sieges." + String.valueOf(this.id) + ".side1areattackers");
this.side2AreAttackers = Main.data2.getConfig()
.getBoolean("Sieges." + String.valueOf(this.id) + ".side2areattackers");
this.MAXSIEGETICKS = 108000;
this.siegeTicks = Main.data2.getConfig().getInt("Sieges." + String.valueOf(this.id) + ".siegeticks");
this.owner = Bukkit.getPlayer(Main.data2.getConfig().getString("Sieges." + String.valueOf(this.id) + ".owner"));
if (this.side1AreAttackers) {
this.attackerPlayers = this.war.getSide1Players();
this.defenderPlayers = this.war.getSide2Players();
} else {
this.attackerPlayers = this.war.getSide2Players();
this.defenderPlayers = this.war.getSide1Players();
}
try {
homeBlock = town.getHomeBlock();
townSpawn = town.getSpawn();
} catch (TownyException e) {
}
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin)Main.getInstance(), (Runnable)new Runnable() {
int homeBlockControl = 0;
@Override
public void run() {
if (homeBlock != null) {
town.setHomeBlock(homeBlock);
town.setSpawn(townSpawn);
}
if (Siege.this.side1AreAttackers) {
Siege.this.attackerPlayers = Siege.this.war.getSide1Players();
Siege.this.defenderPlayers = Siege.this.war.getSide2Players();
}
else {
Siege.this.attackerPlayers = Siege.this.war.getSide2Players();
Siege.this.defenderPlayers = Siege.this.war.getSide1Players();
}
if (Siege.this.siegeTicks >= Siege.this.MAXSIEGETICKS) {
Bukkit.getServer().getScheduler().cancelTask(Siege.this.bukkitId[0]);
if (Siege.this.attackerPoints > Siege.this.defenderPoints) {
Siege.this.attackersWin(Siege.this.owner);
}
else {
Siege.this.defendersWin();
}
}
else {
boolean attackersAreOnHomeBlock = false;
boolean defendersAreOnHomeBlock = false;
final Siege this$0 = Siege.this;
Siege.access$7(this$0, this$0.siegeTicks + 200);
Main.data2.getConfig().set("Sieges." + String.valueOf(Siege.this.id) + ".siegeticks", (Object)Siege.this.siegeTicks);
Main.data2.saveConfig();
for (final String playerName : Siege.this.attackerPlayers) {
try {
if (WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName)).getTownBlock().isHomeBlock() && WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName)).getTownBlock().getTown().equals(town) && !Bukkit.getPlayer(playerName).isDead()) {
attackersAreOnHomeBlock = true;
}
}
catch (NotRegisteredException ex) {}
catch (NullPointerException ex2) {}
}
for (final String playerName : Siege.this.defenderPlayers) {
try {
if (WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName)).getTownBlock().isHomeBlock() && WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName)).getTownBlock().getTown().equals(town) && !Bukkit.getPlayer(playerName).isDead()) {
defendersAreOnHomeBlock = true;
}
}
catch (NotRegisteredException ex3) {}
catch (NullPointerException ex4) {}
}
if (attackersAreOnHomeBlock && defendersAreOnHomeBlock) {
if (this.homeBlockControl != 1) {
for (final String playerName : Siege.this.attackerPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(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()) + "HomeBlock at " + Siege.this.town.getName() + " contested!");
}
catch (NullPointerException ex6) {}
}
}
this.homeBlockControl = 1;
}
else if (attackersAreOnHomeBlock && !defendersAreOnHomeBlock) {
if (this.homeBlockControl != 2) {
for (final String playerName : Siege.this.attackerPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Attackers have captured the HomeBlock at " + Siege.this.town.getName() + "! +1 Attacker Points per second");
}
catch (NullPointerException ex7) {}
}
for (final String playerName : Siege.this.defenderPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Attackers have captured the HomeBlock at " + Siege.this.town.getName() + "! +1 Attacker Points per second");
}
catch (NullPointerException ex8) {}
}
}
this.homeBlockControl = 2;
Siege.this.addPointsToAttackers(10);
Main.data2.getConfig().set("Sieges." + String.valueOf(Siege.this.id) + ".attackerpoints", (Object)Siege.this.attackerPoints);
Main.data2.saveConfig();
}
else {
if (this.homeBlockControl != 3) {
for (final String playerName : Siege.this.attackerPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defenders retain control of the HomeBlock at " + Siege.this.town.getName() + "! +1 Defender Points per second");
}
catch (NullPointerException ex9) {}
}
for (final String playerName : Siege.this.defenderPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defenders retain control of the HomeBlock at " + Siege.this.town.getName() + "! +1 Defender Points per second");
}
catch (NullPointerException ex10) {}
}
}
Siege.this.addPointsToDefenders(10);
Main.data2.getConfig().set("Sieges." + String.valueOf(Siege.this.id) + ".defenderpoints", (Object)Siege.this.defenderPoints);
Main.data2.saveConfig();
this.homeBlockControl = 3;
}
if (Siege.this.siegeTicks % 6000 == 0) {
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "Report on the siege of " + Siege.this.town.getName() + ":");
Bukkit.broadcastMessage("Attacker Points - " + String.valueOf(Siege.this.attackerPoints));
Bukkit.broadcastMessage("Defender Points - " + String.valueOf(Siege.this.defenderPoints));
}
}
}
}, 0L, 200L);
}
public void stop() {
Bukkit.getScheduler().cancelTask(this.bukkitId[0]);
SiegeCommands.sieges.remove(this);
Main.data2.getConfig().set("Sieges." + String.valueOf(this.id), (Object)null);
Main.data2.saveConfig();
}
public void attackersWin(final Player owner) {
final Resident resident = TownyAPI.getInstance().getResident(owner);
Nation nation = null;
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The attackers from " + this.attackers + " have won the siege of " + this.town.getName() + "!");
try {
nation = resident.getTown().getNation();
}
catch (NotRegisteredException e) {
for (final String playerName : this.attackerPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName() + " could not be occupied because the player who started the siege is not part of a nation");
}
catch (NullPointerException ex) {}
}
for (final String playerName : this.defenderPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName() + " could not be occupied because the player who started the siege is not part of a nation");
}
catch (NullPointerException ex2) {}
}
}
if (nation != null) {
TownOccupationController.setTownOccupation(this.town, nation);
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName() + " has been placed under occupation by " + nation.getName() + "!");
}
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(owner.getName());
Main.econ.depositPlayer(offlinePlayer, 20000.0);
double amt = 0.0;
if (this.town.getAccount().getHoldingBalance() > 80000.0) {
amt = Math.floor(this.town.getAccount().getHoldingBalance()) / 4.0;
this.town.getAccount().withdraw(amt, "war loot");
}
else {
if (this.town.getAccount().getHoldingBalance() < 20000.0) {
amt = this.town.getAccount().getHoldingBalance();
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName() + " has been destroyed by " + this.getAttackers() + "!");
TownyUniverse.getInstance().getDataSource().deleteTown(this.town);
Main.econ.depositPlayer(offlinePlayer, amt);
return;
}
this.town.getAccount().withdraw(20000.0, "war loot");
amt = 20000.0;
}
Bukkit.broadcastMessage("The town of " + this.town.getName() + " has been sacked by " + this.getAttackers() + ", valuing $" + String.valueOf(amt));
Main.econ.depositPlayer(offlinePlayer, amt);
stop();
clearBeacon();
}
public void defendersWin() {
this.town.getAccount().deposit(20000.0, "War chest");
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The defenders from " + this.defenders + " have won the siege of " + this.town.getName() + "!");
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + this.town.getName() + " has recovered the attackers' war chest, valued at $20,000");
stop();
clearBeacon();
}
public void createBeacon() {
try {
World world = town.getWorld();
int homeBlockX = this.town.getHomeBlock().getX() * 16;
int homeBlockZ = this.town.getHomeBlock().getZ() * 16;
if (homeBlockX > 0) {
homeBlockX -= 8;
}
if (homeBlockZ > 0) {
homeBlockZ -= 8;
}
if (homeBlockX < 0) {
homeBlockX += 8;
}
if (homeBlockZ < 0) {
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)) {
--homeBlockY;
beaconLoc.setY((double)homeBlockY);
}
homeBlockY += 2;
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, (double)(homeBlockX + 1), (double)(homeBlockY - 1), (double)homeBlockZ));
this.beaconLocs.add(new Location(world, (double)(homeBlockX - 1), (double)(homeBlockY - 1), (double)homeBlockZ));
this.beaconLocs.add(new Location(world, (double)homeBlockX, (double)(homeBlockY - 1), (double)(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)));
for (int i = 2; i < this.beaconLocs.size(); ++i) {
if (this.beaconLocs.get(i).getBlock().getType() != Material.AIR) {
i = 1;
homeBlockY++;
for (final Location loc : this.beaconLocs) {
loc.setY(loc.getY() + 1.0);
}
}
}
this.beaconLocs.get(0).getBlock().setType(Material.BEACON);
this.beaconLocs.get(1).getBlock().setType(Material.RED_STAINED_GLASS);
for (int i = 2; i < this.beaconLocs.size(); ++i) {
this.beaconLocs.get(i).getBlock().setType(Material.IRON_BLOCK);
}
Main.data2.getConfig().set("Sieges." + String.valueOf(this.id) + ".world", world.getName());
Main.data2.getConfig().set("Sieges." + String.valueOf(this.id) + ".homeblockx", homeBlockX);
Main.data2.getConfig().set("Sieges." + String.valueOf(this.id) + ".homeblocky", homeBlockY);
Main.data2.getConfig().set("Sieges." + String.valueOf(this.id) + ".homeblockz", homeBlockZ);
Main.data2.saveConfig();
}
catch (TownyException ex) {}
}
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, (double)(homeBlockX + 1), (double)(homeBlockY - 1), (double)homeBlockZ));
this.beaconLocs.add(new Location(world, (double)(homeBlockX - 1), (double)(homeBlockY - 1), (double)homeBlockZ));
this.beaconLocs.add(new Location(world, (double)homeBlockX, (double)(homeBlockY - 1), (double)(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)));
}
public void clearBeacon() {
for (final Location loc : this.beaconLocs) {
loc.getBlock().setType(Material.AIR);
}
}
public void addPointsToAttackers(final int points) {
this.attackerPoints += points;
}
public void addPointsToDefenders(final int points) {
this.defenderPoints += points;
}
public int getID() {
return this.id;
}
public void setID(final int id) {
this.id = id;
}
public War getWar() {
return this.war;
}
public void setWar(final War war) {
this.war = war;
}
public Town getTown() {
return this.town;
}
public void setTown(final Town town) {
this.town = town;
}
public String getAttackers() {
return this.attackers;
}
public void setAttackers(final String attackers) {
this.attackers = attackers;
}
public String getDefenders() {
return this.defenders;
}
public void setDefenders(final String defenders) {
this.attackers = defenders;
}
public int getAttackerPoints() {
return this.attackerPoints;
}
public void attackerPoints(final int attackerPoints) {
this.attackerPoints = attackerPoints;
}
public int getDefenderPoints() {
return this.defenderPoints;
}
public void defenderPoints(final int defenderPoints) {
this.defenderPoints = this.attackerPoints;
}
public boolean getSide1AreAttackers() {
return this.side1AreAttackers;
}
public void setSide1AreAttackers(final boolean side1AreAttackers) {
this.side1AreAttackers = side1AreAttackers;
}
public boolean getSide2AreAttackers() {
return this.side2AreAttackers;
}
public void setSide2AreAttackers(final boolean side2AreAttackers) {
this.side2AreAttackers = side2AreAttackers;
}
public ArrayList<String> getAttackerPlayers() {
return this.attackerPlayers;
}
public void setAttackerPlayer(final ArrayList<String> attackerPlayers) {
this.attackerPlayers = attackerPlayers;
}
public ArrayList<String> getDefenderPlayers() {
return this.defenderPlayers;
}
public void setDefenderPlayer(final ArrayList<String> defenderPlayers) {
this.defenderPlayers = this.attackerPlayers;
}
static /* synthetic */ void access$7(final Siege siege, final int siegeTicks) {
siege.siegeTicks = siegeTicks;
}
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) Main.getInstance(),
(Runnable) new Runnable() {
int homeBlockControl = 0;
@Override
public void run() {
if (homeBlock != null) {
town.setHomeBlock(homeBlock);
town.setSpawn(townSpawn);
}
if (Siege.this.side1AreAttackers) {
Siege.this.attackerPlayers = Siege.this.war.getSide1Players();
Siege.this.defenderPlayers = Siege.this.war.getSide2Players();
} else {
Siege.this.attackerPlayers = Siege.this.war.getSide2Players();
Siege.this.defenderPlayers = Siege.this.war.getSide1Players();
}
if (Siege.this.siegeTicks >= Siege.this.MAXSIEGETICKS) {
Bukkit.getServer().getScheduler().cancelTask(Siege.this.bukkitId[0]);
if (Siege.this.attackerPoints > Siege.this.defenderPoints) {
Siege.this.attackersWin(Siege.this.owner);
} else {
Siege.this.defendersWin();
}
} else {
boolean attackersAreOnHomeBlock = false;
boolean defendersAreOnHomeBlock = false;
final Siege this$0 = Siege.this;
Siege.access$7(this$0, this$0.siegeTicks + 200);
Main.data2.getConfig().set("Sieges." + String.valueOf(Siege.this.id) + ".siegeticks",
(Object) Siege.this.siegeTicks);
Main.data2.saveConfig();
for (final String playerName : Siege.this.attackerPlayers) {
try {
if (WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName))
.getTownBlock().isHomeBlock()
&& WorldCoord
.parseWorldCoord(
Main.getInstance().getServer().getPlayer(playerName))
.getTownBlock().getTown().equals(town)
&& !Bukkit.getPlayer(playerName).isDead()
&& (Math.abs(
Bukkit.getServer().getPlayer(playerName).getLocation().getBlockY()
- townSpawn.getBlockY())) < 10) {
attackersAreOnHomeBlock = true;
}
} catch (NotRegisteredException ex) {
} catch (NullPointerException ex2) {
}
}
for (final String playerName : Siege.this.defenderPlayers) {
try {
if (WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName))
.getTownBlock().isHomeBlock()
&& WorldCoord
.parseWorldCoord(
Main.getInstance().getServer().getPlayer(playerName))
.getTownBlock().getTown().equals(town)
&& !Bukkit.getPlayer(playerName).isDead()
&& (Math.abs(
Bukkit.getServer().getPlayer(playerName).getLocation().getBlockY()
- townSpawn.getBlockY())) < 10) {
defendersAreOnHomeBlock = true;
}
} catch (NotRegisteredException ex3) {
} catch (NullPointerException ex4) {
}
}
if (attackersAreOnHomeBlock && defendersAreOnHomeBlock) {
if (this.homeBlockControl != 1) {
for (final String playerName : Siege.this.attackerPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(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())
+ "HomeBlock at " + Siege.this.town.getName() + " contested!");
} catch (NullPointerException ex6) {
}
}
}
this.homeBlockControl = 1;
} else if (attackersAreOnHomeBlock && !defendersAreOnHomeBlock) {
if (this.homeBlockControl != 2) {
for (final String playerName : Siege.this.attackerPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel())
+ "Attackers have captured the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Attacker Points per second");
} catch (NullPointerException ex7) {
}
}
for (final String playerName : Siege.this.defenderPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel())
+ "Attackers have captured the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Attacker Points per second");
} catch (NullPointerException ex8) {
}
}
}
this.homeBlockControl = 2;
Siege.this.addPointsToAttackers(10);
Main.data2.getConfig().set(
"Sieges." + String.valueOf(Siege.this.id) + ".attackerpoints",
(Object) Siege.this.attackerPoints);
Main.data2.saveConfig();
} else {
if (this.homeBlockControl != 3) {
for (final String playerName : Siege.this.attackerPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel())
+ "Defenders retain control of the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Defender Points per second");
} catch (NullPointerException ex9) {
}
}
for (final String playerName : Siege.this.defenderPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel())
+ "Defenders retain control of the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Defender Points per second");
} catch (NullPointerException ex10) {
}
}
}
Siege.this.addPointsToDefenders(10);
Main.data2.getConfig().set(
"Sieges." + String.valueOf(Siege.this.id) + ".defenderpoints",
(Object) Siege.this.defenderPoints);
Main.data2.saveConfig();
this.homeBlockControl = 3;
}
if (Siege.this.siegeTicks % 6000 == 0) {
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "Report on the siege of "
+ Siege.this.town.getName() + ":");
Bukkit.broadcastMessage(
"Attacker Points - " + String.valueOf(Siege.this.attackerPoints));
Bukkit.broadcastMessage(
"Defender Points - " + String.valueOf(Siege.this.defenderPoints));
}
}
}
}, 0L, 200L);
}
public void stop() {
Bukkit.getScheduler().cancelTask(this.bukkitId[0]);
SiegeCommands.sieges.remove(this);
Main.data2.getConfig().set("Sieges." + String.valueOf(this.id), (Object) null);
Main.data2.saveConfig();
}
public void attackersWin(final Player owner) {
final Resident resident = TownyAPI.getInstance().getResident(owner);
Nation nation = null;
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The attackers from " + this.attackers
+ " have won the siege of " + this.town.getName() + "!");
try {
nation = resident.getTown().getNation();
} catch (NotRegisteredException e) {
for (final String playerName : this.attackerPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "The town of "
+ this.town.getName()
+ " could not be occupied because the player who started the siege is not part of a nation");
} catch (NullPointerException ex) {
}
}
for (final String playerName : this.defenderPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "The town of "
+ this.town.getName()
+ " could not be occupied because the player who started the siege is not part of a nation");
} catch (NullPointerException ex2) {
}
}
}
if (nation != null) {
TownOccupationController.setTownOccupation(this.town, nation);
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName()
+ " has been placed under occupation by " + nation.getName() + "!");
}
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(owner.getUniqueId());
Main.econ.depositPlayer(offlinePlayer, 20000.0);
double amt = 0.0;
if (this.town.getAccount().getHoldingBalance() > 80000.0) {
amt = Math.floor(this.town.getAccount().getHoldingBalance()) / 4.0;
this.town.getAccount().withdraw(amt, "war loot");
} else {
if (this.town.getAccount().getHoldingBalance() < 20000.0) {
amt = this.town.getAccount().getHoldingBalance();
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName()
+ " has been destroyed by " + this.getAttackers() + "!");
TownyUniverse.getInstance().getDataSource().deleteTown(this.town);
Main.econ.depositPlayer(offlinePlayer, amt);
return;
}
this.town.getAccount().withdraw(20000.0, "war loot");
amt = 20000.0;
}
Bukkit.broadcastMessage("The town of " + this.town.getName() + " has been sacked by " + this.getAttackers()
+ ", valuing $" + String.valueOf(amt));
Main.warLogger.log("The town of " + this.town.getName() + " has been sacked by " + this.getAttackers()
+ ", valuing $" + String.valueOf(amt));
Main.econ.depositPlayer(offlinePlayer, amt);
stop();
clearBeacon();
}
public void defendersWin() {
this.town.getAccount().deposit(20000.0, "War chest");
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The defenders from " + this.defenders
+ " have won the siege of " + this.town.getName() + "!");
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + this.town.getName()
+ " has recovered the attackers' war chest, valued at $20,000");
Main.warLogger
.log("The defenders from " + this.defenders + " have won the siege of " + this.town.getName() + "!");
stop();
clearBeacon();
}
public void createBeacon() {
try {
World world = town.getWorld();
int homeBlockX = this.town.getHomeBlock().getX() * 16;
int homeBlockZ = (this.town.getHomeBlock().getZ() + 1) * 16;
if (homeBlockX > 0) {
homeBlockX -= 8;
}
if (homeBlockZ > 0) {
homeBlockZ -= 8;
}
if (homeBlockX < 0) {
homeBlockX += 8;
}
if (homeBlockZ < 0) {
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)) {
--homeBlockY;
beaconLoc.setY((double) homeBlockY);
}
homeBlockY += 2;
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, (double) (homeBlockX + 1), (double) (homeBlockY - 1), (double) homeBlockZ));
this.beaconLocs.add(
new Location(world, (double) (homeBlockX - 1), (double) (homeBlockY - 1), (double) homeBlockZ));
this.beaconLocs.add(
new Location(world, (double) homeBlockX, (double) (homeBlockY - 1), (double) (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)));
for (int i = 2; i < this.beaconLocs.size(); ++i) {
if (this.beaconLocs.get(i).getBlock().getType() != Material.AIR) {
i = 1;
homeBlockY++;
for (final Location loc : this.beaconLocs) {
loc.setY(loc.getY() + 1.0);
}
}
}
this.beaconLocs.get(0).getBlock().setType(Material.BEACON);
this.beaconLocs.get(1).getBlock().setType(Material.RED_STAINED_GLASS);
for (int i = 2; i < this.beaconLocs.size(); ++i) {
this.beaconLocs.get(i).getBlock().setType(Material.IRON_BLOCK);
}
Main.data2.getConfig().set("Sieges." + String.valueOf(this.id) + ".world", world.getName());
Main.data2.getConfig().set("Sieges." + String.valueOf(this.id) + ".homeblockx", homeBlockX);
Main.data2.getConfig().set("Sieges." + String.valueOf(this.id) + ".homeblocky", homeBlockY);
Main.data2.getConfig().set("Sieges." + String.valueOf(this.id) + ".homeblockz", homeBlockZ);
Main.data2.saveConfig();
} catch (TownyException ex) {
}
}
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, (double) (homeBlockX + 1), (double) (homeBlockY - 1), (double) homeBlockZ));
this.beaconLocs
.add(new Location(world, (double) (homeBlockX - 1), (double) (homeBlockY - 1), (double) homeBlockZ));
this.beaconLocs
.add(new Location(world, (double) homeBlockX, (double) (homeBlockY - 1), (double) (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)));
}
public void clearBeacon() {
for (final Location loc : this.beaconLocs) {
loc.getBlock().setType(Material.AIR);
}
}
public void addPointsToAttackers(final int points) {
this.attackerPoints += points;
}
public void addPointsToDefenders(final int points) {
this.defenderPoints += points;
}
public int getID() {
return this.id;
}
public void setID(final int id) {
this.id = id;
}
public War getWar() {
return this.war;
}
public void setWar(final War war) {
this.war = war;
}
public Town getTown() {
return this.town;
}
public void setTown(final Town town) {
this.town = town;
}
public String getAttackers() {
return this.attackers;
}
public void setAttackers(final String attackers) {
this.attackers = attackers;
}
public String getDefenders() {
return this.defenders;
}
public void setDefenders(final String defenders) {
this.attackers = defenders;
}
public int getAttackerPoints() {
return this.attackerPoints;
}
public void attackerPoints(final int attackerPoints) {
this.attackerPoints = attackerPoints;
}
public int getDefenderPoints() {
return this.defenderPoints;
}
public void defenderPoints(final int defenderPoints) {
this.defenderPoints = this.attackerPoints;
}
public boolean getSide1AreAttackers() {
return this.side1AreAttackers;
}
public void setSide1AreAttackers(final boolean side1AreAttackers) {
this.side1AreAttackers = side1AreAttackers;
}
public boolean getSide2AreAttackers() {
return this.side2AreAttackers;
}
public void setSide2AreAttackers(final boolean side2AreAttackers) {
this.side2AreAttackers = side2AreAttackers;
}
public ArrayList<String> getAttackerPlayers() {
return this.attackerPlayers;
}
public void setAttackerPlayer(final ArrayList<String> attackerPlayers) {
this.attackerPlayers = attackerPlayers;
}
public ArrayList<String> getDefenderPlayers() {
return this.defenderPlayers;
}
public void setDefenderPlayer(final ArrayList<String> defenderPlayers) {
this.defenderPlayers = this.attackerPlayers;
}
static /* synthetic */ void access$7(final Siege siege, final int siegeTicks) {
siege.siegeTicks = siegeTicks;
}
}
@@ -6,7 +6,6 @@ package me.ShermansWorld.AlathraWar;
import org.bukkit.OfflinePlayer;
import com.palmergames.bukkit.towny.object.TownyWorld;
import java.util.Iterator;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.WorldCoord;
@@ -58,7 +57,7 @@ public class SiegeCommands implements CommandExecutor
p.sendMessage("-=-=-=-=-=-=-=-=-=-=-=-");
}
} else if (args[0].equalsIgnoreCase("help")) {
if (p.hasPermission("!AlatrhaWar.admin")) {
if (p.hasPermission("!AlathraWar.admin")) {
p.sendMessage(Helper.Chatlabel() + "/siege stop [id]");
}
p.sendMessage(Helper.Chatlabel() + "/siege start [war] [town]");
@@ -107,6 +106,7 @@ public class SiegeCommands implements CommandExecutor
if (String.valueOf(SiegeCommands.sieges.get(j).getID()).equalsIgnoreCase(args[1])) {
found2 = true;
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The siege at " + SiegeCommands.sieges.get(j).getTown().getName() + " has been abandoned by " + SiegeCommands.sieges.get(j).getAttackers());
Main.warLogger.log(p.getName() + " abandoned the siege they started at " + SiegeCommands.sieges.get(j).getTown().getName());
SiegeCommands.sieges.get(j).defendersWin();
break;
}
@@ -130,13 +130,7 @@ public class SiegeCommands implements CommandExecutor
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]");
}
TownyWorld townyWorld;
try {
townyWorld = WorldCoord.parseWorldCoord(p.getLocation()).getTownyWorld();
}
catch (NotRegisteredException e) {
Bukkit.getLogger().info("TownyWorld not found");
return false;
}
townyWorld = WorldCoord.parseWorldCoord(p.getLocation()).getTownyWorld();
if (!SiegeCommands.towns.isEmpty()) {
SiegeCommands.towns.clear();
}
@@ -228,7 +222,7 @@ public class SiegeCommands implements CommandExecutor
return false;
}
}
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(p.getName());
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(p.getUniqueId());
if (Main.econ.getBalance(offlinePlayer) <= 20000.0) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must have at least $20,000 to put up to start a siege");
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID), (Object)null);
@@ -240,6 +234,8 @@ public class SiegeCommands implements CommandExecutor
siege2.start();
siege2.createBeacon();
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "As part of " + war.getName() + ", forces from " + siege2.getAttackers() + " are laying siege to the town of " + town.getName() + "!");
Main.warLogger.log(p.getName() + " started a siege.");
Main.warLogger.log("As part of " + war.getName() + ", forces from " + siege2.getAttackers() + " are laying siege to the town of " + town.getName() + "!");
}
}
}
@@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.Town;
public class SiegeTabCompletion implements TabCompleter {
@@ -45,8 +45,8 @@ public class SiegeTabCompletion implements TabCompleter {
}
} else if (args.length == 3) {
if (args[0].equalsIgnoreCase("start")) {
if (!TownyUniverse.getInstance().getDataSource().getTowns().isEmpty()) {
for (Town town : TownyUniverse.getInstance().getDataSource().getTowns()) {
if (!TownyAPI.getInstance().getTowns().isEmpty()) {
for (Town town : TownyAPI.getInstance().getTowns()) {
completions.add(town.getName());
}
return completions;
@@ -6,6 +6,10 @@ package me.ShermansWorld.AlathraWar;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import me.neznamy.tab.api.TabAPI;
import me.neznamy.tab.api.TabPlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
@@ -30,7 +34,7 @@ public class WarCommands implements CommandExecutor
}
else if (args.length >= 1) {
if (args[0].equalsIgnoreCase("create")) {
if (!p.hasPermission("AlatrhaWar.admin")) {
if (!p.hasPermission("AlathraWar.admin")) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou do not have permission to do this"));
return false;
}
@@ -50,6 +54,7 @@ public class WarCommands implements CommandExecutor
Main.data.getConfig().set("Wars." + args[1].toLowerCase() + ".side2players", (Object)side2Players);
Main.data.saveConfig();
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War created with the name " + args[1].toLowerCase() + ", " + args[2] + " vs. " + args[3]);
Main.warLogger.log(p.getName() + " created a new war with the name " + args[1].toLowerCase() + ", " + args[2] + " vs. " + args[3]);
}
else {
for (int i = 0; i < WarCommands.wars.size(); ++i) {
@@ -71,7 +76,8 @@ public class WarCommands implements CommandExecutor
Main.data.getConfig().set("Wars." + args[1].toLowerCase() + ".side1players", (Object)side1Players2);
Main.data.getConfig().set("Wars." + args[1].toLowerCase() + ".side2players", (Object)side2Players2);
Main.data.saveConfig();
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War created with the name " + args[1] + ", " + args[2] + " vs. " + args[3]);
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War created with the name " + args[1].toLowerCase() + ", " + args[2] + " vs. " + args[3]);
Main.warLogger.log(p.getName() + " created a new war with the name " + args[1].toLowerCase() + ", " + args[2] + " vs. " + args[3]);
}
}
}
@@ -80,7 +86,7 @@ public class WarCommands implements CommandExecutor
}
}
else if (args[0].equalsIgnoreCase("delete")) {
if (!p.hasPermission("AlatrhaWar.admin")) {
if (!p.hasPermission("AlathraWar.admin")) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou do not have permission to do this"));
return false;
}
@@ -89,6 +95,7 @@ public class WarCommands implements CommandExecutor
for (int j = 0; j < WarCommands.wars.size(); ++j) {
if (WarCommands.wars.get(j).getName().equalsIgnoreCase(args[1])) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "The war named " + args[1] + " has been deleted");
Main.warLogger.log(p.getName() + " deleted a war named " + args[1]);
WarCommands.wars.remove(j);
Main.data.getConfig().set("Wars." + args[1].toLowerCase(), (Object)null);
Main.data.saveConfig();
@@ -127,10 +134,13 @@ public class WarCommands implements CommandExecutor
}
war2.addPlayerSide1(p.getName());
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the war on the side of " + war2.getSide1());
p.setPlayerListName(String.valueOf(Helper.color(new StringBuilder("&c[").append(war2.getSide1()).append("]&r").toString())) + p.getName());
TabPlayer tabPlayer = TabAPI.getInstance().getPlayer(p.getUniqueId());
TabAPI.getInstance().getTablistFormatManager().setSuffix(tabPlayer, Helper.color(new StringBuilder("&c[").append(war2.getSide1()).append("]&r").toString()));
Main.data.getConfig().set("Wars." + args[1].toLowerCase() + ".side1players", (Object)war2.getSide1Players());
Main.data.saveConfig();
Bukkit.getServer().broadcastMessage(String.valueOf(Helper.Chatlabel()) + p.getName() + " has joined " + war2.getName() + " on the side of " + war2.getSide1() + "!");
Bukkit.getLogger().info("[AlathraWar] Player " + p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide1());
Main.warLogger.log(p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide1());
found = true;
}
else {
@@ -143,10 +153,13 @@ public class WarCommands implements CommandExecutor
}
war2.addPlayerSide2(p.getName());
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the war on the side of " + war2.getSide2());
p.setPlayerListName(String.valueOf(Helper.color(new StringBuilder("&9[").append(war2.getSide2()).append("]&r").toString())) + p.getName());
TabPlayer tabPlayer = TabAPI.getInstance().getPlayer(p.getUniqueId());
TabAPI.getInstance().getTablistFormatManager().setSuffix(tabPlayer, Helper.color(new StringBuilder("&9[").append(war2.getSide2()).append("]&r").toString()));
Main.data.getConfig().set("Wars." + args[1].toLowerCase() + ".side2players", (Object)war2.getSide2Players());
Main.data.saveConfig();
Bukkit.getServer().broadcastMessage(String.valueOf(Helper.Chatlabel()) + p.getName() + " has joined " + war2.getName() + " on the side of " + war2.getSide2() + "!");
Bukkit.getLogger().info("[AlathraWar] Player " + p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide2());
Main.warLogger.log(p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide2());
found = true;
}
}
@@ -172,8 +185,10 @@ public class WarCommands implements CommandExecutor
Main.data.getConfig().set("Wars." + args[1] + ".side1players", (Object)war3.getSide1Players());
Main.data.saveConfig();
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have left the war");
p.setPlayerListName(p.getName());
TabPlayer tabPlayer = TabAPI.getInstance().getPlayer(p.getUniqueId());
TabAPI.getInstance().getTablistFormatManager().resetSuffix(tabPlayer);
Bukkit.getServer().broadcastMessage(String.valueOf(Helper.Chatlabel()) + p.getName() + " has left " + war3.getName() + ", they were on the side of " + war3.getSide1());
Main.warLogger.log(p.getName() + " has left " + war3.getName() + ", they were on the side of " + war3.getSide1());
}
if (!war3.getSide2Players().contains(p.getName())) {
continue;
@@ -183,8 +198,10 @@ public class WarCommands implements CommandExecutor
Main.data.getConfig().set("Wars." + args[1] + ".side2players", (Object)war3.getSide2Players());
Main.data.saveConfig();
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have left the war");
p.setPlayerListName(p.getName());
TabPlayer tabPlayer = TabAPI.getInstance().getPlayer(p.getUniqueId());
TabAPI.getInstance().getTablistFormatManager().resetSuffix(tabPlayer);
Bukkit.getServer().broadcastMessage(String.valueOf(Helper.Chatlabel()) + p.getName() + " has left " + war3.getName() + ", they were on the side of " + war3.getSide2());
Main.warLogger.log(p.getName() + " has left " + war3.getName() + ", they were on the side of " + war3.getSide2());
}
}
if (!found) {
@@ -231,7 +248,7 @@ public class WarCommands implements CommandExecutor
}
} else if (args[0].equalsIgnoreCase("help")) {
if (p.hasPermission("!AlatrhaWar.admin")) {
if (p.hasPermission("!AlathraWar.admin")) {
p.sendMessage(Helper.Chatlabel() + "/war create [name] [side1] [side2]");
p.sendMessage(Helper.Chatlabel() + "/war delete [name]");
}