mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 22:14:45 +00:00
refactor: wip update 3
This commit is contained in:
51 files changed
+3700
-2053
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,790 @@
|
||||
package me.ShermansWorld.AlathraWar.deprecated;
|
||||
|
||||
import com.palmergames.bukkit.towny.utils.NameUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Deprecated
|
||||
public class AdminTabCompletion implements TabCompleter {
|
||||
|
||||
List<String> base = List.of("create",
|
||||
"force",
|
||||
"help",
|
||||
"info",
|
||||
"modify",
|
||||
"purgebars",
|
||||
"load",
|
||||
"load-all",
|
||||
"save",
|
||||
"save-all",
|
||||
"item");
|
||||
|
||||
List<String> type = List.of(new String[]{
|
||||
"raid",
|
||||
"siege",
|
||||
"war"
|
||||
});
|
||||
|
||||
List<String> raidModify = List.of(new String[]{
|
||||
"score",
|
||||
"townspawn",
|
||||
"gather",
|
||||
"phase",
|
||||
"loot",
|
||||
"time",
|
||||
"owner"
|
||||
// ,
|
||||
// "move"
|
||||
// ,
|
||||
// "clearActive"
|
||||
});
|
||||
|
||||
List<String> siegeModify = List.of(new String[]{
|
||||
"score",
|
||||
"townspawn",
|
||||
"time",
|
||||
"owner"
|
||||
// ,
|
||||
// "move"
|
||||
});
|
||||
|
||||
List<String> warModify = List.of(new String[]{
|
||||
"score",
|
||||
"side",
|
||||
"name",
|
||||
"add",
|
||||
"surrender",
|
||||
"unsurrender",
|
||||
"raidTimeWar",
|
||||
"raidTimeTown"
|
||||
});
|
||||
|
||||
List<String> force = List.of(new String[]{
|
||||
"end",
|
||||
"join",
|
||||
"leave"
|
||||
});
|
||||
|
||||
List<String> addSet = List.of(new String[]{
|
||||
"add",
|
||||
"set"
|
||||
});
|
||||
|
||||
List<String> addSubSet = List.of(new String[]{
|
||||
"add",
|
||||
"subtract",
|
||||
"set"
|
||||
});
|
||||
|
||||
List<String> boolSet = List.of(new String[]{
|
||||
"true",
|
||||
"false"
|
||||
});
|
||||
|
||||
|
||||
List<String> addSetReset = List.of(new String[]{
|
||||
"add",
|
||||
"set",
|
||||
"reset"
|
||||
});
|
||||
|
||||
List<String> nationTown = List.of(new String[]{
|
||||
"town",
|
||||
"nation"
|
||||
});
|
||||
|
||||
List<String> lootSet = List.of(new String[]{
|
||||
"value",
|
||||
"looted",
|
||||
"ticks",
|
||||
"reset"
|
||||
});
|
||||
|
||||
List<String> empty = Collections.emptyList();
|
||||
|
||||
|
||||
/**
|
||||
* //done
|
||||
* //edit war/event in real time, side can be "both" to effect both
|
||||
* -modify raid score [war] [town] [add/set] [value]
|
||||
* -modify raid townspawn [war] [town] (x) (y) (Z)
|
||||
* -modify raid gather [war] [town] [town]
|
||||
* -modify raid phase [war] [town] [phase] //"next" to move to next phase
|
||||
* -modify raid loot [war] [town] [value,looted,ticks,reset] [amt] (x) (z) //no coords just does current chunk, reset deletes it from the list
|
||||
* -modify raid time [war] [town] [add/set] [value]
|
||||
* -modify raid owner [war] [town] [player]
|
||||
* -modify raid move [war] [town] [newWar] //low priority, moves raid to other war/ town
|
||||
* -modify raid clearActive [war] [town] //low priority
|
||||
* <p>
|
||||
* -modify siege score [war] [town] [side] [amt]
|
||||
* -modify siege townspawn [war] [town] (x) (Z)
|
||||
* -modify siege time [war] [town] [add/set/max] [value] //max modified the max length
|
||||
* -modify siege owner [war] [town] [add/set] [value]
|
||||
* -modify siege move [war] [town] [newWar] //low priority, moves siege to other war/town
|
||||
* <p>
|
||||
* -modify war score [war] [side] [amt]
|
||||
* -modify war side [war] [side] [name]
|
||||
* -modify war name [war] [name]
|
||||
* -modify war add town [war] [town]
|
||||
* -modify war add nation [war] [nation]
|
||||
* -modify war surrender town [war] [town] //adds town to surrender list
|
||||
* -modify war surrender nation [war] [town] //adds all towns to surrender list
|
||||
* -modify war raidTime [add,set,reset] [war] [town] [amt] //set when last raid was
|
||||
* <p>
|
||||
* // low priority idea
|
||||
* -info war score [war]
|
||||
* -info war surrenderedTowns [war]
|
||||
* -info war raids [war]
|
||||
* -info war sieges [war]
|
||||
* -info war towns [war]
|
||||
* -info war lastRaidTime [war]
|
||||
* <p>
|
||||
* -info raid homeblock [war] [town]
|
||||
* -info raid lootedTownBlocks [war] [town]
|
||||
* -info raid timeSinceLastRaid [town]
|
||||
* <p>
|
||||
* -info siege homeblock [war] [town]
|
||||
* <p>
|
||||
* //done
|
||||
* //force make event or war, if owner isn't defined, IDK haven't decided
|
||||
* -create siege [war] [town] (owner)
|
||||
* -create raid [war] [raidTown] (gatherTown) (owner)
|
||||
* -create war [name] [side1] [side2]
|
||||
* <p>
|
||||
* //force end a war/event, can declare winner side, or no winner
|
||||
* -force end war [war] (side/victor)
|
||||
* -force end siege [war] [town] (side/victor)
|
||||
* -force end raid [war] [town] (side/victor)
|
||||
* <p>
|
||||
* //done
|
||||
* //force player into or out of a war/event
|
||||
* -force join war [player] [war] [side]
|
||||
* -force join siege [player] [war] [town] (side)
|
||||
* -force join raid [player] [war] [town] (side)
|
||||
* <p>
|
||||
* //done
|
||||
* -force leave raid [war] [town] [player] (timeout) //kicks from raid party
|
||||
*
|
||||
* @param sender Source of the command. For players tab-completing a
|
||||
* command inside a command block, this will be the player, not
|
||||
* the command block.
|
||||
* @param command Command which was executed
|
||||
* @param label Alias of the command which was used
|
||||
* @param args The arguments passed to the command, including final
|
||||
* partial argument to be completed
|
||||
* @return list of options
|
||||
*/
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!sender.hasPermission("AlathraWar.admin")) {
|
||||
return empty;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
return base;
|
||||
} else if (args.length == 1) {
|
||||
return NameUtil.filterByStart(base, args[0]);
|
||||
} else {
|
||||
if (args[0].equalsIgnoreCase("purgebars")) {
|
||||
return empty;
|
||||
} else if (args[0].equalsIgnoreCase("save")) {
|
||||
if (args.length > 2) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[1]);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("save-all")) {
|
||||
return empty;
|
||||
} else if (args[0].equalsIgnoreCase("load")) {
|
||||
if (args.length > 2) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[1]);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("load-all")) {
|
||||
return empty;
|
||||
} else if (args[0].equalsIgnoreCase("item")) {
|
||||
if (args.length > 2) {
|
||||
if (args.length > 3) {
|
||||
if (args.length > 4) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[3]);
|
||||
}
|
||||
} else {
|
||||
return empty;
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarItems(), args[1]);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("create")) {
|
||||
if (args.length > 2) {
|
||||
switch (args[1]) {
|
||||
case "raid" -> {
|
||||
if (args.length > 3) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyWarTowns(args[2]), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyWarTowns(args[2]), args[3]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[2]);
|
||||
}
|
||||
}
|
||||
case "siege" -> {
|
||||
if (args.length > 3) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyWarTowns(args[2]), args[3]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[2]);
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(type, args[1]);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("force")) {
|
||||
if (args.length > 2) {
|
||||
if (args[1].equalsIgnoreCase("end")) {
|
||||
if (args.length > 3) {
|
||||
if (args[2].equalsIgnoreCase("raid")) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[3]), args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getRaidTowns(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
} else if (args[2].equalsIgnoreCase("siege")) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[3]), args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getSiegeTowns(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
} else if (args[2].equalsIgnoreCase("war")) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[3]), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(type, args[2]);
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("join")) {
|
||||
if (args.length > 3) {
|
||||
if (args[2].equalsIgnoreCase("raid")) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
if (args.length > 8) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(List.of(new String[]{"true", "false"}), args[7]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[4]), args[6]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getRaidTowns(), args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[3]);
|
||||
}
|
||||
} else if (args[2].equalsIgnoreCase("siege")) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
if (args.length > 8) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(List.of(new String[]{"true", "false"}), args[7]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[4]), args[6]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getSiegeTowns(), args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[3]);
|
||||
}
|
||||
} else if (args[2].equalsIgnoreCase("war")) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(List.of(new String[]{"true", "false"}), args[6]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[4]), args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[3]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(type, args[2]);
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("leave")) {
|
||||
if (args.length > 3) {
|
||||
if (args[2].equalsIgnoreCase("raid")) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getRaidTowns(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(List.of(new String[]{"raid"}), args[3]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(List.of(new String[]{"raid"}), args[2]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(force, args[1]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(force, args[1]);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("help")) {
|
||||
return empty;
|
||||
} else if (args[0].equalsIgnoreCase("info")) {
|
||||
if (args.length > 2) {
|
||||
if (args[1].equalsIgnoreCase("raid")) {
|
||||
if (args.length > 3) {
|
||||
if (args.length > 4) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getRaidTowns(), args[3]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[2]);
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("siege")) {
|
||||
if (args.length > 3) {
|
||||
if (args.length > 4) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getSiegeTowns(), args[3]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[2]);
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("war")) {
|
||||
if (args.length > 3) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[2]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(type, args[1]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(type, args[1]);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("awa")) {
|
||||
if (args.length > 2) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[1]);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("modify")) {
|
||||
if (args.length > 2) {
|
||||
if (args[1].equalsIgnoreCase("raid")) {
|
||||
if (args.length > 3) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
switch (args[2]) {
|
||||
/*
|
||||
* -modify raid score [war] [town] [add/subtract/set] [side] [value]
|
||||
* -modify raid townspawn [war] [town] (x) (y) (Z)
|
||||
* -modify raid gather [war] [town] [town]
|
||||
* -modify raid phase [war] [town] [phase] //"next" to move to next phase
|
||||
* -modify raid loot [war] [town] [value,looted,ticks,reset] [amt] (x) (z) //no coords just does current chunk, reset deletes it from the list
|
||||
* -modify raid time [war] [town] [add/set] [value]
|
||||
* -modify raid owner [war] [town] [player]
|
||||
* -modify raid move [war] [town] [newWar] //low priority, moves raid to other war/ town
|
||||
* -modify raid clearActive [war] [town] //low priority
|
||||
*/
|
||||
case "score" -> {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[3]), args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(addSubSet, args[5]);
|
||||
}
|
||||
}
|
||||
case "time" -> {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(addSet, args[5]);
|
||||
}
|
||||
}
|
||||
case "townspawn" -> {
|
||||
if (sender instanceof Player) {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
if (args.length > 8) {
|
||||
return empty;
|
||||
} else {
|
||||
return List.of(new String[]{String.valueOf(((Player) sender).getLocation().getZ())});
|
||||
}
|
||||
} else {
|
||||
return List.of(new String[]{String.valueOf(((Player) sender).getLocation().getY())});
|
||||
}
|
||||
} else {
|
||||
return List.of(new String[]{String.valueOf(((Player) sender).getLocation().getX())});
|
||||
}
|
||||
}
|
||||
}
|
||||
case "gather" -> {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getRaidTowns(), args[5]);
|
||||
}
|
||||
}
|
||||
case "phase" -> {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getRaidPhases(), args[5]);
|
||||
}
|
||||
}
|
||||
case "loot" -> {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
if (args.length > 8) {
|
||||
if (args.length > 9) {
|
||||
return empty;
|
||||
} else {
|
||||
return List.of(new String[]{String.valueOf(((Player) sender).getLocation().getZ())});
|
||||
}
|
||||
} else {
|
||||
return List.of(new String[]{String.valueOf(((Player) sender).getLocation().getX())});
|
||||
}
|
||||
} else {
|
||||
return empty;
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(lootSet, args[5]);
|
||||
}
|
||||
}
|
||||
case "owner" -> {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[5]);
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getRaidTowns(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(raidModify, args[2]);
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("siege")) {
|
||||
if (args.length > 3) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
switch (args[2]) {
|
||||
case "score", "time" -> {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(addSet, args[5]);
|
||||
}
|
||||
}
|
||||
case "townspawn" -> {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
if (args.length > 8) {
|
||||
return empty;
|
||||
} else {
|
||||
return List.of(new String[]{String.valueOf(((Player) sender).getLocation().getZ())});
|
||||
}
|
||||
} else {
|
||||
return List.of(new String[]{String.valueOf(((Player) sender).getLocation().getY())});
|
||||
}
|
||||
} else {
|
||||
return List.of(new String[]{String.valueOf(((Player) sender).getLocation().getX())});
|
||||
}
|
||||
}
|
||||
case "owner" -> {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[5]);
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getSiegeTowns(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(siegeModify, args[2]);
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("war")) {
|
||||
if (args.length > 3) {
|
||||
switch (args[2]) {
|
||||
/*
|
||||
* -modify war score [war] [side] [add/subtract/set] [amt]
|
||||
* -modify war side [war] [side] [name]
|
||||
* -modify war name [war] [name]
|
||||
* -modify war add [war] [side] [town/nation] [town/nation]
|
||||
* -modify war add nation [war] [nation]
|
||||
* -modify war surrender town [war] [town] //adds town to surrender list
|
||||
* -modify war surrender nation [war] [town] //adds all towns to surrender list
|
||||
* -modify war unsurrender [war] town/nation [town/nation]
|
||||
* -modify war unsurrender [war] town/nation [town/nation]
|
||||
* -modify war raidTimeTown [add,set,reset] [war] [town] [amt] //set when last raid was
|
||||
*/
|
||||
case "score" -> {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(addSubSet, args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[3]), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
}
|
||||
//alathrawaradmin modify war raidTimeTown [add,set,reset] [town/war] [amt] [side]
|
||||
case "raidTimeTown" -> {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(addSetReset, args[3]);
|
||||
}
|
||||
}
|
||||
//alathrawaradmin modify war raidTimeWar [add,set,reset] [war] [amt] [side]
|
||||
case "raidTimeWar" -> {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args[3].equalsIgnoreCase("reset")) {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[4]), args[5]);
|
||||
}
|
||||
} else {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[4]), args[6]);
|
||||
}
|
||||
} else {
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(addSetReset, args[3]);
|
||||
|
||||
}
|
||||
}
|
||||
case "side" -> {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[3]), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
}
|
||||
case "name" -> {
|
||||
if (args.length > 4) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
}
|
||||
case "add" -> {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
if (args.length > 8) {
|
||||
return empty;
|
||||
} else {
|
||||
return boolSet;
|
||||
}
|
||||
} else {
|
||||
if (args[5].equalsIgnoreCase("town")) {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[6]);
|
||||
} else if (args[5].equalsIgnoreCase("nation")) {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyNations(), args[6]);
|
||||
} else {
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(nationTown, args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[3]), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
}
|
||||
case "surrender" -> {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
return empty;
|
||||
} else {
|
||||
if (args[5].equalsIgnoreCase("town")) {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyWarTowns(args[3]), args[6]);
|
||||
} else if (args[5].equalsIgnoreCase("nation")) {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyWarNations(args[3]), args[6]);
|
||||
} else {
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(nationTown, args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[3]), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
}
|
||||
case "unsurrender" -> {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
if (args[4].equalsIgnoreCase("town")) {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyWarTowns(args[3]), args[5]);
|
||||
} else if (args[4].equalsIgnoreCase("nation")) {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyWarNations(args[3]), args[5]);
|
||||
} else {
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(nationTown, args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
return NameUtil.filterByStart(warModify, args[2]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(type, args[1]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(type, args[1]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(base, args[0]);
|
||||
}
|
||||
}
|
||||
return NameUtil.filterByStart(base, args[0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
package me.ShermansWorld.AlathraWar.deprecated;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import me.ShermansWorld.AlathraWar.*;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldRaid;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldWar;
|
||||
import me.ShermansWorld.AlathraWar.items.WarItemRegistry;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Deprecated
|
||||
public class CommandHelper {
|
||||
|
||||
/**
|
||||
* Grabs list of all war names
|
||||
*
|
||||
* @return list of wars
|
||||
*/
|
||||
public static List<String> getWarNames() {
|
||||
List<String> out = new ArrayList<>();
|
||||
for (OldWar w : WarData.getWars()) {
|
||||
out.add(w.getName());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs list of all sieges
|
||||
*
|
||||
* @return list of wars
|
||||
*/
|
||||
public static List<String> getSieges() {
|
||||
List<String> out = new ArrayList<>();
|
||||
for (OldSiege s : SiegeData.getSieges()) {
|
||||
out.add(s.getName());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs list of all raids
|
||||
*
|
||||
* @return list of wars
|
||||
*/
|
||||
public static List<String> getRaids() {
|
||||
List<String> out = new ArrayList<>();
|
||||
for (OldRaid r : RaidData.getRaids()) {
|
||||
out.add(r.getName());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs first matching war and lists the sides
|
||||
*
|
||||
* @param name name of war
|
||||
* @return side of war
|
||||
*/
|
||||
public static List<String> getWarSides(String name) {
|
||||
List<String> out = new ArrayList<>();
|
||||
for (OldWar w : WarData.getWars()) {
|
||||
if (w.getName().equalsIgnoreCase(name)) {
|
||||
out.add(w.getSide1());
|
||||
out.add(w.getSide2());
|
||||
break;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* getInstance list of all towny towns
|
||||
*
|
||||
* @return list of all towns
|
||||
*/
|
||||
public static List<String> getTownyTowns() {
|
||||
List<String> out = new ArrayList<>();
|
||||
for (Town t : TownyAPI.getInstance().getTowns()) {
|
||||
out.add(t.getName());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* getInstance list of all towny towns in a war
|
||||
*
|
||||
* @return list of all towns in a war
|
||||
*/
|
||||
public static List<String> getTownyWarTowns(String war) {
|
||||
List<String> out = new ArrayList<>();
|
||||
OldWar w = WarData.getWar(war);
|
||||
if (w == null) return Collections.emptyList();
|
||||
for (Town t : TownyAPI.getInstance().getTowns()) {
|
||||
if (w.getSide2Towns().contains(t.getName().toLowerCase()) || w.getSide1Towns().contains(t.getName().toLowerCase())) {
|
||||
out.add(t.getName());
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* getInstance list of all towny towns in a war
|
||||
*
|
||||
* @return list of all nations in a war
|
||||
*/
|
||||
public static List<String> getTownyWarNations(String war) {
|
||||
List<String> out = new ArrayList<>();
|
||||
OldWar w = WarData.getWar(war);
|
||||
if (w == null) return Collections.emptyList();
|
||||
for (Town t : TownyAPI.getInstance().getTowns()) {
|
||||
if (w.getSide2Towns().contains(t.getName().toLowerCase()) || w.getSide1Towns().contains(t.getName().toLowerCase())) {
|
||||
if (t.hasNation()) {
|
||||
try {
|
||||
out.add(t.getNation().getName());
|
||||
} catch (NotRegisteredException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* getInstance list of all towny towns on a side in a war
|
||||
*
|
||||
* @return list of all towns in a side of a war
|
||||
*/
|
||||
public static List<String> getTownyWarTowns(String war, String side) {
|
||||
List<String> out = new ArrayList<>();
|
||||
OldWar w = WarData.getWar(war);
|
||||
if (w == null) return Collections.emptyList();
|
||||
for (Town t : TownyAPI.getInstance().getTowns()) {
|
||||
if (side.equalsIgnoreCase(w.getSide1())) {
|
||||
if (w.getSide1Towns().contains(t.getName().toLowerCase())) {
|
||||
out.add(t.getName());
|
||||
}
|
||||
} else if (side.equalsIgnoreCase(w.getSide2())) {
|
||||
if (w.getSide2Towns().contains(t.getName().toLowerCase())) {
|
||||
out.add(t.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* return list of all towns in a raid
|
||||
*
|
||||
* @return list of all towns involved in a raid
|
||||
*/
|
||||
public static List<String> getRaidTowns() {
|
||||
List<String> out = new ArrayList<>();
|
||||
for (OldRaid r : RaidData.getRaids()) {
|
||||
out.add(r.getRaidedTown().getName());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* return list of all towns in a siege
|
||||
*
|
||||
* @return list of towns involved in a siege
|
||||
*/
|
||||
public static List<String> getSiegeTowns() {
|
||||
List<String> out = new ArrayList<>();
|
||||
for (OldSiege r : SiegeData.getSieges()) {
|
||||
out.add(r.getTown().getName());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* getInstance list of all towny nations
|
||||
*
|
||||
* @return list of all nations
|
||||
*/
|
||||
public static List<String> getTownyNations() {
|
||||
List<String> out = new ArrayList<>();
|
||||
for (Town t : TownyAPI.getInstance().getTowns()) {
|
||||
Nation n = t.getNationOrNull();
|
||||
if (n != null) {
|
||||
if (!out.contains(n.getName())) {
|
||||
out.add(n.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* getInstance a list of all online players
|
||||
*
|
||||
* @return list of all players online
|
||||
*/
|
||||
public static List<String> getPlayers() {
|
||||
Collection<? extends Player> players = Bukkit.getOnlinePlayers();
|
||||
List<String> out = new ArrayList<>();
|
||||
for (Player p : players) {
|
||||
out.add(p.getName());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* getInstance a list of all raid phases
|
||||
*
|
||||
* @return list of all raid phases
|
||||
*/
|
||||
public static List<String> getRaidPhases() {
|
||||
List<String> out = new ArrayList<>();
|
||||
for (RaidPhase ph : RaidPhase.values()) {
|
||||
out.add(ph.name());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player player to check
|
||||
* @return 0, 1, 2 (good to go, insufficient join, insufficient playtime)
|
||||
*/
|
||||
public static int isPlayerMinuteman(String player) {
|
||||
Resident res = TownyAPI.getInstance().getResident(player);
|
||||
if (res != null) {
|
||||
//getInstance registration time
|
||||
long regTime = res.getRegistered();
|
||||
int playTicks = Bukkit.getPlayer(res.getUUID()).getStatistic(Statistic.PLAY_ONE_MINUTE);
|
||||
int out = 0;
|
||||
if (Main.getInstance().getConfig().getInt("minimumPlayerAge") > 0) {
|
||||
//compare the join date, if they joined less that min age ago it is true
|
||||
if ((System.currentTimeMillis() - regTime) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge"))
|
||||
out = 1;
|
||||
}
|
||||
if (Main.getInstance().getConfig().getInt("minimumPlayTime") > 0) {
|
||||
//check playtime, if its less than min its true
|
||||
if (playTicks < (Main.getInstance().getConfig().getInt("minimumPlayTime") * (60 * 60 * 20))) out = 2;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
//if the player doesnt exist just return true
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* log the command
|
||||
*
|
||||
* @param sender sender
|
||||
* @param label command
|
||||
* @param args command args
|
||||
* @return success
|
||||
*/
|
||||
protected static void logCommand(CommandSender sender, String label, String[] args) {
|
||||
StringBuilder log = new StringBuilder(label);
|
||||
for (String s : args) {
|
||||
log.append(" ").append(s);
|
||||
}
|
||||
Main.warLogger.log(UtilsChat.getPrefix() + sender.getName() + " ran command: " + log);
|
||||
}
|
||||
|
||||
/**
|
||||
* return list of all alathrawar items with namespace
|
||||
*
|
||||
* @return list of all alathrawar items namespaced
|
||||
*/
|
||||
public static List<String> getWarItems() {
|
||||
return new ArrayList<>(WarItemRegistry.getInstance().getItemRegistry().keySet());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Manages file IO & Deletion for other data classes.
|
||||
*/
|
||||
@Deprecated
|
||||
public class DataManager {
|
||||
private static final String dataFolder = "plugins" + File.separator + "AlathraWar" + File.separator + "data";
|
||||
private static DumperOptions options;
|
||||
|
||||
public DataManager() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves data into a .yml format
|
||||
*
|
||||
* @param filePath - File's path after <PLUGIN>/Data/
|
||||
* @param map - Map to be saved
|
||||
*/
|
||||
public static void saveData(String filePath, HashMap<String, Object> map) {
|
||||
File file = getFile(filePath);
|
||||
if (file == null) return;
|
||||
|
||||
Bukkit.getLogger().log(Level.WARNING, "scoreboard.yml printout");
|
||||
Bukkit.getLogger().log(Level.WARNING, "Error Print isAbsolute: " + (file == null ? "" : file.isAbsolute()));
|
||||
Bukkit.getLogger().log(Level.WARNING, "Error Print isFile: " + (file == null ? "" : file.isFile()));
|
||||
Bukkit.getLogger().log(Level.WARNING, "Error Print canWrite: " + (file == null ? "" : file.canWrite()));
|
||||
Bukkit.getLogger().log(Level.WARNING, "Error Print exists: " + (file == null ? "" : file.exists()));
|
||||
Bukkit.getLogger().log(Level.WARNING, "Error Print canRead: " + (file == null ? "" : file.canRead()));
|
||||
Bukkit.getLogger().log(Level.WARNING, "Error Print isHidden: " + (file == null ? "" : file.isHidden()));
|
||||
Bukkit.getLogger().log(Level.WARNING, "Error Print path: " + (file == null ? "" : file.getPath()));
|
||||
PrintWriter writer;
|
||||
try {
|
||||
file.setWritable(true);
|
||||
writer = new PrintWriter(file);
|
||||
} catch (FileNotFoundException e) {
|
||||
Main.warLogger.log("Encountered FileNotFound error when creating PrintWriter for " + filePath);
|
||||
e.printStackTrace();
|
||||
return;
|
||||
} catch (NullPointerException e) {
|
||||
Main.warLogger.log("Encountered NullPointer error when creating PrintWriter for " + filePath);
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
if (options == null) {
|
||||
options = new DumperOptions();
|
||||
options.setIndent(2);
|
||||
options.setPrettyFlow(true);
|
||||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
}
|
||||
|
||||
Yaml yaml = new Yaml(options);
|
||||
yaml.dump(map, writer);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data back as a HashMap
|
||||
*
|
||||
* @param filePath - FilePath of data
|
||||
* @return HashMap of data or null
|
||||
*/
|
||||
public static HashMap<String, Object> getData(String filePath) {
|
||||
File file = getFile(filePath);
|
||||
return getData(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data back as a HashMap
|
||||
*
|
||||
* @param file - Data file
|
||||
* @return HashMap of data or null
|
||||
*/
|
||||
public static HashMap<String, Object> getData(File file) {
|
||||
if (!file.exists()) {
|
||||
Main.warLogger.log("Attempted to retrieve non-existant file: " + file.getPath());
|
||||
return null;
|
||||
}
|
||||
|
||||
InputStream inputStream;
|
||||
try {
|
||||
inputStream = new FileInputStream(file);
|
||||
} catch (FileNotFoundException e) {
|
||||
Main.warLogger.log("Encountered error when creating FileInputStream for " + file.getPath());
|
||||
return null;
|
||||
}
|
||||
Yaml yaml = new Yaml();
|
||||
HashMap<String, Object> data = yaml.load(inputStream);
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
Main.warLogger.log(e.getMessage());
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the specified file
|
||||
*
|
||||
* @param filePath - FilePath of deletion
|
||||
* @return Boolean of success
|
||||
*/
|
||||
public static boolean deleteFile(String filePath) {
|
||||
File file = getFile(filePath);
|
||||
|
||||
if (!file.exists()) {
|
||||
Main.warLogger.log("Attempted to retrieve non-existant file: " + filePath + ".yml");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
return Files.deleteIfExists(file.toPath());
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts filePath into File
|
||||
*
|
||||
* @param path - File's path within data folder
|
||||
* @return File or null
|
||||
*/
|
||||
private static File getFile(String path) {
|
||||
path = dataFolder + File.separator + path;
|
||||
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
Main.warLogger.log("Encountered error when creating file - " + path);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,603 @@
|
||||
package me.ShermansWorld.AlathraWar.deprecated;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.TownyUniverse;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import com.palmergames.bukkit.towny.object.*;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
import me.ShermansWorld.AlathraWar.enums.TownWarState;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.boss.BossBar;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Deprecated
|
||||
public class OldSiege {
|
||||
|
||||
public static final int maxSiegeTicks = 72000; // 60 minute tick constant
|
||||
public final NamespacedKey bossBarKey;
|
||||
public ArrayList<String> attackerPlayers;
|
||||
public ArrayList<String> defenderPlayers;
|
||||
public ArrayList<Location> beaconLocs;
|
||||
int[] bukkitId;
|
||||
private OldWar oldWar; // OldWar which siege belongs to
|
||||
private Town town; // Town of the siege
|
||||
private boolean side1AreAttackers; // bool of if side1 being attacker
|
||||
private int attackerPoints;
|
||||
private int defenderPoints;
|
||||
private OfflinePlayer siegeLeader;
|
||||
private int siegeTicks;
|
||||
private TownBlock homeBlock;
|
||||
private Location townSpawn;
|
||||
|
||||
|
||||
public OldSiege(final OldWar oldWar, final Town town, OfflinePlayer siegeLeader) {
|
||||
this.siegeTicks = 0;
|
||||
this.bukkitId = new int[1];
|
||||
this.attackerPlayers = new ArrayList<>();
|
||||
this.defenderPlayers = new ArrayList<>();
|
||||
this.beaconLocs = new ArrayList<>();
|
||||
this.oldWar = oldWar;
|
||||
this.town = town;
|
||||
this.siegeLeader = siegeLeader;
|
||||
|
||||
bossBarKey = new NamespacedKey(Main.getInstance(), "siegeBar." + this.getName());
|
||||
|
||||
side1AreAttackers = oldWar.getState(town.getName()) == TownWarState.SIDE2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a siege
|
||||
*/
|
||||
public void start() {
|
||||
attackerPoints = 0;
|
||||
defenderPoints = 0;
|
||||
this.siegeTicks = 0;
|
||||
homeBlock = town.getHomeBlockOrNull();
|
||||
townSpawn = town.getSpawnOrNull();
|
||||
|
||||
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), getTickLoop(), 0L, 200L);
|
||||
|
||||
setupDisplayBar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resumes a siege (after a server restart e.t.c.)
|
||||
*/
|
||||
public void resume(int resumeTick) {
|
||||
|
||||
siegeTicks = resumeTick;
|
||||
|
||||
homeBlock = town.getHomeBlockOrNull();
|
||||
townSpawn = town.getSpawnOrNull();
|
||||
|
||||
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), getTickLoop(), 0L, 200L);
|
||||
|
||||
setupDisplayBar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops a siege
|
||||
*/
|
||||
public void stop() {
|
||||
deleteDisplayBar();
|
||||
Bukkit.getScheduler().cancelTask(this.bukkitId[0]);
|
||||
this.oldWar.getSieges().remove(this);
|
||||
SiegeData.removeSiege(this);
|
||||
|
||||
}
|
||||
|
||||
private Runnable getTickLoop() {
|
||||
return new Runnable() {
|
||||
int homeBlockControl = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (homeBlock != null) {
|
||||
town.setHomeBlock(homeBlock);
|
||||
town.setSpawn(townSpawn);
|
||||
}
|
||||
if (OldSiege.this.side1AreAttackers) {
|
||||
OldSiege.this.attackerPlayers = OldSiege.this.oldWar.getSide1Players();
|
||||
OldSiege.this.defenderPlayers = OldSiege.this.oldWar.getSide2Players();
|
||||
} else {
|
||||
OldSiege.this.attackerPlayers = OldSiege.this.oldWar.getSide2Players();
|
||||
OldSiege.this.defenderPlayers = OldSiege.this.oldWar.getSide1Players();
|
||||
}
|
||||
if (OldSiege.this.siegeTicks >= maxSiegeTicks) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(OldSiege.this.bukkitId[0]);
|
||||
SiegeData.removeSiege(OldSiege.this);
|
||||
if (OldSiege.this.attackerPoints > OldSiege.this.defenderPoints) {
|
||||
OldSiege.this.attackersWin(OldSiege.this.siegeLeader);
|
||||
} else {
|
||||
OldSiege.this.defendersWin();
|
||||
}
|
||||
} else {
|
||||
boolean attackersAreOnHomeBlock = false;
|
||||
boolean defendersAreOnHomeBlock = false;
|
||||
siegeTicks = siegeTicks + 200;
|
||||
for (final String playerName : OldSiege.this.attackerPlayers) {
|
||||
Player pl = Main.getInstance().getServer().getPlayer(playerName);
|
||||
try {
|
||||
if (pl != null) {
|
||||
WorldCoord wc = WorldCoord.parseWorldCoord(pl);
|
||||
if (wc.getTownBlock().getTown().equals(town)) {
|
||||
if (town.getHomeBlockOrNull() != null) {
|
||||
if (town.getHomeBlockOrNull().getWorldCoord().equals(wc)) {
|
||||
if (!pl.isDead()) {
|
||||
if ((Math.abs(pl.getLocation().getBlockY() - townSpawn.getBlockY())) < 10) {
|
||||
attackersAreOnHomeBlock = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (NotRegisteredException ignored) {
|
||||
Main.warLogger.log(UtilsChat.getPrefix() + "Attempting to look for town at " + WorldCoord.parseWorldCoord(pl));
|
||||
}
|
||||
}
|
||||
for (final String playerName : OldSiege.this.defenderPlayers) {
|
||||
Player pl = Main.getInstance().getServer().getPlayer(playerName);
|
||||
try {
|
||||
if (pl != null) {
|
||||
WorldCoord wc = WorldCoord.parseWorldCoord(pl);
|
||||
if (wc.getTownBlock().getTown().equals(town)) {
|
||||
if (town.getHomeBlockOrNull() != null) {
|
||||
if (town.getHomeBlockOrNull().getWorldCoord().equals(wc)) {
|
||||
if (!pl.isDead()) {
|
||||
if ((Math.abs(pl.getLocation().getBlockY() - townSpawn.getBlockY())) <= 10) {
|
||||
defendersAreOnHomeBlock = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (NotRegisteredException ignored) {
|
||||
Main.warLogger.log(UtilsChat.getPrefix() + "Attempting to look for town at " + WorldCoord.parseWorldCoord(pl));
|
||||
}
|
||||
}
|
||||
if (attackersAreOnHomeBlock && defendersAreOnHomeBlock) { // Contested
|
||||
if (this.homeBlockControl != 1) {
|
||||
for (final String playerName : OldSiege.this.attackerPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(UtilsChat.getPrefix()
|
||||
+ "HomeBlock at " + OldSiege.this.town.getName() + " contested!");
|
||||
} catch (NullPointerException ex5) {
|
||||
}
|
||||
}
|
||||
for (final String playerName : OldSiege.this.defenderPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(UtilsChat.getPrefix()
|
||||
+ "HomeBlock at " + OldSiege.this.town.getName() + " contested!");
|
||||
} catch (NullPointerException ex6) {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.homeBlockControl = 1;
|
||||
} else if (attackersAreOnHomeBlock && !defendersAreOnHomeBlock) { // Attackers
|
||||
if (this.homeBlockControl != 2) {
|
||||
for (final String playerName : OldSiege.this.attackerPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(UtilsChat.getPrefix()
|
||||
+ "Attackers have captured the HomeBlock at "
|
||||
+ OldSiege.this.town.getName() + "! +1 Attacker Points per second");
|
||||
} catch (NullPointerException ex7) {
|
||||
}
|
||||
}
|
||||
for (final String playerName : OldSiege.this.defenderPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(UtilsChat.getPrefix()
|
||||
+ "Attackers have captured the HomeBlock at "
|
||||
+ OldSiege.this.town.getName() + "! +1 Attacker Points per second");
|
||||
} catch (NullPointerException ex8) {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.homeBlockControl = 2;
|
||||
OldSiege.this.addPointsToAttackers(10);
|
||||
} else { // Defenders / None
|
||||
if (this.homeBlockControl != 3) {
|
||||
for (final String playerName : OldSiege.this.attackerPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(UtilsChat.getPrefix()
|
||||
+ "Defenders retain control of the HomeBlock at "
|
||||
+ OldSiege.this.town.getName() + "! +1 Defender Points per second");
|
||||
} catch (NullPointerException ex9) {
|
||||
}
|
||||
}
|
||||
for (final String playerName : OldSiege.this.defenderPlayers) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(UtilsChat.getPrefix()
|
||||
+ "Defenders retain control of the HomeBlock at "
|
||||
+ OldSiege.this.town.getName() + "! +1 Defender Points per second");
|
||||
} catch (NullPointerException ex10) {
|
||||
}
|
||||
}
|
||||
}
|
||||
OldSiege.this.addPointsToDefenders(10);
|
||||
this.homeBlockControl = 3;
|
||||
}
|
||||
if (OldSiege.this.siegeTicks % 6000 == 0) { // Updates every 5 minutes
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "Report on the siege of "
|
||||
+ OldSiege.this.town.getName() + ":");
|
||||
Bukkit.broadcastMessage(
|
||||
"Attacker Points - " + OldSiege.this.attackerPoints);
|
||||
Bukkit.broadcastMessage(
|
||||
"Defender Points - " + OldSiege.this.defenderPoints);
|
||||
}
|
||||
if (siegeTicks % 1200 == 0) { // Saves every minute
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
refreshDisplayBar();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public void attackersWin(final OfflinePlayer siegeLeader) {
|
||||
final Resident resident = TownyAPI.getInstance().getResident(siegeLeader.getUniqueId());
|
||||
Nation nation = null;
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The attackers have won the siege of " + this.town.getName() + "!");
|
||||
try {
|
||||
nation = resident.getTown().getNation();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
if (nation != null) {
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The town of " + this.town.getName()
|
||||
+ " has been placed under occupation by " + nation.getName() + "!");
|
||||
}
|
||||
Main.econ.depositPlayer(siegeLeader, 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, "oldWar loot");
|
||||
} else {
|
||||
if (this.town.getAccount().getHoldingBalance() < 2500.0) {
|
||||
amt = this.town.getAccount().getHoldingBalance();
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The town of " + this.town.getName()
|
||||
+ " has been destroyed by " + this.getAttackerSide() + "!");
|
||||
TownyUniverse.getInstance().getDataSource().deleteTown(this.town);
|
||||
Main.econ.depositPlayer(siegeLeader, amt);
|
||||
return;
|
||||
}
|
||||
this.town.getAccount().withdraw(2500.0, "oldWar loot");
|
||||
amt = 2500.0;
|
||||
}
|
||||
Bukkit.broadcastMessage("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide()
|
||||
+ ", valuing $" + amt);
|
||||
Main.warLogger.log("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide()
|
||||
+ ", valuing $" + amt);
|
||||
Main.econ.depositPlayer(siegeLeader, amt);
|
||||
|
||||
if (side1AreAttackers) {
|
||||
oldWar.addSide1Points(50);
|
||||
} else {
|
||||
oldWar.addSide2Points(50);
|
||||
}
|
||||
|
||||
stop();
|
||||
clearBeacon();
|
||||
}
|
||||
|
||||
public void defendersWin() {
|
||||
this.town.getAccount().deposit(2500.0, "OldWar chest");
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The defenders have won the siege of " + this.town.getName() + "!");
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + this.town.getName()
|
||||
+ " has recovered the attackers' oldWar chest, valued at $2,500");
|
||||
Main.warLogger
|
||||
.log(oldWar.getName() + ": The defenders have won the siege of " + this.town.getName() + "!");
|
||||
|
||||
if (side1AreAttackers) {
|
||||
oldWar.addSide2Points(50);
|
||||
} else {
|
||||
oldWar.addSide1Points(50);
|
||||
}
|
||||
|
||||
stop();
|
||||
clearBeacon();
|
||||
}
|
||||
|
||||
/**
|
||||
* No winnder declared
|
||||
*/
|
||||
public void noWinner() {
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The siege of " + this.town.getName() + " was a draw!");
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "No money has been recovered.");
|
||||
Main.warLogger
|
||||
.log(oldWar.getName() + ": No one 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(), homeBlockX,
|
||||
homeBlockY - 2, homeBlockZ);
|
||||
while (beaconLoc.getBlock().getType().equals(Material.AIR)) {
|
||||
--homeBlockY;
|
||||
beaconLoc.setY(homeBlockY);
|
||||
}
|
||||
homeBlockY += 2;
|
||||
this.beaconLocs.add(new Location(world, homeBlockX, homeBlockY, homeBlockZ));
|
||||
this.beaconLocs
|
||||
.add(new Location(world, homeBlockX, homeBlockY + 1, homeBlockZ));
|
||||
this.beaconLocs
|
||||
.add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ));
|
||||
this.beaconLocs.add(
|
||||
new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ));
|
||||
this.beaconLocs.add(
|
||||
new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ));
|
||||
this.beaconLocs.add(
|
||||
new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ + 1));
|
||||
this.beaconLocs.add(
|
||||
new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ - 1));
|
||||
this.beaconLocs.add(new Location(world, homeBlockX + 1, homeBlockY - 1,
|
||||
homeBlockZ + 1));
|
||||
this.beaconLocs.add(new Location(world, homeBlockX + 1, homeBlockY - 1,
|
||||
homeBlockZ - 1));
|
||||
this.beaconLocs.add(new Location(world, homeBlockX - 1, homeBlockY - 1,
|
||||
homeBlockZ + 1));
|
||||
this.beaconLocs.add(new Location(world, homeBlockX - 1, homeBlockY - 1,
|
||||
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);
|
||||
}
|
||||
save();
|
||||
} catch (TownyException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
public void resetBeacon(World world, int homeBlockX, int homeBlockY, int homeBlockZ) {
|
||||
this.beaconLocs.add(new Location(world, homeBlockX, homeBlockY, homeBlockZ));
|
||||
this.beaconLocs.add(new Location(world, homeBlockX, homeBlockY + 1, homeBlockZ));
|
||||
this.beaconLocs.add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ));
|
||||
this.beaconLocs
|
||||
.add(new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ));
|
||||
this.beaconLocs
|
||||
.add(new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ));
|
||||
this.beaconLocs
|
||||
.add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ + 1));
|
||||
this.beaconLocs
|
||||
.add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ - 1));
|
||||
this.beaconLocs.add(
|
||||
new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ + 1));
|
||||
this.beaconLocs.add(
|
||||
new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ - 1));
|
||||
this.beaconLocs.add(
|
||||
new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ + 1));
|
||||
this.beaconLocs.add(
|
||||
new Location(world, homeBlockX - 1, homeBlockY - 1, 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 OldWar getWar() {
|
||||
return this.oldWar;
|
||||
}
|
||||
|
||||
public void setWar(final OldWar oldWar) {
|
||||
this.oldWar = oldWar;
|
||||
}
|
||||
|
||||
public Town getTown() {
|
||||
return this.town;
|
||||
}
|
||||
|
||||
public void setTown(final Town town) {
|
||||
this.town = town;
|
||||
}
|
||||
|
||||
public OfflinePlayer getSiegeOwner() {
|
||||
return siegeLeader;
|
||||
}
|
||||
|
||||
public void setSiegeOwner(OfflinePlayer siegeOwner) {
|
||||
this.siegeLeader = siegeOwner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets attacker name string
|
||||
*/
|
||||
public String getAttackerSide() {
|
||||
if (side1AreAttackers) {
|
||||
return oldWar.getSide1();
|
||||
} else {
|
||||
return oldWar.getSide2();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets defender name string
|
||||
*/
|
||||
public String getDefenderSide() {
|
||||
if (side1AreAttackers) {
|
||||
return oldWar.getSide2();
|
||||
} else {
|
||||
return oldWar.getSide1();
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshDisplayBar() {
|
||||
BossBar bossBar = Bukkit.getBossBar(bossBarKey);
|
||||
if (bossBar == null) bossBar = createNewDisplayBar();
|
||||
|
||||
bossBar.setTitle(String.format("%d -- Attackers -OldSiege Score- Defenders -- %d", this.attackerPoints, this.defenderPoints));
|
||||
bossBar.setProgress((this.attackerPoints + 0.5D) / ((this.attackerPoints + this.defenderPoints) + 1.0D));
|
||||
|
||||
for (String s : this.getAttackerPlayers()) {
|
||||
Player p = Bukkit.getPlayer(s);
|
||||
if (p != null) {
|
||||
if (!bossBar.getPlayers().contains(p)) bossBar.addPlayer(p);
|
||||
}
|
||||
}
|
||||
|
||||
for (String s : this.getDefenderPlayers()) {
|
||||
Player p = Bukkit.getPlayer(s);
|
||||
if (p != null) {
|
||||
if (!bossBar.getPlayers().contains(p)) bossBar.addPlayer(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setupDisplayBar() {
|
||||
BossBar bossBar = Bukkit.getBossBar(bossBarKey);
|
||||
if (bossBar == null) bossBar = createNewDisplayBar();
|
||||
|
||||
for (String s : this.getAttackerPlayers()) {
|
||||
Player p = Bukkit.getPlayer(s);
|
||||
if (p != null) {
|
||||
bossBar.addPlayer(p);
|
||||
}
|
||||
}
|
||||
|
||||
for (String s : this.getDefenderPlayers()) {
|
||||
Player p = Bukkit.getPlayer(s);
|
||||
if (p != null) bossBar.addPlayer(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteDisplayBar() {
|
||||
BossBar bossBar = Bukkit.getBossBar(bossBarKey);
|
||||
if (bossBar != null) {
|
||||
bossBar.removeAll();
|
||||
}
|
||||
Bukkit.removeBossBar(bossBarKey);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public BossBar createNewDisplayBar() {
|
||||
return Bukkit.createBossBar(bossBarKey, String.format("%d -- Attackers -OldSiege Score- Defenders -- %d", this.attackerPoints, this.defenderPoints), BarColor.YELLOW, BarStyle.SOLID);
|
||||
}
|
||||
|
||||
public int getAttackerPoints() {
|
||||
return this.attackerPoints;
|
||||
}
|
||||
|
||||
public void setAttackerPoints(int points) {
|
||||
this.attackerPoints = points;
|
||||
}
|
||||
|
||||
public int getDefenderPoints() {
|
||||
return this.defenderPoints;
|
||||
}
|
||||
|
||||
public void setDefenderPoints(int points) {
|
||||
this.defenderPoints = points;
|
||||
}
|
||||
|
||||
public int getMaxSiegeTicks() {
|
||||
return maxSiegeTicks;
|
||||
}
|
||||
|
||||
public TownBlock getHomeBlock() {
|
||||
return homeBlock;
|
||||
}
|
||||
|
||||
public void setHomeBlock(TownBlock homeBlock) {
|
||||
this.homeBlock = homeBlock;
|
||||
}
|
||||
|
||||
public Location getTownSpawn() {
|
||||
return townSpawn;
|
||||
}
|
||||
|
||||
public void setTownSpawn(Location townSpawn) {
|
||||
this.townSpawn = townSpawn;
|
||||
}
|
||||
|
||||
public boolean getSide1AreAttackers() {
|
||||
return this.side1AreAttackers;
|
||||
}
|
||||
|
||||
public void setSide1AreAttackers(final boolean side1AreAttackers) {
|
||||
this.side1AreAttackers = side1AreAttackers;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public int getSiegeTicks() {
|
||||
return siegeTicks;
|
||||
}
|
||||
|
||||
public void setSiegeTicks(int siegeTicks) {
|
||||
this.siegeTicks = siegeTicks;
|
||||
}
|
||||
|
||||
public OfflinePlayer getSiegeLeader() {
|
||||
return siegeLeader;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
SiegeData.saveSiege(this);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.getWar().getName() + "-" + this.getTown();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,340 @@
|
||||
package me.ShermansWorld.AlathraWar.deprecated;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.data.DataManager;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
import me.ShermansWorld.AlathraWar.enums.TownWarState;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Deprecated
|
||||
public class OldWar {
|
||||
|
||||
// References
|
||||
private final ArrayList<OldSiege> oldSieges = new ArrayList<>();
|
||||
private final ArrayList<OldRaid> oldRaids = new ArrayList<>();
|
||||
// Object Fields
|
||||
private final UUID uuid; // TODO Actually convert to using UUID for identifying this war
|
||||
private String name;
|
||||
private String side1;
|
||||
private String side2;
|
||||
private ArrayList<String> side1Towns = new ArrayList<>();
|
||||
private ArrayList<String> side2Towns = new ArrayList<>();
|
||||
private ArrayList<String> surrenderedTowns = new ArrayList<>();
|
||||
private int side1Points = 0;
|
||||
private int side2Points = 0;
|
||||
private int lastRaidTimeSide1 = 0;
|
||||
private int lastRaidTimeSide2 = 0;
|
||||
|
||||
/**
|
||||
* OldWar Constructor
|
||||
*
|
||||
* @param name - Name of war
|
||||
* @param side1 - Side 1 name
|
||||
* @param side2 - Side 2 name
|
||||
*/
|
||||
public OldWar(final String name, final String side1, final String side2) {
|
||||
this.uuid = generateUUID();
|
||||
this.name = name;
|
||||
this.side1 = side1;
|
||||
this.side2 = side2;
|
||||
}
|
||||
|
||||
private static ArrayList<String> townListToPlayers(ArrayList<String> townList) {
|
||||
ArrayList<String> returnList = new ArrayList<>();
|
||||
for (String townString : townList) {
|
||||
Town town = TownyAPI.getInstance().getTown(townString);
|
||||
if (town != null) {
|
||||
for (Resident res : town.getResidents()) {
|
||||
//Minuteman countermeasure! if they are they getInstance skipped
|
||||
if (CommandHelper.isPlayerMinuteman(res.getName()) == 0) {
|
||||
returnList.add(res.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
private UUID generateUUID() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
|
||||
while (WarData.getWar(uuid) != null) {
|
||||
uuid = UUID.randomUUID();
|
||||
}
|
||||
|
||||
return UUID.randomUUID();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a nation to a side of the war
|
||||
*
|
||||
* @param nation - Nation object
|
||||
* @param side - Side name
|
||||
*/
|
||||
public void addNation(final Nation nation, String side) {
|
||||
for (Town town : nation.getTowns()) {
|
||||
addTown(town.getName(), side);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a town to a side of the war
|
||||
*
|
||||
* @param town - Town object
|
||||
* @param side - Side name
|
||||
*/
|
||||
public void addTown(final Town town, String side) {
|
||||
addTown(town.getName(), side);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a town to a side of the war
|
||||
*
|
||||
* @param town - Town object
|
||||
* @param side - Side name
|
||||
*/
|
||||
public void addTown(final String town, String side) {
|
||||
if (side1.equalsIgnoreCase(side)) {
|
||||
if (!side1Towns.contains(town.toLowerCase())) {
|
||||
side1Towns.add(town.toLowerCase());
|
||||
Main.warLogger.log("Town " + town + " joined " + this.name + " on " + side);
|
||||
return;
|
||||
}
|
||||
} else if (side2.equalsIgnoreCase(side)) {
|
||||
if (!side2Towns.contains(town.toLowerCase())) {
|
||||
side2Towns.add(town.toLowerCase());
|
||||
Main.warLogger.log("Town " + town + " joined " + this.name + " on " + side);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Main.warLogger.log("Town " + town + " failed to join " + this.name + " on " + side);
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrenders town
|
||||
*
|
||||
* @param nation - Nation to surrender
|
||||
*/
|
||||
public void surrenderNation(Nation nation) {
|
||||
if (nation != null) {
|
||||
for (Town town : nation.getTowns()) {
|
||||
surrenderTown(town.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrenders town
|
||||
*
|
||||
* @param town - Town to surrender
|
||||
*/
|
||||
public void surrenderTown(String town) {
|
||||
side1Towns.remove(town);
|
||||
side2Towns.remove(town);
|
||||
surrenderedTowns.add(town);
|
||||
}
|
||||
|
||||
/**
|
||||
* unsurrender town, perfidy time
|
||||
*
|
||||
* @param nation - Nation to unsurrender
|
||||
*/
|
||||
public void unSurrenderNation(Nation nation) {
|
||||
for (Town town : nation.getTowns()) {
|
||||
unSurrenderTown(town.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* unsurrender town, perfidy time
|
||||
*
|
||||
* @param town - Town to unsurrender
|
||||
*/
|
||||
public void unSurrenderTown(String town) {
|
||||
surrenderedTowns.remove(town);
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets side of town
|
||||
* -1 - Surrendered
|
||||
* 0 - None
|
||||
* 1 - Side 1
|
||||
* 2 - Side 2
|
||||
*
|
||||
* @param string town
|
||||
* @return result
|
||||
*/
|
||||
public TownWarState getState(String string) {
|
||||
for (String str : surrenderedTowns) {
|
||||
if (str.equalsIgnoreCase(string)) return TownWarState.SURRENDERED;
|
||||
}
|
||||
|
||||
for (String str : side1Towns) {
|
||||
if (str.equalsIgnoreCase(string)) return TownWarState.SIDE1;
|
||||
}
|
||||
|
||||
for (String str : side2Towns) {
|
||||
if (str.equalsIgnoreCase(string)) return TownWarState.SIDE2;
|
||||
}
|
||||
return TownWarState.NOT_PARTICIPANT;
|
||||
}
|
||||
|
||||
public TownWarState getState(Town town) {
|
||||
return getState(town.getName());
|
||||
}
|
||||
|
||||
public boolean isSideValid(String side) {
|
||||
return getSides().contains(side);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
DataManager.deleteFile("wars" + File.separator + this.getName() + ".yml");
|
||||
this.name = name;
|
||||
this.save();
|
||||
}
|
||||
|
||||
public List<String> getSides() {
|
||||
return List.of(getSide1(), getSide2());
|
||||
}
|
||||
|
||||
public String getSide1() {
|
||||
return this.side1;
|
||||
}
|
||||
|
||||
public void setSide1(String side1) {
|
||||
this.side1 = side1;
|
||||
}
|
||||
|
||||
public String getSide2() {
|
||||
return this.side2;
|
||||
}
|
||||
|
||||
public void setSide2(String side2) {
|
||||
this.side2 = side2;
|
||||
}
|
||||
|
||||
public ArrayList<String> getSide1Towns() {
|
||||
return this.side1Towns;
|
||||
}
|
||||
|
||||
public void setSide1Towns(final ArrayList<String> side1Towns) {
|
||||
this.side1Towns = side1Towns;
|
||||
}
|
||||
|
||||
public ArrayList<String> getSide2Towns() {
|
||||
return this.side2Towns;
|
||||
}
|
||||
|
||||
public void setSide2Towns(final ArrayList<String> side2Towns) {
|
||||
this.side2Towns = side2Towns;
|
||||
}
|
||||
|
||||
public ArrayList<String> getSurrenderedTowns() {
|
||||
return surrenderedTowns;
|
||||
}
|
||||
|
||||
public void setSurrenderedTowns(ArrayList<String> towns) {
|
||||
surrenderedTowns = towns;
|
||||
}
|
||||
|
||||
public ArrayList<OldSiege> getSieges() {
|
||||
return oldSieges;
|
||||
}
|
||||
|
||||
public void addSiege(OldSiege oldSiege) {
|
||||
oldSieges.add(oldSiege);
|
||||
}
|
||||
|
||||
public ArrayList<OldRaid> getRaids() {
|
||||
return oldRaids;
|
||||
}
|
||||
|
||||
public void addRaid(OldRaid oldRaid) {
|
||||
oldRaids.add(oldRaid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the war into .yml file folders.
|
||||
*/
|
||||
public void save() {
|
||||
WarData.saveWar(this);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name + "[" + side1 + "." + side2 + "]("
|
||||
+ side1Towns.size() + "/" + side2Towns.size() + "/" +
|
||||
surrenderedTowns.size() + ")";
|
||||
}
|
||||
|
||||
public ArrayList<String> getSide1Players() {
|
||||
return townListToPlayers(side1Towns);
|
||||
}
|
||||
|
||||
public ArrayList<String> getSide2Players() {
|
||||
return townListToPlayers(side2Towns);
|
||||
}
|
||||
|
||||
public int getLastRaidTimeSide1() {
|
||||
return this.lastRaidTimeSide1;
|
||||
}
|
||||
|
||||
public void setLastRaidTimeSide1(int lastRaidTime) {
|
||||
this.lastRaidTimeSide1 = lastRaidTime;
|
||||
}
|
||||
|
||||
public int getLastRaidTimeSide2() {
|
||||
return this.lastRaidTimeSide2;
|
||||
}
|
||||
|
||||
public void setLastRaidTimeSide2(int lastRaidTime) {
|
||||
this.lastRaidTimeSide2 = lastRaidTime;
|
||||
}
|
||||
|
||||
public int getSide1Points() {
|
||||
return this.side1Points;
|
||||
}
|
||||
|
||||
public void setSide1Points(int side1Points) {
|
||||
this.side1Points = side1Points;
|
||||
}
|
||||
|
||||
public int getSide2Points() {
|
||||
return this.side2Points;
|
||||
}
|
||||
|
||||
public void setSide2Points(int side2Points) {
|
||||
this.side2Points = side2Points;
|
||||
}
|
||||
|
||||
public void addSide1Points(int points) {
|
||||
side1Points += points;
|
||||
}
|
||||
|
||||
public void addSide2Points(int points) {
|
||||
side2Points += points;
|
||||
}
|
||||
|
||||
public boolean equals(OldWar oldWar) {
|
||||
return getUUID().equals(oldWar.getUUID());
|
||||
}
|
||||
|
||||
public boolean equals(UUID uuid) {
|
||||
return getUUID().equals(uuid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import com.palmergames.bukkit.towny.object.metadata.CustomDataField;
|
||||
import com.palmergames.bukkit.towny.object.metadata.LongDataField;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldRaid;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldWar;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.*;
|
||||
|
||||
@Deprecated
|
||||
public class RaidData {
|
||||
// Static OldRaid list for all active OLD_RAIDS
|
||||
private static final ArrayList<OldRaid> OLD_RAIDS = new ArrayList<>();
|
||||
|
||||
|
||||
public static ArrayList<OldRaid> getRaids() {
|
||||
return OLD_RAIDS;
|
||||
}
|
||||
|
||||
public static void setRaids(ArrayList<OldRaid> oldRaids) {
|
||||
for (OldRaid oldRaid : oldRaids) {
|
||||
addRaid(oldRaid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a raid with a specific name
|
||||
*
|
||||
* @param name - Name to check
|
||||
* @return OldRaid or Null
|
||||
*/
|
||||
public static @Nullable OldRaid getRaid(String name) {
|
||||
for (OldRaid oldRaid : OLD_RAIDS) {
|
||||
if (oldRaid.getName().equalsIgnoreCase(name)) return oldRaid;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void addRaid(OldRaid oldRaid) {
|
||||
if (oldRaid == null) {
|
||||
Main.warLogger.log("Attempted to add NULL to oldRaid list.");
|
||||
return;
|
||||
}
|
||||
OLD_RAIDS.add(oldRaid);
|
||||
}
|
||||
|
||||
public static void removeRaid(OldRaid oldRaid) {
|
||||
oldRaid.getWar().getRaids().remove(oldRaid);
|
||||
OLD_RAIDS.remove(oldRaid);
|
||||
|
||||
//deleteRaid(oldRaid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a raid object from a provided HashMap
|
||||
*
|
||||
* @param fileData
|
||||
* @return OldRaid object
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static OldRaid fromMap(OldWar oldWar, HashMap<String, Object> fileData) {
|
||||
|
||||
if (fileData.get("raidedTown") == null || fileData.get("gatherTown") == null || fileData.get("side1AreRaiders") == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Town raidedTown = TownyAPI.getInstance().getTown((String) fileData.get("raidedTown"));
|
||||
Town gatherTown = TownyAPI.getInstance().getTown((String) fileData.get("gatherTown"));
|
||||
boolean attackBoolean = Boolean.parseBoolean((String) fileData.get("side1AreRaiders"));
|
||||
//THIS MAY OR MAY NOT WORK
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString((String) fileData.get("owner")));
|
||||
|
||||
if (raidedTown == null || gatherTown == null) {
|
||||
return null;
|
||||
}
|
||||
OldRaid oldRaid = new OldRaid(oldWar, raidedTown, gatherTown, attackBoolean, offlinePlayer);
|
||||
|
||||
//Extra properties, if any are missing the oldRaid doesnt exist yet
|
||||
if (fileData.get("raiderScore") != null && fileData.get("defenderScore") != null && fileData.get("raidTicks") != null && fileData.get("raidPhase") != null && fileData.get("activeRaiders") != null && fileData.get("lootedChunks") != null && fileData.get("side1AreRaiders") != null) {
|
||||
//active properties
|
||||
oldRaid.setRaidPhase(RaidPhase.getByName((String) fileData.get("raidPhase")));
|
||||
oldRaid.setRaidTicks((int) fileData.get("raidTicks"));
|
||||
oldRaid.setActiveRaiders((ArrayList<String>) fileData.get("activeRaiders"));
|
||||
oldRaid.setRaiderScore((int) fileData.get("raiderScore"));
|
||||
oldRaid.setDefenderScore((int) fileData.get("defenderScore"));
|
||||
oldRaid.setSide1AreRaiders(Boolean.parseBoolean((String) fileData.get("side1AreRaiders")));
|
||||
|
||||
//looted chunks
|
||||
ArrayList<Object> o = (ArrayList<Object>) fileData.get("lootedChunks");
|
||||
for (Object hm : o) {
|
||||
//grab the chunk
|
||||
HashMap<String, Object> chunk = (HashMap<String, Object>) hm;
|
||||
|
||||
//grab data for this chunk
|
||||
//worldcoord is its own map
|
||||
HashMap<String, Object> wc = (HashMap<String, Object>) chunk.get("worldCoord");
|
||||
WorldCoord worldCoordc = WorldCoord.parseWorldCoord((String) wc.get("world"), ((int) wc.get("x")), ((int) wc.get("z")));
|
||||
int ticks = (int) chunk.get("ticks");
|
||||
double value = (double) chunk.get("value");
|
||||
boolean finished = (boolean) chunk.get("finished");
|
||||
|
||||
//put
|
||||
OldRaid.LootBlock lb = new OldRaid.LootBlock(worldCoordc, ticks, value, finished);
|
||||
oldRaid.getLootedChunks().put(worldCoordc, lb);
|
||||
}
|
||||
}
|
||||
|
||||
return oldRaid;
|
||||
}
|
||||
|
||||
public static ArrayList<OldRaid> createRaids(OldWar oldWar, Collection<HashMap<String, Object>> raidMaps) {
|
||||
ArrayList<OldRaid> returnList = new ArrayList<>();
|
||||
for (HashMap<String, Object> map : raidMaps) {
|
||||
Town town = TownyAPI.getInstance().getTown((String) map.get("raidedTown"));
|
||||
if (town == null) continue;
|
||||
|
||||
OldRaid oldRaid = fromMap(oldWar, map);
|
||||
returnList.add(oldRaid);
|
||||
RaidData.addRaid(oldRaid);
|
||||
oldRaid.resume();
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves the war into files.
|
||||
*
|
||||
* @param oldRaid - OldWar to be saved.
|
||||
*/
|
||||
public static void saveRaid(OldRaid oldRaid) {
|
||||
OldWar oldWar = oldRaid.getWar();
|
||||
oldWar.save();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * deletes raid, unused
|
||||
// */
|
||||
// private static void deleteRaid(OldWar war) {
|
||||
// File[] files = new File(dataFolderPath + File.separator + "wars").listFiles(ymlFilter);
|
||||
//
|
||||
// for (File file : files) {
|
||||
// if (file.getName().startsWith(war.getName())) {
|
||||
// file.delete();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Turns a oldRaid into a map
|
||||
*
|
||||
* @param oldRaid - OldRaid
|
||||
* @return Map
|
||||
*/
|
||||
public static HashMap<String, Object> raidToMap(OldRaid oldRaid) {
|
||||
HashMap<String, Object> returnMap = new HashMap<>();
|
||||
// Shoves everything into a map.
|
||||
returnMap.put("name", oldRaid.getName());
|
||||
returnMap.put("raidedTown", oldRaid.getRaidedTown().getName());
|
||||
returnMap.put("gatherTown", oldRaid.getGatherTown().getName());
|
||||
returnMap.put("raidTicks", oldRaid.getRaidTicks());
|
||||
returnMap.put("raidPhase", oldRaid.getPhase().name());
|
||||
returnMap.put("raiderScore", oldRaid.getRaiderScore());
|
||||
returnMap.put("defenderScore", oldRaid.getDefenderScore());
|
||||
returnMap.put("side1AreRaiders", Boolean.toString(oldRaid.getSide1AreRaiders()));
|
||||
returnMap.put("activeRaiders", oldRaid.getActiveRaiders());
|
||||
//THIS MAY OR MAY NOT WORK
|
||||
returnMap.put("owner", oldRaid.getOwner().getUniqueId().toString());
|
||||
|
||||
//create a list from the looted chunks
|
||||
final List<Object> chunkList = getChunkList(oldRaid);
|
||||
|
||||
returnMap.put("lootedChunks", chunkList);
|
||||
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<Object> getChunkList(OldRaid oldRaid) {
|
||||
List<Object> chunkList = new ArrayList<>();
|
||||
for (OldRaid.LootBlock b : oldRaid.getLootedChunks().values()) {
|
||||
HashMap<String, Object> blockMap = new HashMap<>();
|
||||
//worldcoord
|
||||
HashMap<String, Object> wcMap = new HashMap<>();
|
||||
wcMap.put("world", b.worldCoord.getWorldName());
|
||||
wcMap.put("x", b.worldCoord.getCoord().getX());
|
||||
wcMap.put("z", b.worldCoord.getCoord().getZ());
|
||||
blockMap.put("worldCoord", wcMap);
|
||||
//properties
|
||||
blockMap.put("ticks", b.ticks);
|
||||
blockMap.put("value", b.value);
|
||||
blockMap.put("finished", b.finished);
|
||||
chunkList.add(blockMap);
|
||||
}
|
||||
return chunkList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a map of raid maps
|
||||
*
|
||||
* @param oldWar - OldWar to map
|
||||
* @return Map of Maps
|
||||
*/
|
||||
public static HashMap<String, Object> getRaidMap(OldWar oldWar) {
|
||||
HashMap<String, Object> returnMap = new HashMap<>();
|
||||
for (OldRaid oldRaid : oldWar.getRaids()) {
|
||||
returnMap.put(oldRaid.getRaidedTown().getName(), raidToMap(oldRaid));
|
||||
}
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @Isaac this is for getting when the last raid was on a town
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static long whenTownLastRaided(Town town) {
|
||||
if (town.hasMeta("AlathraWar-lastRaided")) {
|
||||
CustomDataField field = town.getMetadata("AlathraWar-lastRaided");
|
||||
if (field != null) {
|
||||
if (field instanceof LongDataField) {
|
||||
return ((LongDataField) field).getValue();
|
||||
}
|
||||
}
|
||||
return -1L;
|
||||
} else {
|
||||
town.addMetaData(new LongDataField("AlathraWar-lastRaided", 0L));
|
||||
}
|
||||
return -1L;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @Isaac this is for getting if a town can be raided, return (-2, -1, 0, 1, 2) based on status
|
||||
* (no players online, 24 hours town cooldown, 6 hour oldWar cooldown, town being raided already, valid time to raid)
|
||||
*/
|
||||
public static int isValidRaid(OldWar oldWar, String side, @Nonnull Town town) {
|
||||
long townTime = whenTownLastRaided(town);
|
||||
|
||||
//24 hours town cooldown
|
||||
if ((System.currentTimeMillis() / 1000) - townTime <= 86400) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//6 hour raid cooldown for oldWar
|
||||
if ((System.currentTimeMillis() / 1000) - (side.equalsIgnoreCase(oldWar.getSide1()) ? oldWar.getLastRaidTimeSide1() : oldWar.getLastRaidTimeSide2()) <= 21600) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//make sure a player is online in the raided town
|
||||
boolean onlinePlayer = false;
|
||||
for (Resident r : town.getResidents()) {
|
||||
if (r.isOnline()) {
|
||||
onlinePlayer = true;
|
||||
}
|
||||
}
|
||||
if (!onlinePlayer) return -2;
|
||||
|
||||
//check if being raided
|
||||
for (OldRaid oldRaid : oldWar.getRaids()) {
|
||||
if (oldRaid.getRaidedTown().getName().equalsIgnoreCase(town.getName())) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldWar;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Deprecated
|
||||
public class SiegeData {
|
||||
|
||||
// Static OldSiege list for all active OLD_SIEGES
|
||||
private static final HashSet<OldSiege> OLD_SIEGES = new HashSet<>();
|
||||
|
||||
public static HashSet<OldSiege> getSieges() {
|
||||
return OLD_SIEGES;
|
||||
}
|
||||
|
||||
public static void setSieges(ArrayList<OldSiege> oldSieges) {
|
||||
for (OldSiege oldSiege : oldSieges) {
|
||||
addSiege(oldSiege);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a siege with a specific name
|
||||
*
|
||||
* @param name - Name to check
|
||||
* @return OldSiege or Null
|
||||
*/
|
||||
public static OldSiege getSiege(String name) {
|
||||
for (OldSiege oldSiege : OLD_SIEGES) {
|
||||
if (oldSiege.getTown().getName().equalsIgnoreCase(name)) return oldSiege;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void addSiege(OldSiege oldSiege) {
|
||||
if (oldSiege == null) {
|
||||
Main.warLogger.log("Attempted to add NULL to oldSiege list.");
|
||||
return;
|
||||
}
|
||||
OLD_SIEGES.add(oldSiege);
|
||||
}
|
||||
|
||||
public static void removeSiege(OldSiege oldSiege) {
|
||||
OLD_SIEGES.remove(oldSiege);
|
||||
//deleteSiege(oldSiege);d
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a siege object from a provided HashMap
|
||||
*
|
||||
* @param fileData data
|
||||
* @return OldSiege object
|
||||
*/
|
||||
private static OldSiege fromMap(OldWar oldWar, HashMap<String, Object> fileData) {
|
||||
|
||||
if (fileData.get("town") == null || fileData.get("side1AreAttackers") == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Town town = TownyAPI.getInstance().getTown((String) fileData.get("town"));
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString((String) fileData.get("siegeLeader")));
|
||||
|
||||
return new OldSiege(oldWar, town, offlinePlayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the war into files.
|
||||
*
|
||||
* @param oldSiege - OldSiege to be saved.
|
||||
*/
|
||||
public static void saveSiege(OldSiege oldSiege) {
|
||||
OldWar oldWar = oldSiege.getWar();
|
||||
oldWar.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns a oldSiege into a map
|
||||
*
|
||||
* @param oldSiege - OldSiege
|
||||
* @return Map
|
||||
*/
|
||||
public static HashMap<String, Object> siegeToMap(OldSiege oldSiege) {
|
||||
HashMap<String, Object> returnMap = new HashMap<>();
|
||||
// Shoves everything into a map.
|
||||
returnMap.put("town", oldSiege.getTown().getName());
|
||||
returnMap.put("siegeTicks", oldSiege.getSiegeTicks());
|
||||
returnMap.put("attackerPoints", oldSiege.getAttackerPoints());
|
||||
returnMap.put("defenderPoints", oldSiege.getDefenderPoints());
|
||||
returnMap.put("side1AreAttackers", Boolean.toString(oldSiege.getSide1AreAttackers()));
|
||||
returnMap.put("siegeLeader", oldSiege.getSiegeLeader().getUniqueId().toString());
|
||||
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a map of siege maps
|
||||
*
|
||||
* @param oldWar - OldWar to map
|
||||
* @return Map of Maps
|
||||
*/
|
||||
public static HashMap<String, Object> getSiegeMap(OldWar oldWar) {
|
||||
HashMap<String, Object> returnMap = new HashMap<>();
|
||||
for (OldSiege oldSiege : oldWar.getSieges()) {
|
||||
returnMap.put(oldSiege.getTown().getName(), siegeToMap(oldSiege));
|
||||
}
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
public static ArrayList<OldSiege> createSieges(OldWar oldWar, Collection<HashMap<String, Object>> siegeMaps) {
|
||||
ArrayList<OldSiege> returnList = new ArrayList<>();
|
||||
for (HashMap<String, Object> map : siegeMaps) {
|
||||
Town town = TownyAPI.getInstance().getTown((String) map.get("town"));
|
||||
if (town == null) continue;
|
||||
|
||||
OldSiege oldSiege = fromMap(oldWar, map);
|
||||
oldSiege.addPointsToAttackers((int) map.get("attackerPoints"));
|
||||
oldSiege.addPointsToDefenders((int) map.get("defenderPoints"));
|
||||
oldSiege.resume((int) map.get("siegeTicks"));
|
||||
oldSiege.setWar(oldWar);
|
||||
returnList.add(oldSiege);
|
||||
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldRaid;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldWar;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.*;
|
||||
|
||||
@Deprecated
|
||||
public class WarData {
|
||||
|
||||
private final static String dataFolderPath = "plugins" + File.separator + "AlathraWar" + File.separator + "data";
|
||||
// Filter for only accessing yml files
|
||||
private static final FilenameFilter ymlFilter = (dir, name) -> name.endsWith(".yml");
|
||||
// Static OldWar list for all active oldWars
|
||||
private static ArrayList<OldWar> oldWars = new ArrayList<>();
|
||||
|
||||
// Constructor used to initialise folder.
|
||||
public WarData(final Main plugin) {
|
||||
File userDataFolder = new File(dataFolderPath + File.separator + "oldWars");
|
||||
if (!userDataFolder.exists()) {
|
||||
userDataFolder.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<OldWar> getWars() {
|
||||
return oldWars;
|
||||
}
|
||||
|
||||
public static void setWars(ArrayList<OldWar> oldWars) {
|
||||
WarData.oldWars = oldWars;
|
||||
}
|
||||
|
||||
public static Collection<String> getWarsNames() {
|
||||
List<String> warNames = new ArrayList<>();
|
||||
|
||||
for (OldWar oldWar : getWars()) {
|
||||
warNames.add(oldWar.getName());
|
||||
}
|
||||
|
||||
Collections.sort(warNames);
|
||||
|
||||
return warNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a war with a specific name
|
||||
*
|
||||
* @param name - Name to check
|
||||
* @return OldWar or Null
|
||||
*/
|
||||
public static OldWar getWar(String name) {
|
||||
for (OldWar oldWar : oldWars) {
|
||||
if (oldWar.getName().equalsIgnoreCase(name)) return oldWar;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static OldWar getWar(UUID uuid) {
|
||||
for (OldWar oldWar : oldWars) {
|
||||
if (oldWar.getUUID().equals(uuid)) return oldWar;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void addWar(OldWar oldWar) {
|
||||
if (oldWar == null) {
|
||||
Main.warLogger.log("Attempted to add NULL to oldWar list.");
|
||||
return;
|
||||
}
|
||||
oldWars.add(oldWar);
|
||||
}
|
||||
|
||||
public static void removeWar(OldWar oldWar) {
|
||||
oldWars.remove(oldWar);
|
||||
deleteWar(oldWar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the oldWars currently saved in files as an ArrayList of OldWar Objects
|
||||
*
|
||||
* @return OldWar Object ArrayList
|
||||
*/
|
||||
public static ArrayList<OldWar> createWars() {
|
||||
File[] files = new File(dataFolderPath + File.separator + "oldWars").listFiles(ymlFilter);
|
||||
|
||||
ArrayList<OldWar> returnList = new ArrayList<>();
|
||||
for (File file : files) {
|
||||
try {
|
||||
HashMap<String, Object> fileData = DataManager.getData(file);
|
||||
OldWar fileOldWar = fromMap(fileData);
|
||||
returnList.add(fileOldWar);
|
||||
} catch (Exception e) {
|
||||
Main.warLogger.log("Failed to load " + file.getName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return returnList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a war object from a provided HashMap
|
||||
*
|
||||
* @param fileData
|
||||
* @return OldWar object
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static OldWar fromMap(HashMap<String, Object> fileData) {
|
||||
|
||||
OldWar oldWar = new OldWar((String) fileData.get("name"),
|
||||
(String) fileData.get("side1"),
|
||||
(String) fileData.get("side2")
|
||||
);
|
||||
|
||||
oldWar.setSide1Towns((ArrayList<String>) fileData.get("side1Towns"));
|
||||
oldWar.setSide2Towns((ArrayList<String>) fileData.get("side2Towns"));
|
||||
oldWar.setSurrenderedTowns((ArrayList<String>) fileData.get("surrenderedTowns"));
|
||||
|
||||
oldWar.addSide1Points((int) fileData.get("side1Points"));
|
||||
oldWar.addSide2Points((int) fileData.get("side2Points"));
|
||||
|
||||
if (fileData.get("lastRaidTimeSide1") != null && fileData.get("lastRaidTimeSide2") != null) {
|
||||
oldWar.setLastRaidTimeSide1((int) fileData.get("lastRaidTimeSide1"));
|
||||
oldWar.setLastRaidTimeSide2((int) fileData.get("lastRaidTimeSide2"));
|
||||
}
|
||||
|
||||
|
||||
// OldSiege adding from map.
|
||||
Collection<HashMap<String, Object>> siegeMaps = ((HashMap<String, HashMap<String, Object>>) fileData.get("oldSieges")).values();
|
||||
ArrayList<OldSiege> oldSieges = SiegeData.createSieges(oldWar, siegeMaps);
|
||||
for (OldSiege oldSiege : oldSieges) {
|
||||
oldWar.addSiege(oldSiege);
|
||||
SiegeData.addSiege(oldSiege);
|
||||
}
|
||||
|
||||
// OldRaid adding from map.
|
||||
Collection<HashMap<String, Object>> raidMaps = ((HashMap<String, HashMap<String, Object>>) fileData.get("oldRaids")).values();
|
||||
ArrayList<OldRaid> oldRaids = RaidData.createRaids(oldWar, raidMaps);
|
||||
for (OldRaid oldRaid : oldRaids) {
|
||||
oldWar.addRaid(oldRaid);
|
||||
}
|
||||
|
||||
return oldWar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the oldWar into files.
|
||||
*
|
||||
* @param oldWar - OldWar to be saved.
|
||||
*/
|
||||
public static void saveWar(OldWar oldWar) {
|
||||
HashMap<String, Object> sHashMap = new HashMap<>();
|
||||
|
||||
// Shoves everything into a map.
|
||||
sHashMap.put("name", oldWar.getName());
|
||||
sHashMap.put("side1", oldWar.getSide1());
|
||||
sHashMap.put("side2", oldWar.getSide2());
|
||||
sHashMap.put("side1Towns", oldWar.getSide1Towns());
|
||||
sHashMap.put("side2Towns", oldWar.getSide2Towns());
|
||||
sHashMap.put("surrenderedTowns", oldWar.getSurrenderedTowns());
|
||||
sHashMap.put("side1Points", oldWar.getSide1Points());
|
||||
sHashMap.put("side2Points", oldWar.getSide2Points());
|
||||
|
||||
sHashMap.put("sieges", SiegeData.getSiegeMap(oldWar));
|
||||
sHashMap.put("raids", RaidData.getRaidMap(oldWar));
|
||||
sHashMap.put("lastRaidTimeSide1", oldWar.getLastRaidTimeSide1());
|
||||
sHashMap.put("lastRaidTimeSide2", oldWar.getLastRaidTimeSide2());
|
||||
|
||||
DataManager.saveData("oldWars" + File.separator + oldWar.getName() + ".yml", sHashMap);
|
||||
}
|
||||
|
||||
private static void deleteWar(OldWar oldWar) {
|
||||
File[] files = new File(dataFolderPath + File.separator + "oldWars").listFiles(ymlFilter);
|
||||
for (File file : files) {
|
||||
if (file.getName().startsWith(oldWar.getName())) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user