From c5e64acb5893f266c16244d4594157c4f7862296 Mon Sep 17 00:00:00 2001 From: TheDutchMC Date: Tue, 9 Feb 2021 22:42:19 +0100 Subject: [PATCH] Added jitpack.yml file, some language+color issues fixed, added listener for PlayerTransferEvent, fired by OfflinePlayers, version bump to 2.1.0 --- build.gradle | 13 ++++-- jitpack.yml | 2 + .../nl/thedutchmc/dutchyhome/DutchyHome.java | 21 +++++++++- .../nl/thedutchmc/dutchyhome/PlayerHomes.java | 2 +- .../commands/SetHomeCommandExecutor.java | 6 +-- .../PlayerTransferEventListener.java | 42 +++++++++++++++++++ 6 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 jitpack.yml create mode 100644 src/main/java/nl/thedutchmc/dutchyhome/listeners/PlayerTransferEventListener.java diff --git a/build.gradle b/build.gradle index c8ebb6b..8248436 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'eclipse' } -version = '2.0.0' +version = '2.1.0' sourceCompatibility = 1.11 targetCompatibility = 1.11 @@ -20,15 +20,20 @@ repositories { jcenter() maven{ url "https://hub.spigotmc.org/nexus/content/repositories/snapshots" } maven{ url "https://oss.sonatype.org/content/repositories/snapshots" } - maven { url 'https://jitpack.io' } + maven { url 'https://jitpack.io' } mavenLocal() } dependencies { //Dev only: - //compileOnly 'nl.thedutchmc:dutchycore:0.0.15' + //compileOnly 'nl.thedutchmc:dutchycore:0.0.33' + //compileOnly 'nl.thedutchmc:offlineplayers:1.1.0' + //bug in jitpack, cant use nl.thedutchmc here :/ - compileOnly 'com.github.DutchyPlugins:Dutchycore:0.0.15-R3' + compileOnly 'com.github.DutchyPlugins:DutchyCore:0.0.34' + compileOnly 'com.github.DutchyPlugins:OfflinePlayers:1.1.0' + + //Spigot API compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT' } diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 0000000..ebec7d1 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,2 @@ +jdk: + - openjdk11 \ No newline at end of file diff --git a/src/main/java/nl/thedutchmc/dutchyhome/DutchyHome.java b/src/main/java/nl/thedutchmc/dutchyhome/DutchyHome.java index f6c74bb..202d73f 100644 --- a/src/main/java/nl/thedutchmc/dutchyhome/DutchyHome.java +++ b/src/main/java/nl/thedutchmc/dutchyhome/DutchyHome.java @@ -12,17 +12,19 @@ import org.bukkit.permissions.PermissionDefault; import nl.thedutchmc.dutchycore.DutchyCore; import nl.thedutchmc.dutchycore.module.PluginModule; -import nl.thedutchmc.dutchycore.module.annotations.Nullable; +import nl.thedutchmc.dutchycore.annotations.Nullable; import nl.thedutchmc.dutchycore.module.file.ModuleFileHandler; import nl.thedutchmc.dutchycore.module.file.ModuleStorage; import nl.thedutchmc.dutchyhome.commands.DelHomeCommandExecutor; import nl.thedutchmc.dutchyhome.commands.HomeCommandExecutor; import nl.thedutchmc.dutchyhome.commands.HomesCommandExecutor; import nl.thedutchmc.dutchyhome.commands.SetHomeCommandExecutor; +import nl.thedutchmc.dutchyhome.listeners.PlayerTransferEventListener; import nl.thedutchmc.dutchyhome.tabcompleters.DelHomeCommandCompleter; import nl.thedutchmc.dutchyhome.tabcompleters.HomeCommandCompleter; import nl.thedutchmc.dutchyhome.tabcompleters.HomesCommandCompleter; import nl.thedutchmc.dutchyhome.tabcompleters.SetHomeCommandCompleter; +import nl.thedutchmc.offlineplayers.events.PlayerTransferEvent; public class DutchyHome extends PluginModule { @@ -130,6 +132,15 @@ public void enable(DutchyCore core) { super.logInfo("Initialization complete!"); } + @Override + public void postEnable() { + //Register event listeners + if(super.isModuleRegistered("OfflinePlayers")) { + super.logInfo("OfflinePlayers is installed. Enabling listener!"); + super.registerModuleEventListener(new PlayerTransferEventListener(this), PlayerTransferEvent.class); + } + } + /** * Write a home to disk * @param homeName The name of the home @@ -199,4 +210,12 @@ public PlayerHomes getPlayerHomes(UUID uuid) { public void setPlayerHome(UUID uuid, PlayerHomes playerHomes) { this.playerHomes.put(uuid, playerHomes); } + + /** + * Remove a PlayerHomes for a player + * @param uuid The UUID of the player + */ + public void delPlayerHome(UUID uuid) { + this.playerHomes.remove(uuid); + } } diff --git a/src/main/java/nl/thedutchmc/dutchyhome/PlayerHomes.java b/src/main/java/nl/thedutchmc/dutchyhome/PlayerHomes.java index 8421f6e..64cfd81 100644 --- a/src/main/java/nl/thedutchmc/dutchyhome/PlayerHomes.java +++ b/src/main/java/nl/thedutchmc/dutchyhome/PlayerHomes.java @@ -5,7 +5,7 @@ import org.bukkit.Location; -import nl.thedutchmc.dutchycore.module.annotations.Nullable; +import nl.thedutchmc.dutchycore.annotations.Nullable; public class PlayerHomes { diff --git a/src/main/java/nl/thedutchmc/dutchyhome/commands/SetHomeCommandExecutor.java b/src/main/java/nl/thedutchmc/dutchyhome/commands/SetHomeCommandExecutor.java index b11f62a..2470c3e 100644 --- a/src/main/java/nl/thedutchmc/dutchyhome/commands/SetHomeCommandExecutor.java +++ b/src/main/java/nl/thedutchmc/dutchyhome/commands/SetHomeCommandExecutor.java @@ -76,7 +76,7 @@ public boolean fire(CommandSender sender, String[] args) { //Verify that the amount is an integer if(!Utils.verifyPositiveInteger(parts[parts.length -1])) { - sender.sendMessage("Please contact your server administrator. They have made a mistake with permissions for DutchyHome!"); + sender.sendMessage(ChatColor.RED + "Please contact your server administrator. They have made a mistake with permissions for DutchyHome!"); return true; } @@ -98,7 +98,7 @@ public boolean fire(CommandSender sender, String[] args) { //Check if the player has reached the home limit int amountOfHomes = playerHomes.getAllHomes().size(); if(amountOfHomes >= maxHomes) { - sender.sendMessage("You have reached the limit of homes you can set! Remove a home before setting a new one."); + sender.sendMessage(ChatColor.RED + "You have reached the limit of homes you can set! Remove a home before setting a new one."); return true; } @@ -120,7 +120,7 @@ public boolean fire(CommandSender sender, String[] args) { //Send the message to the player String message = "Set home %s at %d, %d, %d!"; - message = Utils.processColours(message, + message = Utils.processColours(ChatColor.GOLD + message, new Triple("%s", ChatColor.RED, ChatColor.GOLD), new Triple("%d", ChatColor.RED, ChatColor.GOLD)); sender.sendMessage(String.format(message, homeName, playerCurrentLoc.getBlockX(), playerCurrentLoc.getBlockY(), playerCurrentLoc.getBlockZ())); diff --git a/src/main/java/nl/thedutchmc/dutchyhome/listeners/PlayerTransferEventListener.java b/src/main/java/nl/thedutchmc/dutchyhome/listeners/PlayerTransferEventListener.java new file mode 100644 index 0000000..6059591 --- /dev/null +++ b/src/main/java/nl/thedutchmc/dutchyhome/listeners/PlayerTransferEventListener.java @@ -0,0 +1,42 @@ +package nl.thedutchmc.dutchyhome.listeners; + +import java.util.Map; + +import org.bukkit.Location; + +import nl.thedutchmc.dutchycore.module.events.ModuleEvent; +import nl.thedutchmc.dutchycore.module.events.ModuleEventListener; +import nl.thedutchmc.dutchyhome.DutchyHome; +import nl.thedutchmc.dutchyhome.PlayerHomes; +import nl.thedutchmc.offlineplayers.events.PlayerTransferEvent; + +public class PlayerTransferEventListener implements ModuleEventListener { + + private DutchyHome module; + + public PlayerTransferEventListener(DutchyHome module) { + this.module = module; + } + + @Override + public void onEvent(ModuleEvent event) { + PlayerTransferEvent pte = (PlayerTransferEvent) event; + + PlayerHomes playerHomesOld = this.module.getPlayerHomes(pte.getOldUUID()); + + //Create a new PlayerHoems object + PlayerHomes playerHomesNew = new PlayerHomes(pte.getNewUUID()); + + //Add all h omes from the playerHomesOld to the playerHomesNew + for(Map.Entry entry : playerHomesOld.getAllHomes().entrySet()) { + playerHomesNew.setHome(entry.getKey(), entry.getValue()); + } + + //Set the new PlayerHomes, and remove the old + this.module.setPlayerHome(pte.getNewUUID(), playerHomesNew); + this.module.delPlayerHome(pte.getOldUUID()); + + //Write memory to disk + this.module.writeMemory(); + } +}