From 2b37feec072a15c0c8155ddbeec6b0841f096bfa Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Mon, 31 Jan 2022 23:58:42 -0500 Subject: [PATCH] Give fox command - bring up name screen for receiving player (#72) --- .../versions/version_1_14_R1/NMSInterface_1_14_R1.java | 6 ++++++ .../versions/version_1_15_R1/NMSInterface_1_15_R1.java | 6 ++++++ .../versions/version_1_16_R1/NMSInterface_1_16_R1.java | 6 ++++++ .../versions/version_1_16_R2/NMSInterface_1_16_R2.java | 6 ++++++ .../versions/version_1_16_R3/NMSInterface_1_16_R3.java | 6 ++++++ .../version_1_17_1_R1/NMSInterface_1_17_1_R1.java | 6 ++++++ .../versions/version_1_17_R1/NMSInterface_1_17_R1.java | 6 ++++++ .../version_1_18_1_R1/NMSInterface_1_18_1_R1.java | 6 ++++++ .../versions/version_1_18_R1/NMSInterface_1_18_R1.java | 6 ++++++ Plugin/pom.xml | 3 ++- .../java/net/seanomik/tamablefoxes/CommandGiveFox.java | 8 ++++++++ .../java/net/seanomik/tamablefoxes/util/FieldHelper.java | 6 ------ .../java/net/seanomik/tamablefoxes/util/NMSInterface.java | 1 + .../net/seanomik/tamablefoxes/util/io/LanguageConfig.java | 4 ++-- 14 files changed, 67 insertions(+), 9 deletions(-) diff --git a/1_14_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/NMSInterface_1_14_R1.java b/1_14_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/NMSInterface_1_14_R1.java index edb621b..fe567b1 100644 --- a/1_14_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/NMSInterface_1_14_R1.java +++ b/1_14_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/NMSInterface_1_14_R1.java @@ -46,4 +46,10 @@ public class NMSInterface_1_14_R1 implements NMSInterface { EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); return tamableFox.getOwnerUUID(); } + + @Override + public void renameFox(org.bukkit.entity.Fox fox, Player player) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + tamableFox.rename(player); + } } diff --git a/1_15_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/NMSInterface_1_15_R1.java b/1_15_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/NMSInterface_1_15_R1.java index 5e86733..8d624fb 100644 --- a/1_15_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/NMSInterface_1_15_R1.java +++ b/1_15_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/NMSInterface_1_15_R1.java @@ -46,4 +46,10 @@ public class NMSInterface_1_15_R1 implements NMSInterface { EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); return tamableFox.getOwnerUUID(); } + + @Override + public void renameFox(org.bukkit.entity.Fox fox, Player player) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + tamableFox.rename(player); + } } diff --git a/1_16_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/NMSInterface_1_16_R1.java b/1_16_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/NMSInterface_1_16_R1.java index 5d95c9c..f6e77cf 100644 --- a/1_16_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/NMSInterface_1_16_R1.java +++ b/1_16_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/NMSInterface_1_16_R1.java @@ -46,4 +46,10 @@ public class NMSInterface_1_16_R1 implements NMSInterface { EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); return tamableFox.getOwnerUUID(); } + + @Override + public void renameFox(org.bukkit.entity.Fox fox, Player player) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + tamableFox.rename(player); + } } diff --git a/1_16_R2/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/NMSInterface_1_16_R2.java b/1_16_R2/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/NMSInterface_1_16_R2.java index a16ed7a..4f5667c 100644 --- a/1_16_R2/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/NMSInterface_1_16_R2.java +++ b/1_16_R2/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/NMSInterface_1_16_R2.java @@ -46,4 +46,10 @@ public class NMSInterface_1_16_R2 implements NMSInterface { EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); return tamableFox.getOwnerUUID(); } + + @Override + public void renameFox(org.bukkit.entity.Fox fox, Player player) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + tamableFox.rename(player); + } } diff --git a/1_16_R3/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/NMSInterface_1_16_R3.java b/1_16_R3/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/NMSInterface_1_16_R3.java index 21d9133..1a785b6 100644 --- a/1_16_R3/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/NMSInterface_1_16_R3.java +++ b/1_16_R3/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/NMSInterface_1_16_R3.java @@ -46,4 +46,10 @@ public class NMSInterface_1_16_R3 implements NMSInterface { EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); return tamableFox.getOwnerUUID(); } + + @Override + public void renameFox(org.bukkit.entity.Fox fox, Player player) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + tamableFox.rename(player); + } } diff --git a/1_17_1_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_1_R1/NMSInterface_1_17_1_R1.java b/1_17_1_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_1_R1/NMSInterface_1_17_1_R1.java index 9335d56..8ea0ffb 100644 --- a/1_17_1_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_1_R1/NMSInterface_1_17_1_R1.java +++ b/1_17_1_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_1_R1/NMSInterface_1_17_1_R1.java @@ -45,4 +45,10 @@ public class NMSInterface_1_17_1_R1 implements NMSInterface { EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); return tamableFox.getOwnerUUID(); } + + @Override + public void renameFox(org.bukkit.entity.Fox fox, Player player) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + tamableFox.rename(player); + } } diff --git a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/NMSInterface_1_17_R1.java b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/NMSInterface_1_17_R1.java index 1745e69..465db22 100644 --- a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/NMSInterface_1_17_R1.java +++ b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/NMSInterface_1_17_R1.java @@ -45,4 +45,10 @@ public class NMSInterface_1_17_R1 implements NMSInterface { EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); return tamableFox.getOwnerUUID(); } + + @Override + public void renameFox(org.bukkit.entity.Fox fox, Player player) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + tamableFox.rename(player); + } } diff --git a/1_18_1_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_18_1_R1/NMSInterface_1_18_1_R1.java b/1_18_1_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_18_1_R1/NMSInterface_1_18_1_R1.java index f1bc290..b2879b4 100644 --- a/1_18_1_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_18_1_R1/NMSInterface_1_18_1_R1.java +++ b/1_18_1_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_18_1_R1/NMSInterface_1_18_1_R1.java @@ -45,4 +45,10 @@ public class NMSInterface_1_18_1_R1 implements NMSInterface { EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); return tamableFox.getOwnerUUID(); } + + @Override + public void renameFox(org.bukkit.entity.Fox fox, Player player) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + tamableFox.rename(player); + } } diff --git a/1_18_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_18_R1/NMSInterface_1_18_R1.java b/1_18_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_18_R1/NMSInterface_1_18_R1.java index dc6eb34..1275d66 100644 --- a/1_18_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_18_R1/NMSInterface_1_18_R1.java +++ b/1_18_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_18_R1/NMSInterface_1_18_R1.java @@ -45,4 +45,10 @@ public class NMSInterface_1_18_R1 implements NMSInterface { EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); return tamableFox.getOwnerUUID(); } + + @Override + public void renameFox(org.bukkit.entity.Fox fox, Player player) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + tamableFox.rename(player); + } } diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 92dbac9..d16cdd6 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -58,7 +58,8 @@ shade - C:\Development\Java\Spigot Servers\${server.version}\plugins\TamableFoxes_v${project.parent.version}.jar + /home/seanomik/Development/java/spigot-dev/test-servers/${server.version}/plugins/TamableFoxes_v${project.parent.version}.jar + false diff --git a/Plugin/src/main/java/net/seanomik/tamablefoxes/CommandGiveFox.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/CommandGiveFox.java index 60c1d90..115f23c 100644 --- a/Plugin/src/main/java/net/seanomik/tamablefoxes/CommandGiveFox.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/CommandGiveFox.java @@ -71,6 +71,14 @@ public class CommandGiveFox implements TabExecutor { if (plugin.nmsInterface.getFoxOwner(fox).equals(player.getUniqueId()) || player.hasPermission("tamablefoxes.givefox.give.others")) { plugin.nmsInterface.changeFoxOwner(fox, givingToPlayer); + + Bukkit.getScheduler().runTask(plugin, r2 -> { + // If the player that is receiving the fox is online, prompt them to rename their new fox! + if (givingToPlayer.isOnline()) { + plugin.nmsInterface.renameFox(fox, givingToPlayer); + } + }); + sender.sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getGaveFox(givingToPlayer)); } else { sender.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getNotYourFox()); diff --git a/Utility/src/main/java/net/seanomik/tamablefoxes/util/FieldHelper.java b/Utility/src/main/java/net/seanomik/tamablefoxes/util/FieldHelper.java index 23d99c6..01b1b28 100644 --- a/Utility/src/main/java/net/seanomik/tamablefoxes/util/FieldHelper.java +++ b/Utility/src/main/java/net/seanomik/tamablefoxes/util/FieldHelper.java @@ -1,11 +1,5 @@ package net.seanomik.tamablefoxes.util; -import net.seanomik.tamablefoxes.util.io.Config; -import net.seanomik.tamablefoxes.util.io.LanguageConfig; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import sun.misc.Unsafe; - import sun.misc.Unsafe; import java.lang.reflect.Field; diff --git a/Utility/src/main/java/net/seanomik/tamablefoxes/util/NMSInterface.java b/Utility/src/main/java/net/seanomik/tamablefoxes/util/NMSInterface.java index 0d40807..0a66c59 100644 --- a/Utility/src/main/java/net/seanomik/tamablefoxes/util/NMSInterface.java +++ b/Utility/src/main/java/net/seanomik/tamablefoxes/util/NMSInterface.java @@ -16,4 +16,5 @@ public interface NMSInterface { void spawnTamableFox(Location loc, FoxType type); void changeFoxOwner(Fox fox, Player newOwner); UUID getFoxOwner(Fox fox); + void renameFox(org.bukkit.entity.Fox fox, Player player); } \ No newline at end of file diff --git a/Utility/src/main/java/net/seanomik/tamablefoxes/util/io/LanguageConfig.java b/Utility/src/main/java/net/seanomik/tamablefoxes/util/io/LanguageConfig.java index 7014aef..c3a3852 100644 --- a/Utility/src/main/java/net/seanomik/tamablefoxes/util/io/LanguageConfig.java +++ b/Utility/src/main/java/net/seanomik/tamablefoxes/util/io/LanguageConfig.java @@ -158,7 +158,7 @@ public class LanguageConfig extends YamlConfiguration { if (str == null || str.isEmpty()) { str = "Right click the fox that you want to give to " + transferringTo.getDisplayName() + "."; } else { - str.replace("%TRANSFER_TO_PLAYER%", transferringTo.getDisplayName()); + str = str.replace("%TRANSFER_TO_PLAYER%", transferringTo.getDisplayName()); } return str; @@ -169,7 +169,7 @@ public class LanguageConfig extends YamlConfiguration { if (str == null || str.isEmpty()) { str = "Fox has been given to " + givingTo.getDisplayName() + "!"; } else { - str.replace("%GAVE_TO_PLAYER%", givingTo.getDisplayName()); + str = str.replace("%GAVE_TO_PLAYER%", givingTo.getDisplayName()); } return str;