Client listener to sync again, run in scheduler. Add cat color config option

This commit is contained in:
libraryaddict 2019-11-14 14:42:32 +13:00
parent fff4ca8590
commit 8015db68f6
4 changed files with 50 additions and 25 deletions

View File

@ -38,6 +38,7 @@ public class DisguiseConfig {
private static boolean collectEnabled; private static boolean collectEnabled;
private static boolean colorizeSheep; private static boolean colorizeSheep;
private static boolean colorizeWolf; private static boolean colorizeWolf;
private static boolean colorizeCat;
private static HashMap<DisguisePerm, String> customDisguises = new HashMap<>(); private static HashMap<DisguisePerm, String> customDisguises = new HashMap<>();
private static boolean disableInvisibility; private static boolean disableInvisibility;
private static int disguiseCloneExpire; private static int disguiseCloneExpire;
@ -315,6 +316,7 @@ public class DisguiseConfig {
setMaxClonedDisguises(config.getInt("DisguiseCloneSize")); setMaxClonedDisguises(config.getInt("DisguiseCloneSize"));
setSheepDyeable(config.getBoolean("DyeableSheep")); setSheepDyeable(config.getBoolean("DyeableSheep"));
setWolfDyeable(config.getBoolean("DyeableWolf")); setWolfDyeable(config.getBoolean("DyeableWolf"));
setCatDyeable(config.getBoolean("DyeableCat"));
setUndisguiseOnWorldChange(config.getBoolean("UndisguiseOnWorldChange")); setUndisguiseOnWorldChange(config.getBoolean("UndisguiseOnWorldChange"));
setUpdateNotificationPermission(config.getString("Permission")); setUpdateNotificationPermission(config.getString("Permission"));
setStopShulkerDisguisesFromMoving(config.getBoolean("StopShulkerDisguisesFromMoving", true)); setStopShulkerDisguisesFromMoving(config.getBoolean("StopShulkerDisguisesFromMoving", true));
@ -770,6 +772,14 @@ public class DisguiseConfig {
colorizeWolf = color; colorizeWolf = color;
} }
public static void setCatDyeable(boolean color) {
colorizeCat = color;
}
public static boolean isCatDyeable() {
return colorizeCat;
}
private DisguiseConfig() { private DisguiseConfig() {
} }
} }

View File

@ -35,8 +35,7 @@ public class PacketsManager {
clientInteractEntityListener = new PacketListenerClientInteract(libsDisguises); clientInteractEntityListener = new PacketListenerClientInteract(libsDisguises);
PacketListener tabListListener = new PacketListenerTabList(libsDisguises); PacketListener tabListListener = new PacketListenerTabList(libsDisguises);
ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(clientInteractEntityListener) ProtocolLibrary.getProtocolManager().addPacketListener(clientInteractEntityListener);
.syncStart();
ProtocolLibrary.getProtocolManager().addPacketListener(tabListListener); ProtocolLibrary.getProtocolManager().addPacketListener(tabListListener);
// Now I call this and the main listener is registered! // Now I call this and the main listener is registered!

View File

@ -14,6 +14,8 @@ import me.libraryaddict.disguise.disguisetypes.AnimalColor;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise; 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.SheepWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher;
import me.libraryaddict.disguise.events.DisguiseInteractEvent; import me.libraryaddict.disguise.events.DisguiseInteractEvent;
@ -84,32 +86,45 @@ public class PacketListenerClientInteract extends PacketAdapter {
} }
} }
if (disguise.getType() != DisguiseType.SHEEP && disguise.getType() != DisguiseType.WOLF) { if (disguise.getType() != DisguiseType.SHEEP && disguise.getType() != DisguiseType.WOLF &&
disguise.getType() != DisguiseType.CAT) {
return; return;
} }
// If this is something the player can dye the disguise with new BukkitRunnable() {
for (ItemStack item : new ItemStack[]{observer.getInventory().getItemInMainHand(), @Override
observer.getInventory().getItemInOffHand()}) { public void run() {
if (item == null) { // If this is something the player can dye the disguise with
continue; for (ItemStack item : new ItemStack[]{observer.getInventory().getItemInMainHand(),
observer.getInventory().getItemInOffHand()}) {
if (item == null) {
continue;
}
AnimalColor color = AnimalColor.getColorByMaterial(item.getType());
if (color == null) {
continue;
}
if (disguise.getType() == DisguiseType.SHEEP) {
SheepWatcher watcher = (SheepWatcher) disguise.getWatcher();
watcher.setColor(DisguiseConfig.isSheepDyeable() ? color : watcher.getColor());
break;
} else if (disguise.getType() == DisguiseType.WOLF) {
WolfWatcher watcher = (WolfWatcher) disguise.getWatcher();
watcher.setCollarColor(DisguiseConfig.isWolfDyeable() ? color : watcher.getCollarColor());
break;
} else if (disguise.getType() == DisguiseType.CAT) {
CatWatcher watcher = (CatWatcher) disguise.getWatcher();
watcher.setCollarColor(DisguiseConfig.isCatDyeable() ? color : watcher.getCollarColor());
break;
}
}
} }
}.runTask(LibsDisguises.getInstance());
AnimalColor color = AnimalColor.getColorByMaterial(item.getType());
if (color == null) {
continue;
}
if (disguise.getType() == DisguiseType.SHEEP) {
SheepWatcher watcher = (SheepWatcher) disguise.getWatcher();
watcher.setColor(DisguiseConfig.isSheepDyeable() ? color : watcher.getColor());
} else {
WolfWatcher watcher = (WolfWatcher) disguise.getWatcher();
watcher.setCollarColor(DisguiseConfig.isWolfDyeable() ? color : watcher.getCollarColor());
}
}
} }
} }

View File

@ -119,6 +119,7 @@ AddEntityAnimations: true
# Please note that this will not remove the dye from their hands. This also does not check if the disguised entity is actually a sheep/wolf and wants a say in its color. # Please note that this will not remove the dye from their hands. This also does not check if the disguised entity is actually a sheep/wolf and wants a say in its color.
DyeableSheep: false DyeableSheep: false
DyeableWolf: false DyeableWolf: false
DyeableCat: false
# This is only called into action when the disguise is constructed using the commands. # 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. # And when the disguise supports that. This will not be used at all for plugins constructing the disguises for instance.