diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java index f679aad1..d5fd46b5 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java @@ -39,6 +39,8 @@ public class DisguiseConfig { private static boolean colorizeSheep; private static boolean colorizeWolf; private static boolean colorizeCat; + private static boolean saddleableHorse; + private static boolean carpetableLlama; private static HashMap customDisguises = new HashMap<>(); private static boolean disableInvisibility; private static int disguiseCloneExpire; @@ -317,6 +319,8 @@ public class DisguiseConfig { setSheepDyeable(config.getBoolean("DyeableSheep")); setWolfDyeable(config.getBoolean("DyeableWolf")); setCatDyeable(config.getBoolean("DyeableCat")); + setHorseSaddleable(config.getBoolean("SaddleableHorse")); + setLlamaCarpetable(config.getBoolean("CarpetableLlama")); setUndisguiseOnWorldChange(config.getBoolean("UndisguiseOnWorldChange")); setUpdateNotificationPermission(config.getString("Permission")); setStopShulkerDisguisesFromMoving(config.getBoolean("StopShulkerDisguisesFromMoving", true)); @@ -780,6 +784,22 @@ public class DisguiseConfig { return colorizeCat; } + public static void setHorseSaddleable(boolean saddle) { + saddleableHorse = saddle; + } + + public static boolean isHorseSaddleable() { + return saddleableHorse; + } + + public static void setLlamaCarpetable(boolean carpet) { + carpetableLlama = carpet; + } + + public static boolean isLlamaCarpetable() { + return carpetableLlama; + } + private DisguiseConfig() { } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java index b4669475..454c2458 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java @@ -33,6 +33,24 @@ public enum AnimalColor { return null; } + public static AnimalColor getColorByWool(Material carpet) { + if (carpet == null || (!carpet.name().endsWith("_WOOL") && !carpet.name().endsWith("_CARPET"))) { + return null; + } + + String name = carpet.name().replace("_CARPET", "").replace("_WOOL", ""); + + for (AnimalColor color : AnimalColor.values()) { + if (!color.name().equals(name)) { + continue; + } + + return color; + } + + return null; + } + public static AnimalColor getColorByMaterial(Material material) { for (AnimalColor color : values()) { if (color.getDyeMaterial() != material) { diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerClientInteract.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerClientInteract.java index 08a2aaad..fd2c45b6 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerClientInteract.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerClientInteract.java @@ -14,16 +14,15 @@ import me.libraryaddict.disguise.disguisetypes.AnimalColor; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.TargetedDisguise; -import me.libraryaddict.disguise.disguisetypes.watchers.CatWatcher; -import me.libraryaddict.disguise.disguisetypes.watchers.OcelotWatcher; -import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher; -import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher; +import me.libraryaddict.disguise.disguisetypes.watchers.*; import me.libraryaddict.disguise.events.DisguiseInteractEvent; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.*; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; +import org.bukkit.material.Wool; import org.bukkit.scheduler.BukkitRunnable; public class PacketListenerClientInteract extends PacketAdapter { @@ -86,11 +85,84 @@ public class PacketListenerClientInteract extends PacketAdapter { } } - if (disguise.getType() != DisguiseType.SHEEP && disguise.getType() != DisguiseType.WOLF && - disguise.getType() != DisguiseType.CAT) { - return; - } + switch (disguise.getType()) { + case CAT: + case WOLF: + case SHEEP: + doDyeable(observer, disguise); + break; + case MULE: + case DONKEY: + case HORSE: + case ZOMBIE_HORSE: + case SKELETON_HORSE: + if (DisguiseConfig.isHorseSaddleable()) { + doSaddleable(observer, disguise); + } + break; + case LLAMA: + case TRADER_LLAMA: + if (DisguiseConfig.isLlamaCarpetable()) { + doCarpetable(observer, disguise); + } + + break; + default: + break; + } + } + + private void doSaddleable(Player observer, Disguise disguise) { + new BukkitRunnable() { + @Override + public void run() { + // If this is something the player can dye the disguise with + for (ItemStack item : new ItemStack[]{observer.getInventory().getItemInMainHand(), + observer.getInventory().getItemInOffHand()}) { + + if (item == null || item.getType() != Material.SADDLE) { + continue; + } + + AbstractHorseWatcher watcher = (TraderLlamaWatcher) disguise.getWatcher(); + + watcher.setSaddled(true); + break; + } + } + }.runTask(LibsDisguises.getInstance()); + } + + private void doCarpetable(Player observer, Disguise disguise) { + + new BukkitRunnable() { + @Override + public void run() { + // If this is something the player can dye the disguise with + for (ItemStack item : new ItemStack[]{observer.getInventory().getItemInMainHand(), + observer.getInventory().getItemInOffHand()}) { + if (item == null || !item.getType().name().endsWith("_CARPET")) { + continue; + } + + AnimalColor color = AnimalColor.getColorByWool(item.getType()); + + if (color == null) { + continue; + } + + LlamaWatcher llamaWatcher = (LlamaWatcher) disguise.getWatcher(); + + llamaWatcher.setSaddled(true); + llamaWatcher.setCarpet(color); + break; + } + } + }.runTask(LibsDisguises.getInstance()); + } + + private void doDyeable(Player observer, Disguise disguise) { new BukkitRunnable() { @Override public void run() { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e87c6e96..eb772bb2 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -120,6 +120,11 @@ AddEntityAnimations: true DyeableSheep: false DyeableWolf: false DyeableCat: false +# Can a player interact with a llama with carpet to set or change their carpet color? +CarpetableLlama: false +# Can a player interact with a non-saddled horse of any type, to give it a saddle? +# This does not change what you can ride or control! +SaddleableHorse: false # This is only called into action when the disguise is constructed using the commands. # And when the disguise supports that. This will not be used at all for plugins constructing the disguises for instance.