mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 22:14:45 +00:00
Add files via upload
This commit is contained in:
1 parent
999e956699
commit
243d942a4d
31 files changed
+1818
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,13 @@
|
||||
name: AlathraWar
|
||||
version: 1.0.2
|
||||
api-version: 1.16
|
||||
author: ShermansWorld
|
||||
main: me.ShermansWorld.AlathraWar.Main
|
||||
|
||||
commands:
|
||||
war:
|
||||
description: used to create, delete, join and leave wars
|
||||
softdepend: [Vault, Towny]
|
||||
siege:
|
||||
description: used to start, end, and view sieges
|
||||
softdepend: [Vault, Towny]
|
||||
@@ -0,0 +1,3 @@
|
||||
MaxID: 0
|
||||
|
||||
Sieges:
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.36
|
||||
//
|
||||
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class BlockBreakListener implements Listener
|
||||
{
|
||||
@EventHandler
|
||||
public void onBlockBreak(final BlockBreakEvent event) {
|
||||
final Block block = event.getBlock();
|
||||
if (SiegeCommands.sieges.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (final Siege siege : SiegeCommands.sieges) {
|
||||
if (siege.beaconLocs.contains(event.getBlock().getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.36
|
||||
//
|
||||
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class Helper
|
||||
{
|
||||
public static String color(final String input) {
|
||||
return ChatColor.translateAlternateColorCodes('&', input);
|
||||
}
|
||||
|
||||
public static String Chatlabel() {
|
||||
return color("&6[&4AlathraWar&6]&r ");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.36
|
||||
//
|
||||
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import java.util.Iterator;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class JoinListener implements Listener
|
||||
{
|
||||
@EventHandler
|
||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
final Player p = event.getPlayer();
|
||||
for (final War war : WarCommands.wars) {
|
||||
if (war.getSide1Players().contains(p.getName())) {
|
||||
p.setPlayerListName(String.valueOf(Helper.color(new StringBuilder("&c[").append(war.getSide1()).append("]&r").toString())) + p.getName());
|
||||
}
|
||||
else {
|
||||
if (!war.getSide2Players().contains(p.getName())) {
|
||||
continue;
|
||||
}
|
||||
p.setPlayerListName(String.valueOf(Helper.color(new StringBuilder("&9[").append(war.getSide2()).append("]&r").toString())) + p.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.36
|
||||
//
|
||||
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import java.util.Iterator;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import org.bukkit.Bukkit;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import org.bukkit.entity.Entity;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public final class KillsListener implements Listener
|
||||
{
|
||||
@EventHandler
|
||||
public void onPlayerKilled(final PlayerDeathEvent event) {
|
||||
if (event.getEntity().getPlayer() == null || !(event.getEntity().getKiller() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
final Player killed = event.getEntity();
|
||||
final Player killer = event.getEntity().getKiller();
|
||||
Town town = null;
|
||||
try {
|
||||
town = WorldCoord.parseWorldCoord((Entity)killed).getTownBlock().getTown();
|
||||
}
|
||||
catch (NotRegisteredException ex2) {}
|
||||
boolean playerCloseToHomeBlock = false;
|
||||
try {
|
||||
for (final Siege siege : SiegeCommands.sieges) {
|
||||
final int homeBlockXCoord = siege.getTown().getHomeBlock().getCoord().getX() * 16;
|
||||
final int homeBlockZCoord = siege.getTown().getHomeBlock().getCoord().getZ() * 16;
|
||||
if (Math.abs(killed.getLocation().getBlockX() - homeBlockXCoord) <= 300 && Math.abs(killed.getLocation().getBlockZ() - homeBlockZCoord) <= 300) {
|
||||
playerCloseToHomeBlock = true;
|
||||
}
|
||||
if (siege.getAttackerPlayers().contains(killer.getName()) && ((town != null && town.equals(siege.getTown())) || playerCloseToHomeBlock)) {
|
||||
if (siege.getDefenderPlayers().contains(killed.getName())) {
|
||||
siege.addPointsToAttackers(20);
|
||||
for (final String playerName : siege.getAttackerPlayers()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! + 20 Attacker Points");
|
||||
}
|
||||
catch (NullPointerException ex5) {}
|
||||
}
|
||||
for (final String playerName : siege.getDefenderPlayers()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! + 20 Attacker Points");
|
||||
}
|
||||
catch (NullPointerException ex6) {}
|
||||
}
|
||||
}
|
||||
this.siegeKill(killed, event);
|
||||
return;
|
||||
}
|
||||
if (siege.getDefenderPlayers().contains(killer.getName()) && ((town != null && town.equals(siege.getTown())) || playerCloseToHomeBlock)) {
|
||||
if (siege.getAttackerPlayers().contains(killed.getName())) {
|
||||
siege.addPointsToDefenders(20);
|
||||
for (final String playerName : siege.getAttackerPlayers()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Attacker killed! + 20 Defender Points");
|
||||
}
|
||||
catch (NullPointerException ex3) {}
|
||||
}
|
||||
for (final String playerName : siege.getDefenderPlayers()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Attacker killed! + 20 Defender Points");
|
||||
}
|
||||
catch (NullPointerException ex4) {}
|
||||
}
|
||||
}
|
||||
this.siegeKill(killed, event);
|
||||
return;
|
||||
}
|
||||
if ( (town != null && town.equals(siege.getTown()) || playerCloseToHomeBlock) ) {
|
||||
this.siegeKill(killed, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (NullPointerException | TownyException ex7) {
|
||||
final Exception ex;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void siegeKill(final Player killed, final PlayerDeathEvent event) {
|
||||
final Inventory inv = (Inventory)killed.getInventory();
|
||||
for (int i = 0; i < inv.getSize(); ++i) {
|
||||
final ItemStack is = inv.getItem(i);
|
||||
if (is != null && (is.getType() == Material.NETHERITE_AXE || is.getType() == Material.NETHERITE_SWORD || is.getType() == Material.DIAMOND_AXE || is.getType() == Material.DIAMOND_SWORD || is.getType() == Material.IRON_AXE || is.getType() == Material.IRON_SWORD)) {
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
final Damageable damageable = (Damageable)meta;
|
||||
if (is.getType() == Material.NETHERITE_SWORD || is.getType() == Material.NETHERITE_AXE) {
|
||||
damageable.setDamage(damageable.getDamage() + 507);
|
||||
if (damageable.getDamage() > 2000) {
|
||||
damageable.setDamage(2030);
|
||||
}
|
||||
}
|
||||
else if (is.getType() == Material.DIAMOND_SWORD || is.getType() == Material.DIAMOND_AXE) {
|
||||
damageable.setDamage(damageable.getDamage() + 390);
|
||||
if (damageable.getDamage() > 1500) {
|
||||
damageable.setDamage(1560);
|
||||
}
|
||||
}
|
||||
else if (is.getType() == Material.IRON_SWORD || is.getType() == Material.IRON_AXE) {
|
||||
damageable.setDamage(damageable.getDamage() + 62);
|
||||
if (damageable.getDamage() > 200) {
|
||||
damageable.setDamage(249);
|
||||
}
|
||||
}
|
||||
meta = (ItemMeta)damageable;
|
||||
is.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
final ItemStack[] armor = killed.getInventory().getArmorContents();
|
||||
for (int j = 0; j < armor.length; ++j) {
|
||||
if (armor[j] != null) {
|
||||
final ItemStack is2 = armor[j];
|
||||
if (is2.getType() == Material.NETHERITE_HELMET || is2.getType() == Material.NETHERITE_CHESTPLATE || is2.getType() == Material.NETHERITE_LEGGINGS || is2.getType() == Material.NETHERITE_BOOTS || is2.getType() == Material.DIAMOND_HELMET || is2.getType() == Material.DIAMOND_CHESTPLATE || is2.getType() == Material.DIAMOND_LEGGINGS || is2.getType() == Material.NETHERITE_BOOTS || is2.getType() == Material.IRON_HELMET || is2.getType() == Material.IRON_CHESTPLATE || is2.getType() == Material.IRON_LEGGINGS || is2.getType() == Material.IRON_BOOTS) {
|
||||
ItemMeta meta2 = is2.getItemMeta();
|
||||
final Damageable damageable2 = (Damageable)meta2;
|
||||
if (is2.getType() == Material.NETHERITE_HELMET) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 101);
|
||||
if (damageable2.getDamage() > 400) {
|
||||
damageable2.setDamage(406);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.NETHERITE_CHESTPLATE) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 148);
|
||||
if (damageable2.getDamage() > 450) {
|
||||
damageable2.setDamage(591);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.NETHERITE_LEGGINGS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 138);
|
||||
if (damageable2.getDamage() > 420) {
|
||||
damageable2.setDamage(554);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.NETHERITE_BOOTS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 120);
|
||||
if (damageable2.getDamage() > 370) {
|
||||
damageable2.setDamage(480);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.DIAMOND_HELMET) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 90);
|
||||
if (damageable2.getDamage() > 280) {
|
||||
damageable2.setDamage(362);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.DIAMOND_CHESTPLATE) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 132);
|
||||
if (damageable2.getDamage() > 410) {
|
||||
damageable2.setDamage(527);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.DIAMOND_LEGGINGS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 123);
|
||||
if (damageable2.getDamage() > 380) {
|
||||
damageable2.setDamage(494);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.DIAMOND_BOOTS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 107);
|
||||
if (damageable2.getDamage() > 330) {
|
||||
damageable2.setDamage(428);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.IRON_HELMET) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 41);
|
||||
if (damageable2.getDamage() > 125) {
|
||||
damageable2.setDamage(164);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.IRON_CHESTPLATE) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 60);
|
||||
if (damageable2.getDamage() > 190) {
|
||||
damageable2.setDamage(239);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.IRON_LEGGINGS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 56);
|
||||
if (damageable2.getDamage() > 180) {
|
||||
damageable2.setDamage(224);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.IRON_BOOTS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 48);
|
||||
if (damageable2.getDamage() > 150) {
|
||||
damageable2.setDamage(194);
|
||||
}
|
||||
}
|
||||
meta2 = (ItemMeta)damageable2;
|
||||
is2.setItemMeta(meta2);
|
||||
}
|
||||
}
|
||||
}
|
||||
Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + killed.getName());
|
||||
event.setKeepInventory(true);
|
||||
event.getDrops().clear();
|
||||
event.setKeepLevel(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.36
|
||||
//
|
||||
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyUniverse;
|
||||
import java.util.ArrayList;
|
||||
import org.bukkit.Bukkit;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Main extends JavaPlugin
|
||||
{
|
||||
public static WarData data;
|
||||
public static SiegeData data2;
|
||||
public static Main instance;
|
||||
public static Economy econ;
|
||||
|
||||
static {
|
||||
Main.instance = null;
|
||||
Main.econ = null;
|
||||
}
|
||||
|
||||
private static void initData() {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask((Plugin)getInstance(), (Runnable)new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final Set<String> warsSet = (Set<String>)Main.data.getConfig().getConfigurationSection("Wars").getKeys(false);
|
||||
final Iterator<String> it = warsSet.iterator();
|
||||
final ArrayList<String> warsTempList = new ArrayList<String>();
|
||||
while (it.hasNext()) {
|
||||
warsTempList.add(it.next().toLowerCase());
|
||||
}
|
||||
for (int i = 0; i < warsTempList.size(); ++i) {
|
||||
final War war = new War(warsTempList.get(i).toLowerCase(), Main.data.getConfig().getString("Wars." + warsTempList.get(i) + ".side1"), Main.data.getConfig().getString("Wars." + warsTempList.get(i) + ".side2"));
|
||||
ArrayList<String> side1Players = new ArrayList<String>();
|
||||
ArrayList<String> side2Players = new ArrayList<String>();
|
||||
side1Players = (ArrayList<String>)Main.data.getConfig().getList("Wars." + war.getName() + ".side1players");
|
||||
side2Players = (ArrayList<String>)Main.data.getConfig().getList("Wars." + war.getName() + ".side2players");
|
||||
war.setSide1Players(side1Players);
|
||||
war.setSide2Players(side2Players);
|
||||
WarCommands.wars.add(war);
|
||||
for (final String playerName : war.getSide1Players()) {
|
||||
try {
|
||||
Bukkit.getServer().getPlayer(playerName).setPlayerListName(String.valueOf(Helper.color(new StringBuilder("&c[").append(war.getSide1()).append("]&r").toString())) + playerName);
|
||||
}
|
||||
catch (NullPointerException ex) {}
|
||||
}
|
||||
for (final String playerName : war.getSide2Players()) {
|
||||
try {
|
||||
Bukkit.getServer().getPlayer(playerName).setPlayerListName(String.valueOf(Helper.color(new StringBuilder("&9[").append(war.getSide2()).append("]&r").toString())) + playerName);
|
||||
}
|
||||
catch (NullPointerException ex2) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (NullPointerException e) {
|
||||
Bukkit.getLogger().info("NULL when initializing wars");
|
||||
}
|
||||
try {
|
||||
final Set<String> siegeSet = (Set<String>)Main.data2.getConfig().getConfigurationSection("Sieges").getKeys(false);
|
||||
final Iterator<String> it2 = siegeSet.iterator();
|
||||
final ArrayList<String> siegesTempList = new ArrayList<String>();
|
||||
while (it2.hasNext()) {
|
||||
siegesTempList.add(it2.next());
|
||||
}
|
||||
for (int i = 0; i < siegesTempList.size(); ++i) {
|
||||
War siegeWar = null;
|
||||
Town siegeTown = null;
|
||||
for (final War war2 : WarCommands.wars) {
|
||||
if (Main.data2.getConfig().getString("Sieges." + siegesTempList.get(i) + ".war").equalsIgnoreCase(war2.getName())) {
|
||||
siegeWar = war2;
|
||||
}
|
||||
}
|
||||
final List<Town> townList = (List<Town>)TownyUniverse.getInstance().getDataSource().getTowns();
|
||||
for (final Town town : townList) {
|
||||
if (town.getName().equalsIgnoreCase(Main.data2.getConfig().getString("Sieges." + siegesTempList.get(i) + ".town"))) {
|
||||
siegeTown = town;
|
||||
}
|
||||
}
|
||||
final Siege siege = new Siege(Integer.parseInt(siegesTempList.get(i)), siegeWar, siegeTown, Main.data2.getConfig().getString("Sieges." + siegesTempList.get(i) + ".attackers"), Main.data2.getConfig().getString("Sieges." + siegesTempList.get(i) + ".defenders"), Main.data2.getConfig().getBoolean("Sieges." + siegesTempList.get(i) + ".siege1areattackers"), Main.data2.getConfig().getBoolean("Sieges." + siegesTempList.get(i) + ".siege2areattackers"));
|
||||
SiegeCommands.sieges.add(siege);
|
||||
siege.start();
|
||||
siege.resetBeacon(Bukkit.getWorld(Main.data2.getConfig().getString("Sieges." + siegesTempList.get(i) + ".world")), Main.data2.getConfig().getInt("Sieges." + siegesTempList.get(i) + ".homeblockx"), Main.data2.getConfig().getInt("Sieges." + siegesTempList.get(i) + ".homeblocky"), Main.data2.getConfig().getInt("Sieges." + siegesTempList.get(i) + ".homeblockz"));
|
||||
}
|
||||
}
|
||||
catch (NullPointerException e) {
|
||||
Bukkit.getLogger().info("NULL when initializing sieges");
|
||||
}
|
||||
}
|
||||
}, 0L);
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
if (this.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return false;
|
||||
}
|
||||
final RegisteredServiceProvider<Economy> rsp = (RegisteredServiceProvider<Economy>)this.getServer().getServicesManager().getRegistration((Class)Economy.class);
|
||||
if (rsp == null) {
|
||||
return false;
|
||||
}
|
||||
Main.econ = (Economy)rsp.getProvider();
|
||||
return Main.econ != null;
|
||||
}
|
||||
|
||||
public static Main getInstance() {
|
||||
return Main.instance;
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
Main.instance = this;
|
||||
Main.data = new WarData(this);
|
||||
Main.data2 = new SiegeData(this);
|
||||
new WarCommands(this);
|
||||
new SiegeCommands(this);
|
||||
this.getCommand("war").setTabCompleter(new WarTabCompletion());
|
||||
this.getCommand("siege").setTabCompleter(new SiegeTabCompletion());
|
||||
this.getServer().getPluginManager().registerEvents((Listener)new KillsListener(), (Plugin)this);
|
||||
this.getServer().getPluginManager().registerEvents((Listener)new JoinListener(), (Plugin)this);
|
||||
this.getServer().getPluginManager().registerEvents((Listener)new BlockBreakListener(), (Plugin)this);
|
||||
initData();
|
||||
this.setupEconomy();
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,448 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.36
|
||||
//
|
||||
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.TownyUniverse;
|
||||
import com.gmail.goosius.siegewar.TownOccupationController;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import java.util.Iterator;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import org.bukkit.entity.Entity;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import java.util.ArrayList;
|
||||
import org.bukkit.entity.Player;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.TownBlock;
|
||||
|
||||
public class Siege
|
||||
{
|
||||
private War war;
|
||||
private Town town;
|
||||
private String attackers;
|
||||
private String defenders;
|
||||
private boolean side1AreAttackers;
|
||||
private boolean side2AreAttackers;
|
||||
private int id;
|
||||
private int attackerPoints;
|
||||
private int defenderPoints;
|
||||
private int MAXSIEGETICKS;
|
||||
private Player owner;
|
||||
private int siegeTicks;
|
||||
private TownBlock homeBlock;
|
||||
private Location townSpawn;
|
||||
int[] bukkitId;
|
||||
public ArrayList<String> attackerPlayers;
|
||||
public ArrayList<String> defenderPlayers;
|
||||
public ArrayList<Location> beaconLocs;
|
||||
|
||||
public Siege(final int id, final War war, final Town town, final String attackers, final String defenders, final boolean side1AreAttackers, final boolean side2AreAttackers) {
|
||||
this.siegeTicks = 0;
|
||||
this.bukkitId = new int[1];
|
||||
this.attackerPlayers = new ArrayList<String>();
|
||||
this.defenderPlayers = new ArrayList<String>();
|
||||
this.beaconLocs = new ArrayList<Location>();
|
||||
this.war = war;
|
||||
this.town = town;
|
||||
this.attackers = attackers;
|
||||
this.defenders = defenders;
|
||||
this.side1AreAttackers = side1AreAttackers;
|
||||
this.side2AreAttackers = side2AreAttackers;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
this.attackerPoints = Main.data2.getConfig().getInt("Sieges." + String.valueOf(this.id) + ".attackerpoints");
|
||||
this.defenderPoints = Main.data2.getConfig().getInt("Sieges." + String.valueOf(this.id) + ".defenderpoints");
|
||||
this.side1AreAttackers = Main.data2.getConfig().getBoolean("Sieges." + String.valueOf(this.id) + ".side1areattackers");
|
||||
this.side2AreAttackers = Main.data2.getConfig().getBoolean("Sieges." + String.valueOf(this.id) + ".side2areattackers");
|
||||
this.MAXSIEGETICKS = 108000;
|
||||
this.siegeTicks = Main.data2.getConfig().getInt("Sieges." + String.valueOf(this.id) + ".siegeticks");
|
||||
this.owner = Bukkit.getPlayer(Main.data2.getConfig().getString("Sieges." + String.valueOf(this.id) + ".owner"));
|
||||
if (this.side1AreAttackers) {
|
||||
this.attackerPlayers = this.war.getSide1Players();
|
||||
this.defenderPlayers = this.war.getSide2Players();
|
||||
}
|
||||
else {
|
||||
this.attackerPlayers = this.war.getSide2Players();
|
||||
this.defenderPlayers = this.war.getSide1Players();
|
||||
}
|
||||
try {
|
||||
homeBlock = town.getHomeBlock();
|
||||
townSpawn = town.getSpawn();
|
||||
} catch (TownyException e) {
|
||||
}
|
||||
|
||||
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin)Main.getInstance(), (Runnable)new Runnable() {
|
||||
int homeBlockControl = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (homeBlock != null) {
|
||||
town.setHomeBlock(homeBlock);
|
||||
town.setSpawn(townSpawn);
|
||||
}
|
||||
if (Siege.this.side1AreAttackers) {
|
||||
Siege.this.attackerPlayers = Siege.this.war.getSide1Players();
|
||||
Siege.this.defenderPlayers = Siege.this.war.getSide2Players();
|
||||
}
|
||||
else {
|
||||
Siege.this.attackerPlayers = Siege.this.war.getSide2Players();
|
||||
Siege.this.defenderPlayers = Siege.this.war.getSide1Players();
|
||||
}
|
||||
if (Siege.this.siegeTicks >= Siege.this.MAXSIEGETICKS) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(Siege.this.bukkitId[0]);
|
||||
if (Siege.this.attackerPoints > Siege.this.defenderPoints) {
|
||||
Siege.this.attackersWin(Siege.this.owner);
|
||||
}
|
||||
else {
|
||||
Siege.this.defendersWin();
|
||||
}
|
||||
}
|
||||
else {
|
||||
boolean attackersAreOnHomeBlock = false;
|
||||
boolean defendersAreOnHomeBlock = false;
|
||||
final Siege this$0 = Siege.this;
|
||||
Siege.access$7(this$0, this$0.siegeTicks + 200);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(Siege.this.id) + ".siegeticks", (Object)Siege.this.siegeTicks);
|
||||
Main.data2.saveConfig();
|
||||
for (final String playerName : Siege.this.attackerPlayers) {
|
||||
try {
|
||||
if (WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName)).getTownBlock().isHomeBlock() && WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName)).getTownBlock().getTown().equals(town) && !Bukkit.getPlayer(playerName).isDead()) {
|
||||
attackersAreOnHomeBlock = true;
|
||||
}
|
||||
}
|
||||
catch (NotRegisteredException ex) {}
|
||||
catch (NullPointerException ex2) {}
|
||||
}
|
||||
for (final String playerName : Siege.this.defenderPlayers) {
|
||||
try {
|
||||
if (WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName)).getTownBlock().isHomeBlock() && WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName)).getTownBlock().getTown().equals(town) && !Bukkit.getPlayer(playerName).isDead()) {
|
||||
defendersAreOnHomeBlock = true;
|
||||
}
|
||||
}
|
||||
catch (NotRegisteredException ex3) {}
|
||||
catch (NullPointerException ex4) {}
|
||||
}
|
||||
if (attackersAreOnHomeBlock && defendersAreOnHomeBlock) {
|
||||
if (this.homeBlockControl != 1) {
|
||||
for (final String playerName : Siege.this.attackerPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "HomeBlock at " + Siege.this.town.getName() + " contested!");
|
||||
}
|
||||
catch (NullPointerException ex5) {}
|
||||
}
|
||||
for (final String playerName : Siege.this.defenderPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "HomeBlock at " + Siege.this.town.getName() + " contested!");
|
||||
}
|
||||
catch (NullPointerException ex6) {}
|
||||
}
|
||||
}
|
||||
this.homeBlockControl = 1;
|
||||
}
|
||||
else if (attackersAreOnHomeBlock && !defendersAreOnHomeBlock) {
|
||||
if (this.homeBlockControl != 2) {
|
||||
for (final String playerName : Siege.this.attackerPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Attackers have captured the HomeBlock at " + Siege.this.town.getName() + "! +1 Attacker Points per second");
|
||||
}
|
||||
catch (NullPointerException ex7) {}
|
||||
}
|
||||
for (final String playerName : Siege.this.defenderPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Attackers have captured the HomeBlock at " + Siege.this.town.getName() + "! +1 Attacker Points per second");
|
||||
}
|
||||
catch (NullPointerException ex8) {}
|
||||
}
|
||||
}
|
||||
this.homeBlockControl = 2;
|
||||
Siege.this.addPointsToAttackers(10);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(Siege.this.id) + ".attackerpoints", (Object)Siege.this.attackerPoints);
|
||||
Main.data2.saveConfig();
|
||||
}
|
||||
else {
|
||||
if (this.homeBlockControl != 3) {
|
||||
for (final String playerName : Siege.this.attackerPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defenders retain control of the HomeBlock at " + Siege.this.town.getName() + "! +1 Defender Points per second");
|
||||
}
|
||||
catch (NullPointerException ex9) {}
|
||||
}
|
||||
for (final String playerName : Siege.this.defenderPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defenders retain control of the HomeBlock at " + Siege.this.town.getName() + "! +1 Defender Points per second");
|
||||
}
|
||||
catch (NullPointerException ex10) {}
|
||||
}
|
||||
}
|
||||
Siege.this.addPointsToDefenders(10);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(Siege.this.id) + ".defenderpoints", (Object)Siege.this.defenderPoints);
|
||||
Main.data2.saveConfig();
|
||||
this.homeBlockControl = 3;
|
||||
}
|
||||
if (Siege.this.siegeTicks % 6000 == 0) {
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "Report on the siege of " + Siege.this.town.getName() + ":");
|
||||
Bukkit.broadcastMessage("Attacker Points - " + String.valueOf(Siege.this.attackerPoints));
|
||||
Bukkit.broadcastMessage("Defender Points - " + String.valueOf(Siege.this.defenderPoints));
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 0L, 200L);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
Bukkit.getScheduler().cancelTask(this.bukkitId[0]);
|
||||
SiegeCommands.sieges.remove(this);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(this.id), (Object)null);
|
||||
Main.data2.saveConfig();
|
||||
}
|
||||
|
||||
public void attackersWin(final Player owner) {
|
||||
final Resident resident = TownyAPI.getInstance().getResident(owner);
|
||||
Nation nation = null;
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The attackers from " + this.attackers + " have won the siege of " + this.town.getName() + "!");
|
||||
try {
|
||||
nation = resident.getTown().getNation();
|
||||
}
|
||||
catch (NotRegisteredException e) {
|
||||
for (final String playerName : this.attackerPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName() + " could not be occupied because the player who started the siege is not part of a nation");
|
||||
}
|
||||
catch (NullPointerException ex) {}
|
||||
}
|
||||
for (final String playerName : this.defenderPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName() + " could not be occupied because the player who started the siege is not part of a nation");
|
||||
}
|
||||
catch (NullPointerException ex2) {}
|
||||
}
|
||||
}
|
||||
if (nation != null) {
|
||||
TownOccupationController.setTownOccupation(this.town, nation);
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName() + " has been placed under occupation by " + nation.getName() + "!");
|
||||
}
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(owner.getName());
|
||||
Main.econ.depositPlayer(offlinePlayer, 20000.0);
|
||||
double amt = 0.0;
|
||||
if (this.town.getAccount().getHoldingBalance() > 80000.0) {
|
||||
amt = Math.floor(this.town.getAccount().getHoldingBalance()) / 4.0;
|
||||
this.town.getAccount().withdraw(amt, "war loot");
|
||||
}
|
||||
else {
|
||||
if (this.town.getAccount().getHoldingBalance() < 20000.0) {
|
||||
amt = this.town.getAccount().getHoldingBalance();
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName() + " has been destroyed by " + this.getAttackers() + "!");
|
||||
TownyUniverse.getInstance().getDataSource().deleteTown(this.town);
|
||||
Main.econ.depositPlayer(offlinePlayer, amt);
|
||||
return;
|
||||
}
|
||||
this.town.getAccount().withdraw(20000.0, "war loot");
|
||||
amt = 20000.0;
|
||||
}
|
||||
Bukkit.broadcastMessage("The town of " + this.town.getName() + " has been sacked by " + this.getAttackers() + ", valuing $" + String.valueOf(amt));
|
||||
Main.econ.depositPlayer(offlinePlayer, amt);
|
||||
|
||||
stop();
|
||||
clearBeacon();
|
||||
}
|
||||
|
||||
public void defendersWin() {
|
||||
this.town.getAccount().deposit(20000.0, "War chest");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The defenders from " + this.defenders + " have won the siege of " + this.town.getName() + "!");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + this.town.getName() + " has recovered the attackers' war chest, valued at $20,000");
|
||||
|
||||
stop();
|
||||
clearBeacon();
|
||||
}
|
||||
|
||||
public void createBeacon() {
|
||||
try {
|
||||
World world = town.getWorld();
|
||||
int homeBlockX = this.town.getHomeBlock().getX() * 16;
|
||||
int homeBlockZ = this.town.getHomeBlock().getZ() * 16;
|
||||
if (homeBlockX > 0) {
|
||||
homeBlockX -= 8;
|
||||
}
|
||||
if (homeBlockZ > 0) {
|
||||
homeBlockZ -= 8;
|
||||
}
|
||||
if (homeBlockX < 0) {
|
||||
homeBlockX += 8;
|
||||
}
|
||||
if (homeBlockZ < 0) {
|
||||
homeBlockZ += 8;
|
||||
}
|
||||
int homeBlockY = 253;
|
||||
final Location beaconLoc = new Location(this.town.getWorld(), (double)homeBlockX, (double)(homeBlockY - 2), (double)homeBlockZ);
|
||||
while (beaconLoc.getBlock().getType().equals((Object)Material.AIR)) {
|
||||
--homeBlockY;
|
||||
beaconLoc.setY((double)homeBlockY);
|
||||
}
|
||||
homeBlockY += 2;
|
||||
this.beaconLocs.add(new Location(world, (double)homeBlockX, (double)homeBlockY, (double)homeBlockZ));
|
||||
this.beaconLocs.add(new Location(world, (double)homeBlockX, (double)(homeBlockY + 1), (double)homeBlockZ));
|
||||
this.beaconLocs.add(new Location(world, (double)homeBlockX, (double)(homeBlockY - 1), (double)homeBlockZ));
|
||||
this.beaconLocs.add(new Location(world, (double)(homeBlockX + 1), (double)(homeBlockY - 1), (double)homeBlockZ));
|
||||
this.beaconLocs.add(new Location(world, (double)(homeBlockX - 1), (double)(homeBlockY - 1), (double)homeBlockZ));
|
||||
this.beaconLocs.add(new Location(world, (double)homeBlockX, (double)(homeBlockY - 1), (double)(homeBlockZ + 1)));
|
||||
this.beaconLocs.add(new Location(world, (double)homeBlockX, (double)(homeBlockY - 1), (double)(homeBlockZ - 1)));
|
||||
this.beaconLocs.add(new Location(world, (double)(homeBlockX + 1), (double)(homeBlockY - 1), (double)(homeBlockZ + 1)));
|
||||
this.beaconLocs.add(new Location(world, (double)(homeBlockX + 1), (double)(homeBlockY - 1), (double)(homeBlockZ - 1)));
|
||||
this.beaconLocs.add(new Location(world, (double)(homeBlockX - 1), (double)(homeBlockY - 1), (double)(homeBlockZ + 1)));
|
||||
this.beaconLocs.add(new Location(world, (double)(homeBlockX - 1), (double)(homeBlockY - 1), (double)(homeBlockZ - 1)));
|
||||
for (int i = 2; i < this.beaconLocs.size(); ++i) {
|
||||
if (this.beaconLocs.get(i).getBlock().getType() != Material.AIR) {
|
||||
i = 1;
|
||||
homeBlockY++;
|
||||
for (final Location loc : this.beaconLocs) {
|
||||
loc.setY(loc.getY() + 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.beaconLocs.get(0).getBlock().setType(Material.BEACON);
|
||||
this.beaconLocs.get(1).getBlock().setType(Material.RED_STAINED_GLASS);
|
||||
for (int i = 2; i < this.beaconLocs.size(); ++i) {
|
||||
this.beaconLocs.get(i).getBlock().setType(Material.IRON_BLOCK);
|
||||
}
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(this.id) + ".world", world.getName());
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(this.id) + ".homeblockx", homeBlockX);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(this.id) + ".homeblocky", homeBlockY);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(this.id) + ".homeblockz", homeBlockZ);
|
||||
Main.data2.saveConfig();
|
||||
}
|
||||
catch (TownyException ex) {}
|
||||
}
|
||||
|
||||
public void resetBeacon(World world, int homeBlockX, int homeBlockY, int homeBlockZ) {
|
||||
this.beaconLocs.add(new Location(world, (double)homeBlockX, (double)homeBlockY, (double)homeBlockZ));
|
||||
this.beaconLocs.add(new Location(world, (double)homeBlockX, (double)(homeBlockY + 1), (double)homeBlockZ));
|
||||
this.beaconLocs.add(new Location(world, (double)homeBlockX, (double)(homeBlockY - 1), (double)homeBlockZ));
|
||||
this.beaconLocs.add(new Location(world, (double)(homeBlockX + 1), (double)(homeBlockY - 1), (double)homeBlockZ));
|
||||
this.beaconLocs.add(new Location(world, (double)(homeBlockX - 1), (double)(homeBlockY - 1), (double)homeBlockZ));
|
||||
this.beaconLocs.add(new Location(world, (double)homeBlockX, (double)(homeBlockY - 1), (double)(homeBlockZ + 1)));
|
||||
this.beaconLocs.add(new Location(world, (double)homeBlockX, (double)(homeBlockY - 1), (double)(homeBlockZ - 1)));
|
||||
this.beaconLocs.add(new Location(world, (double)(homeBlockX + 1), (double)(homeBlockY - 1), (double)(homeBlockZ + 1)));
|
||||
this.beaconLocs.add(new Location(world, (double)(homeBlockX + 1), (double)(homeBlockY - 1), (double)(homeBlockZ - 1)));
|
||||
this.beaconLocs.add(new Location(world, (double)(homeBlockX - 1), (double)(homeBlockY - 1), (double)(homeBlockZ + 1)));
|
||||
this.beaconLocs.add(new Location(world, (double)(homeBlockX - 1), (double)(homeBlockY - 1), (double)(homeBlockZ - 1)));
|
||||
}
|
||||
|
||||
public void clearBeacon() {
|
||||
for (final Location loc : this.beaconLocs) {
|
||||
loc.getBlock().setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
public void addPointsToAttackers(final int points) {
|
||||
this.attackerPoints += points;
|
||||
}
|
||||
|
||||
public void addPointsToDefenders(final int points) {
|
||||
this.defenderPoints += points;
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setID(final int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public War getWar() {
|
||||
return this.war;
|
||||
}
|
||||
|
||||
public void setWar(final War war) {
|
||||
this.war = war;
|
||||
}
|
||||
|
||||
public Town getTown() {
|
||||
return this.town;
|
||||
}
|
||||
|
||||
public void setTown(final Town town) {
|
||||
this.town = town;
|
||||
}
|
||||
|
||||
public String getAttackers() {
|
||||
return this.attackers;
|
||||
}
|
||||
|
||||
public void setAttackers(final String attackers) {
|
||||
this.attackers = attackers;
|
||||
}
|
||||
|
||||
public String getDefenders() {
|
||||
return this.defenders;
|
||||
}
|
||||
|
||||
public void setDefenders(final String defenders) {
|
||||
this.attackers = defenders;
|
||||
}
|
||||
|
||||
public int getAttackerPoints() {
|
||||
return this.attackerPoints;
|
||||
}
|
||||
|
||||
public void attackerPoints(final int attackerPoints) {
|
||||
this.attackerPoints = attackerPoints;
|
||||
}
|
||||
|
||||
public int getDefenderPoints() {
|
||||
return this.defenderPoints;
|
||||
}
|
||||
|
||||
public void defenderPoints(final int defenderPoints) {
|
||||
this.defenderPoints = this.attackerPoints;
|
||||
}
|
||||
|
||||
public boolean getSide1AreAttackers() {
|
||||
return this.side1AreAttackers;
|
||||
}
|
||||
|
||||
public void setSide1AreAttackers(final boolean side1AreAttackers) {
|
||||
this.side1AreAttackers = side1AreAttackers;
|
||||
}
|
||||
|
||||
public boolean getSide2AreAttackers() {
|
||||
return this.side2AreAttackers;
|
||||
}
|
||||
|
||||
public void setSide2AreAttackers(final boolean side2AreAttackers) {
|
||||
this.side2AreAttackers = side2AreAttackers;
|
||||
}
|
||||
|
||||
public ArrayList<String> getAttackerPlayers() {
|
||||
return this.attackerPlayers;
|
||||
}
|
||||
|
||||
public void setAttackerPlayer(final ArrayList<String> attackerPlayers) {
|
||||
this.attackerPlayers = attackerPlayers;
|
||||
}
|
||||
|
||||
public ArrayList<String> getDefenderPlayers() {
|
||||
return this.defenderPlayers;
|
||||
}
|
||||
|
||||
public void setDefenderPlayer(final ArrayList<String> defenderPlayers) {
|
||||
this.defenderPlayers = this.attackerPlayers;
|
||||
}
|
||||
|
||||
static /* synthetic */ void access$7(final Siege siege, final int siegeTicks) {
|
||||
siege.siegeTicks = siegeTicks;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.36
|
||||
//
|
||||
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import com.palmergames.bukkit.towny.object.TownyWorld;
|
||||
import java.util.Iterator;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import java.util.ArrayList;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
|
||||
public class SiegeCommands implements CommandExecutor
|
||||
{
|
||||
public static ArrayList<Town> towns;
|
||||
public static ArrayList<Siege> sieges;
|
||||
public static int maxID;
|
||||
|
||||
static {
|
||||
SiegeCommands.towns = new ArrayList<Town>();
|
||||
SiegeCommands.sieges = new ArrayList<Siege>();
|
||||
SiegeCommands.maxID = Main.data2.getConfig().getInt("MaxID");
|
||||
}
|
||||
|
||||
public SiegeCommands(final Main plugin) {
|
||||
plugin.getCommand("siege").setExecutor((CommandExecutor)this);
|
||||
}
|
||||
|
||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
|
||||
final Player p = (Player)sender;
|
||||
if (args.length == 0) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /siege help");
|
||||
}
|
||||
else if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("list")) {
|
||||
if (SiegeCommands.sieges.isEmpty()) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "There are currently no sieges in progress");
|
||||
return false;
|
||||
}
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Sieges currently in progress:");
|
||||
for (final Siege siege : SiegeCommands.sieges) {
|
||||
p.sendMessage("ID: " + String.valueOf(siege.getID()));
|
||||
p.sendMessage("War: " + siege.getWar().getName());
|
||||
p.sendMessage("Town: " + siege.getTown().getName());
|
||||
p.sendMessage("Attackers: " + siege.getAttackers());
|
||||
p.sendMessage("Defenders: " + siege.getDefenders());
|
||||
p.sendMessage("Attacker Points: " + String.valueOf(siege.getAttackerPoints()));
|
||||
p.sendMessage("Defender Points: " + String.valueOf(siege.getDefenderPoints()));
|
||||
p.sendMessage("Time Left: " + String.valueOf((108000 - Main.data2.getConfig().getInt("Sieges." + String.valueOf(String.valueOf(siege.getID()) + ".siegeticks"))) / 1200) + " minutes");
|
||||
p.sendMessage("-=-=-=-=-=-=-=-=-=-=-=-");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("help")) {
|
||||
if (p.hasPermission("!AlatrhaWar.admin")) {
|
||||
p.sendMessage(Helper.Chatlabel() + "/siege stop [id]");
|
||||
}
|
||||
p.sendMessage(Helper.Chatlabel() + "/siege start [war] [town]");
|
||||
p.sendMessage(Helper.Chatlabel() + "/siege abandon [id]");
|
||||
p.sendMessage(Helper.Chatlabel() + "/siege list");
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /siege help");
|
||||
}
|
||||
|
||||
}
|
||||
else if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("stop")) {
|
||||
if (!p.hasPermission("AlathraWar.admin")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou do not have permission to do this"));
|
||||
return false;
|
||||
}
|
||||
if (SiegeCommands.sieges.isEmpty()) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "There are currently no sieges in progress");
|
||||
return false;
|
||||
}
|
||||
boolean found = false;
|
||||
for (int i = 0; i < SiegeCommands.sieges.size(); ++i) {
|
||||
if (String.valueOf(SiegeCommands.sieges.get(i).getID()).equalsIgnoreCase(args[1])) {
|
||||
found = true;
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "siege cancelled");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The siege at " + SiegeCommands.sieges.get(i).getTown().getName() + " has been cancelled by an admin");
|
||||
SiegeCommands.sieges.get(i).clearBeacon();
|
||||
SiegeCommands.sieges.get(i).stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "A siege could not be found with this ID! Type /siege list to view current sieges");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("abandon")) {
|
||||
boolean found2 = false;
|
||||
if (Main.data2.getConfig().getString("Sieges." + args[1] + ".owner") == null) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Siege not found! Usage: /siege abandon [siege id]");
|
||||
return false;
|
||||
}
|
||||
final String configOwner = Main.data2.getConfig().getString("Sieges." + args[1] + ".owner");
|
||||
if (configOwner.equalsIgnoreCase(p.getName())) {
|
||||
for (int j = 0; j < SiegeCommands.sieges.size(); ++j) {
|
||||
if (String.valueOf(SiegeCommands.sieges.get(j).getID()).equalsIgnoreCase(args[1])) {
|
||||
found2 = true;
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The siege at " + SiegeCommands.sieges.get(j).getTown().getName() + " has been abandoned by " + SiegeCommands.sieges.get(j).getAttackers());
|
||||
SiegeCommands.sieges.get(j).defendersWin();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found2) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Only the player who started the siege can abandon it");
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /siege help");
|
||||
}
|
||||
}
|
||||
else if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("start")) {
|
||||
boolean warFound = false;
|
||||
boolean townExists = false;
|
||||
for (final War war : WarCommands.wars) {
|
||||
if (war.getName().equalsIgnoreCase(args[1])) {
|
||||
warFound = true;
|
||||
if (!war.getSide1Players().contains(p.getName()) && !war.getSide2Players().contains(p.getName())) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
}
|
||||
TownyWorld townyWorld;
|
||||
try {
|
||||
townyWorld = WorldCoord.parseWorldCoord(p.getLocation()).getTownyWorld();
|
||||
}
|
||||
catch (NotRegisteredException e) {
|
||||
Bukkit.getLogger().info("TownyWorld not found");
|
||||
return false;
|
||||
}
|
||||
if (!SiegeCommands.towns.isEmpty()) {
|
||||
SiegeCommands.towns.clear();
|
||||
}
|
||||
for (final String entry : townyWorld.getTowns().keySet()) {
|
||||
final Town town = townyWorld.getTowns().get(entry);
|
||||
SiegeCommands.towns.add(town);
|
||||
if (town.getName().equalsIgnoreCase(args[2])) {
|
||||
townExists = true;
|
||||
boolean attackingOwnSide = false;
|
||||
++SiegeCommands.maxID;
|
||||
Main.data2.getConfig().set("MaxID", (Object)SiegeCommands.maxID);
|
||||
Main.data2.saveConfig();
|
||||
Siege siege2;
|
||||
if (war.getSide1Players().contains(p.getName())) {
|
||||
siege2 = new Siege(SiegeCommands.maxID, war, town, war.getSide1(), war.getSide2(), true, false);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".war", (Object)war.getName());
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".town", (Object)town.getName());
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".attackers", (Object)war.getSide1());
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".defenders", (Object)war.getSide2());
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".side1areattackers", (Object)true);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".side2areattackers", (Object)false);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".siegeticks", (Object)0);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".attackerpoints", (Object)0);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".defenderpoints", (Object)0);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".owner", (Object)p.getName());
|
||||
Main.data2.saveConfig();
|
||||
}
|
||||
else {
|
||||
if (!war.getSide2Players().contains(p.getName())) {
|
||||
Bukkit.getLogger().info("Unable to find player declaring siege in the war");
|
||||
return false;
|
||||
}
|
||||
siege2 = new Siege(SiegeCommands.maxID, war, town, war.getSide2(), war.getSide1(), false, true);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".war", (Object)war.getName());
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".town", (Object)town.getName());
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".attackers", (Object)war.getSide2());
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".defenders", (Object)war.getSide1());
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".side1areattackers", (Object)false);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".side2areattackers", (Object)true);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".siegeticks", (Object)0);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".attackerpoints", (Object)0);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".defenderpoints", (Object)0);
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".owner", (Object)p.getName());
|
||||
Main.data2.saveConfig();
|
||||
}
|
||||
final ArrayList<String> residentNames = new ArrayList<String>();
|
||||
for (final Resident resident : town.getResidents()) {
|
||||
residentNames.add(resident.getName());
|
||||
}
|
||||
if (siege2.getSide1AreAttackers()) {
|
||||
for (final String playerName : war.getSide1Players()) {
|
||||
if (residentNames.contains(playerName)) {
|
||||
attackingOwnSide = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (final String playerName : war.getSide2Players()) {
|
||||
if (residentNames.contains(playerName)) {
|
||||
attackingOwnSide = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (attackingOwnSide) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot siege a town with members on your side of the war!");
|
||||
return false;
|
||||
}
|
||||
Town currentTown;
|
||||
try {
|
||||
currentTown = WorldCoord.parseWorldCoord(p.getLocation()).getTownBlock().getTown();
|
||||
}
|
||||
catch (NotRegisteredException e2) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must be within the town's claim to begin a siege");
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID), (Object)null);
|
||||
Main.data2.saveConfig();
|
||||
return false;
|
||||
}
|
||||
if (!currentTown.equals(town)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must be within the town's claim to begin a siege");
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID), (Object)null);
|
||||
Main.data2.saveConfig();
|
||||
return false;
|
||||
}
|
||||
for (final Siege siegeEntry : SiegeCommands.sieges) {
|
||||
if (siegeEntry.getTown().getName().equalsIgnoreCase(town.getName())) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already under siege by your side!");
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID), (Object)null);
|
||||
Main.data2.saveConfig();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(p.getName());
|
||||
if (Main.econ.getBalance(offlinePlayer) <= 20000.0) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must have at least $20,000 to put up to start a siege");
|
||||
Main.data2.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID), (Object)null);
|
||||
Main.data2.saveConfig();
|
||||
return false;
|
||||
}
|
||||
Main.econ.withdrawPlayer(offlinePlayer, 20000.0);
|
||||
SiegeCommands.sieges.add(siege2);
|
||||
siege2.start();
|
||||
siege2.createBeacon();
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "As part of " + war.getName() + ", forces from " + siege2.getAttackers() + " are laying siege to the town of " + town.getName() + "!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!warFound) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "That war does not exist! /siege start [war] [town]");
|
||||
return false;
|
||||
}
|
||||
if (!townExists) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town does not exist! /siege start [war] [town]");
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /siege help");
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /siege help");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.36
|
||||
//
|
||||
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import java.io.Reader;
|
||||
import java.io.InputStreamReader;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import java.io.File;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class SiegeData
|
||||
{
|
||||
private Main plugin;
|
||||
private FileConfiguration dataConfig;
|
||||
private File configFile;
|
||||
|
||||
public SiegeData(final Main plugin) {
|
||||
this.dataConfig = null;
|
||||
this.configFile = null;
|
||||
this.plugin = plugin;
|
||||
this.saveDefaultConfig();
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
if (this.configFile == null) {
|
||||
this.configFile = new File(this.plugin.getDataFolder(), "sieges.yml");
|
||||
}
|
||||
this.dataConfig = (FileConfiguration)YamlConfiguration.loadConfiguration(this.configFile);
|
||||
final InputStream defaultStream = this.plugin.getResource("sieges.yml");
|
||||
if (defaultStream != null) {
|
||||
final YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration((Reader)new InputStreamReader(defaultStream));
|
||||
this.dataConfig.setDefaults((Configuration)defaultConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
if (this.dataConfig == null) {
|
||||
this.reloadConfig();
|
||||
}
|
||||
return this.dataConfig;
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
if (this.dataConfig == null || this.configFile == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.getConfig().save(this.configFile);
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveDefaultConfig() {
|
||||
if (this.configFile == null) {
|
||||
this.configFile = new File(this.plugin.getDataFolder(), "sieges.yml");
|
||||
}
|
||||
if (!this.configFile.exists()) {
|
||||
this.plugin.saveResource("sieges.yml", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyUniverse;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
|
||||
public class SiegeTabCompletion implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
Player p = (Player)sender;
|
||||
if (args.length == 1) {
|
||||
if (p.hasPermission("AlathraWar.admin")) {
|
||||
completions.add("stop");
|
||||
}
|
||||
completions.add("start");
|
||||
completions.add("abandon");
|
||||
completions.add("list");
|
||||
completions.add("help");
|
||||
return completions;
|
||||
} else if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("start")) {
|
||||
if (!WarCommands.wars.isEmpty()) {
|
||||
for (War war : WarCommands.wars) {
|
||||
completions.add(war.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("stop") || args[0].equalsIgnoreCase("abandon")) {
|
||||
if (!SiegeCommands.sieges.isEmpty()) {
|
||||
for (Siege siege : SiegeCommands.sieges) {
|
||||
completions.add(String.valueOf(siege.getID()));
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
} else if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("start")) {
|
||||
if (!TownyUniverse.getInstance().getDataSource().getTowns().isEmpty()) {
|
||||
for (Town town : TownyUniverse.getInstance().getDataSource().getTowns()) {
|
||||
completions.add(town.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.36
|
||||
//
|
||||
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Title
|
||||
{
|
||||
public void sendPacket(final Player player, final Object packet) {
|
||||
try {
|
||||
final Object handle = player.getClass().getMethod("getHandle", (Class<?>[])new Class[0]).invoke(player, new Object[0]);
|
||||
final Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
|
||||
playerConnection.getClass().getMethod("sendPacket", this.getNMSClass("Packet")).invoke(playerConnection, packet);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Class<?> getNMSClass(final String name) {
|
||||
try {
|
||||
return Class.forName("net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] + "." + name);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void send(final Player player, final String title, final String subtitle, final int fadeInTime, final int showTime, final int fadeOutTime) {
|
||||
try {
|
||||
final Object chatTitle = this.getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", String.class).invoke(null, "{\"text\": \"" + title + "\"}");
|
||||
final Constructor<?> titleConstructor = this.getNMSClass("PacketPlayOutTitle").getConstructor(this.getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], this.getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE);
|
||||
final Object packet = titleConstructor.newInstance(this.getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TITLE").get(null), chatTitle, fadeInTime, showTime, fadeOutTime);
|
||||
final Object chatsTitle = this.getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", String.class).invoke(null, "{\"text\": \"" + subtitle + "\"}");
|
||||
final Constructor<?> timingTitleConstructor = this.getNMSClass("PacketPlayOutTitle").getConstructor(this.getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], this.getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE);
|
||||
final Object timingPacket = timingTitleConstructor.newInstance(this.getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("SUBTITLE").get(null), chatsTitle, fadeInTime, showTime, fadeOutTime);
|
||||
this.sendPacket(player, packet);
|
||||
this.sendPacket(player, timingPacket);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.36
|
||||
//
|
||||
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class War
|
||||
{
|
||||
private String name;
|
||||
private String side1;
|
||||
private String side2;
|
||||
private ArrayList<String> side1Players;
|
||||
private ArrayList<String> side2Players;
|
||||
|
||||
public War(final String name, final String side1, final String side2) {
|
||||
this.side1Players = new ArrayList<String>();
|
||||
this.side2Players = new ArrayList<String>();
|
||||
this.name = name;
|
||||
this.side1 = side1;
|
||||
this.side2 = side2;
|
||||
}
|
||||
|
||||
public void addPlayerSide1(final String playerName) {
|
||||
boolean duplicate = false;
|
||||
for (int i = 0; i < this.side1Players.size(); ++i) {
|
||||
if (playerName.equalsIgnoreCase(this.side1Players.get(i))) {
|
||||
duplicate = true;
|
||||
}
|
||||
}
|
||||
if (!duplicate) {
|
||||
this.side1Players.add(playerName);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayerSide1(final String playerName) {
|
||||
for (int i = 0; i < this.side1Players.size(); ++i) {
|
||||
if (playerName.equalsIgnoreCase(this.side1Players.get(i))) {
|
||||
this.side1Players.remove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayerSide2(final String playerName) {
|
||||
boolean duplicate = false;
|
||||
for (int i = 0; i < this.side2Players.size(); ++i) {
|
||||
if (playerName.equalsIgnoreCase(this.side2Players.get(i))) {
|
||||
duplicate = true;
|
||||
}
|
||||
}
|
||||
if (!duplicate) {
|
||||
this.side2Players.add(playerName);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayerSide2(final String playerName) {
|
||||
for (int i = 0; i < this.side2Players.size(); ++i) {
|
||||
if (playerName.equalsIgnoreCase(this.side2Players.get(i))) {
|
||||
this.side2Players.remove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSide1() {
|
||||
return this.side1;
|
||||
}
|
||||
|
||||
public void setSide1(final String side1) {
|
||||
this.side1 = side1;
|
||||
}
|
||||
|
||||
public String getSide2() {
|
||||
return this.side2;
|
||||
}
|
||||
|
||||
public void setSide2(final String side2) {
|
||||
this.side2 = this.side1;
|
||||
}
|
||||
|
||||
public ArrayList<String> getSide1Players() {
|
||||
return this.side1Players;
|
||||
}
|
||||
|
||||
public void setSide1Players(final ArrayList<String> side1Players) {
|
||||
this.side1Players = side1Players;
|
||||
}
|
||||
|
||||
public ArrayList<String> getSide2Players() {
|
||||
return this.side2Players;
|
||||
}
|
||||
|
||||
public void setSide2Players(final ArrayList<String> side2Players) {
|
||||
this.side2Players = side2Players;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.36
|
||||
//
|
||||
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import java.util.ArrayList;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
|
||||
public class WarCommands implements CommandExecutor
|
||||
{
|
||||
public static ArrayList<War> wars;
|
||||
|
||||
static {
|
||||
WarCommands.wars = new ArrayList<War>();
|
||||
}
|
||||
|
||||
public WarCommands(final Main plugin) {
|
||||
plugin.getCommand("war").setExecutor((CommandExecutor)this);
|
||||
}
|
||||
|
||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
|
||||
final Player p = (Player)sender;
|
||||
if (args.length == 0) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /war help");
|
||||
}
|
||||
else if (args.length >= 1) {
|
||||
if (args[0].equalsIgnoreCase("create")) {
|
||||
if (!p.hasPermission("AlatrhaWar.admin")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou do not have permission to do this"));
|
||||
return false;
|
||||
}
|
||||
if (args.length == 4) {
|
||||
if (WarCommands.wars.isEmpty()) {
|
||||
final War war = new War(args[1].toLowerCase(), args[2].toLowerCase(), args[3].toLowerCase());
|
||||
WarCommands.wars.add(war);
|
||||
final ArrayList<String> side1Players = new ArrayList<String>();
|
||||
final ArrayList<String> side2Players = new ArrayList<String>();
|
||||
side1Players.add("Notch1");
|
||||
side2Players.add("Notch2");
|
||||
war.setSide1Players(side1Players);
|
||||
war.setSide2Players(side2Players);
|
||||
Main.data.getConfig().set("Wars." + args[1].toLowerCase() + ".side1", (Object)args[2]);
|
||||
Main.data.getConfig().set("Wars." + args[1].toLowerCase() + ".side2", (Object)args[3]);
|
||||
Main.data.getConfig().set("Wars." + args[1].toLowerCase() + ".side1players", (Object)side1Players);
|
||||
Main.data.getConfig().set("Wars." + args[1].toLowerCase() + ".side2players", (Object)side2Players);
|
||||
Main.data.saveConfig();
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War created with the name " + args[1].toLowerCase() + ", " + args[2] + " vs. " + args[3]);
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < WarCommands.wars.size(); ++i) {
|
||||
if (WarCommands.wars.get(i).getName().equalsIgnoreCase(args[1])) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "A war already exists with that name! To view wars type /war list");
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
final War war2 = new War(args[1], args[2], args[3]);
|
||||
WarCommands.wars.add(war2);
|
||||
final ArrayList<String> side1Players2 = new ArrayList<String>();
|
||||
final ArrayList<String> side2Players2 = new ArrayList<String>();
|
||||
side1Players2.add("Notch1");
|
||||
side2Players2.add("Notch2");
|
||||
war2.setSide1Players(side1Players2);
|
||||
war2.setSide2Players(side2Players2);
|
||||
Main.data.getConfig().set("Wars." + args[1].toLowerCase() + ".side1", (Object)args[2]);
|
||||
Main.data.getConfig().set("Wars." + args[1].toLowerCase() + ".side2", (Object)args[3]);
|
||||
Main.data.getConfig().set("Wars." + args[1].toLowerCase() + ".side1players", (Object)side1Players2);
|
||||
Main.data.getConfig().set("Wars." + args[1].toLowerCase() + ".side2players", (Object)side2Players2);
|
||||
Main.data.saveConfig();
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War created with the name " + args[1] + ", " + args[2] + " vs. " + args[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /war create [name] [side1] [side2]");
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("delete")) {
|
||||
if (!p.hasPermission("AlatrhaWar.admin")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou do not have permission to do this"));
|
||||
return false;
|
||||
}
|
||||
if (args.length == 2) {
|
||||
boolean found = false;
|
||||
for (int j = 0; j < WarCommands.wars.size(); ++j) {
|
||||
if (WarCommands.wars.get(j).getName().equalsIgnoreCase(args[1])) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "The war named " + args[1] + " has been deleted");
|
||||
WarCommands.wars.remove(j);
|
||||
Main.data.getConfig().set("Wars." + args[1].toLowerCase(), (Object)null);
|
||||
Main.data.saveConfig();
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Could not find a war with that name! To view wars type /war list");
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /war delete [name]");
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("list")) {
|
||||
if (WarCommands.wars.isEmpty()) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "There are currently no wars");
|
||||
}
|
||||
else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Current Wars:");
|
||||
for (final War war : WarCommands.wars) {
|
||||
p.sendMessage(String.valueOf(war.getName()) + " - " + war.getSide1() + " vs. " + war.getSide2());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("join")) {
|
||||
boolean found = false;
|
||||
if (args.length == 3) {
|
||||
for (final War war2 : WarCommands.wars) {
|
||||
if (war2.getName().equalsIgnoreCase(args[1].toLowerCase())) {
|
||||
if (war2.getSide1().equalsIgnoreCase(args[2].toLowerCase())) {
|
||||
if (war2.getSide1Players().contains(p.getName())) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have already joined this war! Type /war leave [war] to leave the war");
|
||||
return false;
|
||||
}
|
||||
war2.addPlayerSide1(p.getName());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the war on the side of " + war2.getSide1());
|
||||
p.setPlayerListName(String.valueOf(Helper.color(new StringBuilder("&c[").append(war2.getSide1()).append("]&r").toString())) + p.getName());
|
||||
Main.data.getConfig().set("Wars." + args[1].toLowerCase() + ".side1players", (Object)war2.getSide1Players());
|
||||
Main.data.saveConfig();
|
||||
Bukkit.getServer().broadcastMessage(String.valueOf(Helper.Chatlabel()) + p.getName() + " has joined " + war2.getName() + " on the side of " + war2.getSide1() + "!");
|
||||
found = true;
|
||||
}
|
||||
else {
|
||||
if (!war2.getSide2().equalsIgnoreCase(args[2].toLowerCase())) {
|
||||
continue;
|
||||
}
|
||||
if (war2.getSide2Players().contains(p.getName())) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have already joined this war! Type /war leave [war] to leave the war");
|
||||
return false;
|
||||
}
|
||||
war2.addPlayerSide2(p.getName());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the war on the side of " + war2.getSide2());
|
||||
p.setPlayerListName(String.valueOf(Helper.color(new StringBuilder("&9[").append(war2.getSide2()).append("]&r").toString())) + p.getName());
|
||||
Main.data.getConfig().set("Wars." + args[1].toLowerCase() + ".side2players", (Object)war2.getSide2Players());
|
||||
Main.data.saveConfig();
|
||||
Bukkit.getServer().broadcastMessage(String.valueOf(Helper.Chatlabel()) + p.getName() + " has joined " + war2.getName() + " on the side of " + war2.getSide2() + "!");
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War not found. /war join [name] [side], type /war list to view current wars");
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /war join [name] [side]");
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("leave")) {
|
||||
if (args.length == 2) {
|
||||
boolean found = false;
|
||||
boolean found2 = false;
|
||||
for (final War war3 : WarCommands.wars) {
|
||||
if (war3.getName().equalsIgnoreCase(args[1])) {
|
||||
found = true;
|
||||
if (war3.getSide1Players().contains(p.getName())) {
|
||||
found2 = true;
|
||||
war3.removePlayerSide1(p.getName());
|
||||
Main.data.getConfig().set("Wars." + args[1] + ".side1players", (Object)war3.getSide1Players());
|
||||
Main.data.saveConfig();
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have left the war");
|
||||
p.setPlayerListName(p.getName());
|
||||
Bukkit.getServer().broadcastMessage(String.valueOf(Helper.Chatlabel()) + p.getName() + " has left " + war3.getName() + ", they were on the side of " + war3.getSide1());
|
||||
}
|
||||
if (!war3.getSide2Players().contains(p.getName())) {
|
||||
continue;
|
||||
}
|
||||
found2 = true;
|
||||
war3.removePlayerSide2(p.getName());
|
||||
Main.data.getConfig().set("Wars." + args[1] + ".side2players", (Object)war3.getSide2Players());
|
||||
Main.data.saveConfig();
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have left the war");
|
||||
p.setPlayerListName(p.getName());
|
||||
Bukkit.getServer().broadcastMessage(String.valueOf(Helper.Chatlabel()) + p.getName() + " has left " + war3.getName() + ", they were on the side of " + war3.getSide2());
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War not found. /war leave [name], type /war list to view current wars");
|
||||
return false;
|
||||
}
|
||||
if (!found2) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not part of this war!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /war leave [name]");
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("info")) {
|
||||
boolean found = false;
|
||||
if (args.length == 2) {
|
||||
for (final War war2 : WarCommands.wars) {
|
||||
if (war2.getSide1Players().contains(args[1])) {
|
||||
if (!found) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + args[1] + " is currently in the following wars");
|
||||
}
|
||||
found = true;
|
||||
p.sendMessage(String.valueOf(war2.getName()) + " - " + " Fighting for " + war2.getSide1());
|
||||
}
|
||||
else {
|
||||
if (!war2.getSide2Players().contains(args[1])) {
|
||||
continue;
|
||||
}
|
||||
if (!found) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + args[1] + " is currently in the following wars");
|
||||
}
|
||||
found = true;
|
||||
p.sendMessage(String.valueOf(war2.getName()) + " - " + " Fighting for " + war2.getSide2());
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This player is not currently in any wars");
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /war info [player]");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("help")) {
|
||||
|
||||
if (p.hasPermission("!AlatrhaWar.admin")) {
|
||||
p.sendMessage(Helper.Chatlabel() + "/war create [name] [side1] [side2]");
|
||||
p.sendMessage(Helper.Chatlabel() + "/war delete [name]");
|
||||
}
|
||||
p.sendMessage(Helper.Chatlabel() + "/war join [name] [side]");
|
||||
p.sendMessage(Helper.Chatlabel() + "/war leave [name]");
|
||||
p.sendMessage(Helper.Chatlabel() + "/war info [player]");
|
||||
p.sendMessage(Helper.Chatlabel() + "/war list");
|
||||
|
||||
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /war help");
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /war help");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.36
|
||||
//
|
||||
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import java.io.Reader;
|
||||
import java.io.InputStreamReader;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import java.io.File;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class WarData
|
||||
{
|
||||
private Main plugin;
|
||||
private FileConfiguration dataConfig;
|
||||
private File configFile;
|
||||
|
||||
public WarData(final Main plugin) {
|
||||
this.dataConfig = null;
|
||||
this.configFile = null;
|
||||
this.plugin = plugin;
|
||||
this.saveDefaultConfig();
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
if (this.configFile == null) {
|
||||
this.configFile = new File(this.plugin.getDataFolder(), "wars.yml");
|
||||
}
|
||||
this.dataConfig = (FileConfiguration)YamlConfiguration.loadConfiguration(this.configFile);
|
||||
final InputStream defaultStream = this.plugin.getResource("wars.yml");
|
||||
if (defaultStream != null) {
|
||||
final YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration((Reader)new InputStreamReader(defaultStream));
|
||||
this.dataConfig.setDefaults((Configuration)defaultConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
if (this.dataConfig == null) {
|
||||
this.reloadConfig();
|
||||
}
|
||||
return this.dataConfig;
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
if (this.dataConfig == null || this.configFile == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.getConfig().save(this.configFile);
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveDefaultConfig() {
|
||||
if (this.configFile == null) {
|
||||
this.configFile = new File(this.plugin.getDataFolder(), "wars.yml");
|
||||
}
|
||||
if (!this.configFile.exists()) {
|
||||
this.plugin.saveResource("wars.yml", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class WarTabCompletion implements TabCompleter{
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
Player p = (Player)sender;
|
||||
if (args.length == 1) {
|
||||
if (p.hasPermission("AlathraWar.admin")) {
|
||||
completions.add("create");
|
||||
completions.add("delete");
|
||||
}
|
||||
completions.add("join");
|
||||
completions.add("leave");
|
||||
completions.add("info");
|
||||
completions.add("list");
|
||||
completions.add("help");
|
||||
return completions;
|
||||
} else if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("join") || args[0].equalsIgnoreCase("leave")) {
|
||||
if (!WarCommands.wars.isEmpty()) {
|
||||
for (War war : WarCommands.wars) {
|
||||
completions.add(war.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("info")) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
completions.add(player.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
} else if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("join")) {
|
||||
if (!WarCommands.wars.isEmpty()) {
|
||||
for (War war : WarCommands.wars) {
|
||||
if (war.getName().equalsIgnoreCase(args[1])) {
|
||||
completions.add(war.getSide1());
|
||||
completions.add(war.getSide2());
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Wars:
|
||||
Reference in new issue
Block a user