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
+594 -425

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, final boolean side1AreAttackers, final boolean side2AreAttackers) { public Siege(final int id, final War war, final Town town, final String attackers, final String defenders,
this.siegeTicks = 0; final boolean side1AreAttackers, final boolean side2AreAttackers) {
this.bukkitId = new int[1]; this.siegeTicks = 0;
this.attackerPlayers = new ArrayList<String>(); this.bukkitId = new int[1];
this.defenderPlayers = new ArrayList<String>(); this.attackerPlayers = new ArrayList<String>();
this.beaconLocs = new ArrayList<Location>(); this.defenderPlayers = new ArrayList<String>();
this.war = war; this.beaconLocs = new ArrayList<Location>();
this.town = town; this.war = war;
this.attackers = attackers; this.town = town;
this.defenders = defenders; this.attackers = attackers;
this.side1AreAttackers = side1AreAttackers; this.defenders = defenders;
this.side2AreAttackers = side2AreAttackers; this.side1AreAttackers = side1AreAttackers;
this.id = id; this.side2AreAttackers = side2AreAttackers;
} 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 @Override
public void run() { public void run() {
if (homeBlock != null) { if (homeBlock != null) {
town.setHomeBlock(homeBlock); town.setHomeBlock(homeBlock);
town.setSpawn(townSpawn); town.setSpawn(townSpawn);
} }
if (Siege.this.side1AreAttackers) { if (Siege.this.side1AreAttackers) {
Siege.this.attackerPlayers = Siege.this.war.getSide1Players(); Siege.this.attackerPlayers = Siege.this.war.getSide1Players();
Siege.this.defenderPlayers = Siege.this.war.getSide2Players(); 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 {
} Siege.this.defendersWin();
else { }
Siege.this.defendersWin(); } else {
} boolean attackersAreOnHomeBlock = false;
} boolean defendersAreOnHomeBlock = false;
else { final Siege this$0 = Siege.this;
boolean attackersAreOnHomeBlock = false; Siege.access$7(this$0, this$0.siegeTicks + 200);
boolean defendersAreOnHomeBlock = false; Main.data2.getConfig().set("Sieges." + String.valueOf(Siege.this.id) + ".siegeticks",
final Siege this$0 = Siege.this; (Object) Siege.this.siegeTicks);
Siege.access$7(this$0, this$0.siegeTicks + 200); Main.data2.saveConfig();
Main.data2.getConfig().set("Sieges." + String.valueOf(Siege.this.id) + ".siegeticks", (Object)Siege.this.siegeTicks); for (final String playerName : Siege.this.attackerPlayers) {
Main.data2.saveConfig(); try {
for (final String playerName : Siege.this.attackerPlayers) { if (WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName))
try { .getTownBlock().isHomeBlock()
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()) { && WorldCoord
attackersAreOnHomeBlock = true; .parseWorldCoord(
} Main.getInstance().getServer().getPlayer(playerName))
} .getTownBlock().getTown().equals(town)
catch (NotRegisteredException ex) {} && !Bukkit.getPlayer(playerName).isDead()
catch (NullPointerException ex2) {} && (Math.abs(
} Bukkit.getServer().getPlayer(playerName).getLocation().getBlockY()
for (final String playerName : Siege.this.defenderPlayers) { - townSpawn.getBlockY())) < 10) {
try { attackersAreOnHomeBlock = true;
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 ex) {
} } catch (NullPointerException ex2) {
} }
catch (NotRegisteredException ex3) {} }
catch (NullPointerException ex4) {} for (final String playerName : Siege.this.defenderPlayers) {
} try {
if (attackersAreOnHomeBlock && defendersAreOnHomeBlock) { if (WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName))
if (this.homeBlockControl != 1) { .getTownBlock().isHomeBlock()
for (final String playerName : Siege.this.attackerPlayers) { && WorldCoord
try { .parseWorldCoord(
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "HomeBlock at " + Siege.this.town.getName() + " contested!"); Main.getInstance().getServer().getPlayer(playerName))
} .getTownBlock().getTown().equals(town)
catch (NullPointerException ex5) {} && !Bukkit.getPlayer(playerName).isDead()
} && (Math.abs(
for (final String playerName : Siege.this.defenderPlayers) { Bukkit.getServer().getPlayer(playerName).getLocation().getBlockY()
try { - townSpawn.getBlockY())) < 10) {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "HomeBlock at " + Siege.this.town.getName() + " contested!"); defendersAreOnHomeBlock = true;
} }
catch (NullPointerException ex6) {} } catch (NotRegisteredException ex3) {
} } catch (NullPointerException ex4) {
} }
this.homeBlockControl = 1; }
} if (attackersAreOnHomeBlock && defendersAreOnHomeBlock) {
else if (attackersAreOnHomeBlock && !defendersAreOnHomeBlock) { if (this.homeBlockControl != 1) {
if (this.homeBlockControl != 2) { for (final String playerName : Siege.this.attackerPlayers) {
for (final String playerName : Siege.this.attackerPlayers) { try {
try { Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel())
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Attackers have captured the HomeBlock at " + Siege.this.town.getName() + "! +1 Attacker Points per second"); + "HomeBlock at " + Siege.this.town.getName() + " contested!");
} } catch (NullPointerException ex5) {
catch (NullPointerException ex7) {} }
} }
for (final String playerName : Siege.this.defenderPlayers) { for (final String playerName : Siege.this.defenderPlayers) {
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 ex8) {} } catch (NullPointerException ex6) {
} }
} }
this.homeBlockControl = 2; }
Siege.this.addPointsToAttackers(10); this.homeBlockControl = 1;
Main.data2.getConfig().set("Sieges." + String.valueOf(Siege.this.id) + ".attackerpoints", (Object)Siege.this.attackerPoints); } else if (attackersAreOnHomeBlock && !defendersAreOnHomeBlock) {
Main.data2.saveConfig(); if (this.homeBlockControl != 2) {
} for (final String playerName : Siege.this.attackerPlayers) {
else { try {
if (this.homeBlockControl != 3) { Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel())
for (final String playerName : Siege.this.attackerPlayers) { + "Attackers have captured the HomeBlock at "
try { + Siege.this.town.getName() + "! +1 Attacker Points per second");
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 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())
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defenders retain control of the HomeBlock at " + Siege.this.town.getName() + "! +1 Defender Points per second"); + "Attackers have captured the HomeBlock at "
} + Siege.this.town.getName() + "! +1 Attacker Points per second");
catch (NullPointerException ex10) {} } catch (NullPointerException ex8) {
} }
} }
Siege.this.addPointsToDefenders(10); }
Main.data2.getConfig().set("Sieges." + String.valueOf(Siege.this.id) + ".defenderpoints", (Object)Siege.this.defenderPoints); this.homeBlockControl = 2;
Main.data2.saveConfig(); Siege.this.addPointsToAttackers(10);
this.homeBlockControl = 3; Main.data2.getConfig().set(
} "Sieges." + String.valueOf(Siege.this.id) + ".attackerpoints",
if (Siege.this.siegeTicks % 6000 == 0) { (Object) Siege.this.attackerPoints);
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "Report on the siege of " + Siege.this.town.getName() + ":"); Main.data2.saveConfig();
Bukkit.broadcastMessage("Attacker Points - " + String.valueOf(Siege.this.attackerPoints)); } else {
Bukkit.broadcastMessage("Defender Points - " + String.valueOf(Siege.this.defenderPoints)); if (this.homeBlockControl != 3) {
} for (final String playerName : Siege.this.attackerPlayers) {
} try {
} Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel())
}, 0L, 200L); + "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() { public void stop() {
Bukkit.getScheduler().cancelTask(this.bukkitId[0]); Bukkit.getScheduler().cancelTask(this.bukkitId[0]);
SiegeCommands.sieges.remove(this); SiegeCommands.sieges.remove(this);
Main.data2.getConfig().set("Sieges." + String.valueOf(this.id), (Object)null); Main.data2.getConfig().set("Sieges." + String.valueOf(this.id), (Object) null);
Main.data2.saveConfig(); Main.data2.saveConfig();
} }
public void attackersWin(final Player owner) { public void attackersWin(final Player owner) {
final Resident resident = TownyAPI.getInstance().getResident(owner); final Resident resident = TownyAPI.getInstance().getResident(owner);
Nation nation = null; Nation nation = null;
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The attackers from " + this.attackers + " have won the siege of " + this.town.getName() + "!"); Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The attackers from " + this.attackers
try { + " have won the siege of " + this.town.getName() + "!");
nation = resident.getTown().getNation(); try {
} nation = resident.getTown().getNation();
catch (NotRegisteredException e) { } catch (NotRegisteredException e) {
for (final String playerName : this.attackerPlayers) { for (final String playerName : this.attackerPlayers) {
try { 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"); Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "The town of "
} + this.town.getName()
catch (NullPointerException ex) {} + " 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"); for (final String playerName : this.defenderPlayers) {
} try {
catch (NullPointerException ex2) {} 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");
if (nation != null) { } catch (NullPointerException ex2) {
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()); if (nation != null) {
Main.econ.depositPlayer(offlinePlayer, 20000.0); TownOccupationController.setTownOccupation(this.town, nation);
double amt = 0.0; Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName()
if (this.town.getAccount().getHoldingBalance() > 80000.0) { + " has been placed under occupation by " + nation.getName() + "!");
amt = Math.floor(this.town.getAccount().getHoldingBalance()) / 4.0; }
this.town.getAccount().withdraw(amt, "war loot"); final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(owner.getUniqueId());
} Main.econ.depositPlayer(offlinePlayer, 20000.0);
else { double amt = 0.0;
if (this.town.getAccount().getHoldingBalance() < 20000.0) { if (this.town.getAccount().getHoldingBalance() > 80000.0) {
amt = this.town.getAccount().getHoldingBalance(); amt = Math.floor(this.town.getAccount().getHoldingBalance()) / 4.0;
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName() + " has been destroyed by " + this.getAttackers() + "!"); this.town.getAccount().withdraw(amt, "war loot");
TownyUniverse.getInstance().getDataSource().deleteTown(this.town); } else {
Main.econ.depositPlayer(offlinePlayer, amt); if (this.town.getAccount().getHoldingBalance() < 20000.0) {
return; amt = this.town.getAccount().getHoldingBalance();
} Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName()
this.town.getAccount().withdraw(20000.0, "war loot"); + " has been destroyed by " + this.getAttackers() + "!");
amt = 20000.0; TownyUniverse.getInstance().getDataSource().deleteTown(this.town);
} Main.econ.depositPlayer(offlinePlayer, amt);
Bukkit.broadcastMessage("The town of " + this.town.getName() + " has been sacked by " + this.getAttackers() + ", valuing $" + String.valueOf(amt)); return;
Main.econ.depositPlayer(offlinePlayer, amt); }
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(); stop();
clearBeacon(); clearBeacon();
} }
public void defendersWin() { public void defendersWin() {
this.town.getAccount().deposit(20000.0, "War chest"); 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()) + "The defenders from " + this.defenders
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + this.town.getName() + " has recovered the attackers' war chest, valued at $20,000"); + " 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();
}
stop(); public void createBeacon() {
clearBeacon(); 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 createBeacon() { public void resetBeacon(World world, int homeBlockX, int homeBlockY, int homeBlockZ) {
try { this.beaconLocs.add(new Location(world, (double) homeBlockX, (double) homeBlockY, (double) homeBlockZ));
World world = town.getWorld(); this.beaconLocs.add(new Location(world, (double) homeBlockX, (double) (homeBlockY + 1), (double) homeBlockZ));
int homeBlockX = this.town.getHomeBlock().getX() * 16; this.beaconLocs.add(new Location(world, (double) homeBlockX, (double) (homeBlockY - 1), (double) homeBlockZ));
int homeBlockZ = this.town.getHomeBlock().getZ() * 16; this.beaconLocs
if (homeBlockX > 0) { .add(new Location(world, (double) (homeBlockX + 1), (double) (homeBlockY - 1), (double) homeBlockZ));
homeBlockX -= 8; this.beaconLocs
} .add(new Location(world, (double) (homeBlockX - 1), (double) (homeBlockY - 1), (double) homeBlockZ));
if (homeBlockZ > 0) { this.beaconLocs
homeBlockZ -= 8; .add(new Location(world, (double) homeBlockX, (double) (homeBlockY - 1), (double) (homeBlockZ + 1)));
} this.beaconLocs
if (homeBlockX < 0) { .add(new Location(world, (double) homeBlockX, (double) (homeBlockY - 1), (double) (homeBlockZ - 1)));
homeBlockX += 8; this.beaconLocs.add(
} new Location(world, (double) (homeBlockX + 1), (double) (homeBlockY - 1), (double) (homeBlockZ + 1)));
if (homeBlockZ < 0) { this.beaconLocs.add(
homeBlockZ += 8; new Location(world, (double) (homeBlockX + 1), (double) (homeBlockY - 1), (double) (homeBlockZ - 1)));
} this.beaconLocs.add(
int homeBlockY = 253; new Location(world, (double) (homeBlockX - 1), (double) (homeBlockY - 1), (double) (homeBlockZ + 1)));
final Location beaconLoc = new Location(this.town.getWorld(), (double)homeBlockX, (double)(homeBlockY - 2), (double)homeBlockZ); this.beaconLocs.add(
while (beaconLoc.getBlock().getType().equals((Object)Material.AIR)) { new Location(world, (double) (homeBlockX - 1), (double) (homeBlockY - 1), (double) (homeBlockZ - 1)));
--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) { public void clearBeacon() {
this.beaconLocs.add(new Location(world, (double)homeBlockX, (double)homeBlockY, (double)homeBlockZ)); for (final Location loc : this.beaconLocs) {
this.beaconLocs.add(new Location(world, (double)homeBlockX, (double)(homeBlockY + 1), (double)homeBlockZ)); loc.getBlock().setType(Material.AIR);
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() { public void addPointsToAttackers(final int points) {
for (final Location loc : this.beaconLocs) { this.attackerPoints += points;
loc.getBlock().setType(Material.AIR); }
}
}
public void addPointsToAttackers(final int points) { public void addPointsToDefenders(final int points) {
this.attackerPoints += points; this.defenderPoints += points;
} }
public void addPointsToDefenders(final int points) { public int getID() {
this.defenderPoints += points; return this.id;
} }
public int getID() { public void setID(final int id) {
return this.id; this.id = id;
} }
public void setID(final int id) { public War getWar() {
this.id = id; return this.war;
} }
public War getWar() { public void setWar(final War war) {
return this.war; this.war = war;
} }
public void setWar(final War war) { public Town getTown() {
this.war = war; return this.town;
} }
public Town getTown() { public void setTown(final Town town) {
return this.town; this.town = town;
} }
public void setTown(final Town town) { public String getAttackers() {
this.town = town; return this.attackers;
} }
public String getAttackers() { public void setAttackers(final String attackers) {
return this.attackers; this.attackers = attackers;
} }
public void setAttackers(final String attackers) { public String getDefenders() {
this.attackers = attackers; return this.defenders;
} }
public String getDefenders() { public void setDefenders(final String defenders) {
return this.defenders; this.attackers = defenders;
} }
public void setDefenders(final String defenders) { public int getAttackerPoints() {
this.attackers = defenders; return this.attackerPoints;
} }
public int getAttackerPoints() { public void attackerPoints(final int attackerPoints) {
return this.attackerPoints; this.attackerPoints = attackerPoints;
} }
public void attackerPoints(final int attackerPoints) { public int getDefenderPoints() {
this.attackerPoints = attackerPoints; return this.defenderPoints;
} }
public int getDefenderPoints() { public void defenderPoints(final int defenderPoints) {
return this.defenderPoints; this.defenderPoints = this.attackerPoints;
} }
public void defenderPoints(final int defenderPoints) { public boolean getSide1AreAttackers() {
this.defenderPoints = this.attackerPoints; return this.side1AreAttackers;
} }
public boolean getSide1AreAttackers() { public void setSide1AreAttackers(final boolean side1AreAttackers) {
return this.side1AreAttackers; this.side1AreAttackers = side1AreAttackers;
} }
public void setSide1AreAttackers(final boolean side1AreAttackers) { public boolean getSide2AreAttackers() {
this.side1AreAttackers = side1AreAttackers; return this.side2AreAttackers;
} }
public boolean getSide2AreAttackers() { public void setSide2AreAttackers(final boolean side2AreAttackers) {
return this.side2AreAttackers; this.side2AreAttackers = side2AreAttackers;
} }
public void setSide2AreAttackers(final boolean side2AreAttackers) { public ArrayList<String> getAttackerPlayers() {
this.side2AreAttackers = side2AreAttackers; return this.attackerPlayers;
} }
public ArrayList<String> getAttackerPlayers() { public void setAttackerPlayer(final ArrayList<String> attackerPlayers) {
return this.attackerPlayers; this.attackerPlayers = attackerPlayers;
} }
public void setAttackerPlayer(final ArrayList<String> attackerPlayers) { public ArrayList<String> getDefenderPlayers() {
this.attackerPlayers = attackerPlayers; return this.defenderPlayers;
} }
public ArrayList<String> getDefenderPlayers() { public void setDefenderPlayer(final ArrayList<String> defenderPlayers) {
return this.defenderPlayers; this.defenderPlayers = this.attackerPlayers;
} }
public void setDefenderPlayer(final ArrayList<String> defenderPlayers) { static /* synthetic */ void access$7(final Siege siege, final int siegeTicks) {
this.defenderPlayers = this.attackerPlayers; siege.siegeTicks = siegeTicks;
} }
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]");
} }