diff --git a/pom.xml b/pom.xml index 296a531..cea55ca 100644 --- a/pom.xml +++ b/pom.xml @@ -1,10 +1,10 @@ + 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"> 4.0.0 com.hm.petmaster PetMaster - 1.12.5 + 1.12.6 https://github.com/PyvesB/PetMaster PetMaster Manage pets and display useful information via holograms, action bar or chat messages! @@ -30,16 +30,16 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.13.0 - 1.8 - 1.8 + 16 + 16 org.apache.maven.plugins maven-shade-plugin - 3.3.0-SNAPSHOT + 3.5.3 @@ -86,23 +86,27 @@ codemc-repo https://repo.codemc.io/repository/maven-public/ + + jitpack.io + https://jitpack.io + net.kyori adventure-api - 4.11.0 + 4.17.0 net.kyori adventure-text-minimessage - 4.11.0 + 4.17.0 net.kyori adventure-platform-bukkit - 4.1.1 + 4.3.2 @@ -110,22 +114,25 @@ org.spigotmc spigot-api - 1.17-R0.1-SNAPSHOT + 1.20.6-R0.1-SNAPSHOT jar provided + com.github.MilkBowl VaultAPI 1.7 provided + - com.gmail.filoghost.holographicdisplays - holographicdisplays-api - 2.4.0 + com.github.decentsoftware-eu + decentholograms + 2.8.8 provided + com.hm.mcshared MCShared diff --git a/src/main/java/com/hm/petmaster/PetMaster.java b/src/main/java/com/hm/petmaster/PetMaster.java index 17727aa..9cb7d27 100644 --- a/src/main/java/com/hm/petmaster/PetMaster.java +++ b/src/main/java/com/hm/petmaster/PetMaster.java @@ -25,16 +25,16 @@ /** * Manage pets and display useful information via holograms, action bar or chat messages! - * + * * PetMaster is under GNU General Public License version 3. Please visit the plugin's GitHub for more information : * https://github.com/PyvesB/PetMaster * * Official plugin's server: hellominecraft.fr - * + * * Bukkit project page: dev.bukkit.org/bukkit-plugins/pet-master - * + * * Spigot project page: spigotmc.org/resources/pet-master.15904 - * + * * @since December 2015. * @version 1.12.5 * @author DarkPyves @@ -96,10 +96,12 @@ public void onEnable() { this.adventure = BukkitAudiences.create(this); this.messageSender = new MessageSender(this); + getLogger().info("Server version..." + Bukkit.getServer().getBukkitVersion()); + getLogger().info("Registered subVersion..." + Bukkit.getServer().getBukkitVersion().replace(".", ",").split(",")[1].split("-")[0]); getLogger().info("Registering listeners..."); - + serverVersion = Integer.parseInt( - Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3].split("_")[1]); + Bukkit.getServer().getBukkitVersion().replace(".", ",").split(",")[1].split("-")[0]); playerInteractListener = new PlayerInteractListener(this); playerLeashListener = new PlayerLeashListener(this); @@ -118,7 +120,7 @@ public void onEnable() { } extractParametersFromConfig(true); - + PetAbilityFile.petAbilitySetup(); PetAbilityFile.getPetAbilities().options().copyDefaults(true); PetAbilityFile.petAbilitySave(); @@ -175,7 +177,7 @@ public void extractParametersFromConfig(boolean attemptUpdate) { if (config.getBoolean("checkForUpdate", true)) { if (updateChecker == null) { updateChecker = new UpdateChecker(this, "https://raw.githubusercontent.com/PyvesB/PetMaster/master/pom.xml", - "petmaster.admin", chatHeader, "spigotmc.org/resources/pet-master.15904"); + "petmaster.admin", chatHeader, "spigotmc.org/resources/pet-master.15904"); getServer().getPluginManager().registerEvents(updateChecker, this); updateChecker.launchUpdateCheckerTask(); } @@ -201,7 +203,7 @@ public void extractParametersFromConfig(boolean attemptUpdate) { /** * Loads and backs up file fileName. - * + * * @param fileName * @return the loaded CommentedYamlConfiguration */ @@ -212,7 +214,7 @@ private CommentedYamlConfiguration loadAndBackupYamlConfiguration(String fileNam } catch (IOException | InvalidConfigurationException e) { getLogger().severe("Error while loading " + fileName + " file, disabling plugin."); getLogger().log(Level.SEVERE, - "Verify your syntax by visiting yaml-online-parser.appspot.com and using the following logs: ", e); + "Verify your syntax by visiting yaml-online-parser.appspot.com and using the following logs: ", e); getServer().getPluginManager().disablePlugin(this); } @@ -233,7 +235,7 @@ private void updateOldConfiguration() { updateSetting(config, "languageFileName", "lang.yml", "Name of the language file."); updateSetting(config, "checkForUpdate", true, - "Check for update on plugin launch and notify when an OP joins the game."); + "Check for update on plugin launch and notify when an OP joins the game."); updateSetting(config, "changeOwnerPrice", 0, "Price of the /petm setowner command (requires Vault)."); updateSetting(config, "displayDog", true, "Take dogs into account."); updateSetting(config, "displayCat", true, "Take cats into account."); @@ -241,15 +243,15 @@ private void updateOldConfiguration() { updateSetting(config, "displayLlama", true, "Take llamas into account."); updateSetting(config, "displayParrot", true, "Take parrots into account."); updateSetting(config, "actionBarMessage", false, - "Enable or disable action bar messages when right-clicking on a pet."); + "Enable or disable action bar messages when right-clicking on a pet."); updateSetting(config, "displayToOwner", false, - "Enable or disable showing ownership information for a player's own pets."); + "Enable or disable showing ownership information for a player's own pets."); updateSetting(config, "freePetPrice", 0, "Price of the /petm free command (requires Vault)."); updateSetting(config, "showHealth", true, - "Show health next to owner in chat and action bar messages (not holograms)."); + "Show health next to owner in chat and action bar messages (not holograms)."); updateSetting(config, "disablePlayerDamage", false, "Protect pets to avoid being hurt by other player."); updateSetting(config, "enableAngryMobPlayerDamage", true, - "Allows players to defend themselves against angry tamed mobs (e.g. dogs) even if disablePlayerDamage is true."); + "Allows players to defend themselves against angry tamed mobs (e.g. dogs) even if disablePlayerDamage is true."); updateSetting(config, "disableLeash", false, "Prevent others from using leash on pet."); updateSetting(config, "disableRiding", false, "Prevent others from mounting pet (horse/donkey)."); @@ -337,7 +339,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, /** * Updates the configuration file to include a new setting with its default value and its comments. - * + * * @param file * @param name * @param value @@ -349,7 +351,7 @@ private void updateSetting(CommentedYamlConfiguration file, String name, Object updatePerformed = true; } } - + public int getServerVersion() { return serverVersion; } diff --git a/src/main/java/com/hm/petmaster/command/InfoCommand.java b/src/main/java/com/hm/petmaster/command/InfoCommand.java index 5e2f894..af7b2fe 100644 --- a/src/main/java/com/hm/petmaster/command/InfoCommand.java +++ b/src/main/java/com/hm/petmaster/command/InfoCommand.java @@ -11,9 +11,9 @@ /** * Class in charge of displaying the plugin's extra information (/petm info). - * + * * @author Pyves - * + * */ public class InfoCommand { @@ -25,7 +25,7 @@ public InfoCommand(PetMaster plugin) { /** * Displays information about the plugin. - * + * * @param sender */ public void getInfo(CommandSender sender) { diff --git a/src/main/java/com/hm/petmaster/command/SetOwnerCommand.java b/src/main/java/com/hm/petmaster/command/SetOwnerCommand.java index 6a66a41..b559cce 100644 --- a/src/main/java/com/hm/petmaster/command/SetOwnerCommand.java +++ b/src/main/java/com/hm/petmaster/command/SetOwnerCommand.java @@ -11,9 +11,9 @@ /** * Class in charge of handling player requests to change ownership of a pet (/petm setowner). - * + * * @author Pyves - * + * */ public class SetOwnerCommand { diff --git a/src/main/java/com/hm/petmaster/listener/PlayerInteractListener.java b/src/main/java/com/hm/petmaster/listener/PlayerInteractListener.java index a42c566..b288a7a 100644 --- a/src/main/java/com/hm/petmaster/listener/PlayerInteractListener.java +++ b/src/main/java/com/hm/petmaster/listener/PlayerInteractListener.java @@ -1,9 +1,9 @@ package com.hm.petmaster.listener; -import com.gmail.filoghost.holographicdisplays.api.Hologram; -import com.gmail.filoghost.holographicdisplays.api.HologramsAPI; import com.hm.mcshared.event.PlayerChangeAnimalOwnershipEvent; import com.hm.petmaster.PetMaster; +import eu.decentsoftware.holograms.api.DHAPI; +import eu.decentsoftware.holograms.api.holograms.Hologram; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import net.milkbowl.vault.economy.Economy; @@ -20,12 +20,12 @@ import org.bukkit.scheduler.BukkitRunnable; import java.lang.reflect.Method; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** * Class used to display holograms, change the owner of a pet or free a pet. - * + * * @author Pyves * */ @@ -85,13 +85,13 @@ public void extractParameters() { showHealth = plugin.getPluginConfig().getBoolean("showHealth", true); disableRiding = plugin.getPluginConfig().getBoolean("disableRiding", false); - boolean holographicDisplaysAvailable = Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays"); + boolean decentHologramsAvailable = Bukkit.getPluginManager().isPluginEnabled("DecentHolograms"); // Checking whether user configured plugin to display hologram but HolographicsDisplays not available. - if (hologramMessage && !holographicDisplaysAvailable) { + if (hologramMessage && !decentHologramsAvailable) { hologramMessage = false; actionBarMessage = true; plugin.getLogger().warning( - "HolographicDisplays was not found; disabling usage of holograms and enabling action bar messages."); + "DecentHolograms was not found; disabling usage of holograms and enabling action bar messages."); } } @@ -135,7 +135,7 @@ public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) { /** * Determines whether the current PlayerInteractEntityEvent should be handled. - * + * * @param event * @return true if the event should be handled, false otherwise */ @@ -147,7 +147,7 @@ private boolean shouldHandleEvent(PlayerInteractEntityEvent event) { /** * Change the owner of a pet. - * + * * @param player * @param oldOwner * @param newOwner @@ -161,7 +161,7 @@ private void changeOwner(Player player, AnimalTamer oldOwner, Player newOwner, T + plugin.getPluginLang().getString("owner-changed", "This pet was given to a new owner!")); newOwner.sendMessage(plugin.getChatHeader() + plugin.getPluginLang().getString("new-owner", "Player PLAYER gave you ownership of a pet!") - .replace("PLAYER", player.getName())); + .replace("PLAYER", oldOwner.getName())); // Create new event to allow other plugins to be aware of the ownership change. PlayerChangeAnimalOwnershipEvent playerChangeAnimalOwnershipEvent = new PlayerChangeAnimalOwnershipEvent( @@ -172,7 +172,7 @@ private void changeOwner(Player player, AnimalTamer oldOwner, Player newOwner, T /** * Frees a pet; it will no longer be tamed. - * + * * @param player * @param oldOwner * @param tameable @@ -207,7 +207,7 @@ private void freePet(Player player, AnimalTamer oldOwner, Tameable tameable) { /** * Displays a hologram, and automatically delete it after a given delay. - * + * * @param player * @param owner * @param tameable @@ -248,19 +248,29 @@ private void displayHologramAndMessage(Player player, AnimalTamer owner, Tameabl Location hologramLocation = new Location(eventLocation.getWorld(), eventLocation.getX(), eventLocation.getY() + offset, eventLocation.getZ()); - final Hologram hologram = HologramsAPI.createHologram(plugin, hologramLocation); - hologram.appendTextLine(plugin.getMessageSender().parseMessageToString( + + String hologramname = player.getUniqueId() + "_pm"; + + List lines = Collections.singletonList(plugin.getMessageSender().parseMessageToString( "petmaster-hologram", Placeholder.component("owner", Component.text(owner.getName() != null ? owner.getName() : "null")) )); + if (DHAPI.getHologram(hologramname) == null) { + Hologram hologram = DHAPI.createHologram(hologramname, hologramLocation, lines); + } else { + return; + } + + // Runnable to delete hologram. + new BukkitRunnable() { @Override public void run() { - hologram.delete(); + DHAPI.removeHologram(hologramname); } }.runTaskLater(plugin, hologramDuration); } @@ -274,7 +284,7 @@ public void run() { Placeholder.component("current-health", Component.text(String.format("%.1f", animal.getHealth()))), Placeholder.component("max-health", Component.text( plugin.getServerVersion() < 9 ? String.format("%.1f", animal.getMaxHealth()) - : String.format("%.1f", animal.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()))) + : String.format("%.1f", animal.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()))) ); } @@ -303,7 +313,7 @@ public void run() { /** * Charges a player if he has enough money and displays relevant messages. - * + * * @param player * @param price * @return true if money should be withdrawn from the player, false otherwise diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 7595345..29267f8 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -14,11 +14,11 @@ # | General settings | # # 2---------------------------------------------------------2 # #=============================o=o=============================# - + # Enable or disable chat messages when right-clicking on a pet. chatMessage: false -# Enable or disable hologram messages when right-clicking on a pet (requires Holographic Displays). +# Enable or disable hologram messages when right-clicking on a pet (requires DecentHolograms). hologramMessage: false # Enable or disable action bar messages when right-clicking on a pet. diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 526506d..0836449 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,7 +5,7 @@ author: DarkPyves softdepend: [HolographicDisplays,Vault] description: Manage pets and display useful information via holograms, action bar or chat messages! website: https://github.com/PyvesB/PetMaster -api-version: 1.13 +api-version: 1.20 commands: petm: description: Main Pet Master command, use it to list sub-commands.