Add a config option which fixes a bug where you can dye sheep/wolf client sidedly

This commit is contained in:
libraryaddict 2014-06-04 14:43:58 +12:00
parent 87c0cb4a78
commit 956fef9ca1
3 changed files with 45 additions and 1 deletions

View File

@ -28,6 +28,12 @@ RemoveHeldItem: false
# Set this to true if you want the disguise to get the animations of the disguised entity. Such as invisible, on fire, sprinting, sneaking, blocking # Set this to true if you want the disguise to get the animations of the disguised entity. Such as invisible, on fire, sprinting, sneaking, blocking
# This is only valid if you set a animation on the disguise itself. Because the entitys animations are applied otherwise. # This is only valid if you set a animation on the disguise itself. Because the entitys animations are applied otherwise.
AddEntityAnimations: true AddEntityAnimations: true
# When a sheep or wolf is right clicked with dye. The client automatically assumes it was successful and displays the sheeps wool or the wolfs collar as dyed.
# This is a option that either prevents that happening, or it changes their color officially in the plugin so that everyone sees it changed.
# Its currently set to false which means that the color is not changed and will refresh itself to the player.
# 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
# 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.
# Such as prophunt. Its also false because its kind of a retarded feature. # Such as prophunt. Its also false because its kind of a retarded feature.

View File

@ -9,6 +9,8 @@ public class DisguiseConfig {
private static boolean bedEnabled; private static boolean bedEnabled;
private static boolean blowDisguisesOnAttack; private static boolean blowDisguisesOnAttack;
private static boolean collectEnabled; private static boolean collectEnabled;
private static boolean colorizeSheep;
private static boolean colorizeWolf;
private static String disguiseBlownMessage; private static String disguiseBlownMessage;
private static int disguiseCloneExpire; private static int disguiseCloneExpire;
private static int disguiseEntityExpire; private static int disguiseEntityExpire;
@ -81,6 +83,8 @@ public class DisguiseConfig {
setDisguiseEntityExpire(config.getInt("DisguiseEntityExpire")); setDisguiseEntityExpire(config.getInt("DisguiseEntityExpire"));
setDisguiseCloneExpire(config.getInt("DisguiseCloneExpire")); setDisguiseCloneExpire(config.getInt("DisguiseCloneExpire"));
setMaxClonedDisguises(config.getInt("DisguiseCloneSize")); setMaxClonedDisguises(config.getInt("DisguiseCloneSize"));
setSheepDyeable(config.getBoolean("DyeableSheep"));
setWolfDyeable(config.getBoolean("DyeableWolf"));
} }
public static boolean isAnimationPacketsEnabled() { public static boolean isAnimationPacketsEnabled() {
@ -177,6 +181,10 @@ public class DisguiseConfig {
return hearSelfDisguise; return hearSelfDisguise;
} }
public static boolean isSheepDyeable() {
return colorizeSheep;
}
/** /**
* Is the sound packets caught and modified * Is the sound packets caught and modified
*/ */
@ -202,6 +210,10 @@ public class DisguiseConfig {
return witherSkullEnabled; return witherSkullEnabled;
} }
public static boolean isWolfDyeable() {
return colorizeWolf;
}
public static void setAddEntityAnimations(boolean isEntityAnimationsAdded) { public static void setAddEntityAnimations(boolean isEntityAnimationsAdded) {
entityAnimationsAdded = isEntityAnimationsAdded; entityAnimationsAdded = isEntityAnimationsAdded;
} }
@ -347,6 +359,10 @@ public class DisguiseConfig {
} }
} }
public static void setSheepDyeable(boolean color) {
colorizeSheep = color;
}
/** /**
* Set if the disguises play sounds when hurt * Set if the disguises play sounds when hurt
*/ */
@ -369,6 +385,10 @@ public class DisguiseConfig {
witherSkullEnabled = enabled; witherSkullEnabled = enabled;
} }
public static void setWolfDyeable(boolean color) {
colorizeWolf = color;
}
private DisguiseConfig() { private DisguiseConfig() {
} }
} }

View File

@ -8,6 +8,7 @@ import java.util.Random;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
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.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
@ -16,6 +17,8 @@ import me.libraryaddict.disguise.disguisetypes.MobDisguise;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher;
import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType; import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType;
import me.libraryaddict.disguise.utilities.ReflectionManager.LibVersion; import me.libraryaddict.disguise.utilities.ReflectionManager.LibVersion;
@ -75,11 +78,26 @@ public class PacketsManager {
try { try {
Player observer = event.getPlayer(); Player observer = event.getPlayer();
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld()); StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
org.bukkit.entity.Entity entity = entityModifer.read(LibVersion.is1_7() ? 0 : 1); Entity entity = entityModifer.read(LibVersion.is1_7() ? 0 : 1);
if (entity instanceof ExperienceOrb || entity instanceof Item || entity instanceof Arrow if (entity instanceof ExperienceOrb || entity instanceof Item || entity instanceof Arrow
|| entity == observer) { || entity == observer) {
event.setCancelled(true); event.setCancelled(true);
} }
ItemStack item = observer.getItemInHand();
if (item != null && item.getType() == Material.INK_SACK) {
Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
if (disguise != null
&& (disguise.getType() == DisguiseType.SHEEP || disguise.getType() == DisguiseType.WOLF)) {
AnimalColor color = AnimalColor.getColor(item.getDurability());
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());
}
}
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }