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

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

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

@ -14,6 +14,8 @@ 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.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;
}
// 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) {
continue;
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) {
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;
}
}
}
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());
}
}
}.runTask(LibsDisguises.getInstance());
}
}

@ -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.
DyeableSheep: false
DyeableWolf: false
DyeableCat: 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.