Implement #66
This commit is contained in:
parent
3c599e0d6b
commit
7519b049b3
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||
List<String> names = plugin.getServer().getOnlinePlayers().stream().map(HumanEntity::getName).collect(Collectors.toList());
|
||||
return names;
|
||||
}
|
||||
}
|
|
@ -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<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||
return new LinkedList<>(Arrays.asList(
|
||||
"reload"
|
||||
));
|
||||
}
|
||||
}
|
|
@ -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<UUID, SynchronizeFoxObject> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -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
|
||||
|
|
16
README.md
16
README.md
|
@ -32,7 +32,8 @@ Have you ever wanted to tame foxes? Well, now you can! <b>Use chicken to tame</b
|
|||
* Foxes attack chickens and rabbits.
|
||||
* Snow and red foxes.
|
||||
* Language.yml
|
||||
* Message for when a tamed fox dies
|
||||
* Message when a tamed fox dies
|
||||
* /givefox command to give foxes to other players.
|
||||
* Disabling certain gameplay messages
|
||||
* You can do this by changing certain fields in `language.yml` to "disabled". The fields that can be disabled are:
|
||||
* `taming-tamed-message`
|
||||
|
@ -42,11 +43,18 @@ Have you ever wanted to tame foxes? Well, now you can! <b>Use chicken to tame</b
|
|||
|
||||
## Commands:
|
||||
* /spawntamablefox [red/snow]: Spawns a tamable fox at the players' location.
|
||||
* /tamablefoxes reload: Reloads
|
||||
* /givefox [player name]: Give a fox to another player.
|
||||
|
||||
## Permissions:
|
||||
* tamablefoxes.spawn: Gives permission to run the command /spawntamablefox. Default: `op`
|
||||
* tamablefoxes.tame: Gives the player the ability to tame a fox. Default: `Everybody`
|
||||
* tamablefoxes.tame.unlimited: Lets players bypass the tame limit. Default: `op`
|
||||
* `tamablefoxes.reload`: Reloads the plugin config. Default: `op`
|
||||
* `tamablefoxes.spawn`: Gives permission to run the command /spawntamablefox. Default: `op`
|
||||
* `tamablefoxes.tame`: Gives the player the ability to tame a fox. Default: `Everybody`
|
||||
* `tamablefoxes.tame.unlimited`: Lets players bypass the tame limit. Default: `op`
|
||||
* `tamablefoxes.tame.anywhere`: Lets players bypass the banned worlds in config.yml (so they can tame in any world). Default: `op`
|
||||
* `tamablefoxes.givefox.give.others`: Allows the player to give another players fox to a player with /givefox. This will ignore if the other receiving has the `tamablefoxes.givefox.receive` permission. Default: `op`
|
||||
* `tamablefoxes.givefox.give`: Gives the player the ability to give foxes to other players with /givefox. Default: `Everybody`
|
||||
* `tamablefoxes.givefox.receive`: Gives the player the ability to receive foxes from other players from /givefox. Default: `Everybody`
|
||||
|
||||
<br>
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue