diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..26ed197 --- /dev/null +++ b/TODO.md @@ -0,0 +1,6 @@ +# TODO + +[X] Proper file names +[ ] Use ACF? +[ ] Better separation of concerns +[ ] Proper (de)serialization diff --git a/build.gradle b/build.gradle index 8f8f110..3c2274c 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ repositories { dependencies { compileOnly 'io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT' compileOnly 'de.jeff_media:ChestSortAPI:13.0.0-SNAPSHOT' - implementation 'co.aikar:taskchain-bukkit:3.7.2' + implementation 'co.aikar:acf-paper:0.5.1-SNAPSHOT' } group = 'eu.zhincore.chestnetworks' @@ -29,10 +29,16 @@ version = '1.0-SNAPSHOT' description = 'chestnetworks' shadowJar { - relocate 'co.aikar.taskchain', 'eu.zhincore.chestnetworks.taskchain' + relocate 'co.aikar.commands', 'eu.zhincore.chestnetworks.acf' + relocate 'co.aikar.locales', 'eu.zhincore.chestnetworks.locales' archiveClassifier = "shadowed" } +compileJava { + options.compilerArgs += ["-parameters"] + options.fork = true +} + java { toolchain.languageVersion.set(JavaLanguageVersion.of(17)) } diff --git a/src/main/java/eu/zhincore/chestnetworks/ChestNetCommand.java b/src/main/java/eu/zhincore/chestnetworks/ChestNetCommand.java new file mode 100644 index 0000000..6670552 --- /dev/null +++ b/src/main/java/eu/zhincore/chestnetworks/ChestNetCommand.java @@ -0,0 +1,7 @@ +package eu.zhincore.chestnetworks; + +import co.aikar.commands.BaseCommand; + +public class ChestNetCommand extends BaseCommand { + +} diff --git a/src/main/java/eu/zhincore/chestnetworks/NetworksController.java b/src/main/java/eu/zhincore/chestnetworks/ChestNetController.java similarity index 92% rename from src/main/java/eu/zhincore/chestnetworks/NetworksController.java rename to src/main/java/eu/zhincore/chestnetworks/ChestNetController.java index c9d76c6..1f7e69a 100644 --- a/src/main/java/eu/zhincore/chestnetworks/NetworksController.java +++ b/src/main/java/eu/zhincore/chestnetworks/ChestNetController.java @@ -20,15 +20,15 @@ import org.json.simple.JSONArray; import org.json.simple.JSONObject; -public class NetworksController { +public class ChestNetController { private HashMap playerSelectQueue = new HashMap<>(); - private ChestNetworks plugin; - private Database database; + private ChestNetworksPlugin plugin; + private ChestNetDatabase database; private JSONObject players; - public NetworksController(ChestNetworks plugin) { + public ChestNetController(ChestNetworksPlugin plugin) { this.plugin = plugin; - database = new Database(plugin); + database = new ChestNetDatabase(plugin); players = (JSONObject) database.data; } @@ -111,7 +111,8 @@ public List listGlobalChestLocations() { for (String playerId : playerIds) { for (String networkName : listNets(playerId)) { output.addAll(listChests(playerId, networkName).stream() - .map(v -> ((Location) Database.jsonToLoc((JSONObject) v.get("location")))).collect(Collectors.toList())); + .map(v -> ((Location) ChestNetDatabase.jsonToLoc((JSONObject) v.get("location")))) + .collect(Collectors.toList())); } } return output; @@ -128,7 +129,6 @@ public void delete(Player player, String name) { return; } } - plugin.messenger.send("cnet404", player, name); } @SuppressWarnings("unchecked") @@ -200,7 +200,7 @@ public void onPlayerSelected(Player player, Location loc) { @SuppressWarnings("unchecked") private void addChest(Player player, Location loc, String[] playerData) { String playerId = player.getUniqueId().toString(); - JSONObject jsonLoc = (JSONObject) Database.locToJson(loc); + JSONObject jsonLoc = (JSONObject) ChestNetDatabase.locToJson(loc); JSONArray network = (JSONArray) ((JSONObject) players.get(playerId)).get(playerData[1]); // Detect is this chest is already registered @@ -238,7 +238,7 @@ private void checkChest(Player player, Location loc) { public JSONObject getChestData(Location loc) { for (Object chest : listGlobalChests()) { - if (Database.jsonToLoc((JSONObject) ((JSONObject) chest).get("location")).equals(loc)) { + if (ChestNetDatabase.jsonToLoc((JSONObject) ((JSONObject) chest).get("location")).equals(loc)) { return (JSONObject) chest; } } @@ -271,7 +271,7 @@ public void update(String playerId, String netName) { JSONArray network = (JSONArray) ((JSONObject) players.get(playerId)).get(netName); for (Object chestData : network) { - Chest chest = getChestByLoc(Database.jsonToLoc((JSONObject) ((JSONObject) chestData).get("location"))); + Chest chest = getChestByLoc(ChestNetDatabase.jsonToLoc((JSONObject) ((JSONObject) chestData).get("location"))); if (chest != null) { update(chest.getInventory()); } @@ -307,7 +307,7 @@ public void update(Inventory inventory) { for (Object inputChestData : network) { if (((JSONObject) inputChestData).get("type").equals("input")) { Chest inputChest = getChestByLoc( - Database.jsonToLoc((JSONObject) ((JSONObject) inputChestData).get("location"))); + ChestNetDatabase.jsonToLoc((JSONObject) ((JSONObject) inputChestData).get("location"))); if (inputChest != null) { update(inputChest.getInventory()); } @@ -317,7 +317,8 @@ public void update(Inventory inventory) { if (chestData.get("sort") != null) sortInventory(inventory); for (var _chestData : changedChests) { if (_chestData == null || _chestData.get("sort") != null) continue; - Chest _chest = getChestByLoc(Database.jsonToLoc((JSONObject) ((JSONObject) _chestData).get("location"))); + Chest _chest = getChestByLoc( + ChestNetDatabase.jsonToLoc((JSONObject) ((JSONObject) _chestData).get("location"))); sortInventory(_chest.getInventory()); } } @@ -341,7 +342,7 @@ private JSONObject placeItems(JSONArray network, Inventory inventory, ItemStack || !(chestcontent.isEmpty() ? fallback : chestcontent.contains(item.getType().toString()))) continue; - Location loc = Database.jsonToLoc((JSONObject) chestconf.get("location")); + Location loc = ChestNetDatabase.jsonToLoc((JSONObject) chestconf.get("location")); Chest target = getChestByLoc(loc); if (target == null) continue; diff --git a/src/main/java/eu/zhincore/chestnetworks/Database.java b/src/main/java/eu/zhincore/chestnetworks/ChestNetDatabase.java similarity index 95% rename from src/main/java/eu/zhincore/chestnetworks/Database.java rename to src/main/java/eu/zhincore/chestnetworks/ChestNetDatabase.java index 17fcb96..6484d99 100644 --- a/src/main/java/eu/zhincore/chestnetworks/Database.java +++ b/src/main/java/eu/zhincore/chestnetworks/ChestNetDatabase.java @@ -10,12 +10,12 @@ import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; -public class Database { +public class ChestNetDatabase { public JSONObject data; private File file; private JSONParser parser = new JSONParser(); - public Database(ChestNetworks plugin) { + public ChestNetDatabase(ChestNetworksPlugin plugin) { file = new File(plugin.getDataFolder(), "data.json"); reload(); } diff --git a/src/main/java/eu/zhincore/chestnetworks/EventListener.java b/src/main/java/eu/zhincore/chestnetworks/ChestNetListener.java similarity index 91% rename from src/main/java/eu/zhincore/chestnetworks/EventListener.java rename to src/main/java/eu/zhincore/chestnetworks/ChestNetListener.java index 7ee8849..d842c26 100644 --- a/src/main/java/eu/zhincore/chestnetworks/EventListener.java +++ b/src/main/java/eu/zhincore/chestnetworks/ChestNetListener.java @@ -14,10 +14,10 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.Inventory; -public class EventListener implements Listener { - private NetworksController networkController; +public class ChestNetListener implements Listener { + private ChestNetController networkController; - public EventListener(NetworksController networkController) { + public ChestNetListener(ChestNetController networkController) { this.networkController = networkController; } diff --git a/src/main/java/eu/zhincore/chestnetworks/Messenger.java b/src/main/java/eu/zhincore/chestnetworks/ChestNetMessenger.java similarity index 91% rename from src/main/java/eu/zhincore/chestnetworks/Messenger.java rename to src/main/java/eu/zhincore/chestnetworks/ChestNetMessenger.java index 9bf025e..8b58be1 100644 --- a/src/main/java/eu/zhincore/chestnetworks/Messenger.java +++ b/src/main/java/eu/zhincore/chestnetworks/ChestNetMessenger.java @@ -10,12 +10,12 @@ import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; -public class Messenger { +public class ChestNetMessenger { private static final String prefix = "§b[§2ChestNetworks§b]§r "; private JSONObject messages; private JSONParser parser = new JSONParser(); - public Messenger(Reader messagesRaw) throws IOException, ParseException { + public ChestNetMessenger(Reader messagesRaw) throws IOException, ParseException { messages = (JSONObject) parser.parse(messagesRaw); } diff --git a/src/main/java/eu/zhincore/chestnetworks/ChestNetworks.java b/src/main/java/eu/zhincore/chestnetworks/ChestNetworksPlugin.java similarity index 62% rename from src/main/java/eu/zhincore/chestnetworks/ChestNetworks.java rename to src/main/java/eu/zhincore/chestnetworks/ChestNetworksPlugin.java index 4e0fb0b..bdd6f49 100644 --- a/src/main/java/eu/zhincore/chestnetworks/ChestNetworks.java +++ b/src/main/java/eu/zhincore/chestnetworks/ChestNetworksPlugin.java @@ -4,23 +4,23 @@ import org.bukkit.plugin.java.JavaPlugin; import org.json.simple.parser.ParseException; -public class ChestNetworks extends JavaPlugin { - public Messenger messenger; - private NetworksController networksController; +public class ChestNetworksPlugin extends JavaPlugin { + public ChestNetMessenger messenger; + private ChestNetController networksController; @Override public void onEnable() { try { - messenger = new Messenger(getTextResource("messages.json")); + messenger = new ChestNetMessenger(getTextResource("messages.json")); } catch (IOException | ParseException e) { e.printStackTrace(); getServer().getPluginManager().disablePlugin(this); return; } - networksController = new NetworksController(this); + networksController = new ChestNetController(this); getCommand("chestnet").setExecutor(new CommandChestNet(this, networksController)); getCommand("chestnet").setTabCompleter(new CommandChestNetTabCompleter(networksController)); - getServer().getPluginManager().registerEvents(new EventListener(networksController), this); + getServer().getPluginManager().registerEvents(new ChestNetListener(networksController), this); } @Override diff --git a/src/main/java/eu/zhincore/chestnetworks/CommandChestNet.java b/src/main/java/eu/zhincore/chestnetworks/CommandChestNet.java index 5e6caeb..fb2246d 100644 --- a/src/main/java/eu/zhincore/chestnetworks/CommandChestNet.java +++ b/src/main/java/eu/zhincore/chestnetworks/CommandChestNet.java @@ -8,10 +8,10 @@ import org.bukkit.entity.Player; public class CommandChestNet implements CommandExecutor { - private NetworksController networksController; - private ChestNetworks plugin; + private ChestNetController networksController; + private ChestNetworksPlugin plugin; - public CommandChestNet(ChestNetworks plugin, NetworksController networksController) { + public CommandChestNet(ChestNetworksPlugin plugin, ChestNetController networksController) { this.networksController = networksController; this.plugin = plugin; } diff --git a/src/main/java/eu/zhincore/chestnetworks/CommandChestNetTabCompleter.java b/src/main/java/eu/zhincore/chestnetworks/CommandChestNetTabCompleter.java index 753d8d4..d0553e6 100644 --- a/src/main/java/eu/zhincore/chestnetworks/CommandChestNetTabCompleter.java +++ b/src/main/java/eu/zhincore/chestnetworks/CommandChestNetTabCompleter.java @@ -10,9 +10,9 @@ import org.bukkit.entity.Player; public class CommandChestNetTabCompleter implements TabCompleter { - private NetworksController networksController; + private ChestNetController networksController; - public CommandChestNetTabCompleter(NetworksController networksController) { + public CommandChestNetTabCompleter(ChestNetController networksController) { this.networksController = networksController; }