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