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 d39a982..edb621b 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 @@ -10,8 +10,11 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity; +import org.bukkit.entity.Fox; +import org.bukkit.entity.Player; import java.lang.reflect.Field; +import java.util.UUID; public class NMSInterface_1_14_R1 implements NMSInterface { @Override @@ -32,15 +35,15 @@ public class NMSInterface_1_14_R1 implements NMSInterface { tamableFox.setFoxType((type == FoxType.RED) ? EntityFox.Type.RED : EntityFox.Type.SNOW); } - static class ClassDefiner extends ClassLoader { - public ClassDefiner(ClassLoader parent) { - super(parent); - } + @Override + public void changeFoxOwner(Fox fox, Player newOwner) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + tamableFox.setOwnerUUID(newOwner.getUniqueId()); + } - public Class get(String name, byte[] bytes) { - Class c = defineClass(name, bytes, 0, bytes.length); - resolveClass(c); - return c; - } + @Override + public UUID getFoxOwner(Fox fox) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + return tamableFox.getOwnerUUID(); } } 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 fff742e..5e86733 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 @@ -10,8 +10,11 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; +import org.bukkit.entity.Fox; +import org.bukkit.entity.Player; import java.lang.reflect.Field; +import java.util.UUID; public class NMSInterface_1_15_R1 implements NMSInterface { @Override @@ -32,15 +35,15 @@ public class NMSInterface_1_15_R1 implements NMSInterface { tamableFox.setFoxType((type == FoxType.RED) ? EntityFox.Type.RED : EntityFox.Type.SNOW); } - static class ClassDefiner extends ClassLoader { - public ClassDefiner(ClassLoader parent) { - super(parent); - } + @Override + public void changeFoxOwner(Fox fox, Player newOwner) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + tamableFox.setOwnerUUID(newOwner.getUniqueId()); + } - public Class get(String name, byte[] bytes) { - Class c = defineClass(name, bytes, 0, bytes.length); - resolveClass(c); - return c; - } + @Override + public UUID getFoxOwner(Fox fox) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + return tamableFox.getOwnerUUID(); } } 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 ed55032..5d95c9c 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 @@ -10,8 +10,11 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity; +import org.bukkit.entity.Fox; +import org.bukkit.entity.Player; import java.lang.reflect.Field; +import java.util.UUID; public class NMSInterface_1_16_R1 implements NMSInterface { @Override @@ -32,15 +35,15 @@ public class NMSInterface_1_16_R1 implements NMSInterface { tamableFox.setFoxType((type == FoxType.RED) ? EntityFox.Type.RED : EntityFox.Type.SNOW); } - static class ClassDefiner extends ClassLoader { - public ClassDefiner(ClassLoader parent) { - super(parent); - } + @Override + public void changeFoxOwner(Fox fox, Player newOwner) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + tamableFox.setOwnerUUID(newOwner.getUniqueId()); + } - public Class get(String name, byte[] bytes) { - Class c = defineClass(name, bytes, 0, bytes.length); - resolveClass(c); - return c; - } + @Override + public UUID getFoxOwner(Fox fox) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + return tamableFox.getOwnerUUID(); } } 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 2e51f28..a16ed7a 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 @@ -10,8 +10,11 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity; +import org.bukkit.entity.Fox; +import org.bukkit.entity.Player; import java.lang.reflect.Field; +import java.util.UUID; public class NMSInterface_1_16_R2 implements NMSInterface { @Override @@ -32,15 +35,15 @@ public class NMSInterface_1_16_R2 implements NMSInterface { tamableFox.setFoxType((type == FoxType.RED) ? EntityFox.Type.RED : EntityFox.Type.SNOW); } - static class ClassDefiner extends ClassLoader { - public ClassDefiner(ClassLoader parent) { - super(parent); - } + @Override + public void changeFoxOwner(Fox fox, Player newOwner) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + tamableFox.setOwnerUUID(newOwner.getUniqueId()); + } - public Class get(String name, byte[] bytes) { - Class c = defineClass(name, bytes, 0, bytes.length); - resolveClass(c); - return c; - } + @Override + public UUID getFoxOwner(Fox fox) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + return tamableFox.getOwnerUUID(); } } 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 cf3d99a..21d9133 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 @@ -10,8 +10,11 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity; +import org.bukkit.entity.Fox; +import org.bukkit.entity.Player; import java.lang.reflect.Field; +import java.util.UUID; public class NMSInterface_1_16_R3 implements NMSInterface { @Override @@ -32,15 +35,15 @@ public class NMSInterface_1_16_R3 implements NMSInterface { tamableFox.setFoxType((type == FoxType.RED) ? EntityFox.Type.RED : EntityFox.Type.SNOW); } - static class ClassDefiner extends ClassLoader { - public ClassDefiner(ClassLoader parent) { - super(parent); - } + @Override + public void changeFoxOwner(Fox fox, Player newOwner) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + tamableFox.setOwnerUUID(newOwner.getUniqueId()); + } - public Class get(String name, byte[] bytes) { - Class c = defineClass(name, bytes, 0, bytes.length); - resolveClass(c); - return c; - } + @Override + public UUID getFoxOwner(Fox fox) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + return tamableFox.getOwnerUUID(); } } 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 05f7542..9335d56 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 @@ -10,8 +10,10 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity; +import org.bukkit.entity.Player; import java.lang.reflect.Field; +import java.util.UUID; public class NMSInterface_1_17_1_R1 implements NMSInterface { @Override @@ -32,15 +34,15 @@ public class NMSInterface_1_17_1_R1 implements NMSInterface { tamableFox.setFoxType((type == FoxType.RED) ? Fox.Type.RED : Fox.Type.SNOW); } - static class ClassDefiner extends ClassLoader { - public ClassDefiner(ClassLoader parent) { - super(parent); - } + @Override + public void changeFoxOwner(org.bukkit.entity.Fox fox, Player newOwner) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + tamableFox.setOwnerUUID(newOwner.getUniqueId()); + } - public Class get(String name, byte[] bytes) { - Class c = defineClass(name, bytes, 0, bytes.length); - resolveClass(c); - return c; - } + @Override + public UUID getFoxOwner(org.bukkit.entity.Fox fox) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + return tamableFox.getOwnerUUID(); } } 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 651a892..1745e69 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 @@ -10,8 +10,10 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity; +import org.bukkit.entity.Player; import java.lang.reflect.Field; +import java.util.UUID; public class NMSInterface_1_17_R1 implements NMSInterface { @Override @@ -32,15 +34,15 @@ public class NMSInterface_1_17_R1 implements NMSInterface { tamableFox.setFoxType((type == FoxType.RED) ? Fox.Type.RED : Fox.Type.SNOW); } - static class ClassDefiner extends ClassLoader { - public ClassDefiner(ClassLoader parent) { - super(parent); - } + @Override + public void changeFoxOwner(org.bukkit.entity.Fox fox, Player newOwner) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + tamableFox.setOwnerUUID(newOwner.getUniqueId()); + } - public Class get(String name, byte[] bytes) { - Class c = defineClass(name, bytes, 0, bytes.length); - resolveClass(c); - return c; - } + @Override + public UUID getFoxOwner(org.bukkit.entity.Fox fox) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + return tamableFox.getOwnerUUID(); } } 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 dec6e3e..dc6eb34 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 @@ -10,8 +10,10 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity; +import org.bukkit.entity.Player; import java.lang.reflect.Field; +import java.util.UUID; public class NMSInterface_1_18_R1 implements NMSInterface { @Override @@ -32,15 +34,15 @@ public class NMSInterface_1_18_R1 implements NMSInterface { tamableFox.setFoxType((type == FoxType.RED) ? Fox.Type.RED : Fox.Type.SNOW); } - static class ClassDefiner extends ClassLoader { - public ClassDefiner(ClassLoader parent) { - super(parent); - } + @Override + public void changeFoxOwner(org.bukkit.entity.Fox fox, Player newOwner) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + tamableFox.setOwnerUUID(newOwner.getUniqueId()); + } - public Class get(String name, byte[] bytes) { - Class c = defineClass(name, bytes, 0, bytes.length); - resolveClass(c); - return c; - } + @Override + public UUID getFoxOwner(org.bukkit.entity.Fox fox) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) fox).getHandle(); + return tamableFox.getOwnerUUID(); } } diff --git a/Plugin/src/main/java/net/seanomik/tamablefoxes/CommandGiveFox.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/CommandGiveFox.java new file mode 100644 index 0000000..60c1d90 --- /dev/null +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/CommandGiveFox.java @@ -0,0 +1,92 @@ +package net.seanomik.tamablefoxes; + +import net.seanomik.tamablefoxes.util.io.Config; +import net.seanomik.tamablefoxes.util.io.LanguageConfig; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Fox; +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +public class CommandGiveFox implements TabExecutor { + + private final TamableFoxes plugin; + private final PlayerInteractEntityEventListener playerInteractListener; + + public CommandGiveFox(TamableFoxes plugin, PlayerInteractEntityEventListener playerInteractListener) { + this.plugin = plugin; + this.playerInteractListener = playerInteractListener; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getOnlyRunPlayer()); + return true; + } + + if (args.length != 1) { + sender.sendMessage(Config.getPrefix() + "You didn't supply a player name!"); + sender.sendMessage(Config.getPrefix() + "Usage: /givefox [player name]"); + return true; + } + + if (!sender.hasPermission("tamablefoxes.givefox.give")) { + sender.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getNoPermMessage()); + return true; + } + + Player player = (Player) sender; + Player givingToPlayer = plugin.getServer().getPlayer(args[0]); + + if (givingToPlayer == null) { + sender.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getPlayerDoesNotExist()); + return true; + } + + if (!givingToPlayer.hasPermission("tamablefoxes.givefox.receive") && + !player.hasPermission("tamablefoxes.givefox.give.others")) { + sender.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getGiveFoxOtherNoPermMessage()); + return true; + } + + sender.sendMessage(Config.getPrefix() + ChatColor.WHITE + LanguageConfig.getInteractWithTransferringFox(givingToPlayer)); + + Bukkit.getScheduler().runTaskAsynchronously(plugin, r -> { + PlayerInteractEntityEventListener.SynchronizeFoxObject syncObject = new PlayerInteractEntityEventListener.SynchronizeFoxObject(); + playerInteractListener.players.put(player.getUniqueId(), syncObject); + + synchronized(syncObject) { + try { + syncObject.wait(5000); + playerInteractListener.players.remove(player.getUniqueId()); + + Fox fox = syncObject.interactedFox; + if (plugin.nmsInterface.getFoxOwner(fox).equals(player.getUniqueId()) || + player.hasPermission("tamablefoxes.givefox.give.others")) { + plugin.nmsInterface.changeFoxOwner(fox, givingToPlayer); + sender.sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getGaveFox(givingToPlayer)); + } else { + sender.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getNotYourFox()); + } + } catch (InterruptedException e) { + sender.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTooLongInteraction()); + } + } + }); + + return true; + } + + @Override + public List onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { + List names = plugin.getServer().getOnlinePlayers().stream().map(HumanEntity::getName).collect(Collectors.toList()); + return names; + } +} diff --git a/Plugin/src/main/java/net/seanomik/tamablefoxes/CommandTamableFoxes.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/CommandTamableFoxes.java new file mode 100644 index 0000000..ae4cad4 --- /dev/null +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/CommandTamableFoxes.java @@ -0,0 +1,61 @@ +package net.seanomik.tamablefoxes; + +import net.seanomik.tamablefoxes.util.NMSInterface; +import net.seanomik.tamablefoxes.util.io.Config; +import net.seanomik.tamablefoxes.util.io.LanguageConfig; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +public class CommandTamableFoxes implements TabExecutor { + + private final TamableFoxes plugin; + + public CommandTamableFoxes(TamableFoxes plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getOnlyRunPlayer()); + return true; + } + + if (!sender.hasPermission("tamablefoxes.reload")) { + sender.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getNoPermMessage()); + return true; + } + + Player player = (Player) sender; + if (args.length != 0) { + switch (args[0]) { + case "reload": + plugin.reloadConfig(); + Config.reloadConfig(plugin); + LanguageConfig.getConfig(plugin).reloadConfig(); + player.sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getReloadMessage()); + break; + default: + player.sendMessage(ChatColor.RED + "/tamablefox " + ChatColor.GRAY + "[red | snow | reload]"); + } + } else { + player.sendMessage(ChatColor.RED + "/tamablefox " + ChatColor.GRAY + "[red | snow | reload]"); + } + + return true; + } + + @Override + public List onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { + return new LinkedList<>(Arrays.asList( + "reload" + )); + } +} diff --git a/Plugin/src/main/java/net/seanomik/tamablefoxes/PlayerInteractEntityEventListener.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/PlayerInteractEntityEventListener.java new file mode 100644 index 0000000..bbf6c47 --- /dev/null +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/PlayerInteractEntityEventListener.java @@ -0,0 +1,43 @@ +package net.seanomik.tamablefoxes; + +import org.bukkit.entity.Fox; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEntityEvent; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class PlayerInteractEntityEventListener implements Listener { + public static class SynchronizeFoxObject { + Fox interactedFox; + + SynchronizeFoxObject() { + interactedFox = null; + } + + SynchronizeFoxObject(Fox fox) { + this.interactedFox = fox; + } + } + + TamableFoxes plugin; + Map players; + + PlayerInteractEntityEventListener(TamableFoxes plugin) { + this.plugin = plugin; + players = new HashMap<>(); + } + + @EventHandler + public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) { + if (players.containsKey(event.getPlayer().getUniqueId()) && event.getRightClicked() instanceof Fox) { + SynchronizeFoxObject syncObject = players.get(event.getPlayer().getUniqueId()); + synchronized (syncObject) { + syncObject.interactedFox = (Fox) event.getRightClicked(); + syncObject.notify(); + } + } + } +} diff --git a/Plugin/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java index 5935ca2..92c8c8a 100644 --- a/Plugin/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java @@ -29,6 +29,7 @@ public final class TamableFoxes extends JavaPlugin implements Listener { private boolean versionSupported = true; public NMSInterface nmsInterface; + private PlayerInteractEntityEventListener playerInteractEntityEventListener; private boolean equalOrBetween(double num, double min, double max) { return num >= min && num <= max; @@ -90,8 +91,12 @@ public final class TamableFoxes extends JavaPlugin implements Listener { return; } + playerInteractEntityEventListener = new PlayerInteractEntityEventListener(this); getServer().getPluginManager().registerEvents(this, this); + getServer().getPluginManager().registerEvents(playerInteractEntityEventListener, this); this.getCommand("spawntamablefox").setExecutor(new CommandSpawnTamableFox(this)); + this.getCommand("tamablefoxes").setExecutor(new CommandTamableFoxes(this)); + this.getCommand("givefox").setExecutor(new CommandGiveFox(this, playerInteractEntityEventListener)); this.saveDefaultConfig(); getConfig().options().copyDefaults(true); diff --git a/Plugin/src/main/resources/language.yml b/Plugin/src/main/resources/language.yml index b99a656..a2260bb 100644 --- a/Plugin/src/main/resources/language.yml +++ b/Plugin/src/main/resources/language.yml @@ -12,6 +12,13 @@ fox-name-format: "%FOX_NAME% (%OWNER%'s Fox)" fox-name-no-owner-name-format: "%FOX_NAME%" fox-doesnt-trust: "The fox doesn't trust you! You have too many foxes!" +givefox-other-player-no-permission: "The other player you're trying to fix the fox to is unable to receive it!" +givefox-interact-with-transferring-fox: "Right click the fox that you want to give to %TRANSFER_TO_PLAYER%." +givefox-gave-fox: "Fox has been given to %GAVE_TO_PLAYER%!" +givefox-not-your-fox: "This is not your fox to give!" +givefox-interact-timeout: "You took too long to interact with a fox!" +givefox-player-does-not-exist: "The player does not exist!" + no-permission: "You do not have the permission for this command." only-run-by-player: "Command can only be run from player state!" spawned-fox-message: "Spawned a %TYPE% fox." diff --git a/Plugin/src/main/resources/plugin.yml b/Plugin/src/main/resources/plugin.yml index b53c0f5..7c8f54f 100644 --- a/Plugin/src/main/resources/plugin.yml +++ b/Plugin/src/main/resources/plugin.yml @@ -7,10 +7,29 @@ description: Adds tamable foxes to Minecraft! commands: spawntamablefox: - aliases: [tamablefox, stf, spawntf] + aliases: [ stf ] usage: /spawntamablefox [type] description: Spawn a tamable fox at the standing location. Type can be snow or red, or left empty for a red. + tamablefoxes: + aliases: [ tamablefox ] + usage: /tamablefoxes reload + description: Reload the Tamable Foxes plugin config. Restart when updating the plugin. + givefox: + usage: /givefox [player name] + description: Give a fox to another player. permissions: + tamablefoxes.givefox.give.others: + description: "Allows the player to give another players fox to a player with /givefox" + default: op + tamablefoxes.givefox.give: + description: "Gives the player the ability to give foxes to other players with /givefox" + default: true + tamablefoxes.givefox.receive: + description: "Gives the player the ability to receive foxes from other players from /givefox" + default: true + tamablefoxes.reload: + description: "Reloads the plugin config." + default: op tamablefoxes.spawn: description: "Gives the player the ability to spawn tamable foxes." default: op diff --git a/README.md b/README.md index c37690b..95a9809 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,8 @@ Have you ever wanted to tame foxes? Well, now you can! Use chicken to tameUse chicken to tame 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 9ed6191..0d40807 100644 --- a/Utility/src/main/java/net/seanomik/tamablefoxes/util/NMSInterface.java +++ b/Utility/src/main/java/net/seanomik/tamablefoxes/util/NMSInterface.java @@ -1,6 +1,10 @@ package net.seanomik.tamablefoxes.util; import org.bukkit.Location; +import org.bukkit.entity.Fox; +import org.bukkit.entity.Player; + +import java.util.UUID; public interface NMSInterface { enum FoxType { @@ -8,6 +12,8 @@ public interface NMSInterface { SNOW } - public void registerCustomFoxEntity(); - public void spawnTamableFox(Location loc, FoxType type); + void registerCustomFoxEntity(); + void spawnTamableFox(Location loc, FoxType type); + void changeFoxOwner(Fox fox, Player newOwner); + UUID getFoxOwner(Fox fox); } \ 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 8e0babf..7014aef 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 @@ -3,6 +3,7 @@ package net.seanomik.tamablefoxes.util.io; import net.seanomik.tamablefoxes.util.NMSInterface; import org.bukkit.ChatColor; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; @@ -144,6 +145,63 @@ public class LanguageConfig extends YamlConfiguration { return config.getString("no-permission"); } + public static String getGiveFoxOtherNoPermMessage() { + String str = config.getString("givefox-other-player-no-permission"); + if (str == null || str.isEmpty()) { + str = "The other player you're trying to fix the fox to is unable to receive it!"; + } + return str; + } + + public static String getInteractWithTransferringFox(Player transferringTo) { + String str = config.getString("givefox-interact-with-transferring-fox"); + 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()); + } + + return str; + } + + public static String getGaveFox(Player givingTo) { + String str = config.getString("givefox-gave-fox"); + if (str == null || str.isEmpty()) { + str = "Fox has been given to " + givingTo.getDisplayName() + "!"; + } else { + str.replace("%GAVE_TO_PLAYER%", givingTo.getDisplayName()); + } + + return str; + } + + public static String getNotYourFox() { + String str = config.getString("givefox-not-your-fox"); + if (str == null || str.isEmpty()) { + str = "This is not your fox to give!"; + } + + return str; + } + + public static String getTooLongInteraction() { + String str = config.getString("givefox-interact-timeout"); + if (str == null || str.isEmpty()) { + str = "You took too long to interact with a fox!"; + } + + return str; + } + + public static String getPlayerDoesNotExist() { + String str = config.getString("givefox-player-does-not-exist"); + if (str == null || str.isEmpty()) { + str = "The player does not exist!"; + } + + return str; + } + public static String getOnlyRunPlayer() { return config.getString("only-run-by-player"); }