Rename from CustomDisguise to ModdedDisguise

This commit is contained in:
libraryaddict 2020-04-19 08:19:03 +12:00
parent 2ce9b38c74
commit f10870b727
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
12 changed files with 188 additions and 189 deletions

View File

@ -6,7 +6,7 @@ import lombok.Setter;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.modded.CustomEntity;
import me.libraryaddict.disguise.utilities.modded.ModdedEntity;
import me.libraryaddict.disguise.utilities.modded.ModdedManager;
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
@ -638,7 +638,7 @@ public class DisguiseConfig {
requireMessage = ChatColor.translateAlternateColorCodes('&', requireMessage);
}
CustomEntity entity = new CustomEntity(null, name, living, mod, version, requireMessage, 0);
ModdedEntity entity = new ModdedEntity(null, name, living, mod, version, requireMessage, 0);
ModdedManager.registerCustomEntity(
new NamespacedKey(key.substring(0, key.indexOf(":")), key.substring(key.indexOf(":") + 1)),

View File

@ -12,7 +12,7 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsEntityInteract;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.UpdateChecker;
import me.libraryaddict.disguise.utilities.modded.CustomEntity;
import me.libraryaddict.disguise.utilities.modded.ModdedEntity;
import me.libraryaddict.disguise.utilities.modded.ModdedManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.math.RandomUtils;
@ -454,7 +454,7 @@ public class DisguiseListener implements Listener {
}
if (!p.hasMetadata("forge_mods")) {
Optional<CustomEntity> required = ModdedManager.getEntities().values().stream()
Optional<ModdedEntity> required = ModdedManager.getEntities().values().stream()
.filter(c -> c.getMod() != null && c.getRequired() != null).findAny();
required.ifPresent(customEntity -> p.kickPlayer(customEntity.getRequired()));
@ -470,7 +470,7 @@ public class DisguiseListener implements Listener {
}
if (!p.hasMetadata("forge_mods")) {
Optional<CustomEntity> required = ModdedManager.getEntities().values().stream()
Optional<ModdedEntity> required = ModdedManager.getEntities().values().stream()
.filter(c -> c.getMod() != null && c.getRequired() != null).findAny();
required.ifPresent(customEntity -> p.kickPlayer(customEntity.getRequired()));

View File

@ -1,154 +0,0 @@
package me.libraryaddict.disguise.disguisetypes;
import lombok.Getter;
import me.libraryaddict.disguise.disguisetypes.watchers.CustomWatcher;
import me.libraryaddict.disguise.utilities.modded.CustomEntity;
import me.libraryaddict.disguise.utilities.modded.ModdedManager;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.security.InvalidParameterException;
/**
* Created by libraryaddict on 15/04/2020.
*/
public class CustomDisguise extends TargetedDisguise {
@Getter
private CustomEntity customEntity;
public CustomDisguise(String moddedEntityName) {
this(ModdedManager.getCustomEntity(moddedEntityName));
}
public CustomDisguise(CustomEntity customEntity) {
super(customEntity.isLiving() ? DisguiseType.CUSTOM_LIVING : DisguiseType.CUSTOM_MISC);
this.customEntity = customEntity;
createDisguise();
}
public CustomDisguise(DisguiseType disguiseType) {
super(disguiseType);
if (disguiseType != DisguiseType.UNKNOWN) {
throw new InvalidParameterException(
"CustomDisguise is only for DisguiseType.CUSTOM and DisguiseType.UNKNOWN");
}
createDisguise();
}
@Override
public boolean isCustomDisguise() {
return true;
}
@Override
public boolean isMobDisguise() {
return getCustomEntity().isLiving();
}
@Override
public boolean isMiscDisguise() {
return !getCustomEntity().isLiving();
}
@Override
public CustomDisguise addPlayer(Player player) {
return (CustomDisguise) super.addPlayer(player);
}
@Override
public CustomDisguise addPlayer(String playername) {
return (CustomDisguise) super.addPlayer(playername);
}
@Override
public CustomDisguise clone() {
CustomDisguise disguise = new CustomDisguise(getCustomEntity());
clone(disguise);
return disguise;
}
@Override
public CustomWatcher getWatcher() {
return (CustomWatcher) super.getWatcher();
}
@Override
public CustomDisguise setWatcher(FlagWatcher newWatcher) {
return (CustomDisguise) super.setWatcher(newWatcher);
}
@Override
public CustomDisguise removePlayer(Player player) {
return (CustomDisguise) super.removePlayer(player);
}
@Override
public CustomDisguise removePlayer(String playername) {
return (CustomDisguise) super.removePlayer(playername);
}
@Override
public CustomDisguise setDisguiseTarget(TargetType newTargetType) {
return (CustomDisguise) super.setDisguiseTarget(newTargetType);
}
@Override
public CustomDisguise setEntity(Entity entity) {
return (CustomDisguise) super.setEntity(entity);
}
@Override
public CustomDisguise setHearSelfDisguise(boolean hearSelfDisguise) {
return (CustomDisguise) super.setHearSelfDisguise(hearSelfDisguise);
}
@Override
public CustomDisguise setHideArmorFromSelf(boolean hideArmor) {
return (CustomDisguise) super.setHideArmorFromSelf(hideArmor);
}
@Override
public CustomDisguise setHideHeldItemFromSelf(boolean hideHeldItem) {
return (CustomDisguise) super.setHideHeldItemFromSelf(hideHeldItem);
}
@Override
public CustomDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
return (CustomDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise);
}
@Override
public CustomDisguise setModifyBoundingBox(boolean modifyBox) {
return (CustomDisguise) super.setModifyBoundingBox(modifyBox);
}
@Override
public CustomDisguise setReplaceSounds(boolean areSoundsReplaced) {
return (CustomDisguise) super.setReplaceSounds(areSoundsReplaced);
}
@Override
public CustomDisguise setVelocitySent(boolean sendVelocity) {
return (CustomDisguise) super.setVelocitySent(sendVelocity);
}
@Override
public CustomDisguise setViewSelfDisguise(boolean viewSelfDisguise) {
return (CustomDisguise) super.setViewSelfDisguise(viewSelfDisguise);
}
@Override
public CustomDisguise silentlyAddPlayer(String playername) {
return (CustomDisguise) super.silentlyAddPlayer(playername);
}
@Override
public CustomDisguise silentlyRemovePlayer(String playername) {
return (CustomDisguise) super.silentlyRemovePlayer(playername);
}
}

View File

@ -35,10 +35,6 @@ public enum DisguiseType {
CREEPER,
CUSTOM_MISC,
CUSTOM_LIVING,
DOLPHIN,
DONKEY,
@ -119,6 +115,10 @@ public enum DisguiseType {
MINECART_TNT(10, 3),
MODDED_MISC,
MODDED_LIVING,
MULE,
MUSHROOM_COW,
@ -266,7 +266,7 @@ public enum DisguiseType {
try {
// Why oh why can't isCustom() work :(
if (name().startsWith("CUSTOM_")) {
if (name().startsWith("MODDED_")) {
setEntityType(EntityType.UNKNOWN);
} else {
setEntityType(EntityType.valueOf(name()));
@ -327,12 +327,12 @@ public enum DisguiseType {
}
public boolean isMisc() {
return this == DisguiseType.CUSTOM_MISC ||
return this == DisguiseType.MODDED_MISC ||
(!isCustom() && getEntityType() != null && !getEntityType().isAlive());
}
public boolean isMob() {
return this == DisguiseType.CUSTOM_LIVING ||
return this == DisguiseType.MODDED_LIVING ||
(!isCustom() && getEntityType() != null && getEntityType().isAlive() && !isPlayer());
}
@ -345,7 +345,7 @@ public enum DisguiseType {
}
public boolean isCustom() {
return this == DisguiseType.CUSTOM_MISC || this == DisguiseType.CUSTOM_LIVING;
return this == DisguiseType.MODDED_MISC || this == DisguiseType.MODDED_LIVING;
}
public String toReadable() {

View File

@ -0,0 +1,154 @@
package me.libraryaddict.disguise.disguisetypes;
import lombok.Getter;
import me.libraryaddict.disguise.disguisetypes.watchers.ModdedWatcher;
import me.libraryaddict.disguise.utilities.modded.ModdedEntity;
import me.libraryaddict.disguise.utilities.modded.ModdedManager;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.security.InvalidParameterException;
/**
* Created by libraryaddict on 15/04/2020.
*/
public class ModdedDisguise extends TargetedDisguise {
@Getter
private ModdedEntity moddedEntity;
public ModdedDisguise(String moddedEntityName) {
this(ModdedManager.getCustomEntity(moddedEntityName));
}
public ModdedDisguise(ModdedEntity moddedEntity) {
super(moddedEntity.isLiving() ? DisguiseType.MODDED_LIVING : DisguiseType.MODDED_MISC);
this.moddedEntity = moddedEntity;
createDisguise();
}
public ModdedDisguise(DisguiseType disguiseType) {
super(disguiseType);
if (disguiseType != DisguiseType.UNKNOWN) {
throw new InvalidParameterException(
"CustomDisguise is only for DisguiseType.MODDED_LIVING/MISC and DisguiseType.UNKNOWN");
}
createDisguise();
}
@Override
public boolean isCustomDisguise() {
return true;
}
@Override
public boolean isMobDisguise() {
return getModdedEntity().isLiving();
}
@Override
public boolean isMiscDisguise() {
return !getModdedEntity().isLiving();
}
@Override
public ModdedDisguise addPlayer(Player player) {
return (ModdedDisguise) super.addPlayer(player);
}
@Override
public ModdedDisguise addPlayer(String playername) {
return (ModdedDisguise) super.addPlayer(playername);
}
@Override
public ModdedDisguise clone() {
ModdedDisguise disguise = new ModdedDisguise(getModdedEntity());
clone(disguise);
return disguise;
}
@Override
public ModdedWatcher getWatcher() {
return (ModdedWatcher) super.getWatcher();
}
@Override
public ModdedDisguise setWatcher(FlagWatcher newWatcher) {
return (ModdedDisguise) super.setWatcher(newWatcher);
}
@Override
public ModdedDisguise removePlayer(Player player) {
return (ModdedDisguise) super.removePlayer(player);
}
@Override
public ModdedDisguise removePlayer(String playername) {
return (ModdedDisguise) super.removePlayer(playername);
}
@Override
public ModdedDisguise setDisguiseTarget(TargetType newTargetType) {
return (ModdedDisguise) super.setDisguiseTarget(newTargetType);
}
@Override
public ModdedDisguise setEntity(Entity entity) {
return (ModdedDisguise) super.setEntity(entity);
}
@Override
public ModdedDisguise setHearSelfDisguise(boolean hearSelfDisguise) {
return (ModdedDisguise) super.setHearSelfDisguise(hearSelfDisguise);
}
@Override
public ModdedDisguise setHideArmorFromSelf(boolean hideArmor) {
return (ModdedDisguise) super.setHideArmorFromSelf(hideArmor);
}
@Override
public ModdedDisguise setHideHeldItemFromSelf(boolean hideHeldItem) {
return (ModdedDisguise) super.setHideHeldItemFromSelf(hideHeldItem);
}
@Override
public ModdedDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
return (ModdedDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise);
}
@Override
public ModdedDisguise setModifyBoundingBox(boolean modifyBox) {
return (ModdedDisguise) super.setModifyBoundingBox(modifyBox);
}
@Override
public ModdedDisguise setReplaceSounds(boolean areSoundsReplaced) {
return (ModdedDisguise) super.setReplaceSounds(areSoundsReplaced);
}
@Override
public ModdedDisguise setVelocitySent(boolean sendVelocity) {
return (ModdedDisguise) super.setVelocitySent(sendVelocity);
}
@Override
public ModdedDisguise setViewSelfDisguise(boolean viewSelfDisguise) {
return (ModdedDisguise) super.setViewSelfDisguise(viewSelfDisguise);
}
@Override
public ModdedDisguise silentlyAddPlayer(String playername) {
return (ModdedDisguise) super.silentlyAddPlayer(playername);
}
@Override
public ModdedDisguise silentlyRemovePlayer(String playername) {
return (ModdedDisguise) super.silentlyRemovePlayer(playername);
}
}

View File

@ -6,8 +6,8 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
/**
* Created by libraryaddict on 13/04/2020.
*/
public class CustomWatcher extends FlagWatcher {
public CustomWatcher(Disguise disguise) {
public class ModdedWatcher extends FlagWatcher {
public ModdedWatcher(Disguise disguise) {
super(disguise);
}

View File

@ -55,7 +55,7 @@ public class SerializerDisguise implements JsonDeserializer<Disguise>, JsonSeria
@Override
public JsonElement serialize(Disguise src, Type typeOfSrc, JsonSerializationContext context) {
if (src.isCustomDisguise()) {
return context.serialize(src, CustomDisguise.class);
return context.serialize(src, ModdedDisguise.class);
} else if (src.isPlayerDisguise())
return context.serialize(src, PlayerDisguise.class);
else if (src.isMobDisguise())

View File

@ -9,7 +9,7 @@ import lombok.Setter;
*/
@AllArgsConstructor
@Getter
public class CustomEntity {
public class ModdedEntity {
@Setter
private Object entityType;
private final String name;

View File

@ -22,7 +22,7 @@ import java.util.Map;
*/
public class ModdedManager implements PluginMessageListener {
@Getter
private static final HashMap<NamespacedKey, CustomEntity> entities = new HashMap<>();
private static final HashMap<NamespacedKey, ModdedEntity> entities = new HashMap<>();
@Getter
private static byte[] fmlHandshake;
@ -67,7 +67,7 @@ public class ModdedManager implements PluginMessageListener {
fmlHandshake = stream.toByteArray();
}
public static void registerCustomEntity(NamespacedKey name, CustomEntity entity, boolean register) {
public static void registerCustomEntity(NamespacedKey name, ModdedEntity entity, boolean register) {
if (entities.keySet().stream().anyMatch(n -> n.toString().equalsIgnoreCase(name.toString()))) {
throw new IllegalArgumentException(name + " has already been registered");
}
@ -93,12 +93,12 @@ public class ModdedManager implements PluginMessageListener {
entities.put(name, entity);
}
public static CustomEntity getCustomEntity(NamespacedKey name) {
public static ModdedEntity getCustomEntity(NamespacedKey name) {
return entities.get(name);
}
public static CustomEntity getCustomEntity(String name) {
for (CustomEntity entity : entities.values()) {
public static ModdedEntity getCustomEntity(String name) {
for (ModdedEntity entity : entities.values()) {
if (!entity.getName().equalsIgnoreCase(name)) {
continue;
}
@ -112,9 +112,9 @@ public class ModdedManager implements PluginMessageListener {
public static ArrayList<DisguisePerm> getDisguiseTypes() {
ArrayList<DisguisePerm> perms = new ArrayList<>();
for (Map.Entry<NamespacedKey, CustomEntity> entry : entities.entrySet()) {
for (Map.Entry<NamespacedKey, ModdedEntity> entry : entities.entrySet()) {
perms.add(new DisguisePerm(
entry.getValue().isLiving() ? DisguiseType.CUSTOM_LIVING : DisguiseType.CUSTOM_MISC,
entry.getValue().isLiving() ? DisguiseType.MODDED_LIVING : DisguiseType.MODDED_MISC,
entry.getValue().getName()));
}
@ -147,7 +147,7 @@ public class ModdedManager implements PluginMessageListener {
player.setMetadata("forge_mods", new FixedMetadataValue(LibsDisguises.getInstance(), mods));
for (CustomEntity e : getEntities().values()) {
for (ModdedEntity e : getEntities().values()) {
if (e.getMod() == null) {
continue;
}

View File

@ -234,7 +234,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
if (!disguise.getType().isCustom()) {
mods.write(2, disguise.getType().getTypeId());
} else {
mods.write(2, ((CustomDisguise) disguise).getCustomEntity().getTypeId());
mods.write(2, ((ModdedDisguise) disguise).getModdedEntity().getTypeId());
}
// region Vector calculations
@ -310,7 +310,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
Object entityType;
if (disguise.isCustomDisguise()) {
entityType = ((CustomDisguise) disguise).getCustomEntity().getEntityType();
entityType = ((ModdedDisguise) disguise).getModdedEntity().getEntityType();
} else {
entityType = ReflectionManager.getEntityType(disguise.getType().getEntityType());
}
@ -325,7 +325,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
int objectId = disguise.getType().getObjectId();
if (disguise.isCustomDisguise()) {
objectId = ((CustomDisguise) disguise).getCustomEntity().getTypeId();
objectId = ((ModdedDisguise) disguise).getModdedEntity().getTypeId();
}
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);

View File

@ -4,7 +4,7 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.modded.CustomEntity;
import me.libraryaddict.disguise.utilities.modded.ModdedEntity;
import me.libraryaddict.disguise.utilities.modded.ModdedManager;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
@ -647,13 +647,13 @@ public class DisguiseParser {
name = disguisePerm.toReadable();
if (disguisePerm.getType().isCustom()) {
CustomEntity ent = ModdedManager.getCustomEntity(disguisePerm.toReadable());
ModdedEntity ent = ModdedManager.getCustomEntity(disguisePerm.toReadable());
if (ent == null) {
throw new DisguiseParseException(LibsMsg.PARSE_CANT_DISG_UNKNOWN);
}
disguise = new CustomDisguise(ent);
disguise = new ModdedDisguise(ent);
}
Entry<DisguisePerm, String> customDisguise = DisguiseConfig.getRawCustomDisguise(args[0]);

View File

@ -21,7 +21,6 @@ import org.bukkit.entity.*;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.InvalidDescriptionException;
import org.bukkit.potion.PotionEffect;
import org.bukkit.util.Vector;
@ -1491,9 +1490,9 @@ public class ReflectionManager {
case ARROW:
watcherClass = TippedArrowWatcher.class;
break;
case CUSTOM_LIVING:
case CUSTOM_MISC:
watcherClass = CustomWatcher.class;
case MODDED_LIVING:
case MODDED_MISC:
watcherClass = ModdedWatcher.class;
break;
case COD:
case SALMON: