mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 14:38:55 +00:00
Refactoring into root
AlathraWar2 is unrequired
This commit is contained in:
1 parent
a43b794d1c
commit
110f8d7791
28 files changed
+377
-382
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
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 ");
|
||||
}
|
||||
|
||||
public static void testMsg() {
|
||||
Bukkit.broadcastMessage("test message");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
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 me.ShermansWorld.AlathraWar.commands.SiegeCommands;
|
||||
import me.ShermansWorld.AlathraWar.commands.SiegeTabCompletion;
|
||||
import me.ShermansWorld.AlathraWar.commands.WarCommands;
|
||||
import me.ShermansWorld.AlathraWar.commands.WarTabCompletion;
|
||||
import me.ShermansWorld.AlathraWar.data.RolesData;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
import me.ShermansWorld.AlathraWar.hooks.TABHook;
|
||||
import me.ShermansWorld.AlathraWar.listeners.BlockBreakListener;
|
||||
import me.ShermansWorld.AlathraWar.listeners.JoinListener;
|
||||
import me.ShermansWorld.AlathraWar.listeners.KillsListener;
|
||||
import me.ShermansWorld.AlathraWar.roles.AssassinCommand;
|
||||
import me.ShermansWorld.AlathraWar.roles.ContractCommand;
|
||||
import me.ShermansWorld.AlathraWar.roles.MercCommand;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
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 warData;
|
||||
public static SiegeData siegeData;
|
||||
public static RolesData rolesData;
|
||||
public static Main instance;
|
||||
public static Economy econ;
|
||||
public static AlathraWarLogger warLogger;
|
||||
|
||||
static {
|
||||
instance = null;
|
||||
econ = null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void initData() {
|
||||
File userDataFolder = new File("plugins" + File.separator + "AlathraWar" + File.separator + "userdata");
|
||||
if (!userDataFolder.exists()) {
|
||||
userDataFolder.mkdirs();
|
||||
}
|
||||
rolesData = new RolesData();
|
||||
try {
|
||||
Set<String> warsSet = (Set<String>) warData.getConfig().getConfigurationSection("Wars").getKeys(false);
|
||||
Iterator<String> it = warsSet.iterator();
|
||||
ArrayList<String> warsTempList = new ArrayList<String>();
|
||||
while (it.hasNext()) {
|
||||
warsTempList.add(it.next());
|
||||
}
|
||||
for (int i = 0; i < warsTempList.size(); ++i) {
|
||||
final War war = new War(warsTempList.get(i),
|
||||
warData.getConfig().getString("Wars." + warsTempList.get(i) + ".side1"),
|
||||
warData.getConfig().getString("Wars." + warsTempList.get(i) + ".side2"));
|
||||
ArrayList<String> side1Players = new ArrayList<String>();
|
||||
ArrayList<String> side2Players = new ArrayList<String>();
|
||||
ArrayList<String> side1Mercs = new ArrayList<String>();
|
||||
ArrayList<String> side2Mercs = new ArrayList<String>();
|
||||
side1Players = (ArrayList<String>) warData.getConfig()
|
||||
.getList("Wars." + war.getName() + ".side1players");
|
||||
side2Players = (ArrayList<String>) warData.getConfig()
|
||||
.getList("Wars." + war.getName() + ".side2players");
|
||||
side1Mercs = (ArrayList<String>) warData.getConfig()
|
||||
.getList("Wars." + war.getName() + ".side1mercs");
|
||||
side2Mercs = (ArrayList<String>) warData.getConfig()
|
||||
.getList("Wars." + war.getName() + ".side2mercs");
|
||||
war.setSide1Players(side1Players);
|
||||
war.setSide2Players(side2Players);
|
||||
war.setSide1Mercs(side1Mercs);
|
||||
war.setSide2Mercs(side2Mercs);
|
||||
WarCommands.wars.add(war);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
Bukkit.getLogger().info("NULL when initializing wars");
|
||||
}
|
||||
try {
|
||||
Set<String> siegeSet = (Set<String>) siegeData.getConfig().getConfigurationSection("Sieges").getKeys(false);
|
||||
Iterator<String> it2 = siegeSet.iterator();
|
||||
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 (siegeData.getConfig().getString("Sieges." + siegesTempList.get(i) + ".war")
|
||||
.equalsIgnoreCase(war2.getName())) {
|
||||
siegeWar = war2;
|
||||
}
|
||||
}
|
||||
List<Town> townList = TownyAPI.getInstance().getTowns();
|
||||
for (final Town town : townList) {
|
||||
if (town.getName().equalsIgnoreCase(
|
||||
siegeData.getConfig().getString("Sieges." + siegesTempList.get(i) + ".town"))) {
|
||||
siegeTown = town;
|
||||
}
|
||||
}
|
||||
Siege siege = new Siege(Integer.parseInt(siegesTempList.get(i)), siegeWar, siegeTown,
|
||||
siegeData.getConfig().getString("Sieges." + siegesTempList.get(i) + ".attackers"),
|
||||
siegeData.getConfig().getString("Sieges." + siegesTempList.get(i) + ".defenders"),
|
||||
siegeData.getConfig().getBoolean("Sieges." + siegesTempList.get(i) + ".siege1areattackers"),
|
||||
siegeData.getConfig().getBoolean("Sieges." + siegesTempList.get(i) + ".siege2areattackers"));
|
||||
SiegeCommands.sieges.add(siege);
|
||||
siege.start();
|
||||
siege.resetBeacon(
|
||||
Bukkit.getWorld(siegeData.getConfig().getString("Sieges." + siegesTempList.get(i) + ".world")),
|
||||
siegeData.getConfig().getInt("Sieges." + siegesTempList.get(i) + ".homeblockx"),
|
||||
siegeData.getConfig().getInt("Sieges." + siegesTempList.get(i) + ".homeblocky"),
|
||||
siegeData.getConfig().getInt("Sieges." + siegesTempList.get(i) + ".homeblockz"));
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
Bukkit.getLogger().info("NULL when initializing sieges");
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private boolean setupEconomy() {
|
||||
if (this.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return false;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
final RegisteredServiceProvider<Economy> rsp = (RegisteredServiceProvider<Economy>) this.getServer()
|
||||
.getServicesManager().getRegistration((Class) Economy.class);
|
||||
if (rsp == null) {
|
||||
return false;
|
||||
}
|
||||
econ = (Economy) rsp.getProvider();
|
||||
return econ != null;
|
||||
}
|
||||
|
||||
public static Main getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
private static void initAPIs() {
|
||||
TABHook.init();
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
warData = new WarData(this);
|
||||
siegeData = new SiegeData(this);
|
||||
new WarCommands(this);
|
||||
new SiegeCommands(this);
|
||||
new MercCommand(this);
|
||||
new AssassinCommand(this);
|
||||
new ContractCommand(this);
|
||||
getCommand("war").setTabCompleter(new WarTabCompletion());
|
||||
getCommand("siege").setTabCompleter(new SiegeTabCompletion());
|
||||
getServer().getPluginManager().registerEvents((Listener) new KillsListener(), (Plugin) this);
|
||||
getServer().getPluginManager().registerEvents((Listener) new JoinListener(), (Plugin) this);
|
||||
getServer().getPluginManager().registerEvents((Listener) new BlockBreakListener(), (Plugin) this);
|
||||
initData();
|
||||
initAPIs();
|
||||
setupEconomy();
|
||||
initLogs();
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,508 @@
|
||||
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 com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.commands.SiegeCommands;
|
||||
|
||||
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.siegeData.getConfig().getInt("Sieges." + String.valueOf(this.id) + ".attackerpoints");
|
||||
this.defenderPoints = Main.siegeData.getConfig().getInt("Sieges." + String.valueOf(this.id) + ".defenderpoints");
|
||||
this.side1AreAttackers = Main.siegeData.getConfig()
|
||||
.getBoolean("Sieges." + String.valueOf(this.id) + ".side1areattackers");
|
||||
this.side2AreAttackers = Main.siegeData.getConfig()
|
||||
.getBoolean("Sieges." + String.valueOf(this.id) + ".side2areattackers");
|
||||
this.MAXSIEGETICKS = 108000;
|
||||
this.siegeTicks = Main.siegeData.getConfig().getInt("Sieges." + String.valueOf(this.id) + ".siegeticks");
|
||||
this.owner = Bukkit.getPlayer(Main.siegeData.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.siegeData.getConfig().set("Sieges." + String.valueOf(Siege.this.id) + ".siegeticks",
|
||||
(Object) Siege.this.siegeTicks);
|
||||
Main.siegeData.saveConfig();
|
||||
for (final String playerName : Siege.this.attackerPlayers) {
|
||||
try {
|
||||
if (WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName))
|
||||
.getTownBlock().isHomeBlock()
|
||||
&& WorldCoord
|
||||
.parseWorldCoord(
|
||||
Main.getInstance().getServer().getPlayer(playerName))
|
||||
.getTownBlock().getTown().equals(town)
|
||||
&& !Bukkit.getPlayer(playerName).isDead()
|
||||
&& (Math.abs(
|
||||
Bukkit.getServer().getPlayer(playerName).getLocation().getBlockY()
|
||||
- townSpawn.getBlockY())) < 10) {
|
||||
attackersAreOnHomeBlock = true;
|
||||
}
|
||||
} catch (NotRegisteredException ex) {
|
||||
} catch (NullPointerException ex2) {
|
||||
}
|
||||
}
|
||||
for (final String playerName : Siege.this.defenderPlayers) {
|
||||
try {
|
||||
if (WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName))
|
||||
.getTownBlock().isHomeBlock()
|
||||
&& WorldCoord
|
||||
.parseWorldCoord(
|
||||
Main.getInstance().getServer().getPlayer(playerName))
|
||||
.getTownBlock().getTown().equals(town)
|
||||
&& !Bukkit.getPlayer(playerName).isDead()
|
||||
&& (Math.abs(
|
||||
Bukkit.getServer().getPlayer(playerName).getLocation().getBlockY()
|
||||
- townSpawn.getBlockY())) < 10) {
|
||||
defendersAreOnHomeBlock = true;
|
||||
}
|
||||
} catch (NotRegisteredException ex3) {
|
||||
} catch (NullPointerException ex4) {
|
||||
}
|
||||
}
|
||||
if (attackersAreOnHomeBlock && defendersAreOnHomeBlock) {
|
||||
if (this.homeBlockControl != 1) {
|
||||
for (final String playerName : Siege.this.attackerPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel())
|
||||
+ "HomeBlock at " + Siege.this.town.getName() + " contested!");
|
||||
} catch (NullPointerException ex5) {
|
||||
}
|
||||
}
|
||||
for (final String playerName : Siege.this.defenderPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel())
|
||||
+ "HomeBlock at " + Siege.this.town.getName() + " contested!");
|
||||
} catch (NullPointerException ex6) {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.homeBlockControl = 1;
|
||||
} else if (attackersAreOnHomeBlock && !defendersAreOnHomeBlock) {
|
||||
if (this.homeBlockControl != 2) {
|
||||
for (final String playerName : Siege.this.attackerPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel())
|
||||
+ "Attackers have captured the HomeBlock at "
|
||||
+ Siege.this.town.getName() + "! +1 Attacker Points per second");
|
||||
} catch (NullPointerException ex7) {
|
||||
}
|
||||
}
|
||||
for (final String playerName : Siege.this.defenderPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel())
|
||||
+ "Attackers have captured the HomeBlock at "
|
||||
+ Siege.this.town.getName() + "! +1 Attacker Points per second");
|
||||
} catch (NullPointerException ex8) {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.homeBlockControl = 2;
|
||||
Siege.this.addPointsToAttackers(10);
|
||||
Main.siegeData.getConfig().set(
|
||||
"Sieges." + String.valueOf(Siege.this.id) + ".attackerpoints",
|
||||
(Object) Siege.this.attackerPoints);
|
||||
Main.siegeData.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.siegeData.getConfig().set(
|
||||
"Sieges." + String.valueOf(Siege.this.id) + ".defenderpoints",
|
||||
(Object) Siege.this.defenderPoints);
|
||||
Main.siegeData.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.siegeData.getConfig().set("Sieges." + String.valueOf(this.id), (Object) null);
|
||||
Main.siegeData.saveConfig();
|
||||
}
|
||||
|
||||
public void attackersWin(final Player owner) {
|
||||
final Resident resident = TownyAPI.getInstance().getResident(owner);
|
||||
Nation nation = null;
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The attackers from " + this.attackers
|
||||
+ " have won the siege of " + this.town.getName() + "!");
|
||||
try {
|
||||
nation = resident.getTown().getNation();
|
||||
} catch (NotRegisteredException e) {
|
||||
for (final String playerName : this.attackerPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "The town of "
|
||||
+ this.town.getName()
|
||||
+ " could not be occupied because the player who started the siege is not part of a nation");
|
||||
} catch (NullPointerException ex) {
|
||||
}
|
||||
}
|
||||
for (final String playerName : this.defenderPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "The town of "
|
||||
+ this.town.getName()
|
||||
+ " could not be occupied because the player who started the siege is not part of a nation");
|
||||
} catch (NullPointerException ex2) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nation != null) {
|
||||
TownOccupationController.setTownOccupation(this.town, nation);
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName()
|
||||
+ " has been placed under occupation by " + nation.getName() + "!");
|
||||
}
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(owner.getUniqueId());
|
||||
Main.econ.depositPlayer(offlinePlayer, 2500.0);
|
||||
double amt = 0.0;
|
||||
if (this.town.getAccount().getHoldingBalance() > 10000.0) {
|
||||
amt = Math.floor(this.town.getAccount().getHoldingBalance()) / 4.0;
|
||||
this.town.getAccount().withdraw(amt, "war loot");
|
||||
} else {
|
||||
if (this.town.getAccount().getHoldingBalance() < 2500.0) {
|
||||
amt = this.town.getAccount().getHoldingBalance();
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName()
|
||||
+ " has been destroyed by " + this.getAttackers() + "!");
|
||||
TownyUniverse.getInstance().getDataSource().deleteTown(this.town);
|
||||
Main.econ.depositPlayer(offlinePlayer, amt);
|
||||
return;
|
||||
}
|
||||
this.town.getAccount().withdraw(2500.0, "war loot");
|
||||
amt = 2500.0;
|
||||
}
|
||||
Bukkit.broadcastMessage("The town of " + this.town.getName() + " has been sacked by " + this.getAttackers()
|
||||
+ ", valuing $" + String.valueOf(amt));
|
||||
Main.warLogger.log("The town of " + this.town.getName() + " has been sacked by " + this.getAttackers()
|
||||
+ ", valuing $" + String.valueOf(amt));
|
||||
Main.econ.depositPlayer(offlinePlayer, amt);
|
||||
|
||||
stop();
|
||||
clearBeacon();
|
||||
}
|
||||
|
||||
public void defendersWin() {
|
||||
this.town.getAccount().deposit(2500.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 $2,500");
|
||||
Main.warLogger
|
||||
.log("The defenders from " + this.defenders + " have won the siege of " + this.town.getName() + "!");
|
||||
stop();
|
||||
clearBeacon();
|
||||
}
|
||||
|
||||
public void createBeacon() {
|
||||
try {
|
||||
World world = town.getWorld();
|
||||
int homeBlockX = this.town.getHomeBlock().getX() * 16;
|
||||
int homeBlockZ = (this.town.getHomeBlock().getZ() + 1) * 16;
|
||||
if (homeBlockX > 0) {
|
||||
homeBlockX -= 8;
|
||||
}
|
||||
if (homeBlockZ > 0) {
|
||||
homeBlockZ -= 8;
|
||||
}
|
||||
if (homeBlockX < 0) {
|
||||
homeBlockX += 8;
|
||||
}
|
||||
if (homeBlockZ < 0) {
|
||||
homeBlockZ += 8;
|
||||
}
|
||||
int homeBlockY = 253;
|
||||
final Location beaconLoc = new Location(this.town.getWorld(), (double) homeBlockX,
|
||||
(double) (homeBlockY - 2), (double) homeBlockZ);
|
||||
while (beaconLoc.getBlock().getType().equals((Object) Material.AIR)) {
|
||||
--homeBlockY;
|
||||
beaconLoc.setY((double) homeBlockY);
|
||||
}
|
||||
homeBlockY += 2;
|
||||
this.beaconLocs.add(new Location(world, (double) homeBlockX, (double) homeBlockY, (double) homeBlockZ));
|
||||
this.beaconLocs
|
||||
.add(new Location(world, (double) homeBlockX, (double) (homeBlockY + 1), (double) homeBlockZ));
|
||||
this.beaconLocs
|
||||
.add(new Location(world, (double) homeBlockX, (double) (homeBlockY - 1), (double) homeBlockZ));
|
||||
this.beaconLocs.add(
|
||||
new Location(world, (double) (homeBlockX + 1), (double) (homeBlockY - 1), (double) homeBlockZ));
|
||||
this.beaconLocs.add(
|
||||
new Location(world, (double) (homeBlockX - 1), (double) (homeBlockY - 1), (double) homeBlockZ));
|
||||
this.beaconLocs.add(
|
||||
new Location(world, (double) homeBlockX, (double) (homeBlockY - 1), (double) (homeBlockZ + 1)));
|
||||
this.beaconLocs.add(
|
||||
new Location(world, (double) homeBlockX, (double) (homeBlockY - 1), (double) (homeBlockZ - 1)));
|
||||
this.beaconLocs.add(new Location(world, (double) (homeBlockX + 1), (double) (homeBlockY - 1),
|
||||
(double) (homeBlockZ + 1)));
|
||||
this.beaconLocs.add(new Location(world, (double) (homeBlockX + 1), (double) (homeBlockY - 1),
|
||||
(double) (homeBlockZ - 1)));
|
||||
this.beaconLocs.add(new Location(world, (double) (homeBlockX - 1), (double) (homeBlockY - 1),
|
||||
(double) (homeBlockZ + 1)));
|
||||
this.beaconLocs.add(new Location(world, (double) (homeBlockX - 1), (double) (homeBlockY - 1),
|
||||
(double) (homeBlockZ - 1)));
|
||||
for (int i = 2; i < this.beaconLocs.size(); ++i) {
|
||||
if (this.beaconLocs.get(i).getBlock().getType() != Material.AIR) {
|
||||
i = 1;
|
||||
homeBlockY++;
|
||||
for (final Location loc : this.beaconLocs) {
|
||||
loc.setY(loc.getY() + 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.beaconLocs.get(0).getBlock().setType(Material.BEACON);
|
||||
this.beaconLocs.get(1).getBlock().setType(Material.RED_STAINED_GLASS);
|
||||
for (int i = 2; i < this.beaconLocs.size(); ++i) {
|
||||
this.beaconLocs.get(i).getBlock().setType(Material.IRON_BLOCK);
|
||||
}
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(this.id) + ".world", world.getName());
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(this.id) + ".homeblockx", homeBlockX);
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(this.id) + ".homeblocky", homeBlockY);
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(this.id) + ".homeblockz", homeBlockZ);
|
||||
Main.siegeData.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,162 @@
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
public class UUIDFetcher {
|
||||
|
||||
/**
|
||||
* Date when name changes were introduced
|
||||
* @see UUIDFetcher#getUUIDAt(String, long)
|
||||
*/
|
||||
public static final long FEBRUARY_2015 = 1422748800000L;
|
||||
|
||||
|
||||
private static Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
|
||||
|
||||
private static final String UUID_URL = "https://api.mojang.com/users/profiles/minecraft/%s?at=%d";
|
||||
private static final String NAME_URL = "https://api.mojang.com/user/profiles/%s/names";
|
||||
|
||||
private static Map<String, UUID> uuidCache = new HashMap<String, UUID>();
|
||||
private static Map<UUID, String> nameCache = new HashMap<UUID, String>();
|
||||
|
||||
private static ExecutorService pool = Executors.newCachedThreadPool();
|
||||
|
||||
private String name;
|
||||
private UUID id;
|
||||
|
||||
/**
|
||||
* Fetches the uuid asynchronously and passes it to the consumer
|
||||
*
|
||||
* @param name The name
|
||||
* @param action Do what you want to do with the uuid her
|
||||
*/
|
||||
public static void getUUID(String name, Consumer<UUID> action) {
|
||||
pool.execute(() -> action.accept(getUUID(name)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the uuid synchronously and returns it
|
||||
*
|
||||
* @param name The name
|
||||
* @return The uuid
|
||||
*/
|
||||
public static UUID getUUID(String name) {
|
||||
return getUUIDAt(name, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the uuid synchronously for a specified name and time and passes the result to the consumer
|
||||
*
|
||||
* @param name The name
|
||||
* @param timestamp Time when the player had this name in milliseconds
|
||||
* @param action Do what you want to do with the uuid her
|
||||
*/
|
||||
public static void getUUIDAt(String name, long timestamp, Consumer<UUID> action) {
|
||||
pool.execute(() -> action.accept(getUUIDAt(name, timestamp)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the uuid synchronously for a specified name and time
|
||||
*
|
||||
* @param name The name
|
||||
* @param timestamp Time when the player had this name in milliseconds
|
||||
* @see UUIDFetcher#FEBRUARY_2015
|
||||
*/
|
||||
public static UUID getUUIDAt(String name, long timestamp) {
|
||||
name = name.toLowerCase();
|
||||
if (uuidCache.containsKey(name)) {
|
||||
return uuidCache.get(name);
|
||||
}
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(String.format(UUID_URL, name, timestamp/1000)).openConnection();
|
||||
connection.setReadTimeout(5000);
|
||||
UUIDFetcher data = gson.fromJson(new BufferedReader(new InputStreamReader(connection.getInputStream())), UUIDFetcher.class);
|
||||
|
||||
uuidCache.put(name, data.id);
|
||||
nameCache.put(data.id, data.name);
|
||||
|
||||
return data.id;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the name asynchronously and passes it to the consumer
|
||||
*
|
||||
* @param uuid The uuid
|
||||
* @param action Do what you want to do with the name her
|
||||
*/
|
||||
public static void getName(UUID uuid, Consumer<String> action) {
|
||||
pool.execute(() -> action.accept(getName(uuid)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the name synchronously and returns it
|
||||
*
|
||||
* @param uuid The uuid
|
||||
* @return The name
|
||||
*/
|
||||
public static String getName(UUID uuid) {
|
||||
if (nameCache.containsKey(uuid)) {
|
||||
return nameCache.get(uuid);
|
||||
}
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(String.format(NAME_URL, UUIDTypeAdapter.fromUUID(uuid))).openConnection();
|
||||
connection.setReadTimeout(5000);
|
||||
UUIDFetcher[] nameHistory = gson.fromJson(new BufferedReader(new InputStreamReader(connection.getInputStream())), UUIDFetcher[].class);
|
||||
UUIDFetcher currentNameData = nameHistory[nameHistory.length - 1];
|
||||
|
||||
uuidCache.put(currentNameData.name.toLowerCase(), uuid);
|
||||
nameCache.put(uuid, currentNameData.name);
|
||||
|
||||
return currentNameData.name;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class UUIDTypeAdapter extends TypeAdapter<UUID> {
|
||||
|
||||
public static String fromUUID(UUID value) {
|
||||
return value.toString().replace("-", "");
|
||||
}
|
||||
|
||||
public static UUID fromString(String input) {
|
||||
return UUID.fromString(input.replaceFirst(
|
||||
"(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter out, UUID value) throws IOException {
|
||||
// TODO Auto-generated method stub
|
||||
out.value(fromUUID(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID read(JsonReader in) throws IOException {
|
||||
// TODO Auto-generated method stub
|
||||
return fromString(in.nextString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
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;
|
||||
private ArrayList<String> side1Mercs;
|
||||
private ArrayList<String> side2Mercs;
|
||||
|
||||
public War(final String name, final String side1, final String side2) {
|
||||
side1Players = new ArrayList<String>();
|
||||
side2Players = new ArrayList<String>();
|
||||
side1Mercs = new ArrayList<String>();
|
||||
side2Mercs = new ArrayList<String>();
|
||||
this.name = name;
|
||||
this.side1 = side1;
|
||||
this.side2 = side2;
|
||||
side1Players.add("Placeholder1");
|
||||
side2Players.add("Placeholder2");
|
||||
side1Mercs.add("Placeholder1");
|
||||
side2Mercs.add("Placeholder2");
|
||||
}
|
||||
|
||||
public void addPlayerSide1(final String playerName) {
|
||||
boolean duplicate = false;
|
||||
if (!side1Players.isEmpty()) {
|
||||
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) {
|
||||
if (!side1Players.isEmpty()) {
|
||||
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;
|
||||
if (!side2Players.isEmpty()) {
|
||||
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) {
|
||||
if (!side2Players.isEmpty()) {
|
||||
for (int i = 0; i < this.side2Players.size(); ++i) {
|
||||
if (playerName.equalsIgnoreCase(this.side2Players.get(i))) {
|
||||
this.side2Players.remove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addMercSide1(final String playerName) {
|
||||
boolean duplicate = false;
|
||||
if (!side1Mercs.isEmpty()) {
|
||||
for (int i = 0; i < side1Mercs.size(); ++i) {
|
||||
if (playerName.equalsIgnoreCase(side1Mercs.get(i))) {
|
||||
duplicate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!duplicate) {
|
||||
side1Mercs.add(playerName);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeMercSide1(final String playerName) {
|
||||
if (!side1Mercs.isEmpty()) {
|
||||
for (int i = 0; i < side1Mercs.size(); ++i) {
|
||||
if (playerName.equalsIgnoreCase(side1Mercs.get(i))) {
|
||||
side1Mercs.remove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addMercSide2(final String playerName) {
|
||||
boolean duplicate = false;
|
||||
if (!side2Mercs.isEmpty()) {
|
||||
for (int i = 0; i < side2Mercs.size(); ++i) {
|
||||
if (playerName.equalsIgnoreCase(side2Mercs.get(i))) {
|
||||
duplicate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!duplicate) {
|
||||
side2Mercs.add(playerName);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeMercSide2(final String playerName) {
|
||||
if (!side2Mercs.isEmpty()) {
|
||||
for (int i = 0; i < side2Mercs.size(); ++i) {
|
||||
if (playerName.equalsIgnoreCase(side2Mercs.get(i))) {
|
||||
side2Mercs.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;
|
||||
}
|
||||
|
||||
public ArrayList<String> getSide1Mercs() {
|
||||
return this.side1Mercs;
|
||||
}
|
||||
|
||||
public void setSide1Mercs(final ArrayList<String> side1Mercs) {
|
||||
this.side1Mercs = side1Mercs;
|
||||
}
|
||||
|
||||
public ArrayList<String> getSide2Mercs() {
|
||||
return this.side2Mercs;
|
||||
}
|
||||
|
||||
public void setSide2Mercs(final ArrayList<String> side2Mercs) {
|
||||
this.side2Mercs = side2Mercs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import com.palmergames.bukkit.towny.object.TownyWorld;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Helper;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.Siege;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
|
||||
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.siegeData.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.siegeData.getConfig().getInt("Sieges." + String.valueOf(String.valueOf(siege.getID()) + ".siegeticks"))) / 1200) + " minutes");
|
||||
p.sendMessage("-=-=-=-=-=-=-=-=-=-=-=-");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("help")) {
|
||||
if (p.hasPermission("!AlathraWar.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.siegeData.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.siegeData.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());
|
||||
Main.warLogger.log(p.getName() + " abandoned the siege they started at " + SiegeCommands.sieges.get(j).getTown().getName());
|
||||
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;
|
||||
townyWorld = WorldCoord.parseWorldCoord(p.getLocation()).getTownyWorld();
|
||||
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.siegeData.getConfig().set("MaxID", (Object)SiegeCommands.maxID);
|
||||
Main.siegeData.saveConfig();
|
||||
Siege siege2;
|
||||
if (war.getSide1Players().contains(p.getName())) {
|
||||
siege2 = new Siege(SiegeCommands.maxID, war, town, war.getSide1(), war.getSide2(), true, false);
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".war", (Object)war.getName());
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".town", (Object)town.getName());
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".attackers", (Object)war.getSide1());
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".defenders", (Object)war.getSide2());
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".side1areattackers", (Object)true);
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".side2areattackers", (Object)false);
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".siegeticks", (Object)0);
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".attackerpoints", (Object)0);
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".defenderpoints", (Object)0);
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".owner", (Object)p.getName());
|
||||
Main.siegeData.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.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".war", (Object)war.getName());
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".town", (Object)town.getName());
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".attackers", (Object)war.getSide2());
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".defenders", (Object)war.getSide1());
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".side1areattackers", (Object)false);
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".side2areattackers", (Object)true);
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".siegeticks", (Object)0);
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".attackerpoints", (Object)0);
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".defenderpoints", (Object)0);
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID) + ".owner", (Object)p.getName());
|
||||
Main.siegeData.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.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID), (Object)null);
|
||||
Main.siegeData.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.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID), (Object)null);
|
||||
Main.siegeData.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.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID), (Object)null);
|
||||
Main.siegeData.saveConfig();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(p.getUniqueId());
|
||||
if (Main.econ.getBalance(offlinePlayer) <= 2500.0) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must have at least $20,000 to put up to start a siege");
|
||||
Main.siegeData.getConfig().set("Sieges." + String.valueOf(SiegeCommands.maxID), (Object)null);
|
||||
Main.siegeData.saveConfig();
|
||||
return false;
|
||||
}
|
||||
Main.econ.withdrawPlayer(offlinePlayer, 2500.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() + "!");
|
||||
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() + "!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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,62 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
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.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Siege;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
|
||||
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 (!TownyAPI.getInstance().getTowns().isEmpty()) {
|
||||
for (Town town : TownyAPI.getInstance().getTowns()) {
|
||||
completions.add(town.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,329 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Helper;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
import me.ShermansWorld.AlathraWar.hooks.TABHook;
|
||||
import me.ShermansWorld.AlathraWar.roles.Merc;
|
||||
|
||||
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("AlathraWar.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], args[2], args[3]);
|
||||
WarCommands.wars.add(war);
|
||||
final ArrayList<String> side1Players = new ArrayList<String>();
|
||||
final ArrayList<String> side2Players = new ArrayList<String>();
|
||||
final ArrayList<String> side1Mercs = new ArrayList<String>();
|
||||
final ArrayList<String> side2Mercs = new ArrayList<String>();
|
||||
side1Players.add("Placeholder1");
|
||||
side2Players.add("Placeholder2");
|
||||
side1Mercs.add("Placeholder1");
|
||||
side2Mercs.add("Placeholder2");
|
||||
war.setSide1Players(side1Players);
|
||||
war.setSide2Players(side2Players);
|
||||
war.setSide1Mercs(side1Mercs);
|
||||
war.setSide2Mercs(side2Mercs);
|
||||
Main.warData.getConfig().set("Wars." + args[1] + ".side1", (Object)args[2]);
|
||||
Main.warData.getConfig().set("Wars." + args[1] + ".side2", (Object)args[3]);
|
||||
Main.warData.getConfig().set("Wars." + args[1] + ".side1players", (Object)side1Players);
|
||||
Main.warData.getConfig().set("Wars." + args[1] + ".side2players", (Object)side2Players);
|
||||
Main.warData.getConfig().set("Wars." + args[1] + ".side1mercs", (Object)side1Mercs);
|
||||
Main.warData.getConfig().set("Wars." + args[1] + ".side2mercs", (Object)side2Mercs);
|
||||
Main.warData.saveConfig();
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War created with the name " + args[1] + ", " + args[2] + " vs. " + args[3]);
|
||||
Main.warLogger.log(p.getName() + " created a new war with the name " + args[1] + ", " + args[2] + " vs. " + args[3]);
|
||||
}
|
||||
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("Placeholder1");
|
||||
side2Players2.add("Placeholder2");
|
||||
war2.setSide1Players(side1Players2);
|
||||
war2.setSide2Players(side2Players2);
|
||||
Main.warData.getConfig().set("Wars." + args[1] + ".side1", (Object)args[2]);
|
||||
Main.warData.getConfig().set("Wars." + args[1] + ".side2", (Object)args[3]);
|
||||
Main.warData.getConfig().set("Wars." + args[1] + ".side1players", (Object)side1Players2);
|
||||
Main.warData.getConfig().set("Wars." + args[1] + ".side2players", (Object)side2Players2);
|
||||
Main.warData.saveConfig();
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War created with the name " + args[1] + ", " + args[2] + " vs. " + args[3]);
|
||||
Main.warLogger.log(p.getName() + " created a new war with the name " + args[1] + ", " + args[2] + " vs. " + args[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /war create [name] [side1] [side2]");
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("delete")) {
|
||||
if (args.length != 2) {
|
||||
p.sendMessage(Helper.Chatlabel() + Helper.color("&cInvalid Arguements. /war delete [name]"));
|
||||
return false;
|
||||
}
|
||||
String deleteTarget = args[1];
|
||||
if (!p.hasPermission("AlathraWar.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 " + deleteTarget + " has been deleted");
|
||||
Main.warLogger.log(p.getName() + " deleted a war named " + deleteTarget);
|
||||
for (String playername : WarCommands.wars.get(j).getSide1Players()) {
|
||||
TABHook.resetSuffix(playername);
|
||||
}
|
||||
for (String playername : WarCommands.wars.get(j).getSide2Players()) {
|
||||
TABHook.resetSuffix(playername);
|
||||
}
|
||||
deleteTarget = wars.get(j).getName();
|
||||
Main.warData.getConfig().set("Wars." + deleteTarget, (Object)null);
|
||||
WarCommands.wars.remove(j);
|
||||
Main.warData.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;
|
||||
boolean isMercJoining = false;
|
||||
if (args.length == 3 || args.length == 4) {
|
||||
String joinWarTarget = args[1];
|
||||
String joinSideTarget = args[2];
|
||||
if (args.length == 4 && (args[3].equalsIgnoreCase("merc") || args[3].equalsIgnoreCase("mercenary")) ) {
|
||||
if (!Merc.hasMercRole(p)) {
|
||||
p.sendMessage(Helper.Chatlabel() + Helper.color("&cYou must have the mercenary role to join a war as a mercenary!"));
|
||||
return false;
|
||||
}
|
||||
isMercJoining = true;
|
||||
}
|
||||
|
||||
for (final War war2 : WarCommands.wars) {
|
||||
if (war2.getName().equalsIgnoreCase(joinWarTarget)) {
|
||||
if (war2.getSide1().equalsIgnoreCase(joinSideTarget)) {
|
||||
if (war2.getSide1Players().contains(p.getName()) || 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;
|
||||
}
|
||||
joinWarTarget = war2.getName();
|
||||
war2.addPlayerSide1(p.getName());
|
||||
Main.warData.getConfig().set("Wars." + joinWarTarget + ".side1players", (Object)war2.getSide1Players());
|
||||
Main.warData.saveConfig();
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the war on the side of " + war2.getSide1());
|
||||
if (isMercJoining) {
|
||||
TABHook.assignSide1WarSuffixMerc(p, war2);
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + p.getName() + " has joined " + war2.getName() + " on the side of " + war2.getSide1() + " as a mercenary!");
|
||||
Bukkit.getLogger().info("[AlathraWar] Player " + p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide1() + " as a mercenary");
|
||||
Main.warLogger.log(p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide1() + " as a mercenary");
|
||||
war2.addMercSide1(p.getName());
|
||||
Main.warData.getConfig().set("Wars." + joinWarTarget + ".side1mercs", (Object)war2.getSide1Players());
|
||||
Main.warData.saveConfig();
|
||||
} else {
|
||||
TABHook.assignSide1WarSuffix(p, war2);
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + p.getName() + " has joined " + war2.getName() + " on the side of " + war2.getSide1() + "!");
|
||||
Bukkit.getLogger().info("[AlathraWar] Player " + p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide1());
|
||||
Main.warLogger.log(p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide1());
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
else {
|
||||
if (!war2.getSide2().equalsIgnoreCase(args[2])) {
|
||||
continue;
|
||||
}
|
||||
if (war2.getSide2Players().contains(p.getName()) || 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;
|
||||
}
|
||||
joinWarTarget = war2.getName();
|
||||
war2.addPlayerSide2(p.getName());
|
||||
Main.warData.getConfig().set("Wars." + joinWarTarget + ".side2players", (Object)war2.getSide2Players());
|
||||
Main.warData.saveConfig();
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the war on the side of " + war2.getSide2());
|
||||
if (isMercJoining) {
|
||||
TABHook.assignSide2WarSuffixMerc(p, war2);
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + p.getName() + " has joined " + war2.getName() + " on the side of " + war2.getSide2() + " as a mercenary!");
|
||||
Bukkit.getLogger().info("[AlathraWar] Player " + p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide2() + " as a mercenary");
|
||||
Main.warLogger.log(p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide2() + " as a mercenary");
|
||||
war2.addMercSide2(p.getName());
|
||||
Main.warData.getConfig().set("Wars." + joinWarTarget + ".side2mercs", (Object)war2.getSide2Players());
|
||||
Main.warData.saveConfig();
|
||||
} else {
|
||||
TABHook.assignSide2WarSuffix(p, war2);
|
||||
Bukkit.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War not found. /war join [name] [side] {merc}, type /war list to view current wars");
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /war join [name] [side] {merc}");
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("leave")) {
|
||||
if (args.length == 2) {
|
||||
boolean found = false;
|
||||
boolean found2 = false;
|
||||
String leaveWarTarget = args[1];
|
||||
for (final War war3 : WarCommands.wars) {
|
||||
if (war3.getName().equalsIgnoreCase(leaveWarTarget)) {
|
||||
found = true;
|
||||
leaveWarTarget = war3.getName();
|
||||
if (war3.getSide1Players().contains(p.getName())) {
|
||||
found2 = true;
|
||||
war3.removePlayerSide1(p.getName());
|
||||
Main.warData.getConfig().set("Wars." + leaveWarTarget + ".side1players", (Object)war3.getSide1Players());
|
||||
Main.warData.saveConfig();
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have left the war");
|
||||
TABHook.resetSuffix(p);
|
||||
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.getSide1Mercs().contains(p.getName())) {
|
||||
war3.removeMercSide1(p.getName());
|
||||
Main.warData.getConfig().set("Wars." + leaveWarTarget + ".side1mercs", (Object)war3.getSide1Mercs());
|
||||
Main.warData.saveConfig();
|
||||
}
|
||||
}
|
||||
if (war3.getSide2Players().contains(p.getName())) {
|
||||
found2 = true;
|
||||
war3.removePlayerSide2(p.getName());
|
||||
Main.warData.getConfig().set("Wars." + leaveWarTarget + ".side2players", (Object)war3.getSide2Players());
|
||||
Main.warData.saveConfig();
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have left the war");
|
||||
TABHook.resetSuffix(p);
|
||||
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 (war3.getSide2Mercs().contains(p.getName())) {
|
||||
war3.removeMercSide2(p.getName());
|
||||
Main.warData.getConfig().set("Wars." + leaveWarTarget + ".side2mercs", (Object)war3.getSide2Mercs());
|
||||
Main.warData.saveConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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("!AlathraWar.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] {merc}");
|
||||
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,72 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
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;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
import me.ShermansWorld.AlathraWar.roles.Merc;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (args.length == 4) {
|
||||
if (args[0].equalsIgnoreCase("join")) {
|
||||
if (Merc.hasMercRole(p)) {
|
||||
completions.add("merc");
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class RolesData {
|
||||
|
||||
public String editData(UUID pID, String key, Object value) {
|
||||
Map <String, Object> userData = getPlayer(pID);
|
||||
userData.put(key, value);
|
||||
setPlayer(pID, userData);
|
||||
return "Banana";
|
||||
}
|
||||
|
||||
public Object getData(UUID pID) {
|
||||
return getPlayer(pID);
|
||||
}
|
||||
|
||||
private File getFile(String strID) {
|
||||
// Gets user file, or creates if not yet made.
|
||||
File userFile = new File("plugins" + File.separator + "AlathraWar" + File.separator + "userdata" + File.separator + strID + ".yml");
|
||||
if (!userFile.exists()) {
|
||||
try {
|
||||
userFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger().warning("[AlathraWar] Encountered error when creating user file for " + strID);
|
||||
}
|
||||
}
|
||||
return userFile;
|
||||
}
|
||||
|
||||
private Map getPlayer(UUID pID) {
|
||||
Map<String, Object> DefaultData = new HashMap<String,Object>();
|
||||
DefaultData.put("MercPermission", false);
|
||||
DefaultData.put("AssassinPermission", false);
|
||||
DefaultData.put("Contracts", new HashMap<String, Map>());
|
||||
|
||||
|
||||
String strID = pID.toString();
|
||||
File userFile = getFile(strID);
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = new FileInputStream(userFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
Bukkit.getLogger().warning("[AlathraWar] Encountered error when creating FileInputStream for " + strID);
|
||||
}
|
||||
Yaml yaml = new Yaml();
|
||||
Map<String, Object> data = yaml.load(inputStream);
|
||||
//System.out.println(data);
|
||||
if (data == null) {data = DefaultData; setPlayer(pID, data);}
|
||||
return data;
|
||||
}
|
||||
|
||||
private void setPlayer(UUID pID, Map<String, Object> data) {
|
||||
String strID = pID.toString();
|
||||
File userFile = getFile(strID);
|
||||
|
||||
PrintWriter writer = null;
|
||||
try {
|
||||
writer = new PrintWriter(userFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
Bukkit.getLogger().warning("[AlathraWar] Encountered error when creating PrintWriter for " + strID);
|
||||
}
|
||||
|
||||
DumperOptions options = new DumperOptions();
|
||||
options.setIndent(2);
|
||||
options.setPrettyFlow(true);
|
||||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
Yaml yaml = new Yaml(options);
|
||||
yaml.dump(data, writer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
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 me.ShermansWorld.AlathraWar.Main;
|
||||
|
||||
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,67 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
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 me.ShermansWorld.AlathraWar.Main;
|
||||
|
||||
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,96 @@
|
||||
package me.ShermansWorld.AlathraWar.hooks;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Helper;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
import me.neznamy.tab.api.TabAPI;
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
|
||||
public class TABHook {
|
||||
|
||||
public static boolean init = false;
|
||||
public static TabAPI tabAPI;
|
||||
|
||||
public static void init() {
|
||||
tabAPI = TabAPI.getInstance();
|
||||
init = true;
|
||||
}
|
||||
|
||||
public static void assignSide1WarSuffix(Player p, War war) {
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
tabAPI.getTablistFormatManager().setSuffix(tabPlayer,
|
||||
Helper.color("&c[") + war.getSide1() + "]&r");
|
||||
}
|
||||
|
||||
public static void assignSide2WarSuffix(Player p, War war) {
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
tabAPI.getTablistFormatManager().setSuffix(tabPlayer,
|
||||
Helper.color("&9[") + war.getSide2() + "]&r");
|
||||
}
|
||||
|
||||
public static void assignSide1WarSuffixMerc(Player p, War war) {
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
tabAPI.getTablistFormatManager().setSuffix(tabPlayer,
|
||||
Helper.color("&a[M]&c[") + war.getSide1() + "]&r");
|
||||
}
|
||||
|
||||
public static void assignSide2WarSuffixMerc(Player p, War war) {
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
tabAPI.getTablistFormatManager().setSuffix(tabPlayer,
|
||||
Helper.color("&a[M]&9[") + war.getSide2() + "]&r");
|
||||
}
|
||||
|
||||
public static void resetSuffix(Player p) {
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
tabAPI.getTablistFormatManager().resetSuffix(tabPlayer);
|
||||
}
|
||||
|
||||
public static void resetSuffix(String playername) {
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(playername);
|
||||
try {
|
||||
if (op.isOnline()) {
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(playername);
|
||||
tabAPI.getTablistFormatManager().resetSuffix(tabPlayer);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetPrefix(Player p) {
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
tabAPI.getTablistFormatManager().resetPrefix(tabPlayer);
|
||||
}
|
||||
|
||||
public static void resetPrefix(String playername) {
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(playername);
|
||||
try {
|
||||
if (op.isOnline()) {
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(playername);
|
||||
tabAPI.getTablistFormatManager().resetPrefix(tabPlayer);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeColorPrefix(Player p, String prefix) {
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
if(prefix.length() > 2) {
|
||||
prefix = prefix.substring(0, prefix.length() - 2);
|
||||
}
|
||||
else{
|
||||
Bukkit.getLogger().info("There is an error when removing a color prefix, prefix not long enough:");
|
||||
Bukkit.getLogger().info("Player: " + p.getDisplayName());
|
||||
Bukkit.getLogger().info("Prefix: " + prefix);
|
||||
Bukkit.getLogger().info("------");
|
||||
}
|
||||
tabAPI.getTablistFormatManager().setPrefix(tabPlayer, Helper.color(prefix));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Siege;
|
||||
import me.ShermansWorld.AlathraWar.commands.SiegeCommands;
|
||||
|
||||
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(block.getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
import me.ShermansWorld.AlathraWar.commands.WarCommands;
|
||||
import me.ShermansWorld.AlathraWar.hooks.TABHook;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class JoinListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
final Player p = event.getPlayer();
|
||||
Main.rolesData.getData(p.getUniqueId());
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
boolean inWar = false;
|
||||
for (final War war : WarCommands.wars) {
|
||||
if (war.getSide1Players() == null) {
|
||||
Main.warLogger.log("ERROR: Unable to retrieve side 1 of war " + war.getName());
|
||||
} else if (war.getSide1Players().contains(p.getName())) {
|
||||
if (war.getSide1Mercs().contains(p.getName())) {
|
||||
TABHook.assignSide1WarSuffixMerc(p, war);
|
||||
} else {
|
||||
TABHook.assignSide1WarSuffix(p, war);
|
||||
}
|
||||
inWar = true;
|
||||
} else if (war.getSide2Players() == null) {
|
||||
Main.warLogger.log("ERROR: Unable to retrieve side 2 of war " + war.getName());
|
||||
} else if (war.getSide2Players().contains(p.getName())) {
|
||||
if (war.getSide2Mercs().contains(p.getName())) {
|
||||
TABHook.assignSide2WarSuffixMerc(p, war);
|
||||
} else {
|
||||
TABHook.assignSide2WarSuffix(p, war);
|
||||
}
|
||||
inWar = true;
|
||||
}
|
||||
}
|
||||
if (!inWar) {
|
||||
TABHook.resetPrefix(p);
|
||||
}
|
||||
|
||||
}
|
||||
}, 60L); // 20 Tick (1 Second) delay before run() is called
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
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 me.ShermansWorld.AlathraWar.Helper;
|
||||
import me.ShermansWorld.AlathraWar.Siege;
|
||||
import me.ShermansWorld.AlathraWar.commands.SiegeCommands;
|
||||
import me.ShermansWorld.AlathraWar.roles.Assassin;
|
||||
|
||||
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) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public static void assassinKillListener(PlayerDeathEvent e) {
|
||||
if (e.getEntity().getKiller() instanceof Player) {
|
||||
Player killed = e.getEntity();
|
||||
Player killer = killed.getKiller();
|
||||
if (killed.hasMetadata("NPC")) {
|
||||
e.setDeathMessage(null);
|
||||
} else if (killer.hasMetadata("NPC")) {
|
||||
Bukkit.broadcastMessage(killed.getName() + " has been slain by " + killer.getName());
|
||||
} else if (killer.hasPotionEffect(PotionEffectType.INVISIBILITY) && Assassin.hasAssassinRole(killer)) {
|
||||
e.setDeathMessage(killed.getName() + " has been assassinated by an invisible player");
|
||||
Bukkit.getLogger().info(Helper.Chatlabel() + killed.getName() + " was killed by " + killer.getName());
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (p.hasPermission("AlathraExtras.deathmsg")) {
|
||||
p.sendMessage(Helper.Chatlabel() + killed.getName() + " was killed by " + killer.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package me.ShermansWorld.AlathraWar.roles;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
|
||||
public class Assassin {
|
||||
public static boolean hasAssassinRole(Player p) {
|
||||
Map userData = (Map) Main.rolesData.getData(p.getUniqueId());
|
||||
if ((Boolean) userData.get("AssassinPermission")) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,382 @@
|
||||
package me.ShermansWorld.AlathraWar.roles;
|
||||
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.UUIDFetcher;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public class AssassinCommand implements CommandExecutor {
|
||||
|
||||
public static Map<String, Object> ActiveAssassinRequests = new HashMap<String, Object>();
|
||||
|
||||
public AssassinCommand(final Main plugin) {
|
||||
plugin.getCommand("assassin").setExecutor((CommandExecutor) this);
|
||||
plugin.getCommand("assassin").setTabCompleter(new CustomRoleTabCompletion());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
Player p = (Player) sender;
|
||||
|
||||
//LOAD PLAYER DATA
|
||||
UUID pID = p.getUniqueId();
|
||||
Map pData = (Map) Main.rolesData.getData(pID);
|
||||
//Bukkit.getwarLogger().info(Arrays.asList(pData).toString());
|
||||
|
||||
if(!p.hasPermission("AlathraWar.UseRoles")) {
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
|
||||
return false;
|
||||
}
|
||||
if(args.length == 0 || args[0].equalsIgnoreCase("help")) {
|
||||
p.sendMessage(ChatColor.RED + "! "+ ChatColor.RESET + ChatColor.GOLD + "---- Assassin Help ----");
|
||||
p.sendMessage(ChatColor.RED + "! " + ChatColor.GREEN + "/assassin hire <player> <price>");
|
||||
if ((Boolean) pData.get("AssassinPermission")) {
|
||||
p.sendMessage(ChatColor.RED + "! " + ChatColor.GREEN + "/assassin accept <player>");
|
||||
p.sendMessage(ChatColor.RED + "! " + ChatColor.GREEN + "/assassin decline <player>");
|
||||
}
|
||||
if (p.hasPermission("AlathraWar.Admin")) {
|
||||
p.sendMessage(ChatColor.RED + "! " + ChatColor.GREEN + "/assassin add <player>");
|
||||
p.sendMessage(ChatColor.RED + "! " + ChatColor.GREEN + "/assassin remove <player>");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if(args[0].equalsIgnoreCase("hire")) {
|
||||
// Valid number of arguments
|
||||
if (args.length < 3) {
|
||||
p.sendMessage(ChatColor.RED + "/assassin hire <player> <price>");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Target Validator
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
if (!(target instanceof Player)) {
|
||||
p.sendMessage(ChatColor.RED + "Please enter a valid player.");
|
||||
return false;
|
||||
}
|
||||
UUID targetID = target.getUniqueId();
|
||||
|
||||
|
||||
// Number Validator
|
||||
double val = 0;
|
||||
try {
|
||||
val = Double.parseDouble(args[2]);
|
||||
} catch (Exception e) {
|
||||
p.sendMessage(ChatColor.RED + "Please enter a valid price.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Minimum Price
|
||||
if (val < 10000) {
|
||||
p.sendMessage(ChatColor.DARK_RED + "You must comply with the minimum pricing of the server.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't have enough money.
|
||||
double pVal = Main.econ.getBalance(p);
|
||||
if (pVal < val) {
|
||||
p.sendMessage(ChatColor.DARK_RED + "You do not have a high enough balance.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
String targetStrID = targetID.toString();
|
||||
Map<String, Object> TargetRequests = null;
|
||||
|
||||
Bukkit.getLogger().info(String.valueOf(ActiveAssassinRequests.containsKey(targetStrID)));
|
||||
if (ActiveAssassinRequests.containsKey(targetStrID)) {
|
||||
TargetRequests = (Map) ActiveAssassinRequests.get(targetStrID);
|
||||
} else {
|
||||
TargetRequests = new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
if (TargetRequests.containsKey(pID.toString())) {
|
||||
p.sendMessage(ChatColor.RED + "You already have a pending contract.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Map targetData = (Map) Main.rolesData.getData(targetID);
|
||||
|
||||
if (targetData.containsKey(pID.toString())) {
|
||||
p.sendMessage(ChatColor.RED + "You already have an assassin contract with this user.");
|
||||
return false;
|
||||
}
|
||||
if (!(Boolean) targetData.get("AssassinPermission")) {
|
||||
p.sendMessage(ChatColor.RED + "This user is not an assassin.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Adding request to pending contracts
|
||||
Map contractData = new HashMap<String, String>();
|
||||
contractData.put("Value", val);
|
||||
TargetRequests.put(pID.toString(), contractData);
|
||||
ActiveAssassinRequests.put(targetStrID, TargetRequests);
|
||||
|
||||
// Messaging and logging
|
||||
p.sendMessage(ChatColor.GREEN + "You have requested an assassin contract with " + target.getDisplayName() + " for " + ChatColor.YELLOW + Main.econ.format(val) + ".");
|
||||
target.sendMessage(p.getDisplayName() + ChatColor.GREEN + " has requested an assassin contract worth " + ChatColor.YELLOW + Main.econ.format(val) + ".");
|
||||
Main.warLogger.log("User " + p.getName() + " requested assassin work from " + p.getName() + ", value " + val);
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("accept")) {
|
||||
// Valid number of arguments
|
||||
if (args.length < 2) {
|
||||
p.sendMessage(ChatColor.RED + "/assassin accept <player>");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Checks and defining target
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
if (!(target instanceof Player)) {
|
||||
p.sendMessage(ChatColor.RED + "Please enter a valid player.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Map AssassinRequests = (Map) ActiveAssassinRequests.get(pID.toString());
|
||||
if (AssassinRequests == null) {
|
||||
p.sendMessage(ChatColor.RED + "You do not have any pending contracts.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(AssassinRequests.isEmpty() || !AssassinRequests.containsKey(target.getUniqueId().toString())) {
|
||||
p.sendMessage(ChatColor.RED + "This player has not made any requests.");
|
||||
return false;
|
||||
}
|
||||
Map Request = (Map) AssassinRequests.get(target.getUniqueId().toString());
|
||||
|
||||
|
||||
if (!(Boolean) pData.get("AssassinPermission")) {
|
||||
p.sendMessage("You don't have assassin perms?");
|
||||
return false;
|
||||
}
|
||||
|
||||
Map Contracts = (Map) pData.get("Contracts");
|
||||
if (Contracts.containsKey(target.getUniqueId().toString())) {
|
||||
p.sendMessage(ChatColor.RED + "You already have a contract with this person.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Adds contract to userdata
|
||||
Map ContractData = new HashMap<String, Object>();
|
||||
ContractData.put("Type", "Assassin");
|
||||
ContractData.put("Value", Request.get("Value"));
|
||||
Contracts.put(target.getUniqueId().toString(), ContractData);
|
||||
|
||||
Main.rolesData.editData(pID, "Contracts", Contracts);
|
||||
|
||||
// Removes from ActiveAssassinRequests list
|
||||
AssassinRequests.remove(target.getUniqueId().toString());
|
||||
ActiveAssassinRequests.put(pID.toString(), AssassinRequests);
|
||||
|
||||
// Money Changes
|
||||
Double Value = (Double) Request.get("Value");
|
||||
Main.econ.withdrawPlayer(target, Value);
|
||||
Main.econ.depositPlayer(p, Value);
|
||||
|
||||
|
||||
// Messaging and logging
|
||||
p.sendMessage(ChatColor.GREEN + "You have " + ChatColor.YELLOW + "accepted " + target.getDisplayName() + ChatColor.GREEN + "'s request.");
|
||||
target.sendMessage(ChatColor.GREEN + "Your request to " + p.getDisplayName() + ChatColor.GREEN + " has been "+ ChatColor.YELLOW + "accepted" + ChatColor.YELLOW + ".");
|
||||
Main.warLogger.log("User " + p.getName() + " accepted assassin work for " + target.getName());
|
||||
return true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("decline") || args[0].equalsIgnoreCase("deny")) {
|
||||
// Valid number of arguments
|
||||
if (args.length < 2) {
|
||||
p.sendMessage(ChatColor.RED + "/assassin decline <player>");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Checks and defining target
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
UUID targetID;
|
||||
String msgName;
|
||||
if(target != null) {
|
||||
targetID = target.getUniqueId();
|
||||
msgName = target.getDisplayName();
|
||||
}
|
||||
else {
|
||||
targetID = UUIDFetcher.getUUID(args[1]);
|
||||
if(targetID == null) {
|
||||
p.sendMessage(ChatColor.RED + "Please enter a valid player.");
|
||||
return false;
|
||||
}
|
||||
msgName = args[1];
|
||||
}
|
||||
|
||||
Map AssassinRequests = (Map) ActiveAssassinRequests.get(pID.toString());
|
||||
if (AssassinRequests == null) {
|
||||
p.sendMessage(ChatColor.RED + "You do not have any pending assassin contracts.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(AssassinRequests.isEmpty() || !AssassinRequests.containsKey(targetID.toString())) {
|
||||
p.sendMessage(ChatColor.RED + "This player has not made any requests.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Removes from ActiveAssassinRequests list
|
||||
AssassinRequests.remove(targetID.toString());
|
||||
ActiveAssassinRequests.put(pID.toString(), AssassinRequests);
|
||||
|
||||
// Messaging and logging
|
||||
p.sendMessage(ChatColor.GREEN + "You have " + ChatColor.RED + "denied " + ChatColor.WHITE + msgName + ChatColor.GREEN + "'s request.");
|
||||
if(target != null) {
|
||||
target.sendMessage(ChatColor.GREEN + "Your request to " + p.getDisplayName() + ChatColor.GREEN + " has been "+ ChatColor.RED + "denied" + ChatColor.GREEN + ".");
|
||||
Main.warLogger.log("User " + p.getName() + " declined assassin work for " + target.getName());
|
||||
}
|
||||
else {
|
||||
Main.warLogger.log("User " + p.getName() + " declined assassin work for " + msgName);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("add") && p.hasPermission("AlathraWar.Admin")) {
|
||||
// Valid number of arguments
|
||||
if (args.length < 2) {
|
||||
p.sendMessage(ChatColor.RED + "/assassin add <player>");
|
||||
return false;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
UUID targetID;
|
||||
String msgName;
|
||||
if(target != null) {
|
||||
targetID = target.getUniqueId();
|
||||
msgName = target.getDisplayName();
|
||||
}
|
||||
else {
|
||||
targetID = UUIDFetcher.getUUID(args[1]);
|
||||
if(targetID == null) {
|
||||
p.sendMessage(ChatColor.RED + "Please enter a valid player.");
|
||||
return false;
|
||||
}
|
||||
msgName = args[1];
|
||||
}
|
||||
|
||||
// Gets data and re-writes
|
||||
Map targetData = (Map) Main.rolesData.getData(targetID);
|
||||
Boolean AssassinPerm = (Boolean) targetData.get("AssassinPermission");
|
||||
if (AssassinPerm) {
|
||||
p.sendMessage(ChatColor.RED + "This user already has assassin permissions!");
|
||||
return false;
|
||||
}
|
||||
Main.rolesData.editData(targetID, "AssassinPermission", true);
|
||||
|
||||
// Messaging and logging
|
||||
p.sendMessage(ChatColor.GREEN + "User " + ChatColor.WHITE + msgName + ChatColor.YELLOW + " may " + ChatColor.GREEN + "accept assassin work.");
|
||||
if(target != null) {
|
||||
target.sendMessage(ChatColor.GREEN + "You " + ChatColor.YELLOW + " may now " + ChatColor.GREEN + "accept assassin work.");
|
||||
Main.warLogger.log("User " + p.getName() + " gave " + target.getName() + " assassin permissions");
|
||||
}
|
||||
else {
|
||||
Main.warLogger.log("User " + p.getName() + " gave " + msgName + " assassin permissions");
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("remove") && p.hasPermission("AlathraWar.Admin")) {
|
||||
// Valid number of arguments
|
||||
if (args.length < 2) {
|
||||
p.sendMessage(ChatColor.RED + "/assassin remove <player>");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
UUID targetID;
|
||||
String msgName;
|
||||
if(target != null) {
|
||||
targetID = target.getUniqueId();
|
||||
msgName = target.getDisplayName();
|
||||
}
|
||||
else {
|
||||
targetID = UUIDFetcher.getUUID(args[1]);
|
||||
if(targetID == null) {
|
||||
p.sendMessage(ChatColor.RED + "Please enter a valid player.");
|
||||
return false;
|
||||
}
|
||||
msgName = args[1];
|
||||
}
|
||||
|
||||
// Gets data and re-writes
|
||||
Map targetData = (Map) Main.rolesData.getData(targetID);
|
||||
Boolean AssassinPerm = (Boolean) targetData.get("AssassinPermission");
|
||||
if (!AssassinPerm) {
|
||||
p.sendMessage(ChatColor.RED + "This user has no assassin permissions!");
|
||||
return false;
|
||||
}
|
||||
Main.rolesData.editData(targetID, "AssassinPermission", false);
|
||||
|
||||
// Messaging and logging
|
||||
p.sendMessage(ChatColor.GREEN + "User " + ChatColor.WHITE + msgName + ChatColor.RED + " may not " + ChatColor.GREEN + "accept assassin work.");
|
||||
if(target != null) {
|
||||
target.sendMessage(ChatColor.GREEN + "You " + ChatColor.RED + " may no longer " + ChatColor.GREEN + "accept assassin work.");
|
||||
Main.warLogger.log("User " + p.getName() + " removed " + target.getName() + "'s assassin permissions");
|
||||
}
|
||||
else {
|
||||
Main.warLogger.log("User " + p.getName() + " removed " + msgName + "'s assassin permissions");
|
||||
}
|
||||
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("complete")) {
|
||||
// Valid number of arguments
|
||||
if (args.length < 2) {
|
||||
p.sendMessage(ChatColor.RED + "/assassin complete <player>");
|
||||
return false;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
UUID targetID;
|
||||
String msgName;
|
||||
if(target != null) {
|
||||
targetID = target.getUniqueId();
|
||||
msgName = target.getDisplayName();
|
||||
}
|
||||
else {
|
||||
targetID = UUIDFetcher.getUUID(args[1]);
|
||||
if(targetID == null) {
|
||||
p.sendMessage(ChatColor.RED + "Please enter a valid player.");
|
||||
return false;
|
||||
}
|
||||
msgName = args[1];
|
||||
}
|
||||
|
||||
// Removal of contract from userdata
|
||||
Map Contracts = (Map) pData.get("Contracts");
|
||||
if (!Contracts.containsKey(targetID.toString())) {
|
||||
p.sendMessage(ChatColor.RED + "You have no assassin contract with this user!");
|
||||
return false;
|
||||
}
|
||||
Contracts.remove(targetID.toString());
|
||||
Main.rolesData.editData(pID, "Contracts", Contracts);
|
||||
|
||||
// Messaging and logging
|
||||
p.sendMessage(ChatColor.GREEN + "You have " + ChatColor.GOLD + "completed " + ChatColor.WHITE + msgName + ChatColor.GREEN + "'s assassin contract.");
|
||||
if(target != null) {
|
||||
target.sendMessage(ChatColor.GREEN + "Your assassin contract with " + p.getDisplayName() + ChatColor.GREEN + " has been "+ ChatColor.GOLD + "completed" + ChatColor.GREEN + ".");
|
||||
Main.warLogger.log("User " + p.getName() + " completed " + target.getName() + "'s assassin contract.");
|
||||
}
|
||||
else {
|
||||
Main.warLogger.log("User " + p.getName() + " completed " + msgName + "'s assassin contract.");
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
p.sendMessage(ChatColor.RED + "Unknown sub-command. Do " + ChatColor.YELLOW + "/assassin help" + ChatColor.RED + " for more info.");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package me.ShermansWorld.AlathraWar.roles;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.UUIDFetcher;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public class ContractCommand implements CommandExecutor {
|
||||
|
||||
public ContractCommand(final Main plugin) {
|
||||
plugin.getCommand("contract").setExecutor((CommandExecutor) this);
|
||||
plugin.getCommand("contract").setTabCompleter(new CustomRoleTabCompletion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
Player p = (Player) sender;
|
||||
|
||||
//LOAD PLAYER DATA
|
||||
UUID pID = p.getUniqueId();
|
||||
Map pData = (Map) Main.rolesData.getData(pID);
|
||||
|
||||
if(!p.hasPermission("AlathraWar.UseRoles")) {
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
|
||||
return false;
|
||||
}
|
||||
if(args.length == 0 || args[0].equalsIgnoreCase("help")) {
|
||||
p.sendMessage(ChatColor.RED + "! "+ ChatColor.RESET + ChatColor.GOLD + "---- Contracts Help ----");
|
||||
if (p.hasPermission("AlathraWar.Admin")) {
|
||||
p.sendMessage(ChatColor.RED + "! " + ChatColor.GREEN + "/contract list <player>");
|
||||
}
|
||||
else {
|
||||
p.sendMessage(ChatColor.RED + "! " + ChatColor.GREEN + "/contract list");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if(args[0].equalsIgnoreCase("list")) {
|
||||
UUID targetID;
|
||||
if(p.hasPermission("AlathraWar.Admin") && args.length > 1) {
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
String msgName;
|
||||
if(target != null) {
|
||||
targetID = target.getUniqueId();
|
||||
msgName = target.getDisplayName();
|
||||
}
|
||||
else {
|
||||
targetID = UUIDFetcher.getUUID(args[1]);
|
||||
if(targetID == null) {
|
||||
p.sendMessage(ChatColor.RED + "Please enter a valid player.");
|
||||
return false;
|
||||
}
|
||||
msgName = args[1];
|
||||
}
|
||||
}
|
||||
else {
|
||||
targetID = pID;
|
||||
}
|
||||
|
||||
if(targetID == null) {
|
||||
p.sendMessage("ERROR");
|
||||
return false;
|
||||
}
|
||||
Map tData = (Map) Main.rolesData.getData(targetID);
|
||||
Map<String, Object> tContracts = (Map<String, Object>) tData.get("Contracts");
|
||||
|
||||
if(tContracts.size() < 1) {
|
||||
if(pID == targetID) {
|
||||
p.sendMessage(ChatColor.GREEN + "You have " + ChatColor.GOLD + "0" + ChatColor.GREEN + " current contracts.");
|
||||
} else {
|
||||
p.sendMessage(ChatColor.GREEN + "They have " + ChatColor.GOLD + "0" + ChatColor.GREEN + " current contracts.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.sendMessage(ChatColor.GOLD + "Current Contracts:");
|
||||
for (String key : tContracts.keySet()) {
|
||||
Map<String,Object> Contract = (Map<String, Object>) tContracts.get(key);
|
||||
String ContractName = Bukkit.getOfflinePlayer(UUID.fromString(key)).getName();
|
||||
String ContractType = (String) Contract.get("Type");
|
||||
if(ContractType.equalsIgnoreCase("Assassin")) {
|
||||
p.sendMessage(ChatColor.GREEN + "- " + ContractName + " for " + ChatColor.DARK_PURPLE + Main.econ.format((double) Contract.get("Value")));
|
||||
}
|
||||
else if(ContractType.equalsIgnoreCase("Merc")) {
|
||||
p.sendMessage(ChatColor.GREEN + "- " + ContractName + " for " + ChatColor.DARK_AQUA + Main.econ.format((double) Contract.get("Value")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
p.sendMessage(ChatColor.RED + "Unknown sub-command. Do " + ChatColor.YELLOW + "/contract help" + ChatColor.RED + " for more info.");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package me.ShermansWorld.AlathraWar.roles;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public class CustomRoleTabCompletion implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
Map pData = (Map) Main.rolesData.getData(player.getUniqueId());
|
||||
|
||||
String cmdName = command.getName();
|
||||
List<String> completions = new ArrayList<>();
|
||||
if(cmdName.equalsIgnoreCase("mercenary")){
|
||||
if(args.length == 1) {
|
||||
completions.add("hire");
|
||||
if ((Boolean) pData.get("MercPermission")) {
|
||||
completions.add("accept");
|
||||
completions.add("decline");
|
||||
completions.add("complete");
|
||||
}
|
||||
if (player.hasPermission("AlathraWar.Admin")) {
|
||||
completions.add("add");
|
||||
completions.add("remove");
|
||||
}
|
||||
return completions;
|
||||
} else if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("add")) {
|
||||
return null;
|
||||
} else if (args[0].equalsIgnoreCase("remove")) {
|
||||
return null;
|
||||
} else if (args[0].equalsIgnoreCase("accept")) {
|
||||
// Get everyone who has a request
|
||||
return null;
|
||||
} else if (args[0].equalsIgnoreCase("decline")) {
|
||||
// Get everyone who has a request
|
||||
return null;
|
||||
} else if (args[0].equalsIgnoreCase("hire")) {
|
||||
return null;
|
||||
}
|
||||
return completions;
|
||||
} else if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("hire")) {
|
||||
completions.add("10000");
|
||||
completions.add("20000");
|
||||
completions.add("50000");
|
||||
completions.add("100000");
|
||||
return completions;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (cmdName.equalsIgnoreCase("assassin")) {
|
||||
if(args.length == 1) {
|
||||
completions.add("hire");
|
||||
if ((Boolean) pData.get("AssassinPermission")) {
|
||||
completions.add("accept");
|
||||
completions.add("decline");
|
||||
completions.add("complete");
|
||||
}
|
||||
if (player.hasPermission("AlathraWar.Admin")) {
|
||||
completions.add("add");
|
||||
completions.add("remove");
|
||||
}
|
||||
return completions;
|
||||
} else if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("add")) {
|
||||
return null;
|
||||
} else if (args[0].equalsIgnoreCase("remove")) {
|
||||
return null;
|
||||
} else if (args[0].equalsIgnoreCase("accept")) {
|
||||
// Get everyone who has a request
|
||||
return null;
|
||||
} else if (args[0].equalsIgnoreCase("decline")) {
|
||||
// Get everyone who has a request
|
||||
return null;
|
||||
} else if (args[0].equalsIgnoreCase("hire")) {
|
||||
return null;
|
||||
}
|
||||
return completions;
|
||||
} else if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("hire")) {
|
||||
completions.add("10000");
|
||||
completions.add("20000");
|
||||
completions.add("50000");
|
||||
completions.add("100000");
|
||||
return completions;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (cmdName.equalsIgnoreCase("contract")) {
|
||||
if(args.length == 1) {
|
||||
completions.add("list");
|
||||
return completions;
|
||||
}
|
||||
else if(args.length == 2) {
|
||||
if(player.hasPermission("AlathraWar.Admin")) {
|
||||
return null;
|
||||
} else {
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package me.ShermansWorld.AlathraWar.roles;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
|
||||
public class Merc {
|
||||
public static boolean hasMercRole(Player p) {
|
||||
Map userData = (Map) Main.rolesData.getData(p.getUniqueId());
|
||||
if ((Boolean) userData.get("MercPermission")) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,372 @@
|
||||
package me.ShermansWorld.AlathraWar.roles;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.UUIDFetcher;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public class MercCommand implements CommandExecutor {
|
||||
|
||||
public static Map<String, Object> ActiveMercRequests = new HashMap<String, Object>();
|
||||
|
||||
public MercCommand(final Main plugin) {
|
||||
plugin.getCommand("mercenary").setExecutor((CommandExecutor) this);
|
||||
plugin.getCommand("mercenary").setTabCompleter(new CustomRoleTabCompletion());
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
Player p = (Player) sender;
|
||||
|
||||
//LOAD PLAYER DATA
|
||||
UUID pID = p.getUniqueId();
|
||||
Map pData = (Map) Main.rolesData.getData(pID);
|
||||
//Bukkit.getLogger().info(Arrays.asList(pData).toString());
|
||||
|
||||
if(!p.hasPermission("AlathraWar.UseRoles")) {
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
|
||||
return false;
|
||||
}
|
||||
if(args.length == 0 || args[0].equalsIgnoreCase("help")) {
|
||||
p.sendMessage(ChatColor.RED + "! "+ ChatColor.RESET + ChatColor.GOLD + "---- Mercenary Help ----");
|
||||
p.sendMessage(ChatColor.RED + "! " + ChatColor.GREEN + "/mercenary hire <player> <price>");
|
||||
if ((Boolean) pData.get("MercPermission")) {
|
||||
p.sendMessage(ChatColor.RED + "! " + ChatColor.GREEN + "/mercenary accept <player>");
|
||||
p.sendMessage(ChatColor.RED + "! " + ChatColor.GREEN + "/mercenary decline <player>");
|
||||
}
|
||||
if (p.hasPermission("AlathraWar.Admin")) {
|
||||
p.sendMessage(ChatColor.RED + "! " + ChatColor.GREEN + "/mercenary add <player>");
|
||||
p.sendMessage(ChatColor.RED + "! " + ChatColor.GREEN + "/mercenary remove <player>");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if(args[0].equalsIgnoreCase("hire")) {
|
||||
// Valid number of arguments
|
||||
if (args.length < 3) {
|
||||
p.sendMessage(ChatColor.RED + "/mercenary hire <player> <price>");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Target Validator
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
if (!(target instanceof Player)) {
|
||||
p.sendMessage(ChatColor.RED + "Please enter a valid player.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Number Validator
|
||||
double val = 0;
|
||||
try {
|
||||
val = Double.parseDouble(args[2]);
|
||||
} catch (Exception e) {
|
||||
p.sendMessage(ChatColor.RED + "Please enter a valid price.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Minimum Price
|
||||
if (val < 10000) {
|
||||
p.sendMessage(ChatColor.DARK_RED + "You must comply with the minimum pricing of the server.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't have enough money.
|
||||
double pVal = Main.econ.getBalance(p);
|
||||
if (pVal < val) {
|
||||
p.sendMessage(ChatColor.DARK_RED + "You do not have a high enough balance.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
String targetStrID = target.getUniqueId().toString();
|
||||
Map TargetRequests = null;
|
||||
|
||||
Bukkit.getLogger().info(String.valueOf(ActiveMercRequests.containsKey(targetStrID)));
|
||||
if (ActiveMercRequests.containsKey(targetStrID)) {
|
||||
TargetRequests = (Map) ActiveMercRequests.get(targetStrID);
|
||||
} else {
|
||||
TargetRequests = new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
if (TargetRequests.containsKey(pID.toString())) {
|
||||
p.sendMessage(ChatColor.RED + "You already have a pending contract.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Map targetData = (Map) Main.rolesData.getData(target.getUniqueId());
|
||||
|
||||
if (targetData.containsKey(pID.toString())) {
|
||||
p.sendMessage(ChatColor.RED + "You already have a mercenary contract with this user.");
|
||||
return false;
|
||||
}
|
||||
if (!(Boolean) targetData.get("MercPermission")) {
|
||||
p.sendMessage(ChatColor.RED + "This user is not a mercenary.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Adding request to pending contracts
|
||||
Map contractData = new HashMap<String, String>();
|
||||
contractData.put("Value", val);
|
||||
TargetRequests.put(pID.toString(), contractData);
|
||||
ActiveMercRequests.put(targetStrID, TargetRequests);
|
||||
|
||||
// Messaging and logging
|
||||
p.sendMessage(ChatColor.GREEN + "You have requested a contract with " + target.getDisplayName() + " for " + ChatColor.YELLOW + Main.econ.format(val) + ".");
|
||||
target.sendMessage(p.getDisplayName() + ChatColor.GREEN + " has requested a contract worth " + ChatColor.YELLOW + Main.econ.format(val) + ".");
|
||||
Main.warLogger.log("User " + p.getName() + " requested mercenary work from " + p.getName() + ", value " + val);
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("accept")) {
|
||||
// Valid number of arguments
|
||||
if (args.length < 2) {
|
||||
p.sendMessage(ChatColor.RED + "/mercenary accept <player>");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Checks and defining target
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
if (!(target instanceof Player)) {
|
||||
p.sendMessage(ChatColor.RED + "Please enter a valid player.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Map MercRequests = (Map) ActiveMercRequests.get(pID.toString());
|
||||
if (MercRequests == null) {
|
||||
p.sendMessage(ChatColor.RED + "You do not have any pending contracts.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(MercRequests.isEmpty() || !MercRequests.containsKey(target.getUniqueId().toString())) {
|
||||
p.sendMessage(ChatColor.RED + "This player has not made any requests.");
|
||||
return false;
|
||||
}
|
||||
Map Request = (Map) MercRequests.get(target.getUniqueId().toString());
|
||||
|
||||
|
||||
if (!(Boolean) pData.get("MercPermission")) {
|
||||
p.sendMessage("You don't have merc perms?");
|
||||
return false;
|
||||
}
|
||||
|
||||
Map Contracts = (Map) pData.get("Contracts");
|
||||
if (Contracts.containsKey(target.getUniqueId().toString())) {
|
||||
p.sendMessage(ChatColor.RED + "You already have a contract with this person.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Adds contract to userdata
|
||||
Map ContractData = new HashMap<String, Object>();
|
||||
ContractData.put("Type", "Merc");
|
||||
ContractData.put("Value", Request.get("Value"));
|
||||
Contracts.put(target.getUniqueId().toString(), ContractData);
|
||||
|
||||
Main.rolesData.editData(pID, "Contracts", Contracts);
|
||||
|
||||
// Money Changes
|
||||
Double Value = (Double) Request.get("Value");
|
||||
Main.econ.withdrawPlayer(target, Value);
|
||||
Main.econ.depositPlayer(p, Value);
|
||||
|
||||
// Removes from ActiveMercRequests list
|
||||
MercRequests.remove(target.getUniqueId().toString());
|
||||
ActiveMercRequests.put(pID.toString(), MercRequests);
|
||||
|
||||
// Messaging and logging
|
||||
p.sendMessage(ChatColor.GREEN + "You have " + ChatColor.YELLOW + "accepted " + target.getDisplayName() + ChatColor.GREEN + "'s request.");
|
||||
target.sendMessage(ChatColor.GREEN + "Your request to " + p.getDisplayName() + ChatColor.GREEN + " has been "+ ChatColor.YELLOW + "accepted" + ChatColor.YELLOW + ".");
|
||||
Main.warLogger.log("User " + p.getName() + " accepted mercenary work for " + target.getName());
|
||||
return true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("decline") || args[0].equalsIgnoreCase("deny")) {
|
||||
// Valid number of arguments
|
||||
if (args.length < 2) {
|
||||
p.sendMessage(ChatColor.RED + "/mercenary decline <player>");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Checks and defining target
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
UUID targetID;
|
||||
String msgName;
|
||||
if(target != null) {
|
||||
targetID = target.getUniqueId();
|
||||
msgName = target.getDisplayName();
|
||||
}
|
||||
else {
|
||||
targetID = UUIDFetcher.getUUID(args[1]);
|
||||
if(targetID == null) {
|
||||
p.sendMessage(ChatColor.RED + "Please enter a valid player.");
|
||||
return false;
|
||||
}
|
||||
msgName = args[1];
|
||||
}
|
||||
|
||||
Map MercRequests = (Map) ActiveMercRequests.get(pID.toString());
|
||||
if (MercRequests == null) {
|
||||
p.sendMessage(ChatColor.RED + "You do not have any pending contracts.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(MercRequests.isEmpty() || !MercRequests.containsKey(targetID.toString())) {
|
||||
p.sendMessage(ChatColor.RED + "This player has not made any requests.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Removes from ActiveMercRequests list
|
||||
MercRequests.remove(targetID.toString());
|
||||
ActiveMercRequests.put(pID.toString(), MercRequests);
|
||||
|
||||
// Messaging and logging
|
||||
p.sendMessage(ChatColor.GREEN + "You have " + ChatColor.RED + "denied " + ChatColor.WHITE + msgName + ChatColor.GREEN + "'s request.");
|
||||
if(target != null) {
|
||||
target.sendMessage(ChatColor.GREEN + "Your request to " + p.getDisplayName() + ChatColor.GREEN + " has been "+ ChatColor.RED + "denied" + ChatColor.GREEN + ".");
|
||||
Main.warLogger.log("User " + p.getName() + " declined mercenary work for " + target.getName());
|
||||
}
|
||||
else {
|
||||
Main.warLogger.log("User " + p.getName() + " declined mercenary work for " + msgName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("add") && p.hasPermission("AlathraWar.Admin")) {
|
||||
// Valid number of arguments
|
||||
if (args.length < 2) {
|
||||
p.sendMessage(ChatColor.RED + "/mercenary add <player>");
|
||||
return false;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
UUID targetID;
|
||||
String msgName;
|
||||
if(target != null) {
|
||||
targetID = target.getUniqueId();
|
||||
msgName = target.getDisplayName();
|
||||
}
|
||||
else {
|
||||
targetID = UUIDFetcher.getUUID(args[1]);
|
||||
if(targetID == null) {
|
||||
p.sendMessage(ChatColor.RED + "Please enter a valid player.");
|
||||
return false;
|
||||
}
|
||||
msgName = args[1];
|
||||
}
|
||||
|
||||
// Gets data and re-writes
|
||||
Map targetData = (Map) Main.rolesData.getData(targetID);
|
||||
Boolean MercPerm = (Boolean) targetData.get("MercPermission");
|
||||
if (MercPerm) {
|
||||
p.sendMessage(ChatColor.RED + "This user already has mercenary permissions!");
|
||||
return false;
|
||||
}
|
||||
Main.rolesData.editData(targetID, "MercPermission", true);
|
||||
|
||||
// Messaging and logging
|
||||
p.sendMessage(ChatColor.GREEN + "User " + ChatColor.WHITE + msgName + ChatColor.YELLOW + " may " + ChatColor.GREEN + "accept mercenary work.");
|
||||
if(target != null) {
|
||||
target.sendMessage(ChatColor.GREEN + "You " + ChatColor.YELLOW + " may now " + ChatColor.GREEN + "accept mercenary work.");
|
||||
Main.warLogger.log("User " + p.getName() + " gave " + target.getName() + " mercenary permissions");
|
||||
}
|
||||
else {
|
||||
Main.warLogger.log("User " + p.getName() + " gave " + msgName + " mercenary permissions");
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("remove") && p.hasPermission("AlathraWar.Admin")) {
|
||||
// Valid number of arguments
|
||||
if (args.length < 2) {
|
||||
p.sendMessage(ChatColor.RED + "/mercenary remove <player>");
|
||||
return false;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
UUID targetID;
|
||||
String msgName;
|
||||
if(target != null) {
|
||||
targetID = target.getUniqueId();
|
||||
msgName = target.getDisplayName();
|
||||
}
|
||||
else {
|
||||
targetID = UUIDFetcher.getUUID(args[1]);
|
||||
if(targetID == null) {
|
||||
p.sendMessage(ChatColor.RED + "Please enter a valid player.");
|
||||
return false;
|
||||
}
|
||||
msgName = args[1];
|
||||
}
|
||||
|
||||
// Gets data and re-writes
|
||||
Map targetData = (Map) Main.rolesData.getData(targetID);
|
||||
Boolean MercPerm = (Boolean) targetData.get("MercPermission");
|
||||
if (!MercPerm) {
|
||||
p.sendMessage(ChatColor.RED + "This user has no mercenary permissions!");
|
||||
return false;
|
||||
}
|
||||
Main.rolesData.editData(targetID, "MercPermission", false);
|
||||
|
||||
// Messaging and logging
|
||||
p.sendMessage(ChatColor.GREEN + "User " + ChatColor.WHITE + msgName + ChatColor.RED + " may not " + ChatColor.GREEN + "accept mercenary work.");
|
||||
if(target != null) {
|
||||
target.sendMessage(ChatColor.GREEN + "You " + ChatColor.RED + " may no longer " + ChatColor.GREEN + "accept mercenary work.");
|
||||
Main.warLogger.log("User " + p.getName() + " removed " + target.getName() + "'s mercenary permissions");
|
||||
}
|
||||
else {
|
||||
Main.warLogger.log("User " + p.getName() + " removed " + msgName + "'s mercenary permissions");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("complete")) {
|
||||
// Valid number of arguments
|
||||
if (args.length < 2) {
|
||||
p.sendMessage(ChatColor.RED + "/mercenary complete <player>");
|
||||
return false;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
UUID targetID;
|
||||
String msgName;
|
||||
if(target != null) {
|
||||
targetID = target.getUniqueId();
|
||||
msgName = target.getDisplayName();
|
||||
}
|
||||
else {
|
||||
targetID = UUIDFetcher.getUUID(args[1]);
|
||||
if(targetID == null) {
|
||||
p.sendMessage(ChatColor.RED + "Please enter a valid player.");
|
||||
return false;
|
||||
}
|
||||
msgName = args[1];
|
||||
}
|
||||
|
||||
// Removal of contract from userdata
|
||||
Map Contracts = (Map) pData.get("Contracts");
|
||||
if (!Contracts.containsKey(targetID.toString())) {
|
||||
p.sendMessage(ChatColor.RED + "You have no contract with this user!");
|
||||
return false;
|
||||
}
|
||||
Contracts.remove(targetID.toString());
|
||||
Main.rolesData.editData(pID, "Contracts", Contracts);
|
||||
|
||||
// Messaging and logging
|
||||
p.sendMessage(ChatColor.GREEN + "You have " + ChatColor.GOLD + "completed " + ChatColor.WHITE + msgName + ChatColor.GREEN + "'s mercenary contract.");
|
||||
if(target != null) {
|
||||
target.sendMessage(ChatColor.GREEN + "Your contract with " + p.getDisplayName() + ChatColor.GREEN + " has been "+ ChatColor.GOLD + "completed" + ChatColor.GREEN + ".");
|
||||
Main.warLogger.log("User " + p.getName() + " completed " + target.getName() + "'s mercenary contract.");
|
||||
}
|
||||
else {
|
||||
Main.warLogger.log("User " + p.getName() + " completed " + msgName + "'s mercenary contract.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.sendMessage(ChatColor.RED + "Unknown sub-command. Do " + ChatColor.YELLOW + "/mercenary help" + ChatColor.RED + " for more info.");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user