mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 14:38:55 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e5908fecc | ||
|
|
850bf6768d | ||
|
|
60a75c5f8b | ||
|
|
0008d63fe9 | ||
|
|
6ceedaf448 | ||
|
|
0d7ba5b235 | ||
|
|
c83c153f11 | ||
|
|
1dbb69c3bd | ||
|
|
60b425b056 | ||
|
|
89fc6d1769 | ||
|
|
1dd938da60 | ||
|
|
c2b5629df5 | ||
|
|
994509b823 | ||
|
|
0f167ef6c3 | ||
|
|
a01b7e909d | ||
|
|
5e2b1ada29 | ||
|
|
57ac917e93 | ||
|
|
a1f1adc527 | ||
|
|
e771416d10 | ||
|
|
cab30a6eae | ||
|
|
392ff18aaa | ||
|
|
4eff1dbb2e | ||
|
|
39dd212a30 | ||
|
|
4428d18a82 | ||
|
|
496a387ac7 | ||
|
|
7039ed1861 | ||
|
|
1811d345b2 | ||
|
|
7094a38299 | ||
|
|
f1be2da31e | ||
|
|
46fd8b03e9 | ||
|
|
bc9dc24f1b | ||
|
|
11b7a404bf | ||
|
|
59a700ba46 | ||
|
|
7b14a7595f | ||
|
|
e72b6a4460 | ||
|
|
b11f06abcd | ||
|
|
431304d065 | ||
|
|
879145b433 | ||
|
|
e9f2786743 | ||
|
|
ddc45babba | ||
|
|
ff9cbd4e96 | ||
|
|
d139834169 | ||
|
|
12386ebe4b | ||
|
|
9f98cc0fae | ||
|
|
18f32af4b2 | ||
|
|
df0a66d089 | ||
|
|
acbefe71e8 | ||
|
|
33251eee05 | ||
|
|
f8e072adcd | ||
|
|
6d7550ee3f | ||
|
|
d84c837c0f | ||
|
|
4f1e66e642 | ||
|
|
c7e1f8a026 | ||
|
|
4b66168af7 | ||
|
|
b8b9cb10d9 | ||
|
|
0f0c8c5548 | ||
|
|
001955763a | ||
|
|
da9a6cb58d | ||
|
|
c87d2dd35e | ||
|
|
9ba06d70a6 | ||
|
|
1007dbcd12 | ||
|
|
ea8c3db0f5 | ||
|
|
782d228e1d | ||
|
|
11a0d019fd | ||
|
|
117130f67a | ||
|
|
cd61aa175c | ||
|
|
9d2b8612d2 | ||
|
|
95175f1057 | ||
|
|
6c6828f7fa | ||
|
|
23ade97d5f | ||
|
|
bacf39583e | ||
|
|
71b5d21b20 | ||
|
|
ba6ebf6e91 | ||
|
|
fe231e31d0 | ||
|
|
395e3742d4 | ||
|
|
2dbfcdb9df | ||
|
|
8b2958655e | ||
|
|
628d458700 | ||
|
|
14b962424d | ||
|
|
7c483a9c39 | ||
|
|
021c5a3b05 | ||
|
|
0eb83e49f2 | ||
|
|
1b1c85afcb | ||
|
|
80cae9b5b7 | ||
|
|
c74130869f | ||
|
|
54ef115792 | ||
|
|
d5bf05e0ec | ||
|
|
2aa106b29c | ||
|
|
8835c59a2d | ||
|
|
7fb5494885 | ||
|
|
889c79e46a | ||
|
|
a6a65d8476 | ||
|
|
43c82661ac | ||
|
|
f568e62256 | ||
|
|
49e4600d1b | ||
|
|
421c6ac9a1 | ||
|
|
eb5a095eff | ||
|
|
62833c7077 | ||
|
|
cdbfb50a67 | ||
|
|
bdc3962dbf | ||
|
|
1e19d8eaf6 | ||
|
|
53a9ee85df | ||
|
|
72d6e9e655 | ||
|
|
0b2dbbc473 | ||
|
|
d858c193db | ||
|
|
0816fd17e4 | ||
|
|
55b1f529d2 | ||
|
|
93aff6e642 | ||
|
|
7a8ec5914b | ||
|
|
47528a99d6 | ||
|
|
ffc047df0f | ||
|
|
63bf909b0c | ||
|
|
6586d92046 | ||
|
|
40061cf40a | ||
|
|
8e05bb7b5d | ||
|
|
f45ef2b427 | ||
|
|
97f118d4d8 | ||
|
|
e7c7836a21 | ||
|
|
9adaa4bc94 | ||
|
|
37b790a228 | ||
|
|
c36165e7b6 | ||
|
|
5d01ebe50d | ||
|
|
c4885e0c18 | ||
|
|
fa2c01c398 | ||
|
|
cac8d3190b | ||
|
|
ebaf26ebce | ||
|
|
dc21fb981d | ||
|
|
1693e1c4c5 | ||
|
|
c360b7907e | ||
|
|
4317be4acd | ||
|
|
ec45dec635 | ||
|
|
2574dec7d6 | ||
|
|
1d8b9913dc | ||
|
|
200b1c0a3a | ||
|
|
83590b4209 | ||
|
|
c281d5dd91 | ||
|
|
f01ea0ceb1 | ||
|
|
89201b2980 | ||
|
|
69442c3b69 | ||
|
|
9efefed13d | ||
|
|
7f79e33179 | ||
|
|
0869229548 | ||
|
|
56a897d6a3 | ||
|
|
844c44f56b | ||
|
|
341ba1a4af | ||
|
|
063826581c | ||
|
|
fc06d640fd | ||
|
|
923a031253 | ||
|
|
3e2cec6809 | ||
|
|
2a733fe867 | ||
|
|
23f61e99a4 | ||
|
|
c23018bd79 | ||
|
|
a59d59e962 | ||
|
|
e86af9b3c7 | ||
|
|
700e760ae5 | ||
|
|
011f54d4d6 | ||
|
|
098b414101 | ||
|
|
da221d1589 | ||
|
|
7e83d66417 | ||
|
|
cfc28b8fa4 | ||
|
|
c234911454 | ||
|
|
00b416a975 | ||
|
|
2cced058ca | ||
|
|
16add93b85 | ||
|
|
c2595bcd1d | ||
|
|
bfeaf1bd0d | ||
|
|
874fc734a0 | ||
|
|
5727464d76 | ||
|
|
f7c9522fda | ||
|
|
76e0f9331b | ||
|
|
35da505bd7 | ||
|
|
4b094d7dca | ||
|
|
5c57e73e8b | ||
|
|
1489d54116 | ||
|
|
5a3d52176f | ||
|
|
62c7c40a7b | ||
|
|
ad0b0f3d0f | ||
|
|
b7a4f84164 | ||
|
|
1524981074 | ||
|
|
6168428a54 | ||
|
|
a82153b4a2 | ||
|
|
07bc17f1ad | ||
|
|
5fca86aca7 | ||
|
|
e75becf44e | ||
|
|
ffe9bd0c2e | ||
|
|
2f867fca2c | ||
|
|
df456ba15b | ||
|
|
3a264b7708 | ||
|
|
53444b81b9 | ||
|
|
8d197ef210 | ||
|
|
d2a39e0088 | ||
|
|
84708bdec5 | ||
|
|
cac219e684 | ||
|
|
358165a58c | ||
|
|
484db589b7 | ||
|
|
6fa8fa70ed | ||
|
|
12c2b70b4b | ||
|
|
17b9010992 | ||
|
|
c2c5d82127 | ||
|
|
8f6e8025b1 | ||
|
|
bb80ad8fa5 | ||
|
|
2f64dbe51b | ||
|
|
d4996a7f4a | ||
|
|
03ad84008c | ||
|
|
c5f8d26f0b | ||
|
|
c1f5b5cbe5 | ||
|
|
850ea26171 | ||
|
|
81103e385d | ||
|
|
6c5cf097e3 | ||
|
|
ab1ce3d70f | ||
|
|
9a49325c36 | ||
|
|
5f6adfa2f4 | ||
|
|
a3a8619179 | ||
|
|
2824c8829f | ||
|
|
af1292aa93 | ||
|
|
0e7ffd16c3 | ||
|
|
65a3dc46a1 | ||
|
|
40ed1d457e | ||
|
|
d85cf05eee | ||
|
|
edd3d2c7eb | ||
|
|
5cb7263e6d | ||
|
|
8ffcbc33d3 | ||
|
|
4f033344a9 | ||
|
|
6f171d4410 | ||
|
|
7e13f99bbf | ||
|
|
bbe57311c1 | ||
|
|
9c80c5d0a2 | ||
|
|
575c00242c | ||
|
|
65e1624581 | ||
|
|
10908764d3 | ||
|
|
4ce603f635 | ||
|
|
77c458fb4a | ||
|
|
2dec08df80 | ||
|
|
b60a551914 | ||
|
|
7eb677f8af | ||
|
|
840ea44ebc | ||
|
|
119a2f5e33 | ||
|
|
61e71cd9e7 | ||
|
|
25375ae0c3 | ||
|
|
a16b590b03 | ||
|
|
790ea96166 | ||
|
|
2e4285a630 | ||
|
|
6d9e1ef2ec | ||
|
|
9e60eff516 | ||
|
|
91742bb24e | ||
|
|
f2d51bda49 | ||
|
|
297cb0aa11 | ||
|
|
c46eb60e7d | ||
|
|
dadf7aa0c8 | ||
|
|
8d8710c762 | ||
|
|
2158233292 | ||
|
|
c16d3ee17a | ||
|
|
ae3925218b | ||
|
|
55f96c4897 | ||
|
|
c87e1e9737 | ||
|
|
d754c5e279 | ||
|
|
12d2786096 | ||
|
|
6b5000e26b | ||
|
|
65dc1c9846 | ||
|
|
48915e7086 | ||
|
|
5bcbb9da9b | ||
|
|
3420e8cc02 | ||
|
|
ef070be338 | ||
|
|
26cd6d04f8 | ||
|
|
9c62de50a9 | ||
|
|
861868e7d8 | ||
|
|
8cdae79c42 | ||
|
|
3e99ec55e2 | ||
|
|
c902f9e314 | ||
|
|
4ed964e292 | ||
|
|
c658158cf5 | ||
|
|
214ff299a8 | ||
|
|
7f20a552b6 | ||
|
|
4bf91d5cd9 | ||
|
|
50738bb784 | ||
|
|
7757e0fe79 | ||
|
|
a0d44d19e9 | ||
|
|
9d619678a5 | ||
|
|
7be0ff8f8d | ||
|
|
a81928e69e | ||
|
|
dbc7001c09 | ||
|
|
f260e28ae1 | ||
|
|
4a4bcc02cd | ||
|
|
8c413ba158 | ||
|
|
aca1a685aa | ||
|
|
d6e5518c1e | ||
|
|
e65bae6f67 | ||
|
|
d1a46ba2e0 | ||
|
|
271648712d | ||
|
|
dcad9611d6 | ||
|
|
81e0ca47cd | ||
|
|
471a03bb7b | ||
|
|
388c600ce5 | ||
|
|
2cb609acc6 | ||
|
|
168851ec63 | ||
|
|
0a3fba997e | ||
|
|
048f533cb2 | ||
|
|
7a653575e9 | ||
|
|
1452a750ae | ||
|
|
90cdc320ac | ||
|
|
e5e9bbe899 | ||
|
|
e91d80fec9 | ||
|
|
7005387555 | ||
|
|
acc465a58b | ||
|
|
0b48677810 | ||
|
|
110f8d7791 | ||
|
|
a43b794d1c | ||
|
|
6f29b29ca8 | ||
|
|
dc7f29943e | ||
|
|
78268810dd | ||
|
|
8b6564bda7 | ||
|
|
70c5a291a0 | ||
|
|
7eedd0f38e | ||
|
|
1f3312ca79 | ||
|
|
d2ba9bce40 | ||
|
|
732b3a8a95 | ||
|
|
d8ede6d074 | ||
|
|
9257322c71 | ||
|
|
43ce827bfa | ||
|
|
46960941d3 | ||
|
|
3c78b1f70a | ||
|
|
02642ff18a | ||
|
|
eae8ed8923 | ||
|
|
bb622ad8f0 | ||
|
|
d91945978a | ||
|
|
57676bccc3 | ||
|
|
06df5024f2 | ||
|
|
1c265b4677 |
No files matched your search
@@ -0,0 +1,28 @@
|
||||
name: Build with Maven
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [ published ]
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
publish_build_files:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 17
|
||||
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --file pom.xml
|
||||
|
||||
- name: Upload Release Assets
|
||||
uses: AButler/[email protected]
|
||||
with:
|
||||
files: 'target/AlathraWar-*.jar'
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
release-tag: ${{ github.event.release.tag_name }}
|
||||
@@ -0,0 +1,8 @@
|
||||
/target/
|
||||
/.settings/
|
||||
/bin/
|
||||
.classpath
|
||||
.project
|
||||
/.idea/
|
||||
/.vscode/
|
||||
AlathraWar.iml
|
||||
@@ -1,5 +0,0 @@
|
||||
/target/
|
||||
/.classpath
|
||||
/.project
|
||||
/.settings
|
||||
/bin/
|
||||
@@ -1,30 +0,0 @@
|
||||
name: AlathraWar
|
||||
version: 1.2.1
|
||||
api-version: 1.19
|
||||
author: ShermansWorld
|
||||
main: me.ShermansWorld.AlathraWar.Main
|
||||
depend: [Vault, Towny, LuckPerms]
|
||||
|
||||
commands:
|
||||
war:
|
||||
description: used to create, delete, join and leave wars
|
||||
softdepend: [Vault, Towny, LuckPerms]
|
||||
siege:
|
||||
description: used to start, end, and view sieges
|
||||
softdepend: [Vault, Towny]
|
||||
mercenary:
|
||||
description: Framework for handling mercenary work
|
||||
softdepend: [Vault, Towny]
|
||||
aliases:
|
||||
- merc
|
||||
assassin:
|
||||
description: Framework for handling assassin work
|
||||
softdepend: [Vault, Towny]
|
||||
aliases:
|
||||
- ass
|
||||
- assin
|
||||
contract:
|
||||
description: Framework for handling contracts
|
||||
softdepend: [Vault, Towny]
|
||||
aliases:
|
||||
- contracts
|
||||
@@ -1 +0,0 @@
|
||||
Prefixes:
|
||||
@@ -1,3 +0,0 @@
|
||||
MaxID: 0
|
||||
|
||||
Sieges:
|
||||
@@ -1 +0,0 @@
|
||||
Wars:
|
||||
@@ -1,19 +0,0 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
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.PrefixData;
|
||||
import me.ShermansWorld.AlathraWar.data.RolesData;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
import me.ShermansWorld.AlathraWar.hooks.LuckPermsHook;
|
||||
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 PrefixData prefixData;
|
||||
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().toLowerCase());
|
||||
}
|
||||
for (int i = 0; i < warsTempList.size(); ++i) {
|
||||
final War war = new War(warsTempList.get(i).toLowerCase(),
|
||||
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>();
|
||||
side1Players = (ArrayList<String>) warData.getConfig()
|
||||
.getList("Wars." + war.getName() + ".side1players");
|
||||
side2Players = (ArrayList<String>) warData.getConfig()
|
||||
.getList("Wars." + war.getName() + ".side2players");
|
||||
war.setSide1Players(side1Players);
|
||||
war.setSide2Players(side2Players);
|
||||
WarCommands.wars.add(war);
|
||||
for (final String playerName : war.getSide1Players()) {
|
||||
try {
|
||||
Bukkit.getServer().getPlayer(playerName)
|
||||
.setPlayerListName(String.valueOf(Helper.color(
|
||||
new StringBuilder("&c[").append(war.getSide1()).append("]&r").toString()))
|
||||
+ playerName);
|
||||
} catch (NullPointerException ex) {
|
||||
}
|
||||
}
|
||||
for (final String playerName : war.getSide2Players()) {
|
||||
try {
|
||||
Bukkit.getServer().getPlayer(playerName)
|
||||
.setPlayerListName(String.valueOf(Helper.color(
|
||||
new StringBuilder("&9[").append(war.getSide2()).append("]&r").toString()))
|
||||
+ playerName);
|
||||
} catch (NullPointerException ex2) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
Bukkit.getLogger().info("NULL when initializing wars");
|
||||
}
|
||||
try {
|
||||
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");
|
||||
}
|
||||
try {
|
||||
Set<String> prefixSet = (Set<String>) prefixData.getConfig().getConfigurationSection("Prefixes")
|
||||
.getKeys(false);
|
||||
Iterator<String> it3 = prefixSet.iterator();
|
||||
ArrayList<String> prefixesTempList = new ArrayList<String>();
|
||||
while (it3.hasNext()) {
|
||||
prefixesTempList.add(it3.next());
|
||||
}
|
||||
for (int i = 0; i < prefixesTempList.size(); ++i) {
|
||||
LuckPermsHook.prefixMap.put(prefixesTempList.get(i),
|
||||
prefixData.getConfig().getString("Prefixes." + prefixesTempList.get(i)));
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
Bukkit.getLogger().info("NULL when initializing prefixes");
|
||||
}
|
||||
}
|
||||
|
||||
@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() {
|
||||
LuckPermsHook.init();
|
||||
TABHook.init();
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
warData = new WarData(this);
|
||||
siegeData = new SiegeData(this);
|
||||
prefixData = new PrefixData(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() {
|
||||
}
|
||||
}
|
||||
@@ -1,508 +0,0 @@
|
||||
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, 20000.0);
|
||||
double amt = 0.0;
|
||||
if (this.town.getAccount().getHoldingBalance() > 80000.0) {
|
||||
amt = Math.floor(this.town.getAccount().getHoldingBalance()) / 4.0;
|
||||
this.town.getAccount().withdraw(amt, "war loot");
|
||||
} else {
|
||||
if (this.town.getAccount().getHoldingBalance() < 20000.0) {
|
||||
amt = this.town.getAccount().getHoldingBalance();
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName()
|
||||
+ " has been destroyed by " + this.getAttackers() + "!");
|
||||
TownyUniverse.getInstance().getDataSource().deleteTown(this.town);
|
||||
Main.econ.depositPlayer(offlinePlayer, amt);
|
||||
return;
|
||||
}
|
||||
this.town.getAccount().withdraw(20000.0, "war loot");
|
||||
amt = 20000.0;
|
||||
}
|
||||
Bukkit.broadcastMessage("The town of " + this.town.getName() + " has been sacked by " + this.getAttackers()
|
||||
+ ", valuing $" + String.valueOf(amt));
|
||||
Main.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(20000.0, "War chest");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The defenders from " + this.defenders
|
||||
+ " have won the siege of " + this.town.getName() + "!");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + this.town.getName()
|
||||
+ " has recovered the attackers' war chest, valued at $20,000");
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class War {
|
||||
private String name;
|
||||
private String side1;
|
||||
private String side2;
|
||||
private ArrayList<String> side1Players;
|
||||
private ArrayList<String> side2Players;
|
||||
|
||||
public War(final String name, final String side1, final String side2) {
|
||||
this.side1Players = new ArrayList<String>();
|
||||
this.side2Players = new ArrayList<String>();
|
||||
this.name = name;
|
||||
this.side1 = side1;
|
||||
this.side2 = side2;
|
||||
}
|
||||
|
||||
public void addPlayerSide1(final String playerName) {
|
||||
boolean duplicate = false;
|
||||
for (int i = 0; i < this.side1Players.size(); ++i) {
|
||||
if (playerName.equalsIgnoreCase(this.side1Players.get(i))) {
|
||||
duplicate = true;
|
||||
}
|
||||
}
|
||||
if (!duplicate) {
|
||||
this.side1Players.add(playerName);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayerSide1(final String playerName) {
|
||||
for (int i = 0; i < this.side1Players.size(); ++i) {
|
||||
if (playerName.equalsIgnoreCase(this.side1Players.get(i))) {
|
||||
this.side1Players.remove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayerSide2(final String playerName) {
|
||||
boolean duplicate = false;
|
||||
for (int i = 0; i < this.side2Players.size(); ++i) {
|
||||
if (playerName.equalsIgnoreCase(this.side2Players.get(i))) {
|
||||
duplicate = true;
|
||||
}
|
||||
}
|
||||
if (!duplicate) {
|
||||
this.side2Players.add(playerName);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayerSide2(final String playerName) {
|
||||
for (int i = 0; i < this.side2Players.size(); ++i) {
|
||||
if (playerName.equalsIgnoreCase(this.side2Players.get(i))) {
|
||||
this.side2Players.remove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSide1() {
|
||||
return this.side1;
|
||||
}
|
||||
|
||||
public void setSide1(final String side1) {
|
||||
this.side1 = side1;
|
||||
}
|
||||
|
||||
public String getSide2() {
|
||||
return this.side2;
|
||||
}
|
||||
|
||||
public void setSide2(final String side2) {
|
||||
this.side2 = this.side1;
|
||||
}
|
||||
|
||||
public ArrayList<String> getSide1Players() {
|
||||
return this.side1Players;
|
||||
}
|
||||
|
||||
public void setSide1Players(final ArrayList<String> side1Players) {
|
||||
this.side1Players = side1Players;
|
||||
}
|
||||
|
||||
public ArrayList<String> getSide2Players() {
|
||||
return this.side2Players;
|
||||
}
|
||||
|
||||
public void setSide2Players(final ArrayList<String> side2Players) {
|
||||
this.side2Players = side2Players;
|
||||
}
|
||||
}
|
||||
@@ -1,261 +0,0 @@
|
||||
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) <= 20000.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, 20000.0);
|
||||
SiegeCommands.sieges.add(siege2);
|
||||
siege2.start();
|
||||
siege2.createBeacon();
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "As part of " + war.getName() + ", forces from " + siege2.getAttackers() + " are laying siege to the town of " + town.getName() + "!");
|
||||
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;
|
||||
}
|
||||
}
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,313 +0,0 @@
|
||||
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.LuckPermsHook;
|
||||
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].toLowerCase(), args[2].toLowerCase(), args[3].toLowerCase());
|
||||
WarCommands.wars.add(war);
|
||||
final ArrayList<String> side1Players = new ArrayList<String>();
|
||||
final ArrayList<String> side2Players = new ArrayList<String>();
|
||||
side1Players.add("Notch1");
|
||||
side2Players.add("Notch2");
|
||||
war.setSide1Players(side1Players);
|
||||
war.setSide2Players(side2Players);
|
||||
Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side1", (Object)args[2]);
|
||||
Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side2", (Object)args[3]);
|
||||
Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side1players", (Object)side1Players);
|
||||
Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side2players", (Object)side2Players);
|
||||
Main.warData.saveConfig();
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War created with the name " + args[1].toLowerCase() + ", " + args[2] + " vs. " + args[3]);
|
||||
Main.warLogger.log(p.getName() + " created a new war with the name " + args[1].toLowerCase() + ", " + args[2] + " vs. " + args[3]);
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < WarCommands.wars.size(); ++i) {
|
||||
if (WarCommands.wars.get(i).getName().equalsIgnoreCase(args[1])) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "A war already exists with that name! To view wars type /war list");
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
final War war2 = new War(args[1], args[2], args[3]);
|
||||
WarCommands.wars.add(war2);
|
||||
final ArrayList<String> side1Players2 = new ArrayList<String>();
|
||||
final ArrayList<String> side2Players2 = new ArrayList<String>();
|
||||
side1Players2.add("Notch1");
|
||||
side2Players2.add("Notch2");
|
||||
war2.setSide1Players(side1Players2);
|
||||
war2.setSide2Players(side2Players2);
|
||||
Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side1", (Object)args[2]);
|
||||
Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side2", (Object)args[3]);
|
||||
Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side1players", (Object)side1Players2);
|
||||
Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side2players", (Object)side2Players2);
|
||||
Main.warData.saveConfig();
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War created with the name " + args[1].toLowerCase() + ", " + args[2] + " vs. " + args[3]);
|
||||
Main.warLogger.log(p.getName() + " created a new war with the name " + args[1].toLowerCase() + ", " + args[2] + " vs. " + args[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /war create [name] [side1] [side2]");
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("delete")) {
|
||||
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 " + args[1] + " has been deleted");
|
||||
Main.warLogger.log(p.getName() + " deleted a war named " + args[1]);
|
||||
for (String playername : WarCommands.wars.get(j).getSide1Players()) {
|
||||
TABHook.resetSuffix(playername);
|
||||
LuckPermsHook.resetPrefix(playername);
|
||||
TABHook.resetPrefix(playername);
|
||||
}
|
||||
for (String playername : WarCommands.wars.get(j).getSide2Players()) {
|
||||
TABHook.resetSuffix(playername);
|
||||
LuckPermsHook.resetPrefix(playername);
|
||||
TABHook.resetPrefix(playername);
|
||||
}
|
||||
WarCommands.wars.remove(j);
|
||||
Main.warData.getConfig().set("Wars." + args[1].toLowerCase(), (Object)null);
|
||||
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) {
|
||||
|
||||
if (args.length == 4) {
|
||||
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(args[1].toLowerCase())) {
|
||||
if (war2.getSide1().equalsIgnoreCase(args[2].toLowerCase())) {
|
||||
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;
|
||||
}
|
||||
war2.addPlayerSide1(p.getName());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the war on the side of " + war2.getSide1());
|
||||
TABHook.assignSide1WarSuffix(p, war2);
|
||||
if (isMercJoining) {
|
||||
LuckPermsHook.assignSide1WarColor(p.getName(), true);
|
||||
} else {
|
||||
LuckPermsHook.assignSide1WarColor(p.getName(), false);
|
||||
}
|
||||
TABHook.removeColorPrefix(p, LuckPermsHook.getPrefix(p.getName()));
|
||||
Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side1players", (Object)war2.getSide1Players());
|
||||
Main.warData.saveConfig();
|
||||
if (isMercJoining) {
|
||||
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");
|
||||
} else {
|
||||
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].toLowerCase())) {
|
||||
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;
|
||||
}
|
||||
war2.addPlayerSide2(p.getName());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the war on the side of " + war2.getSide2());
|
||||
TABHook.assignSide2WarSuffix(p, war2);
|
||||
if (isMercJoining) {
|
||||
LuckPermsHook.assignSide2WarColor(p.getName(), true);
|
||||
} else {
|
||||
LuckPermsHook.assignSide2WarColor(p.getName(), false);
|
||||
}
|
||||
TABHook.removeColorPrefix(p, LuckPermsHook.getPrefix(p.getName()));
|
||||
Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side2players", (Object)war2.getSide2Players());
|
||||
Main.warData.saveConfig();
|
||||
if (isMercJoining) {
|
||||
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");
|
||||
} else {
|
||||
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;
|
||||
for (final War war3 : WarCommands.wars) {
|
||||
if (war3.getName().equalsIgnoreCase(args[1])) {
|
||||
found = true;
|
||||
if (war3.getSide1Players().contains(p.getName())) {
|
||||
found2 = true;
|
||||
war3.removePlayerSide1(p.getName());
|
||||
Main.warData.getConfig().set("Wars." + args[1] + ".side1players", (Object)war3.getSide1Players());
|
||||
Main.warData.saveConfig();
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have left the war");
|
||||
TABHook.resetSuffix(p);
|
||||
LuckPermsHook.resetPrefix(p.getName());
|
||||
TABHook.resetPrefix(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.getSide2Players().contains(p.getName())) {
|
||||
found2 = true;
|
||||
war3.removePlayerSide2(p.getName());
|
||||
Main.warData.getConfig().set("Wars." + args[1] + ".side2players", (Object)war3.getSide2Players());
|
||||
Main.warData.saveConfig();
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have left the war");
|
||||
TABHook.resetSuffix(p);
|
||||
LuckPermsHook.resetPrefix(p.getName());
|
||||
TABHook.resetPrefix(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 (!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;
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
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 PrefixData
|
||||
{
|
||||
private Main plugin;
|
||||
private FileConfiguration dataConfig;
|
||||
private File configFile;
|
||||
|
||||
public PrefixData(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(), "prefixes.yml");
|
||||
}
|
||||
this.dataConfig = (FileConfiguration)YamlConfiguration.loadConfiguration(this.configFile);
|
||||
final InputStream defaultStream = this.plugin.getResource("prefixes.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(), "prefixes.yml");
|
||||
}
|
||||
if (!this.configFile.exists()) {
|
||||
this.plugin.saveResource("prefixes.yml", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
package me.ShermansWorld.AlathraWar.hooks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.model.group.Group;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import net.luckperms.api.model.user.UserManager;
|
||||
import net.luckperms.api.node.Node;
|
||||
import net.luckperms.api.node.NodeType;
|
||||
import net.luckperms.api.node.types.PrefixNode;
|
||||
|
||||
public class LuckPermsHook {
|
||||
public static boolean init = false;
|
||||
public static LuckPerms lp;
|
||||
private static UserManager um;
|
||||
|
||||
public static HashMap<String, String> prefixMap = new HashMap<String, String>();
|
||||
|
||||
public static void init() {
|
||||
RegisteredServiceProvider<LuckPerms> provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class);
|
||||
if (provider != null) {
|
||||
lp = provider.getProvider();
|
||||
um = lp.getUserManager();
|
||||
}
|
||||
init = true;
|
||||
}
|
||||
|
||||
public static String getPrefix(String playername) {
|
||||
User user = um.getUser(playername);
|
||||
String prefix = user.getCachedData().getMetaData().getPrefix();
|
||||
if (prefix == null) {
|
||||
return "";
|
||||
} else {
|
||||
return prefix;
|
||||
}
|
||||
}
|
||||
|
||||
public static void assignSide1WarColor(String playername, boolean isWarMerc) {
|
||||
String prefix = getPrefix(playername);
|
||||
boolean isGroupPrefix = false;
|
||||
if (!prefix.equals("")) {
|
||||
User user = um.getUser(playername);
|
||||
for (Group group : user.getInheritedGroups(user.getQueryOptions())) {
|
||||
String groupPrefix = group.getCachedData().getMetaData().getPrefix();
|
||||
if (groupPrefix == null) {
|
||||
groupPrefix = "";
|
||||
}
|
||||
if (groupPrefix.equals(prefix)) {
|
||||
isGroupPrefix = true;
|
||||
}
|
||||
}
|
||||
if (!isGroupPrefix) {
|
||||
prefixMap.put(playername, prefix);
|
||||
Main.prefixData.getConfig().set("Prefixes." + playername, prefix);
|
||||
Main.prefixData.saveConfig();
|
||||
}
|
||||
}
|
||||
if (isWarMerc) {
|
||||
prefix = prefix + "&a[M]&r&c";
|
||||
} else {
|
||||
prefix = prefix + "&c";
|
||||
}
|
||||
removePrefixNodes(playername);
|
||||
addPrefix(playername, prefix);
|
||||
}
|
||||
|
||||
public static void assignSide2WarColor(String playername, boolean isWarMerc) {
|
||||
String prefix = getPrefix(playername);
|
||||
boolean isGroupPrefix = false;
|
||||
if (!prefix.equals("")) {
|
||||
User user = um.getUser(playername);
|
||||
for (Group group : user.getInheritedGroups(user.getQueryOptions())) {
|
||||
String groupPrefix = group.getCachedData().getMetaData().getPrefix();
|
||||
if (groupPrefix == null) {
|
||||
groupPrefix = "";
|
||||
}
|
||||
if (groupPrefix.equals(prefix)) {
|
||||
isGroupPrefix = true;
|
||||
}
|
||||
}
|
||||
if (!isGroupPrefix) {
|
||||
prefixMap.put(playername, prefix);
|
||||
Main.prefixData.getConfig().set("Prefixes." + playername, prefix);
|
||||
Main.prefixData.saveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
if (isWarMerc) {
|
||||
prefix = prefix + "&a[M]&r&9";
|
||||
} else {
|
||||
prefix = prefix + "&9";
|
||||
}
|
||||
removePrefixNodes(playername);
|
||||
addPrefix(playername, prefix);
|
||||
}
|
||||
|
||||
public static void resetPrefix(String playername) {
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(playername);
|
||||
try {
|
||||
if (op.isOnline()) {
|
||||
removePrefixNodes(playername);
|
||||
if (prefixMap.containsKey(playername)) {
|
||||
addPrefix(playername, prefixMap.get(playername));
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void removePrefixNodes(String playername) {
|
||||
ArrayList<Node> prefixNodes = new ArrayList<Node>();
|
||||
User user = um.getUser(playername);
|
||||
for (Node node : user.getNodes()) {
|
||||
if (node.getType().equals(NodeType.PREFIX)) {
|
||||
prefixNodes.add(node);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < prefixNodes.size(); i++) {
|
||||
user.data().remove(prefixNodes.get(i));
|
||||
}
|
||||
um.saveUser(user);
|
||||
}
|
||||
|
||||
private static void addPrefix(String playername, String prefix) {
|
||||
User user = um.getUser(playername);
|
||||
user.data().add(PrefixNode.builder(prefix, 100).build());
|
||||
um.saveUser(user);
|
||||
}
|
||||
|
||||
}
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
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.LuckPermsHook;
|
||||
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;
|
||||
boolean colorRemoved = false;
|
||||
for (final War war : WarCommands.wars) {
|
||||
if (war.getSide1Players().contains(p.getName())) {
|
||||
TABHook.assignSide1WarSuffix(p, war);
|
||||
if (!colorRemoved) {
|
||||
TABHook.removeColorPrefix(p, LuckPermsHook.getPrefix(p.getName()));
|
||||
colorRemoved = true;
|
||||
}
|
||||
inWar = true;
|
||||
} else if (war.getSide2Players().contains(p.getName())) {
|
||||
TABHook.assignSide2WarSuffix(p, war);
|
||||
if (!colorRemoved) {
|
||||
TABHook.removeColorPrefix(p, LuckPermsHook.getPrefix(p.getName()));
|
||||
colorRemoved = true;
|
||||
}
|
||||
inWar = true;
|
||||
}
|
||||
if (!inWar) {
|
||||
LuckPermsHook.resetPrefix(p.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 60L); // 20 Tick (1 Second) delay before run() is called
|
||||
}
|
||||
}
|
||||
@@ -1,381 +0,0 @@
|
||||
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 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());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@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 ActiveMercRequests 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")) {
|
||||
// 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")) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
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;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
-119
@@ -1,119 +0,0 @@
|
||||
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;
|
||||
|
||||
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("AlathraExtras.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("AlathraExtras.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("AlathraExtras.Admin")) {
|
||||
return null;
|
||||
} else {
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,372 +0,0 @@
|
||||
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")) {
|
||||
// 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")) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
# AlathraWar Version: 1.2.1
|
||||
# AlathraWar Version: 1.3.1
|
||||
## A unique Towny war system for the AlathraMC server
|
||||
|
||||
### Dependencies: Vault, Towny, SiegeWar, TAB, LuckPerms
|
||||
### Dependencies: Vault, Towny, SiegeWar, TAB
|
||||
|
||||
### Commands
|
||||
+ /war - war commands
|
||||
|
||||
@@ -1,50 +1,70 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>me.ShermansWorld</groupId>
|
||||
<artifactId>AlathraWar</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>AlathraWar</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<!-- This adds the Spigot Maven repository to the build -->
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!--This adds the Spigot API artifact to the build -->
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.19-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.LlmDl</groupId>
|
||||
<artifactId>Towny</artifactId>
|
||||
<version>0.98.3.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>me.ShermansWorld</groupId>
|
||||
<artifactId>AlathraWar</artifactId>
|
||||
<version>2.1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>AlathraWar</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<!-- This adds the Spigot Maven repository to the build -->
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>krypton</id>
|
||||
<url>https://repo.kryptonmc.org/releases</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!--This adds the Spigot API artifact to the build -->
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.19-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.LlmDl</groupId>
|
||||
<artifactId>Towny</artifactId>
|
||||
<version>0.98.3.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.neznamy</groupId>
|
||||
<artifactId>tab-api</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,8 @@
|
||||
#Minimum time in days a player must have joined ago to join any war or event.
|
||||
#Set to 0 to disable check
|
||||
minimumPlayerAge: 4
|
||||
#Minimum playtime in hours a player must have in hours to join a war/siege/raid
|
||||
#Set to 0 to disable check
|
||||
minimumPlayTime: 12
|
||||
#How long should a bettering ram open a door (in seconds)
|
||||
batteringRamEffectiveness: 10
|
||||
@@ -0,0 +1,25 @@
|
||||
name: AlathraWar
|
||||
version: ${project.version}
|
||||
api-version: 1.19
|
||||
author: ShermansWorld
|
||||
main: me.ShermansWorld.AlathraWar.Main
|
||||
depend: [Vault, Towny, TAB]
|
||||
|
||||
commands:
|
||||
war:
|
||||
description: used to create, delete, join and leave wars
|
||||
softdepend: [Vault, Towny, TAB]
|
||||
usage: /war
|
||||
siege:
|
||||
description: used to start, end, and view sieges
|
||||
softdepend: [Vault, Towny]
|
||||
usage: /siege
|
||||
raid:
|
||||
description: used to start, end, and view raids
|
||||
softdepend: [Vault, Towny]
|
||||
usage: /raid
|
||||
alathrawaradmin:
|
||||
description: used to administrate wars and modify existing events
|
||||
softdepend: [Vault, Towny, TAB]
|
||||
usage: /alathrawaradmin
|
||||
aliases: [awa]
|
||||
+66
-66
@@ -1,66 +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();
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
+99
-94
@@ -1,99 +1,39 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import 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 org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public final class KillsListener implements Listener
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Helper
|
||||
{
|
||||
@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) {
|
||||
|
||||
}
|
||||
public static String color(final String input) {
|
||||
return ChatColor.translateAlternateColorCodes('&', input);
|
||||
}
|
||||
|
||||
private void siegeKill(final Player killed, final PlayerDeathEvent event) {
|
||||
final Inventory inv = (Inventory)killed.getInventory();
|
||||
public static String chatLabel() {
|
||||
return color("&6[&4AlathraWar&6]&r ");
|
||||
}
|
||||
|
||||
public static void testMsg() {
|
||||
Bukkit.broadcastMessage("test message");
|
||||
}
|
||||
|
||||
/**
|
||||
* Damages all gear in a players inventory
|
||||
*
|
||||
* @param p
|
||||
* @author ShermansWorld
|
||||
*/
|
||||
public static void damageAllGear(Player p) {
|
||||
final Inventory inv = p.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)) {
|
||||
@@ -117,11 +57,17 @@ public final class KillsListener implements Listener
|
||||
damageable.setDamage(249);
|
||||
}
|
||||
}
|
||||
else if (is.getType() == Material.TRIDENT) {
|
||||
damageable.setDamage(damageable.getDamage() + 62);
|
||||
if (damageable.getDamage() > 200) {
|
||||
damageable.setDamage(249);
|
||||
}
|
||||
}
|
||||
meta = (ItemMeta)damageable;
|
||||
is.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
final ItemStack[] armor = killed.getInventory().getArmorContents();
|
||||
final ItemStack[] armor = p.getInventory().getArmorContents();
|
||||
for (int j = 0; j < armor.length; ++j) {
|
||||
if (armor[j] != null) {
|
||||
final ItemStack is2 = armor[j];
|
||||
@@ -205,9 +151,68 @@ public final class KillsListener implements Listener
|
||||
}
|
||||
}
|
||||
}
|
||||
Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + killed.getName());
|
||||
event.setKeepInventory(true);
|
||||
event.getDrops().clear();
|
||||
event.setKeepLevel(true);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param worldCoord worldCoord
|
||||
* @return List of connected chunks
|
||||
* @author NinjaMandalorian
|
||||
*/
|
||||
private static ArrayList<WorldCoord> getAdjCells(WorldCoord worldCoord) {
|
||||
ArrayList<WorldCoord> ReturnList = new ArrayList<>();
|
||||
|
||||
int[][] XZarray = new int[][]{
|
||||
{-1, 0},
|
||||
{1, 0},
|
||||
{0, -1},
|
||||
{0, 1}
|
||||
}; // Array that contains relative orthogonal shifts from origin
|
||||
for ( int[] pair: XZarray) {
|
||||
// Constructs new WorldCoord for comparison
|
||||
WorldCoord tCoord = new WorldCoord(worldCoord.getWorldName(), worldCoord.getX() + pair[0], worldCoord.getZ() + pair[1]);
|
||||
if (tCoord.getTownOrNull() != null && tCoord.getTownOrNull() == worldCoord.getTownOrNull()) {
|
||||
// If in town, and in same town, adds to return list
|
||||
ReturnList.add(tCoord);
|
||||
}
|
||||
}
|
||||
return ReturnList;
|
||||
}
|
||||
|
||||
/** Gets all adjacently connected townblocks
|
||||
* @param chunkCoord - WorldCoord to check at
|
||||
* @return List of WorldCoords
|
||||
* @author NinjaMandalorian
|
||||
*/
|
||||
public static ArrayList<WorldCoord> getCluster(WorldCoord chunkCoord){
|
||||
// WCoordList is the returning array, SearchList is the to-search list.
|
||||
ArrayList<WorldCoord> WCoordList = new ArrayList<>();
|
||||
ArrayList<WorldCoord> SearchList = new ArrayList<>();
|
||||
SearchList.add(chunkCoord); // Adds 1st chunk to list
|
||||
|
||||
// Iterates through SearchList, to create a full list of every adjacent cell.
|
||||
while (SearchList.size() > 0) {
|
||||
// Gets WorldCoord
|
||||
WorldCoord toSearch = SearchList.get(0);
|
||||
// Gets adjacent cells
|
||||
ArrayList<WorldCoord> adjCells = getAdjCells(toSearch);
|
||||
for (WorldCoord cell : adjCells) {
|
||||
// If in final list, ignore.
|
||||
if (WCoordList.contains(cell)) {
|
||||
continue;
|
||||
// If in to-search list, ignore
|
||||
} else if (SearchList.contains(cell)) {
|
||||
continue;
|
||||
// Otherwise, add to search-list.
|
||||
} else {
|
||||
SearchList.add(cell);
|
||||
}
|
||||
}
|
||||
// Removes from search list and adds to finished list. After checking all adjacent chunks.
|
||||
SearchList.remove(toSearch);
|
||||
WCoordList.add(toSearch);
|
||||
}
|
||||
|
||||
return WCoordList; // Returns list
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.commands.*;
|
||||
import me.ShermansWorld.AlathraWar.items.WarItemRegistry;
|
||||
import me.ShermansWorld.AlathraWar.listeners.*;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
import me.ShermansWorld.AlathraWar.hooks.TABHook;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import org.bukkit.Bukkit;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
public static Main instance;
|
||||
public static Economy econ;
|
||||
public static AlathraWarLogger warLogger;
|
||||
|
||||
static {
|
||||
instance = null;
|
||||
econ = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dangerous if done at the wrong time!
|
||||
*/
|
||||
public static void initData() {
|
||||
File userDataFolder = new File("plugins" + File.separator + "AlathraWar" + File.separator + "userdata");
|
||||
if (!userDataFolder.exists()) {
|
||||
userDataFolder.mkdirs();
|
||||
}
|
||||
|
||||
WarData.setWars(WarData.createWars());
|
||||
}
|
||||
|
||||
@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;
|
||||
this.saveDefaultConfig();
|
||||
initLogs();
|
||||
|
||||
new WarData(this);
|
||||
// new TimeoutData(this);
|
||||
new WarCommands(this);
|
||||
new SiegeCommands(this);
|
||||
new RaidCommands(this);
|
||||
new AdminCommands(this);
|
||||
getCommand("war").setTabCompleter(new WarTabCompletion());
|
||||
getCommand("siege").setTabCompleter(new SiegeTabCompletion());
|
||||
getCommand("raid").setTabCompleter(new RaidTabCompletion());
|
||||
getCommand("alathrawaradmin").setTabCompleter(new AdminTabCompletion());
|
||||
getServer().getPluginManager().registerEvents(new KillsListener(), (Plugin) this);
|
||||
getServer().getPluginManager().registerEvents(new CommandsListener(), (Plugin) this);
|
||||
getServer().getPluginManager().registerEvents(new JoinListener(), (Plugin) this);
|
||||
getServer().getPluginManager().registerEvents(new BlockBreakListener(), (Plugin) this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerInteractListener(), this);
|
||||
|
||||
// //run first
|
||||
new WarItemRegistry();
|
||||
// //run second
|
||||
// new WarRecipeRegistry();
|
||||
|
||||
initData();
|
||||
initAPIs();
|
||||
setupEconomy();
|
||||
initLogs();
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
for (War war : WarData.getWars()) {
|
||||
war.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,599 @@
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import org.bukkit.*;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.TownyUniverse;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.boss.BossBar;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.TownBlock;
|
||||
|
||||
public class Siege {
|
||||
|
||||
public static final int maxSiegeTicks = 72000; // 60 minute tick constant
|
||||
|
||||
private War war; // War 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;
|
||||
int[] bukkitId;
|
||||
public ArrayList<String> attackerPlayers;
|
||||
public ArrayList<String> defenderPlayers;
|
||||
public ArrayList<Location> beaconLocs;
|
||||
public final NamespacedKey bossBarKey;
|
||||
|
||||
|
||||
public Siege(final War war, final Town town, OfflinePlayer siegeLeader) {
|
||||
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.siegeLeader = siegeLeader;
|
||||
|
||||
bossBarKey = new NamespacedKey(Main.getInstance(), "siegeBar." + this.getName());
|
||||
|
||||
if (war.getSide(town.getName()) == 2) side1AreAttackers = true;
|
||||
else side1AreAttackers = false;
|
||||
}
|
||||
|
||||
/** 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((Plugin) 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((Plugin) Main.getInstance(), getTickLoop(), 0L, 200L);
|
||||
|
||||
setupDisplayBar();
|
||||
}
|
||||
|
||||
/** Stops a siege */
|
||||
public void stop() {
|
||||
deleteDisplayBar();
|
||||
Bukkit.getScheduler().cancelTask(this.bukkitId[0]);
|
||||
this.war.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 (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 >= maxSiegeTicks) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(Siege.this.bukkitId[0]);
|
||||
SiegeData.removeSiege(Siege.this);
|
||||
if (Siege.this.attackerPoints > Siege.this.defenderPoints) {
|
||||
Siege.this.attackersWin(Siege.this.siegeLeader);
|
||||
} else {
|
||||
Siege.this.defendersWin();
|
||||
}
|
||||
} else {
|
||||
boolean attackersAreOnHomeBlock = false;
|
||||
boolean defendersAreOnHomeBlock = false;
|
||||
siegeTicks = siegeTicks + 200;
|
||||
for (final String playerName : Siege.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(Helper.chatLabel() + "Attempting to look for town at " + WorldCoord.parseWorldCoord(pl).toString());
|
||||
}
|
||||
}
|
||||
for (final String playerName : Siege.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(Helper.chatLabel() + "Attempting to look for town at " + WorldCoord.parseWorldCoord(pl).toString());
|
||||
}
|
||||
}
|
||||
if (attackersAreOnHomeBlock && defendersAreOnHomeBlock) { // Contested
|
||||
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) { // Attackers
|
||||
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);
|
||||
} else { // Defenders / None
|
||||
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);
|
||||
this.homeBlockControl = 3;
|
||||
}
|
||||
if (Siege.this.siegeTicks % 6000 == 0) { // Updates every 5 minutes
|
||||
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));
|
||||
}
|
||||
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(String.valueOf(Helper.chatLabel()) + "The attackers have won the siege of " + this.town.getName() + "!");
|
||||
try {
|
||||
nation = resident.getTown().getNation();
|
||||
} catch (Exception e) {}
|
||||
if (nation != null) {
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "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, "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.getAttackerSide() + "!");
|
||||
TownyUniverse.getInstance().getDataSource().deleteTown(this.town);
|
||||
Main.econ.depositPlayer(siegeLeader, 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.getAttackerSide()
|
||||
+ ", valuing $" + String.valueOf(amt));
|
||||
Main.warLogger.log("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide()
|
||||
+ ", valuing $" + String.valueOf(amt));
|
||||
Main.econ.depositPlayer(siegeLeader, amt);
|
||||
|
||||
if (side1AreAttackers) {
|
||||
war.addSide1Points(50);
|
||||
} else {
|
||||
war.addSide2Points(50);
|
||||
}
|
||||
|
||||
stop();
|
||||
clearBeacon();
|
||||
}
|
||||
|
||||
public void defendersWin() {
|
||||
this.town.getAccount().deposit(2500.0, "War chest");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The 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(war.getName() + ": The defenders have won the siege of " + this.town.getName() + "!");
|
||||
|
||||
if (side1AreAttackers) {
|
||||
war.addSide2Points(50);
|
||||
} else {
|
||||
war.addSide1Points(50);
|
||||
}
|
||||
|
||||
stop();
|
||||
clearBeacon();
|
||||
}
|
||||
|
||||
/**
|
||||
* No winnder declared
|
||||
*/
|
||||
public void noWinner() {
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The siege of " + this.town.getName() + " was a draw!");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "No money has been recovered.");
|
||||
Main.warLogger
|
||||
.log(war.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(), (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);
|
||||
}
|
||||
save();
|
||||
} 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 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 OfflinePlayer getSiegeOwner() {
|
||||
return siegeLeader;
|
||||
}
|
||||
|
||||
public void setSiegeOwner(OfflinePlayer siegeOwner) {
|
||||
this.siegeLeader = siegeOwner;
|
||||
}
|
||||
|
||||
/** Gets attacker name string */
|
||||
public String getAttackerSide() {
|
||||
if (side1AreAttackers) {
|
||||
return war.getSide1();
|
||||
} else {
|
||||
return war.getSide2();
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets defender name string */
|
||||
public String getDefenderSide() {
|
||||
if (side1AreAttackers) {
|
||||
return war.getSide2();
|
||||
} else {
|
||||
return war.getSide1();
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshDisplayBar() {
|
||||
BossBar bossBar = Bukkit.getBossBar(bossBarKey);
|
||||
if(bossBar == null) bossBar = createNewDisplayBar();
|
||||
|
||||
bossBar.setTitle(String.format("%d -- Attackers -Siege Score- Defenders -- %d", this.attackerPoints, this.defenderPoints));
|
||||
bossBar.setProgress((double) (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 -Siege Score- Defenders -- %d", this.attackerPoints, this.defenderPoints), BarColor.YELLOW, BarStyle.SOLID);
|
||||
}
|
||||
|
||||
public int getAttackerPoints() {
|
||||
return this.attackerPoints;
|
||||
}
|
||||
|
||||
public int getDefenderPoints() {
|
||||
return this.defenderPoints;
|
||||
}
|
||||
|
||||
public int getMaxSiegeTicks() {
|
||||
return maxSiegeTicks;
|
||||
}
|
||||
|
||||
public void setSiegeTicks(int siegeTicks) {
|
||||
this.siegeTicks = siegeTicks;
|
||||
}
|
||||
|
||||
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 void setAttackerPoints(int points) {
|
||||
this.attackerPoints = points;
|
||||
}
|
||||
|
||||
public void setDefenderPoints(int points) {
|
||||
this.defenderPoints = points;
|
||||
}
|
||||
|
||||
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 OfflinePlayer getSiegeLeader() {
|
||||
return siegeLeader;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
SiegeData.saveSiege(this);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.getWar().getName() + "-" + this.getTown();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,297 @@
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
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.commands.CommandHelper;
|
||||
import me.ShermansWorld.AlathraWar.data.DataManager;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
|
||||
public class War {
|
||||
|
||||
// Object Fields
|
||||
private String name;
|
||||
private String side1;
|
||||
private String side2;
|
||||
private ArrayList<String> side1Towns = new ArrayList<String>();
|
||||
private ArrayList<String> side2Towns = new ArrayList<String>();
|
||||
private ArrayList<String> surrenderedTowns = new ArrayList<String>();
|
||||
private int side1Points = 0;
|
||||
private int side2Points = 0;
|
||||
|
||||
// References
|
||||
private ArrayList<Siege> sieges = new ArrayList<Siege>();
|
||||
private ArrayList<Raid> raids = new ArrayList<Raid>();
|
||||
private int lastRaidTimeSide1 = 0;
|
||||
private int lastRaidTimeSide2 = 0;
|
||||
|
||||
/**
|
||||
* War Constructor
|
||||
* @param name - Name of war
|
||||
* @param side1 - Side 1 name
|
||||
* @param side2 - Side 2 name
|
||||
*/
|
||||
public War(final String name, final String side1, final String side2) {
|
||||
this.name = name;
|
||||
this.side1 = side1;
|
||||
this.side2 = side2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets side of town
|
||||
* -1 - Surrendered
|
||||
* 0 - None
|
||||
* 1 - Side 1
|
||||
* 2 - Side 2
|
||||
* @param string town
|
||||
* @return result
|
||||
*/
|
||||
public int getSide(String string) {
|
||||
for (String str : surrenderedTowns) {
|
||||
if (str.equalsIgnoreCase(string)) return -1;
|
||||
}
|
||||
|
||||
for (String str : side1Towns) {
|
||||
if (str.equalsIgnoreCase(string)) return 1;
|
||||
}
|
||||
|
||||
for (String str : side2Towns) {
|
||||
if (str.equalsIgnoreCase(string)) return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getSide(Town town) {
|
||||
return getSide(town.getName());
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getSide1() {
|
||||
return this.side1;
|
||||
}
|
||||
|
||||
public String getSide2() {
|
||||
return this.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<Siege> getSieges() {
|
||||
return sieges;
|
||||
}
|
||||
|
||||
public void addSiege(Siege siege) {
|
||||
sieges.add(siege);
|
||||
}
|
||||
|
||||
public ArrayList<Raid> getRaids() {
|
||||
return raids;
|
||||
}
|
||||
|
||||
public void addRaid(Raid raid) {
|
||||
raids.add(raid);
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
DataManager.deleteFile("wars" + File.separator + this.getName() + ".yml");
|
||||
this.name = name;
|
||||
this.save();
|
||||
}
|
||||
|
||||
public void setSide1(String side1) {
|
||||
this.side1 = side1;
|
||||
}
|
||||
|
||||
public void setSide2(String side2) {
|
||||
this.side2 = side2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
private static ArrayList<String> townListToPlayers(ArrayList<String> townList) {
|
||||
ArrayList<String> returnList = new ArrayList<String>();
|
||||
for (String townString : townList) {
|
||||
Town town = TownyAPI.getInstance().getTown(townString);
|
||||
if (town != null) {
|
||||
for (Resident res : town.getResidents()) {
|
||||
//Minuteman countermeasure! if they are they get skipped
|
||||
if (CommandHelper.isPlayerMinuteman(res.getName()) == 0) {
|
||||
returnList.add(res.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
public void setLastRaidTimeSide1(int lastRaidTime) {
|
||||
this.lastRaidTimeSide1 = lastRaidTime;
|
||||
}
|
||||
|
||||
public int getLastRaidTimeSide1() {
|
||||
return this.lastRaidTimeSide1;
|
||||
}
|
||||
|
||||
public void setLastRaidTimeSide2(int lastRaidTime) {
|
||||
this.lastRaidTimeSide2 = lastRaidTime;
|
||||
}
|
||||
|
||||
public int getLastRaidTimeSide2() {
|
||||
return this.lastRaidTimeSide2;
|
||||
}
|
||||
|
||||
public int getSide1Points() {
|
||||
return this.side1Points;
|
||||
}
|
||||
|
||||
public int getSide2Points() {
|
||||
return this.side2Points;
|
||||
}
|
||||
|
||||
public void addSide1Points(int points) {
|
||||
side1Points += points;
|
||||
}
|
||||
|
||||
public void addSide2Points(int points){
|
||||
side2Points += points;
|
||||
}
|
||||
|
||||
public void setSide1Points(int side1Points) {
|
||||
this.side1Points = side1Points;
|
||||
}
|
||||
|
||||
public void setSide2Points(int side2Points) {
|
||||
this.side2Points = side2Points;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,791 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
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;
|
||||
|
||||
public class AdminTabCompletion implements TabCompleter {
|
||||
|
||||
List<String> base = List.of(new String[]{
|
||||
"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,247 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
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.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;
|
||||
|
||||
public class CommandHelper {
|
||||
|
||||
/**
|
||||
* Grabs list of all war names
|
||||
* @return list of wars
|
||||
*/
|
||||
public static List<String> getWarNames() {
|
||||
List<String> out = new ArrayList<>();
|
||||
for (War w : WarData.getWars()) {
|
||||
out.add(w.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 (War w : WarData.getWars()) {
|
||||
if(w.getName().equalsIgnoreCase(name)) {
|
||||
out.add(w.getSide1());
|
||||
out.add(w.getSide2());
|
||||
break;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* get 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* get 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<>();
|
||||
War 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* get 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<>();
|
||||
War 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* get 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<>();
|
||||
War 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 (Raid 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 (Siege r : SiegeData.getSieges()) {
|
||||
out.add(r.getTown().getName());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* get 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* get 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* get 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) {
|
||||
//get 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(Helper.chatLabel() + sender.getName() + " ran command: " + log.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,600 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import com.palmergames.bukkit.towny.object.*;
|
||||
import me.ShermansWorld.AlathraWar.*;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RaidCommands implements CommandExecutor {
|
||||
|
||||
public RaidCommands(final Main plugin) {
|
||||
plugin.getCommand("raid").setExecutor((CommandExecutor)this);
|
||||
}
|
||||
|
||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
|
||||
// final Player p = (Player) sender;
|
||||
CommandHelper.logCommand(sender, label, args);
|
||||
if (args.length == 0) {
|
||||
fail(sender, args, "syntax");
|
||||
} else if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("list")) {
|
||||
listRaids(sender, args);
|
||||
} else if (args[0].equalsIgnoreCase("help")) {
|
||||
raidHelp(sender, args);
|
||||
} else {
|
||||
fail(sender, args, "syntax");
|
||||
}
|
||||
}else if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("start")) {
|
||||
startRaid(sender, args, false);
|
||||
} else if (args[0].equalsIgnoreCase("stop")) {
|
||||
stopRaid(sender, args);
|
||||
} else if (args[0].equalsIgnoreCase("join")) {
|
||||
joinRaid(sender, args, false);
|
||||
} else if (args[0].equalsIgnoreCase("leave")) {
|
||||
leaveRaid(sender, args, false);
|
||||
} else if (args[0].equalsIgnoreCase("abandon")) {
|
||||
abandonRaid(sender, args);
|
||||
} else {
|
||||
fail(sender, args, "syntax");
|
||||
}
|
||||
} else {
|
||||
fail(sender, args, "syntax");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a raid
|
||||
*
|
||||
* @param p
|
||||
* @param args
|
||||
*/
|
||||
protected static void startRaid(CommandSender p, String[] args, boolean admin) {
|
||||
boolean warFound = false;
|
||||
boolean townExists = false;
|
||||
for (final War war : WarData.getWars()) {
|
||||
//if this is run as admin, shift our check forward a slot
|
||||
if (war.getName().equalsIgnoreCase(args[1 + (admin ? 1 : 0)])) {
|
||||
warFound = true;
|
||||
|
||||
Player raidOwner = null;
|
||||
if((p instanceof Player)) {
|
||||
raidOwner = (Player) p;
|
||||
}
|
||||
if(admin && args.length >= 6) {
|
||||
raidOwner = Bukkit.getPlayer(args[5]);
|
||||
if(raidOwner == null) {
|
||||
p.sendMessage("Player Does not exist");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (raidOwner == null) {
|
||||
p.sendMessage("Raid Owner is Null");
|
||||
return;
|
||||
}
|
||||
|
||||
TownyWorld townyWorld;
|
||||
townyWorld = WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownyWorld();
|
||||
|
||||
String side = "";
|
||||
if (war.getSide1Players().contains(raidOwner.getName())) {
|
||||
side = war.getSide1();
|
||||
} else if (war.getSide2Players().contains(raidOwner.getName())) {
|
||||
side = war.getSide2();
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
return;
|
||||
}
|
||||
|
||||
//Minuteman countermeasures
|
||||
int minuteman = CommandHelper.isPlayerMinuteman(raidOwner.getName());
|
||||
boolean override = false;
|
||||
if (admin) {
|
||||
if (args.length >= 7) {
|
||||
if (Boolean.parseBoolean(args[6])) {
|
||||
//player has joined to recently
|
||||
p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!");
|
||||
override = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
//override?
|
||||
if(!override) {
|
||||
if (minuteman != 0) {
|
||||
if (minuteman == 1) {
|
||||
//player has joined to recently
|
||||
if (admin) p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
raidOwner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
return;
|
||||
} else if (minuteman == 2) {
|
||||
//player has played too little
|
||||
if (admin) p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
raidOwner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//check if in a town
|
||||
//takes the command runners town as the gather point
|
||||
Town gatherTown = null;
|
||||
try {
|
||||
//if admin, and we have a gather town argument, use it
|
||||
if(admin && args.length >= 5) {
|
||||
if(args[4].equalsIgnoreCase("defaultCode")) {
|
||||
//use default behavior
|
||||
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock());
|
||||
} else if(TownyAPI.getInstance().getTown(args[4]) != null) {
|
||||
gatherTown = TownyAPI.getInstance().getTown(args[4]);
|
||||
} else {
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "No valid town set for gather town, defaulting to current location");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "No valid town set for gather town, defaulting to current location");
|
||||
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock());
|
||||
}
|
||||
} else {
|
||||
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock());
|
||||
}
|
||||
} catch (NotRegisteredException e2) {
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
|
||||
return;
|
||||
}
|
||||
if (gatherTown == null) {
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
|
||||
return;
|
||||
}
|
||||
|
||||
//parse the argunment for town
|
||||
for (final String entry : townyWorld.getTowns().keySet()) {
|
||||
final Town raidedTown = townyWorld.getTowns().get(entry);
|
||||
|
||||
//if this is run as admin, shift our check forward a slot
|
||||
if (raidedTown.getName().equalsIgnoreCase(args[2 + (admin ? 1 : 0)]) && gatherTown != null) {
|
||||
|
||||
Main.warLogger.log("Raided town: " + raidedTown.getName());
|
||||
Main.warLogger.log("Gather town: " + gatherTown.getName());
|
||||
Main.warLogger.log("Raid Owner: " + raidOwner.getName());
|
||||
p.sendMessage("Raided town: " + raidedTown.getName());
|
||||
p.sendMessage("Gather town: " + gatherTown.getName());
|
||||
p.sendMessage("Raid Owner: " + raidOwner.getName());
|
||||
//DEBUG PRINT
|
||||
for (String t : war.getSide1Towns()) {
|
||||
Main.warLogger.log("Side1 town: " + t);
|
||||
p.sendMessage("Side1 town: " + t);
|
||||
}
|
||||
for (String t : war.getSide2Towns()) {
|
||||
Main.warLogger.log("Side2 town: " + t);
|
||||
p.sendMessage("Side2 town: " + t);
|
||||
}
|
||||
|
||||
//check if the town were attempting to raid is in the war
|
||||
if(!war.getSide1Towns().contains(raidedTown.getName().toLowerCase()) && !war.getSide2Towns().contains(raidedTown.getName().toLowerCase())) {
|
||||
if (war.getSurrenderedTowns().contains(raidedTown.getName().toLowerCase())) {
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "The town you are trying to raid has already surrendered!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "The town you are trying to raid has already surrendered!");
|
||||
return;
|
||||
}
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "The town you are trying to raid is not part of the war!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "The town you are trying to raid is not part of the war!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Is being sieged check
|
||||
for (Siege s : SiegeData.getSieges()) {
|
||||
if(s.getTown().getName().equalsIgnoreCase(raidedTown.getName())) {
|
||||
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "That town is already currently being sieged! Cannot raid at this time!");
|
||||
if(admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "That town is already currently being sieged! Cannot raid at this time!");
|
||||
}
|
||||
}
|
||||
|
||||
townExists = true;
|
||||
|
||||
Raid raid2;
|
||||
if (war.getSide1Players().contains(raidOwner.getName())) {
|
||||
//Time and raid activity validity check
|
||||
int c = RaidData.isValidRaid(war, side, raidedTown);
|
||||
if (c == 2) {
|
||||
//if were admin, see if an owner arg exists, and if so then use it
|
||||
raid2 = new Raid(war, raidedTown, gatherTown, true, raidOwner);
|
||||
} else if (c == 1) {
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "This town is already being raided at this time!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "This town is already being raided at this time!");
|
||||
return;
|
||||
} else if (c == 0) {
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Your side has raided too recently!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "Your side has raided too recently!");
|
||||
return;
|
||||
} else if (c == -1) {
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "This town was raided too recently!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "This town was raided too recently!");
|
||||
return;
|
||||
} else if (c == -2) {
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "At least on member of the raided town must be online to defend it!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "At least on member of the raided town must be online to defend it!");
|
||||
return;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
} else {
|
||||
//Something broke if this runs
|
||||
if (!war.getSide2Players().contains(raidOwner.getName())) {
|
||||
Bukkit.getLogger().info("Unable to find player declaring raid in the war");
|
||||
return;
|
||||
}
|
||||
//Time and raid activity validity check
|
||||
int c = RaidData.isValidRaid(war, side, raidedTown);
|
||||
if (c == 2) {
|
||||
raid2 = new Raid(war, raidedTown, gatherTown, false, raidOwner);
|
||||
} else if (c == 1) {
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "This town is already being raided at this time!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "This town is already being raided at this time!");
|
||||
return;
|
||||
} else if (c == 0) {
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Your side has raided too recently!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "Your side has raided too recently!");
|
||||
return;
|
||||
} else if (c == -1) {
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "This town was raided too recently!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "This town was raided too recently!");
|
||||
return;
|
||||
} else if (c == -2) {
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "At least on member of the raided town must be online to defend it!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "At least on member of the raided town must be online to defend it!");
|
||||
return;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
// Player participance check
|
||||
Town leaderTown = TownyAPI.getInstance().getResident(raidOwner).getTownOrNull();
|
||||
int sideR = war.getSide(leaderTown.getName().toLowerCase());
|
||||
if (sideR == 0) {
|
||||
if (admin) p.sendMessage(Helper.chatLabel() + "You are not in this war.");
|
||||
raidOwner.sendMessage(Helper.chatLabel() + "You are not in this war.");
|
||||
return;
|
||||
} else if (sideR == -1) {
|
||||
if (admin) p.sendMessage(Helper.chatLabel() + "You have surrendered.");
|
||||
raidOwner.sendMessage(Helper.chatLabel() + "You have surrendered.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Attacking own side
|
||||
if (war.getSide(raidedTown) == sideR) {
|
||||
if (admin) p.sendMessage(Helper.chatLabel() + "You cannot attack your own towns.");
|
||||
raidOwner.sendMessage(Helper.chatLabel() + "You cannot attack your own towns.");
|
||||
return;
|
||||
}
|
||||
|
||||
//check player balance
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(raidOwner.getUniqueId());
|
||||
if (Main.econ.getBalance(offlinePlayer) <= 1000.0) {
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "You must have at least $1000 to put up to start a raid.");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "You must have at least $1000 to put up to start a raid.");
|
||||
return;
|
||||
}
|
||||
|
||||
//publish raid
|
||||
Main.econ.withdrawPlayer(offlinePlayer, 1000);
|
||||
raid2.addActiveRaider(raidOwner.getName());
|
||||
RaidData.addRaid(raid2);
|
||||
raid2.start(); //funny funny method haha
|
||||
WarData.saveWar(raid2.getWar());
|
||||
|
||||
//broadcast
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "As part of " + war.getName() + ", forces from " + raid2.getRaiderSide() + " are gathering to raid the town of " + raidedTown.getName() + "!");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "All players from the defending side have been drafted for the town's defense.");
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + "The raid of "
|
||||
+ raidedTown.getName() + " will begin in " + (int) (RaidPhase.TRAVEL.startTick / 20 / 60) + " minutes!");
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() +
|
||||
"The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!");
|
||||
|
||||
Main.warLogger.log(raidOwner.getName() + " started a raid.");
|
||||
if(admin) Main.warLogger.log(raidOwner.getName() + " started a raid from admin interference.");
|
||||
Main.warLogger.log("As part of " + war.getName() + ", forces from " + raid2.getRaiderSide() + " are raiding the town of " + raidedTown.getName() + "!");
|
||||
Main.warLogger.log("The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!warFound) {
|
||||
p.sendMessage(Helper.chatLabel() + "That war does not exist! /raid start [war] [town]");
|
||||
return;
|
||||
}
|
||||
if (!townExists) {
|
||||
p.sendMessage(Helper.chatLabel() + "That town does not exist! /raid start [war] [town]");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the current raid by admins
|
||||
*
|
||||
* @param p
|
||||
* @param args
|
||||
*/
|
||||
private static void stopRaid(CommandSender p, String[] args) {
|
||||
//admin check
|
||||
if (!p.hasPermission("AlathraWar.admin")) {
|
||||
fail(p, args, "permission");
|
||||
return;
|
||||
}
|
||||
|
||||
//are there even any raids
|
||||
if (RaidData.getRaids().isEmpty()) {
|
||||
fail(p, args, "noRaids");
|
||||
return;
|
||||
}
|
||||
|
||||
//find our desired raid and stop it
|
||||
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
|
||||
|
||||
if (raid != null) {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "raid cancelled");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The raid of " + raid.getRaidedTown().getName() + " has been cancelled by an admin");
|
||||
raid.stop(); //this purges itself from raids
|
||||
} else {
|
||||
fail(p, args, "badName");
|
||||
}
|
||||
}
|
||||
|
||||
protected static void joinRaid(CommandSender p, String[] args, boolean admin) {
|
||||
//Grab raid!
|
||||
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
|
||||
if (raid != null) {
|
||||
if (raid.getWar().getName().equalsIgnoreCase(args[1])) {
|
||||
Player joiner = null;
|
||||
if(p instanceof Player) {
|
||||
joiner = (Player) p;
|
||||
}
|
||||
|
||||
if (admin) {
|
||||
joiner = Bukkit.getPlayer(args[3]);
|
||||
|
||||
if(joiner != null) {
|
||||
if (args[4] != null) {
|
||||
if (args[4].equalsIgnoreCase(raid.getDefenderSide())) {
|
||||
if (!raid.getDefenderPlayers().contains(joiner.getName()))
|
||||
raid.getDefenderPlayers().add(joiner.getName());
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "Player " + joiner.getName() + " added to defender side.");
|
||||
Main.warLogger.log("Player " + joiner.getName() + " added to defender side.");
|
||||
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You were forcefully added to the defender side against the raid party on " + raid.getRaidedTown() + " by an admin.");
|
||||
return;
|
||||
} else {
|
||||
if (!raid.getRaiderPlayers().contains(joiner.getName()))
|
||||
raid.getRaiderPlayers().add(joiner.getName());
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "Player " + joiner.getName() + " added to raider side.");
|
||||
Main.warLogger.log("Player " + joiner.getName() + " added to raider side.");
|
||||
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You were forcefully added to the raid party on " + raid.getRaidedTown() + " by an admin. Leaving the gather town will remove you from the raid party.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "Player " + args[3] + " not found!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(joiner == null) {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "Player not found! Is something broken?");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!raid.getWar().getSide1Players().contains(joiner.getName()) && !raid.getWar().getSide2Players().contains(joiner.getName())) {
|
||||
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
}
|
||||
|
||||
//Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime
|
||||
//also 12 hours min platim by default
|
||||
int minuteman = CommandHelper.isPlayerMinuteman(joiner.getName());
|
||||
boolean override = false;
|
||||
if (admin) {
|
||||
if (args.length >= 6) {
|
||||
if (Boolean.parseBoolean(args[5])) {
|
||||
//player has joined to recently
|
||||
p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!");
|
||||
override = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!override) {
|
||||
if (minuteman != 0) {
|
||||
if (minuteman == 1) {
|
||||
//player has joined to recently
|
||||
if (admin) p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
joiner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
return;
|
||||
} else if (minuteman == 2) {
|
||||
//player has played too little
|
||||
if (admin) p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
joiner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//check if gather phase
|
||||
if(!admin) {
|
||||
if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START) {
|
||||
try {
|
||||
//check if the player is in the gather town
|
||||
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
|
||||
if (cluster.contains(WorldCoord.parseWorldCoord(joiner))) {
|
||||
raid.addActiveRaider(joiner.getName());
|
||||
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
|
||||
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
|
||||
} else {
|
||||
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be in the gathering town to join the raid on " + raid.getRaidedTown().getName() + ".");
|
||||
}
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You cannot join the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
//check if the player is in the gather town
|
||||
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
|
||||
if (cluster.contains(WorldCoord.parseWorldCoord(joiner))) {
|
||||
raid.addActiveRaider(joiner.getName());
|
||||
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
|
||||
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
|
||||
} else {
|
||||
joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be in the gathering town to join the raid on " + raid.getRaidedTown().getName() + ".");
|
||||
}
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
raid.save();
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "No raid is gathering in this town or this town does not exist!");
|
||||
}
|
||||
}
|
||||
|
||||
protected static void leaveRaid(CommandSender player, String[] args, boolean admin) {
|
||||
//Get raid!
|
||||
Player p = null;
|
||||
if (admin) {
|
||||
p = Bukkit.getPlayer(args[3]);
|
||||
if (p == null) {
|
||||
player.sendMessage(String.valueOf(Helper.chatLabel()) + "Error: player not found!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(p == null) {
|
||||
p = (Player) player;
|
||||
}
|
||||
|
||||
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
|
||||
if (raid != null) {
|
||||
if (raid.getWar().getName().equalsIgnoreCase(args[1])) {
|
||||
if (!raid.getWar().getSide1Players().contains(p.getName()) && !raid.getWar().getSide2Players().contains(p.getName())) {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
if (admin) player.sendMessage(String.valueOf(Helper.chatLabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
}
|
||||
|
||||
//check if gather phase
|
||||
if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START) {
|
||||
try {
|
||||
//check if player is in gather town
|
||||
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
|
||||
if (cluster.contains(WorldCoord.parseWorldCoord(p))) {
|
||||
raid.removeActiveRaider(p.getName());
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "You have left the raid on " + raid.getRaidedTown().getName() + "!");
|
||||
if (admin) player.sendMessage(String.valueOf(Helper.chatLabel()) + "You have left the raid on " + raid.getRaidedTown().getName() + "!");
|
||||
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "You cannot leave the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
|
||||
if (admin) player.sendMessage(String.valueOf(Helper.chatLabel()) + "You cannot leave the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
|
||||
}
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
raid.save();
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "No raid is gathering in this town or this town does not exist!");
|
||||
if (admin) player.sendMessage(String.valueOf(Helper.chatLabel()) + "No raid is gathering in this town or this town does not exist!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abandons the raid
|
||||
*
|
||||
* @param p
|
||||
* @param args
|
||||
*/
|
||||
private static void abandonRaid(CommandSender p, String[] args) {
|
||||
//Get raid
|
||||
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
|
||||
if (raid != null) {
|
||||
if (raid.getWar().getName().equalsIgnoreCase(args[1])) {
|
||||
if (!raid.getWar().getSide1Players().contains(p.getName()) && !raid.getWar().getSide2Players().contains(p.getName())) {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (raid.getOwner().getName().equalsIgnoreCase(p.getName())) {
|
||||
//check if gather phase
|
||||
if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START || raid.getPhase() == RaidPhase.TRAVEL || raid.getPhase() == RaidPhase.COMBAT) {
|
||||
//force defender victory
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The raid on " + raid.getRaidedTown().getName() + " has been abandoned by " + raid.getRaiderSide());
|
||||
Main.warLogger.log(p.getName() + " abandoned the raid on " + raid.getRaidedTown().getName() + " they started at " + raid.getGatherTown().getName());
|
||||
raid.defendersWin(raid.getRaiderScore(), raid.getDefenderScore());
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "You cannot abandon the raid on " + raid.getRaidedTown().getName() + "! It has a problem!");
|
||||
}
|
||||
} else {
|
||||
fail(p, args, "owner");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "This raid does not exist!");
|
||||
}
|
||||
|
||||
private static void listRaids(CommandSender p, String[] args) {
|
||||
if (RaidData.getRaids().isEmpty()) {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "There are currently no Raids in progress");
|
||||
return;
|
||||
}
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "Raids currently in progress:");
|
||||
for (final Raid raid : RaidData.getRaids()) {
|
||||
p.sendMessage("Name: " + raid.getName());
|
||||
p.sendMessage("War: " + raid.getWar().getName());
|
||||
p.sendMessage("Owner: " + raid.getOwner().getName());
|
||||
p.sendMessage("Raiding: " + raid.getRaidedTown().getName().toLowerCase());
|
||||
p.sendMessage("Gathering In: " + raid.getGatherTown().getName().toLowerCase());
|
||||
p.sendMessage("Raiders: " + raid.getRaiderSide());
|
||||
p.sendMessage("Defenders: " + raid.getDefenderSide());
|
||||
p.sendMessage("Raider Score: " + raid.getRaiderScore());
|
||||
p.sendMessage("Defender Score: " + raid.getDefenderScore());
|
||||
p.sendMessage("Raid Phase: " + raid.getPhase().name());
|
||||
p.sendMessage("Time Left: " + (RaidPhase.END.startTick - raid.getRaidTicks()) / 1200 + " minutes");
|
||||
p.sendMessage("-=-=-=-=-=-=-=-=-=-=-=-");
|
||||
}
|
||||
}
|
||||
|
||||
private static void raidHelp(CommandSender p, String[] args) {
|
||||
if (p.hasPermission("!AlathraWar.admin")) {
|
||||
p.sendMessage(Helper.chatLabel() + "/raid stop [name]");
|
||||
}
|
||||
p.sendMessage(Helper.chatLabel() + "/raid start [war] [town]");
|
||||
p.sendMessage(Helper.chatLabel() + "/raid join [war] [town]");
|
||||
p.sendMessage(Helper.chatLabel() + "/raid leave [war] [town]");
|
||||
p.sendMessage(Helper.chatLabel() + "/raid abandon [war] [town]");
|
||||
p.sendMessage(Helper.chatLabel() + "/raid list");
|
||||
}
|
||||
|
||||
private static void fail(CommandSender p, String[] args, String type) {
|
||||
switch (type) {
|
||||
case "permissions" -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "&cYou do not have permission to do this");
|
||||
case "syntax" -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "Invalid Syntax. /raid help");
|
||||
case "noRaids" -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "There are currently no Raids in progress");
|
||||
case "badName" -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "A raid could not be found with this Name! Type /raid list to view current raids");
|
||||
case "owner" -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "Only the player who started the raid can abandon it.");
|
||||
default -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "Invalid Arguments. /raid help");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
import com.palmergames.bukkit.towny.utils.NameUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class RaidTabCompletion implements TabCompleter {
|
||||
|
||||
private static final List<String> base = List.of(new String[] {
|
||||
"abandon",
|
||||
"help",
|
||||
"join",
|
||||
"leave",
|
||||
"list",
|
||||
"start"
|
||||
});
|
||||
|
||||
private static final List<String> baseAdmin = List.of(new String[] {
|
||||
"abandon",
|
||||
"help",
|
||||
"join",
|
||||
"leave",
|
||||
"list",
|
||||
"start",
|
||||
"stop"
|
||||
});
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
boolean flag = sender.hasPermission("AlathraWar.admin");
|
||||
|
||||
if (args.length > 0) {
|
||||
if(args.length > 1) {
|
||||
switch (args[0]) {
|
||||
case "abandon", "join", "leave", "start", "stop" -> {
|
||||
if (args.length > 2) {
|
||||
if (args.length > 3) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyWarTowns(args[1]), args[2]);
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[1]);
|
||||
}
|
||||
}
|
||||
//help, list
|
||||
default -> {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(flag ? baseAdmin : base, args[0]);
|
||||
}
|
||||
} else {
|
||||
return flag ? baseAdmin : base;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,290 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.*;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
|
||||
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.HashSet;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
|
||||
public class SiegeCommands implements CommandExecutor {
|
||||
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) {
|
||||
CommandHelper.logCommand(sender, label, args);
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(String.valueOf(Helper.chatLabel()) + "Invalid Arguments. /siege help");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Start
|
||||
// Stop
|
||||
// Abandon
|
||||
// List
|
||||
// Help
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "start" -> {
|
||||
siegeStart(sender, args, false);
|
||||
return true;
|
||||
}
|
||||
case "stop" -> {
|
||||
siegeStop(sender, args);
|
||||
return true;
|
||||
}
|
||||
case "abandon" -> {
|
||||
siegeAbandon(sender, args);
|
||||
return true;
|
||||
}
|
||||
case "list" -> {
|
||||
siegeList(sender, args);
|
||||
return true;
|
||||
}
|
||||
case "help" -> {
|
||||
siegeHelp(sender, args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static void siegeStart(CommandSender sender, String[] args, boolean admin) {
|
||||
// if (!(sender instanceof Player)) return;
|
||||
//if this is admin mode use the forth arg instad of sender.
|
||||
//if player is null after this then force end
|
||||
Player siegeOwner = null;
|
||||
if((sender instanceof Player)) {
|
||||
siegeOwner = (Player) sender;
|
||||
}
|
||||
if(admin && args.length >= 5) {
|
||||
siegeOwner = Bukkit.getPlayer(args[3]);
|
||||
if(siegeOwner == null) {
|
||||
sender.sendMessage("Player Does not exist");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (siegeOwner == null) {
|
||||
sender.sendMessage("Owner is Null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length < 3) {
|
||||
sender.sendMessage(Helper.chatLabel() + "/war siege [war] [town]");
|
||||
return;
|
||||
}
|
||||
|
||||
// War check
|
||||
War war = WarData.getWar(args[1]);
|
||||
if (war == null) {
|
||||
siegeOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "That war does not exist! /siege start [war] [town]");
|
||||
if(admin) sender.sendMessage(String.valueOf(Helper.chatLabel()) + "That war does not exist! /siege start [war] [town]");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Player participance check
|
||||
Town leaderTown = TownyAPI.getInstance().getResident(siegeOwner).getTownOrNull();
|
||||
int side = war.getSide(leaderTown.getName().toLowerCase());
|
||||
|
||||
//DEBUG PRINT
|
||||
Main.warLogger.log("Leader Town: " + leaderTown.getName());
|
||||
Main.warLogger.log("Siege Owner: " + siegeOwner.getName());
|
||||
sender.sendMessage("Leader Town: " + leaderTown.getName());
|
||||
sender.sendMessage("Siege Owner: " + siegeOwner.getName());
|
||||
//DEBUG PRINT
|
||||
for (String t : war.getSide1Towns()) {
|
||||
Main.warLogger.log("Side1 town: " + t);
|
||||
sender.sendMessage("Side1 town: " + t);
|
||||
}
|
||||
for (String t : war.getSide2Towns()) {
|
||||
Main.warLogger.log("Side2 town: " + t);
|
||||
sender.sendMessage("Side2 town: " + t);
|
||||
}
|
||||
|
||||
if (side == 0) {
|
||||
siegeOwner.sendMessage(Helper.chatLabel() + "You are not in this war.");
|
||||
if(admin) sender.sendMessage(Helper.chatLabel() + "You are not in this war.");
|
||||
return;
|
||||
} else if (side == -1) {
|
||||
siegeOwner.sendMessage(Helper.chatLabel() + "You have surrendered.");
|
||||
if(admin) sender.sendMessage(Helper.chatLabel() + "You have surrendered.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime
|
||||
//Minuteman countermeasures
|
||||
int minuteman = CommandHelper.isPlayerMinuteman(siegeOwner.getName());
|
||||
boolean override = false;
|
||||
if (admin) {
|
||||
if (args.length >= 6) {
|
||||
if (Boolean.parseBoolean(args[5])) {
|
||||
//player has joined to recently
|
||||
sender.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!");
|
||||
override = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
//override?
|
||||
if(!override) {
|
||||
if (minuteman != 0) {
|
||||
if (minuteman == 1) {
|
||||
//player has joined to recently
|
||||
if (admin) sender.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
siegeOwner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
return;
|
||||
} else if (minuteman == 2) {
|
||||
//player has played too little
|
||||
if (admin) sender.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
siegeOwner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Town check
|
||||
Town town = TownyAPI.getInstance().getTown(args[2]);
|
||||
if (town == null) {
|
||||
siegeOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "That town does not exist! /siege start [war] [town]");
|
||||
if(admin) sender.sendMessage(String.valueOf(Helper.chatLabel()) + "That town does not exist! /siege start [war] [town]");
|
||||
return;
|
||||
}
|
||||
Main.warLogger.log("Attacked Town: " + town.getName().toLowerCase());
|
||||
sender.sendMessage("Attacked Town: " + town.getName().toLowerCase());
|
||||
|
||||
// Is being raided check
|
||||
for ( Raid r : RaidData.getRaids()) {
|
||||
if(r.getRaidedTown().getName().equalsIgnoreCase(town.getName())) {
|
||||
siegeOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "That town is already currently being raided! Cannot siege at this time!");
|
||||
if(admin) sender.sendMessage(String.valueOf(Helper.chatLabel()) + "That town is already currently being raided! Cannot siege at this time!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Attacking own side
|
||||
if (war.getSide(town) == side) {
|
||||
siegeOwner.sendMessage(Helper.chatLabel() + "You cannot attack your own towns.");
|
||||
if(admin) sender.sendMessage(Helper.chatLabel() + "You cannot attack your own towns.");
|
||||
return;
|
||||
}
|
||||
|
||||
Siege siege = new Siege(war, town, siegeOwner);
|
||||
SiegeData.addSiege(siege);
|
||||
war.addSiege(siege);
|
||||
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + "A siege has been laid on " + siege.getTown() + " by " + siege.getAttackerSide() + "!");
|
||||
|
||||
war.save();
|
||||
siege.start();
|
||||
}
|
||||
|
||||
private static void siegeStop(CommandSender sender, String[] args) {
|
||||
if (!sender.hasPermission("AlathraWar.admin")) {
|
||||
sender.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou do not have permission to do this"));
|
||||
return;
|
||||
}
|
||||
HashSet<Siege> sieges = SiegeData.getSieges();
|
||||
if (sieges.isEmpty()) {
|
||||
sender.sendMessage(String.valueOf(Helper.chatLabel()) + "There are currently no sieges in progress");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length < 3) {
|
||||
sender.sendMessage(Helper.chatLabel() + "/siege stop [town]");
|
||||
return;
|
||||
}
|
||||
|
||||
// War check
|
||||
War war = WarData.getWar(args[1]);
|
||||
if (war == null) {
|
||||
sender.sendMessage(String.valueOf(Helper.chatLabel()) + "That war does not exist! /siege stop [war] [town]");
|
||||
return;
|
||||
}
|
||||
|
||||
for (Siege siege : sieges) {
|
||||
if (siege.getTown().getName().equalsIgnoreCase(args[2])) {
|
||||
sender.sendMessage(String.valueOf(Helper.chatLabel()) + "siege cancelled");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The siege at " + siege.getTown().getName() + " has been cancelled by an admin");
|
||||
//siege.clearBeacon();
|
||||
siege.stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
sender.sendMessage(String.valueOf(Helper.chatLabel()) + "A siege could not be found with this town name! Type /siege list to view current sieges");
|
||||
}
|
||||
|
||||
private static void siegeAbandon(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof Player)) return;
|
||||
final Player p = (Player) sender;
|
||||
|
||||
if (args.length < 3) {
|
||||
sender.sendMessage(Helper.chatLabel() + "/siege abandon [town]");
|
||||
return;
|
||||
}
|
||||
|
||||
// War check
|
||||
War war = WarData.getWar(args[1]);
|
||||
if (war == null) {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "That war does not exist! /siege abandon [war] [town]");
|
||||
return;
|
||||
}
|
||||
|
||||
Siege siege = SiegeData.getSiege(args[2]);
|
||||
if (siege == null) {
|
||||
p.sendMessage(Helper.chatLabel() + "Invalid siege");
|
||||
return;
|
||||
}
|
||||
|
||||
OfflinePlayer oPlayer = siege.getSiegeLeader();
|
||||
if (oPlayer != (OfflinePlayer) p) {
|
||||
p.sendMessage(Helper.chatLabel() + "You are not the leader of this siege.");
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The siege at " + siege.getTown().getName() + " has been abandoned.");
|
||||
Main.warLogger.log(p.getName() + " abandoned the siege they started at " + siege.getTown().getName());
|
||||
siege.defendersWin();
|
||||
|
||||
}
|
||||
|
||||
private static void siegeList(CommandSender sender, String[] args) {
|
||||
HashSet<Siege> sieges = SiegeData.getSieges();
|
||||
if (sieges.isEmpty()) {
|
||||
sender.sendMessage(String.valueOf(Helper.chatLabel()) + "There are currently no sieges in progress");
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(String.valueOf(Helper.chatLabel()) + "Sieges currently in progress:");
|
||||
for (Siege siege : sieges) {
|
||||
War war = siege.getWar();
|
||||
String color = (siege.getSide1AreAttackers() && (war.getSide(siege.getTown().getName().toLowerCase()) == 1) ) ? "§c" : "§9";
|
||||
sender.sendMessage(war.getName() + " - " + color + siege.getTown().getName().toLowerCase());
|
||||
sender.sendMessage(war.getSide1() + " - " + (siege.getSide1AreAttackers() ? siege.getAttackerPoints() : siege.getDefenderPoints()));
|
||||
sender.sendMessage(war.getSide2() + " - " + (siege.getSide1AreAttackers() ? siege.getDefenderPoints() : siege.getAttackerPoints()));
|
||||
sender.sendMessage("Time Left: " + (Siege.maxSiegeTicks - siege.getSiegeTicks())/1200 + " minutes");
|
||||
sender.sendMessage("-=-=-=-=-=-=-=-=-=-=-=-");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void siegeHelp(CommandSender sender, String[] args) {
|
||||
if (sender.hasPermission("AlathraWar.admin")) {
|
||||
sender.sendMessage(Helper.chatLabel() + "/siege stop [war] [town]");
|
||||
}
|
||||
sender.sendMessage(Helper.chatLabel() + "/siege start [war] [town]");
|
||||
sender.sendMessage(Helper.chatLabel() + "/siege abandon [war] [town]");
|
||||
sender.sendMessage(Helper.chatLabel() + "/siege list");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
import com.palmergames.bukkit.towny.utils.NameUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SiegeTabCompletion implements TabCompleter {
|
||||
|
||||
|
||||
private static final List<String> baseAdmin = List.of(new String[] {
|
||||
"abandon",
|
||||
"help",
|
||||
"list",
|
||||
"start",
|
||||
"stop"
|
||||
});
|
||||
|
||||
private static final List<String> base = List.of(new String[] {
|
||||
"abandon",
|
||||
"help",
|
||||
"list",
|
||||
"start"
|
||||
});
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
boolean flag = sender.hasPermission("AlathraWar.admin");
|
||||
|
||||
if (args.length > 0) {
|
||||
if(args.length > 1) {
|
||||
switch (args[0]) {
|
||||
case "abandon", "start", "stop" -> {
|
||||
if (args.length > 2) {
|
||||
if (args.length > 3) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyWarTowns(args[1]), args[2]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[1]);
|
||||
}
|
||||
}
|
||||
//help, list, debug
|
||||
default -> {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(flag ? baseAdmin : base, args[0]);
|
||||
}
|
||||
} else {
|
||||
return flag ? baseAdmin : base;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,354 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
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 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) {
|
||||
CommandHelper.logCommand(sender, label, args);
|
||||
if (!(sender instanceof Player)) {
|
||||
consoleCommand(sender, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
final Player p = (Player) sender;
|
||||
if (args.length == 0) {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "Invalid Arguments. /war help");
|
||||
return true;
|
||||
} else if (args.length >= 1) {
|
||||
|
||||
switch(args[0].toLowerCase()) {
|
||||
case "create":
|
||||
warCreate(p, args);
|
||||
return true;
|
||||
case "delete":
|
||||
warDelete(p, args);
|
||||
return true;
|
||||
case "join":
|
||||
warJoin(p, args, false);
|
||||
return true;
|
||||
case "surrender":
|
||||
warSurrender(p, args, false);
|
||||
return true;
|
||||
case "list":
|
||||
warList(p, args);
|
||||
return true;
|
||||
case "info":
|
||||
warInfo(p, args);
|
||||
return true;
|
||||
case "help":
|
||||
warHelp(p, args);
|
||||
return true;
|
||||
default:
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + "Invalid Arguments. /war help");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static void warCreate(CommandSender p, String[] args) {
|
||||
if (!p.hasPermission("AlathraWar.admin")) {
|
||||
p.sendMessage("You do not have permission to run this command.");
|
||||
return;
|
||||
}
|
||||
if (args.length >= 4) {
|
||||
War war = new War(args[1], args[2], args[3]);
|
||||
WarData.addWar(war);
|
||||
war.save();
|
||||
|
||||
Bukkit.broadcastMessage(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]);
|
||||
return;
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel())
|
||||
+ "Invalid Arguments. /war create [name] [side1] [side2]");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void warDelete(Player p, String[] args) {
|
||||
if (!p.hasPermission("AlathraWar.admin")) {
|
||||
p.sendMessage("You do not have permission to run this command.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length >= 2) {
|
||||
War war = WarData.getWar(args[1]);
|
||||
|
||||
// War Check
|
||||
if (war == null) {
|
||||
p.sendMessage(Helper.chatLabel()
|
||||
+ "War not found. Type /war list to view current wars.");
|
||||
return;
|
||||
}
|
||||
|
||||
for(Siege s : war.getSieges()) {
|
||||
s.stop();
|
||||
}
|
||||
for(Raid r : war.getRaids()) {
|
||||
r.stop();
|
||||
}
|
||||
|
||||
WarData.removeWar(war);
|
||||
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "War " + args[1] + " deleted.");
|
||||
Main.warLogger.log(p.getName() + " deleted " + args[1]);
|
||||
return;
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel())
|
||||
+ "Invalid Arguments. /war delete [name]");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param p - executor
|
||||
* @param args
|
||||
* @param admin - admin behavior
|
||||
*/
|
||||
protected static void warJoin(CommandSender p, String[] args, boolean admin) {
|
||||
// Sufficient args check
|
||||
if (args.length < 3) {
|
||||
p.sendMessage(Helper.chatLabel()
|
||||
+ "/war join [name] [side], type /war list to view current wars");
|
||||
return;
|
||||
}
|
||||
|
||||
// War check
|
||||
War war = WarData.getWar(args[1]);
|
||||
if (war == null) {
|
||||
p.sendMessage(Helper.chatLabel()
|
||||
+ "War not found. /war join [name] [side], type /war list to view current wars");
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = null;
|
||||
if (admin){
|
||||
player = Bukkit.getPlayer(args[3]);
|
||||
if(player == null) {
|
||||
p.sendMessage(Helper.chatLabel() + "Player " + args[3] + " not found!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(player == null) {
|
||||
player = (Player) p;
|
||||
}
|
||||
|
||||
|
||||
// Towny Resident Object, if admin then dont use command runner, use declared player
|
||||
Resident res = TownyAPI.getInstance().getResident(player);
|
||||
|
||||
// Town check
|
||||
Town town = res.getTownOrNull();
|
||||
if (town == null) {
|
||||
p.sendMessage(ChatColor.RED + "You are not in a town.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Minuteman countermeasures
|
||||
int minuteman = CommandHelper.isPlayerMinuteman(player.getName());
|
||||
boolean override = false;
|
||||
if (admin) {
|
||||
if (args.length >= 6) {
|
||||
if (Boolean.parseBoolean(args[5])) {
|
||||
//player has joined to recently
|
||||
p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!");
|
||||
override = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
//override?
|
||||
if(!override) {
|
||||
if (minuteman != 0) {
|
||||
if (minuteman == 1) {
|
||||
//player has joined to recently
|
||||
if (admin) p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
player.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
return;
|
||||
} else if (minuteman == 2) {
|
||||
//player has played too little
|
||||
if (admin) p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
player.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Side checks
|
||||
int side = war.getSide(town.getName().toLowerCase());
|
||||
if (side == -1) {
|
||||
p.sendMessage(Helper.chatLabel() + "You've already surrendered!");
|
||||
return;
|
||||
} else if (side > 0) {
|
||||
p.sendMessage(Helper.chatLabel() + "You're already in this war!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (res.hasNation()) {
|
||||
if(res.getPlayer().hasPermission("AlathraWar.nationjoin" )|| res.isKing()) {
|
||||
// Has nation declaration permission
|
||||
war.addNation(res.getNationOrNull(), args[2]);
|
||||
res.getPlayer().sendMessage(Helper.chatLabel() + "You have joined the war for " + res.getNationOrNull().getName());
|
||||
p.sendMessage(Helper.chatLabel() + "You have joined the war for " + res.getNationOrNull().getName());
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + "The nation of " + res.getNationOrNull().getName() + " has joined the war on the side of " + args[2] + "!");
|
||||
war.save();
|
||||
return;
|
||||
} else {
|
||||
// Cannot declare nation involvement
|
||||
p.sendMessage(Helper.chatLabel() + "You cannot declare war for your nation.");
|
||||
return;
|
||||
}
|
||||
} else if (res.hasTown()) {
|
||||
if (res.getPlayer().hasPermission("AlathraWar.townjoin") || res.isMayor()) {
|
||||
// Is in indepdenent town & has declaration perms
|
||||
war.addTown(res.getTownOrNull(), args[2]);
|
||||
res.getPlayer().sendMessage(Helper.chatLabel() + "You have joined the war for " + res.getTownOrNull().getName());
|
||||
p.sendMessage(Helper.chatLabel() + "You have joined the war for " + res.getTownOrNull().getName());
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + "The town of " + res.getTownOrNull().getName() + " has joined the war on the side of " + args[2] + "!");
|
||||
war.save();
|
||||
return;
|
||||
} else {
|
||||
// No perms
|
||||
p.sendMessage(Helper.chatLabel() + "You cannot declare war for your town.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static void warSurrender(Player p, String[] args, boolean admin) {
|
||||
// Sufficient args check
|
||||
if (args.length < 2) {
|
||||
p.sendMessage(Helper.chatLabel()
|
||||
+ "/war surrender [name], type /war list to view current wars");
|
||||
return;
|
||||
}
|
||||
|
||||
// War check
|
||||
War war = WarData.getWar(args[1]);
|
||||
if (war == null) {
|
||||
p.sendMessage(Helper.chatLabel()
|
||||
+ "War not found. Type /war list to view current wars");
|
||||
return;
|
||||
}
|
||||
|
||||
// Towny Resident Object
|
||||
Resident res = TownyAPI.getInstance().getResident(p);
|
||||
|
||||
// Town check
|
||||
Town town = res.getTownOrNull();
|
||||
if (town == null) {
|
||||
p.sendMessage(ChatColor.RED + "You are not in a town.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (res.hasNation()) {
|
||||
if(p.hasPermission("AlathraWar.nationsurrender" )|| res.isKing()) {
|
||||
// Has nation surrender permission
|
||||
war.surrenderNation(res.getNationOrNull());
|
||||
p.sendMessage(Helper.chatLabel() + "You have surrendered the war for " + res.getNationOrNull().getName());
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + "The nation of " + res.getNationOrNull().getName() + " has surrendered! They were fighting for " + args[2] + ".");
|
||||
war.save();
|
||||
return;
|
||||
} else {
|
||||
// Cannot surrender nation involvement
|
||||
p.sendMessage(Helper.chatLabel() + "You cannot surrender war for your nation.");
|
||||
return;
|
||||
}
|
||||
} else if (res.hasTown()) {
|
||||
if (p.hasPermission("AlathraWar.townsurrender") || res.isMayor()) {
|
||||
// Is in indepdenent town & has surrender perms
|
||||
war.surrenderTown(res.getTownOrNull().getName());
|
||||
p.sendMessage(Helper.chatLabel() + "You have surrendered the war for " + res.getTownOrNull().getName());
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + "The town of " + res.getTownOrNull().getName() + " has surrendered! They were fighting for " + args[2] + ".");
|
||||
war.save();
|
||||
return;
|
||||
} else {
|
||||
// No perms
|
||||
p.sendMessage(Helper.chatLabel() + "You cannot surrender war for your town.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void warList(Player p, String[] args) {
|
||||
p.sendMessage(Helper.chatLabel()+ "Wars:");
|
||||
ArrayList<War> wars = WarData.getWars();
|
||||
if (wars.size() < 1) {
|
||||
p.sendMessage("There are no current wars.");
|
||||
} else {
|
||||
for (War war : wars) {
|
||||
p.sendMessage(war.getName() + " - " + war.getSide1() + " (" + war.getSide1Points() + ") vs. " + war.getSide2() + " (" + war.getSide2Points() + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void warInfo(Player p, String[] args) {
|
||||
if (args.length < 2) {
|
||||
p.sendMessage(Helper.chatLabel() + "/war info [Player]");
|
||||
}
|
||||
|
||||
Resident res = TownyAPI.getInstance().getResident(args[1]);
|
||||
if (res == null || res.getTownOrNull() == null) {
|
||||
p.sendMessage(Helper.chatLabel() + "Invalid town resident.");
|
||||
}
|
||||
|
||||
p.sendMessage(Helper.chatLabel() + p.getName() + "'s wars:");
|
||||
for (War war : WarData.getWars()) {
|
||||
int side = war.getSide(args[1]);
|
||||
if (side != 0) {
|
||||
if (side == -1) {
|
||||
p.sendMessage(war.getName() + " - Surrendered");
|
||||
} else if (side == 1) {
|
||||
p.sendMessage(war.getName() + " - " + war.getSide1());
|
||||
} else if (side == 2) {
|
||||
p.sendMessage(war.getName() + " - " + war.getSide2());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void warHelp(Player p, String[] args) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for console access
|
||||
* @param sender
|
||||
* @param args
|
||||
*/
|
||||
private static void consoleCommand(CommandSender sender, String[] args) {
|
||||
if (args.length < 1) return;
|
||||
if (args[0].equalsIgnoreCase("list")) {
|
||||
ArrayList<War> warList = WarData.getWars();
|
||||
sender.sendMessage("Wars: " + warList.size());
|
||||
for (War war : WarData.getWars()) {
|
||||
if (war == null) continue;
|
||||
sender.sendMessage(war.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
import com.palmergames.bukkit.towny.utils.NameUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class WarTabCompletion implements TabCompleter{
|
||||
|
||||
private static final List<String> baseAdmin = List.of(new String[]{
|
||||
"create",
|
||||
"delete",
|
||||
"help",
|
||||
"info",
|
||||
"join",
|
||||
"list",
|
||||
"surrender"
|
||||
});
|
||||
|
||||
private static final List<String> base = List.of(new String[]{
|
||||
"help",
|
||||
"info",
|
||||
"join",
|
||||
"list",
|
||||
"surrender"
|
||||
});
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
boolean flag = sender.hasPermission("AlathraWar.admin");
|
||||
|
||||
if (args.length > 0) {
|
||||
if(args.length > 1) {
|
||||
switch (args[0]) {
|
||||
case "join" -> {
|
||||
if (args.length > 2) {
|
||||
if (args.length > 3) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[1]), args[2]);
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[1]);
|
||||
}
|
||||
}
|
||||
case "info" -> {
|
||||
if (args.length > 2) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[1]);
|
||||
}
|
||||
case "delete", "surrender" -> {
|
||||
if (args.length > 2) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[1]);
|
||||
}
|
||||
//create, list, help
|
||||
default -> {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(flag ? baseAdmin : base, args[0]);
|
||||
}
|
||||
} else {
|
||||
return flag ? baseAdmin : base;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
|
||||
/**
|
||||
* Manages file IO & Deletion for other data classes.
|
||||
*/
|
||||
public class DataManager {
|
||||
private static DumperOptions options;
|
||||
|
||||
public DataManager() {
|
||||
|
||||
}
|
||||
|
||||
private static String dataFolder = "plugins" + File.separator + "AlathraWar" + File.separator + "data";
|
||||
|
||||
/**
|
||||
* 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 = null;
|
||||
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 = null;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
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.Raid;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.*;
|
||||
|
||||
public class RaidData {
|
||||
// Static Raid list for all active raids
|
||||
private static ArrayList<Raid> raids = new ArrayList<Raid>();
|
||||
|
||||
|
||||
|
||||
|
||||
public static ArrayList<Raid> getRaids() {
|
||||
return raids;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a raid with a specific name
|
||||
*
|
||||
* @param name - Name to check
|
||||
* @return Raid or Null
|
||||
*/
|
||||
public static Raid getRaidOrNull(String name) {
|
||||
for (Raid raid : raids) {
|
||||
if (raid.getName().equalsIgnoreCase(name)) return raid;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setRaids(ArrayList<Raid> raids) {
|
||||
for (Raid raid : raids) {
|
||||
addRaid(raid);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addRaid(Raid raid) {
|
||||
if (raid == null) {
|
||||
Main.warLogger.log("Attempted to add NULL to raid list.");
|
||||
return;
|
||||
}
|
||||
raids.add(raid);
|
||||
}
|
||||
|
||||
public static void removeRaid(Raid raid) {
|
||||
raid.getWar().getRaids().remove(raid);
|
||||
raids.remove(raid);
|
||||
|
||||
//deleteRaid(raid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a raid object from a provided HashMap
|
||||
*
|
||||
* @param fileData
|
||||
* @return Raid object
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Raid fromMap(War war, 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;
|
||||
}
|
||||
Raid raid = new Raid(war, raidedTown, gatherTown, attackBoolean, offlinePlayer);
|
||||
|
||||
//Extra properties, if any are missing the raid 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
|
||||
raid.setRaidPhase(RaidPhase.getByName((String) fileData.get("raidPhase")));
|
||||
raid.setRaidTicks((int) fileData.get("raidTicks"));
|
||||
raid.setActiveRaiders((ArrayList<String>) fileData.get("activeRaiders"));
|
||||
raid.setRaiderScore((int) fileData.get("raiderScore"));
|
||||
raid.setDefenderScore((int) fileData.get("defenderScore"));
|
||||
raid.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
|
||||
Raid.LootBlock lb = new Raid.LootBlock(worldCoordc, ticks, value, finished);
|
||||
raid.getLootedChunks().put(worldCoordc, lb);
|
||||
}
|
||||
}
|
||||
|
||||
return raid;
|
||||
}
|
||||
|
||||
public static ArrayList<Raid> createRaids(War war, Collection<HashMap<String, Object>> raidMaps) {
|
||||
ArrayList<Raid> returnList = new ArrayList<Raid>();
|
||||
for (HashMap<String, Object> map : raidMaps) {
|
||||
Town town = TownyAPI.getInstance().getTown((String) map.get("raidedTown"));
|
||||
if (town == null) continue;
|
||||
|
||||
Raid raid = fromMap(war, map);
|
||||
returnList.add(raid);
|
||||
RaidData.addRaid(raid);
|
||||
raid.resume();
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves the war into files.
|
||||
*
|
||||
* @param raid - War to be saved.
|
||||
*/
|
||||
public static void saveRaid(Raid raid) {
|
||||
War war = raid.getWar();
|
||||
war.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes raid, unused
|
||||
*/
|
||||
// private static void deleteRaid(War 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 raid into a map
|
||||
*
|
||||
* @param raid - Raid
|
||||
* @return Map
|
||||
*/
|
||||
public static HashMap<String, Object> raidToMap(Raid raid) {
|
||||
HashMap<String, Object> returnMap = new HashMap<String, Object>();
|
||||
// Shoves everything into a map.
|
||||
returnMap.put("name", raid.getName());
|
||||
returnMap.put("raidedTown", raid.getRaidedTown().getName());
|
||||
returnMap.put("gatherTown", raid.getGatherTown().getName());
|
||||
returnMap.put("raidTicks", raid.getRaidTicks());
|
||||
returnMap.put("raidPhase", raid.getPhase().name());
|
||||
returnMap.put("raiderScore", raid.getRaiderScore());
|
||||
returnMap.put("defenderScore", raid.getDefenderScore());
|
||||
returnMap.put("side1AreRaiders", Boolean.toString(raid.getSide1AreRaiders()));
|
||||
returnMap.put("activeRaiders", raid.getActiveRaiders());
|
||||
//THIS MAY OR MAY NOT WORK
|
||||
returnMap.put("owner", raid.getOwner().getUniqueId().toString());
|
||||
|
||||
//create a list from the looted chunks
|
||||
List<Object> chunkList = new ArrayList<Object>();
|
||||
for (Raid.LootBlock b : raid.getLootedChunks().values()) {
|
||||
HashMap<String, Object> blockMap = new HashMap<String, Object>();
|
||||
//worldcoord
|
||||
HashMap<String, Object> wcMap = new HashMap<String, Object>();
|
||||
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);
|
||||
}
|
||||
|
||||
returnMap.put("lootedChunks", chunkList);
|
||||
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a map of raid maps
|
||||
*
|
||||
* @param war - War to map
|
||||
* @return Map of Maps
|
||||
*/
|
||||
public static HashMap<String, Object> getRaidMap(War war) {
|
||||
HashMap<String, Object> returnMap = new HashMap<String, Object>();
|
||||
for (Raid raid : war.getRaids()) {
|
||||
returnMap.put(raid.getRaidedTown().getName(), raidToMap(raid));
|
||||
}
|
||||
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 war cooldown, town being raided already, valid time to raid)
|
||||
*/
|
||||
public static int isValidRaid(War war, 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 war
|
||||
if ((System.currentTimeMillis() / 1000) - (side.equalsIgnoreCase(war.getSide1()) ? war.getLastRaidTimeSide1() : war.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 (Raid raid : war.getRaids()) {
|
||||
if (raid.getRaidedTown().getName().equalsIgnoreCase(town.getName())) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
public enum RaidPhase {
|
||||
START(0, 0),
|
||||
GATHER(1, 0),
|
||||
TRAVEL(2, 18000),
|
||||
COMBAT(3, 24000),
|
||||
END(4, 72000);
|
||||
|
||||
//Start phase starts when the command to start a raid is ran, it allows the raiders to join, and for people to get geared up
|
||||
//after 15 minutes travel phase begins, where the raiders start travelling and moving to the new town.
|
||||
//no killing can occur during these two phases.
|
||||
//Once at least one player has stepped into the defending town, or 5 min have passed during the travel phase,
|
||||
//the combat begins and lasts 40 minutes.
|
||||
|
||||
public final int id;
|
||||
public final int startTick;
|
||||
|
||||
private RaidPhase(int id, int startTick) {
|
||||
this.id = id;
|
||||
this.startTick = startTick;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the phase by name, ignores case
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static RaidPhase getByName(String name) {
|
||||
for(RaidPhase p : RaidPhase.values()) {
|
||||
if(p.name().equalsIgnoreCase(name)) return p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs phase by id number for easy storage reading
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static RaidPhase getByID(int id) {
|
||||
for(RaidPhase p : RaidPhase.values()) {
|
||||
if(p.id == id) return p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static RaidPhase getNext(RaidPhase phase) {
|
||||
switch (phase) {
|
||||
case START: {
|
||||
return GATHER;
|
||||
}
|
||||
case GATHER: {
|
||||
return TRAVEL;
|
||||
}
|
||||
case TRAVEL: {
|
||||
return COMBAT;
|
||||
}
|
||||
case COMBAT: {
|
||||
return END;
|
||||
}
|
||||
default: {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
import me.ShermansWorld.AlathraWar.Siege;
|
||||
|
||||
public class SiegeData
|
||||
{
|
||||
|
||||
// Static Siege list for all active sieges
|
||||
private static HashSet<Siege> sieges = new HashSet<Siege>();
|
||||
|
||||
public static HashSet<Siege> getSieges() {
|
||||
return sieges;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets a siege with a specific name
|
||||
* @param name - Name to check
|
||||
* @return Siege or Null
|
||||
*/
|
||||
public static Siege getSiege(String name) {
|
||||
for (Siege siege : sieges) {
|
||||
if (siege.getTown().getName().equalsIgnoreCase(name)) return siege;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setSieges(ArrayList<Siege> sieges) {
|
||||
for (Siege siege : sieges) {
|
||||
addSiege(siege);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addSiege(Siege siege) {
|
||||
if (siege == null) {
|
||||
Main.warLogger.log("Attempted to add NULL to siege list.");
|
||||
return;
|
||||
}
|
||||
sieges.add(siege);
|
||||
}
|
||||
|
||||
public static void removeSiege(Siege siege) {
|
||||
sieges.remove(siege);
|
||||
//deleteSiege(siege);d
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a siege object from a provided HashMap
|
||||
* @param fileData data
|
||||
* @return Siege object
|
||||
*/
|
||||
private static Siege fromMap(War war, 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")));
|
||||
|
||||
Siege siege = new Siege(war, town, offlinePlayer);
|
||||
|
||||
return siege;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the war into files.
|
||||
|
||||
* @param siege - Siege to be saved.
|
||||
*/
|
||||
public static void saveSiege(Siege siege) {
|
||||
War war = siege.getWar();
|
||||
war.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns a siege into a map
|
||||
* @param siege - Siege
|
||||
* @return Map
|
||||
*/
|
||||
public static HashMap<String, Object> siegeToMap(Siege siege) {
|
||||
HashMap<String, Object> returnMap = new HashMap<String, Object>();
|
||||
// Shoves everything into a map.
|
||||
returnMap.put("town", siege.getTown().getName());
|
||||
returnMap.put("siegeTicks", siege.getSiegeTicks());
|
||||
returnMap.put("attackerPoints", siege.getAttackerPoints());
|
||||
returnMap.put("defenderPoints", siege.getDefenderPoints());
|
||||
returnMap.put("side1AreAttackers", Boolean.toString(siege.getSide1AreAttackers()));
|
||||
returnMap.put("siegeLeader", siege.getSiegeLeader().getUniqueId().toString());
|
||||
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a map of siege maps
|
||||
* @param war - War to map
|
||||
* @return Map of Maps
|
||||
*/
|
||||
public static HashMap<String, Object> getSiegeMap(War war) {
|
||||
HashMap<String, Object> returnMap = new HashMap<String, Object>();
|
||||
for (Siege siege : war.getSieges()) {
|
||||
returnMap.put(siege.getTown().getName(), siegeToMap(siege));
|
||||
}
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
public static ArrayList<Siege> createSieges(War war, Collection<HashMap<String, Object>> siegeMaps) {
|
||||
ArrayList<Siege> returnList = new ArrayList<Siege>();
|
||||
for (HashMap<String, Object> map : siegeMaps) {
|
||||
Town town = TownyAPI.getInstance().getTown((String) map.get("town"));
|
||||
if (town == null) continue;
|
||||
|
||||
Siege siege = fromMap(war, map);
|
||||
siege.addPointsToAttackers((int) map.get("attackerPoints"));
|
||||
siege.addPointsToDefenders((int) map.get("defenderPoints"));
|
||||
siege.resume((int) map.get("siegeTicks"));
|
||||
siege.setWar(war);
|
||||
returnList.add(siege);
|
||||
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.Raid;
|
||||
import me.ShermansWorld.AlathraWar.Siege;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
public class WarData
|
||||
{
|
||||
|
||||
// Static War list for all active wars
|
||||
private static ArrayList<War> wars = new ArrayList<War>();
|
||||
private final static String dataFolderPath = "plugins" + File.separator + "AlathraWar" + File.separator + "data";
|
||||
|
||||
// Filter for only accessing yml files
|
||||
private static FilenameFilter ymlFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".yml");
|
||||
}
|
||||
};
|
||||
|
||||
// Constructor used to initialise folder.
|
||||
public WarData(final Main plugin) {
|
||||
File userDataFolder = new File(dataFolderPath + File.separator + "wars");
|
||||
if (!userDataFolder.exists()) {
|
||||
userDataFolder.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<War> getWars() {
|
||||
return wars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a war with a specific name
|
||||
* @param name - Name to check
|
||||
* @return War or Null
|
||||
*/
|
||||
public static War getWar(String name) {
|
||||
for (War war : wars) {
|
||||
if (war.getName().equalsIgnoreCase(name)) return war;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setWars(ArrayList<War> wars) {
|
||||
WarData.wars = wars;
|
||||
}
|
||||
|
||||
public static void addWar(War war) {
|
||||
if (war == null) {
|
||||
Main.warLogger.log("Attempted to add NULL to war list.");
|
||||
return;
|
||||
}
|
||||
wars.add(war);
|
||||
}
|
||||
|
||||
public static void removeWar(War war) {
|
||||
wars.remove(war);
|
||||
deleteWar(war);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the wars currently saved in files as an ArrayList of War Objects
|
||||
* @return War Object ArrayList
|
||||
*/
|
||||
public static ArrayList<War> createWars() {
|
||||
File[] files = new File(dataFolderPath + File.separator + "wars").listFiles(ymlFilter);
|
||||
|
||||
ArrayList<War> returnList = new ArrayList<War>();
|
||||
for (File file : files) {
|
||||
try {
|
||||
HashMap<String, Object> fileData = DataManager.getData(file);
|
||||
War fileWar = fromMap(fileData);
|
||||
returnList.add(fileWar);
|
||||
} 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 War object
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static War fromMap(HashMap<String, Object> fileData) {
|
||||
|
||||
War war = new War((String) fileData.get("name"),
|
||||
(String) fileData.get("side1"),
|
||||
(String) fileData.get("side2")
|
||||
);
|
||||
|
||||
war.setSide1Towns((ArrayList<String>) fileData.get("side1Towns"));
|
||||
war.setSide2Towns((ArrayList<String>) fileData.get("side2Towns"));
|
||||
war.setSurrenderedTowns((ArrayList<String>) fileData.get("surrenderedTowns"));
|
||||
|
||||
war.addSide1Points((int) fileData.get("side1Points"));
|
||||
war.addSide2Points((int) fileData.get("side2Points"));
|
||||
|
||||
if(fileData.get("lastRaidTimeSide1") != null && fileData.get("lastRaidTimeSide2") != null) {
|
||||
war.setLastRaidTimeSide1((int) fileData.get("lastRaidTimeSide1"));
|
||||
war.setLastRaidTimeSide2((int) fileData.get("lastRaidTimeSide2"));
|
||||
}
|
||||
|
||||
|
||||
// Siege adding from map.
|
||||
Collection<HashMap<String, Object>> siegeMaps = ((HashMap<String,HashMap<String, Object>>) fileData.get("sieges")).values();
|
||||
ArrayList<Siege> sieges = SiegeData.createSieges(war, siegeMaps);
|
||||
for (Siege siege : sieges) {
|
||||
war.addSiege(siege);
|
||||
SiegeData.addSiege(siege);
|
||||
}
|
||||
|
||||
// Raid adding from map.
|
||||
Collection<HashMap<String, Object>> raidMaps = ((HashMap<String,HashMap<String, Object>>) fileData.get("raids")).values();
|
||||
ArrayList<Raid> raids = RaidData.createRaids(war, raidMaps);
|
||||
for (Raid raid : raids) {
|
||||
war.addRaid(raid);
|
||||
}
|
||||
|
||||
return war;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the war into files.
|
||||
* @param war - War to be saved.
|
||||
*/
|
||||
public static void saveWar(War war) {
|
||||
HashMap<String, Object> sHashMap = new HashMap<String,Object>();
|
||||
|
||||
// Shoves everything into a map.
|
||||
sHashMap.put("name", war.getName());
|
||||
sHashMap.put("side1", war.getSide1());
|
||||
sHashMap.put("side2", war.getSide2());
|
||||
sHashMap.put("side1Towns", (List<String>) war.getSide1Towns());
|
||||
sHashMap.put("side2Towns", (List<String>) war.getSide2Towns());
|
||||
sHashMap.put("surrenderedTowns", (List<String>) war.getSurrenderedTowns());
|
||||
sHashMap.put("side1Points", war.getSide1Points());
|
||||
sHashMap.put("side2Points", war.getSide2Points());
|
||||
|
||||
sHashMap.put("sieges", SiegeData.getSiegeMap(war));
|
||||
sHashMap.put("raids", RaidData.getRaidMap(war));
|
||||
sHashMap.put("lastRaidTimeSide1", war.getLastRaidTimeSide1());
|
||||
sHashMap.put("lastRaidTimeSide2", war.getLastRaidTimeSide2());
|
||||
|
||||
DataManager.saveData("wars" + File.separator + war.getName() + ".yml", sHashMap);
|
||||
}
|
||||
|
||||
private static void deleteWar(War war) {
|
||||
File[] files = new File(dataFolderPath + File.separator + "wars").listFiles(ymlFilter);
|
||||
for (File file : files) {
|
||||
if (file.getName().startsWith(war.getName())) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+96
-76
@@ -1,76 +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(new StringBuilder("&c[").append(war.getSide1()).append("]&r").toString()));
|
||||
}
|
||||
|
||||
public static void assignSide2WarSuffix(Player p, War war) {
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
tabAPI.getTablistFormatManager().setSuffix(tabPlayer,
|
||||
Helper.color(new StringBuilder("&9[").append(war.getSide2()).append("]&r").toString()));
|
||||
}
|
||||
|
||||
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());
|
||||
prefix = prefix.substring(0, prefix.length() - 2);
|
||||
tabAPI.getTablistFormatManager().setPrefix(tabPlayer, Helper.color(prefix));
|
||||
}
|
||||
|
||||
}
|
||||
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,12 @@
|
||||
package me.ShermansWorld.AlathraWar.items;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
public interface IWarItem {
|
||||
|
||||
public ItemStack getItemStack();
|
||||
|
||||
public Recipe getRecipe();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package me.ShermansWorld.AlathraWar.items;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Helper;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.items.item.RamItem;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class WarItemRegistry {
|
||||
|
||||
private static WarItemRegistry instance;
|
||||
|
||||
private static final HashMap<String, IWarItem> itemRegistry = new HashMap<>();
|
||||
|
||||
public static final String namespace = Main.getInstance().getName().toLowerCase();
|
||||
|
||||
/**
|
||||
* loads all items into the plugin registry list
|
||||
*/
|
||||
public WarItemRegistry() {
|
||||
instance = this;
|
||||
|
||||
Main.warLogger.log(Helper.chatLabel() + "Registering AlathraWar items.");
|
||||
|
||||
itemRegistry.put(registryName("ram"), new RamItem());
|
||||
//THIS BREAKS EVERYTHING???? TODO
|
||||
// Bukkit.getServer().addRecipe(new RamItem().getRecipe());
|
||||
|
||||
Main.warLogger.log(Helper.chatLabel() + "Registered AlathraWar items.");
|
||||
}
|
||||
|
||||
public static WarItemRegistry getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a registry name
|
||||
* @param item
|
||||
* @return
|
||||
*/
|
||||
public static String registryName(String item) {
|
||||
return namespace + ":" + item;
|
||||
}
|
||||
|
||||
public Map<String, ItemStack> getItemRegistry() {
|
||||
return itemRegistry.entrySet()
|
||||
.stream()
|
||||
.filter(v -> v.getValue() != null)
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
v -> v.getValue().getItemStack()));
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the associated itemstack with the item key, use for finding without namespace
|
||||
* @param registryName
|
||||
* @return
|
||||
*/
|
||||
public ItemStack getOrNull(String registryName) {
|
||||
return itemRegistry.get(registryName(registryName)).getItemStack().clone();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns the associated itemstack with the item key, use for finding with namespace
|
||||
* @param registryName
|
||||
* @return
|
||||
*/
|
||||
public ItemStack getOrNullNamespace(String registryName) {
|
||||
return itemRegistry.get(registryName).getItemStack().clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the associated IWarItem with the item key, use for finding with namespace
|
||||
* @param registryName
|
||||
* @return
|
||||
*/
|
||||
public IWarItem getWarItem(String registryName) {
|
||||
return itemRegistry.get(registryName);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package me.ShermansWorld.AlathraWar.items;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Helper;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
public class WarRecipeRegistry {
|
||||
|
||||
private static WarRecipeRegistry instance;
|
||||
|
||||
private static final HashMap<String, Recipe> recipeRegistry = new HashMap<>();
|
||||
|
||||
public WarRecipeRegistry() {
|
||||
instance = this;
|
||||
|
||||
Main.warLogger.log(Helper.chatLabel() + "Registering AlathraWar recipes.");
|
||||
|
||||
// register(WarItemRegistry.registryName("ram"), new RamItem().getRecipes());
|
||||
|
||||
Main.warLogger.log(Helper.chatLabel() + "Registered AlathraWar recipes.");
|
||||
}
|
||||
|
||||
public void register(String name, Set<Recipe> recipes) {
|
||||
for (Recipe recipe : recipes) {
|
||||
// Bukkit.getServer().addRecipe(recipe);
|
||||
recipeRegistry.put(name, recipe);
|
||||
}
|
||||
}
|
||||
|
||||
public static WarRecipeRegistry getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public HashMap<String, Recipe> getRecipeRegistry() {
|
||||
return recipeRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the associated itemstack with the item key, use for finding without namespace
|
||||
* @param registryName recipe name without namespace
|
||||
* @return recipe
|
||||
*/
|
||||
public Recipe getOrNull(String registryName) {
|
||||
return recipeRegistry.get(WarItemRegistry.registryName(registryName));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns the associated itemstack with the item key, use for finding with namespace
|
||||
* @param registryName registry name including namespace
|
||||
* @return recipe
|
||||
*/
|
||||
public Recipe getOrNullNamespace(String registryName) {
|
||||
return recipeRegistry.get(registryName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package me.ShermansWorld.AlathraWar.items.item;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.items.IWarItem;
|
||||
import me.ShermansWorld.AlathraWar.items.WarItemRegistry;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RamItem implements IWarItem {
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
|
||||
ItemStack ram = new ItemStack(Material.WOODEN_HOE);
|
||||
ItemMeta meta = ram.getItemMeta();
|
||||
|
||||
meta.setDisplayName("Door Ram");
|
||||
ArrayList<String> lore = new ArrayList<String>();
|
||||
meta.setLore(lore);
|
||||
meta.setCustomModelData(14700);
|
||||
|
||||
ram.setItemMeta(meta);
|
||||
|
||||
return ram;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe() {
|
||||
ItemStack output = WarItemRegistry.getInstance().getOrNull("ram");
|
||||
NamespacedKey key = new NamespacedKey(Main.getInstance(), "ram");
|
||||
ShapedRecipe recipe = new ShapedRecipe(key, output);
|
||||
recipe.shape("$@$", "B##");
|
||||
recipe.setIngredient('@', Material.STICK);
|
||||
recipe.setIngredient('$', Material.IRON_INGOT);
|
||||
recipe.setIngredient('B', Material.IRON_BLOCK);
|
||||
recipe.setIngredient('%', new RecipeChoice.MaterialChoice(Tag.LOGS));
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Raid;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Helper;
|
||||
import me.ShermansWorld.AlathraWar.Siege;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class BlockBreakListener implements Listener {
|
||||
|
||||
private static final Set<Material> allowedBlocks = new HashSet<>();
|
||||
|
||||
static {
|
||||
allowedBlocks.add(Material.TNT);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(final BlockBreakEvent event) {
|
||||
|
||||
final Block block = event.getBlock();
|
||||
if (SiegeData.getSieges().isEmpty() && RaidData.getRaids().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (final Siege siege : SiegeData.getSieges()) {
|
||||
if (siege.beaconLocs.contains(block.getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (allowedBlocks.contains(block.getType())) {
|
||||
return;
|
||||
}
|
||||
Player p = event.getPlayer();
|
||||
if(p.hasPermission("AlathraWar.break")) {
|
||||
return;
|
||||
}
|
||||
if (WorldCoord.parseWorldCoord(block).getTownOrNull() != null) {
|
||||
for (final Siege siege : SiegeData.getSieges()) {
|
||||
if (siege.getTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
p.sendMessage(Helper.color("&cYou can not break blocks during sieges"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (final Raid raid : RaidData.getRaids()) {
|
||||
if (raid.getRaidedTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
p.sendMessage(Helper.color("&cYou can not break blocks during raids"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(final BlockPlaceEvent event) {
|
||||
final Block block = event.getBlock();
|
||||
if (SiegeData.getSieges().isEmpty() && RaidData.getRaids().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (allowedBlocks.contains(block.getType())) {
|
||||
return;
|
||||
}
|
||||
Player p = event.getPlayer();
|
||||
if(p.hasPermission("AlathraWar.place")) {
|
||||
return;
|
||||
}
|
||||
if (WorldCoord.parseWorldCoord(block).getTownOrNull() != null) {
|
||||
for (final Siege siege : SiegeData.getSieges()) {
|
||||
if (siege.getTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
p.sendMessage(Helper.color("&cYou can not place blocks during sieges"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (final Raid raid : RaidData.getRaids()) {
|
||||
if (raid.getRaidedTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
p.sendMessage(Helper.color("&cYou can not place blocks during raids"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Helper;
|
||||
import me.ShermansWorld.AlathraWar.Raid;
|
||||
import me.ShermansWorld.AlathraWar.Siege;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class CommandsListener implements Listener {
|
||||
|
||||
final static String[] prefixes = new String[]{
|
||||
"", "towny", "essentials", "wild", "minecraft"
|
||||
};
|
||||
final static String[] prefixesTowny = new String[]{
|
||||
"", "towny"
|
||||
};
|
||||
final static String[] blacklistedXLong = new String[]{
|
||||
"n set spawn", "nat set spawn", "nation set spawn",
|
||||
"t set spawn", "town set spawn",
|
||||
"t set homeblock", "town set homeblock",
|
||||
"t set name", "town set name",
|
||||
"n set name", "nat set name", "nation set name"
|
||||
};
|
||||
final static String[] blacklistedLong = new String[]{
|
||||
"n spawn", "nat spawn", "nation spawn",
|
||||
"t spawn", "town spawn",
|
||||
"t outpost", "town outpost"
|
||||
};
|
||||
final static String[] payment = new String[]{
|
||||
"n withdraw", "nat withdraw", "nation withdraw",
|
||||
"t withdraw", "town withdraw"
|
||||
};
|
||||
final static String[] blacklistedShort = new String[]{
|
||||
"home", "homes", "warp", "warps",
|
||||
"wild", "rtp", "spawn", "wilderness", "wildtp",
|
||||
"tpa", "tpahere", "tpaccept", "tpacancel",
|
||||
"etpa", "etpahere", "etpaccept", "etpacancel",
|
||||
"ehome", "ehomes", "ewarp", "ewarps"
|
||||
|
||||
};
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onCommandSend(final PlayerCommandPreprocessEvent event) {
|
||||
|
||||
Player p = event.getPlayer();
|
||||
|
||||
//if player is admin, ignore this behavior
|
||||
// if (p.hasPermission("!AlathraWar.admin")) return;
|
||||
|
||||
String[] args = event.getMessage().split(" ");
|
||||
|
||||
/*
|
||||
Prevent any teleport command events from occurring
|
||||
If using PlayerTeleportEvent, it breaks the death logic
|
||||
|
||||
allow n spawn and t spawn for defenders trapped in spawn
|
||||
*/
|
||||
for (Raid raid : RaidData.getRaids()) {
|
||||
//Only do this during regular phases, start and end ignored in case something breaks
|
||||
if (raid.getPhase() == RaidPhase.COMBAT || raid.getPhase() == RaidPhase.TRAVEL || raid.getPhase() == RaidPhase.GATHER) {
|
||||
//only do for active raiders and any defenders
|
||||
if (raid.getActiveRaiders().contains(p.getName()) || raid.getDefenderPlayers().contains(p.getName())) {
|
||||
//set spawn and properties
|
||||
if (args.length >= 3) {
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1] + " " + args[2];
|
||||
for (String prefix : prefixesTowny) {
|
||||
//payment check
|
||||
for (String cmd : blacklistedXLong) {
|
||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot modify this property during a raid!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//n spawn and t spawn
|
||||
if (args.length >= 2) {
|
||||
//parse what we have, remove the starting sslash
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1];
|
||||
for (String prefix : prefixesTowny) {
|
||||
//payment check
|
||||
for (String cmd : payment) {
|
||||
//check for each prefix
|
||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot withdraw money whilst in a raid!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (String cmd : blacklistedLong) {
|
||||
//check for each prefix
|
||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
//check if in spawn
|
||||
if (p.getWorld().getName().equalsIgnoreCase("world")) {
|
||||
if (parse.equalsIgnoreCase("n spawn") || parse.equalsIgnoreCase("nat spawn") || parse.equalsIgnoreCase("nation spawn")
|
||||
|| parse.equalsIgnoreCase("t spawn") || parse.equalsIgnoreCase("town spawn")
|
||||
|| parse.equalsIgnoreCase("towny:n spawn") || parse.equalsIgnoreCase("towny:nat spawn") || parse.equalsIgnoreCase("towny:nation spawn")
|
||||
|| parse.equalsIgnoreCase("towny:t spawn") || parse.equalsIgnoreCase("towny:town spawn")) {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
return;
|
||||
}
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&eUse /t spawn, or /n spawn"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
//else
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot teleport whilst in a raid!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//random tp commands
|
||||
if (args.length >= 1) {
|
||||
//parse what we have, remove the starting slash
|
||||
String parse = args[0].charAt(0) == '/' ? args[0].substring(1) : args[0];
|
||||
for (String prefix : prefixes) {
|
||||
for (String cmd : blacklistedShort) {
|
||||
//check for each prefix
|
||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
//spawn world check
|
||||
if (p.getWorld().getName().equalsIgnoreCase("world")) {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&eUse /t spawn, or /n spawn"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot teleport whilst in a raid!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Prevent players from teleporting during a siege
|
||||
*/
|
||||
for (Siege siege : SiegeData.getSieges()) {
|
||||
//Only do this during regular phases, start and end ignored in case something breaks
|
||||
if (siege.getSiegeTicks() > 0) {
|
||||
//only do for active raiders and any defenders
|
||||
if (siege.getAttackerPlayers().contains(p.getName()) || siege.getDefenderPlayers().contains(p.getName())) {
|
||||
//set spawn and properties
|
||||
if (args.length >= 3) {
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1] + " " + args[2];
|
||||
for (String prefix : prefixesTowny) {
|
||||
//payment check
|
||||
for (String cmd : blacklistedXLong) {
|
||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot modify this property during a siege!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//n spawn and t spawn
|
||||
if (args.length >= 2) {
|
||||
//parse what we have, remove the starting sslash
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1];
|
||||
for (String prefix : prefixesTowny) {
|
||||
//payment check
|
||||
for (String cmd : payment) {
|
||||
//check for each prefix
|
||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou cannot withdraw money whilst in a siege!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (String cmd : blacklistedLong) {
|
||||
//check for each prefix
|
||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
//check if in spawn
|
||||
if (p.getWorld().getName().equalsIgnoreCase("world")) {
|
||||
if (parse.equalsIgnoreCase("n spawn") || parse.equalsIgnoreCase("nat spawn") || parse.equalsIgnoreCase("nation spawn")
|
||||
|| parse.equalsIgnoreCase("t spawn") || parse.equalsIgnoreCase("town spawn")
|
||||
|| parse.equalsIgnoreCase("towny:n spawn") || parse.equalsIgnoreCase("towny:nat spawn") || parse.equalsIgnoreCase("towny:nation spawn")
|
||||
|| parse.equalsIgnoreCase("towny:t spawn") || parse.equalsIgnoreCase("towny:town spawn")) {
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
return;
|
||||
}
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&eUse /t spawn, or /n spawn"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
//else
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou cannot teleport whilst in a siege!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//random tp commands
|
||||
if (args.length >= 1) {
|
||||
//parse what we have, remove the starting slash
|
||||
String parse = args[0].charAt(0) == '/' ? args[0].substring(1) : args[0];
|
||||
for (String prefix : prefixes) {
|
||||
for (String cmd : blacklistedShort) {
|
||||
//check for each prefix
|
||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
//spawn world check
|
||||
if (p.getWorld().getName().equalsIgnoreCase("world")) {
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&eUse /t spawn, or /n spawn"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot teleport whilst in a siege!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
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 com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
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();
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> checkPlayer(p), 60L); // 20 Tick (1 Second) delay before run() is called
|
||||
}
|
||||
|
||||
public static void checkPlayer(Player p) {
|
||||
Town town = TownyAPI.getInstance().getResident(p).getTownOrNull();
|
||||
if (town == null) return;
|
||||
String townName = town.getName();
|
||||
boolean inWar = false;
|
||||
for (final War war : WarData.getWars()) {
|
||||
if (war.getSide1Towns().contains(townName.toLowerCase())) {
|
||||
TABHook.assignSide1WarSuffix(p, war);
|
||||
inWar = true;
|
||||
} else if (war.getSide2Towns().contains(townName.toLowerCase())) {
|
||||
TABHook.assignSide2WarSuffix(p, war);
|
||||
inWar = true;
|
||||
}
|
||||
}
|
||||
if (!inWar) {
|
||||
TABHook.resetPrefix(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import me.ShermansWorld.AlathraWar.Helper;
|
||||
import me.ShermansWorld.AlathraWar.Raid;
|
||||
import me.ShermansWorld.AlathraWar.Siege;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class KillsListener implements Listener
|
||||
{
|
||||
|
||||
public static final HashMap<UUID, Raid> respawnqueue = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerKilled(final PlayerDeathEvent event) {
|
||||
|
||||
final Player killed = event.getEntity();
|
||||
final Player killer = event.getEntity().getKiller();
|
||||
Town town = null;
|
||||
try {
|
||||
town = WorldCoord.parseWorldCoord(killed).getTownBlock().getTown();
|
||||
}
|
||||
catch (NotRegisteredException ex2) {
|
||||
ex2.printStackTrace();
|
||||
}
|
||||
boolean playerCloseToHomeBlockSiege = false;
|
||||
boolean playerCloseToHomeBlockRaid = false;
|
||||
|
||||
try {
|
||||
//Raid logic
|
||||
for (final Raid raid : RaidData.getRaids()) {
|
||||
final int homeBlockXCoordRaided = raid.getRaidedTown().getHomeBlock().getCoord().getX() * 16;
|
||||
final int homeBlockZCoordRaided = raid.getRaidedTown().getHomeBlock().getCoord().getZ() * 16;
|
||||
// final int homeBlockXCoordGather = raid.getGatherTown().getHomeBlock().getCoord().getX() * 16;
|
||||
// final int homeBlockZCoordGather = raid.getGatherTown().getHomeBlock().getCoord().getZ() * 16;
|
||||
//Carryover from sieges
|
||||
if (Math.abs(killed.getLocation().getBlockX() - homeBlockXCoordRaided) <= 200 && Math.abs(killed.getLocation().getBlockZ() - homeBlockZCoordRaided) <= 200) {
|
||||
playerCloseToHomeBlockRaid = true;
|
||||
}
|
||||
|
||||
if (raid.getDefenderPlayers().contains(killed.getName()) && ((town != null && town.equals(raid.getRaidedTown())) || playerCloseToHomeBlockRaid)) {
|
||||
//There is seperate behavior if combat hasnt started
|
||||
if (raid.getPhase() == RaidPhase.COMBAT && killer != null) {
|
||||
if (raid.getActiveRaiders().contains(killer.getName())) {
|
||||
this.raidKill(killed, event);
|
||||
raid.defenderKilledInCombat(event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
//teleport back to raided spawn, without damaged gear
|
||||
this.oocKill(killed, event);
|
||||
raid.defenderKilledOutofCombat(event);
|
||||
return;
|
||||
}
|
||||
if (raid.getActiveRaiders().contains(killed.getName()) && ((town != null && town.equals(raid.getRaidedTown())) || playerCloseToHomeBlockRaid)) {
|
||||
//There is seperate behavior if combat hasnt started
|
||||
if (raid.getPhase() == RaidPhase.COMBAT && killer != null) {
|
||||
if (raid.getDefenderPlayers().contains(killer.getName())) {
|
||||
this.raidKill(killed, event);
|
||||
raid.raiderKilledInCombat(event);
|
||||
respawnqueue.put(killed.getUniqueId(), raid);
|
||||
return;
|
||||
}
|
||||
} else if (raid.getPhase() != RaidPhase.COMBAT && killer != null) {
|
||||
this.oocKill(killed, event);
|
||||
raid.raiderKilledOutofCombat(event);
|
||||
respawnqueue.put(killed.getUniqueId(), raid);
|
||||
return;
|
||||
}
|
||||
//teleport back to gather town spawn, without damaged gear
|
||||
//this is to disincentive people prekilling
|
||||
this.oocKill(killed, event);
|
||||
raid.raiderKilledOutofCombat(event);
|
||||
respawnqueue.put(killed.getUniqueId(), raid);
|
||||
return;
|
||||
}
|
||||
if ((town != null && town.equals(raid.getRaidedTown()) || playerCloseToHomeBlockRaid)) {
|
||||
this.raidKill(killed, event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(killer == null) return;
|
||||
|
||||
for (final Siege siege : SiegeData.getSieges()) {
|
||||
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) {
|
||||
playerCloseToHomeBlockSiege = true;
|
||||
}
|
||||
if (siege.getAttackerPlayers().contains(killer.getName()) && ((town != null && town.equals(siege.getTown())) || playerCloseToHomeBlockSiege)) {
|
||||
if (siege.getDefenderPlayers().contains(killed.getName())) {
|
||||
siege.addPointsToAttackers(20);
|
||||
for (final String playerName : siege.getAttackerPlayers()) {
|
||||
try {
|
||||
Player p = Bukkit.getPlayer(playerName);
|
||||
if (p != null) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Defender killed! + 20 Attacker Points");
|
||||
}
|
||||
catch (NullPointerException ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
}
|
||||
for (final String playerName : siege.getDefenderPlayers()) {
|
||||
try {
|
||||
Player p = Bukkit.getPlayer(playerName);
|
||||
if (p != null) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Defender killed! + 20 Attacker Points");
|
||||
}
|
||||
catch (NullPointerException ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
this.siegeKill(killed, event);
|
||||
return;
|
||||
}
|
||||
if (siege.getDefenderPlayers().contains(killer.getName()) && ((town != null && town.equals(siege.getTown())) || playerCloseToHomeBlockSiege)) {
|
||||
if (siege.getAttackerPlayers().contains(killed.getName())) {
|
||||
siege.addPointsToDefenders(20);
|
||||
for (final String playerName : siege.getAttackerPlayers()) {
|
||||
try {
|
||||
Player p = Bukkit.getPlayer(playerName);
|
||||
if (p != null) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Attacker killed! + 20 Defender Points");
|
||||
}
|
||||
catch (NullPointerException ex3) {
|
||||
ex3.printStackTrace();
|
||||
}
|
||||
}
|
||||
for (final String playerName : siege.getDefenderPlayers()) {
|
||||
try {
|
||||
Player p = Bukkit.getPlayer(playerName);
|
||||
if (p != null) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Attacker killed! + 20 Defender Points");
|
||||
}
|
||||
catch (NullPointerException ex4) {
|
||||
ex4.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
this.siegeKill(killed, event);
|
||||
return;
|
||||
}
|
||||
if ( (town != null && town.equals(siege.getTown()) || playerCloseToHomeBlockSiege) ) {
|
||||
this.siegeKill(killed, event);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (NullPointerException | TownyException ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs last so that it overrides everyone else!
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onRespawn(PlayerRespawnEvent event) {
|
||||
if(respawnqueue.containsKey(event.getPlayer().getUniqueId())) {
|
||||
Raid raid = respawnqueue.get(event.getPlayer().getUniqueId());
|
||||
if (raid == null) return;
|
||||
if(raid.getActiveRaiders().contains(event.getPlayer().getName())) {
|
||||
//do raider respawn
|
||||
try {
|
||||
event.setRespawnLocation(raid.getGatherTown().getSpawn());
|
||||
event.getPlayer().sendMessage(String.valueOf(Helper.chatLabel()) + "You died " + (raid.getPhase().equals(RaidPhase.COMBAT) ? "raiding" : "before combat") + " and have been teleported back to the gather point.");
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else if(raid.getDefenderSide().contains(event.getPlayer().getName())) {
|
||||
//do defender respawn ?
|
||||
} else {
|
||||
//invalid code
|
||||
}
|
||||
respawnqueue.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Damage all gear held by the player (and then send them to spawn?)
|
||||
* They don't lose items from death.
|
||||
* @param killed killed player
|
||||
* @param event event
|
||||
*/
|
||||
private void siegeKill(final Player killed, final PlayerDeathEvent event) {
|
||||
//Helper
|
||||
Helper.damageAllGear(killed);
|
||||
|
||||
//Siege specific
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "spawn " + killed.getName());
|
||||
event.setKeepInventory(true);
|
||||
event.getDrops().clear();
|
||||
event.setKeepLevel(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Damage all gear held by the player (and then send them to spawn?)
|
||||
* They don't lose items from death.
|
||||
*
|
||||
* @param killed killed player
|
||||
* @param event event
|
||||
*/
|
||||
private void raidKill(final Player killed, final PlayerDeathEvent event) {
|
||||
//Helper
|
||||
Helper.damageAllGear(killed);
|
||||
|
||||
//Siege specific
|
||||
// Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + killed.getName());
|
||||
event.setKeepInventory(true);
|
||||
event.getDrops().clear();
|
||||
event.setKeepLevel(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dont damage items held by the player
|
||||
* They don't lose items from death.
|
||||
*
|
||||
* @param killed killed player
|
||||
* @param event event
|
||||
*/
|
||||
private void oocKill(final Player killed, final PlayerDeathEvent event) {
|
||||
//Siege specific
|
||||
// Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + killed.getName());
|
||||
event.setKeepInventory(true);
|
||||
event.getDrops().clear();
|
||||
event.setKeepLevel(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.TownBlock;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import me.ShermansWorld.AlathraWar.Helper;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.Raid;
|
||||
import me.ShermansWorld.AlathraWar.Siege;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
import me.ShermansWorld.AlathraWar.items.WarItemRegistry;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.Bisected;
|
||||
import org.bukkit.block.data.type.Door;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class PlayerInteractListener implements Listener {
|
||||
|
||||
//predefined foor materials
|
||||
private static Set<Material> doors = new HashSet<Material>();
|
||||
|
||||
static {
|
||||
doors.add(Material.ACACIA_DOOR);
|
||||
doors.add(Material.BIRCH_DOOR);
|
||||
doors.add(Material.CRIMSON_DOOR);
|
||||
doors.add(Material.DARK_OAK_DOOR);
|
||||
doors.add(Material.IRON_DOOR);
|
||||
doors.add(Material.JUNGLE_DOOR);
|
||||
doors.add(Material.MANGROVE_DOOR);
|
||||
doors.add(Material.OAK_DOOR);
|
||||
doors.add(Material.SPRUCE_DOOR);
|
||||
doors.add(Material.WARPED_DOOR);
|
||||
}
|
||||
|
||||
//map of broken doors
|
||||
public Map<Location, Long> brokenDoors = new HashMap<Location, Long>();
|
||||
|
||||
/**
|
||||
* @param event event
|
||||
* @author DunnoConz
|
||||
* @author AubriTheHuman
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerInteract(final PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Action action = event.getAction();
|
||||
|
||||
if (action == Action.LEFT_CLICK_BLOCK) {
|
||||
Block clicked = event.getClickedBlock();
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
if (clicked != null) {
|
||||
if (doors.contains(clicked.getType())) { // left click + any door types
|
||||
Door door = (Door) clicked.getBlockData();
|
||||
// lock door in the opposite position
|
||||
if (item.equals(WarItemRegistry.getInstance().getOrNull("ram"))) {
|
||||
boolean inSiegeOrRaid = false;
|
||||
//siege check
|
||||
for (Siege s : SiegeData.getSieges()) {
|
||||
for (TownBlock townBlock : s.getTown().getTownBlocks()) {
|
||||
if (WorldCoord.parseWorldCoord(clicked).equals(townBlock.getWorldCoord())) {
|
||||
// if we find one, just end no need to continue
|
||||
inSiegeOrRaid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if it wasnt in a siege, then
|
||||
if (!inSiegeOrRaid) {
|
||||
for (Raid r : RaidData.getRaids()) {
|
||||
for (TownBlock townBlock : r.getRaidedTown().getTownBlocks()) {
|
||||
if (WorldCoord.parseWorldCoord(clicked).equals(townBlock.getWorldCoord())) {
|
||||
// if we find one, just end no need to continue
|
||||
inSiegeOrRaid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (inSiegeOrRaid) {
|
||||
|
||||
// Returns if already broken.
|
||||
if (doorBroken(clicked, door)) {
|
||||
player.sendMessage(Helper.chatLabel() + Helper.color("&cThe door is already broken!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
player.sendMessage(Helper.chatLabel() + Helper.color("&eBreak it down alright!"));
|
||||
brokenDoors.put(getDoorPos(clicked, door), System.currentTimeMillis() + (1000L * Main.getInstance().getConfig().getInt("batteringRamEffectiveness")));
|
||||
door.setOpen(!door.isOpen());
|
||||
clicked.setBlockData(door);
|
||||
player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1);
|
||||
Main.warLogger.log("User " + player.getName() + " has broken down door" + clicked.getLocation().toString());
|
||||
} else {
|
||||
player.sendMessage(Helper.chatLabel() + Helper.color("&cThis item can only be used in a siege or raid!"));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerRClick(final PlayerItemDamageEvent event) {
|
||||
ItemStack item = event.getItem();
|
||||
if (item.equals(WarItemRegistry.getInstance().getOrNull("ram"))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param event event
|
||||
* @author DunnoConz
|
||||
* @author AubriTheHuman
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerRClick(final PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Action action = event.getAction();
|
||||
Block clicked = event.getClickedBlock();
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
if (action == Action.RIGHT_CLICK_BLOCK) {
|
||||
if (clicked != null) {
|
||||
if (doors.contains(clicked.getType())) {
|
||||
Door door = (Door) clicked.getBlockData();
|
||||
if (doorBroken(clicked, door)) {
|
||||
player.sendMessage(Helper.chatLabel() + Helper.color("Door is broken!"));
|
||||
event.setCancelled(true);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (item.equals(WarItemRegistry.getInstance().getOrNull("ram"))) {
|
||||
if (clicked != null) {
|
||||
if (clicked.getType().name().equals("GRASS_BLOCK")
|
||||
|| clicked.getType().name().equals("DIRT")
|
||||
|| clicked.getType().name().equals("COARSE_DIRT")
|
||||
|| clicked.getType().name().equals("ROOTED_DIRT")
|
||||
|| clicked.getType().name().equals("DIRT_PATH")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Location getDoorPos(Block clicked, Door door) {
|
||||
if(door.getHalf() == Bisected.Half.BOTTOM) {
|
||||
return clicked.getLocation().clone();
|
||||
} else if(door.getHalf() == Bisected.Half.TOP) {
|
||||
return clicked.getLocation().subtract(0.0, 1.0, 0.0).clone();
|
||||
}
|
||||
return clicked.getLocation().clone();
|
||||
}
|
||||
|
||||
private boolean doorBroken(@Nonnull Block clicked, Door door) {
|
||||
if(door.getHalf() == Bisected.Half.BOTTOM) {
|
||||
if(brokenDoors.get(clicked.getLocation()) != null) {
|
||||
return brokenDoors.get(clicked.getLocation()) > System.currentTimeMillis();
|
||||
}
|
||||
} else if(door.getHalf() == Bisected.Half.TOP) {
|
||||
if(brokenDoors.get(clicked.getLocation().subtract(0.0, 1.0D, 0.0)) != null) {
|
||||
return brokenDoors.get(clicked.getLocation().subtract(0.0, 1.0D, 0.0)) > System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user