Initial work for custom disguises

This commit is contained in:
libraryaddict 2020-04-13 21:14:04 +12:00
parent 80cf5cef27
commit 3c40a27c8f
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
8 changed files with 74 additions and 14 deletions

View File

@ -45,7 +45,8 @@ public class GrabSkinCommand implements CommandExecutor {
}
String[] args = DisguiseUtilities.split(StringUtils.join(strings, " "));
String tName = args.length > 1 ? args[1] : null;
String tName = args.length > 1 ? args[0] : null;
String skin = args.length > 1 ? args[1] : args[0];
String usable = SkinUtils.getUsableStatus();
@ -54,8 +55,8 @@ public class GrabSkinCommand implements CommandExecutor {
return true;
}
if (tName == null && args[0].matches("(.*\\/)?[a-zA-Z0-9_-]{3,20}\\.png")) {
tName = args[0].substring(args[0].lastIndexOf("/") + 1, args[0].lastIndexOf("."));
if (tName == null && skin.matches("(.*\\/)?[a-zA-Z0-9_-]{3,20}\\.png")) {
tName = skin.substring(skin.lastIndexOf("/") + 1, skin.lastIndexOf("."));
if (DisguiseUtilities.hasGameProfile(tName)) {
tName = null;
@ -146,7 +147,7 @@ public class GrabSkinCommand implements CommandExecutor {
}
};
SkinUtils.grabSkin(args[0], callback);
SkinUtils.grabSkin(skin, callback);
return true;
}

View File

@ -35,6 +35,8 @@ public enum DisguiseType {
CREEPER,
CUSTOM,
DOLPHIN,
DONKEY,
@ -261,7 +263,11 @@ public enum DisguiseType {
}
try {
setEntityType(EntityType.valueOf(name()));
if (name().equalsIgnoreCase("CUSTOM")) {
setEntityType(EntityType.UNKNOWN);
} else {
setEntityType(EntityType.valueOf(name()));
}
}
catch (Exception ex) {
}

View File

@ -9,6 +9,8 @@ import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import com.google.common.base.Strings;
import lombok.AccessLevel;
import lombok.Getter;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
@ -33,8 +35,13 @@ public class FlagWatcher {
/**
* These are the entity values I need to add else it could crash them..
*/
@Getter(value = AccessLevel.PROTECTED)
private HashMap<Integer, Object> backupEntityValues = new HashMap<>();
private transient TargetedDisguise disguise;
/**
* Disguise set data
*/
@Getter(value = AccessLevel.PROTECTED)
private HashMap<Integer, Object> entityValues = new HashMap<>();
private LibsEquipment equipment;
private boolean hasDied;

View File

@ -1,9 +1,6 @@
package me.libraryaddict.disguise.disguisetypes;
import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.PaintingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.*;
import org.bukkit.Art;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
@ -147,6 +144,8 @@ public class MiscDisguise extends TargetedDisguise {
public int getId() {
if (getType() == DisguiseType.FALLING_BLOCK) {
return ((FallingBlockWatcher) getWatcher()).getBlock().getType().ordinal();
} else if (getType() == DisguiseType.CUSTOM) {
return ((CustomWatcher) getWatcher()).getTypeId();
}
return id;

View File

@ -0,0 +1,39 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import lombok.Getter;
import lombok.Setter;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
/**
* Created by libraryaddict on 13/04/2020.
*/
public class CustomWatcher extends FlagWatcher {
@Getter
private DisguiseType inherits;
@Getter
@Setter
private int typeId;
public CustomWatcher(Disguise disguise) {
super(disguise);
}
public void setInherits(DisguiseType toClone) {
this.inherits = toClone;
}
/**
* @param index
* @param object
*/
public void setMetadata(int index, Object object) {
getEntityValues().put(index, object);
}
public Object getMetadata(int index) {
return getEntityValues().get(index);
}
}

View File

@ -9,6 +9,7 @@ import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.disguisetypes.watchers.CustomWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
@ -221,7 +222,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
} else {
spawnPlayer.getDataWatcherModifier().write(0, newWatcher);
}
} else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) {
} else if (disguise.isMobDisguise() || disguise.getType() == DisguiseType.ARMOR_STAND) {
Vector vec = disguisedEntity.getVelocity();
PacketContainer spawnEntity = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY_LIVING);
@ -231,7 +232,12 @@ public class PacketHandlerSpawn implements IPacketHandler {
mods.write(0, disguisedEntity.getEntityId());
mods.write(1, disguisedEntity.getUniqueId());
mods.write(2, disguise.getType().getTypeId());
if (disguise.getType() != DisguiseType.CUSTOM) {
mods.write(2, disguise.getType().getTypeId());
} else {
mods.write(2, ((CustomWatcher) disguise.getWatcher()).getTypeId());
}
// region Vector calculations
double d1 = 3.9D;

View File

@ -231,9 +231,9 @@ public enum LibsMsg {
GRAB_DISG_HELP_1(ChatColor.GREEN +
"You can choose a name to save the skins under, the names will be usable as if it was an actual player " +
"skin"),
GRAB_DISG_HELP_2(ChatColor.DARK_GREEN + "/grabskin https://somesite.com/myskin.png <Optional Name>"),
GRAB_DISG_HELP_3(ChatColor.DARK_GREEN + "/grabskin myskin.png <Optional Name> - Skins must be in the folder!"),
GRAB_DISG_HELP_4(ChatColor.DARK_GREEN + "/grabskin <Player name or UUID> <Optional Name>"),
GRAB_DISG_HELP_2(ChatColor.DARK_GREEN + "/grabskin <Optional Name> https://somesite.com/myskin.png"),
GRAB_DISG_HELP_3(ChatColor.DARK_GREEN + "/grabskin <Optional Name> myskin.png - Skins must be in the folder!"),
GRAB_DISG_HELP_4(ChatColor.DARK_GREEN + "/grabskin <Optional Name> <Player name or UUID>"),
GRAB_DISG_HELP_5(ChatColor.GREEN + "If you want the slim Alex version of the skin, append :slim. So 'myskin.png:slim'"),
GRAB_DISG_HELP_6(
ChatColor.GREEN + "You will be sent the skin data, but you can also use the saved names in disguises"),

View File

@ -14,6 +14,8 @@ public class DisguiseTypesTest {
for (EntityType entityType : EntityType.values()) {
if (entityType == EntityType.LIGHTNING) {
continue;
} else if (entityType == EntityType.UNKNOWN) {
continue;
}
DisguiseType disguiseType = DisguiseType.getType(entityType);