Modulization of NMS versions for 1.18+
This commit is contained in:
532
plugin/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java
Normal file
532
plugin/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java
Normal file
@@ -0,0 +1,532 @@
|
||||
package me.libraryaddict.disguise;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
import me.libraryaddict.disguise.disguisetypes.*;
|
||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DisguiseAPI {
|
||||
private static int selfDisguiseId;
|
||||
private static int entityAttachmentId;
|
||||
|
||||
public static int getEntityAttachmentId() {
|
||||
if (entityAttachmentId == 0) {
|
||||
entityAttachmentId = ReflectionManager.getNewEntityId();
|
||||
}
|
||||
|
||||
return entityAttachmentId;
|
||||
}
|
||||
|
||||
public static void addCustomDisguise(String disguiseName, String disguiseInfo) throws DisguiseParseException {
|
||||
// Dirty fix for anyone that somehow got this far with a . in the name, invalid yaml!
|
||||
disguiseName = disguiseName.replace(".", "");
|
||||
|
||||
try {
|
||||
DisguiseConfig.removeCustomDisguise(disguiseName);
|
||||
DisguiseConfig.addCustomDisguise(disguiseName, disguiseInfo);
|
||||
|
||||
File disguisesFile = new File(LibsDisguises.getInstance().getDataFolder(), "configs/disguises.yml");
|
||||
|
||||
if (!disguisesFile.exists()) {
|
||||
disguisesFile.getParentFile().mkdirs();
|
||||
disguisesFile.createNewFile();
|
||||
}
|
||||
|
||||
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(disguisesFile);
|
||||
|
||||
if (!configuration.isConfigurationSection("Disguises")) {
|
||||
configuration.createSection("Disguises");
|
||||
}
|
||||
|
||||
ConfigurationSection section = configuration.getConfigurationSection("Disguises");
|
||||
section.set(disguiseName, disguiseInfo.replace("\n", "\\n").replace("\r", "\\r"));
|
||||
|
||||
configuration.save(disguisesFile);
|
||||
|
||||
DisguiseUtilities.getLogger().info("Added new Custom Disguise " + disguiseName);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void addGameProfile(String profileName, WrappedGameProfile gameProfile) {
|
||||
DisguiseUtilities.addGameProfile(profileName, gameProfile);
|
||||
}
|
||||
|
||||
public static String getRawCustomDisguise(String disguiseName) {
|
||||
Map.Entry<DisguisePerm, String> entry = DisguiseConfig.getRawCustomDisguise(disguiseName);
|
||||
|
||||
if (entry == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return entry.getValue();
|
||||
}
|
||||
|
||||
public static Disguise getCustomDisguise(String disguiseName) {
|
||||
Map.Entry<DisguisePerm, Disguise> disguise = DisguiseConfig.getCustomDisguise(disguiseName);
|
||||
|
||||
if (disguise == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return disguise.getValue();
|
||||
}
|
||||
|
||||
public static Disguise constructDisguise(Entity entity) {
|
||||
return constructDisguise(entity, true, false);
|
||||
}
|
||||
|
||||
public static Disguise constructDisguise(Entity entity, boolean doEquipment, boolean displayExtraAnimations) {
|
||||
DisguiseType disguiseType = DisguiseType.getType(entity);
|
||||
Disguise disguise;
|
||||
|
||||
if (disguiseType.isMisc()) {
|
||||
disguise = new MiscDisguise(disguiseType);
|
||||
} else if (disguiseType.isMob()) {
|
||||
disguise = new MobDisguise(disguiseType);
|
||||
} else {
|
||||
disguise = new PlayerDisguise(entity.getName());
|
||||
}
|
||||
|
||||
FlagWatcher watcher = disguise.getWatcher();
|
||||
|
||||
if (doEquipment && entity instanceof LivingEntity) {
|
||||
EntityEquipment equip = ((LivingEntity) entity).getEquipment();
|
||||
|
||||
watcher.setArmor(equip.getArmorContents());
|
||||
|
||||
ItemStack mainItem = equip.getItemInMainHand();
|
||||
|
||||
if (mainItem != null && mainItem.getType() != Material.AIR) {
|
||||
watcher.setItemInMainHand(mainItem);
|
||||
}
|
||||
|
||||
ItemStack offItem = equip.getItemInMainHand();
|
||||
|
||||
if (offItem != null && offItem.getType() != Material.AIR) {
|
||||
watcher.setItemInOffHand(offItem);
|
||||
}
|
||||
}
|
||||
|
||||
WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(entity);
|
||||
|
||||
for (WrappedWatchableObject obj : dataWatcher.getWatchableObjects()) {
|
||||
MetaIndex index = MetaIndex.getMetaIndex(watcher.getClass(), obj.getIndex());
|
||||
|
||||
if (index == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (index.getDefault() == obj.getValue() || index.getDefault() == obj.getRawValue()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
watcher.setUnsafeData(index, obj.getRawValue());
|
||||
|
||||
// Update the meta for 0, otherwise boolean be weird
|
||||
if (index == MetaIndex.ENTITY_META) {
|
||||
watcher.setSprinting(watcher.isSprinting() && displayExtraAnimations);
|
||||
watcher.setFlyingWithElytra(watcher.isFlyingWithElytra() && displayExtraAnimations);
|
||||
watcher.setSneaking(watcher.isSneaking() && displayExtraAnimations);
|
||||
watcher.setSwimming(watcher.isSwimming() && displayExtraAnimations);
|
||||
|
||||
if (!NmsVersion.v1_13.isSupported()) {
|
||||
watcher.setMainHandRaised(watcher.isMainHandRaised() && displayExtraAnimations);
|
||||
}
|
||||
|
||||
if (!displayExtraAnimations) {
|
||||
Arrays.fill(watcher.getModifiedEntityAnimations(), false);
|
||||
}
|
||||
|
||||
watcher.setGlowing(watcher.isGlowing());
|
||||
watcher.setInvisible(watcher.isInvisible());
|
||||
} else if (index == MetaIndex.LIVING_META && NmsVersion.v1_13.isSupported()) {
|
||||
LivingWatcher livingWatcher = (LivingWatcher) watcher;
|
||||
|
||||
livingWatcher.setMainHandRaised(livingWatcher.isMainHandRaised() && displayExtraAnimations);
|
||||
livingWatcher.setOffhandRaised(livingWatcher.isOffhandRaised() && displayExtraAnimations);
|
||||
livingWatcher.setSpinning(livingWatcher.isSpinning() && displayExtraAnimations);
|
||||
|
||||
if (!displayExtraAnimations) {
|
||||
Arrays.fill(livingWatcher.getModifiedLivingAnimations(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return disguise;
|
||||
}
|
||||
|
||||
public static void disguiseEntity(Entity entity, Disguise disguise) {
|
||||
disguiseEntity(null, entity, disguise);
|
||||
}
|
||||
|
||||
public static void disguiseEntity(CommandSender commandSender, Entity entity, Disguise disguise) {
|
||||
// If they are trying to disguise a null entity or use a null disguise
|
||||
// Just return.
|
||||
if (entity == null || disguise == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The event wasn't cancelled.
|
||||
// If the disguise entity isn't the same as the one we are disguising
|
||||
if (disguise.getEntity() != entity) {
|
||||
// If the disguise entity actually exists
|
||||
if (disguise.getEntity() != null) {
|
||||
// Clone the disguise
|
||||
disguise = disguise.clone();
|
||||
}
|
||||
// Set the disguise's entity
|
||||
disguise.setEntity(entity);
|
||||
}
|
||||
|
||||
// They prefer to have the opposite of whatever the view disguises option is
|
||||
if (hasSelfDisguisePreference(entity) && disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewSelfDisguisesDefault()) {
|
||||
disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible());
|
||||
}
|
||||
|
||||
if (hasActionBarPreference(entity) && !isNotifyBarShown(entity)) {
|
||||
disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE);
|
||||
}
|
||||
|
||||
disguise.startDisguise(commandSender);
|
||||
}
|
||||
|
||||
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Collection playersToNotSeeDisguise) {
|
||||
if (disguise.getEntity() != null) {
|
||||
disguise = disguise.clone();
|
||||
}
|
||||
|
||||
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS);
|
||||
|
||||
for (Object obj : playersToNotSeeDisguise) {
|
||||
if (obj instanceof String) {
|
||||
((TargetedDisguise) disguise).addPlayer((String) obj);
|
||||
} else if (obj instanceof Player) {
|
||||
((TargetedDisguise) disguise).addPlayer(((Player) obj).getName());
|
||||
}
|
||||
}
|
||||
|
||||
disguiseEntity(entity, disguise);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, List<String> playersToNotSeeDisguise) {
|
||||
disguiseIgnorePlayers(entity, disguise, (Collection) playersToNotSeeDisguise);
|
||||
}
|
||||
|
||||
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Player... playersToNotSeeDisguise) {
|
||||
disguiseIgnorePlayers(entity, disguise, Arrays.asList(playersToNotSeeDisguise));
|
||||
}
|
||||
|
||||
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, String... playersToNotSeeDisguise) {
|
||||
disguiseIgnorePlayers(entity, disguise, (Collection) Arrays.asList(playersToNotSeeDisguise));
|
||||
}
|
||||
|
||||
/**
|
||||
* Disguise the next entity to spawn, this means you need to spawn an entity immediately after calling this.
|
||||
*
|
||||
* @param disguise
|
||||
* @return
|
||||
*/
|
||||
public static int disguiseNextEntity(Disguise disguise) {
|
||||
if (disguise == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (disguise.getEntity() != null || DisguiseUtilities.getDisguises().containsValue(disguise)) {
|
||||
disguise = disguise.clone();
|
||||
}
|
||||
|
||||
int id = ReflectionManager.getNewEntityId(false);
|
||||
DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disguise this entity with this disguise
|
||||
*
|
||||
* @param entity
|
||||
* @param disguise
|
||||
*/
|
||||
public static void disguiseToAll(Entity entity, Disguise disguise) {
|
||||
if (disguise.getEntity() != null) {
|
||||
disguise = disguise.clone();
|
||||
}
|
||||
|
||||
// You called the disguiseToAll method foolish mortal! Prepare to have your custom settings wiped!!!
|
||||
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS);
|
||||
|
||||
for (String observer : ((TargetedDisguise) disguise).getObservers()) {
|
||||
((TargetedDisguise) disguise).removePlayer(observer);
|
||||
}
|
||||
|
||||
disguiseEntity(entity, disguise);
|
||||
}
|
||||
|
||||
public static void disguiseToPlayers(Entity entity, Disguise disguise, Collection playersToViewDisguise) {
|
||||
if (disguise.getEntity() != null) {
|
||||
disguise = disguise.clone();
|
||||
}
|
||||
|
||||
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS);
|
||||
|
||||
for (Object obj : playersToViewDisguise) {
|
||||
if (obj instanceof String) {
|
||||
((TargetedDisguise) disguise).addPlayer((String) obj);
|
||||
} else if (obj instanceof Player) {
|
||||
((TargetedDisguise) disguise).addPlayer(((Player) obj).getName());
|
||||
}
|
||||
}
|
||||
|
||||
disguiseEntity(entity, disguise);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void disguiseToPlayers(Entity entity, Disguise disguise, List<String> playersToViewDisguise) {
|
||||
disguiseToPlayers(entity, disguise, (Collection) playersToViewDisguise);
|
||||
}
|
||||
|
||||
public static void disguiseToPlayers(Entity entity, Disguise disguise, Player... playersToViewDisguise) {
|
||||
disguiseToPlayers(entity, disguise, Arrays.asList(playersToViewDisguise));
|
||||
}
|
||||
|
||||
public static void disguiseToPlayers(Entity entity, Disguise disguise, String... playersToViewDisguise) {
|
||||
disguiseToPlayers(entity, disguise, (Collection) Arrays.asList(playersToViewDisguise));
|
||||
}
|
||||
|
||||
private static int firstCapital(String str) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
if (Character.isUpperCase(str.charAt(i))) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the disguise of a entity
|
||||
*
|
||||
* @param disguised
|
||||
* @return
|
||||
*/
|
||||
public static Disguise getDisguise(Entity disguised) {
|
||||
if (disguised == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return DisguiseUtilities.getMainDisguise(disguised.getEntityId());
|
||||
}
|
||||
|
||||
public static String parseToString(Disguise disguise, boolean outputSkin) {
|
||||
return DisguiseParser.parseToString(disguise, outputSkin);
|
||||
}
|
||||
|
||||
public static String parseToString(Disguise disguise) {
|
||||
return parseToString(disguise, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the disguise of a entity
|
||||
*
|
||||
* @param observer
|
||||
* @param disguised
|
||||
* @return
|
||||
*/
|
||||
public static Disguise getDisguise(Player observer, Entity disguised) {
|
||||
if (disguised == null || observer == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return DisguiseUtilities.getDisguise(observer, disguised);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the disguises of a entity
|
||||
*
|
||||
* @param disguised
|
||||
* @return
|
||||
*/
|
||||
public static Disguise[] getDisguises(Entity disguised) {
|
||||
if (disguised == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return DisguiseUtilities.getDisguises(disguised.getEntityId());
|
||||
}
|
||||
|
||||
public static int getSelfDisguiseId() {
|
||||
if (selfDisguiseId == 0) {
|
||||
selfDisguiseId = ReflectionManager.getNewEntityId();
|
||||
}
|
||||
|
||||
return selfDisguiseId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this entity disguised
|
||||
*
|
||||
* @param disguised
|
||||
* @return
|
||||
*/
|
||||
public static boolean isDisguised(Entity disguised) {
|
||||
return getDisguise(disguised) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this entity disguised
|
||||
*
|
||||
* @param observer
|
||||
* @param disguised
|
||||
* @return
|
||||
*/
|
||||
public static boolean isDisguised(Player observer, Entity disguised) {
|
||||
return getDisguise(observer, disguised) != null;
|
||||
}
|
||||
|
||||
public static boolean isDisguiseInUse(Disguise disguise) {
|
||||
return disguise.isDisguiseInUse();
|
||||
}
|
||||
|
||||
public static boolean isSelfDisguised(Player player) {
|
||||
return DisguiseUtilities.getSelfDisguised().contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the entitiy has /disguiseviewself toggled on.
|
||||
*
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public static boolean isViewSelfToggled(Entity entity) {
|
||||
return hasSelfDisguisePreference(entity) != DisguiseConfig.isViewSelfDisguisesDefault();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean isActionBarShown(Entity entity) {
|
||||
return isNotifyBarShown(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the entity wants to see the action bar / boss bar
|
||||
*
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public static boolean isNotifyBarShown(Entity entity) {
|
||||
// If default is no notify bar, but they toggled it. Then we want to show it.
|
||||
// If default is a notify bar, but they toggled it. Then we want to hide it.
|
||||
|
||||
return (DisguiseConfig.getNotifyBar() == DisguiseConfig.NotifyBar.NONE) == hasActionBarPreference(entity);
|
||||
}
|
||||
|
||||
public static boolean hasSelfDisguisePreference(Entity entity) {
|
||||
return DisguiseUtilities.getViewSelf().contains(entity.getUniqueId());
|
||||
}
|
||||
|
||||
public static boolean hasActionBarPreference(Entity entity) {
|
||||
return DisguiseUtilities.getViewBar().contains(entity.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Undisguise the entity. This doesn't let you cancel the UndisguiseEvent if the entity is no longer valid. Aka
|
||||
* removed from
|
||||
* the world.
|
||||
*
|
||||
* @param entity
|
||||
*/
|
||||
public static void undisguiseToAll(Entity entity) {
|
||||
undisguiseToAll(null, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undisguise the entity. This doesn't let you cancel the UndisguiseEvent if the entity is no longer valid. Aka
|
||||
* removed from
|
||||
* the world.
|
||||
*
|
||||
* @param entity
|
||||
*/
|
||||
public static void undisguiseToAll(CommandSender sender, Entity entity) {
|
||||
Disguise[] disguises = getDisguises(entity);
|
||||
|
||||
for (Disguise disguise : disguises) {
|
||||
disguise.removeDisguise(sender);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this player can see his own disguise or not.
|
||||
*
|
||||
* @param entity
|
||||
* @param canSeeSelfDisguises
|
||||
*/
|
||||
public static void setViewDisguiseToggled(Entity entity, boolean canSeeSelfDisguises) {
|
||||
if (isDisguised(entity)) {
|
||||
Disguise[] disguises = getDisguises(entity);
|
||||
|
||||
for (Disguise disguise : disguises) {
|
||||
disguise.setViewSelfDisguise(canSeeSelfDisguises);
|
||||
}
|
||||
}
|
||||
|
||||
if (!canSeeSelfDisguises == DisguiseConfig.isViewSelfDisguisesDefault()) {
|
||||
if (!hasSelfDisguisePreference(entity)) {
|
||||
DisguiseUtilities.getViewSelf().add(entity.getUniqueId());
|
||||
DisguiseUtilities.addSaveAttempt();
|
||||
}
|
||||
} else {
|
||||
DisguiseUtilities.getViewSelf().remove(entity.getUniqueId());
|
||||
DisguiseUtilities.addSaveAttempt();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setActionBarShown(Player player, boolean isShown) {
|
||||
if (isDisguised(player)) {
|
||||
Disguise[] disguises = getDisguises(player);
|
||||
|
||||
for (Disguise disguise : disguises) {
|
||||
disguise.setNotifyBar(isShown ? DisguiseConfig.getNotifyBar() : DisguiseConfig.NotifyBar.NONE);
|
||||
}
|
||||
}
|
||||
|
||||
// If default is view and we want the opposite
|
||||
if (!isShown) {
|
||||
if (!hasActionBarPreference(player)) {
|
||||
DisguiseUtilities.getViewBar().add(player.getUniqueId());
|
||||
DisguiseUtilities.addSaveAttempt();
|
||||
}
|
||||
} else {
|
||||
DisguiseUtilities.getViewBar().remove(player.getUniqueId());
|
||||
DisguiseUtilities.addSaveAttempt();
|
||||
}
|
||||
}
|
||||
|
||||
private DisguiseAPI() {
|
||||
}
|
||||
}
|
1086
plugin/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java
Normal file
1086
plugin/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,375 @@
|
||||
package me.libraryaddict.disguise;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import lombok.Getter;
|
||||
import me.libraryaddict.disguise.commands.LibsDisguisesCommand;
|
||||
import me.libraryaddict.disguise.commands.disguise.DisguiseCommand;
|
||||
import me.libraryaddict.disguise.commands.disguise.DisguiseEntityCommand;
|
||||
import me.libraryaddict.disguise.commands.disguise.DisguisePlayerCommand;
|
||||
import me.libraryaddict.disguise.commands.disguise.DisguiseRadiusCommand;
|
||||
import me.libraryaddict.disguise.commands.modify.DisguiseModifyCommand;
|
||||
import me.libraryaddict.disguise.commands.modify.DisguiseModifyEntityCommand;
|
||||
import me.libraryaddict.disguise.commands.modify.DisguiseModifyPlayerCommand;
|
||||
import me.libraryaddict.disguise.commands.modify.DisguiseModifyRadiusCommand;
|
||||
import me.libraryaddict.disguise.commands.undisguise.UndisguiseCommand;
|
||||
import me.libraryaddict.disguise.commands.undisguise.UndisguiseEntityCommand;
|
||||
import me.libraryaddict.disguise.commands.undisguise.UndisguisePlayerCommand;
|
||||
import me.libraryaddict.disguise.commands.undisguise.UndisguiseRadiusCommand;
|
||||
import me.libraryaddict.disguise.commands.utils.*;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.config.DisguiseCommandConfig;
|
||||
import me.libraryaddict.disguise.utilities.listeners.DisguiseListener;
|
||||
import me.libraryaddict.disguise.utilities.listeners.PaperDisguiseListener;
|
||||
import me.libraryaddict.disguise.utilities.listeners.PlayerSkinHandler;
|
||||
import me.libraryaddict.disguise.utilities.metrics.MetricsInitalizer;
|
||||
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.sounds.SoundManager;
|
||||
import me.libraryaddict.disguise.utilities.updates.UpdateChecker;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class LibsDisguises extends JavaPlugin {
|
||||
private static LibsDisguises instance;
|
||||
private DisguiseListener listener;
|
||||
private String buildNumber;
|
||||
@Getter
|
||||
private boolean reloaded;
|
||||
@Getter
|
||||
private final UpdateChecker updateChecker = new UpdateChecker();
|
||||
@Getter
|
||||
private PlayerSkinHandler skinHandler;
|
||||
private DisguiseCommandConfig commandConfig;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
try {
|
||||
if (instance != null || !Bukkit.getServer().getWorlds().isEmpty() || !Bukkit.getOnlinePlayers().isEmpty()) {
|
||||
reloaded = true;
|
||||
getLogger().severe("Server was reloaded! Please do not report any bugs! This plugin can't handle " + "reloads gracefully!");
|
||||
}
|
||||
|
||||
instance = this;
|
||||
|
||||
Plugin plugin = Bukkit.getPluginManager().getPlugin("ProtocolLib");
|
||||
|
||||
if (plugin == null || DisguiseUtilities.isProtocolLibOutdated()) {
|
||||
getLogger().warning("Noticed you're using an older version of ProtocolLib (or not using it)! We're forcibly updating you!");
|
||||
|
||||
try {
|
||||
File dest = DisguiseUtilities.updateProtocolLib();
|
||||
|
||||
if (plugin == null) {
|
||||
getLogger().info("ProtocolLib downloaded and stuck in plugins folder! Now trying to load it!");
|
||||
plugin = Bukkit.getPluginManager().loadPlugin(dest);
|
||||
plugin.onLoad();
|
||||
|
||||
Bukkit.getPluginManager().enablePlugin(plugin);
|
||||
} else {
|
||||
getLogger().severe("Please restart the server to complete the ProtocolLib update!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
getLogger()
|
||||
.severe("Looks like ProtocolLib's site may be down! MythicCraft/MythicMobs has a discord server https://discord.gg/EErRhJ4qgx you" +
|
||||
" can " + "join. Check the pins in #libs-support for a ProtocolLib.jar you can download!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
Class cl = Class.forName("org.bukkit.Server$Spigot");
|
||||
} catch (ClassNotFoundException e) {
|
||||
getLogger().severe("Oh dear, you seem to be using CraftBukkit. Please use Spigot or Paper instead! This " +
|
||||
"plugin will continue to load, but it will look like a mugging victim");
|
||||
}
|
||||
|
||||
commandConfig = new DisguiseCommandConfig();
|
||||
|
||||
if (!reloaded) {
|
||||
commandConfig.load();
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
try {
|
||||
if (isNumberedBuild() && DisguiseConfig.isAutoUpdate()) {
|
||||
getUpdateChecker().doUpdate();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
getLogger().severe("Failed to even do a forced update");
|
||||
}
|
||||
|
||||
throw throwable;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
try {
|
||||
if (reloaded) {
|
||||
getLogger().severe("Server was reloaded! Please do not report any bugs! This plugin can't handle " + "reloads gracefully!");
|
||||
}
|
||||
|
||||
if (Bukkit.getVersion().contains("(MC: 1.17)")) {
|
||||
getLogger().severe("Please update from MC 1.17! You should be using 1.17.1!");
|
||||
}
|
||||
|
||||
try {
|
||||
Class cl = Class.forName("org.bukkit.Server$Spigot");
|
||||
} catch (ClassNotFoundException e) {
|
||||
getLogger().severe("Oh dear, you seem to be using CraftBukkit. Please use Spigot or Paper instead! This " +
|
||||
"plugin will continue to load, but it will look like a mugging victim");
|
||||
}
|
||||
|
||||
File disguiseFile = new File(getDataFolder(), "configs/disguises.yml");
|
||||
|
||||
if (!disguiseFile.exists()) {
|
||||
disguiseFile.getParentFile().mkdirs();
|
||||
|
||||
File oldFile = new File(getDataFolder(), "disguises.yml");
|
||||
|
||||
if (oldFile.exists()) {
|
||||
oldFile.renameTo(disguiseFile);
|
||||
} else {
|
||||
saveResource("configs/disguises.yml", false);
|
||||
}
|
||||
}
|
||||
|
||||
YamlConfiguration pluginYml = ReflectionManager.getPluginYAML(getFile());
|
||||
buildNumber = StringUtils.stripToNull(pluginYml.getString("build-number"));
|
||||
|
||||
getLogger().info("File Name: " + getFile().getName());
|
||||
|
||||
getLogger().info("Discovered nms version: " + ReflectionManager.getBukkitVersion());
|
||||
|
||||
getLogger().info("Jenkins Build: " + (isNumberedBuild() ? "#" : "") + getBuildNo());
|
||||
|
||||
getLogger().info("Build Date: " + pluginYml.getString("build-date"));
|
||||
|
||||
DisguiseConfig.loadInternalConfig();
|
||||
|
||||
LibsPremium.check(getDescription().getVersion(), getFile());
|
||||
|
||||
if (!LibsPremium.isPremium()) {
|
||||
getLogger()
|
||||
.info("You are running the free version, commands limited to non-players and operators. (Console," + " Command " + "Blocks, Admins)");
|
||||
}
|
||||
|
||||
if (ReflectionManager.getVersion() == null) {
|
||||
getLogger().severe("You're using the wrong version of Lib's Disguises for your server! This is " + "intended for " +
|
||||
StringUtils.join(Arrays.stream(NmsVersion.values()).map(v -> v.name().replace("_", ".")).collect(Collectors.toList()), " & ") + "!");
|
||||
getPluginLoader().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
String requiredProtocolLib = StringUtils.join(DisguiseUtilities.getProtocolLibRequiredVersion(), " or build #");
|
||||
String version = ProtocolLibrary.getPlugin().getDescription().getVersion();
|
||||
|
||||
if (DisguiseUtilities.isProtocolLibOutdated()) {
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
private int timesRun;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
getLogger().severe("!! May I have your attention please !!");
|
||||
getLogger().severe("Update your ProtocolLib! You are running " + version + " but the minimum version you should be on is " +
|
||||
requiredProtocolLib + "!");
|
||||
getLogger().severe("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target" + "/ProtocolLib" + ".jar");
|
||||
getLogger().severe("Or! Use /ld protocollib - To update to the latest development build");
|
||||
|
||||
if (timesRun++ > 0) {
|
||||
getLogger().severe("This message is on repeat due to the sheer number of people who don't see this.");
|
||||
}
|
||||
|
||||
getLogger().severe("!! May I have your attention please !!");
|
||||
}
|
||||
};
|
||||
|
||||
runnable.run();
|
||||
runnable.runTaskTimer(this, 20, 10 * 60 * 20);
|
||||
}
|
||||
|
||||
// If this is a release build, even if jenkins build..
|
||||
if (isReleaseBuild()) {
|
||||
// If downloaded from spigot, forcibly set release build to true
|
||||
if (LibsPremium.getUserID().matches("[0-9]+")) {
|
||||
DisguiseConfig.setUsingReleaseBuilds(true);
|
||||
}
|
||||
// Otherwise leave it untouched as they might've just happened to hit a dev build, which is a release build
|
||||
} else {
|
||||
DisguiseConfig.setUsingReleaseBuilds(false);
|
||||
}
|
||||
|
||||
ReflectionManager.init();
|
||||
|
||||
PacketsManager.init();
|
||||
DisguiseUtilities.init();
|
||||
|
||||
ReflectionManager.registerValues();
|
||||
|
||||
new SoundManager().load();
|
||||
|
||||
DisguiseConfig.loadConfig();
|
||||
|
||||
DisguiseParser.createDefaultMethods();
|
||||
|
||||
PacketsManager.addPacketListeners();
|
||||
|
||||
listener = new DisguiseListener(this);
|
||||
skinHandler = new PlayerSkinHandler();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(getSkinHandler(), LibsDisguises.getInstance());
|
||||
|
||||
if (DisguiseUtilities.isRunningPaper()) {
|
||||
Bukkit.getPluginManager().registerEvents(new PaperDisguiseListener(), this);
|
||||
}
|
||||
|
||||
registerCommand("libsdisguises", new LibsDisguisesCommand());
|
||||
registerCommand("disguise", new DisguiseCommand());
|
||||
registerCommand("undisguise", new UndisguiseCommand());
|
||||
registerCommand("disguiseplayer", new DisguisePlayerCommand());
|
||||
registerCommand("undisguiseplayer", new UndisguisePlayerCommand());
|
||||
registerCommand("undisguiseentity", new UndisguiseEntityCommand());
|
||||
registerCommand("disguiseentity", new DisguiseEntityCommand());
|
||||
registerCommand("disguiseradius", new DisguiseRadiusCommand());
|
||||
registerCommand("undisguiseradius", new UndisguiseRadiusCommand());
|
||||
registerCommand("disguisehelp", new DisguiseHelpCommand());
|
||||
registerCommand("disguiseclone", new DisguiseCloneCommand());
|
||||
registerCommand("disguiseviewself", new DisguiseViewSelfCommand());
|
||||
registerCommand("disguiseviewbar", new DisguiseViewBarCommand());
|
||||
registerCommand("disguisemodify", new DisguiseModifyCommand());
|
||||
registerCommand("disguisemodifyentity", new DisguiseModifyEntityCommand());
|
||||
registerCommand("disguisemodifyplayer", new DisguiseModifyPlayerCommand());
|
||||
registerCommand("disguisemodifyradius", new DisguiseModifyRadiusCommand());
|
||||
registerCommand("copydisguise", new CopyDisguiseCommand());
|
||||
registerCommand("grabskin", new GrabSkinCommand());
|
||||
registerCommand("savedisguise", new SaveDisguiseCommand());
|
||||
registerCommand("grabhead", new GrabHeadCommand());
|
||||
|
||||
unregisterCommands(false);
|
||||
|
||||
new MetricsInitalizer();
|
||||
} catch (Throwable throwable) {
|
||||
try {
|
||||
if (isNumberedBuild() && DisguiseConfig.isAutoUpdate()) {
|
||||
getUpdateChecker().doUpdate();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
getLogger().severe("Failed to even do a forced update");
|
||||
}
|
||||
|
||||
throw throwable;
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterCommands(boolean force) {
|
||||
CommandMap map = ReflectionManager.getCommandMap();
|
||||
Map<String, Command> commands = ReflectionManager.getCommands(map);
|
||||
|
||||
for (String command : getDescription().getCommands().keySet()) {
|
||||
PluginCommand cmd = getCommand("libsdisguises:" + command);
|
||||
|
||||
if (cmd == null || (cmd.getExecutor() != this && !force)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cmd.getPermission() != null && cmd.getPermission().startsWith("libsdisguises.seecmd")) {
|
||||
Bukkit.getPluginManager().removePermission(cmd.getPermission());
|
||||
}
|
||||
|
||||
Iterator<Map.Entry<String, Command>> itel = commands.entrySet().iterator();
|
||||
|
||||
while (itel.hasNext()) {
|
||||
Map.Entry<String, Command> entry = itel.next();
|
||||
|
||||
if (entry.getValue() != cmd) {
|
||||
continue;
|
||||
}
|
||||
|
||||
itel.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFile() {
|
||||
return super.getFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
DisguiseUtilities.saveDisguises();
|
||||
|
||||
reloaded = true;
|
||||
}
|
||||
|
||||
public boolean isReleaseBuild() {
|
||||
return !getDescription().getVersion().contains("-SNAPSHOT");
|
||||
}
|
||||
|
||||
public String getBuildNo() {
|
||||
return buildNumber;
|
||||
}
|
||||
|
||||
public int getBuildNumber() {
|
||||
return isNumberedBuild() ? Integer.parseInt(getBuildNo()) : 0;
|
||||
}
|
||||
|
||||
public boolean isNumberedBuild() {
|
||||
return getBuildNo() != null && getBuildNo().matches("[0-9]+");
|
||||
}
|
||||
|
||||
private void registerCommand(String commandName, CommandExecutor executioner) {
|
||||
String name = commandConfig.getCommand(commandName);
|
||||
|
||||
if (name == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PluginCommand command = getCommand("libsdisguises:" + name);
|
||||
|
||||
if (command == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
command.setExecutor(executioner);
|
||||
|
||||
if (executioner instanceof TabCompleter) {
|
||||
command.setTabCompleter((TabCompleter) executioner);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the config with new config options.
|
||||
*/
|
||||
@Deprecated
|
||||
public void reload() {
|
||||
DisguiseConfig.loadConfig();
|
||||
}
|
||||
|
||||
public DisguiseListener getListener() {
|
||||
return listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* External APIs shouldn't actually need this instance. DisguiseAPI should be enough to handle most cases.
|
||||
*
|
||||
* @return The instance of this plugin
|
||||
*/
|
||||
public static LibsDisguises getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
@@ -0,0 +1,323 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.commands.disguise.DisguiseCommand;
|
||||
import me.libraryaddict.disguise.commands.disguise.DisguiseEntityCommand;
|
||||
import me.libraryaddict.disguise.commands.disguise.DisguisePlayerCommand;
|
||||
import me.libraryaddict.disguise.commands.disguise.DisguiseRadiusCommand;
|
||||
import me.libraryaddict.disguise.commands.modify.DisguiseModifyCommand;
|
||||
import me.libraryaddict.disguise.commands.modify.DisguiseModifyEntityCommand;
|
||||
import me.libraryaddict.disguise.commands.modify.DisguiseModifyPlayerCommand;
|
||||
import me.libraryaddict.disguise.commands.modify.DisguiseModifyRadiusCommand;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.params.ParamInfo;
|
||||
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
|
||||
import me.libraryaddict.disguise.utilities.parser.WatcherMethod;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author libraryaddict
|
||||
*/
|
||||
public abstract class DisguiseBaseCommand implements CommandExecutor {
|
||||
private static final Map<Class<? extends DisguiseBaseCommand>, String> disguiseCommands;
|
||||
private final Cache<UUID, Long> rateLimit = CacheBuilder.newBuilder().expireAfterWrite(500, TimeUnit.MILLISECONDS).build();
|
||||
|
||||
static {
|
||||
HashMap<Class<? extends DisguiseBaseCommand>, String> map = new HashMap<>();
|
||||
|
||||
map.put(DisguiseCommand.class, "Disguise");
|
||||
map.put(DisguiseEntityCommand.class, "DisguiseEntity");
|
||||
map.put(DisguisePlayerCommand.class, "DisguisePlayer");
|
||||
map.put(DisguiseRadiusCommand.class, "DisguiseRadius");
|
||||
map.put(DisguiseModifyCommand.class, "DisguiseModify");
|
||||
map.put(DisguiseModifyEntityCommand.class, "DisguiseModifyEntity");
|
||||
map.put(DisguiseModifyPlayerCommand.class, "DisguiseModifyPlayer");
|
||||
map.put(DisguiseModifyRadiusCommand.class, "DisguiseModifyRadius");
|
||||
|
||||
disguiseCommands = map;
|
||||
}
|
||||
|
||||
protected boolean hasHitRateLimit(CommandSender sender) {
|
||||
if (sender.isOp() || !(sender instanceof Player) || sender.hasPermission("libsdisguises.ratelimitbypass")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rateLimit.getIfPresent(((Player) sender).getUniqueId()) != null) {
|
||||
LibsMsg.TOO_FAST.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
rateLimit.put(((Player) sender).getUniqueId(), System.currentTimeMillis());
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isNotPremium(CommandSender sender) {
|
||||
String requiredProtocolLib = StringUtils.join(DisguiseUtilities.getProtocolLibRequiredVersion(), " or build #");
|
||||
String version = ProtocolLibrary.getPlugin().getDescription().getVersion();
|
||||
|
||||
if (DisguiseUtilities.isProtocolLibOutdated()) {
|
||||
DisguiseUtilities.sendProtocolLibUpdateMessage(sender, version, requiredProtocolLib);
|
||||
}
|
||||
|
||||
if (sender instanceof Player && !sender.isOp() &&
|
||||
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
|
||||
sender.sendMessage(ChatColor.RED + "This is the free version of Lib's Disguises, player commands are limited to console and " +
|
||||
"Operators only! Purchase the plugin for non-admin usage!");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected List<String> getTabDisguiseTypes(CommandSender sender, DisguisePermissions perms, String[] allArgs, int startsAt, String currentArg) {
|
||||
// If not enough arguments to get current disguise type
|
||||
if (allArgs.length <= startsAt) {
|
||||
return getAllowedDisguises(perms);
|
||||
}
|
||||
|
||||
// Get current disguise type
|
||||
DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(allArgs[startsAt]);
|
||||
|
||||
// If disguise type isn't found, return nothing
|
||||
if (disguiseType == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// If current argument is just after the disguise type, and disguise type is a player which is not a custom
|
||||
// disguise
|
||||
if (allArgs.length == startsAt + 1 && disguiseType.getType() == DisguiseType.PLAYER && !disguiseType.isCustomDisguise()) {
|
||||
ArrayList<String> tabs = new ArrayList<>();
|
||||
|
||||
// Add all player names to tab list
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
// If command user cannot see player online, don't tab-complete name
|
||||
if (sender instanceof Player && !((Player) sender).canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tabs.add(player.getName());
|
||||
}
|
||||
|
||||
// Return tablist
|
||||
return tabs;
|
||||
}
|
||||
|
||||
return getTabDisguiseOptions(sender, perms, disguiseType, allArgs, startsAt + (disguiseType.isPlayer() ? 2 : 1), currentArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param perms What permissions they can use
|
||||
* @param disguisePerm The disguise permission they're using
|
||||
* @param allArgs All the arguments in the command
|
||||
* @param startsAt What index this starts at
|
||||
* @return a list of viable disguise options
|
||||
*/
|
||||
protected List<String> getTabDisguiseOptions(CommandSender commandSender, DisguisePermissions perms, DisguisePerm disguisePerm, String[] allArgs,
|
||||
int startsAt, String currentArg) {
|
||||
ArrayList<String> usedOptions = new ArrayList<>();
|
||||
|
||||
WatcherMethod[] methods = ParamInfoManager.getDisguiseWatcherMethods(disguisePerm.getWatcherClass());
|
||||
|
||||
// Find which methods the disguiser has already used
|
||||
for (int i = startsAt; i < allArgs.length; i++) {
|
||||
for (WatcherMethod method : methods) {
|
||||
String arg = allArgs[i];
|
||||
|
||||
if (!method.getName().equalsIgnoreCase(arg)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
usedOptions.add(arg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If the disguiser has used options that they have not been granted to use, ignore them
|
||||
if (!perms.isAllowedDisguise(disguisePerm, usedOptions)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
return getTabDisguiseSubOptions(commandSender, perms, disguisePerm, allArgs, startsAt, currentArg);
|
||||
}
|
||||
|
||||
protected List<String> getTabDisguiseSubOptions(CommandSender commandSender, DisguisePermissions perms, DisguisePerm disguisePerm, String[] allArgs,
|
||||
int startsAt, String currentArg) {
|
||||
boolean addMethods = true;
|
||||
List<String> tabs = new ArrayList<>();
|
||||
|
||||
ParamInfo info = null;
|
||||
|
||||
if (allArgs.length == startsAt) {
|
||||
if (disguisePerm.getType() == DisguiseType.FALLING_BLOCK) {
|
||||
info = ParamInfoManager.getParamInfoItemBlock();
|
||||
} else if (disguisePerm.getType() == DisguiseType.DROPPED_ITEM) {
|
||||
info = ParamInfoManager.getParamInfo(ItemStack.class);
|
||||
}
|
||||
} else if (allArgs.length > startsAt) {
|
||||
// Check what argument was used before the current argument to see what we're displaying
|
||||
|
||||
String prevArg = allArgs[allArgs.length - 1];
|
||||
|
||||
info = ParamInfoManager.getParamInfo(disguisePerm, prevArg);
|
||||
|
||||
if (info != null && !info.isParam(boolean.class)) {
|
||||
addMethods = false;
|
||||
}
|
||||
|
||||
// Enderman can't hold non-blocks
|
||||
if (disguisePerm.getType() == DisguiseType.ENDERMAN && prevArg.equalsIgnoreCase("setItemInMainHand")) {
|
||||
info = ParamInfoManager.getParamInfoItemBlock();
|
||||
}
|
||||
}
|
||||
|
||||
// If the previous argument is a method
|
||||
if (info != null) {
|
||||
// If there is a list of default values
|
||||
if (info.hasValues()) {
|
||||
tabs.addAll(info.getEnums(currentArg));
|
||||
} else if (info.isParam(String.class)) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
// If command user cannot see player online, don't tab-complete name
|
||||
if (commandSender instanceof Player && !((Player) commandSender).canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tabs.add(player.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (addMethods) {
|
||||
// If this is a method, add. Else if it can be a param of the previous argument, add.
|
||||
for (WatcherMethod method : ParamInfoManager.getDisguiseWatcherMethods(disguisePerm.getWatcherClass())) {
|
||||
if (!perms.isAllowedDisguise(disguisePerm, Collections.singletonList(method.getName()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tabs.add(method.getName());
|
||||
}
|
||||
}
|
||||
|
||||
return tabs;
|
||||
}
|
||||
|
||||
protected List<String> filterTabs(List<String> list, String[] origArgs) {
|
||||
if (origArgs.length == 0) {
|
||||
return list;
|
||||
}
|
||||
|
||||
Iterator<String> itel = list.iterator();
|
||||
String label = origArgs[origArgs.length - 1].toLowerCase(Locale.ENGLISH);
|
||||
|
||||
while (itel.hasNext()) {
|
||||
String name = itel.next();
|
||||
|
||||
if (name.toLowerCase(Locale.ENGLISH).startsWith(label)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
itel.remove();
|
||||
}
|
||||
|
||||
return new ArrayList<>(new HashSet<>(list));
|
||||
}
|
||||
|
||||
protected String getDisplayName(CommandSender player) {
|
||||
String name = DisguiseConfig.getNameAboveDisguise().replace("%simple%", player.getName());
|
||||
|
||||
if (name.contains("%complex%")) {
|
||||
name = name.replace("%complex%", DisguiseUtilities.getDisplayName(player));
|
||||
}
|
||||
|
||||
return DisguiseUtilities.translateAlternateColorCodes(name);
|
||||
}
|
||||
|
||||
protected ArrayList<String> getAllowedDisguises(DisguisePermissions permissions) {
|
||||
ArrayList<String> allowedDisguises = new ArrayList<>();
|
||||
|
||||
for (DisguisePerm type : permissions.getAllowed()) {
|
||||
if (type.isUnknown()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
allowedDisguises.add(type.toReadable().replaceAll(" ", "_"));
|
||||
}
|
||||
|
||||
return allowedDisguises;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* @return Array of strings excluding current argument
|
||||
*/
|
||||
protected String[] getPreviousArgs(String[] args) {
|
||||
ArrayList<String> newArgs = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < args.length - 1; i++) {
|
||||
String s = args[i];
|
||||
|
||||
if (s.trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
newArgs.add(s);
|
||||
}
|
||||
|
||||
return newArgs.toArray(new String[0]);
|
||||
}
|
||||
|
||||
protected String getCurrentArg(String[] args) {
|
||||
if (args.length == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return args[args.length - 1].trim();
|
||||
}
|
||||
|
||||
protected static final Map<Class<? extends DisguiseBaseCommand>, String> getCommandNames() {
|
||||
return disguiseCommands;
|
||||
}
|
||||
|
||||
public final String getPermNode() {
|
||||
String name = getCommandNames().get(this.getClass());
|
||||
|
||||
if (name == null) {
|
||||
throw new UnsupportedOperationException("Unknown disguise command, perm node not found");
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
protected DisguisePermissions getPermissions(CommandSender sender) {
|
||||
return DisguiseParser.getPermissions(sender, getPermNode());
|
||||
}
|
||||
|
||||
protected boolean isInteger(String string) {
|
||||
try {
|
||||
Integer.parseInt(string);
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void sendCommandUsage(CommandSender sender, DisguisePermissions disguisePermissions);
|
||||
}
|
@@ -0,0 +1,163 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.commands.libsdisguises.*;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
|
||||
@Getter
|
||||
private final ArrayList<LDCommand> commands = new ArrayList<>();
|
||||
|
||||
public LibsDisguisesCommand() {
|
||||
getCommands().add(new LDHelp(this));
|
||||
getCommands().add(new LDReload());
|
||||
getCommands().add(new LDUpdate());
|
||||
getCommands().add(new LDChangelog());
|
||||
getCommands().add(new LDCount());
|
||||
getCommands().add(new LDConfig());
|
||||
getCommands().add(new LDPermTest());
|
||||
getCommands().add(new LDScoreboard());
|
||||
getCommands().add(new LDJson());
|
||||
getCommands().add(new LDMods());
|
||||
getCommands().add(new LDMetaInfo());
|
||||
getCommands().add(new LDDebugPlayer());
|
||||
getCommands().add(new LDUploadLogs());
|
||||
getCommands().add(new LDUpdateProtocolLib());
|
||||
getCommands().add(new LDDebugMineSkin());
|
||||
}
|
||||
|
||||
protected ArrayList<String> filterTabs(ArrayList<String> list, String[] origArgs) {
|
||||
if (origArgs.length == 0)
|
||||
return list;
|
||||
|
||||
Iterator<String> itel = list.iterator();
|
||||
String label = origArgs[origArgs.length - 1].toLowerCase(Locale.ENGLISH);
|
||||
|
||||
while (itel.hasNext()) {
|
||||
String name = itel.next();
|
||||
|
||||
if (name.toLowerCase(Locale.ENGLISH).startsWith(label))
|
||||
continue;
|
||||
|
||||
itel.remove();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
protected String[] getArgs(String[] args) {
|
||||
ArrayList<String> newArgs = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < args.length - 1; i++) {
|
||||
String s = args[i];
|
||||
|
||||
if (s.trim().isEmpty())
|
||||
continue;
|
||||
|
||||
newArgs.add(s);
|
||||
}
|
||||
|
||||
return newArgs.toArray(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (args.length == 0) {
|
||||
LibsDisguises disguises = LibsDisguises.getInstance();
|
||||
|
||||
String version = disguises.getDescription().getVersion();
|
||||
|
||||
if (!disguises.isReleaseBuild()) {
|
||||
version += "-";
|
||||
|
||||
if (disguises.isNumberedBuild()) {
|
||||
version += "b";
|
||||
}
|
||||
|
||||
version += disguises.getBuildNo();
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "This server is running Lib's Disguises " + "v" + version +
|
||||
" by libraryaddict, formerly maintained by Byteflux and NavidK0.");
|
||||
|
||||
if (sender.hasPermission("libsdisguises.reload")) {
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "Use " + ChatColor.GREEN + "/libsdisguises " + "reload" +
|
||||
ChatColor.DARK_GREEN + " to reload the config. All disguises will be blown by doing this" +
|
||||
".");
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "Use /libsdisguises help to see more help");
|
||||
}
|
||||
|
||||
if (LibsPremium.isPremium()) {
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "This server supports the plugin developer!");
|
||||
}
|
||||
} else if (args.length > 0) {
|
||||
LDCommand command = null;
|
||||
|
||||
for (LDCommand c : getCommands()) {
|
||||
if (!c.getTabComplete().contains(args[0].toLowerCase(Locale.ENGLISH))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
command = c;
|
||||
break;
|
||||
}
|
||||
|
||||
if (command != null) {
|
||||
if (!command.hasPermission(sender)) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
command.onCommand(sender, args);
|
||||
} else {
|
||||
LibsMsg.LIBS_COMMAND_WRONG_ARG.send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
|
||||
ArrayList<String> tabs = new ArrayList<>();
|
||||
String[] args = getArgs(origArgs);
|
||||
|
||||
for (LDCommand command : getCommands()) {
|
||||
if (!command.hasPermission(sender)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (origArgs.length <= 1) {
|
||||
tabs.addAll(command.getTabComplete());
|
||||
} else {
|
||||
for (String s : command.getTabComplete()) {
|
||||
if (!s.contains(" ")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String[] split = s.split(" ");
|
||||
|
||||
if (!args[0].equalsIgnoreCase(split[0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tabs.add(split[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return filterTabs(tabs, origArgs);
|
||||
}
|
||||
}
|
@@ -0,0 +1,139 @@
|
||||
package me.libraryaddict.disguise.commands.disguise;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (isNotPremium(sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Entity)) {
|
||||
LibsMsg.NO_CONSOLE.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
sendCommandUsage(sender, getPermissions(sender));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hasHitRateLimit(sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Disguise disguise;
|
||||
|
||||
try {
|
||||
disguise = DisguiseParser
|
||||
.parseDisguise(sender, (Entity) sender, getPermNode(), DisguiseUtilities.split(StringUtils.join(args, " ")), getPermissions(sender));
|
||||
} catch (DisguiseParseException ex) {
|
||||
ex.send(sender);
|
||||
|
||||
return true;
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise() && !sender.hasPermission("libsdisguises.hidename")) {
|
||||
if (disguise.getWatcher() instanceof LivingWatcher) {
|
||||
disguise.getWatcher().setCustomName(getDisplayName(sender));
|
||||
|
||||
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
|
||||
disguise.getWatcher().setCustomNameVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
disguise.setEntity((Player) sender);
|
||||
|
||||
if (!setViewDisguise(args)) {
|
||||
// They prefer to have the opposite of whatever the view disguises option is
|
||||
if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) && disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewSelfDisguisesDefault()) {
|
||||
disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible());
|
||||
}
|
||||
}
|
||||
|
||||
if (!DisguiseAPI.isNotifyBarShown(disguise.getEntity())) {
|
||||
disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE);
|
||||
}
|
||||
|
||||
disguise.startDisguise(sender);
|
||||
|
||||
if (disguise.isDisguiseInUse()) {
|
||||
LibsMsg.DISGUISED.send(sender, disguise.getDisguiseName());
|
||||
} else {
|
||||
LibsMsg.FAILED_DISGIUSE.send(sender, disguise.getDisguiseName());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean setViewDisguise(String[] strings) {
|
||||
for (String string : strings) {
|
||||
if (!string.equalsIgnoreCase("setSelfDisguiseVisible")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
|
||||
ArrayList<String> tabs = new ArrayList<>();
|
||||
String[] args = getPreviousArgs(origArgs);
|
||||
|
||||
DisguisePermissions perms = getPermissions(sender);
|
||||
|
||||
return filterTabs(getTabDisguiseTypes(sender, perms, args, 0, getCurrentArg(origArgs)), origArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the player the information
|
||||
*/
|
||||
@Override
|
||||
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
|
||||
|
||||
if (allowedDisguises.isEmpty()) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
LibsMsg.DISG_HELP1.send(sender);
|
||||
LibsMsg.CAN_USE_DISGS.send(sender, StringUtils.join(allowedDisguises, LibsMsg.CAN_USE_DISGS_SEPERATOR.get()));
|
||||
|
||||
if (allowedDisguises.contains("player")) {
|
||||
LibsMsg.DISG_HELP2.send(sender);
|
||||
}
|
||||
|
||||
LibsMsg.DISG_HELP3.send(sender);
|
||||
|
||||
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
|
||||
LibsMsg.DISG_HELP4.send(sender);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,109 @@
|
||||
package me.libraryaddict.disguise.commands.disguise;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
|
||||
import me.libraryaddict.disguise.commands.interactions.DisguiseEntityInteraction;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCompleter {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (isNotPremium(sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
LibsMsg.NO_CONSOLE.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!getPermissions(sender).hasPermissions()) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
sendCommandUsage(sender, getPermissions(sender));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hasHitRateLimit(sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(args, " "));
|
||||
Disguise testDisguise;
|
||||
|
||||
try {
|
||||
testDisguise = DisguiseParser.parseTestDisguise(sender, getPermNode(), disguiseArgs, getPermissions(sender));
|
||||
} catch (DisguiseParseException ex) {
|
||||
ex.send(sender);
|
||||
|
||||
return true;
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
|
||||
LibsDisguises.getInstance().getListener()
|
||||
.addInteraction(sender.getName(), new DisguiseEntityInteraction(disguiseArgs), DisguiseConfig.getDisguiseEntityExpire());
|
||||
|
||||
LibsMsg.DISG_ENT_CLICK.send(sender, DisguiseConfig.getDisguiseEntityExpire(), testDisguise.getDisguiseName());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
|
||||
ArrayList<String> tabs = new ArrayList<>();
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
return tabs;
|
||||
}
|
||||
|
||||
String[] args = getPreviousArgs(origArgs);
|
||||
|
||||
DisguisePermissions perms = getPermissions(sender);
|
||||
|
||||
return filterTabs(getTabDisguiseTypes(sender, perms, args, 0, getCurrentArg(origArgs)), origArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the player the information
|
||||
*/
|
||||
@Override
|
||||
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
|
||||
|
||||
if (allowedDisguises.isEmpty()) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
LibsMsg.DISG_ENT_HELP1.send(sender);
|
||||
LibsMsg.CAN_USE_DISGS.send(sender, StringUtils.join(allowedDisguises, LibsMsg.CAN_USE_DISGS_SEPERATOR.get()));
|
||||
|
||||
if (allowedDisguises.contains("player")) {
|
||||
LibsMsg.DISG_ENT_HELP3.send(sender);
|
||||
}
|
||||
|
||||
LibsMsg.DISG_ENT_HELP4.send(sender);
|
||||
|
||||
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
|
||||
LibsMsg.DISG_ENT_HELP5.send(sender);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,193 @@
|
||||
package me.libraryaddict.disguise.commands.disguise;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (isNotPremium(sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
DisguisePermissions permissions = getPermissions(sender);
|
||||
|
||||
if (!permissions.hasPermissions()) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
sendCommandUsage(sender, permissions);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
LibsMsg.DPLAYER_SUPPLY.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hasHitRateLimit(sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Entity entityTarget = Bukkit.getPlayer(args[0]);
|
||||
|
||||
if (entityTarget == null) {
|
||||
if (args[0].contains("-")) {
|
||||
try {
|
||||
entityTarget = Bukkit.getEntity(UUID.fromString(args[0]));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entityTarget == null) {
|
||||
LibsMsg.CANNOT_FIND_PLAYER.send(sender, args[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
String[] newArgs = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, newArgs, 0, newArgs.length);
|
||||
|
||||
if (newArgs.length == 0) {
|
||||
sendCommandUsage(sender, permissions);
|
||||
return true;
|
||||
}
|
||||
|
||||
Disguise disguise;
|
||||
|
||||
try {
|
||||
disguise = DisguiseParser.parseDisguise(sender, entityTarget, getPermNode(), DisguiseUtilities.split(StringUtils.join(newArgs, " ")), permissions);
|
||||
} catch (DisguiseParseException ex) {
|
||||
ex.send(sender);
|
||||
return true;
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()) {
|
||||
LibsMsg.DISABLED_LIVING_TO_MISC.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise() && !entityTarget.hasPermission("libsdisguises.hidename")) {
|
||||
if (disguise.getWatcher() instanceof LivingWatcher) {
|
||||
disguise.getWatcher().setCustomName(getDisplayName(entityTarget));
|
||||
|
||||
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
|
||||
disguise.getWatcher().setCustomNameVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
disguise.setEntity(entityTarget);
|
||||
|
||||
if (!setViewDisguise(args)) {
|
||||
// They prefer to have the opposite of whatever the view disguises option is
|
||||
if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) && disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewSelfDisguisesDefault()) {
|
||||
disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible());
|
||||
}
|
||||
}
|
||||
|
||||
if (!DisguiseAPI.isNotifyBarShown(disguise.getEntity())) {
|
||||
disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE);
|
||||
}
|
||||
|
||||
disguise.startDisguise(sender);
|
||||
|
||||
if (disguise.isDisguiseInUse()) {
|
||||
LibsMsg.DISG_PLAYER_AS_DISG.send(sender, entityTarget instanceof Player ? entityTarget.getName() : DisguiseType.getType(entityTarget).toReadable(),
|
||||
disguise.getDisguiseName());
|
||||
} else {
|
||||
LibsMsg.DISG_PLAYER_AS_DISG_FAIL
|
||||
.send(sender, entityTarget instanceof Player ? entityTarget.getName() : DisguiseType.getType(entityTarget).toReadable(),
|
||||
disguise.getDisguiseName());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean setViewDisguise(String[] strings) {
|
||||
for (String string : strings) {
|
||||
if (!string.equalsIgnoreCase("setSelfDisguiseVisible")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
|
||||
ArrayList<String> tabs = new ArrayList<>();
|
||||
String[] args = getPreviousArgs(origArgs);
|
||||
|
||||
DisguisePermissions perms = getPermissions(sender);
|
||||
|
||||
if (args.length == 0) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
// If command user cannot see player online, don't tab-complete name
|
||||
if (sender instanceof Player && !((Player) sender).canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tabs.add(player.getName());
|
||||
}
|
||||
} else {
|
||||
tabs.addAll(getTabDisguiseTypes(sender, perms, args, 1, getCurrentArg(origArgs)));
|
||||
}
|
||||
|
||||
return filterTabs(tabs, origArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the player the information
|
||||
*/
|
||||
@Override
|
||||
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
|
||||
|
||||
if (allowedDisguises.isEmpty()) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
LibsMsg.D_HELP1.send(sender);
|
||||
LibsMsg.CAN_USE_DISGS.send(sender, StringUtils.join(allowedDisguises, LibsMsg.CAN_USE_DISGS_SEPERATOR.get()));
|
||||
|
||||
if (allowedDisguises.contains("player")) {
|
||||
LibsMsg.D_HELP3.send(sender);
|
||||
}
|
||||
|
||||
LibsMsg.D_HELP4.send(sender);
|
||||
|
||||
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
|
||||
LibsMsg.D_HELP5.send(sender);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,303 @@
|
||||
package me.libraryaddict.disguise.commands.disguise;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import me.libraryaddict.disguise.utilities.translations.TranslateType;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCompleter {
|
||||
private ArrayList<Class<? extends Entity>> validClasses = new ArrayList<>();
|
||||
|
||||
public DisguiseRadiusCommand() {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
Class c = type.getEntityClass();
|
||||
|
||||
while (c != null && Entity.class.isAssignableFrom(c) && !validClasses.contains(c)) {
|
||||
validClasses.add(c);
|
||||
|
||||
c = c.getSuperclass();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (isNotPremium(sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender.getName().equals("CONSOLE")) {
|
||||
LibsMsg.NO_CONSOLE.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
DisguisePermissions permissions = getPermissions(sender);
|
||||
|
||||
if (!permissions.hasPermissions()) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
sendCommandUsage(sender, permissions);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hasHitRateLimit(sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("EntityType")) || args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("EntityType") + "s")) {
|
||||
ArrayList<String> classes = new ArrayList<>();
|
||||
|
||||
for (Class c : validClasses) {
|
||||
classes.add(TranslateType.DISGUISES.get(c.getSimpleName()));
|
||||
}
|
||||
|
||||
Collections.sort(classes);
|
||||
|
||||
LibsMsg.DRADIUS_ENTITIES.send(sender, ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN));
|
||||
return true;
|
||||
}
|
||||
|
||||
Class entityClass = Entity.class;
|
||||
EntityType type = null;
|
||||
int starting = 0;
|
||||
|
||||
if (!isInteger(args[0])) {
|
||||
for (Class c : validClasses) {
|
||||
if (TranslateType.DISGUISES.get(c.getSimpleName()).equalsIgnoreCase(args[0])) {
|
||||
entityClass = c;
|
||||
starting = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (starting == 0) {
|
||||
try {
|
||||
type = EntityType.valueOf(args[0].toUpperCase(Locale.ENGLISH));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
if (type == null) {
|
||||
LibsMsg.DMODRADIUS_UNRECOGNIZED.send(sender, args[0]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length == starting + 1) {
|
||||
if (starting == 0) {
|
||||
LibsMsg.DRADIUS_NEEDOPTIONS.send(sender);
|
||||
} else {
|
||||
LibsMsg.DRADIUS_NEEDOPTIONS_ENTITY.send(sender);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (args.length < 2) {
|
||||
LibsMsg.DRADIUS_NEEDOPTIONS.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isInteger(args[starting])) {
|
||||
LibsMsg.NOT_NUMBER.send(sender, args[starting]);
|
||||
return true;
|
||||
}
|
||||
|
||||
int radius = Integer.parseInt(args[starting]);
|
||||
|
||||
if (radius > DisguiseConfig.getDisguiseRadiusMax()) {
|
||||
LibsMsg.LIMITED_RADIUS.send(sender, DisguiseConfig.getDisguiseRadiusMax());
|
||||
radius = DisguiseConfig.getDisguiseRadiusMax();
|
||||
}
|
||||
|
||||
String[] newArgs = new String[args.length - (starting + 1)];
|
||||
System.arraycopy(args, starting + 1, newArgs, 0, newArgs.length);
|
||||
|
||||
if (newArgs.length == 0) {
|
||||
sendCommandUsage(sender, permissions);
|
||||
return true;
|
||||
}
|
||||
|
||||
String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(newArgs, " "));
|
||||
|
||||
try {
|
||||
|
||||
Disguise testDisguise = DisguiseParser.parseTestDisguise(sender, getPermNode(), disguiseArgs, permissions);
|
||||
|
||||
// Time to use it!
|
||||
int disguisedEntitys = 0;
|
||||
int miscDisguises = 0;
|
||||
|
||||
Location center;
|
||||
|
||||
if (sender instanceof Player) {
|
||||
center = ((Player) sender).getLocation();
|
||||
} else {
|
||||
center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5);
|
||||
}
|
||||
|
||||
for (Entity entity : center.getWorld().getNearbyEntities(center, radius, radius, radius)) {
|
||||
if (entity == sender) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type != null ? entity.getType() != type : !entityClass.isAssignableFrom(entity.getClass())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (testDisguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) {
|
||||
miscDisguises++;
|
||||
continue;
|
||||
}
|
||||
|
||||
Disguise disguise = DisguiseParser.parseDisguise(sender, entity, getPermNode(), disguiseArgs, permissions);
|
||||
|
||||
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise() && !entity.hasPermission("libsdisguises.hidename")) {
|
||||
if (disguise.getWatcher() instanceof LivingWatcher) {
|
||||
disguise.getWatcher().setCustomName(getDisplayName(entity));
|
||||
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
|
||||
disguise.getWatcher().setCustomNameVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
disguise.setEntity(entity);
|
||||
|
||||
if (!setViewDisguise(args)) {
|
||||
// They prefer to have the opposite of whatever the view disguises option is
|
||||
if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) && disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewSelfDisguisesDefault()) {
|
||||
disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible());
|
||||
}
|
||||
}
|
||||
|
||||
if (!DisguiseAPI.isNotifyBarShown(disguise.getEntity())) {
|
||||
disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE);
|
||||
}
|
||||
|
||||
disguise.startDisguise(sender);
|
||||
|
||||
if (disguise.isDisguiseInUse()) {
|
||||
disguisedEntitys++;
|
||||
}
|
||||
}
|
||||
|
||||
if (disguisedEntitys > 0) {
|
||||
LibsMsg.DISRADIUS.send(sender, disguisedEntitys);
|
||||
} else {
|
||||
LibsMsg.DISRADIUS_FAIL.send(sender);
|
||||
}
|
||||
|
||||
if (miscDisguises > 0) {
|
||||
LibsMsg.DRADIUS_MISCDISG.send(sender, miscDisguises);
|
||||
}
|
||||
} catch (DisguiseParseException ex) {
|
||||
ex.send(sender);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean setViewDisguise(String[] strings) {
|
||||
for (String string : strings) {
|
||||
if (!string.equalsIgnoreCase("setSelfDisguiseVisible")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
|
||||
ArrayList<String> tabs = new ArrayList<>();
|
||||
String[] args = getPreviousArgs(origArgs);
|
||||
|
||||
DisguisePermissions perms = getPermissions(sender);
|
||||
|
||||
if (args.length == 0) {
|
||||
for (Class<? extends Entity> entityClass : validClasses) {
|
||||
tabs.add(TranslateType.DISGUISES.get(entityClass.getSimpleName()));
|
||||
}
|
||||
|
||||
return filterTabs(tabs, origArgs);
|
||||
}
|
||||
|
||||
int starting = 1;
|
||||
|
||||
if (!isInteger(args[0])) {
|
||||
for (Class c : validClasses) {
|
||||
if (!TranslateType.DISGUISES.get(c.getSimpleName()).equalsIgnoreCase(args[0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
starting = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
// Not a valid radius
|
||||
if (starting == 1 || args.length == 1 || !isInteger(args[1])) {
|
||||
return filterTabs(tabs, origArgs);
|
||||
}
|
||||
}
|
||||
|
||||
tabs.addAll(getTabDisguiseTypes(sender, perms, args, starting, getCurrentArg(origArgs)));
|
||||
|
||||
return filterTabs(tabs, origArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the player the information
|
||||
*/
|
||||
@Override
|
||||
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
|
||||
|
||||
if (allowedDisguises.isEmpty()) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
LibsMsg.DRADIUS_HELP1.send(sender, DisguiseConfig.getDisguiseRadiusMax());
|
||||
LibsMsg.CAN_USE_DISGS.send(sender, StringUtils.join(allowedDisguises, LibsMsg.CAN_USE_DISGS_SEPERATOR.get()));
|
||||
|
||||
if (allowedDisguises.contains("player")) {
|
||||
LibsMsg.DRADIUS_HELP3.send(sender);
|
||||
}
|
||||
|
||||
LibsMsg.DRADIUS_HELP4.send(sender);
|
||||
|
||||
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
|
||||
LibsMsg.DRADIUS_HELP5.send(sender);
|
||||
}
|
||||
|
||||
LibsMsg.DRADIUS_HELP6.send(sender);
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package me.libraryaddict.disguise.commands.interactions;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.commands.utils.CopyDisguiseCommand;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.utilities.LibsEntityInteract;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 4/04/2020.
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class CopyDisguiseInteraction implements LibsEntityInteract {
|
||||
private CopyDisguiseCommand copyDisguiseCommand;
|
||||
|
||||
@Override
|
||||
public void onInteract(Player player, Entity entity) {
|
||||
if (DisguiseAPI.isDisguised(entity)) {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(player, entity);
|
||||
String disguiseString = DisguiseParser.parseToString(disguise, false);
|
||||
|
||||
getCopyDisguiseCommand()
|
||||
.sendMessage(player, LibsMsg.CLICK_TO_COPY, LibsMsg.COPY_DISGUISE_NO_COPY, disguiseString, false);
|
||||
|
||||
if (disguise instanceof PlayerDisguise) {
|
||||
getCopyDisguiseCommand()
|
||||
.sendMessage(player, LibsMsg.CLICK_TO_COPY_WITH_SKIN, LibsMsg.CLICK_TO_COPY_WITH_SKIN_NO_COPY,
|
||||
DisguiseParser.parseToString(disguise), true);
|
||||
}
|
||||
} else {
|
||||
LibsMsg.TARGET_NOT_DISGUISED.send(player);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package me.libraryaddict.disguise.commands.interactions;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsEntityInteract;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 4/04/2020.
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class DisguiseCloneInteraction implements LibsEntityInteract {
|
||||
private Boolean[] options;
|
||||
|
||||
@Override
|
||||
public void onInteract(Player player, Entity entity) {
|
||||
DisguiseUtilities.createClonedDisguise(player, entity, options);
|
||||
}
|
||||
}
|
@@ -0,0 +1,107 @@
|
||||
package me.libraryaddict.disguise.commands.interactions;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsEntityInteract;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 4/04/2020.
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class DisguiseEntityInteraction implements LibsEntityInteract {
|
||||
private String[] disguiseArgs;
|
||||
|
||||
@Override
|
||||
public void onInteract(Player p, Entity entity) {
|
||||
String entityName;
|
||||
|
||||
if (entity instanceof Player) {
|
||||
entityName = entity.getName();
|
||||
} else {
|
||||
entityName = DisguiseType.getType(entity).toReadable();
|
||||
}
|
||||
|
||||
Disguise disguise;
|
||||
|
||||
try {
|
||||
disguise = DisguiseParser.parseDisguise(p, entity, "disguiseentity", disguiseArgs, DisguiseParser.getPermissions(p, "disguiseentity"));
|
||||
} catch (DisguiseParseException e) {
|
||||
e.send(p);
|
||||
return;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) {
|
||||
LibsMsg.DISABLED_LIVING_TO_MISC.send(p);
|
||||
} else {
|
||||
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise() && !entity.hasPermission("libsdisguises.hidename")) {
|
||||
if (disguise.getWatcher() instanceof LivingWatcher) {
|
||||
disguise.getWatcher().setCustomName(getDisplayName(entity));
|
||||
|
||||
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
|
||||
disguise.getWatcher().setCustomNameVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DisguiseAPI.disguiseEntity(p, entity, disguise);
|
||||
|
||||
String disguiseName = disguise.getDisguiseName();
|
||||
|
||||
// Jeez, maybe I should redo my messages here
|
||||
if (disguise.isDisguiseInUse()) {
|
||||
if (disguise.isPlayerDisguise()) {
|
||||
if (entity instanceof Player) {
|
||||
LibsMsg.LISTEN_ENTITY_PLAYER_DISG_PLAYER.send(p, entityName, disguiseName);
|
||||
} else {
|
||||
LibsMsg.LISTEN_ENTITY_ENTITY_DISG_PLAYER.send(p, entityName, disguiseName);
|
||||
}
|
||||
} else {
|
||||
if (entity instanceof Player) {
|
||||
LibsMsg.LISTEN_ENTITY_PLAYER_DISG_ENTITY.send(p, entityName, disguiseName);
|
||||
} else {
|
||||
LibsMsg.LISTEN_ENTITY_ENTITY_DISG_ENTITY.send(p, entityName, disguiseName);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (disguise.isPlayerDisguise()) {
|
||||
if (entity instanceof Player) {
|
||||
LibsMsg.LISTEN_ENTITY_PLAYER_DISG_PLAYER_FAIL.send(p, entityName, disguiseName);
|
||||
} else {
|
||||
LibsMsg.LISTEN_ENTITY_ENTITY_DISG_PLAYER_FAIL.send(p, entityName, disguiseName);
|
||||
}
|
||||
} else {
|
||||
if (entity instanceof Player) {
|
||||
LibsMsg.LISTEN_ENTITY_PLAYER_DISG_ENTITY_FAIL.send(p, entityName, disguiseName);
|
||||
} else {
|
||||
LibsMsg.LISTEN_ENTITY_ENTITY_DISG_ENTITY_FAIL.send(p, entityName, disguiseName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String getDisplayName(CommandSender player) {
|
||||
String name = DisguiseConfig.getNameAboveDisguise().replace("%simple%", player.getName());
|
||||
|
||||
if (name.contains("%complex%")) {
|
||||
name = name.replace("%complex%", DisguiseUtilities.getDisplayName(player));
|
||||
}
|
||||
|
||||
return DisguiseUtilities.translateAlternateColorCodes(name);
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
package me.libraryaddict.disguise.commands.interactions;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.utilities.LibsEntityInteract;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 4/04/2020.
|
||||
*/
|
||||
|
||||
@AllArgsConstructor
|
||||
public class DisguiseModifyInteraction implements LibsEntityInteract {
|
||||
private String[] options;
|
||||
|
||||
@Override
|
||||
public void onInteract(Player p, Entity entity) {
|
||||
String entityName;
|
||||
|
||||
if (entity instanceof Player) {
|
||||
entityName = entity.getName();
|
||||
} else {
|
||||
entityName = DisguiseType.getType(entity).toReadable();
|
||||
}
|
||||
|
||||
Disguise disguise = DisguiseAPI.getDisguise(p, entity);
|
||||
|
||||
if (disguise == null) {
|
||||
LibsMsg.UNDISG_PLAYER_FAIL.send(p, entityName);
|
||||
return;
|
||||
}
|
||||
|
||||
options = DisguiseParser.parsePlaceholders(options, p, entity);
|
||||
|
||||
DisguisePermissions perms = DisguiseParser.getPermissions(p, "disguiseentitymodify");
|
||||
DisguisePerm disguisePerm = new DisguisePerm(disguise.getType());
|
||||
|
||||
if (!perms.isAllowedDisguise(disguisePerm, Arrays.asList(options))) {
|
||||
LibsMsg.DMODPLAYER_NOPERM.send(p);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
DisguiseParser.callMethods(p, disguise, perms, disguisePerm, new ArrayList<>(Arrays.asList(options)), options, "DisguiseModifyEntity");
|
||||
LibsMsg.LISTENER_MODIFIED_DISG.send(p);
|
||||
} catch (DisguiseParseException ex) {
|
||||
ex.send(p);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package me.libraryaddict.disguise.commands.interactions;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.utilities.LibsEntityInteract;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 4/04/2020.
|
||||
*/
|
||||
public class UndisguiseEntityInteraction implements LibsEntityInteract {
|
||||
@Override
|
||||
public void onInteract(Player p, Entity entity) {
|
||||
String entityName;
|
||||
|
||||
if (entity instanceof Player) {
|
||||
entityName = entity.getName();
|
||||
} else {
|
||||
entityName = DisguiseType.getType(entity).toReadable();
|
||||
}
|
||||
|
||||
if (DisguiseAPI.isDisguised(entity)) {
|
||||
DisguiseAPI.undisguiseToAll(p, entity);
|
||||
|
||||
if (entity instanceof Player)
|
||||
LibsMsg.LISTEN_UNDISG_PLAYER.send(p, entityName);
|
||||
else
|
||||
LibsMsg.LISTEN_UNDISG_ENT.send(p, entityName);
|
||||
} else {
|
||||
if (entity instanceof Player)
|
||||
LibsMsg.LISTEN_UNDISG_PLAYER_FAIL.send(p, entityName);
|
||||
else
|
||||
LibsMsg.LISTEN_UNDISG_ENT_FAIL.send(p, entityName);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import me.libraryaddict.disguise.utilities.updates.UpdateChecker;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 27/04/2020.
|
||||
*/
|
||||
public class LDChangelog implements LDCommand {
|
||||
@Override
|
||||
public List<String> getTabComplete() {
|
||||
return Collections.singletonList("changelog");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender.hasPermission(getPermission());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "libsdisguises.update";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
UpdateChecker checker = LibsDisguises.getInstance().getUpdateChecker();
|
||||
|
||||
if (checker.isDownloading()) {
|
||||
LibsMsg.UPDATE_IN_PROGRESS.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (checker.getUpdate() == null) {
|
||||
LibsMsg.UPDATE_REQUIRED.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!checker.getUpdate().isReleaseBuild()) {
|
||||
sender.sendMessage(
|
||||
ChatColor.GOLD + "You are on build " + (LibsDisguises.getInstance().isNumberedBuild() ? "#" : "") +
|
||||
LibsDisguises.getInstance().getBuildNo());
|
||||
}
|
||||
|
||||
for (String msg : checker.getUpdate().getChangelog()) {
|
||||
sender.sendMessage(ChatColor.GOLD + msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibsMsg getHelp() {
|
||||
return LibsMsg.LD_COMMAND_CHANGELOG;
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 20/04/2020.
|
||||
*/
|
||||
public interface LDCommand {
|
||||
List<String> getTabComplete();
|
||||
|
||||
boolean hasPermission(CommandSender sender);
|
||||
|
||||
String getPermission();
|
||||
|
||||
void onCommand(CommandSender sender, String[] args);
|
||||
|
||||
LibsMsg getHelp();
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 20/04/2020.
|
||||
*/
|
||||
public class LDConfig implements LDCommand {
|
||||
@Override
|
||||
public List<String> getTabComplete() {
|
||||
return Arrays.asList("config", "configuration");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender.hasPermission(getPermission());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "libsdisguises.config";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
ArrayList<String> returns = DisguiseConfig.doOutput(true, true);
|
||||
|
||||
if (returns.isEmpty()) {
|
||||
LibsMsg.USING_DEFAULT_CONFIG.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
for (String s : returns) {
|
||||
sender.sendMessage(ChatColor.AQUA + "[LibsDisguises] " + s);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibsMsg getHelp() {
|
||||
return LibsMsg.LD_COMMAND_CONFIG;
|
||||
}
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import me.libraryaddict.disguise.utilities.translations.TranslateType;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 20/04/2020.
|
||||
*/
|
||||
public class LDCount implements LDCommand {
|
||||
@Override
|
||||
public List<String> getTabComplete() {
|
||||
return Collections.singletonList("count");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "libsdisguises.count";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
HashMap<DisguiseType, Integer> counts = new HashMap<>();
|
||||
|
||||
for (Set<TargetedDisguise> disguises : DisguiseUtilities.getDisguises().values()) {
|
||||
for (Disguise disguise : disguises) {
|
||||
counts.compute(disguise.getType(), (a, b) -> (b != null ? b : 0) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (counts.isEmpty()) {
|
||||
LibsMsg.NO_DISGUISES_IN_USE.send(sender);
|
||||
} else {
|
||||
LibsMsg.ACTIVE_DISGUISES_COUNT.send(sender,
|
||||
counts.values().stream().reduce(Integer::sum).get());
|
||||
|
||||
ArrayList<DisguiseType> types = new ArrayList<>(counts.keySet());
|
||||
types.sort((d1, d2) -> String.CASE_INSENSITIVE_ORDER.compare(TranslateType.DISGUISES.get(d1.toReadable()),
|
||||
TranslateType.DISGUISES.get(d2.toReadable())));
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < types.size(); i++) {
|
||||
builder.append(LibsMsg.ACTIVE_DISGUISES_DISGUISE
|
||||
.get(TranslateType.DISGUISES.get(types.get(i).toReadable()), counts.get(types.get(i))));
|
||||
|
||||
if (i + 1 < types.size()) {
|
||||
builder.append(LibsMsg.ACTIVE_DISGUISES_SEPERATOR.get());
|
||||
}
|
||||
}
|
||||
|
||||
LibsMsg.ACTIVE_DISGUISES.send(sender, builder.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender.hasPermission(getPermission());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibsMsg getHelp() {
|
||||
return LibsMsg.LD_COMMAND_COUNT;
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.mineskin.MineSkinAPI;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 22/05/2021.
|
||||
*/
|
||||
public class LDDebugMineSkin implements LDCommand {
|
||||
@Override
|
||||
public List<String> getTabComplete() {
|
||||
return Collections.singletonList("mineskin");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender.hasPermission(getPermission());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "libsdisguises.mineskin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
MineSkinAPI api = DisguiseUtilities.getMineSkinAPI();
|
||||
api.setDebugging(!api.isDebugging());
|
||||
|
||||
LibsMsg.LD_DEBUG_MINESKIN_TOGGLE.send(sender, api.isDebugging());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibsMsg getHelp() {
|
||||
return LibsMsg.LD_DEBUG_MINESKIN;
|
||||
}
|
||||
}
|
@@ -0,0 +1,114 @@
|
||||
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsEntityInteract;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 24/04/2020.
|
||||
*/
|
||||
public class LDDebugPlayer implements LDCommand {
|
||||
public class DebugInteraction implements LibsEntityInteract {
|
||||
@Override
|
||||
public void onInteract(Player player, Entity entity) {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(player, entity);
|
||||
|
||||
if (disguise == null) {
|
||||
LibsMsg.TARGET_NOT_DISGUISED.send(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!disguise.isPlayerDisguise()) {
|
||||
player.sendMessage(ChatColor.RED + "Meant to be used on player disguises!");
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerDisguise disg = (PlayerDisguise) disguise;
|
||||
|
||||
player.sendMessage(ChatColor.RED + "Name: " + disg.getName().replace(ChatColor.COLOR_CHAR, '&'));
|
||||
|
||||
if (!disg.hasScoreboardName()) {
|
||||
player.sendMessage(ChatColor.RED + "Disguise doesn't have scoreboard name, can't say more.");
|
||||
return;
|
||||
}
|
||||
|
||||
DisguiseUtilities.DScoreTeam name = disg.getScoreboardName();
|
||||
|
||||
player.sendMessage(ChatColor.RED +
|
||||
String.format("Prefix: '%s', Suffix: '%s', Disguise Name: '%s', Team '%s'",
|
||||
name.getPrefix().replace(ChatColor.COLOR_CHAR, '&'),
|
||||
name.getSuffix().replace(ChatColor.COLOR_CHAR, '&'),
|
||||
name.getPlayer().replace(ChatColor.COLOR_CHAR, '&'), name.getTeamName()));
|
||||
|
||||
if (DisguiseConfig.isArmorstandsName()) {
|
||||
player.sendMessage(
|
||||
ChatColor.AQUA + "Oh! You're using armorstands! Lets give some debug for that too..");
|
||||
player.sendMessage(ChatColor.RED + String.format("Names: %s, Length: %s, Custom Name: '%s'",
|
||||
new Gson().toJson(disg.getMultiName()).replace(ChatColor.COLOR_CHAR, '&'),
|
||||
disg.getMultiNameLength(),
|
||||
disg.getWatcher().getCustomName().replace(ChatColor.COLOR_CHAR, '&')));
|
||||
}
|
||||
|
||||
Team team = player.getScoreboard().getTeam(name.getTeamName());
|
||||
|
||||
if (team == null) {
|
||||
player.sendMessage(ChatColor.RED + "That team doesn't exist to you");
|
||||
|
||||
if (Bukkit.getScoreboardManager().getMainScoreboard().getTeam(name.getTeamName()) != null) {
|
||||
player.sendMessage(ChatColor.RED + "But it does exist on the main scoreboard..");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(ChatColor.RED +
|
||||
String.format("Prefix Matches: %s, Suffix Matches: %s, In Team: %s, Name Visibility: %s",
|
||||
team.getPrefix().equals(name.getPrefix()), team.getSuffix().equals(name.getSuffix()),
|
||||
team.hasEntry(name.getPlayer()), team.getOption(Team.Option.NAME_TAG_VISIBILITY)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabComplete() {
|
||||
return Collections.singletonList("debug");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender.hasPermission(getPermission());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "libsdisguises.debug";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
}
|
||||
|
||||
LibsDisguises.getInstance().getListener().addInteraction(sender.getName(), new DebugInteraction(), 60);
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "Right click a disguised player to get some debug outta em");
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibsMsg getHelp() {
|
||||
return LibsMsg.LD_COMMAND_DEBUG;
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import me.libraryaddict.disguise.commands.LibsDisguisesCommand;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 22/04/2020.
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public class LDHelp implements LDCommand {
|
||||
private LibsDisguisesCommand command;
|
||||
|
||||
@Override
|
||||
public List<String> getTabComplete() {
|
||||
return Collections.singletonList("help");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return getCommand().getCommands().stream().anyMatch(c -> c.getPermission() != null && c.hasPermission(sender));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
for (LDCommand cmd : command.getCommands()) {
|
||||
if (!cmd.hasPermission(sender)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cmd.getHelp().send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibsMsg getHelp() {
|
||||
return LibsMsg.LD_COMMAND_HELP;
|
||||
}
|
||||
}
|
@@ -0,0 +1,135 @@
|
||||
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 20/04/2020.
|
||||
*/
|
||||
public class LDJson implements LDCommand {
|
||||
@Override
|
||||
public List<String> getTabComplete() {
|
||||
return Arrays.asList("json", "gson", "tostring", "item", "parse");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "libsdisguises.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
LibsMsg.NO_CONSOLE.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack item = ((Player) sender).getInventory().getItemInMainHand();
|
||||
|
||||
String gson = DisguiseUtilities.getGson().toJson(item);
|
||||
String simple = ParamInfoManager.toString(item);
|
||||
|
||||
// item{nbt} amount
|
||||
// item amount data {nbt}
|
||||
|
||||
String itemName = ReflectionManager.getItemName(item.getType());
|
||||
ArrayList<String> mcArray = new ArrayList<>();
|
||||
|
||||
if (NmsVersion.v1_13.isSupported() && item.hasItemMeta()) {
|
||||
mcArray.add(itemName + DisguiseUtilities.serialize(NbtFactory.fromItemTag(item)));
|
||||
} else {
|
||||
mcArray.add(itemName);
|
||||
}
|
||||
|
||||
if (item.getAmount() != 1) {
|
||||
mcArray.add(String.valueOf(item.getAmount()));
|
||||
}
|
||||
|
||||
if (!NmsVersion.v1_13.isSupported()) {
|
||||
if (item.getDurability() != 0) {
|
||||
mcArray.add(String.valueOf(item.getDurability()));
|
||||
}
|
||||
|
||||
if (item.hasItemMeta()) {
|
||||
mcArray.add(DisguiseUtilities.serialize(NbtFactory.fromItemTag(item)));
|
||||
}
|
||||
}
|
||||
|
||||
String ldItem = StringUtils.join(mcArray, "-");
|
||||
String mcItem = StringUtils.join(mcArray, " ");
|
||||
|
||||
sendMessage(sender, LibsMsg.ITEM_SERIALIZED, LibsMsg.ITEM_SERIALIZED_NO_COPY, gson);
|
||||
|
||||
if (!gson.equals(simple) && !ldItem.equals(simple) && !mcItem.equals(simple)) {
|
||||
sendMessage(sender, LibsMsg.ITEM_SIMPLE_STRING, LibsMsg.ITEM_SIMPLE_STRING_NO_COPY, simple);
|
||||
}
|
||||
|
||||
sendMessage(sender, LibsMsg.ITEM_SERIALIZED_MC, LibsMsg.ITEM_SERIALIZED_MC_NO_COPY, mcItem);
|
||||
|
||||
if (mcArray.size() > 1) {
|
||||
sendMessage(sender, LibsMsg.ITEM_SERIALIZED_MC, LibsMsg.ITEM_SERIALIZED_MC_NO_COPY, ldItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendMessage(CommandSender sender, LibsMsg prefix, LibsMsg oldVer, String string) {
|
||||
/* if (!NmsVersion.v1_13.isSupported()) {
|
||||
oldVer.send(sender, string);
|
||||
return;
|
||||
}*/
|
||||
|
||||
int start = 0;
|
||||
int msg = 1;
|
||||
|
||||
ComponentBuilder builder = new ComponentBuilder("").append(prefix.getBase());
|
||||
|
||||
while (start < string.length()) {
|
||||
int end = Math.min(256, string.length() - start);
|
||||
|
||||
String sub = string.substring(start, start + end);
|
||||
|
||||
builder.append(" ");
|
||||
|
||||
if (string.length() <= 256) {
|
||||
builder.append(LibsMsg.CLICK_TO_COPY_DATA.getBase());
|
||||
} else {
|
||||
builder.reset();
|
||||
builder.append(LibsMsg.CLICK_COPY.getBase(msg));
|
||||
}
|
||||
|
||||
start += end;
|
||||
|
||||
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, sub));
|
||||
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new ComponentBuilder("").append(LibsMsg.CLICK_TO_COPY_HOVER.getBase()).append((string.length() <= 256 ? "" : " " + msg))
|
||||
.create()));
|
||||
msg += 1;
|
||||
}
|
||||
|
||||
sender.spigot().sendMessage(builder.create());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender.hasPermission(getPermission());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibsMsg getHelp() {
|
||||
return LibsMsg.LD_COMMAND_JSON;
|
||||
}
|
||||
}
|
@@ -0,0 +1,84 @@
|
||||
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 20/04/2020.
|
||||
*/
|
||||
public class LDMetaInfo implements LDCommand {
|
||||
@Override
|
||||
public List<String> getTabComplete() {
|
||||
return Arrays.asList("metainfo", "metadata", "metadatainfo", "metaindex");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "libsdisguises.metainfo";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
if (args.length > 1) {
|
||||
MetaIndex index = MetaIndex.getMetaIndexByName(args[1]);
|
||||
|
||||
if (index == null) {
|
||||
LibsMsg.META_NOT_FOUND.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(index.toString());
|
||||
} else {
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
|
||||
for (MetaIndex index : MetaIndex.values()) {
|
||||
names.add(MetaIndex.getName(index));
|
||||
}
|
||||
|
||||
names.sort(String::compareToIgnoreCase);
|
||||
|
||||
// if (NmsVersion.v1_13.isSupported()) {
|
||||
ComponentBuilder builder = new ComponentBuilder("").append(LibsMsg.META_VALUES.getBase());
|
||||
|
||||
Iterator<String> itel = names.iterator();
|
||||
|
||||
while (itel.hasNext()) {
|
||||
String name = itel.next();
|
||||
|
||||
builder.append(TextComponent.fromLegacyText(name));
|
||||
builder.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/libsdisguises metainfo " + name));
|
||||
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, LibsMsg.META_CLICK_SHOW.getBase(name)));
|
||||
|
||||
if (itel.hasNext()) {
|
||||
builder.append(LibsMsg.META_VALUE_SEPERATOR.getBase());
|
||||
}
|
||||
}
|
||||
|
||||
sender.spigot().sendMessage(builder.create());
|
||||
/*} else {
|
||||
LibsMsg.META_VALUES_NO_CLICK.send(sender,
|
||||
StringUtils.join(names, LibsMsg.META_VALUE_SEPERATOR.get()));
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender.hasPermission(getPermission());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibsMsg getHelp() {
|
||||
return LibsMsg.LD_COMMAND_METAINFO;
|
||||
}
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.modded.ModdedManager;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 20/04/2020.
|
||||
*/
|
||||
public class LDMods implements LDCommand {
|
||||
@Override
|
||||
public List<String> getTabComplete() {
|
||||
return Collections.singletonList("mods");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "libsdisguises.mods";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
if (ModdedManager.getEntities().isEmpty()) {
|
||||
LibsMsg.NO_MODS_LISTENING.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
Player player;
|
||||
|
||||
if (args.length > 1) {
|
||||
player = Bukkit.getPlayer(args[1]);
|
||||
|
||||
if (player == null) {
|
||||
LibsMsg.CANNOT_FIND_PLAYER.send(sender, args[1]);
|
||||
return;
|
||||
}
|
||||
} else if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
} else {
|
||||
LibsMsg.NO_CONSOLE.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.hasMetadata("forge_mods")) {
|
||||
LibsMsg.NO_MODS.send(sender, player.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
LibsMsg.MODS_LIST.send(sender, player.getName(),
|
||||
StringUtils.join((List<String>) player.getMetadata("forge_mods").get(0).value(), ", "));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender.hasPermission(getPermission());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibsMsg getHelp() {
|
||||
return LibsMsg.LD_COMMAND_MODS;
|
||||
}
|
||||
}
|
@@ -0,0 +1,100 @@
|
||||
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.permissions.Permissible;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 20/04/2020.
|
||||
*/
|
||||
public class LDPermTest implements LDCommand {
|
||||
@Override
|
||||
public List<String> getTabComplete() {
|
||||
return Arrays.asList("permtest", "permissions", "permissiontest");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "libsdisguises.permtest";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
if (!LibsPremium.isPremium()) {
|
||||
LibsMsg.LIBS_PERM_CHECK_NON_PREM.send(sender);
|
||||
}
|
||||
|
||||
Permissible player;
|
||||
|
||||
if (args.length > 1) {
|
||||
player = Bukkit.getPlayer(args[1]);
|
||||
|
||||
if (player == null) {
|
||||
LibsMsg.CANNOT_FIND_PLAYER.send(sender, args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
LibsMsg.LIBS_PERM_CHECK_USING_TARGET.send(sender, args[1]);
|
||||
} else {
|
||||
player = sender;
|
||||
LibsMsg.LIBS_PERM_CHECK_CAN_TARGET.send(sender);
|
||||
}
|
||||
|
||||
DisguisePermissions permissions = new DisguisePermissions(player, "disguise");
|
||||
LibsMsg.LIBS_PERM_CHECK_INFO_1.send(sender);
|
||||
LibsMsg.LIBS_PERM_CHECK_INFO_2.send(sender);
|
||||
|
||||
if (player.hasPermission("libsdisguises.disguise.pig")) {
|
||||
LibsMsg.NORMAL_PERM_CHECK_SUCCESS.send(sender);
|
||||
|
||||
if (permissions.isAllowedDisguise(new DisguisePerm(DisguiseType.PIG))) {
|
||||
LibsMsg.LIBS_PERM_CHECK_SUCCESS.send(sender);
|
||||
} else {
|
||||
LibsMsg.LIBS_PERM_CHECK_FAIL.send(sender);
|
||||
}
|
||||
} else {
|
||||
LibsMsg.NORMAL_PERM_CHECK_FAIL.send(sender);
|
||||
}
|
||||
|
||||
if (player.hasPermission("libsdisguises.disguise.zombie") ||
|
||||
permissions.isAllowedDisguise(new DisguisePerm(DisguiseType.ZOMBIE))) {
|
||||
LibsMsg.LIBS_PERM_CHECK_ZOMBIE_PERMISSIONS.send(sender);
|
||||
}
|
||||
|
||||
PluginCommand command = LibsDisguises.getInstance().getCommand("disguise");
|
||||
|
||||
if (command == null) {
|
||||
LibsMsg.LIBS_PERM_CHECK_COMMAND_UNREGISTERED.send(sender);
|
||||
} else if (player.hasPermission(command.getPermission())) {
|
||||
LibsMsg.LIBS_PERM_COMMAND_SUCCESS.send(sender, command.getPermission());
|
||||
} else {
|
||||
LibsMsg.LIBS_PERM_COMMAND_FAIL.send(sender, command.getPermission());
|
||||
}
|
||||
|
||||
if (!sender.hasPermission("libsdisguises.seecmd.disguise")) {
|
||||
LibsMsg.LIBS_PERM_COMMAND_FAIL.send(sender, "libsdisguises.seecmd.disguise");
|
||||
} else {
|
||||
LibsMsg.LIBS_PERM_COMMAND_SUCCESS.send(sender, "libsdisguises.seecmd.disguise");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender.hasPermission(getPermission());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibsMsg getHelp() {
|
||||
return LibsMsg.LD_COMMAND_PERMTEST;
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.utilities.sounds.SoundManager;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 20/04/2020.
|
||||
*/
|
||||
public class LDReload implements LDCommand {
|
||||
@Override
|
||||
public List<String> getTabComplete() {
|
||||
return Collections.singletonList("reload");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "libsdisguises.reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
DisguiseConfig.loadConfig();
|
||||
new SoundManager().load();
|
||||
LibsMsg.RELOADED_CONFIG.send(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender.hasPermission(getPermission());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibsMsg getHelp() {
|
||||
return LibsMsg.LD_COMMAND_RELOAD;
|
||||
}
|
||||
}
|
@@ -0,0 +1,220 @@
|
||||
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 20/04/2020.
|
||||
*/
|
||||
public class LDScoreboard implements LDCommand {
|
||||
@Override
|
||||
public List<String> getTabComplete() {
|
||||
return Arrays.asList("teams", "scoreboard", "board", "pushing");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "libsdisguises.scoreboard";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
if (DisguiseConfig.isScoreboardNames()) {
|
||||
int issuesFound = 0;
|
||||
int unexpected = 0;
|
||||
|
||||
for (Set<TargetedDisguise> disguises : DisguiseUtilities.getDisguises().values()) {
|
||||
for (Disguise disguise : disguises) {
|
||||
if (!disguise.isPlayerDisguise()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!((PlayerDisguise) disguise).hasScoreboardName()) {
|
||||
if (unexpected++ < 3) {
|
||||
sender.sendMessage(
|
||||
"The player disguise " + ((PlayerDisguise) disguise).getName() + " isn't using a scoreboard name? This is unexpected");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
DisguiseUtilities.DScoreTeam scoreboardName = ((PlayerDisguise) disguise).getScoreboardName();
|
||||
|
||||
if (scoreboardName.getTeamName() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ArrayList<Scoreboard> checked = new ArrayList<>();
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
Scoreboard board = player.getScoreboard();
|
||||
|
||||
if (checked.contains(board)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
checked.add(board);
|
||||
|
||||
|
||||
Team team = board.getTeam(scoreboardName.getTeamName());
|
||||
|
||||
if (team == null) {
|
||||
if (issuesFound++ < 5) {
|
||||
sender.sendMessage("The player disguise " + ((PlayerDisguise) disguise).getName().replace(ChatColor.COLOR_CHAR, '&') +
|
||||
" is missing a scoreboard team '" + scoreboardName.getTeamName() + "' on " + player.getName() +
|
||||
" and possibly more players!");
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!team.getPrefix().equals("Colorize") &&
|
||||
(!team.getPrefix().equals(scoreboardName.getPrefix()) || !team.getSuffix().equals(scoreboardName.getSuffix()))) {
|
||||
if (issuesFound++ < 5) {
|
||||
sender.sendMessage("The player disguise " + ((PlayerDisguise) disguise).getName().replace(ChatColor.COLOR_CHAR, '&') +
|
||||
" on scoreboard team '" + scoreboardName.getTeamName() + "' on " + player.getName() +
|
||||
" has an unexpected prefix/suffix of '" + team.getPrefix().replace(ChatColor.COLOR_CHAR, '&') + "' & '" +
|
||||
team.getSuffix().replace(ChatColor.COLOR_CHAR, '&') + "'! Expected '" +
|
||||
scoreboardName.getPrefix().replace(ChatColor.COLOR_CHAR, '&') + "' & '" +
|
||||
scoreboardName.getSuffix().replace(ChatColor.COLOR_CHAR, '&') + "'");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!team.hasEntry(scoreboardName.getPlayer())) {
|
||||
if (issuesFound++ < 5) {
|
||||
sender.sendMessage("The player disguise " + ((PlayerDisguise) disguise).getName().replace(ChatColor.COLOR_CHAR, '&') +
|
||||
" on scoreboard team '" + scoreboardName.getTeamName() + "' on " + player.getName() +
|
||||
" does not have the player entry expected! Instead has '" +
|
||||
StringUtils.join(team.getEntries(), ", ").replace(ChatColor.COLOR_CHAR, '&') + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (issuesFound == 0) {
|
||||
LibsMsg.LIBS_SCOREBOARD_NO_ISSUES.send(sender);
|
||||
} else {
|
||||
LibsMsg.LIBS_SCOREBOARD_ISSUES.send(sender, issuesFound);
|
||||
}
|
||||
} else {
|
||||
LibsMsg.LIBS_SCOREBOARD_NAMES_DISABLED.send(sender);
|
||||
}
|
||||
|
||||
List<PacketListener> listeners = ProtocolLibrary.getProtocolManager().getPacketListeners().stream()
|
||||
.filter(listener -> listener.getPlugin() != LibsDisguises.getInstance() &&
|
||||
listener.getSendingWhitelist().getTypes().contains(PacketType.Play.Server.SCOREBOARD_TEAM)).collect(Collectors.toList());
|
||||
|
||||
if (!listeners.isEmpty()) {
|
||||
ComponentBuilder builder = new ComponentBuilder("");
|
||||
builder.append("The following plugins are listening for scoreboard teams using ProtocolLib, and could be modifying collisions: ");
|
||||
builder.color(net.md_5.bungee.api.ChatColor.BLUE);
|
||||
|
||||
boolean comma = false;
|
||||
|
||||
for (PacketListener listener : listeners) {
|
||||
if (comma) {
|
||||
builder.reset();
|
||||
builder.append(", ");
|
||||
builder.color(net.md_5.bungee.api.ChatColor.BLUE);
|
||||
}
|
||||
|
||||
comma = true;
|
||||
|
||||
builder.reset();
|
||||
builder.append(listener.getPlugin().getName());
|
||||
builder.color(net.md_5.bungee.api.ChatColor.AQUA);
|
||||
|
||||
String plugin = ChatColor.GOLD + "Plugin: " + ChatColor.YELLOW + listener.getPlugin().getName() + " v" +
|
||||
listener.getPlugin().getDescription().getVersion();
|
||||
String listenerClass = ChatColor.GOLD + "Listener: " + ChatColor.YELLOW + listener.getClass().toString();
|
||||
String packets = ChatColor.GOLD + "Packets: " + ChatColor.YELLOW + StringUtils.join(listener.getSendingWhitelist().getTypes(), ", ");
|
||||
String priority = ChatColor.GOLD + "Priority: " + ChatColor.YELLOW + listener.getSendingWhitelist().getPriority();
|
||||
String options = ChatColor.GOLD + "Options: " + ChatColor.YELLOW + StringUtils.join(listener.getSendingWhitelist().getOptions(), ", ");
|
||||
|
||||
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
TextComponent.fromLegacyText(plugin + "\n" + listenerClass + "\n" + packets + "\n" + priority + "\n" + options)));
|
||||
}
|
||||
|
||||
sender.spigot().sendMessage(builder.create());
|
||||
}
|
||||
|
||||
LibsMsg.LIBS_SCOREBOARD_IGNORE_TEST.send(sender);
|
||||
|
||||
sender.sendMessage(ChatColor.RED +
|
||||
"This command is somewhat outdated and needs to be changed, pushing is now disabled on the entities themselves and not players");
|
||||
|
||||
Player player;
|
||||
|
||||
if (args.length > 1) {
|
||||
player = Bukkit.getPlayer(args[1]);
|
||||
|
||||
if (player == null) {
|
||||
LibsMsg.CANNOT_FIND_PLAYER.send(sender, args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!DisguiseAPI.isDisguised(player)) {
|
||||
LibsMsg.DMODPLAYER_NODISGUISE.send(sender, player.getName());
|
||||
LibsMsg.DISGUISE_REQUIRED.send(sender);
|
||||
return;
|
||||
}
|
||||
} else if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
|
||||
if (!DisguiseAPI.isDisguised(player)) {
|
||||
LibsMsg.DISGUISE_REQUIRED.send(sender);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
LibsMsg.NO_CONSOLE.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
Scoreboard board = player.getScoreboard();
|
||||
|
||||
Team team = board.getEntryTeam(sender.getName());
|
||||
|
||||
if (team == null) {
|
||||
LibsMsg.LIBS_SCOREBOARD_NO_TEAM.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
LibsMsg.LIBS_SCOREBOARD_SUCCESS.send(sender, team.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender.hasPermission(getPermission());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibsMsg getHelp() {
|
||||
return LibsMsg.LD_COMMAND_SCOREBOARD;
|
||||
}
|
||||
}
|
@@ -0,0 +1,120 @@
|
||||
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.plugin.PluginInformation;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import me.libraryaddict.disguise.utilities.updates.UpdateChecker;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 20/04/2020.
|
||||
*/
|
||||
public class LDUpdate implements LDCommand {
|
||||
@Override
|
||||
public List<String> getTabComplete() {
|
||||
// Update by download
|
||||
// Update check
|
||||
// Update to latest dev build
|
||||
return Arrays.asList("update", "update dev", "update release", "update!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "libsdisguises.update";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
UpdateChecker checker = LibsDisguises.getInstance().getUpdateChecker();
|
||||
|
||||
if (checker.isDownloading()) {
|
||||
LibsMsg.UPDATE_IN_PROGRESS.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean releaseBuilds = checker.isUsingReleaseBuilds();
|
||||
|
||||
if (args.length > 1) {
|
||||
boolean previous = releaseBuilds;
|
||||
|
||||
if (args[1].equalsIgnoreCase("dev")) {
|
||||
releaseBuilds = false;
|
||||
} else if (args[1].equalsIgnoreCase("release")) {
|
||||
releaseBuilds = true;
|
||||
} else {
|
||||
LibsMsg.LIBS_UPDATE_UNKNOWN_BRANCH.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
DisguiseConfig.setUsingReleaseBuilds(releaseBuilds);
|
||||
}
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LibsMsg updateResult = checker.doUpdateCheck();
|
||||
|
||||
if (checker.getUpdate() == null) {
|
||||
LibsMsg.UPDATE_FAILED.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (checker.isOnLatestUpdate(true)) {
|
||||
if (checker.getLastDownload() != null) {
|
||||
LibsMsg.UPDATE_ALREADY_DOWNLOADED.send(sender);
|
||||
} else {
|
||||
LibsMsg.UPDATE_ON_LATEST.send(sender);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*if (!finalWantsDownload) {
|
||||
if (updateResult != null) {
|
||||
updateResult.send(sender);
|
||||
} else {
|
||||
for (String msg : checker.getUpdateMessage()) {
|
||||
DisguiseUtilities.sendMessage(sender, msg);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}*/
|
||||
|
||||
PluginInformation result = checker.doUpdate();
|
||||
|
||||
if (result == null) {
|
||||
LibsMsg.UPDATE_FAILED.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
for (String msg : checker.getUpdateMessage()) {
|
||||
DisguiseUtilities.sendMessage(sender, msg);
|
||||
}
|
||||
|
||||
if (sender instanceof Player) {
|
||||
for (String msg : checker.getUpdateMessage()) {
|
||||
DisguiseUtilities.getLogger().info(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(LibsDisguises.getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender.hasPermission(getPermission());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibsMsg getHelp() {
|
||||
return LibsMsg.LD_COMMAND_UPDATE;
|
||||
}
|
||||
}
|
@@ -0,0 +1,82 @@
|
||||
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 30/06/2020.
|
||||
*/
|
||||
public class LDUpdateProtocolLib implements LDCommand {
|
||||
private final AtomicBoolean updateInProgress = new AtomicBoolean(false);
|
||||
|
||||
@Override
|
||||
public List<String> getTabComplete() {
|
||||
return Arrays.asList("updateprotocollib", "updatepl", "protocollib");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender.isOp() || sender.hasPermission("minecraft.command.op");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
if (updateInProgress.get()) {
|
||||
sender.sendMessage(ChatColor.RED + "Update already in progress");
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.RED + "Please hold, now downloading..");
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
File protocolLibFile = null;
|
||||
|
||||
try {
|
||||
DisguiseUtilities.updateProtocolLib();
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sender.sendMessage(ChatColor.RED + "Update success! Restart server to finish update!");
|
||||
}
|
||||
}.runTask(LibsDisguises.getInstance());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sender.sendMessage(ChatColor.RED +
|
||||
"Looks like ProtocolLib's site may be down! MythicCraft/MythicMobs has a discord server https://discord.gg/EErRhJ4qgx you" +
|
||||
" can join. Check the pins in #libs-support for a ProtocolLib.jar you can download!");
|
||||
sender.sendMessage(ChatColor.RED + "Update failed, " + ex.getMessage());
|
||||
}
|
||||
}.runTask(LibsDisguises.getInstance());
|
||||
} finally {
|
||||
updateInProgress.set(false);
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(LibsDisguises.getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibsMsg getHelp() {
|
||||
return LibsMsg.LD_COMMAND_UPDATEPROTOCOLLIB;
|
||||
}
|
||||
}
|
@@ -0,0 +1,264 @@
|
||||
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import lombok.Data;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.utilities.config.ConfigLoader;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.file.Files;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 18/06/2020.
|
||||
*/
|
||||
public class LDUploadLogs implements LDCommand {
|
||||
private long lastUsed;
|
||||
|
||||
/**
|
||||
* Small modification of https://gist.github.com/jamezrin/12de49643d7be7150da362e86407113f
|
||||
*/
|
||||
@Data
|
||||
public class GuestPaste {
|
||||
private String name = null;
|
||||
private final String text;
|
||||
|
||||
public GuestPaste(String name, String text) {
|
||||
this.name = name;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public URL paste() throws Exception {
|
||||
URL url = new URL("https://pastebin.com/api/api_post.php");
|
||||
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
|
||||
|
||||
con.setRequestMethod("POST");
|
||||
con.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||
|
||||
List<SimpleEntry<String, String>> params = new LinkedList<>();
|
||||
// This doesn't give you access to my pastebin account ;)
|
||||
// You need to enter another key for that, this key is for pastebin's tracking metrics.
|
||||
// If you're using this code, please use your own pastebin dev key.
|
||||
// Overuse will get it banned, and you'll have to ship a new version with your own key anyways.
|
||||
// This is seperated into strings to prevent super easy scraping.
|
||||
if (getClass().getName().contains("me.libraryaddict")) {
|
||||
params.add(new SimpleEntry<>("api_dev_key", "62067f9d" + "cc1979a475105b529" + "eb453a5"));
|
||||
}
|
||||
params.add(new SimpleEntry<>("api_option", "paste"));
|
||||
params.add(new SimpleEntry<>("api_paste_name", name));
|
||||
params.add(new SimpleEntry<>("api_paste_code", text));
|
||||
|
||||
params.add(new SimpleEntry<>("api_paste_format", "text"));
|
||||
params.add(new SimpleEntry<>("api_paste_expire_date", "1M"));
|
||||
params.add(new SimpleEntry<>("api_paste_private", "1"));
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
for (SimpleEntry<String, String> entry : params) {
|
||||
if (output.length() > 0) {
|
||||
output.append('&');
|
||||
}
|
||||
|
||||
output.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
|
||||
output.append('=');
|
||||
output.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
|
||||
}
|
||||
|
||||
con.setDoOutput(true);
|
||||
try (DataOutputStream dos = new DataOutputStream(con.getOutputStream())) {
|
||||
dos.writeBytes(output.toString());
|
||||
dos.flush();
|
||||
}
|
||||
|
||||
int status = con.getResponseCode();
|
||||
|
||||
if (status >= 200 && status < 300) {
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
|
||||
String inputLine;
|
||||
StringBuilder response = new StringBuilder();
|
||||
|
||||
while ((inputLine = br.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
|
||||
return new URL(response.toString());
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException("Unexpected response code " + status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabComplete() {
|
||||
return Arrays.asList("uploadlog", "uploadlogs", "uploadconfig", "uploadconfigs", "logs", "log");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender.isOp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
if (lastUsed + TimeUnit.MINUTES.toMillis(3) > System.currentTimeMillis()) {
|
||||
sender.sendMessage(ChatColor.RED + "You last used this command under 3 minutes ago! Restart the server or wait for this timer to " + "disappear!");
|
||||
return;
|
||||
}
|
||||
|
||||
File latest = new File("logs/latest.log");
|
||||
File disguises = new File(LibsDisguises.getInstance().getDataFolder(), "configs/disguises.yml");
|
||||
|
||||
List<File> configs =
|
||||
new ConfigLoader().getConfigs().stream().map(f -> new File(LibsDisguises.getInstance().getDataFolder(), f)).collect(Collectors.toList());
|
||||
|
||||
StringBuilder configText = new StringBuilder();
|
||||
|
||||
for (File config : configs) {
|
||||
if (configText.length() != 0) {
|
||||
configText.append("\n\n================\n\n");
|
||||
}
|
||||
|
||||
try {
|
||||
String text = new String(Files.readAllBytes(config.toPath()));
|
||||
text = text.replaceAll("\n? *#[^\n]*", "").replaceAll("[\n\r]+", "\n");
|
||||
|
||||
configText.append("File: ").append(config.getName()).append("\n\n").append(text);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (isTooBig(latest)) {
|
||||
sender.sendMessage(
|
||||
ChatColor.RED + "Your latest.log file is too big! It should be less than 512kb! Please restart and run this " + "command again!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (isTooBig(disguises)) {
|
||||
sender.sendMessage(ChatColor.RED + "Your disguises.yml is too big! You'll need to trim that file down before using this command! It " +
|
||||
"should be less than 512kb!");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String latestText = new String(Files.readAllBytes(latest.toPath()));
|
||||
|
||||
boolean valid = false;
|
||||
int lastFind = 0;
|
||||
|
||||
for (int i = 0; i < 15; i++) {
|
||||
int nextLine = latestText.indexOf("\n", lastFind);
|
||||
|
||||
if (nextLine == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
String str = latestText.substring(lastFind, nextLine);
|
||||
|
||||
lastFind = nextLine + 2;
|
||||
|
||||
if (!str.contains("Starting minecraft server version") && !str.contains("Loading properties") && !str.contains("This server is running")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
valid = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
sender.sendMessage(ChatColor.RED + "Your latest.log is too old! Please restart the server and try again!");
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.GOLD + "Now creating pastebin links...");
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String disguiseText = new String(Files.readAllBytes(disguises.toPath()));
|
||||
|
||||
configText.append("\n\n================\n");
|
||||
|
||||
ArrayList<String> modified = DisguiseConfig.doOutput(true, true);
|
||||
|
||||
for (String s : modified) {
|
||||
configText.append("\n").append(s);
|
||||
}
|
||||
|
||||
if (modified.isEmpty()) {
|
||||
configText.append("\nUsing default config!");
|
||||
}
|
||||
|
||||
URL latestPaste = new GuestPaste("latest.log", latestText).paste();
|
||||
URL configPaste = new GuestPaste("LibsDisguises config.yml", configText.toString()).paste();
|
||||
URL disguisesPaste = new GuestPaste("LibsDisguises disguises.yml", disguiseText).paste();
|
||||
|
||||
lastUsed = System.currentTimeMillis();
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sender.sendMessage(ChatColor.GOLD + "Upload successful!");
|
||||
|
||||
// Console can't click :(
|
||||
if (sender instanceof Player) {
|
||||
sender.sendMessage(ChatColor.GOLD + "Click on the below message to have it appear in your chat input");
|
||||
}
|
||||
|
||||
String text = "My log file: " + latestPaste + ", my combined config files: " + configPaste + " and my disguises file: " +
|
||||
disguisesPaste;
|
||||
|
||||
ComponentBuilder builder = new ComponentBuilder("");
|
||||
builder.append(text);
|
||||
builder.color(net.md_5.bungee.api.ChatColor.AQUA);
|
||||
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, text));
|
||||
|
||||
sender.spigot().sendMessage(builder.create());
|
||||
}
|
||||
}.runTask(LibsDisguises.getInstance());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
sender.sendMessage(ChatColor.RED + "Unexpected error! Upload failed! " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(LibsDisguises.getInstance());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTooBig(File file) {
|
||||
return file.exists() && isTooBig(file.length());
|
||||
}
|
||||
|
||||
private boolean isTooBig(long length) {
|
||||
return length >= 512 * 1024;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibsMsg getHelp() {
|
||||
return LibsMsg.LD_COMMAND_UPLOAD_LOGS;
|
||||
}
|
||||
}
|
@@ -0,0 +1,112 @@
|
||||
package me.libraryaddict.disguise.commands.modify;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCompleter {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (!(sender instanceof Entity)) {
|
||||
LibsMsg.NO_CONSOLE.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
DisguisePermissions permissions = getPermissions(sender);
|
||||
|
||||
if (!permissions.hasPermissions()) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
sendCommandUsage(sender, permissions);
|
||||
return true;
|
||||
}
|
||||
|
||||
Disguise disguise = DisguiseAPI.getDisguise((Player) sender, (Entity) sender);
|
||||
|
||||
if (disguise == null) {
|
||||
LibsMsg.NOT_DISGUISED.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
DisguisePerm disguisePerm = new DisguisePerm(disguise.getType());
|
||||
|
||||
if (!permissions.isAllowedDisguise(disguisePerm)) {
|
||||
LibsMsg.DMODIFY_NO_PERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
String[] options = DisguiseUtilities.split(StringUtils.join(args, " "));
|
||||
|
||||
options = DisguiseParser.parsePlaceholders(options, sender, sender);
|
||||
|
||||
try {
|
||||
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), options,
|
||||
"DisguiseModify");
|
||||
}
|
||||
catch (DisguiseParseException ex) {
|
||||
ex.send(sender);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
|
||||
LibsMsg.DMODIFY_MODIFIED.send(sender);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
|
||||
if (!(sender instanceof Player))
|
||||
return new ArrayList<>();
|
||||
|
||||
Disguise disguise = DisguiseAPI.getDisguise((Player) sender, (Entity) sender);
|
||||
|
||||
if (disguise == null)
|
||||
return new ArrayList<>();
|
||||
|
||||
String[] args = getPreviousArgs(origArgs);
|
||||
|
||||
DisguisePermissions perms = getPermissions(sender);
|
||||
|
||||
DisguisePerm disguiseType = new DisguisePerm(disguise.getType());
|
||||
|
||||
List<String> tabs = getTabDisguiseOptions(sender, perms, disguiseType, args, 0, getCurrentArg(origArgs));
|
||||
|
||||
return filterTabs(tabs, origArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the player the information
|
||||
*/
|
||||
@Override
|
||||
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
|
||||
|
||||
LibsMsg.DMODIFY_HELP1.send(sender);
|
||||
LibsMsg.DMODIFY_HELP2.send(sender);
|
||||
LibsMsg.DMODIFY_HELP3.send(sender,
|
||||
StringUtils.join(allowedDisguises, LibsMsg.CAN_USE_DISGS_SEPERATOR.get()));
|
||||
}
|
||||
}
|
@@ -0,0 +1,85 @@
|
||||
package me.libraryaddict.disguise.commands.modify;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
|
||||
import me.libraryaddict.disguise.commands.interactions.DisguiseModifyInteraction;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
LibsMsg.NO_CONSOLE.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
DisguisePermissions permissions = getPermissions(sender);
|
||||
|
||||
if (!permissions.hasPermissions()) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
sendCommandUsage(sender, permissions);
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO Validate if any disguises have this arg
|
||||
|
||||
LibsDisguises.getInstance().getListener().addInteraction(sender.getName(),
|
||||
new DisguiseModifyInteraction(DisguiseUtilities.split(StringUtils.join(args, " "))),
|
||||
DisguiseConfig.getDisguiseEntityExpire());
|
||||
|
||||
LibsMsg.DMODIFYENT_CLICK.send(sender, DisguiseConfig.getDisguiseEntityExpire());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
String[] args = getPreviousArgs(origArgs);
|
||||
|
||||
DisguisePermissions perms = getPermissions(sender);
|
||||
|
||||
if (!perms.hasPermissions()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<String> tabs = new ArrayList<>();
|
||||
|
||||
for (DisguisePerm perm : perms.getAllowed()) {
|
||||
tabs.addAll(getTabDisguiseOptions(sender, perms, perm, args, 0, getCurrentArg(origArgs)));
|
||||
}
|
||||
|
||||
return filterTabs(tabs, origArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the player the information
|
||||
*/
|
||||
@Override
|
||||
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
|
||||
|
||||
LibsMsg.DMODENT_HELP1.send(sender);
|
||||
LibsMsg.DMODIFY_HELP3.send(sender,
|
||||
StringUtils.join(allowedDisguises, LibsMsg.CAN_USE_DISGS_SEPERATOR.get()));
|
||||
}
|
||||
}
|
@@ -0,0 +1,166 @@
|
||||
package me.libraryaddict.disguise.commands.modify;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
DisguisePermissions permissions = getPermissions(sender);
|
||||
|
||||
if (!permissions.hasPermissions()) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
sendCommandUsage(sender, permissions);
|
||||
return true;
|
||||
}
|
||||
|
||||
Entity entityTarget = Bukkit.getPlayer(args[0]);
|
||||
|
||||
if (entityTarget == null) {
|
||||
if (args[0].contains("-")) {
|
||||
try {
|
||||
entityTarget = Bukkit.getEntity(UUID.fromString(args[0]));
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entityTarget == null) {
|
||||
LibsMsg.CANNOT_FIND_PLAYER.send(sender, args[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
String[] newArgs = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, newArgs, 0, newArgs.length);
|
||||
|
||||
if (newArgs.length == 0) {
|
||||
sendCommandUsage(sender, permissions);
|
||||
return true;
|
||||
}
|
||||
|
||||
Disguise disguise = null;
|
||||
|
||||
if (sender instanceof Player)
|
||||
disguise = DisguiseAPI.getDisguise((Player) sender, entityTarget);
|
||||
|
||||
if (disguise == null)
|
||||
disguise = DisguiseAPI.getDisguise(entityTarget);
|
||||
|
||||
if (disguise == null) {
|
||||
LibsMsg.DMODPLAYER_NODISGUISE.send(sender, entityTarget.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
DisguisePerm disguisePerm = new DisguisePerm(disguise.getType());
|
||||
|
||||
if (!permissions.isAllowedDisguise(disguisePerm)) {
|
||||
LibsMsg.DMODPLAYER_NOPERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
String[] options = DisguiseUtilities.split(StringUtils.join(newArgs, " "));
|
||||
|
||||
options = DisguiseParser.parsePlaceholders(options, sender, entityTarget);
|
||||
|
||||
try {
|
||||
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), options,
|
||||
"DisguiseModifyPlayer");
|
||||
}
|
||||
catch (DisguiseParseException ex) {
|
||||
ex.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
|
||||
LibsMsg.DMODPLAYER_MODIFIED.send(sender, entityTarget.getName());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
|
||||
ArrayList<String> tabs = new ArrayList<>();
|
||||
String[] args = getPreviousArgs(origArgs);
|
||||
|
||||
DisguisePermissions perms = getPermissions(sender);
|
||||
|
||||
if (!perms.hasPermissions()) {
|
||||
return tabs;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
// If command user cannot see player online, don't tab-complete name
|
||||
if (sender instanceof Player && !((Player) sender).canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tabs.add(player.getName());
|
||||
}
|
||||
} else {
|
||||
Player player = Bukkit.getPlayer(args[0]);
|
||||
|
||||
if (player == null) {
|
||||
return tabs;
|
||||
}
|
||||
|
||||
Disguise disguise = null;
|
||||
|
||||
if (sender instanceof Player)
|
||||
disguise = DisguiseAPI.getDisguise((Player) sender, player);
|
||||
|
||||
if (disguise == null)
|
||||
disguise = DisguiseAPI.getDisguise(player);
|
||||
|
||||
if (disguise == null) {
|
||||
return tabs;
|
||||
}
|
||||
|
||||
DisguisePerm disguiseType = new DisguisePerm(disguise.getType());
|
||||
|
||||
tabs.addAll(getTabDisguiseOptions(sender, perms, disguiseType, args, 1, getCurrentArg(args)));
|
||||
}
|
||||
|
||||
return filterTabs(tabs, origArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the player the information
|
||||
*/
|
||||
@Override
|
||||
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
|
||||
|
||||
LibsMsg.DMODPLAYER_HELP1.send(sender);
|
||||
LibsMsg.DMODIFY_HELP3.send(sender,
|
||||
StringUtils.join(allowedDisguises, LibsMsg.CAN_USE_DISGS_SEPERATOR.get()));
|
||||
}
|
||||
}
|
@@ -0,0 +1,289 @@
|
||||
package me.libraryaddict.disguise.commands.modify;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
|
||||
import me.libraryaddict.disguise.utilities.parser.*;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import me.libraryaddict.disguise.utilities.translations.TranslateType;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements TabCompleter {
|
||||
private Collection<Entity> getNearbyEntities(CommandSender sender, int radius) {
|
||||
Location center;
|
||||
|
||||
if (sender instanceof Player) {
|
||||
center = ((Player) sender).getLocation();
|
||||
} else {
|
||||
center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5);
|
||||
}
|
||||
|
||||
return center.getWorld().getNearbyEntities(center, radius, radius, radius);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender.getName().equals("CONSOLE")) {
|
||||
LibsMsg.NO_CONSOLE.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
DisguisePermissions permissions = getPermissions(sender);
|
||||
|
||||
if (!permissions.hasPermissions()) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
sendCommandUsage(sender, permissions);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("DisguiseType")) ||
|
||||
args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("DisguiseType") + "s")) {
|
||||
ArrayList<String> classes = new ArrayList<>();
|
||||
|
||||
for (DisguiseType type : DisguiseType.values()) {
|
||||
if (type.getEntityType() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
classes.add(type.toReadable());
|
||||
}
|
||||
|
||||
Collections.sort(classes);
|
||||
|
||||
LibsMsg.DMODRADIUS_USABLE.send(sender, ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN));
|
||||
return true;
|
||||
}
|
||||
|
||||
DisguiseType baseType = null;
|
||||
int starting = 0;
|
||||
|
||||
if (!isInteger(args[0])) {
|
||||
for (DisguiseType t : DisguiseType.values()) {
|
||||
if (t.getEntityType() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) {
|
||||
baseType = t;
|
||||
starting = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (baseType == null) {
|
||||
LibsMsg.DMODRADIUS_UNRECOGNIZED.send(sender, args[0]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length == starting + 1) {
|
||||
if (starting == 0) {
|
||||
LibsMsg.DMODRADIUS_NEEDOPTIONS.send(sender);
|
||||
} else {
|
||||
LibsMsg.DMODRADIUS_NEEDOPTIONS_ENTITY.send(sender);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (args.length < 2) {
|
||||
LibsMsg.DMODRADIUS_NEEDOPTIONS.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isInteger(args[starting])) {
|
||||
LibsMsg.NOT_NUMBER.send(sender, args[starting]);
|
||||
return true;
|
||||
}
|
||||
|
||||
int radius = Integer.parseInt(args[starting]);
|
||||
|
||||
if (radius > DisguiseConfig.getDisguiseRadiusMax()) {
|
||||
LibsMsg.LIMITED_RADIUS.send(sender, DisguiseConfig.getDisguiseRadiusMax());
|
||||
radius = DisguiseConfig.getDisguiseRadiusMax();
|
||||
}
|
||||
|
||||
String[] newArgs = new String[args.length - (starting + 1)];
|
||||
System.arraycopy(args, starting + 1, newArgs, 0, newArgs.length);
|
||||
|
||||
if (newArgs.length == 0) {
|
||||
sendCommandUsage(sender, permissions);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Time to use it!
|
||||
int modifiedDisguises = 0;
|
||||
int noPermission = 0;
|
||||
|
||||
String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(newArgs, " "));
|
||||
|
||||
for (Entity entity : getNearbyEntities(sender, radius)) {
|
||||
if (entity == sender) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (baseType != null && !baseType.name().equalsIgnoreCase(entity.getType().name())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Disguise disguise;
|
||||
|
||||
if (sender instanceof Player) {
|
||||
disguise = DisguiseAPI.getDisguise((Player) sender, entity);
|
||||
} else {
|
||||
disguise = DisguiseAPI.getDisguise(entity);
|
||||
}
|
||||
|
||||
if (disguise == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DisguisePerm disguisePerm = new DisguisePerm(disguise.getType());
|
||||
|
||||
if (!permissions.isAllowedDisguise(disguisePerm)) {
|
||||
noPermission++;
|
||||
continue;
|
||||
}
|
||||
|
||||
String[] tempArgs = Arrays.copyOf(disguiseArgs, disguiseArgs.length);
|
||||
tempArgs = DisguiseParser.parsePlaceholders(tempArgs, sender, entity);
|
||||
|
||||
try {
|
||||
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), tempArgs, "DisguiseModifyRadius");
|
||||
modifiedDisguises++;
|
||||
} catch (DisguiseParseException ex) {
|
||||
ex.send(sender);
|
||||
|
||||
return true;
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (noPermission > 0) {
|
||||
LibsMsg.DMODRADIUS_NOPERM.send(sender, noPermission);
|
||||
}
|
||||
|
||||
if (modifiedDisguises > 0) {
|
||||
LibsMsg.DMODRADIUS.send(sender, modifiedDisguises);
|
||||
} else {
|
||||
LibsMsg.DMODRADIUS_NOENTS.send(sender);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
|
||||
ArrayList<String> tabs = new ArrayList<>();
|
||||
String[] args = getPreviousArgs(origArgs);
|
||||
|
||||
DisguisePermissions perms = getPermissions(sender);
|
||||
|
||||
if (args.length == 0) {
|
||||
for (DisguiseType type : DisguiseType.values()) {
|
||||
if (type.getEntityType() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tabs.add(type.toReadable().replaceAll(" ", "_"));
|
||||
}
|
||||
|
||||
return filterTabs(tabs, origArgs);
|
||||
}
|
||||
|
||||
int starting = 0;
|
||||
|
||||
if (!isInteger(args[0])) {
|
||||
for (DisguiseType t : DisguiseType.values()) {
|
||||
if (t.getEntityType() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) {
|
||||
starting = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Not a valid radius
|
||||
if (starting == 1 || args.length == 1 || !isInteger(args[1])) {
|
||||
return filterTabs(tabs, origArgs);
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length <= starting || !isInteger(args[starting])) {
|
||||
return filterTabs(tabs, origArgs);
|
||||
}
|
||||
|
||||
int radius = Integer.parseInt(args[starting]);
|
||||
|
||||
if (radius > DisguiseConfig.getDisguiseRadiusMax()) {
|
||||
LibsMsg.LIMITED_RADIUS.send(sender, DisguiseConfig.getDisguiseRadiusMax());
|
||||
radius = DisguiseConfig.getDisguiseRadiusMax();
|
||||
}
|
||||
|
||||
starting++;
|
||||
|
||||
ArrayList<String> usedOptions = new ArrayList<>();
|
||||
|
||||
for (Entity entity : getNearbyEntities(sender, radius)) {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(entity);
|
||||
|
||||
if (disguise == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DisguiseType disguiseType = disguise.getType();
|
||||
|
||||
for (WatcherMethod method : ParamInfoManager.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) {
|
||||
for (String arg : args) {
|
||||
if (!method.getName().equalsIgnoreCase(arg) || usedOptions.contains(arg)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
usedOptions.add(arg);
|
||||
}
|
||||
}
|
||||
|
||||
DisguisePerm perm = new DisguisePerm(disguiseType);
|
||||
|
||||
if (perms.isAllowedDisguise(perm, usedOptions)) {
|
||||
tabs.addAll(getTabDisguiseSubOptions(sender, perms, perm, args, starting, getCurrentArg(args)));
|
||||
}
|
||||
}
|
||||
|
||||
return filterTabs(tabs, origArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the player the information
|
||||
*/
|
||||
@Override
|
||||
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
|
||||
|
||||
LibsMsg.DMODRADIUS_HELP1.send(sender, DisguiseConfig.getDisguiseRadiusMax());
|
||||
LibsMsg.DMODIFY_HELP3.send(sender, StringUtils.join(allowedDisguises, LibsMsg.CAN_USE_DISGS_SEPERATOR.get()));
|
||||
|
||||
LibsMsg.DMODRADIUS_HELP2.send(sender);
|
||||
LibsMsg.DMODRADIUS_HELP3.send(sender);
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package me.libraryaddict.disguise.commands.undisguise;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class UndisguiseCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player && !sender.isOp() &&
|
||||
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
|
||||
sender.sendMessage(ChatColor.RED + "This is the free version of Lib's Disguises, player commands are limited to console and Operators only! Purchase the plugin for non-admin usage!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender.getName().equals("CONSOLE")) {
|
||||
LibsMsg.NO_CONSOLE.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender.hasPermission("libsdisguises.undisguise") && !"%%__USER__%%".equals(12345 + "")) {
|
||||
if (DisguiseAPI.isDisguised((Entity) sender)) {
|
||||
DisguiseAPI.undisguiseToAll(sender, (Player) sender);
|
||||
LibsMsg.UNDISG.send(sender);
|
||||
} else {
|
||||
LibsMsg.NOT_DISGUISED.send(sender);
|
||||
}
|
||||
} else {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package me.libraryaddict.disguise.commands.undisguise;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.commands.interactions.UndisguiseEntityInteraction;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class UndisguiseEntityCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player && !sender.isOp() &&
|
||||
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
|
||||
sender.sendMessage(ChatColor.RED + "This is the free version of Lib's Disguises, player commands are limited to console and Operators only! Purchase the plugin for non-admin usage!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender.getName().equals("CONSOLE")) {
|
||||
LibsMsg.NO_CONSOLE.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission("libsdisguises.undisguiseentity")) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
LibsDisguises.getInstance().getListener().addInteraction(sender.getName(), new UndisguiseEntityInteraction(),
|
||||
DisguiseConfig.getDisguiseEntityExpire());
|
||||
LibsMsg.UND_ENTITY.send(sender);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,121 @@
|
||||
package me.libraryaddict.disguise.commands.undisguise;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter {
|
||||
protected ArrayList<String> filterTabs(ArrayList<String> list, String[] origArgs) {
|
||||
if (origArgs.length == 0)
|
||||
return list;
|
||||
|
||||
Iterator<String> itel = list.iterator();
|
||||
String label = origArgs[origArgs.length - 1].toLowerCase(Locale.ENGLISH);
|
||||
|
||||
while (itel.hasNext()) {
|
||||
String name = itel.next();
|
||||
|
||||
if (name.toLowerCase(Locale.ENGLISH).startsWith(label))
|
||||
continue;
|
||||
|
||||
itel.remove();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
protected String[] getArgs(String[] args) {
|
||||
ArrayList<String> newArgs = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < args.length - 1; i++) {
|
||||
String s = args[i];
|
||||
|
||||
if (s.trim().isEmpty())
|
||||
continue;
|
||||
|
||||
newArgs.add(s);
|
||||
}
|
||||
|
||||
return newArgs.toArray(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player && !sender.isOp() &&
|
||||
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
|
||||
sender.sendMessage(ChatColor.RED + "This is the free version of Lib's Disguises, player commands are limited to console and Operators only! Purchase the plugin for non-admin usage!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission("libsdisguises.undisguiseplayer")) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
LibsMsg.UNDISG_PLAYER_HELP.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
Entity entityTarget = Bukkit.getPlayer(args[0]);
|
||||
|
||||
if (entityTarget == null) {
|
||||
if (args[0].contains("-")) {
|
||||
try {
|
||||
entityTarget = Bukkit.getEntity(UUID.fromString(args[0]));
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entityTarget == null) {
|
||||
LibsMsg.CANNOT_FIND_PLAYER.send(sender, args[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (DisguiseAPI.isDisguised(entityTarget)) {
|
||||
DisguiseAPI.undisguiseToAll(sender, entityTarget);
|
||||
LibsMsg.UNDISG_PLAYER.send(sender,
|
||||
entityTarget instanceof Player ? entityTarget.getName() :
|
||||
DisguiseType.getType(entityTarget).toReadable());
|
||||
} else {
|
||||
LibsMsg.UNDISG_PLAYER_FAIL.send(sender,
|
||||
entityTarget instanceof Player ? entityTarget.getName() :
|
||||
DisguiseType.getType(entityTarget).toReadable());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
|
||||
ArrayList<String> tabs = new ArrayList<>();
|
||||
String[] args = getArgs(origArgs);
|
||||
|
||||
if (args.length != 0)
|
||||
return filterTabs(tabs, origArgs);
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
// If command user cannot see player online, don't tab-complete name
|
||||
if (sender instanceof Player && !((Player) sender).canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tabs.add(player.getName());
|
||||
}
|
||||
|
||||
return filterTabs(tabs, origArgs);
|
||||
}
|
||||
}
|
@@ -0,0 +1,84 @@
|
||||
package me.libraryaddict.disguise.commands.undisguise;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class UndisguiseRadiusCommand implements CommandExecutor {
|
||||
private boolean isNumeric(String string) {
|
||||
try {
|
||||
Integer.parseInt(string);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player && !sender.isOp() &&
|
||||
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
|
||||
sender.sendMessage(ChatColor.RED + "This is the free version of Lib's Disguises, player commands are limited to console and Operators only! Purchase the plugin for non-admin usage!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender.getName().equals("CONSOLE")) {
|
||||
LibsMsg.NO_CONSOLE.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender.hasPermission("libsdisguises.undisguiseradius")) {
|
||||
int radius = DisguiseConfig.getDisguiseRadiusMax();
|
||||
|
||||
if (args.length > 0) {
|
||||
if (!isNumeric(args[0])) {
|
||||
LibsMsg.NOT_NUMBER.send(sender, args[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
radius = Integer.parseInt(args[0]);
|
||||
|
||||
if (radius > DisguiseConfig.getDisguiseRadiusMax()) {
|
||||
LibsMsg.LIMITED_RADIUS.send(sender, DisguiseConfig.getDisguiseRadiusMax());
|
||||
radius = DisguiseConfig.getDisguiseRadiusMax();
|
||||
}
|
||||
}
|
||||
|
||||
Location center;
|
||||
|
||||
if (sender instanceof Player) {
|
||||
center = ((Player) sender).getLocation();
|
||||
} else {
|
||||
center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5);
|
||||
}
|
||||
|
||||
int disguisedEntitys = 0;
|
||||
|
||||
for (Entity entity : center.getWorld().getNearbyEntities(center, radius, radius, radius)) {
|
||||
if (entity == sender) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (DisguiseAPI.isDisguised(entity)) {
|
||||
DisguiseAPI.undisguiseToAll(sender, entity);
|
||||
disguisedEntitys++;
|
||||
}
|
||||
}
|
||||
|
||||
LibsMsg.UNDISRADIUS.send(sender, disguisedEntitys);
|
||||
} else {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,152 @@
|
||||
package me.libraryaddict.disguise.commands.utils;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.commands.interactions.CopyDisguiseInteraction;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 1/01/2020.
|
||||
*/
|
||||
public class CopyDisguiseCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
||||
if (sender instanceof Player && !sender.isOp() &&
|
||||
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
|
||||
sender.sendMessage(ChatColor.RED +
|
||||
"This is the free version of Lib's Disguises, player commands are limited to console and Operators only! Purchase the plugin for " +
|
||||
"non-admin usage!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission("libsdisguises.copydisguise")) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
Entity target = sender instanceof Player ? (Entity) sender : null;
|
||||
|
||||
if (args.length > 0) {
|
||||
target = Bukkit.getPlayer(args[0]);
|
||||
|
||||
if (target == null) {
|
||||
if (args[0].contains("-")) {
|
||||
try {
|
||||
target = Bukkit.getEntity(UUID.fromString(args[0]));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
LibsMsg.CANNOT_FIND_PLAYER.send(sender, args[0]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Disguise disguise = DisguiseAPI.getDisguise(target);
|
||||
|
||||
if (disguise == null) {
|
||||
LibsDisguises.getInstance().getListener()
|
||||
.addInteraction(sender.getName(), new CopyDisguiseInteraction(this), DisguiseConfig.getDisguiseEntityExpire());
|
||||
|
||||
LibsMsg.DISGUISECOPY_INTERACT.send(sender, DisguiseConfig.getDisguiseEntityExpire());
|
||||
return true;
|
||||
}
|
||||
|
||||
String disguiseString = DisguiseParser.parseToString(disguise, false);
|
||||
|
||||
sendMessage(sender, LibsMsg.CLICK_TO_COPY, LibsMsg.COPY_DISGUISE_NO_COPY, disguiseString, false);
|
||||
|
||||
if (disguise instanceof PlayerDisguise) {
|
||||
sendMessage(sender, LibsMsg.CLICK_TO_COPY_WITH_SKIN, LibsMsg.CLICK_TO_COPY_WITH_SKIN_NO_COPY, DisguiseParser.parseToString(disguise), true);
|
||||
}
|
||||
|
||||
DisguiseUtilities.setCopyDisguiseCommandUsed();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void sendMessage(CommandSender sender, LibsMsg msg, LibsMsg oldVer, String string, boolean forceAbbrev) {
|
||||
/* if (!NmsVersion.v1_13.isSupported()) {
|
||||
oldVer.send(sender, string);
|
||||
return;
|
||||
}*/
|
||||
|
||||
ComponentBuilder builder = new ComponentBuilder("").append(msg.getBase()).append(" ");
|
||||
|
||||
if (string.length() > 256 || forceAbbrev) {
|
||||
String[] split = DisguiseUtilities.split(string);
|
||||
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
if (split[i].length() <= 256) {
|
||||
continue;
|
||||
}
|
||||
|
||||
split = Arrays.copyOf(split, split.length + 1);
|
||||
|
||||
for (int a = split.length - 1; a > i; a--) {
|
||||
split[a] = split[a - 1];
|
||||
}
|
||||
|
||||
split[i + 1] = split[i].substring(256);
|
||||
split[i] = split[i].substring(0, 256);
|
||||
}
|
||||
|
||||
int sections = 0;
|
||||
StringBuilder current = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
if (current.length() > 0) {
|
||||
current.append(" ");
|
||||
}
|
||||
|
||||
current.append(split[i]);
|
||||
|
||||
// If the next split would fit
|
||||
if (split.length > i + 1 && split[i + 1].length() + current.length() + 1 <= 256) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sections != 0) {
|
||||
builder.append(" ");
|
||||
builder.reset();
|
||||
}
|
||||
|
||||
sections++;
|
||||
|
||||
builder.append(LibsMsg.CLICK_COPY.getBase(sections));
|
||||
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, current.toString()));
|
||||
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new ComponentBuilder("").append(LibsMsg.CLICK_TO_COPY_HOVER.getBase()).append(" " + sections).create()));
|
||||
|
||||
current = new StringBuilder();
|
||||
}
|
||||
} else {
|
||||
builder.append(LibsMsg.CLICK_COPY.getBase(string));
|
||||
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, string));
|
||||
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, LibsMsg.CLICK_TO_COPY_HOVER.getBase()));
|
||||
}
|
||||
|
||||
sender.spigot().sendMessage(builder.create());
|
||||
}
|
||||
}
|
@@ -0,0 +1,102 @@
|
||||
package me.libraryaddict.disguise.commands.utils;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
|
||||
import me.libraryaddict.disguise.commands.interactions.DisguiseCloneInteraction;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender.getName().equals("CONSOLE")) {
|
||||
LibsMsg.NO_CONSOLE.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission("libsdisguises.disguise.disguiseclone")) {
|
||||
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean doEquipment = true;
|
||||
boolean doAdded = false;
|
||||
Player player = null;
|
||||
|
||||
if (args.length > 0) {
|
||||
player = Bukkit.getPlayerExact(args[0]);
|
||||
}
|
||||
|
||||
for (int i = player == null ? 0 : 1; i < args.length; i++) {
|
||||
String option = args[i];
|
||||
if (StringUtils.startsWithIgnoreCase(option, LibsMsg.DCLONE_EQUIP.get())) {
|
||||
doEquipment = false;
|
||||
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_ADDEDANIMATIONS.get())) {
|
||||
doAdded = true;
|
||||
} else {
|
||||
LibsMsg.INVALID_CLONE.send(sender, option);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Boolean[] options = new Boolean[]{doEquipment, doAdded};
|
||||
|
||||
if (player != null) {
|
||||
DisguiseUtilities.createClonedDisguise((Player) sender, player, options);
|
||||
} else {
|
||||
LibsDisguises.getInstance().getListener()
|
||||
.addInteraction(sender.getName(), new DisguiseCloneInteraction(options),
|
||||
DisguiseConfig.getDisguiseCloneExpire());
|
||||
|
||||
LibsMsg.CLICK_TIMER.send(sender, DisguiseConfig.getDisguiseCloneExpire());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
|
||||
ArrayList<String> tabs = new ArrayList<>();
|
||||
|
||||
String[] args = getPreviousArgs(origArgs);
|
||||
|
||||
if (args.length == 0) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
// If command user cannot see player online, don't tab-complete name
|
||||
if (sender instanceof Player && !((Player) sender).canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tabs.add(player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
tabs.add(LibsMsg.DCLONE_EQUIP.get());
|
||||
tabs.add(LibsMsg.DCLONE_ADDEDANIMATIONS.get());
|
||||
|
||||
return filterTabs(tabs, origArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the player the information
|
||||
*/
|
||||
@Override
|
||||
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
|
||||
LibsMsg.CLONE_HELP1.send(sender);
|
||||
LibsMsg.CLONE_HELP2.send(sender);
|
||||
LibsMsg.CLONE_HELP3.send(sender);
|
||||
}
|
||||
}
|
@@ -0,0 +1,172 @@
|
||||
package me.libraryaddict.disguise.commands.utils;
|
||||
|
||||
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
|
||||
import me.libraryaddict.disguise.utilities.params.ParamInfo;
|
||||
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
|
||||
import me.libraryaddict.disguise.utilities.parser.WatcherMethod;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import me.libraryaddict.disguise.utilities.translations.TranslateType;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
for (String node : getCommandNames().values()) {
|
||||
DisguisePermissions perms = DisguiseParser.getPermissions(sender, node);
|
||||
|
||||
if (!perms.hasPermissions()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
sendCommandUsage(sender, null);
|
||||
return true;
|
||||
} else {
|
||||
ParamInfo help = null;
|
||||
|
||||
for (ParamInfo s : ParamInfoManager.getParamInfos()) {
|
||||
String name = s.getName().replaceAll(" ", "");
|
||||
|
||||
if (args[0].equalsIgnoreCase(name) || args[0].equalsIgnoreCase(name + "s")) {
|
||||
help = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (help != null) {
|
||||
if (help.hasValues() && help.canTranslateValues()) {
|
||||
LibsMsg.DHELP_HELP4.send(sender, help.getName(),
|
||||
StringUtils.join(help.getEnums(""), LibsMsg.DHELP_HELP4_SEPERATOR.get()));
|
||||
} else {
|
||||
if (!help.getName().equals(help.getDescriptiveName())) {
|
||||
LibsMsg.DHELP_HELP6
|
||||
.send(sender, help.getName(), help.getDescriptiveName(), help.getDescription());
|
||||
} else {
|
||||
LibsMsg.DHELP_HELP5.send(sender, help.getName(), help.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DisguisePerm type = DisguiseParser.getDisguisePerm(args[0]);
|
||||
|
||||
if (type == null) {
|
||||
LibsMsg.DHELP_CANTFIND.send(sender, args[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!perms.isAllowedDisguise(type)) {
|
||||
LibsMsg.NO_PERM_DISGUISE.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
ArrayList<String> methods = new ArrayList<>();
|
||||
Class watcher = type.getWatcherClass();
|
||||
int ignored = 0;
|
||||
|
||||
try {
|
||||
for (WatcherMethod method : ParamInfoManager.getDisguiseWatcherMethods(watcher)) {
|
||||
if (args.length < 2 || !args[1].equalsIgnoreCase(LibsMsg.DHELP_SHOW.get())) {
|
||||
if (!perms.isAllowedDisguise(type, Collections.singleton(method.getName().toLowerCase(
|
||||
Locale.ENGLISH)))) {
|
||||
ignored++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ParamInfo info = ParamInfoManager.getParamInfo(method);
|
||||
|
||||
int value = ParamInfoManager.getValue(method);
|
||||
ChatColor methodColor = ChatColor.YELLOW;
|
||||
|
||||
if (value == 1) {
|
||||
methodColor = ChatColor.AQUA;
|
||||
} else if (value == 2) {
|
||||
methodColor = ChatColor.GRAY;
|
||||
}
|
||||
|
||||
String str = TranslateType.DISGUISE_OPTIONS.get(method.getName()) + ChatColor.DARK_RED + "(" +
|
||||
ChatColor.GREEN + info.getName() + ChatColor.DARK_RED + ")";
|
||||
|
||||
methods.add(methodColor + str);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
if (methods.isEmpty()) {
|
||||
methods.add(LibsMsg.DHELP_NO_OPTIONS.get());
|
||||
}
|
||||
|
||||
LibsMsg.DHELP_OPTIONS.send(sender, ChatColor.DARK_RED + type.toReadable(),
|
||||
StringUtils.join(methods, ChatColor.DARK_RED + ", "));
|
||||
|
||||
if (ignored > 0) {
|
||||
LibsMsg.NO_PERMS_USE_OPTIONS.send(sender, ignored);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
|
||||
ArrayList<String> tabs = new ArrayList<>();
|
||||
String[] args = getPreviousArgs(origArgs);
|
||||
|
||||
for (String node : getCommandNames().values()) {
|
||||
DisguisePermissions perms = DisguiseParser.getPermissions(sender, node);
|
||||
|
||||
if (args.length == 0) {
|
||||
for (DisguisePerm type : perms.getAllowed()) {
|
||||
if (type.isUnknown())
|
||||
continue;
|
||||
|
||||
tabs.add(type.toReadable().replaceAll(" ", "_"));
|
||||
}
|
||||
|
||||
for (ParamInfo s : ParamInfoManager.getParamInfos()) {
|
||||
tabs.add(s.getName().replaceAll(" ", ""));
|
||||
}
|
||||
} else if (DisguiseParser.getDisguisePerm(args[0]) == null) {
|
||||
tabs.add(LibsMsg.DHELP_SHOW.get());
|
||||
}
|
||||
}
|
||||
|
||||
return filterTabs(tabs, origArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the player the information
|
||||
*/
|
||||
@Override
|
||||
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
|
||||
LibsMsg.DHELP_HELP1.send(sender);
|
||||
LibsMsg.DHELP_HELP2.send(sender);
|
||||
|
||||
for (ParamInfo s : ParamInfoManager.getParamInfos()) {
|
||||
LibsMsg.DHELP_HELP3.send(sender, s.getName().replaceAll(" ", "") +
|
||||
(!s.getName().equals(s.getDescriptiveName()) ? " ~ " + s.getDescriptiveName() : ""),
|
||||
s.getDescription());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package me.libraryaddict.disguise.commands.utils;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 2/07/2020.
|
||||
*/
|
||||
public class DisguiseViewBarCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (sender.getName().equals("CONSOLE")) {
|
||||
LibsMsg.NO_CONSOLE.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (DisguiseAPI.isNotifyBarShown(player)) {
|
||||
DisguiseAPI.setActionBarShown(player, false);
|
||||
LibsMsg.VIEW_BAR_OFF.send(sender);
|
||||
} else {
|
||||
DisguiseAPI.setActionBarShown(player, true);
|
||||
LibsMsg.VIEW_BAR_ON.send(sender);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package me.libraryaddict.disguise.commands.utils;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Navid
|
||||
*/
|
||||
public class DisguiseViewSelfCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (sender.getName().equals("CONSOLE")) {
|
||||
LibsMsg.NO_CONSOLE.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (DisguiseAPI.isViewSelfToggled(player)) {
|
||||
DisguiseAPI.setViewDisguiseToggled(player, false);
|
||||
LibsMsg.VIEW_SELF_OFF.send(sender);
|
||||
} else {
|
||||
DisguiseAPI.setViewDisguiseToggled(player, true);
|
||||
LibsMsg.VIEW_SELF_ON.send(sender);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,124 @@
|
||||
package me.libraryaddict.disguise.commands.utils;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.SkinUtils;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 20/06/2020.
|
||||
*/
|
||||
public class GrabHeadCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] strings) {
|
||||
if (sender instanceof Player && !sender.isOp() &&
|
||||
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
|
||||
sender.sendMessage(ChatColor.RED + "This is the free version of Lib's Disguises, player commands are limited to console and Operators only! Purchase the plugin for non-admin usage!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission("libsdisguises.grabhead")) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
LibsMsg.NO_CONSOLE.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strings.length == 0) {
|
||||
sendHelp(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
String[] args = DisguiseUtilities.split(StringUtils.join(strings, " "));
|
||||
String skin = args[0];
|
||||
|
||||
String usable = SkinUtils.getUsableStatus();
|
||||
|
||||
if (usable != null) {
|
||||
sender.sendMessage(usable);
|
||||
return true;
|
||||
}
|
||||
|
||||
SkinUtils.SkinCallback callback = new SkinUtils.SkinCallback() {
|
||||
private BukkitTask runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LibsMsg.PLEASE_WAIT.send(sender);
|
||||
}
|
||||
}.runTaskTimer(LibsDisguises.getInstance(), 100, 100);
|
||||
|
||||
@Override
|
||||
public void onError(LibsMsg msg, Object... args) {
|
||||
msg.send(sender, args);
|
||||
|
||||
runnable.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInfo(LibsMsg msg, Object... args) {
|
||||
msg.send(sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(WrappedGameProfile profile) {
|
||||
runnable.cancel();
|
||||
DisguiseUtilities.doSkinUUIDWarning(sender);
|
||||
|
||||
DisguiseUtilities.setGrabHeadCommandUsed();
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ItemStack skull = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta meta = (SkullMeta) skull.getItemMeta();
|
||||
|
||||
try {
|
||||
Field field = meta.getClass().getDeclaredField("profile");
|
||||
field.setAccessible(true);
|
||||
field.set(meta, profile.getHandle());
|
||||
}
|
||||
catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
skull.setItemMeta(meta);
|
||||
|
||||
((Player) sender).getInventory().addItem(skull);
|
||||
LibsMsg.GRAB_HEAD_SUCCESS.send(sender);
|
||||
}
|
||||
}.runTask(LibsDisguises.getInstance());
|
||||
}
|
||||
};
|
||||
|
||||
SkinUtils.grabSkin(skin, callback);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sendHelp(CommandSender sender) {
|
||||
LibsMsg.GRAB_DISG_HELP_1.send(sender);
|
||||
LibsMsg.GRAB_DISG_HELP_2.send(sender);
|
||||
LibsMsg.GRAB_DISG_HELP_3.send(sender);
|
||||
LibsMsg.GRAB_DISG_HELP_4.send(sender);
|
||||
LibsMsg.GRAB_DISG_HELP_5.send(sender);
|
||||
LibsMsg.GRAB_DISG_HELP_6.send(sender);
|
||||
}
|
||||
}
|
@@ -0,0 +1,171 @@
|
||||
package me.libraryaddict.disguise.commands.utils;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.SkinUtils;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 28/12/2019.
|
||||
*/
|
||||
public class GrabSkinCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] strings) {
|
||||
if (sender instanceof Player && !sender.isOp() &&
|
||||
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
|
||||
sender.sendMessage(ChatColor.RED +
|
||||
"This is the free version of Lib's Disguises, player commands are limited to console and Operators only! Purchase the plugin for " +
|
||||
"non-admin usage!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission("libsdisguises.grabskin")) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strings.length == 0) {
|
||||
sendHelp(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
String[] args = DisguiseUtilities.split(StringUtils.join(strings, " "));
|
||||
String tName = args.length > 1 ? args[0] : null;
|
||||
String skin = args.length > 1 ? args[1] : args[0];
|
||||
|
||||
String usable = SkinUtils.getUsableStatus();
|
||||
|
||||
if (usable != null) {
|
||||
sender.sendMessage(usable);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (tName == null && skin.matches("(.*\\/)?[a-zA-Z0-9_-]{3,20}(\\.png)?")) {
|
||||
int start = skin.lastIndexOf("/") + 1;
|
||||
int end = skin.length();
|
||||
|
||||
if (skin.lastIndexOf(".", start) > start) {
|
||||
end = skin.lastIndexOf(".", start);
|
||||
}
|
||||
|
||||
tName = skin.substring(start, end);
|
||||
|
||||
if (DisguiseUtilities.hasGameProfile(tName)) {
|
||||
tName = null;
|
||||
}
|
||||
}
|
||||
|
||||
String name = tName;
|
||||
|
||||
SkinUtils.SkinCallback callback = new SkinUtils.SkinCallback() {
|
||||
private BukkitTask runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LibsMsg.PLEASE_WAIT.send(sender);
|
||||
}
|
||||
}.runTaskTimer(LibsDisguises.getInstance(), 100, 100);
|
||||
|
||||
@Override
|
||||
public void onError(LibsMsg msg, Object... args) {
|
||||
msg.send(sender, args);
|
||||
|
||||
runnable.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInfo(LibsMsg msg, Object... args) {
|
||||
msg.send(sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(WrappedGameProfile profile) {
|
||||
runnable.cancel();
|
||||
DisguiseUtilities.doSkinUUIDWarning(sender);
|
||||
|
||||
String nName = name;
|
||||
|
||||
if (nName == null) {
|
||||
int i = 1;
|
||||
|
||||
while (DisguiseUtilities.hasGameProfile("skin" + i)) {
|
||||
i++;
|
||||
}
|
||||
|
||||
nName = "skin" + i;
|
||||
}
|
||||
|
||||
if (profile.getName() == null || !profile.getName().equals(nName)) {
|
||||
profile = ReflectionManager.getGameProfileWithThisSkin(profile.getUUID(), profile.getName(), profile);
|
||||
}
|
||||
|
||||
DisguiseAPI.addGameProfile(nName, profile);
|
||||
LibsMsg.GRABBED_SKIN.send(sender, nName);
|
||||
|
||||
String string = DisguiseUtilities.getGson().toJson(profile);
|
||||
int start = 0;
|
||||
int msg = 1;
|
||||
|
||||
//if (NmsVersion.v1_13.isSupported()) {
|
||||
ComponentBuilder builder = new ComponentBuilder("").append(LibsMsg.CLICK_TO_COPY.getBase());
|
||||
|
||||
while (start < string.length()) {
|
||||
int end = Math.min(256, string.length() - start);
|
||||
|
||||
String sub = string.substring(start, start + end);
|
||||
|
||||
builder.append(" ");
|
||||
|
||||
if (string.length() <= 256) {
|
||||
builder.append(LibsMsg.CLICK_TO_COPY_DATA.getBase());
|
||||
} else {
|
||||
builder.reset();
|
||||
builder.append(LibsMsg.CLICK_COPY.getBase(msg));
|
||||
}
|
||||
|
||||
start += end;
|
||||
|
||||
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, sub));
|
||||
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new ComponentBuilder("").append(LibsMsg.CLICK_TO_COPY_HOVER.getBase()).append(" " + msg).create()));
|
||||
msg += 1;
|
||||
}
|
||||
|
||||
sender.spigot().sendMessage(builder.create());
|
||||
/*} else {
|
||||
LibsMsg.SKIN_DATA.send(sender, string);
|
||||
}*/
|
||||
|
||||
DisguiseUtilities.setGrabSkinCommandUsed();
|
||||
}
|
||||
};
|
||||
|
||||
SkinUtils.grabSkin(skin, callback);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sendHelp(CommandSender sender) {
|
||||
LibsMsg.GRAB_DISG_HELP_1.send(sender);
|
||||
LibsMsg.GRAB_DISG_HELP_2.send(sender);
|
||||
LibsMsg.GRAB_DISG_HELP_3.send(sender);
|
||||
LibsMsg.GRAB_DISG_HELP_4.send(sender);
|
||||
LibsMsg.GRAB_DISG_HELP_5.send(sender);
|
||||
LibsMsg.GRAB_DISG_HELP_6.send(sender);
|
||||
}
|
||||
}
|
@@ -0,0 +1,189 @@
|
||||
package me.libraryaddict.disguise.commands.utils;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.SkinUtils;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 28/12/2019.
|
||||
*/
|
||||
public class SaveDisguiseCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] strings) {
|
||||
if (sender instanceof Player && !sender.isOp() &&
|
||||
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
|
||||
sender.sendMessage(ChatColor.RED +
|
||||
"This is the free version of Lib's Disguises, player commands are limited to console and Operators only! Purchase the plugin for " +
|
||||
"non-admin usage!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission("libsdisguises.savedisguise")) {
|
||||
LibsMsg.NO_PERM.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strings.length == 0) {
|
||||
sendHelp(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
strings = DisguiseUtilities.split(StringUtils.join(strings, " "));
|
||||
|
||||
String name = strings[0];
|
||||
String[] args = Arrays.copyOfRange(strings, 1, strings.length);
|
||||
|
||||
if (args.length == 0) {
|
||||
if (!(sender instanceof Player)) {
|
||||
LibsMsg.NO_CONSOLE.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
Disguise disguise = DisguiseAPI.getDisguise((Entity) sender);
|
||||
|
||||
if (disguise == null) {
|
||||
LibsMsg.NOT_DISGUISED.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
String disguiseString = DisguiseAPI.parseToString(disguise);
|
||||
|
||||
try {
|
||||
DisguiseAPI.addCustomDisguise(name, disguiseString);
|
||||
|
||||
LibsMsg.CUSTOM_DISGUISE_SAVED.send(sender, name);
|
||||
} catch (DisguiseParseException e) {
|
||||
if (e.getMessage() != null) {
|
||||
e.send(sender);
|
||||
} else {
|
||||
LibsMsg.PARSE_CANT_LOAD.send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// If going to be doing a player disguise...
|
||||
if (args.length >= 2 && args[0].equalsIgnoreCase("player")) {
|
||||
int i = 2;
|
||||
|
||||
for (; i < args.length; i++) {
|
||||
if (!args[i].equalsIgnoreCase("setskin")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Make array larger, and some logic incase 'setskin' was the last arg
|
||||
// Player Notch = 2 - Add 2
|
||||
// player Notch setskin = 2 - Add 1
|
||||
// player Notch setskin Notch = 2 - Add 0
|
||||
if (args.length < i + 1) {
|
||||
args = Arrays.copyOf(args, Math.max(args.length, i + 2));
|
||||
i = args.length - 2;
|
||||
|
||||
args[i] = "setSkin";
|
||||
args[i + 1] = args[1];
|
||||
}
|
||||
|
||||
int skinId = i + 1;
|
||||
|
||||
if (!args[skinId].startsWith("{")) {
|
||||
String usable = SkinUtils.getUsableStatus();
|
||||
|
||||
if (usable != null) {
|
||||
DisguiseUtilities.sendMessage(sender, usable);
|
||||
return true;
|
||||
}
|
||||
|
||||
String[] finalArgs = args;
|
||||
|
||||
SkinUtils.grabSkin(args[skinId], new SkinUtils.SkinCallback() {
|
||||
private BukkitTask runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LibsMsg.PLEASE_WAIT.send(sender);
|
||||
}
|
||||
}.runTaskTimer(LibsDisguises.getInstance(), 100, 100);
|
||||
|
||||
@Override
|
||||
public void onError(LibsMsg msg, Object... args) {
|
||||
runnable.cancel();
|
||||
|
||||
msg.send(sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInfo(LibsMsg msg, Object... args) {
|
||||
msg.send(sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(WrappedGameProfile profile) {
|
||||
runnable.cancel();
|
||||
DisguiseUtilities.doSkinUUIDWarning(sender);
|
||||
|
||||
finalArgs[skinId] = DisguiseUtilities.getGson().toJson(profile);
|
||||
|
||||
saveDisguise(sender, name, finalArgs);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
saveDisguise(sender, name, args);
|
||||
}
|
||||
} else {
|
||||
saveDisguise(sender, name, args);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void saveDisguise(CommandSender sender, String name, String[] args) {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
args[i] = DisguiseUtilities.quote(args[i]);
|
||||
}
|
||||
|
||||
String disguiseString = StringUtils.join(args, " ");
|
||||
|
||||
try {
|
||||
DisguiseAPI.addCustomDisguise(name, disguiseString);
|
||||
LibsMsg.CUSTOM_DISGUISE_SAVED.send(sender, name);
|
||||
|
||||
DisguiseUtilities.setSaveDisguiseCommandUsed();
|
||||
} catch (DisguiseParseException e) {
|
||||
if (e.getMessage() != null) {
|
||||
e.send(sender);
|
||||
} else {
|
||||
LibsMsg.PARSE_CANT_LOAD.send(sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void sendHelp(CommandSender sender) {
|
||||
LibsMsg.SAVE_DISG_HELP_1.send(sender);
|
||||
LibsMsg.SAVE_DISG_HELP_2.send(sender);
|
||||
LibsMsg.SAVE_DISG_HELP_3.send(sender);
|
||||
LibsMsg.SAVE_DISG_HELP_4.send(sender);
|
||||
LibsMsg.SAVE_DISG_HELP_5.send(sender);
|
||||
LibsMsg.SAVE_DISG_HELP_6.send(sender);
|
||||
}
|
||||
}
|
@@ -0,0 +1,124 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public enum AnimalColor {
|
||||
BLACK(DyeColor.BLACK,
|
||||
NmsVersion.v1_13.isSupported() ? Material.getMaterial("INK_SAC") : Material.getMaterial("INK_SACK")),
|
||||
BLUE(DyeColor.BLUE, NmsVersion.v1_13.isSupported() ? Material.getMaterial("LAPIS_LAZULI") : null),
|
||||
BROWN(DyeColor.BROWN, NmsVersion.v1_13.isSupported() ? Material.getMaterial("COCOA_BEANS") : null),
|
||||
CYAN(DyeColor.CYAN, NmsVersion.v1_13.isSupported() ? Material.getMaterial("CYAN_DYE") : null),
|
||||
GRAY(DyeColor.GRAY, NmsVersion.v1_13.isSupported() ? Material.getMaterial("GRAY_DYE") : null),
|
||||
GREEN(DyeColor.GREEN,
|
||||
NmsVersion.v1_14.isSupported() ? Material.getMaterial("GREEN_DYE") : Material.getMaterial("CACTUS_GREEN")),
|
||||
LIGHT_BLUE(DyeColor.LIGHT_BLUE, NmsVersion.v1_13.isSupported() ? Material.getMaterial("LIGHT_BLUE_DYE") : null),
|
||||
LIME(DyeColor.LIME, NmsVersion.v1_13.isSupported() ? Material.getMaterial("LIME_DYE") : null),
|
||||
MAGENTA(DyeColor.MAGENTA, NmsVersion.v1_13.isSupported() ? Material.getMaterial("MAGENTA_DYE") : null),
|
||||
ORANGE(DyeColor.ORANGE, NmsVersion.v1_13.isSupported() ? Material.getMaterial("ORANGE_DYE") : null),
|
||||
PINK(DyeColor.PINK, NmsVersion.v1_13.isSupported() ? Material.getMaterial("PINK_DYE") : null),
|
||||
PURPLE(DyeColor.PURPLE, NmsVersion.v1_13.isSupported() ? Material.getMaterial("PURPLE_DYE") : null),
|
||||
RED(DyeColor.RED,
|
||||
NmsVersion.v1_14.isSupported() ? Material.getMaterial("RED_DYE") : Material.getMaterial("ROSE_RED")),
|
||||
LIGHT_GRAY(DyeColor.valueOf(NmsVersion.v1_13.isSupported() ? "LIGHT_GRAY" : "SILVER"),
|
||||
NmsVersion.v1_13.isSupported() ? Material.getMaterial("LIGHT_GRAY_DYE") : null),
|
||||
WHITE(DyeColor.WHITE, NmsVersion.v1_13.isSupported() ? Material.getMaterial("BONE_MEAL") : null),
|
||||
YELLOW(DyeColor.YELLOW, NmsVersion.v1_14.isSupported() ? Material.getMaterial("YELLOW_DYE") :
|
||||
Material.getMaterial("DANDELION_YELLOW"));
|
||||
|
||||
public static AnimalColor getColorByWool(int woolId) {
|
||||
for (AnimalColor color : values()) {
|
||||
if (woolId != color.getDyeColor().getWoolData()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static AnimalColor getColorByWool(Material carpet) {
|
||||
if (carpet == null || (!carpet.name().endsWith("_WOOL") && !carpet.name().endsWith("_CARPET"))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String name = carpet.name().replace("_CARPET", "").replace("_WOOL", "");
|
||||
|
||||
for (AnimalColor color : AnimalColor.values()) {
|
||||
if (!color.name().equals(name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static AnimalColor getColorByItem(ItemStack itemStack) {
|
||||
if (NmsVersion.v1_13.isSupported()) {
|
||||
return getColorByMaterial(itemStack.getType());
|
||||
}
|
||||
|
||||
if (itemStack.getType().name().matches("(WOOL)|(CARPET)|(INK_SACK?)")) {
|
||||
return getColorByWool(itemStack.getDurability());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static AnimalColor getColorByMaterial(Material material) {
|
||||
for (AnimalColor color : values()) {
|
||||
if (color.getDyeMaterial() != material) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static AnimalColor getColorByDye(int dyeId) {
|
||||
for (AnimalColor color : values()) {
|
||||
if (dyeId != color.getDyeColor().getDyeData()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static AnimalColor getColor(DyeColor dyeColor) {
|
||||
for (AnimalColor color : values()) {
|
||||
if (dyeColor != color.getDyeColor()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private DyeColor dyeColor;
|
||||
private Material material;
|
||||
|
||||
AnimalColor(DyeColor color, Material material) {
|
||||
dyeColor = color;
|
||||
this.material = NmsVersion.v1_13.isSupported() ? material : Material.getMaterial("INK_SACK");
|
||||
}
|
||||
|
||||
public Material getDyeMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public DyeColor getDyeColor() {
|
||||
return dyeColor;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,245 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.BatWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 20/05/2021.
|
||||
*/
|
||||
class DisguiseRunnable extends BukkitRunnable {
|
||||
private int blockX, blockY, blockZ, facing;
|
||||
private int deadTicks = 0;
|
||||
private int actionBarTicks = -1;
|
||||
private int refreshRate;
|
||||
private long lastRefreshed = System.currentTimeMillis();
|
||||
private Disguise disguise;
|
||||
final Double vectorY;
|
||||
final boolean alwaysSendVelocity;
|
||||
|
||||
public DisguiseRunnable(Disguise disguise) {
|
||||
this.disguise = disguise;
|
||||
|
||||
switch (disguise.getType()) {
|
||||
case FIREWORK:
|
||||
case WITHER_SKULL:
|
||||
case EXPERIENCE_ORB:
|
||||
vectorY = 0.000001D;
|
||||
alwaysSendVelocity = true;
|
||||
break;
|
||||
default:
|
||||
vectorY = null;
|
||||
alwaysSendVelocity = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Where refresh rate is in ticks, exp is in here due to a fire exploit + stop it glitching out so much
|
||||
switch (disguise.getType()) {
|
||||
case FIREWORK:
|
||||
case EXPERIENCE_ORB:
|
||||
refreshRate = 40; // 2 seconds
|
||||
break;
|
||||
case EVOKER_FANGS:
|
||||
refreshRate = 23;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
refreshRate *= 50;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!disguise.isDisguiseInUse() || disguise.getEntity() == null || !Bukkit.getWorlds().contains(disguise.getEntity().getWorld())) {
|
||||
disguise.stopDisguise();
|
||||
|
||||
// If still somehow not cancelled
|
||||
if (!isCancelled()) {
|
||||
cancel();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (++actionBarTicks % 15 == 0) {
|
||||
actionBarTicks = 0;
|
||||
|
||||
disguise.doActionBar();
|
||||
}
|
||||
|
||||
// If entity is no longer valid. Remove it.
|
||||
if (disguise.getEntity() instanceof Player && !((Player) disguise.getEntity()).isOnline()) {
|
||||
disguise.removeDisguise();
|
||||
} else if (disguise.disguiseExpires > 0 && (DisguiseConfig.isDynamicExpiry() ? disguise.disguiseExpires-- == 1 :
|
||||
disguise.disguiseExpires < System.currentTimeMillis())) { // If disguise expired
|
||||
disguise.removeDisguise();
|
||||
|
||||
if (disguise.getEntity() instanceof Player) {
|
||||
LibsMsg.EXPIRED_DISGUISE.send(disguise.getEntity());
|
||||
}
|
||||
|
||||
return;
|
||||
} else if (!disguise.getEntity().isValid()) {
|
||||
// If it has been dead for 30+ ticks
|
||||
// This is to ensure that this disguise isn't removed while clients think its the real entity
|
||||
// The delay is because if it sends the destroy entity packets straight away, then it means no
|
||||
// death animation
|
||||
// This is probably still a problem for wither and enderdragon deaths.
|
||||
if (deadTicks++ > (disguise.getType() == DisguiseType.ENDER_DRAGON ? 200 : 20)) {
|
||||
if (disguise.isRemoveDisguiseOnDeath()) {
|
||||
disguise.removeDisguise();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
deadTicks = 0;
|
||||
|
||||
// If the disguise type is invisibable, we need to resend the entity packet else it will turn invisible
|
||||
if (refreshRate > 0 && lastRefreshed + refreshRate < System.currentTimeMillis()) {
|
||||
lastRefreshed = System.currentTimeMillis();
|
||||
|
||||
DisguiseUtilities.refreshTrackers((TargetedDisguise) disguise);
|
||||
}
|
||||
|
||||
if (disguise.isModifyBoundingBox()) {
|
||||
DisguiseUtilities.doBoundingBox((TargetedDisguise) disguise);
|
||||
}
|
||||
|
||||
if (disguise.getType() == DisguiseType.BAT && !((BatWatcher) disguise.getWatcher()).isHanging()) {
|
||||
return;
|
||||
}
|
||||
|
||||
doVelocity(vectorY, alwaysSendVelocity);
|
||||
|
||||
if (disguise.getType() == DisguiseType.EXPERIENCE_ORB) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE);
|
||||
|
||||
packet.getIntegers().write(0, disguise.getEntity().getEntityId());
|
||||
|
||||
try {
|
||||
for (Player player : DisguiseUtilities.getPerverts(disguise)) {
|
||||
if (disguise.getEntity() != player) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
continue;
|
||||
} else if (!disguise.isSelfDisguiseVisible() || !(disguise.getEntity() instanceof Player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PacketContainer selfPacket = packet.shallowClone();
|
||||
|
||||
selfPacket.getModifier().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), selfPacket, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doVelocity(Double vectorY, boolean alwaysSendVelocity) {
|
||||
// If the vectorY isn't 0. Cos if it is. Then it doesn't want to send any vectors.
|
||||
// If this disguise has velocity sending enabled and the entity is flying.
|
||||
if (disguise.isVelocitySent() && vectorY != null && (alwaysSendVelocity || !disguise.getEntity().isOnGround())) {
|
||||
Vector vector = disguise.getEntity().getVelocity();
|
||||
|
||||
// If the entity doesn't have velocity changes already - You know. I really can't wrap my
|
||||
// head about the
|
||||
// if statement.
|
||||
// But it doesn't seem to do anything wrong..
|
||||
if (vector.getY() != 0 && !(vector.getY() < 0 && alwaysSendVelocity && disguise.getEntity().isOnGround())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If disguise isn't a experience orb, or the entity isn't standing on the ground
|
||||
if (disguise.getType() != DisguiseType.EXPERIENCE_ORB || !disguise.getEntity().isOnGround()) {
|
||||
PacketContainer lookPacket = null;
|
||||
|
||||
if (disguise.getType() == DisguiseType.WITHER_SKULL && DisguiseConfig.isWitherSkullPacketsEnabled()) {
|
||||
lookPacket = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
|
||||
|
||||
StructureModifier<Object> mods = lookPacket.getModifier();
|
||||
lookPacket.getIntegers().write(0, disguise.getEntity().getEntityId());
|
||||
Location loc = disguise.getEntity().getLocation();
|
||||
|
||||
mods.write(4,
|
||||
DisguiseUtilities.getYaw(disguise.getType(), disguise.getEntity().getType(), (byte) Math.floor(loc.getYaw() * 256.0F / 360.0F)));
|
||||
mods.write(5, DisguiseUtilities
|
||||
.getPitch(disguise.getType(), disguise.getEntity().getType(), (byte) Math.floor(loc.getPitch() * 256.0F / 360.0F)));
|
||||
|
||||
if (disguise.isSelfDisguiseVisible() && disguise.getEntity() instanceof Player) {
|
||||
PacketContainer selfLookPacket = lookPacket.shallowClone();
|
||||
|
||||
selfLookPacket.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), selfLookPacket, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
PacketContainer velocityPacket = new PacketContainer(PacketType.Play.Server.ENTITY_VELOCITY);
|
||||
|
||||
StructureModifier<Integer> mods = velocityPacket.getIntegers();
|
||||
|
||||
// Write entity ID
|
||||
mods.write(0, disguise.getEntity().getEntityId());
|
||||
mods.write(1, (int) (vector.getX() * 8000));
|
||||
mods.write(3, (int) (vector.getZ() * 8000));
|
||||
|
||||
for (Player player : DisguiseUtilities.getPerverts(disguise)) {
|
||||
PacketContainer tempVelocityPacket = velocityPacket.shallowClone();
|
||||
mods = tempVelocityPacket.getIntegers();
|
||||
|
||||
// If the viewing player is the disguised player
|
||||
if (disguise.getEntity() == player) {
|
||||
// If not using self disguise, continue
|
||||
if (!disguise.isSelfDisguiseVisible()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Write self disguise ID
|
||||
mods.write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
}
|
||||
|
||||
mods.write(2, (int) (8000D * (vectorY * ReflectionManager.getPing(player)) * 0.069D));
|
||||
|
||||
if (lookPacket != null && player != disguise.getEntity()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, lookPacket, false);
|
||||
}
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, tempVelocityPacket, false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// If we need to send a packet to update the exp position as it likes to gravitate client
|
||||
// sided to
|
||||
// players.
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,381 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import me.libraryaddict.disguise.utilities.translations.TranslateType;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public enum DisguiseType {
|
||||
AREA_EFFECT_CLOUD(3, 0),
|
||||
|
||||
ARMOR_STAND(78),
|
||||
|
||||
ARROW(60, 0),
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_17) AXOLOTL,
|
||||
|
||||
BAT,
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_15) BEE,
|
||||
|
||||
BLAZE,
|
||||
|
||||
BOAT(1),
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14) CAT,
|
||||
|
||||
CAVE_SPIDER,
|
||||
|
||||
CHICKEN,
|
||||
|
||||
COD,
|
||||
|
||||
COW,
|
||||
|
||||
CREEPER,
|
||||
|
||||
DOLPHIN,
|
||||
|
||||
DONKEY,
|
||||
|
||||
DRAGON_FIREBALL(93),
|
||||
|
||||
DROWNED,
|
||||
|
||||
DROPPED_ITEM(2, 1),
|
||||
|
||||
EGG(62),
|
||||
|
||||
ELDER_GUARDIAN,
|
||||
|
||||
ENDER_CRYSTAL(51),
|
||||
|
||||
ENDER_DRAGON,
|
||||
|
||||
ENDER_PEARL(65),
|
||||
|
||||
ENDER_SIGNAL(72),
|
||||
|
||||
ENDERMAN,
|
||||
|
||||
ENDERMITE,
|
||||
|
||||
EVOKER,
|
||||
|
||||
EVOKER_FANGS(79),
|
||||
|
||||
EXPERIENCE_ORB,
|
||||
|
||||
FALLING_BLOCK(70),
|
||||
|
||||
FIREBALL(63),
|
||||
|
||||
FIREWORK(76),
|
||||
|
||||
FISHING_HOOK(90),
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14) FOX,
|
||||
|
||||
GHAST,
|
||||
|
||||
GIANT,
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_17) GLOW_ITEM_FRAME,
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_17) GLOW_SQUID,
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_17) GOAT,
|
||||
|
||||
GUARDIAN,
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_16) HOGLIN,
|
||||
|
||||
HORSE,
|
||||
|
||||
HUSK,
|
||||
|
||||
ILLUSIONER,
|
||||
|
||||
IRON_GOLEM,
|
||||
|
||||
ITEM_FRAME(71),
|
||||
|
||||
LLAMA,
|
||||
|
||||
LLAMA_SPIT(68),
|
||||
|
||||
LEASH_HITCH(77),
|
||||
|
||||
MAGMA_CUBE,
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_17) MARKER,
|
||||
|
||||
MINECART(10),
|
||||
|
||||
MINECART_CHEST(10, 1),
|
||||
|
||||
MINECART_COMMAND(10, 6),
|
||||
|
||||
MINECART_FURNACE(10, 2),
|
||||
|
||||
MINECART_HOPPER(10, 5),
|
||||
|
||||
MINECART_MOB_SPAWNER(10, 4),
|
||||
|
||||
MINECART_TNT(10, 3),
|
||||
|
||||
MODDED_MISC,
|
||||
|
||||
MODDED_LIVING,
|
||||
|
||||
MULE,
|
||||
|
||||
MUSHROOM_COW,
|
||||
|
||||
OCELOT,
|
||||
|
||||
PAINTING,
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14) PANDA,
|
||||
|
||||
PARROT,
|
||||
|
||||
PHANTOM,
|
||||
|
||||
PIG,
|
||||
|
||||
@NmsRemovedIn(NmsVersion.v1_16) PIG_ZOMBIE,
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_16) PIGLIN,
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_16) PIGLIN_BRUTE,
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14) PILLAGER,
|
||||
|
||||
PLAYER,
|
||||
|
||||
POLAR_BEAR,
|
||||
|
||||
PRIMED_TNT(50),
|
||||
|
||||
PUFFERFISH,
|
||||
|
||||
RABBIT,
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14) RAVAGER,
|
||||
|
||||
SALMON,
|
||||
|
||||
SHEEP,
|
||||
|
||||
SHULKER,
|
||||
|
||||
SHULKER_BULLET(67),
|
||||
|
||||
SILVERFISH,
|
||||
|
||||
SKELETON,
|
||||
|
||||
SKELETON_HORSE,
|
||||
|
||||
SLIME,
|
||||
|
||||
SMALL_FIREBALL(63),
|
||||
|
||||
SNOWBALL(61),
|
||||
|
||||
SNOWMAN,
|
||||
|
||||
SPECTRAL_ARROW(91),
|
||||
|
||||
SPIDER,
|
||||
|
||||
SPLASH_POTION(73, 0),
|
||||
|
||||
SQUID,
|
||||
|
||||
STRAY,
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_16) STRIDER,
|
||||
|
||||
THROWN_EXP_BOTTLE(75),
|
||||
|
||||
@NmsRemovedIn(NmsVersion.v1_14) TIPPED_ARROW(60),
|
||||
|
||||
TRIDENT(94, 0),
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14) TRADER_LLAMA,
|
||||
|
||||
TROPICAL_FISH,
|
||||
|
||||
TURTLE,
|
||||
|
||||
UNKNOWN,
|
||||
|
||||
VEX,
|
||||
|
||||
VILLAGER,
|
||||
|
||||
VINDICATOR,
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14) WANDERING_TRADER,
|
||||
|
||||
WITCH,
|
||||
|
||||
WITHER,
|
||||
|
||||
WITHER_SKELETON,
|
||||
|
||||
WITHER_SKULL(66),
|
||||
|
||||
WOLF,
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_16) ZOGLIN,
|
||||
|
||||
ZOMBIE,
|
||||
|
||||
ZOMBIE_HORSE,
|
||||
|
||||
ZOMBIE_VILLAGER,
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_16) ZOMBIFIED_PIGLIN;
|
||||
|
||||
public static DisguiseType getType(Entity entity) {
|
||||
DisguiseType disguiseType = getType(entity.getType());
|
||||
|
||||
return disguiseType;
|
||||
}
|
||||
|
||||
public static DisguiseType getType(EntityType entityType) {
|
||||
for (DisguiseType type : values()) {
|
||||
if (type.getEntityType() != entityType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
return DisguiseType.UNKNOWN;
|
||||
}
|
||||
|
||||
private EntityType entityType;
|
||||
|
||||
private int objectId = -1, defaultData = 0;
|
||||
private int typeId;
|
||||
|
||||
private Class<? extends FlagWatcher> watcherClass;
|
||||
|
||||
DisguiseType(int... ints) {
|
||||
for (int i = 0; i < ints.length; i++) {
|
||||
int value = ints[i];
|
||||
|
||||
switch (i) {
|
||||
case 0:
|
||||
objectId = value;
|
||||
|
||||
break;
|
||||
case 1:
|
||||
defaultData = value;
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Why oh why can't isCustom() work :(
|
||||
if (name().startsWith("MODDED_")) {
|
||||
setEntityType(EntityType.UNKNOWN);
|
||||
} else {
|
||||
setEntityType(EntityType.valueOf(name()));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
public int getDefaultData() {
|
||||
return defaultData;
|
||||
}
|
||||
|
||||
public Class<? extends Entity> getEntityClass() {
|
||||
if (entityType != null && getEntityType().getEntityClass() != null) {
|
||||
return getEntityType().getEntityClass();
|
||||
}
|
||||
|
||||
return Entity.class;
|
||||
}
|
||||
|
||||
public EntityType getEntityType() {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
private void setEntityType(EntityType entityType) {
|
||||
this.entityType = entityType;
|
||||
}
|
||||
|
||||
/**
|
||||
* The object type send in packets when spawning a misc entity. Otherwise, -1.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getObjectId() {
|
||||
return objectId;
|
||||
}
|
||||
|
||||
/**
|
||||
* The TYPE id of this entity. Different from the Object Id send in spawn packets when spawning miscs.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getTypeId() {
|
||||
return typeId;
|
||||
}
|
||||
|
||||
public void setTypeId(int typeId) {
|
||||
this.typeId = typeId;
|
||||
}
|
||||
|
||||
public Class<? extends FlagWatcher> getWatcherClass() {
|
||||
return watcherClass;
|
||||
}
|
||||
|
||||
public void setWatcherClass(Class<? extends FlagWatcher> c) {
|
||||
watcherClass = c;
|
||||
}
|
||||
|
||||
public boolean isMisc() {
|
||||
return this == DisguiseType.MODDED_MISC || (!isCustom() && getEntityType() != null && !getEntityType().isAlive());
|
||||
}
|
||||
|
||||
public boolean isMob() {
|
||||
return this == DisguiseType.MODDED_LIVING || (!isCustom() && getEntityType() != null && getEntityType().isAlive() && !isPlayer());
|
||||
}
|
||||
|
||||
public boolean isPlayer() {
|
||||
return this == DisguiseType.PLAYER;
|
||||
}
|
||||
|
||||
public boolean isUnknown() {
|
||||
return this == DisguiseType.UNKNOWN;
|
||||
}
|
||||
|
||||
public boolean isCustom() {
|
||||
return this == DisguiseType.MODDED_MISC || this == DisguiseType.MODDED_LIVING;
|
||||
}
|
||||
|
||||
public String toReadable() {
|
||||
String[] split = name().split("_");
|
||||
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
split[i] = split[i].charAt(0) + split[i].substring(1).toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
return TranslateType.DISGUISES.get(StringUtils.join(split, " "));
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 6/05/2019.
|
||||
*/
|
||||
public enum EntityPose {
|
||||
STANDING,
|
||||
FALL_FLYING,
|
||||
SLEEPING,
|
||||
SWIMMING,
|
||||
SPIN_ATTACK,
|
||||
SNEAKING,
|
||||
DYING
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 24/04/2021.
|
||||
*/
|
||||
public enum GolemCrack {
|
||||
HEALTH_100,
|
||||
HEALTH_75,
|
||||
HEALTH_50,
|
||||
HEALTH_25
|
||||
}
|
@@ -0,0 +1,263 @@
|
||||
package me.libraryaddict.disguise.disguisetypes; // Its here so I can make use of flagWatcher.sendItemStack() which
|
||||
// is protected
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class LibsEquipment implements EntityEquipment {
|
||||
private ItemStack[] equipment = new ItemStack[EquipmentSlot.values().length];
|
||||
private transient FlagWatcher flagWatcher;
|
||||
|
||||
public LibsEquipment(FlagWatcher flagWatcher) {
|
||||
this.flagWatcher = flagWatcher;
|
||||
}
|
||||
|
||||
public void setEquipment(EntityEquipment equipment) {
|
||||
if (equipment == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setArmorContents(equipment.getArmorContents());
|
||||
setItemInMainHand(equipment.getItemInMainHand());
|
||||
setItemInOffHand(equipment.getItemInOffHand());
|
||||
}
|
||||
|
||||
protected void setFlagWatcher(FlagWatcher flagWatcher) {
|
||||
this.flagWatcher = flagWatcher;
|
||||
}
|
||||
|
||||
public LibsEquipment clone(FlagWatcher flagWatcher) {
|
||||
LibsEquipment newEquip = new LibsEquipment(flagWatcher);
|
||||
|
||||
for (int i = 0; i < equipment.length; i++) {
|
||||
ItemStack item = equipment[i];
|
||||
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
newEquip.equipment[i] = item.clone();
|
||||
}
|
||||
|
||||
return newEquip;
|
||||
}
|
||||
|
||||
public ItemStack getItem(EquipmentSlot slot) {
|
||||
return equipment[slot.ordinal()];
|
||||
}
|
||||
|
||||
public void setItem(EquipmentSlot slot, ItemStack item) {
|
||||
if (getItem(slot) == item) {
|
||||
return;
|
||||
}
|
||||
|
||||
equipment[slot.ordinal()] = item;
|
||||
flagWatcher.sendItemStack(slot, item);
|
||||
}
|
||||
|
||||
public ItemStack getItemInMainHand() {
|
||||
return getItem(EquipmentSlot.HAND);
|
||||
}
|
||||
|
||||
public void setItemInMainHand(ItemStack item) {
|
||||
setItem(EquipmentSlot.HAND, item);
|
||||
}
|
||||
|
||||
public ItemStack getItemInOffHand() {
|
||||
return getItem(EquipmentSlot.OFF_HAND);
|
||||
}
|
||||
|
||||
public void setItemInOffHand(ItemStack item) {
|
||||
setItem(EquipmentSlot.OFF_HAND, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemInHand() {
|
||||
return getItem(EquipmentSlot.HAND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInHand(ItemStack stack) {
|
||||
setItem(EquipmentSlot.HAND, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getHelmet() {
|
||||
return getItem(EquipmentSlot.HEAD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHelmet(ItemStack helmet) {
|
||||
setItem(EquipmentSlot.HEAD, helmet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getChestplate() {
|
||||
return getItem(EquipmentSlot.CHEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChestplate(ItemStack chestplate) {
|
||||
setItem(EquipmentSlot.CHEST, chestplate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getLeggings() {
|
||||
return getItem(EquipmentSlot.LEGS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLeggings(ItemStack leggings) {
|
||||
setItem(EquipmentSlot.LEGS, leggings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getBoots() {
|
||||
return getItem(EquipmentSlot.FEET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBoots(ItemStack boots) {
|
||||
setItem(EquipmentSlot.FEET, boots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getArmorContents() {
|
||||
return new ItemStack[]{getBoots(), getLeggings(), getChestplate(), getHelmet()};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setArmorContents(ItemStack[] items) {
|
||||
setBoots(items[0]);
|
||||
setLeggings(items[1]);
|
||||
setChestplate(items[2]);
|
||||
setHelmet(items[3]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
setBoots(null);
|
||||
setLeggings(null);
|
||||
setChestplate(null);
|
||||
setHelmet(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getItemInHandDropChance() {
|
||||
throw new UnsupportedOperationException("This is not supported on a disguise");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInHandDropChance(float chance) {
|
||||
throw new UnsupportedOperationException("This is not supported on a disguise");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getItemInMainHandDropChance() {
|
||||
throw new UnsupportedOperationException("This is not supported on a disguise");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInMainHandDropChance(float chance) {
|
||||
throw new UnsupportedOperationException("This is not supported on a disguise");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getItemInOffHandDropChance() {
|
||||
throw new UnsupportedOperationException("This is not supported on a disguise");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInOffHandDropChance(float chance) {
|
||||
throw new UnsupportedOperationException("This is not supported on a disguise");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHelmetDropChance() {
|
||||
throw new UnsupportedOperationException("This is not supported on a disguise");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHelmetDropChance(float chance) {
|
||||
throw new UnsupportedOperationException("This is not supported on a disguise");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChestplateDropChance() {
|
||||
throw new UnsupportedOperationException("This is not supported on a disguise");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChestplateDropChance(float chance) {
|
||||
throw new UnsupportedOperationException("This is not supported on a disguise");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLeggingsDropChance() {
|
||||
throw new UnsupportedOperationException("This is not supported on a disguise");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLeggingsDropChance(float chance) {
|
||||
throw new UnsupportedOperationException("This is not supported on a disguise");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getBootsDropChance() {
|
||||
throw new UnsupportedOperationException("This is not supported on a disguise");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBootsDropChance(float chance) {
|
||||
throw new UnsupportedOperationException("This is not supported on a disguise");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity getHolder() {
|
||||
throw new UnsupportedOperationException("This is not supported on a disguise");
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Deprecated
|
||||
public void setBoots(ItemStack boots, boolean silent) {
|
||||
setBoots(boots);
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Deprecated
|
||||
public void setChestplate(ItemStack chestplate, boolean silent) {
|
||||
setChestplate(chestplate);
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Deprecated
|
||||
public void setLeggings(ItemStack leggings, boolean silent) {
|
||||
setLeggings(leggings);
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Deprecated
|
||||
public void setHelmet(ItemStack helmet, boolean silent) {
|
||||
setHelmet(helmet);
|
||||
}
|
||||
|
||||
// @Override
|
||||
@Deprecated
|
||||
public void setItem(EquipmentSlot equipmentSlot, ItemStack itemStack, boolean silent) {
|
||||
setItem(equipmentSlot, itemStack);
|
||||
}
|
||||
|
||||
// @Override
|
||||
@Deprecated
|
||||
public void setItemInMainHand(ItemStack itemStack, boolean silent) {
|
||||
setItemInMainHand(itemStack);
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Deprecated
|
||||
public void setItemInOffHand(ItemStack itemStack, boolean silent) {
|
||||
setItemInOffHand(itemStack);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,238 @@
|
||||
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.utilities.DisguiseValues;
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
public class MiscDisguise extends TargetedDisguise {
|
||||
private int id = -1, data = 0;
|
||||
|
||||
public MiscDisguise(DisguiseType disguiseType) {
|
||||
this(disguiseType, -1, disguiseType.getDefaultData());
|
||||
}
|
||||
|
||||
public MiscDisguise(DisguiseType disguiseType, Material material, int data) {
|
||||
this(disguiseType, new ItemStack(material, 1, (short) data));
|
||||
}
|
||||
|
||||
public MiscDisguise(DisguiseType disguiseType, ItemStack itemStack) {
|
||||
super(disguiseType);
|
||||
|
||||
if (disguiseType != DisguiseType.FALLING_BLOCK && disguiseType != DisguiseType.DROPPED_ITEM) {
|
||||
throw new IllegalArgumentException(
|
||||
"This constructor requires a DROPPED_ITEM or FALLING_BLOCK disguise type!");
|
||||
}
|
||||
|
||||
apply(0, itemStack);
|
||||
}
|
||||
|
||||
public MiscDisguise(DisguiseType disguiseType, Material material) {
|
||||
super(disguiseType);
|
||||
|
||||
if (disguiseType != DisguiseType.FALLING_BLOCK && disguiseType != DisguiseType.DROPPED_ITEM) {
|
||||
throw new IllegalArgumentException(
|
||||
"This constructor requires a DROPPED_ITEM or FALLING_BLOCK disguise type!");
|
||||
}
|
||||
|
||||
apply(0, new ItemStack(material));
|
||||
}
|
||||
|
||||
public MiscDisguise(DisguiseType disguiseType, int id) {
|
||||
this(disguiseType, id, disguiseType.getDefaultData());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public MiscDisguise(DisguiseType disguiseType, int id, int data) {
|
||||
super(disguiseType);
|
||||
|
||||
if (!disguiseType.isMisc()) {
|
||||
throw new InvalidParameterException(
|
||||
"Expected a non-living DisguiseType while constructing MiscDisguise. Received " + disguiseType +
|
||||
" instead. Please use " + (disguiseType.isPlayer() ? "PlayerDisguise" : "MobDisguise") +
|
||||
" instead");
|
||||
}
|
||||
|
||||
apply(id, new ItemStack(Material.STONE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight() {
|
||||
DisguiseValues values = DisguiseValues.getDisguiseValues(getType());
|
||||
|
||||
if (values == null || values.getAdultBox() == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return values.getAdultBox().getY();
|
||||
}
|
||||
|
||||
private void apply(int id, ItemStack itemStack) {
|
||||
createDisguise();
|
||||
|
||||
this.id = getType().getTypeId();
|
||||
this.data = getType().getDefaultData();
|
||||
|
||||
switch (getType()) {
|
||||
// The only disguises which should use a custom data.
|
||||
case PAINTING:
|
||||
((PaintingWatcher) getWatcher()).setArt(Art.values()[Math.max(0, id) % Art.values().length]);
|
||||
break;
|
||||
case FALLING_BLOCK:
|
||||
((FallingBlockWatcher) getWatcher()).setBlock(itemStack);
|
||||
break;
|
||||
case SPLASH_POTION:
|
||||
((SplashPotionWatcher) getWatcher()).setPotionId(Math.max(0, id));
|
||||
break;
|
||||
case DROPPED_ITEM:
|
||||
((DroppedItemWatcher) getWatcher()).setItemStack(itemStack);
|
||||
break;
|
||||
case FISHING_HOOK: // Entity ID of whoever is holding fishing rod
|
||||
case ARROW: // Entity ID of shooter. Used for "Is he on this scoreboard team and do I render it moving
|
||||
// through his body?"
|
||||
case SPECTRAL_ARROW:
|
||||
case SMALL_FIREBALL: // Unknown. Uses entity id of shooter. 0 if no shooter
|
||||
case FIREBALL: // Unknown. Uses entity id of shooter. 0 if no shooter
|
||||
case WITHER_SKULL: // Unknown. Uses entity id of shooter. 0 if no shooter
|
||||
case TRIDENT: // Unknown. Uses 1 + (entityId of target, or shooter)
|
||||
this.data = id;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise addPlayer(Player player) {
|
||||
return (MiscDisguise) super.addPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise addPlayer(String playername) {
|
||||
return (MiscDisguise) super.addPlayer(playername);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise clone() {
|
||||
MiscDisguise disguise = new MiscDisguise(getType(), getData());
|
||||
|
||||
clone(disguise);
|
||||
|
||||
return disguise;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the getId of everything but falling block.
|
||||
*/
|
||||
public int getData() {
|
||||
switch (getType()) {
|
||||
case FALLING_BLOCK:
|
||||
return ((FallingBlockWatcher) getWatcher()).getBlock().getDurability();
|
||||
case PAINTING:
|
||||
return ((PaintingWatcher) getWatcher()).getArt().getId();
|
||||
case SPLASH_POTION:
|
||||
return ((SplashPotionWatcher) getWatcher()).getPotionId();
|
||||
default:
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only falling block should use this
|
||||
*/
|
||||
public int getId() {
|
||||
if (getType() == DisguiseType.FALLING_BLOCK) {
|
||||
return ((FallingBlockWatcher) getWatcher()).getBlock().getType().ordinal();
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMiscDisguise() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise removePlayer(Player player) {
|
||||
return (MiscDisguise) super.removePlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise removePlayer(String playername) {
|
||||
return (MiscDisguise) super.removePlayer(playername);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise setDisguiseTarget(TargetType newTargetType) {
|
||||
return (MiscDisguise) super.setDisguiseTarget(newTargetType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise setEntity(Entity entity) {
|
||||
return (MiscDisguise) super.setEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise setHearSelfDisguise(boolean hearSelfDisguise) {
|
||||
return (MiscDisguise) super.setHearSelfDisguise(hearSelfDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise setHideArmorFromSelf(boolean hideArmor) {
|
||||
return (MiscDisguise) super.setHideArmorFromSelf(hideArmor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise setHideHeldItemFromSelf(boolean hideHeldItem) {
|
||||
return (MiscDisguise) super.setHideHeldItemFromSelf(hideHeldItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
|
||||
return (MiscDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise setModifyBoundingBox(boolean modifyBox) {
|
||||
return (MiscDisguise) super.setModifyBoundingBox(modifyBox);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise setReplaceSounds(boolean areSoundsReplaced) {
|
||||
return (MiscDisguise) super.setReplaceSounds(areSoundsReplaced);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise setVelocitySent(boolean sendVelocity) {
|
||||
return (MiscDisguise) super.setVelocitySent(sendVelocity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise setViewSelfDisguise(boolean viewSelfDisguise) {
|
||||
return (MiscDisguise) super.setViewSelfDisguise(viewSelfDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise setWatcher(FlagWatcher newWatcher) {
|
||||
return (MiscDisguise) super.setWatcher(newWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise silentlyAddPlayer(String playername) {
|
||||
return (MiscDisguise) super.silentlyAddPlayer(playername);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiscDisguise silentlyRemovePlayer(String playername) {
|
||||
return (MiscDisguise) super.silentlyRemovePlayer(playername);
|
||||
}
|
||||
}
|
@@ -0,0 +1,176 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.*;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseValues;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
public class MobDisguise extends TargetedDisguise {
|
||||
private boolean isAdult;
|
||||
|
||||
public MobDisguise(DisguiseType disguiseType) {
|
||||
this(disguiseType, true);
|
||||
}
|
||||
|
||||
public MobDisguise(DisguiseType disguiseType, boolean isAdult) {
|
||||
super(disguiseType);
|
||||
|
||||
if (!disguiseType.isMob()) {
|
||||
throw new InvalidParameterException(
|
||||
"Expected a living DisguiseType while constructing MobDisguise. Received " + disguiseType +
|
||||
" instead. Please use " + (disguiseType.isPlayer() ? "PlayerDisguise" : "MiscDisguise") +
|
||||
" instead");
|
||||
}
|
||||
|
||||
this.isAdult = isAdult;
|
||||
|
||||
createDisguise();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight() {
|
||||
DisguiseValues values = DisguiseValues.getDisguiseValues(getType());
|
||||
|
||||
if (values == null || values.getAdultBox() == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!isAdult() && values.getBabyBox() != null) {
|
||||
return values.getBabyBox().getY();
|
||||
}
|
||||
|
||||
if (getWatcher() != null) {
|
||||
if (getType() == DisguiseType.ARMOR_STAND) {
|
||||
return (((ArmorStandWatcher) getWatcher()).isSmall() ? values.getBabyBox() : values.getAdultBox())
|
||||
.getY();
|
||||
} else if (getType() == DisguiseType.SLIME || getType() == DisguiseType.MAGMA_CUBE) {
|
||||
return 0.51 * (0.255 * ((SlimeWatcher) getWatcher()).getSize());
|
||||
}
|
||||
}
|
||||
|
||||
return values.getAdultBox().getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise addPlayer(Player player) {
|
||||
return (MobDisguise) super.addPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise addPlayer(String playername) {
|
||||
return (MobDisguise) super.addPlayer(playername);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise clone() {
|
||||
MobDisguise disguise = new MobDisguise(getType(), isAdult());
|
||||
|
||||
clone(disguise);
|
||||
|
||||
return disguise;
|
||||
}
|
||||
|
||||
public boolean doesDisguiseAge() {
|
||||
return getWatcher() != null &&
|
||||
(getWatcher() instanceof AgeableWatcher || getWatcher() instanceof ZombieWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingWatcher getWatcher() {
|
||||
return (LivingWatcher) super.getWatcher();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setWatcher(FlagWatcher newWatcher) {
|
||||
return (MobDisguise) super.setWatcher(newWatcher);
|
||||
}
|
||||
|
||||
public boolean isAdult() {
|
||||
if (getWatcher() != null) {
|
||||
if (getWatcher() instanceof AgeableWatcher) {
|
||||
return ((AgeableWatcher) getWatcher()).isAdult();
|
||||
} else if (getWatcher() instanceof ZombieWatcher) {
|
||||
return ((ZombieWatcher) getWatcher()).isAdult();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return isAdult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMobDisguise() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise removePlayer(Player player) {
|
||||
return (MobDisguise) super.removePlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise removePlayer(String playername) {
|
||||
return (MobDisguise) super.removePlayer(playername);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setDisguiseTarget(TargetType newTargetType) {
|
||||
return (MobDisguise) super.setDisguiseTarget(newTargetType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setEntity(Entity entity) {
|
||||
return (MobDisguise) super.setEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setHearSelfDisguise(boolean hearSelfDisguise) {
|
||||
return (MobDisguise) super.setHearSelfDisguise(hearSelfDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setHideArmorFromSelf(boolean hideArmor) {
|
||||
return (MobDisguise) super.setHideArmorFromSelf(hideArmor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setHideHeldItemFromSelf(boolean hideHeldItem) {
|
||||
return (MobDisguise) super.setHideHeldItemFromSelf(hideHeldItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
|
||||
return (MobDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setModifyBoundingBox(boolean modifyBox) {
|
||||
return (MobDisguise) super.setModifyBoundingBox(modifyBox);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setReplaceSounds(boolean areSoundsReplaced) {
|
||||
return (MobDisguise) super.setReplaceSounds(areSoundsReplaced);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setVelocitySent(boolean sendVelocity) {
|
||||
return (MobDisguise) super.setVelocitySent(sendVelocity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setViewSelfDisguise(boolean viewSelfDisguise) {
|
||||
return (MobDisguise) super.setViewSelfDisguise(viewSelfDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise silentlyAddPlayer(String playername) {
|
||||
return (MobDisguise) super.silentlyAddPlayer(playername);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise silentlyRemovePlayer(String playername) {
|
||||
return (MobDisguise) super.silentlyRemovePlayer(playername);
|
||||
}
|
||||
}
|
@@ -0,0 +1,159 @@
|
||||
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.getModdedEntity(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 double getHeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
@@ -0,0 +1,728 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import lombok.Getter;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.reflection.LibsProfileLookup;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class PlayerDisguise extends TargetedDisguise {
|
||||
private transient LibsProfileLookup currentLookup;
|
||||
private WrappedGameProfile gameProfile;
|
||||
private String playerName = "Herobrine";
|
||||
private String skinToUse;
|
||||
private boolean nameVisible = true;
|
||||
/**
|
||||
* Has someone set name visible explicitly?
|
||||
*/
|
||||
private boolean explicitNameVisible = false;
|
||||
private transient DisguiseUtilities.DScoreTeam scoreboardName;
|
||||
@Getter
|
||||
private boolean deadmau5Ears;
|
||||
|
||||
private PlayerDisguise() {
|
||||
super(DisguiseType.PLAYER);
|
||||
}
|
||||
|
||||
public PlayerDisguise(Player player) {
|
||||
this(ReflectionManager.getGameProfile(player));
|
||||
}
|
||||
|
||||
public PlayerDisguise(Player player, Player skinToUse) {
|
||||
this(ReflectionManager.getGameProfile(player), ReflectionManager.getGameProfile(skinToUse));
|
||||
}
|
||||
|
||||
public PlayerDisguise(String name) {
|
||||
this(name, name);
|
||||
}
|
||||
|
||||
public PlayerDisguise(String name, String skinToUse) {
|
||||
this();
|
||||
|
||||
if (name.equals(skinToUse)) {
|
||||
WrappedGameProfile profile = getProfile(skinToUse);
|
||||
|
||||
if (profile != null) {
|
||||
setName(profile.getName());
|
||||
setSkin(profile);
|
||||
createDisguise();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setName(name);
|
||||
setSkin(skinToUse);
|
||||
|
||||
createDisguise();
|
||||
}
|
||||
|
||||
public PlayerDisguise(WrappedGameProfile gameProfile) {
|
||||
this();
|
||||
|
||||
setName(gameProfile.getName());
|
||||
|
||||
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(getUUID(), gameProfile.getName(), gameProfile);
|
||||
|
||||
createDisguise();
|
||||
}
|
||||
|
||||
public PlayerDisguise(WrappedGameProfile gameProfile, WrappedGameProfile skinToUse) {
|
||||
this();
|
||||
|
||||
setName(gameProfile.getName());
|
||||
|
||||
this.gameProfile = ReflectionManager.getGameProfile(getUUID(), gameProfile.getName());
|
||||
|
||||
setSkin(skinToUse);
|
||||
|
||||
createDisguise();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight() {
|
||||
if (getWatcher() == null) {
|
||||
return 1.8;
|
||||
}
|
||||
|
||||
if (getEntity() == null || getWatcher().getModifiedEntityAnimations()[1]) {
|
||||
return getWatcher().isSneaking() ? 1.5 : 1.8;
|
||||
}
|
||||
|
||||
return getEntity() instanceof Player && ((Player) getEntity()).isSneaking() ? 1.5 : 1.8;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public DisguiseUtilities.DScoreTeam getScoreboardName() {
|
||||
if (!DisguiseConfig.isScoreboardNames()) {
|
||||
throw new IllegalStateException("Cannot use this method when it's been disabled in config!");
|
||||
}
|
||||
|
||||
if (scoreboardName == null) {
|
||||
if (isUpsideDown() || isDeadmau5Ears()) {
|
||||
scoreboardName = new DisguiseUtilities.DScoreTeam(this, new String[]{"", getProfileName(), ""});
|
||||
} else {
|
||||
scoreboardName = DisguiseUtilities.createExtendedName(this);
|
||||
}
|
||||
}
|
||||
|
||||
return scoreboardName;
|
||||
}
|
||||
|
||||
private void setScoreboardName(String[] split) {
|
||||
if (isUpsideDown() || isDeadmau5Ears()) {
|
||||
return;
|
||||
}
|
||||
|
||||
getScoreboardName().setSplit(split);
|
||||
}
|
||||
|
||||
private boolean isStaticName(String name) {
|
||||
return name != null && (name.equalsIgnoreCase("Dinnerbone") || name.equalsIgnoreCase("Grumm"));
|
||||
}
|
||||
|
||||
public boolean hasScoreboardName() {
|
||||
if (!DisguiseConfig.isArmorstandsName() && isStaticName(getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return DisguiseConfig.isScoreboardNames();
|
||||
}
|
||||
|
||||
/**
|
||||
* The actual name that'll be sent in the game profile, not the name that they're known as
|
||||
*/
|
||||
public String getProfileName() {
|
||||
return isUpsideDown() ? "Dinnerbone" :
|
||||
isDeadmau5Ears() ? "deadmau5" : hasScoreboardName() ? getScoreboardName().getPlayer() : getName().isEmpty() ? "§r" : getName();
|
||||
}
|
||||
|
||||
|
||||
public boolean isNameVisible() {
|
||||
return nameVisible;
|
||||
}
|
||||
|
||||
public PlayerDisguise setNameVisible(boolean nameVisible) {
|
||||
return setNameVisible(nameVisible, false);
|
||||
}
|
||||
|
||||
private PlayerDisguise setNameVisible(boolean nameVisible, boolean setInternally) {
|
||||
if (isNameVisible() == nameVisible || (setInternally && explicitNameVisible)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (!setInternally) {
|
||||
explicitNameVisible = true;
|
||||
}
|
||||
|
||||
if (isDisguiseInUse()) {
|
||||
if (DisguiseConfig.isArmorstandsName()) {
|
||||
this.nameVisible = nameVisible;
|
||||
sendArmorStands(isNameVisible() ? DisguiseUtilities.reverse(getMultiName()) : new String[0]);
|
||||
} else if (!DisguiseConfig.isScoreboardNames()) {
|
||||
if (removeDisguise()) {
|
||||
this.nameVisible = nameVisible;
|
||||
|
||||
if (!startDisguise()) {
|
||||
throw new IllegalStateException("Unable to restart disguise");
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException("Unable to restart disguise");
|
||||
}
|
||||
} else {
|
||||
this.nameVisible = nameVisible;
|
||||
DisguiseUtilities.updateExtendedName(this);
|
||||
}
|
||||
} else {
|
||||
this.nameVisible = nameVisible;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise addPlayer(Player player) {
|
||||
return (PlayerDisguise) super.addPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise addPlayer(String playername) {
|
||||
return (PlayerDisguise) super.addPlayer(playername);
|
||||
}
|
||||
|
||||
public PlayerDisguise setUpsideDown(boolean upsideDown) {
|
||||
if (isUpsideDown() == upsideDown) {
|
||||
return this;
|
||||
}
|
||||
|
||||
getWatcher().setInternalUpsideDown(upsideDown);
|
||||
|
||||
if (isDisguiseInUse()) {
|
||||
resendDisguise(DisguiseConfig.isArmorstandsName() ? getName() : "Dinnerbone", true);
|
||||
} else {
|
||||
scoreboardName = null;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlayerDisguise setDeadmau5Ears(boolean deadmau5Ears) {
|
||||
if (deadmau5Ears == isDeadmau5Ears()) {
|
||||
return this;
|
||||
}
|
||||
|
||||
this.deadmau5Ears = deadmau5Ears;
|
||||
|
||||
if (isDisguiseInUse()) {
|
||||
resendDisguise(DisguiseConfig.isArmorstandsName() ? getName() : "deadmau5", true);
|
||||
} else {
|
||||
scoreboardName = null;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise clone() {
|
||||
PlayerDisguise disguise = new PlayerDisguise();
|
||||
|
||||
if (getWatcher() != null) {
|
||||
disguise.setWatcher(getWatcher().clone(disguise));
|
||||
}
|
||||
|
||||
if (currentLookup == null && gameProfile != null) {
|
||||
disguise.skinToUse = getSkin();
|
||||
disguise.gameProfile = ReflectionManager.getGameProfileWithThisSkin(disguise.getUUID(), getGameProfile().getName(), getGameProfile());
|
||||
} else {
|
||||
disguise.setSkin(getSkin());
|
||||
}
|
||||
|
||||
disguise.setName(getName());
|
||||
disguise.nameVisible = isNameVisible();
|
||||
disguise.explicitNameVisible = explicitNameVisible;
|
||||
disguise.setUpsideDown(isUpsideDown());
|
||||
disguise.setDeadmau5Ears(isDeadmau5Ears());
|
||||
|
||||
clone(disguise);
|
||||
|
||||
return disguise;
|
||||
}
|
||||
|
||||
public WrappedGameProfile getGameProfile() {
|
||||
if (gameProfile == null) {
|
||||
if (getSkin() != null) {
|
||||
gameProfile = ReflectionManager.getGameProfile(getUUID(), getProfileName());
|
||||
} else {
|
||||
gameProfile = ReflectionManager.getGameProfileWithThisSkin(getUUID(), getProfileName(), DisguiseUtilities.getProfileFromMojang(this));
|
||||
}
|
||||
}
|
||||
|
||||
return gameProfile;
|
||||
}
|
||||
|
||||
public void setGameProfile(WrappedGameProfile gameProfile) {
|
||||
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(getUUID(), gameProfile.getName(), gameProfile);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
if (getName().equals("<Inherit>") && getEntity() != null) {
|
||||
name = getEntity().getCustomName();
|
||||
|
||||
if (name == null || name.isEmpty()) {
|
||||
name = getEntity().getType().name();
|
||||
}
|
||||
}
|
||||
|
||||
if (DisguiseConfig.isCopyPlayerTeamInfo() && (DisguiseConfig.getPlayerNameType() == DisguiseConfig.PlayerNameType.TEAMS ||
|
||||
DisguiseConfig.getPlayerNameType() == DisguiseConfig.PlayerNameType.ARMORSTANDS)) {
|
||||
name = DisguiseUtilities.getDisplayName(name);
|
||||
}
|
||||
|
||||
if (name.equals(playerName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int cLimit;
|
||||
|
||||
switch (DisguiseConfig.getPlayerNameType()) {
|
||||
case TEAMS:
|
||||
cLimit = (NmsVersion.v1_13.isSupported() ? 64 : 16) * 2;
|
||||
break;
|
||||
case EXTENDED:
|
||||
cLimit = ((NmsVersion.v1_13.isSupported() ? 64 : 16) * 2) + 16;
|
||||
break;
|
||||
case ARMORSTANDS:
|
||||
cLimit = 256;
|
||||
break;
|
||||
default:
|
||||
cLimit = 16;
|
||||
break;
|
||||
}
|
||||
|
||||
if (name.length() > cLimit) {
|
||||
name = name.substring(0, cLimit);
|
||||
}
|
||||
|
||||
if (isDisguiseInUse()) {
|
||||
if (DisguiseConfig.isArmorstandsName()) {
|
||||
playerName = name;
|
||||
|
||||
setNameVisible(!name.isEmpty(), true);
|
||||
setMultiName(DisguiseUtilities.splitNewLine(name));
|
||||
} else {
|
||||
boolean resendDisguise = false;
|
||||
|
||||
if (DisguiseConfig.isScoreboardNames() && !isStaticName(name)) {
|
||||
DisguiseUtilities.DScoreTeam team = getScoreboardName();
|
||||
String[] split = DisguiseUtilities.getExtendedNameSplit(team.getPlayer(), name);
|
||||
|
||||
resendDisguise = !split[1].equals(team.getPlayer());
|
||||
setScoreboardName(split);
|
||||
}
|
||||
|
||||
resendDisguise = !DisguiseConfig.isScoreboardNames() || isStaticName(name) || isStaticName(getName()) || resendDisguise;
|
||||
|
||||
if (resendDisguise) {
|
||||
resendDisguise(name, false);
|
||||
} else {
|
||||
if (getName().isEmpty() && !name.isEmpty() && !isNameVisible()) {
|
||||
setNameVisible(true, true);
|
||||
} else if (!getName().isEmpty() && name.isEmpty() && isNameVisible()) {
|
||||
setNameVisible(false, true);
|
||||
} else {
|
||||
DisguiseUtilities.updateExtendedName(this);
|
||||
}
|
||||
|
||||
playerName = name;
|
||||
}
|
||||
}
|
||||
|
||||
if (isDisplayedInTab()) {
|
||||
PacketContainer addTab = DisguiseUtilities.getTabPacket(this, PlayerInfoAction.UPDATE_DISPLAY_NAME);
|
||||
|
||||
try {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (scoreboardName != null) {
|
||||
DisguiseUtilities.DScoreTeam team = getScoreboardName();
|
||||
String[] split = DisguiseUtilities.getExtendedNameSplit(team.getPlayer(), name);
|
||||
|
||||
setScoreboardName(split);
|
||||
}
|
||||
|
||||
if (DisguiseConfig.isArmorstandsName()) {
|
||||
setMultiName(DisguiseUtilities.splitNewLine(name));
|
||||
}
|
||||
|
||||
setNameVisible(!name.isEmpty(), true);
|
||||
playerName = name;
|
||||
|
||||
if (gameProfile != null) {
|
||||
gameProfile = ReflectionManager.getGameProfileWithThisSkin(getUUID(), getProfileName(), getGameProfile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void resendDisguise(String name, boolean updateTeams) {
|
||||
if (removeDisguise()) {
|
||||
if (getName().isEmpty() && !name.isEmpty()) {
|
||||
setNameVisible(true, true);
|
||||
} else if (!getName().isEmpty() && name.isEmpty()) {
|
||||
setNameVisible(false, true);
|
||||
}
|
||||
|
||||
playerName = name;
|
||||
|
||||
if (updateTeams) {
|
||||
scoreboardName = null;
|
||||
}
|
||||
|
||||
if (gameProfile != null) {
|
||||
gameProfile = ReflectionManager.getGameProfileWithThisSkin(getUUID(), getProfileName(), getGameProfile());
|
||||
}
|
||||
|
||||
if (!startDisguise()) {
|
||||
throw new IllegalStateException("Unable to restart disguise");
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException("Unable to restart disguise");
|
||||
}
|
||||
}
|
||||
|
||||
public String getSkin() {
|
||||
return skinToUse;
|
||||
}
|
||||
|
||||
public PlayerDisguise setSkin(String newSkin) {
|
||||
WrappedGameProfile profile = getProfile(newSkin);
|
||||
|
||||
if (profile != null) {
|
||||
return setSkin(profile);
|
||||
}
|
||||
|
||||
if (newSkin != null) {
|
||||
String[] split = DisguiseUtilities.splitNewLine(newSkin);
|
||||
|
||||
if (split.length > 0) {
|
||||
newSkin = split[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (newSkin != null && newSkin.length() > 16) {
|
||||
newSkin = null;
|
||||
}
|
||||
|
||||
String oldSkin = skinToUse;
|
||||
skinToUse = newSkin;
|
||||
|
||||
if (newSkin == null) {
|
||||
currentLookup = null;
|
||||
gameProfile = null;
|
||||
} else {
|
||||
if (newSkin.length() > 16) {
|
||||
skinToUse = newSkin.substring(0, 16);
|
||||
}
|
||||
|
||||
if (newSkin.equals(oldSkin)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (isDisguiseInUse()) {
|
||||
currentLookup = new LibsProfileLookup() {
|
||||
@Override
|
||||
public void onLookup(WrappedGameProfile gameProfile) {
|
||||
if (currentLookup != this || gameProfile == null || gameProfile.getProperties().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setSkin(gameProfile);
|
||||
|
||||
currentLookup = null;
|
||||
}
|
||||
};
|
||||
|
||||
WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup, DisguiseConfig.isContactMojangServers());
|
||||
|
||||
if (gameProfile != null) {
|
||||
setSkin(gameProfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the GameProfile, without tampering.
|
||||
*
|
||||
* @param gameProfile GameProfile
|
||||
* @return
|
||||
*/
|
||||
public PlayerDisguise setSkin(WrappedGameProfile gameProfile) {
|
||||
if (gameProfile == null) {
|
||||
this.gameProfile = null;
|
||||
this.skinToUse = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
currentLookup = null;
|
||||
|
||||
this.skinToUse = gameProfile.getName();
|
||||
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(getUUID(), getProfileName(), gameProfile);
|
||||
|
||||
refreshDisguise();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private WrappedGameProfile getProfile(String string) {
|
||||
if (string != null && string.length() > 70 && string.startsWith("{\"id\":") && string.endsWith("}") && string.contains(",\"name\":")) {
|
||||
try {
|
||||
return DisguiseUtilities.getGson().fromJson(string, WrappedGameProfile.class);
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalStateException("Tried to parse " + string + " to a GameProfile, but it has been formatted incorrectly!");
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void refreshDisguise() {
|
||||
if (!DisguiseUtilities.isDisguiseInUse(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isDisplayedInTab()) {
|
||||
PacketContainer addTab = DisguiseUtilities.getTabPacket(this, PlayerInfoAction.ADD_PLAYER);
|
||||
|
||||
PacketContainer deleteTab = addTab.shallowClone();
|
||||
deleteTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER);
|
||||
|
||||
try {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
DisguiseUtilities.refreshTrackers(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerWatcher getWatcher() {
|
||||
return (PlayerWatcher) super.getWatcher();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setWatcher(FlagWatcher newWatcher) {
|
||||
return (PlayerDisguise) super.setWatcher(newWatcher);
|
||||
}
|
||||
|
||||
public boolean isDisplayedInTab() {
|
||||
return getWatcher().isDisplayedInTab();
|
||||
}
|
||||
|
||||
public void setDisplayedInTab(boolean showPlayerInTab) {
|
||||
getWatcher().setDisplayedInTab(showPlayerInTab);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerDisguise() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise removePlayer(Player player) {
|
||||
return (PlayerDisguise) super.removePlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise removePlayer(String playername) {
|
||||
return (PlayerDisguise) super.removePlayer(playername);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setDisguiseTarget(TargetType newTargetType) {
|
||||
return (PlayerDisguise) super.setDisguiseTarget(newTargetType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setEntity(Entity entity) {
|
||||
return (PlayerDisguise) super.setEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setHearSelfDisguise(boolean hearSelfDisguise) {
|
||||
return (PlayerDisguise) super.setHearSelfDisguise(hearSelfDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setHideArmorFromSelf(boolean hideArmor) {
|
||||
return (PlayerDisguise) super.setHideArmorFromSelf(hideArmor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setHideHeldItemFromSelf(boolean hideHeldItem) {
|
||||
return (PlayerDisguise) super.setHideHeldItemFromSelf(hideHeldItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
|
||||
return (PlayerDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setModifyBoundingBox(boolean modifyBox) {
|
||||
return (PlayerDisguise) super.setModifyBoundingBox(modifyBox);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setReplaceSounds(boolean areSoundsReplaced) {
|
||||
return (PlayerDisguise) super.setReplaceSounds(areSoundsReplaced);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startDisguise() {
|
||||
return startDisguise(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startDisguise(CommandSender sender) {
|
||||
if (isDisguiseInUse()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (skinToUse != null && gameProfile == null) {
|
||||
currentLookup = new LibsProfileLookup() {
|
||||
@Override
|
||||
public void onLookup(WrappedGameProfile gameProfile) {
|
||||
if (currentLookup != this || gameProfile == null || gameProfile.getProperties().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setSkin(gameProfile);
|
||||
|
||||
currentLookup = null;
|
||||
}
|
||||
};
|
||||
|
||||
WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup, DisguiseConfig.isContactMojangServers());
|
||||
|
||||
if (gameProfile != null) {
|
||||
setSkin(gameProfile);
|
||||
}
|
||||
}
|
||||
|
||||
if (isDynamicName()) {
|
||||
String name;
|
||||
|
||||
if (getEntity() instanceof Player) {
|
||||
name = DisguiseUtilities.translateAlternateColorCodes(DisguiseUtilities.getDisplayName(getEntity()));
|
||||
} else {
|
||||
name = getEntity().getCustomName();
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
name = "";
|
||||
}
|
||||
|
||||
if (!getName().equals(name)) {
|
||||
setName(name);
|
||||
}
|
||||
} else if (getName().equals("<Inherit>") && getEntity() != null) {
|
||||
String name = getEntity().getCustomName();
|
||||
|
||||
if (name == null || name.isEmpty()) {
|
||||
name = getEntity().getType().name();
|
||||
}
|
||||
|
||||
setName(name);
|
||||
}
|
||||
|
||||
boolean result = super.startDisguise(sender);
|
||||
|
||||
if (result && hasScoreboardName()) {
|
||||
DisguiseUtilities.registerExtendedName(this);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setVelocitySent(boolean sendVelocity) {
|
||||
return (PlayerDisguise) super.setVelocitySent(sendVelocity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setViewSelfDisguise(boolean viewSelfDisguise) {
|
||||
return (PlayerDisguise) super.setViewSelfDisguise(viewSelfDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise silentlyAddPlayer(String playername) {
|
||||
return (PlayerDisguise) super.silentlyAddPlayer(playername);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise silentlyRemovePlayer(String playername) {
|
||||
return (PlayerDisguise) super.silentlyRemovePlayer(playername);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeDisguise(boolean disguiseBeingReplaced) {
|
||||
boolean result = super.removeDisguise(disguiseBeingReplaced);
|
||||
|
||||
if (!result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (hasScoreboardName()) {
|
||||
if (disguiseBeingReplaced) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DisguiseUtilities.unregisterExtendedName(PlayerDisguise.this);
|
||||
}
|
||||
}.runTaskLater(LibsDisguises.getInstance(), 5);
|
||||
} else {
|
||||
DisguiseUtilities.unregisterExtendedName(this);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
public enum RabbitType {
|
||||
BLACK(2),
|
||||
BROWN(0),
|
||||
GOLD(4),
|
||||
KILLER_BUNNY(99),
|
||||
PATCHES(3),
|
||||
PEPPER(5),
|
||||
WHITE(1);
|
||||
|
||||
public static RabbitType getType(int id) {
|
||||
for (RabbitType type : values()) {
|
||||
if (type.getTypeId() == id) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private int type;
|
||||
|
||||
RabbitType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getTypeId() {
|
||||
return type;
|
||||
}
|
||||
}
|
@@ -0,0 +1,171 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
|
||||
import com.comphenix.protocol.wrappers.PlayerInfoData;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class TargetedDisguise extends Disguise {
|
||||
|
||||
public TargetedDisguise(DisguiseType disguiseType) {
|
||||
super(disguiseType);
|
||||
}
|
||||
|
||||
public enum TargetType {
|
||||
HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS,
|
||||
SHOW_TO_EVERYONE_BUT_THESE_PLAYERS
|
||||
}
|
||||
|
||||
private ArrayList<String> disguiseViewers = new ArrayList<>();
|
||||
private TargetType targetType = TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS;
|
||||
|
||||
@Override
|
||||
protected void clone(Disguise disguise) {
|
||||
((TargetedDisguise) disguise).targetType = getDisguiseTarget();
|
||||
((TargetedDisguise) disguise).disguiseViewers = new ArrayList<>(disguiseViewers);
|
||||
|
||||
super.clone(disguise);
|
||||
}
|
||||
|
||||
public TargetedDisguise addPlayer(Player player) {
|
||||
addPlayer(player.getName());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TargetedDisguise addPlayer(String playername) {
|
||||
if (!disguiseViewers.contains(playername)) {
|
||||
disguiseViewers.add(playername);
|
||||
|
||||
if (DisguiseAPI.isDisguiseInUse(this)) {
|
||||
DisguiseUtilities.checkConflicts(this, playername);
|
||||
DisguiseUtilities.refreshTracker(this, playername);
|
||||
|
||||
if (isHidePlayer() && getEntity() instanceof Player) {
|
||||
try {
|
||||
Player player = Bukkit.getPlayerExact(playername);
|
||||
|
||||
if (player != null) {
|
||||
PacketContainer deleteTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
|
||||
deleteTab.getPlayerInfoAction().write(0,
|
||||
canSee(player) ? PlayerInfoAction.REMOVE_PLAYER : PlayerInfoAction.ADD_PLAYER);
|
||||
deleteTab.getPlayerInfoDataLists().write(0, Arrays.asList(
|
||||
new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0,
|
||||
NativeGameMode.SURVIVAL, WrappedChatComponent
|
||||
.fromText(DisguiseUtilities.getPlayerListName((Player) getEntity())))));
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab);
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean canSee(Player player) {
|
||||
return canSee(player.getName());
|
||||
}
|
||||
|
||||
public boolean canSee(String playername) {
|
||||
boolean hasPlayer = disguiseViewers.contains(playername);
|
||||
|
||||
if (targetType == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
||||
return !hasPlayer;
|
||||
}
|
||||
|
||||
return hasPlayer;
|
||||
}
|
||||
|
||||
public TargetType getDisguiseTarget() {
|
||||
return targetType;
|
||||
}
|
||||
|
||||
public TargetedDisguise setDisguiseTarget(TargetType newTargetType) {
|
||||
if (DisguiseUtilities.isDisguiseInUse(this)) {
|
||||
throw new RuntimeException("Cannot set the disguise target after the entity has been disguised");
|
||||
}
|
||||
|
||||
targetType = newTargetType;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<String> getObservers() {
|
||||
return Collections.unmodifiableList(disguiseViewers);
|
||||
}
|
||||
|
||||
public TargetedDisguise removePlayer(Player player) {
|
||||
removePlayer(player.getName());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TargetedDisguise removePlayer(String playername) {
|
||||
if (disguiseViewers.contains(playername)) {
|
||||
disguiseViewers.remove(playername);
|
||||
|
||||
if (DisguiseAPI.isDisguiseInUse(this)) {
|
||||
DisguiseUtilities.checkConflicts(this, playername);
|
||||
DisguiseUtilities.refreshTracker(this, playername);
|
||||
|
||||
if (isHidePlayer() && getEntity() instanceof Player) {
|
||||
try {
|
||||
Player player = Bukkit.getPlayerExact(playername);
|
||||
|
||||
if (player != null) {
|
||||
PacketContainer deleteTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
|
||||
deleteTab.getPlayerInfoAction().write(0,
|
||||
canSee(player) ? PlayerInfoAction.ADD_PLAYER : PlayerInfoAction.REMOVE_PLAYER);
|
||||
deleteTab.getPlayerInfoDataLists().write(0, Arrays.asList(
|
||||
new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0,
|
||||
NativeGameMode.SURVIVAL, WrappedChatComponent
|
||||
.fromText(DisguiseUtilities.getPlayerListName((Player) getEntity())))));
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab);
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TargetedDisguise silentlyAddPlayer(String playername) {
|
||||
if (!disguiseViewers.contains(playername)) {
|
||||
disguiseViewers.add(playername);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TargetedDisguise silentlyRemovePlayer(String playername) {
|
||||
disguiseViewers.remove(playername);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import org.bukkit.entity.Villager;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 6/05/2019.
|
||||
*/
|
||||
public class VillagerData {
|
||||
private final Villager.Type type;
|
||||
private final Villager.Profession profession;
|
||||
private final int level;
|
||||
|
||||
public VillagerData(Villager.Type type, Villager.Profession profession, int level) {
|
||||
this.type = type;
|
||||
this.profession = profession;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public Villager.Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Villager.Profession getProfession() {
|
||||
return profession;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
}
|
@@ -0,0 +1,107 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class AbstractHorseWatcher extends AgeableWatcher {
|
||||
private static final int TAMED = 2, SADDLED = 4, REPRODUCED = 8, GRAZING = 16, REARING = 32, EATING = 64;
|
||||
|
||||
public AbstractHorseWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public UUID getOwner() {
|
||||
return getData(MetaIndex.HORSE_OWNER).orElse(null);
|
||||
}
|
||||
|
||||
public void setOwner(UUID uuid) {
|
||||
setData(MetaIndex.HORSE_OWNER, Optional.of(uuid));
|
||||
sendData(MetaIndex.HORSE_OWNER);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the horse can be breeded, no visible effect
|
||||
*
|
||||
* @return Is horse breedable
|
||||
*/
|
||||
public boolean isReproduced() {
|
||||
return isHorseFlag(REPRODUCED);
|
||||
}
|
||||
|
||||
public void setReproduced(boolean reproduced) {
|
||||
setHorseFlag(REPRODUCED, reproduced);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the horse is grazing
|
||||
*
|
||||
* @return Is horse grazing
|
||||
*/
|
||||
public boolean isGrazing() {
|
||||
return isHorseFlag(GRAZING);
|
||||
}
|
||||
|
||||
public void setGrazing(boolean grazing) {
|
||||
setHorseFlag(GRAZING, grazing);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the horse has it's mouth open
|
||||
*
|
||||
* @return Horse has mouth open
|
||||
*/
|
||||
public boolean isEating() {
|
||||
return isHorseFlag(EATING);
|
||||
}
|
||||
|
||||
public void setEating(boolean mouthOpen) {
|
||||
setHorseFlag(EATING, mouthOpen);
|
||||
}
|
||||
|
||||
public boolean isRearing() {
|
||||
return isHorseFlag(REARING);
|
||||
}
|
||||
|
||||
public void setRearing(boolean rear) {
|
||||
setHorseFlag(REARING, rear);
|
||||
}
|
||||
|
||||
public boolean isSaddled() {
|
||||
return isHorseFlag(SADDLED);
|
||||
}
|
||||
|
||||
public void setSaddled(boolean saddled) {
|
||||
setHorseFlag(SADDLED, saddled);
|
||||
}
|
||||
|
||||
public boolean isTamed() {
|
||||
return isHorseFlag(TAMED);
|
||||
}
|
||||
|
||||
public void setTamed(boolean tamed) {
|
||||
setHorseFlag(TAMED, tamed);
|
||||
}
|
||||
|
||||
private boolean isHorseFlag(int i) {
|
||||
return (getHorseFlag() & i) != 0;
|
||||
}
|
||||
|
||||
private byte getHorseFlag() {
|
||||
return getData(MetaIndex.HORSE_META);
|
||||
}
|
||||
|
||||
private void setHorseFlag(int i, boolean flag) {
|
||||
byte j = getData(MetaIndex.HORSE_META);
|
||||
|
||||
if (flag) {
|
||||
setData(MetaIndex.HORSE_META, (byte) (j | i));
|
||||
} else {
|
||||
setData(MetaIndex.HORSE_META, (byte) (j & ~i));
|
||||
}
|
||||
|
||||
sendData(MetaIndex.HORSE_META);
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
|
||||
/**
|
||||
* @author Navid
|
||||
*/
|
||||
public abstract class AbstractSkeletonWatcher extends InsentientWatcher {
|
||||
public AbstractSkeletonWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@NmsRemovedIn(NmsVersion.v1_14)
|
||||
public boolean isSwingArms() {
|
||||
return getData(MetaIndex.SKELETON_SWING_ARMS);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@NmsRemovedIn(NmsVersion.v1_14)
|
||||
public void setSwingArms(boolean swingingArms) {
|
||||
setData(MetaIndex.SKELETON_SWING_ARMS, swingingArms);
|
||||
sendData(MetaIndex.SKELETON_SWING_ARMS);
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 18/05/2019.
|
||||
*/
|
||||
public class AbstractVillagerWatcher extends AgeableWatcher {
|
||||
public AbstractVillagerWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
public int getAngry() {
|
||||
return getData(MetaIndex.ABSTRACT_VILLAGER_ANGRY);
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
public boolean isAngry() {
|
||||
return getAngry() > 0;
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
public void setAngry(int ticks) {
|
||||
setData(MetaIndex.ABSTRACT_VILLAGER_ANGRY, ticks);
|
||||
sendData(MetaIndex.ABSTRACT_VILLAGER_ANGRY);
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
|
||||
public class AgeableWatcher extends InsentientWatcher {
|
||||
public AgeableWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public boolean isAdult() {
|
||||
return !isBaby();
|
||||
}
|
||||
|
||||
public boolean isBaby() {
|
||||
return getData(MetaIndex.AGEABLE_BABY);
|
||||
}
|
||||
|
||||
public void setBaby(boolean isBaby) {
|
||||
setData(MetaIndex.AGEABLE_BABY, isBaby);
|
||||
sendData(MetaIndex.AGEABLE_BABY);
|
||||
}
|
||||
|
||||
public void setAdult() {
|
||||
setBaby(false);
|
||||
}
|
||||
|
||||
public void setBaby() {
|
||||
setBaby(true);
|
||||
}
|
||||
}
|
@@ -0,0 +1,108 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedParticle;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import org.apache.commons.lang.math.RandomUtils;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Particle;
|
||||
|
||||
/**
|
||||
* @author Navid
|
||||
*/
|
||||
public class AreaEffectCloudWatcher extends FlagWatcher {
|
||||
|
||||
public AreaEffectCloudWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
|
||||
if (DisguiseConfig.isRandomDisguises()) {
|
||||
setColor(Color.fromRGB(RandomUtils.nextInt(256), RandomUtils.nextInt(256), RandomUtils.nextInt(256)));
|
||||
}
|
||||
}
|
||||
|
||||
public float getRadius() {
|
||||
return getData(MetaIndex.AREA_EFFECT_RADIUS);
|
||||
}
|
||||
|
||||
public void setRadius(float radius) {
|
||||
if (radius > 30) {
|
||||
radius = 30;
|
||||
} else if (radius < 0.1) {
|
||||
radius = 0.1f;
|
||||
}
|
||||
|
||||
setData(MetaIndex.AREA_EFFECT_RADIUS, radius);
|
||||
sendData(MetaIndex.AREA_EFFECT_RADIUS);
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
int color = getData(MetaIndex.AREA_EFFECT_CLOUD_COLOR);
|
||||
return Color.fromRGB(color);
|
||||
}
|
||||
|
||||
@RandomDefaultValue
|
||||
public void setColor(Color color) {
|
||||
setData(MetaIndex.AREA_EFFECT_CLOUD_COLOR, color.asRGB());
|
||||
sendData(MetaIndex.AREA_EFFECT_CLOUD_COLOR);
|
||||
}
|
||||
|
||||
public boolean isIgnoreRadius() {
|
||||
return getData(MetaIndex.AREA_EFFECT_IGNORE_RADIUS);
|
||||
}
|
||||
|
||||
public void setIgnoreRadius(boolean ignore) {
|
||||
setData(MetaIndex.AREA_EFFECT_IGNORE_RADIUS, ignore);
|
||||
sendData(MetaIndex.AREA_EFFECT_IGNORE_RADIUS);
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_13)
|
||||
public <T> void setParticle(Particle particle, T particleData) {
|
||||
setParticle(WrappedParticle.create(particle, particleData));
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_13)
|
||||
public WrappedParticle getParticle() {
|
||||
if (NmsVersion.v1_13.isSupported()) {
|
||||
return getData(MetaIndex.AREA_EFFECT_PARTICLE);
|
||||
} else {
|
||||
// Item crack, block crack, block dust, falling dust
|
||||
int particleId = getData(MetaIndex.AREA_EFFECT_PARTICLE_OLD);
|
||||
Particle particle = Particle.values()[particleId];
|
||||
|
||||
return WrappedParticle.create(particle, null);
|
||||
}
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_13)
|
||||
public void setParticle(WrappedParticle particle) {
|
||||
if (NmsVersion.v1_13.isSupported()) {
|
||||
setData(MetaIndex.AREA_EFFECT_PARTICLE, particle);
|
||||
sendData(MetaIndex.AREA_EFFECT_PARTICLE);
|
||||
} else {
|
||||
setParticleType(particle.getParticle());
|
||||
}
|
||||
}
|
||||
|
||||
public Particle getParticleType() {
|
||||
if (NmsVersion.v1_13.isSupported()) {
|
||||
return getParticle().getParticle();
|
||||
} else {
|
||||
return Particle.values()[getData(MetaIndex.AREA_EFFECT_PARTICLE_OLD)];
|
||||
}
|
||||
}
|
||||
|
||||
public void setParticleType(Particle particle) {
|
||||
if (NmsVersion.v1_13.isSupported()) {
|
||||
setParticle(WrappedParticle.create(particle, null));
|
||||
} else {
|
||||
setData(MetaIndex.AREA_EFFECT_PARTICLE_OLD, particle.ordinal());
|
||||
|
||||
sendData(MetaIndex.AREA_EFFECT_PARTICLE_OLD);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,131 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import com.comphenix.protocol.wrappers.Vector3F;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import org.bukkit.util.EulerAngle;
|
||||
|
||||
public class ArmorStandWatcher extends LivingWatcher {
|
||||
public ArmorStandWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
private boolean getArmorStandFlag(int value) {
|
||||
return (getData(MetaIndex.ARMORSTAND_META) & value) != 0;
|
||||
}
|
||||
|
||||
public EulerAngle getBody() {
|
||||
return getPose(MetaIndex.ARMORSTAND_BODY);
|
||||
}
|
||||
|
||||
public EulerAngle getHead() {
|
||||
return getPose(MetaIndex.ARMORSTAND_HEAD);
|
||||
}
|
||||
|
||||
public EulerAngle getLeftArm() {
|
||||
return getPose(MetaIndex.ARMORSTAND_LEFT_ARM);
|
||||
}
|
||||
|
||||
public EulerAngle getLeftLeg() {
|
||||
return getPose(MetaIndex.ARMORSTAND_LEFT_LEG);
|
||||
}
|
||||
|
||||
private EulerAngle getPose(MetaIndex<Vector3F> type) {
|
||||
if (!hasValue(type))
|
||||
return new EulerAngle(0, 0, 0);
|
||||
|
||||
Vector3F vec = getData(type);
|
||||
|
||||
return new EulerAngle(vec.getX(), vec.getY(), vec.getZ());
|
||||
}
|
||||
|
||||
public EulerAngle getRightArm() {
|
||||
return getPose(MetaIndex.ARMORSTAND_RIGHT_ARM);
|
||||
}
|
||||
|
||||
public EulerAngle getRightLeg() {
|
||||
return getPose(MetaIndex.ARMORSTAND_RIGHT_LEG);
|
||||
}
|
||||
|
||||
public boolean isMarker() {
|
||||
return getArmorStandFlag(16);
|
||||
}
|
||||
|
||||
public boolean isNoBasePlate() {
|
||||
return getArmorStandFlag(8);
|
||||
}
|
||||
|
||||
public boolean isNoGravity() {
|
||||
return getArmorStandFlag(2);
|
||||
}
|
||||
|
||||
public boolean isShowArms() {
|
||||
return getArmorStandFlag(4);
|
||||
}
|
||||
|
||||
public boolean isSmall() {
|
||||
return getArmorStandFlag(1);
|
||||
}
|
||||
|
||||
private void setArmorStandFlag(int value, boolean isTrue) {
|
||||
byte b1 = getData(MetaIndex.ARMORSTAND_META);
|
||||
|
||||
if (isTrue) {
|
||||
b1 = (byte) (b1 | value);
|
||||
} else {
|
||||
b1 = (byte) (b1 & value);
|
||||
}
|
||||
|
||||
setData(MetaIndex.ARMORSTAND_META, b1);
|
||||
sendData(MetaIndex.ARMORSTAND_META);
|
||||
}
|
||||
|
||||
public void setBody(EulerAngle vector) {
|
||||
setPose(MetaIndex.ARMORSTAND_BODY, vector);
|
||||
}
|
||||
|
||||
public void setHead(EulerAngle vector) {
|
||||
setPose(MetaIndex.ARMORSTAND_HEAD, vector);
|
||||
}
|
||||
|
||||
public void setLeftArm(EulerAngle vector) {
|
||||
setPose(MetaIndex.ARMORSTAND_LEFT_ARM, vector);
|
||||
}
|
||||
|
||||
public void setLeftLeg(EulerAngle vector) {
|
||||
setPose(MetaIndex.ARMORSTAND_LEFT_LEG, vector);
|
||||
}
|
||||
|
||||
public void setMarker(boolean isMarker) {
|
||||
setArmorStandFlag(16, isMarker);
|
||||
}
|
||||
|
||||
public void setNoBasePlate(boolean noBasePlate) {
|
||||
setArmorStandFlag(8, noBasePlate);
|
||||
}
|
||||
|
||||
public void setNoGravity(boolean noGravity) {
|
||||
setArmorStandFlag(2, noGravity);
|
||||
}
|
||||
|
||||
private void setPose(MetaIndex<Vector3F> type, EulerAngle vector) {
|
||||
setData(type, new Vector3F((float) vector.getX(), (float) vector.getY(), (float) vector.getZ()));
|
||||
sendData(type);
|
||||
}
|
||||
|
||||
public void setRightArm(EulerAngle vector) {
|
||||
setPose(MetaIndex.ARMORSTAND_RIGHT_ARM, vector);
|
||||
}
|
||||
|
||||
public void setRightLeg(EulerAngle vector) {
|
||||
setPose(MetaIndex.ARMORSTAND_RIGHT_LEG, vector);
|
||||
}
|
||||
|
||||
public void setShowArms(boolean showArms) {
|
||||
setArmorStandFlag(4, showArms);
|
||||
}
|
||||
|
||||
public void setSmall(boolean isSmall) {
|
||||
setArmorStandFlag(1, isSmall);
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
|
||||
public class ArrowWatcher extends FlagWatcher {
|
||||
public ArrowWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public boolean isCritical() {
|
||||
return getData(MetaIndex.ARROW_CRITICAL) == 1;
|
||||
}
|
||||
|
||||
public void setCritical(boolean critical) {
|
||||
setData(MetaIndex.ARROW_CRITICAL, (byte) (critical ? 1 : 0));
|
||||
sendData(MetaIndex.ARROW_CRITICAL);
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
public int getPierceLevel() {
|
||||
return getData(MetaIndex.ARROW_PIERCE_LEVEL);
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
public void setPierceLevel(int pierceLevel) {
|
||||
setData(MetaIndex.ARROW_PIERCE_LEVEL, (byte) pierceLevel);
|
||||
sendData(MetaIndex.ARROW_PIERCE_LEVEL);
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import org.bukkit.entity.Axolotl;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 15/06/2021.
|
||||
*/
|
||||
public class AxolotlWatcher extends AgeableWatcher {
|
||||
public AxolotlWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public boolean isPlayingDead() {
|
||||
return getData(MetaIndex.AXOLOTL_PLAYING_DEAD);
|
||||
}
|
||||
|
||||
public void setPlayingDead(boolean playingDead) {
|
||||
setData(MetaIndex.AXOLOTL_PLAYING_DEAD, playingDead);
|
||||
sendData(MetaIndex.AXOLOTL_PLAYING_DEAD);
|
||||
}
|
||||
|
||||
public Axolotl.Variant getVariant() {
|
||||
return Axolotl.Variant.values()[getData(MetaIndex.AXOLOTL_VARIANT)];
|
||||
}
|
||||
|
||||
public void setVariant(Axolotl.Variant variant) {
|
||||
setData(MetaIndex.AXOLOTL_VARIANT, variant.ordinal());
|
||||
sendData(MetaIndex.AXOLOTL_VARIANT);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
|
||||
public class BatWatcher extends InsentientWatcher {
|
||||
|
||||
public BatWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
|
||||
setHanging(false);
|
||||
}
|
||||
|
||||
public boolean isHanging() {
|
||||
return getData(MetaIndex.BAT_HANGING) == 1;
|
||||
}
|
||||
|
||||
public void setHanging(boolean hanging) {
|
||||
setData(MetaIndex.BAT_HANGING, hanging ? (byte) 1 : (byte) 0);
|
||||
sendData(MetaIndex.BAT_HANGING);
|
||||
}
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 14/12/2019.
|
||||
*/
|
||||
@NmsAddedIn(NmsVersion.v1_15)
|
||||
public class BeeWatcher extends AgeableWatcher {
|
||||
public BeeWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public void setBeeAnger(int beeAnger) {
|
||||
setData(MetaIndex.BEE_ANGER, beeAnger);
|
||||
sendData(MetaIndex.BEE_ANGER);
|
||||
}
|
||||
|
||||
public int getBeeAnger() {
|
||||
return getData(MetaIndex.BEE_ANGER);
|
||||
}
|
||||
|
||||
public void setHasNectar(boolean hasNectar) {
|
||||
setBeeFlag(8, hasNectar);
|
||||
}
|
||||
|
||||
public boolean hasNectar() {
|
||||
return getBeeFlag(8);
|
||||
}
|
||||
|
||||
public void setHasStung(boolean hasStung) {
|
||||
setBeeFlag(4, hasStung);
|
||||
}
|
||||
|
||||
public boolean hasStung() {
|
||||
return getBeeFlag(4);
|
||||
}
|
||||
|
||||
public void setFlipped(boolean isFlipped) {
|
||||
setBeeFlag(2, isFlipped);
|
||||
}
|
||||
|
||||
public boolean isFlipped() {
|
||||
return getBeeFlag(2);
|
||||
}
|
||||
|
||||
private boolean getBeeFlag(int value) {
|
||||
return (getData(MetaIndex.BEE_META) & value) != 0;
|
||||
}
|
||||
|
||||
private void setBeeFlag(int no, boolean flag) {
|
||||
byte b1 = getData(MetaIndex.BEE_META);
|
||||
|
||||
if (flag) {
|
||||
b1 = (byte) (b1 | no);
|
||||
} else {
|
||||
b1 = (byte) (b1 & ~no);
|
||||
}
|
||||
|
||||
setData(MetaIndex.BEE_META, b1);
|
||||
sendData(MetaIndex.BEE_META);
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
|
||||
public class BlazeWatcher extends InsentientWatcher {
|
||||
public BlazeWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public boolean isBlazing() {
|
||||
return getData(MetaIndex.BLAZE_BLAZING) == 1;
|
||||
}
|
||||
|
||||
public void setBlazing(boolean isBlazing) {
|
||||
setData(MetaIndex.BLAZE_BLAZING, (byte) (isBlazing ? 1 : 0));
|
||||
sendData(MetaIndex.BLAZE_BLAZING);
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import org.bukkit.TreeSpecies;
|
||||
|
||||
public class BoatWatcher extends FlagWatcher {
|
||||
public BoatWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
|
||||
setBoatType(TreeSpecies.GENERIC);
|
||||
}
|
||||
|
||||
public float getDamage() {
|
||||
return getData(MetaIndex.BOAT_DAMAGE);
|
||||
}
|
||||
|
||||
public void setDamage(float dmg) {
|
||||
setData(MetaIndex.BOAT_DAMAGE, dmg);
|
||||
sendData(MetaIndex.BOAT_DAMAGE);
|
||||
}
|
||||
|
||||
public boolean isRightPaddling() {
|
||||
return getData(MetaIndex.BOAT_RIGHT_PADDLING);
|
||||
}
|
||||
|
||||
public void setRightPaddling(boolean rightPaddling) {
|
||||
setData(MetaIndex.BOAT_RIGHT_PADDLING, rightPaddling);
|
||||
sendData(MetaIndex.BOAT_RIGHT_PADDLING);
|
||||
}
|
||||
|
||||
public boolean isLeftPaddling() {
|
||||
return getData(MetaIndex.BOAT_LEFT_PADDLING);
|
||||
}
|
||||
|
||||
public void setLeftPaddling(boolean leftPaddling) {
|
||||
setData(MetaIndex.BOAT_LEFT_PADDLING, leftPaddling);
|
||||
sendData(MetaIndex.BOAT_LEFT_PADDLING);
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_13)
|
||||
public int getBoatShake() {
|
||||
return getData(MetaIndex.BOAT_SHAKE);
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_13)
|
||||
public void setBoatShake(int number) {
|
||||
setData(MetaIndex.BOAT_SHAKE, number);
|
||||
sendData(MetaIndex.BOAT_SHAKE);
|
||||
}
|
||||
|
||||
public TreeSpecies getBoatType() {
|
||||
return TreeSpecies.getByData(getData(MetaIndex.BOAT_TYPE).byteValue());
|
||||
}
|
||||
|
||||
public void setBoatType(TreeSpecies boatType) {
|
||||
setData(MetaIndex.BOAT_TYPE, (int) boatType.getData());
|
||||
sendData(MetaIndex.BOAT_TYPE);
|
||||
}
|
||||
}
|
@@ -0,0 +1,77 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.entity.Cat;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 6/05/2019.
|
||||
*/
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
public class CatWatcher extends TameableWatcher {
|
||||
public CatWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
|
||||
if (DisguiseConfig.isRandomDisguises()) {
|
||||
setType(Cat.Type.values()[new Random().nextInt(Cat.Type.values().length)]);
|
||||
}
|
||||
}
|
||||
|
||||
public Cat.Type getType() {
|
||||
return Cat.Type.values()[getData(MetaIndex.CAT_TYPE)];
|
||||
}
|
||||
|
||||
@RandomDefaultValue
|
||||
public void setType(Cat.Type type) {
|
||||
setData(MetaIndex.CAT_TYPE, type.ordinal());
|
||||
sendData(MetaIndex.CAT_TYPE);
|
||||
}
|
||||
|
||||
public DyeColor getCollarColor() {
|
||||
return AnimalColor.getColorByWool(getData(MetaIndex.CAT_COLLAR)).getDyeColor();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setCollarColor(AnimalColor color) {
|
||||
setCollarColor(color.getDyeColor());
|
||||
}
|
||||
|
||||
public void setCollarColor(DyeColor newColor) {
|
||||
if (!isTamed()) {
|
||||
setTamed(true);
|
||||
}
|
||||
|
||||
if (newColor == getCollarColor()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setData(MetaIndex.CAT_COLLAR, (int) newColor.getWoolData());
|
||||
sendData(MetaIndex.CAT_COLLAR);
|
||||
}
|
||||
|
||||
public boolean isLyingDown() {
|
||||
return getData(MetaIndex.CAT_LYING_DOWN);
|
||||
}
|
||||
|
||||
public void setLyingDown(boolean value) {
|
||||
setData(MetaIndex.CAT_LYING_DOWN, value);
|
||||
sendData(MetaIndex.CAT_LYING_DOWN);
|
||||
}
|
||||
|
||||
public boolean isLookingUp() {
|
||||
return getData(MetaIndex.CAT_LOOKING_UP);
|
||||
}
|
||||
|
||||
public void setLookingUp(boolean value) {
|
||||
setData(MetaIndex.CAT_LOOKING_UP, value);
|
||||
sendData(MetaIndex.CAT_LOOKING_UP);
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
|
||||
public class ChestedHorseWatcher extends AbstractHorseWatcher {
|
||||
|
||||
public ChestedHorseWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public void setCarryingChest(boolean carryingChest) {
|
||||
setData(MetaIndex.HORSE_CHESTED_CARRYING_CHEST, carryingChest);
|
||||
sendData(MetaIndex.HORSE_CHESTED_CARRYING_CHEST);
|
||||
}
|
||||
|
||||
public boolean isCarryingChest() {
|
||||
return getData(MetaIndex.HORSE_CHESTED_CARRYING_CHEST);
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import org.bukkit.entity.Creeper;
|
||||
|
||||
public class CreeperWatcher extends InsentientWatcher {
|
||||
|
||||
public CreeperWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public boolean isIgnited() {
|
||||
return getData(MetaIndex.CREEPER_IGNITED);
|
||||
}
|
||||
|
||||
public void setIgnited(boolean ignited) {
|
||||
// If creeper is already ignited and they want to set it to unignited, then resend disguise
|
||||
boolean resend = !ignited && getDisguise() != null && getDisguise().isDisguiseInUse() &&
|
||||
((hasValue(MetaIndex.CREEPER_IGNITED) && isIgnited()) ||
|
||||
(getDisguise().getEntity() instanceof Creeper &&
|
||||
((Creeper) getDisguise().getEntity()).isPowered()));
|
||||
|
||||
setData(MetaIndex.CREEPER_IGNITED, ignited);
|
||||
sendData(MetaIndex.CREEPER_IGNITED);
|
||||
|
||||
if (resend) {
|
||||
DisguiseUtilities.refreshTrackers(getDisguise());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPowered() {
|
||||
return getData(MetaIndex.CREEPER_POWERED);
|
||||
}
|
||||
|
||||
public void setPowered(boolean powered) {
|
||||
setData(MetaIndex.CREEPER_POWERED, powered);
|
||||
sendData(MetaIndex.CREEPER_POWERED);
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 6/08/2018.
|
||||
*/
|
||||
public class DolphinWatcher extends InsentientWatcher {
|
||||
public DolphinWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
public class DonkeyWatcher extends ChestedHorseWatcher {
|
||||
|
||||
public DonkeyWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.translations.TranslateType;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class DroppedItemWatcher extends FlagWatcher {
|
||||
public DroppedItemWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return getData(MetaIndex.DROPPED_ITEM);
|
||||
}
|
||||
|
||||
public void setItemStack(ItemStack item) {
|
||||
setData(MetaIndex.DROPPED_ITEM, item);
|
||||
sendData(MetaIndex.DROPPED_ITEM);
|
||||
|
||||
if (!getDisguise().isCustomDisguiseName()) {
|
||||
getDisguise().setDisguiseName(TranslateType.DISGUISES.get(DisguiseType.DROPPED_ITEM.toReadable()) + " " +
|
||||
TranslateType.DISGUISE_OPTIONS_PARAMETERS.get(ReflectionManager
|
||||
.toReadable((item == null ? Material.AIR : item.getType()).name(), " ")));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 6/05/2019.
|
||||
*/
|
||||
public class EggWatcher extends ThrowableWatcher {
|
||||
public EggWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getDefaultItemStack() {
|
||||
return new ItemStack(Material.EGG);
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Navid
|
||||
*/
|
||||
public class EnderCrystalWatcher extends FlagWatcher {
|
||||
public EnderCrystalWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public void setBeamTarget(BlockPosition position) {
|
||||
setData(MetaIndex.ENDER_CRYSTAL_BEAM, position == null ? Optional.empty() : Optional.of(position));
|
||||
sendData(MetaIndex.ENDER_CRYSTAL_BEAM);
|
||||
}
|
||||
|
||||
public BlockPosition getBeamTarget() {
|
||||
return getData(MetaIndex.ENDER_CRYSTAL_BEAM).orElse(null);
|
||||
}
|
||||
|
||||
public void setShowBottom(boolean bool) {
|
||||
setData(MetaIndex.ENDER_CRYSTAL_PLATE, bool);
|
||||
sendData(MetaIndex.ENDER_CRYSTAL_PLATE);
|
||||
}
|
||||
|
||||
public boolean isShowBottom() {
|
||||
return getData(MetaIndex.ENDER_CRYSTAL_PLATE);
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
|
||||
/**
|
||||
* @author Navid
|
||||
*/
|
||||
public class EnderDragonWatcher extends InsentientWatcher {
|
||||
|
||||
public EnderDragonWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public int getPhase() {
|
||||
return getData(MetaIndex.ENDER_DRAGON_PHASE);
|
||||
}
|
||||
|
||||
public void setPhase(int phase) {
|
||||
setData(MetaIndex.ENDER_DRAGON_PHASE, phase);
|
||||
sendData(MetaIndex.ENDER_DRAGON_PHASE);
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 6/05/2019.
|
||||
*/
|
||||
public class EnderPearlWatcher extends ThrowableWatcher {
|
||||
public EnderPearlWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getDefaultItemStack() {
|
||||
return new ItemStack(Material.ENDER_PEARL);
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 6/05/2019.
|
||||
*/
|
||||
public class EnderSignalWatcher extends FlagWatcher {
|
||||
public EnderSignalWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
|
||||
if (NmsVersion.v1_14.isSupported()) {
|
||||
setItemStack(new ItemStack(Material.ENDER_EYE));
|
||||
}
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
public ItemStack getItemStack() {
|
||||
return getData(MetaIndex.ENDER_SIGNAL_ITEM);
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
public void setItemStack(ItemStack item) {
|
||||
setData(MetaIndex.ENDER_SIGNAL_ITEM, item);
|
||||
sendData(MetaIndex.ENDER_SIGNAL_ITEM);
|
||||
}
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class EndermanWatcher extends InsentientWatcher {
|
||||
|
||||
public EndermanWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemInMainHand() {
|
||||
Optional<WrappedBlockData> value = getData(MetaIndex.ENDERMAN_ITEM);
|
||||
|
||||
if (value.isPresent()) {
|
||||
WrappedBlockData pair = value.get();
|
||||
return new ItemStack(pair.getType(), 1);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInMainHand(ItemStack itemstack) {
|
||||
setItemInMainHand(itemstack.getType());
|
||||
}
|
||||
|
||||
public void setItemInMainHand(Material type) {
|
||||
if (!type.isBlock()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<WrappedBlockData> optional;
|
||||
|
||||
if (type == null) {
|
||||
optional = Optional.empty();
|
||||
} else {
|
||||
optional = Optional.of(WrappedBlockData.createData(type));
|
||||
}
|
||||
|
||||
setData(MetaIndex.ENDERMAN_ITEM, optional);
|
||||
sendData(MetaIndex.ENDERMAN_ITEM);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setItemInMainHand(Material type, int data) {
|
||||
setItemInMainHand(type);
|
||||
}
|
||||
|
||||
public boolean isAggressive() {
|
||||
return getData(MetaIndex.ENDERMAN_AGRESSIVE);
|
||||
}
|
||||
|
||||
public void setAggressive(boolean isAggressive) {
|
||||
setData(MetaIndex.ENDERMAN_AGRESSIVE, isAggressive);
|
||||
sendData(MetaIndex.ENDERMAN_AGRESSIVE);
|
||||
}
|
||||
}
|
@@ -0,0 +1,148 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.translations.TranslateType;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class FallingBlockWatcher extends FlagWatcher {
|
||||
private int blockCombinedId = 1;
|
||||
private boolean gridLocked;
|
||||
|
||||
public FallingBlockWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FallingBlockWatcher clone(Disguise disguise) {
|
||||
FallingBlockWatcher watcher = (FallingBlockWatcher) super.clone(disguise);
|
||||
|
||||
if (NmsVersion.v1_13.isSupported()) {
|
||||
watcher.setBlockData(getBlockData().clone());
|
||||
} else {
|
||||
watcher.setBlock(getBlock().clone());
|
||||
}
|
||||
|
||||
return watcher;
|
||||
}
|
||||
|
||||
public boolean isGridLocked() {
|
||||
return gridLocked;
|
||||
}
|
||||
|
||||
public void setGridLocked(boolean gridLocked) {
|
||||
if (isGridLocked() == gridLocked) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.gridLocked = gridLocked;
|
||||
|
||||
if (getDisguise().isDisguiseInUse() && getDisguise().getEntity() != null) {
|
||||
PacketContainer relMove = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE);
|
||||
relMove.getModifier().write(0, getDisguise().getEntity().getEntityId());
|
||||
|
||||
Location loc = getDisguise().getEntity().getLocation();
|
||||
|
||||
if (NmsVersion.v1_14.isSupported()) {
|
||||
StructureModifier<Short> shorts = relMove.getShorts();
|
||||
|
||||
shorts.write(0, conRel(loc.getX(), loc.getBlockX() + 0.5));
|
||||
shorts.write(1, conRel(loc.getY(), loc.getBlockY() + (loc.getY() % 1 >= 0.85 ? 1 : loc.getY() % 1 >= 0.35 ? .5 : 0)));
|
||||
shorts.write(2, conRel(loc.getZ(), loc.getBlockZ() + 0.5));
|
||||
} else {
|
||||
StructureModifier<Integer> ints = relMove.getIntegers();
|
||||
|
||||
ints.write(0, (int) conRel(loc.getX(), loc.getBlockX() + 0.5));
|
||||
ints.write(1, (int) conRel(loc.getY(), loc.getBlockY() + (loc.getY() % 1 >= 0.85 ? 1 : loc.getY() % 1 >= 0.35 ? .5 : 0)));
|
||||
ints.write(2, (int) conRel(loc.getZ(), loc.getBlockZ() + 0.5));
|
||||
}
|
||||
|
||||
try {
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
if (player == getDisguise().getEntity()) {
|
||||
PacketContainer temp = relMove.shallowClone();
|
||||
temp.getModifier().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, temp, isGridLocked());
|
||||
} else {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, relMove, isGridLocked());
|
||||
}
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private short conRel(double oldCord, double newCord) {
|
||||
return (short) (((oldCord - newCord) * 4096) * (isGridLocked() ? -1 : 1));
|
||||
}
|
||||
|
||||
public ItemStack getBlock() {
|
||||
return ReflectionManager.getItemStackByCombinedId(getBlockCombinedId());
|
||||
}
|
||||
|
||||
public void setBlock(ItemStack block) {
|
||||
if (block == null || block.getType() == null || block.getType() == Material.AIR || !block.getType().isBlock()) {
|
||||
block = new ItemStack(Material.STONE);
|
||||
}
|
||||
|
||||
this.blockCombinedId = ReflectionManager.getCombinedIdByItemStack(block);
|
||||
|
||||
if (!getDisguise().isCustomDisguiseName()) {
|
||||
getDisguise().setDisguiseName(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("Block") + " " +
|
||||
TranslateType.DISGUISE_OPTIONS_PARAMETERS.get(ReflectionManager.toReadable(block.getType().name(), " ")));
|
||||
}
|
||||
|
||||
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) {
|
||||
DisguiseUtilities.refreshTrackers(getDisguise());
|
||||
}
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_13)
|
||||
public BlockData getBlockData() {
|
||||
return ReflectionManager.getBlockDataByCombinedId(getBlockCombinedId());
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_13)
|
||||
public void setBlockData(BlockData data) {
|
||||
if (data == null || data.getMaterial() == Material.AIR && data.getMaterial().isBlock()) {
|
||||
setBlock(null);
|
||||
return;
|
||||
}
|
||||
|
||||
this.blockCombinedId = ReflectionManager.getCombinedIdByBlockData(data);
|
||||
|
||||
if (!getDisguise().isCustomDisguiseName()) {
|
||||
getDisguise().setDisguiseName(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("Block") + " " +
|
||||
TranslateType.DISGUISE_OPTIONS_PARAMETERS.get(ReflectionManager.toReadable(data.getMaterial().name(), " ")));
|
||||
}
|
||||
|
||||
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) {
|
||||
DisguiseUtilities.refreshTrackers(getDisguise());
|
||||
}
|
||||
}
|
||||
|
||||
public int getBlockCombinedId() {
|
||||
if (blockCombinedId < 1) {
|
||||
blockCombinedId = 1;
|
||||
}
|
||||
|
||||
return blockCombinedId;
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 6/05/2019.
|
||||
*/
|
||||
public class FireballWatcher extends FlagWatcher {
|
||||
public FireballWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
|
||||
if (NmsVersion.v1_14.isSupported()) {
|
||||
setData(MetaIndex.FIREBALL_ITEM, new ItemStack(Material.FIRE_CHARGE));
|
||||
}
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
public ItemStack getItemStack() {
|
||||
return getData(MetaIndex.FIREBALL_ITEM);
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
public void setItemStack(ItemStack item) {
|
||||
setData(MetaIndex.FIREBALL_ITEM, item);
|
||||
sendData(MetaIndex.FIREBALL_ITEM);
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
|
||||
public class FireworkWatcher extends FlagWatcher {
|
||||
public FireworkWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public ItemStack getFirework() {
|
||||
if (getData(MetaIndex.FIREWORK_ITEM) == null) {
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
|
||||
return getData(MetaIndex.FIREWORK_ITEM);
|
||||
}
|
||||
|
||||
public void setFirework(ItemStack newItem) {
|
||||
if (newItem == null) {
|
||||
newItem = new ItemStack(Material.AIR);
|
||||
}
|
||||
|
||||
newItem = newItem.clone();
|
||||
newItem.setAmount(1);
|
||||
|
||||
setData(MetaIndex.FIREWORK_ITEM, newItem);
|
||||
sendData(MetaIndex.FIREWORK_ITEM);
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
public boolean isShotAtAngle() {
|
||||
return getData(MetaIndex.FIREWORK_SHOT_AT_ANGLE);
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
public void setShotAtAngle(boolean shotAtAngle) {
|
||||
setData(MetaIndex.FIREWORK_SHOT_AT_ANGLE, shotAtAngle);
|
||||
sendData(MetaIndex.FIREWORK_SHOT_AT_ANGLE);
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
public OptionalInt getAttachedEntityOpt() {
|
||||
return getData(MetaIndex.FIREWORK_ATTACHED_ENTITY);
|
||||
}
|
||||
|
||||
public int getAttachedEntity() {
|
||||
return getData(MetaIndex.FIREWORK_ATTACHED_ENTITY).orElse(0);
|
||||
}
|
||||
|
||||
public void setAttachedEntity(int entityId) {
|
||||
setAttachedEntity(entityId == 0 ? OptionalInt.empty() : OptionalInt.of(entityId));
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
public void setAttachedEntity(OptionalInt entityId) {
|
||||
if (NmsVersion.v1_14.isSupported()) {
|
||||
setData(MetaIndex.FIREWORK_ATTACHED_ENTITY, entityId);
|
||||
sendData(MetaIndex.FIREWORK_ATTACHED_ENTITY);
|
||||
} else {
|
||||
setData(MetaIndex.FIREWORK_ATTACHED_ENTITY_OLD, entityId.orElse(0));
|
||||
sendData(MetaIndex.FIREWORK_ATTACHED_ENTITY_OLD);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 6/08/2018.
|
||||
*/
|
||||
public class FishWatcher extends InsentientWatcher {
|
||||
public FishWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
|
||||
public class FishingHookWatcher extends FlagWatcher {
|
||||
public FishingHookWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public int getHookedId() {
|
||||
int hooked = getData(MetaIndex.FISHING_HOOK_HOOKED_ID);
|
||||
|
||||
if (hooked > 0)
|
||||
hooked--;
|
||||
|
||||
return hooked;
|
||||
}
|
||||
|
||||
public void setHookedId(int hookedId) {
|
||||
setData(MetaIndex.FISHING_HOOK_HOOKED_ID, hookedId + 1);
|
||||
sendData(MetaIndex.FISHING_HOOK_HOOKED_ID);
|
||||
}
|
||||
|
||||
public boolean isHooked() {
|
||||
return getData(MetaIndex.FISHING_HOOK_HOOKED);
|
||||
}
|
||||
|
||||
public void setHooked(boolean hooked) {
|
||||
setData(MetaIndex.FISHING_HOOK_HOOKED, hooked);
|
||||
sendData(MetaIndex.FISHING_HOOK_HOOKED);
|
||||
}
|
||||
}
|
@@ -0,0 +1,108 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import org.bukkit.entity.Fox;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 6/05/2019.
|
||||
*/
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
public class FoxWatcher extends AgeableWatcher {
|
||||
public FoxWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
|
||||
if (DisguiseConfig.isRandomDisguises()) {
|
||||
setType(Fox.Type.values()[new Random().nextInt(Fox.Type.values().length)]);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSitting() {
|
||||
return getFoxFlag(1);
|
||||
}
|
||||
|
||||
public void setSitting(boolean value) {
|
||||
setFoxFlag(1, value);
|
||||
}
|
||||
|
||||
public boolean isCrouching() {
|
||||
return getFoxFlag(4);
|
||||
}
|
||||
|
||||
public void setCrouching(boolean value) {
|
||||
setFoxFlag(4, value);
|
||||
}
|
||||
|
||||
public boolean isSleeping() {
|
||||
return getFoxFlag(32);
|
||||
}
|
||||
|
||||
public void setSleeping(boolean value) {
|
||||
setFoxFlag(32, value);
|
||||
}
|
||||
|
||||
@RandomDefaultValue
|
||||
public Fox.Type getType() {
|
||||
return Fox.Type.values()[getData(MetaIndex.FOX_TYPE)];
|
||||
}
|
||||
|
||||
public void setType(Fox.Type type) {
|
||||
setData(MetaIndex.FOX_TYPE, type.ordinal());
|
||||
sendData(MetaIndex.FOX_TYPE);
|
||||
}
|
||||
|
||||
public boolean isHeadTilted() {
|
||||
return getFoxFlag(8);
|
||||
}
|
||||
|
||||
public void setHeadTilted(boolean value) {
|
||||
setFoxFlag(8, value);
|
||||
}
|
||||
|
||||
public boolean isSpringing() {
|
||||
return getFoxFlag(16);
|
||||
}
|
||||
|
||||
public void setSpringing(boolean value) {
|
||||
setFoxFlag(16, value);
|
||||
}
|
||||
|
||||
public boolean isTipToeing() {
|
||||
return getFoxFlag(64);
|
||||
}
|
||||
|
||||
public void setTipToeing(boolean value) {
|
||||
setFoxFlag(64, value);
|
||||
}
|
||||
|
||||
public boolean isAngry() {
|
||||
return getFoxFlag(128);
|
||||
}
|
||||
|
||||
public void setAngry(boolean value) {
|
||||
setFoxFlag(128, value);
|
||||
}
|
||||
|
||||
private boolean getFoxFlag(int value) {
|
||||
return (getData(MetaIndex.FOX_META) & value) != 0;
|
||||
}
|
||||
|
||||
private void setFoxFlag(int no, boolean flag) {
|
||||
byte b1 = getData(MetaIndex.FOX_META);
|
||||
|
||||
if (flag) {
|
||||
b1 = (byte) (b1 | no);
|
||||
} else {
|
||||
b1 = (byte) (b1 & ~no);
|
||||
}
|
||||
|
||||
setData(MetaIndex.FOX_META, b1);
|
||||
sendData(MetaIndex.FOX_META);
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
|
||||
public class GhastWatcher extends InsentientWatcher {
|
||||
|
||||
public GhastWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public boolean isAggressive() {
|
||||
return getData(MetaIndex.GHAST_AGRESSIVE);
|
||||
}
|
||||
|
||||
public void setAggressive(boolean isAggressive) {
|
||||
setData(MetaIndex.GHAST_AGRESSIVE, isAggressive);
|
||||
sendData(MetaIndex.GHAST_AGRESSIVE);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 15/06/2021.
|
||||
*/
|
||||
public class GlowSquidWatcher extends SquidWatcher {
|
||||
public GlowSquidWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public int getDarkTicksRemaining() {
|
||||
return getData(MetaIndex.GLOW_SQUID_DARK_TICKS_REMAINING);
|
||||
}
|
||||
|
||||
public void setDarkTicksRemaining(int ticks) {
|
||||
setData(MetaIndex.GLOW_SQUID_DARK_TICKS_REMAINING, ticks);
|
||||
sendData(MetaIndex.GLOW_SQUID_DARK_TICKS_REMAINING);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 15/06/2021.
|
||||
*/
|
||||
public class GoatWatcher extends AgeableWatcher {
|
||||
public GoatWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public boolean isScreaming() {
|
||||
return getData(MetaIndex.GOAT_SCREAMING);
|
||||
}
|
||||
|
||||
public void setScreaming(boolean screaming) {
|
||||
setData(MetaIndex.GOAT_SCREAMING, screaming);
|
||||
sendData(MetaIndex.GOAT_SCREAMING);
|
||||
}
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class GuardianWatcher extends InsentientWatcher {
|
||||
public GuardianWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this guardian targetting someone?
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isTarget() {
|
||||
return getData(MetaIndex.GUARDIAN_TARGET) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shoot a beam at the given entityId.
|
||||
*
|
||||
* @param entityId
|
||||
*/
|
||||
public void setTarget(int entityId) {
|
||||
setData(MetaIndex.GUARDIAN_TARGET, entityId);
|
||||
sendData(MetaIndex.GUARDIAN_TARGET);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Entity id of target
|
||||
*/
|
||||
public int getTarget() {
|
||||
return getData(MetaIndex.GUARDIAN_TARGET);
|
||||
}
|
||||
|
||||
public void setTarget(Entity entity) {
|
||||
setTarget(entity == null ? 0 : entity.getEntityId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Shoot a beam at the given player name.
|
||||
*
|
||||
* @param playername
|
||||
*/
|
||||
public void setTarget(String playername) {
|
||||
Player player = Bukkit.getPlayer(playername);
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
setData(MetaIndex.GUARDIAN_TARGET, player.getEntityId());
|
||||
sendData(MetaIndex.GUARDIAN_TARGET);
|
||||
}
|
||||
|
||||
public boolean isRetractingSpikes() {
|
||||
return getData(MetaIndex.GUARDIAN_RETRACT_SPIKES);
|
||||
}
|
||||
|
||||
public void setRetractingSpikes(boolean isRetracting) {
|
||||
setData(MetaIndex.GUARDIAN_RETRACT_SPIKES, isRetracting);
|
||||
sendData(MetaIndex.GUARDIAN_RETRACT_SPIKES);
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 25/06/2020.
|
||||
*/
|
||||
public class HoglinWatcher extends AgeableWatcher {
|
||||
public HoglinWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
|
||||
setShaking(false);
|
||||
}
|
||||
|
||||
public boolean isShaking() {
|
||||
return !getData(MetaIndex.HOGLIN_SHAKING);
|
||||
}
|
||||
|
||||
public void setShaking(boolean shaking) {
|
||||
setData(MetaIndex.HOGLIN_SHAKING, !shaking);
|
||||
sendData(MetaIndex.HOGLIN_SHAKING);
|
||||
}
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Horse.Color;
|
||||
import org.bukkit.entity.Horse.Style;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class HorseWatcher extends AbstractHorseWatcher {
|
||||
public HorseWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
|
||||
if (DisguiseConfig.isRandomDisguises()) {
|
||||
setStyle(Style.values()[DisguiseUtilities.random.nextInt(Style.values().length)]);
|
||||
setColor(Color.values()[DisguiseUtilities.random.nextInt(Color.values().length)]);
|
||||
}
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return Color.values()[(getData(MetaIndex.HORSE_COLOR) & 0xFF)];
|
||||
}
|
||||
|
||||
@RandomDefaultValue
|
||||
public void setColor(Color color) {
|
||||
setData(MetaIndex.HORSE_COLOR, color.ordinal() & 0xFF | getStyle().ordinal() << 8);
|
||||
sendData(MetaIndex.HORSE_COLOR);
|
||||
}
|
||||
|
||||
public Style getStyle() {
|
||||
return Style.values()[(getData(MetaIndex.HORSE_COLOR) >>> 8)];
|
||||
}
|
||||
|
||||
@RandomDefaultValue
|
||||
public void setStyle(Style style) {
|
||||
setData(MetaIndex.HORSE_COLOR, getColor().ordinal() & 0xFF | style.ordinal() << 8);
|
||||
sendData(MetaIndex.HORSE_COLOR);
|
||||
}
|
||||
|
||||
public ItemStack getHorseArmor() {
|
||||
return getEquipment().getChestplate();
|
||||
}
|
||||
|
||||
public void setHorseArmor(ItemStack item) {
|
||||
getEquipment().setChestplate(item);
|
||||
|
||||
if (!NmsVersion.v1_14.isSupported()) {
|
||||
int value = 0;
|
||||
|
||||
if (item != null) {
|
||||
Material mat = item.getType();
|
||||
|
||||
if (mat == Material.IRON_HORSE_ARMOR) {
|
||||
value = 1;
|
||||
} else if (mat == Material.GOLDEN_HORSE_ARMOR) {
|
||||
value = 2;
|
||||
} else if (mat == Material.DIAMOND_HORSE_ARMOR) {
|
||||
value = 3;
|
||||
}
|
||||
}
|
||||
|
||||
setData(MetaIndex.HORSE_ARMOR, value);
|
||||
sendData(MetaIndex.HORSE_ARMOR);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 9/06/2017.
|
||||
*/
|
||||
public class IllagerWatcher extends RaiderWatcher {
|
||||
public IllagerWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import org.bukkit.entity.Spellcaster;
|
||||
|
||||
public class IllagerWizardWatcher extends IllagerWatcher {
|
||||
public IllagerWizardWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
public Spellcaster.Spell getSpell() {
|
||||
return Spellcaster.Spell.values()[getData(MetaIndex.ILLAGER_SPELL)];
|
||||
}
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
public void setSpell(Spellcaster.Spell spell) {
|
||||
setData(MetaIndex.ILLAGER_SPELL, (byte) spell.ordinal());
|
||||
sendData(MetaIndex.ILLAGER_SPELL);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@NmsRemovedIn(NmsVersion.v1_14)
|
||||
public int getSpellTicks() {
|
||||
return getData(MetaIndex.ILLAGER_SPELL_TICKS);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@NmsRemovedIn(NmsVersion.v1_14)
|
||||
public void setSpellTicks(int spellTicks) {
|
||||
setData(MetaIndex.ILLAGER_SPELL_TICKS, (byte) spellTicks);
|
||||
sendData(MetaIndex.ILLAGER_SPELL_TICKS);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user