Add command sender in the disguise event

This commit is contained in:
libraryaddict 2021-03-29 21:42:41 +13:00
parent 8ff6686b1e
commit 4528624283
14 changed files with 86 additions and 77 deletions

View File

@ -13,6 +13,7 @@ import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.*; import org.bukkit.entity.*;
@ -209,6 +210,10 @@ public class DisguiseAPI {
} }
public static void disguiseEntity(Entity entity, Disguise 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 // If they are trying to disguise a null entity or use a null disguise
// Just return. // Just return.
if (entity == null || disguise == null) { if (entity == null || disguise == null) {
@ -236,7 +241,7 @@ public class DisguiseAPI {
disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE); disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE);
} }
disguise.startDisguise(); disguise.startDisguise(commandSender);
} }
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Collection playersToNotSeeDisguise) { public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Collection playersToNotSeeDisguise) {
@ -473,10 +478,21 @@ public class DisguiseAPI {
* @param entity * @param entity
*/ */
public static void undisguiseToAll(Entity 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); Disguise[] disguises = getDisguises(entity);
for (Disguise disguise : disguises) { for (Disguise disguise : disguises) {
disguise.removeDisguise(); disguise.removeDisguise(sender);
} }
} }

View File

@ -78,7 +78,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE); disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE);
} }
disguise.startDisguise(); disguise.startDisguise(sender);
if (disguise.isDisguiseInUse()) { if (disguise.isDisguiseInUse()) {
LibsMsg.DISGUISED.send(sender, disguise.getDisguiseName()); LibsMsg.DISGUISED.send(sender, disguise.getDisguiseName());

View File

@ -120,7 +120,7 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE); disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE);
} }
disguise.startDisguise(); disguise.startDisguise(sender);
if (disguise.isDisguiseInUse()) { if (disguise.isDisguiseInUse()) {
LibsMsg.DISG_PLAYER_AS_DISG.send(sender, LibsMsg.DISG_PLAYER_AS_DISG.send(sender,

View File

@ -200,7 +200,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE); disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE);
} }
disguise.startDisguise(); disguise.startDisguise(sender);
if (disguise.isDisguiseInUse()) { if (disguise.isDisguiseInUse()) {
disguisedEntitys++; disguisedEntitys++;

View File

@ -65,7 +65,7 @@ public class DisguiseEntityInteraction implements LibsEntityInteract {
} }
} }
DisguiseAPI.disguiseEntity(entity, disguise); DisguiseAPI.disguiseEntity(p, entity, disguise);
String disguiseName = disguise.getDisguiseName(); String disguiseName = disguise.getDisguiseName();

View File

@ -22,7 +22,7 @@ public class UndisguiseEntityInteraction implements LibsEntityInteract {
} }
if (DisguiseAPI.isDisguised(entity)) { if (DisguiseAPI.isDisguised(entity)) {
DisguiseAPI.undisguiseToAll(entity); DisguiseAPI.undisguiseToAll(p, entity);
if (entity instanceof Player) if (entity instanceof Player)
LibsMsg.LISTEN_UNDISG_PLAYER.send(p, entityName); LibsMsg.LISTEN_UNDISG_PLAYER.send(p, entityName);

View File

@ -27,7 +27,7 @@ public class UndisguiseCommand implements CommandExecutor {
if (sender.hasPermission("libsdisguises.undisguise") && !"%%__USER__%%".equals(12345 + "")) { if (sender.hasPermission("libsdisguises.undisguise") && !"%%__USER__%%".equals(12345 + "")) {
if (DisguiseAPI.isDisguised((Entity) sender)) { if (DisguiseAPI.isDisguised((Entity) sender)) {
DisguiseAPI.undisguiseToAll((Player) sender); DisguiseAPI.undisguiseToAll(sender, (Player) sender);
LibsMsg.UNDISG.send(sender); LibsMsg.UNDISG.send(sender);
} else { } else {
LibsMsg.NOT_DISGUISED.send(sender); LibsMsg.NOT_DISGUISED.send(sender);

View File

@ -86,7 +86,7 @@ public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter {
} }
if (DisguiseAPI.isDisguised(entityTarget)) { if (DisguiseAPI.isDisguised(entityTarget)) {
DisguiseAPI.undisguiseToAll(entityTarget); DisguiseAPI.undisguiseToAll(sender, entityTarget);
LibsMsg.UNDISG_PLAYER.send(sender, LibsMsg.UNDISG_PLAYER.send(sender,
entityTarget instanceof Player ? entityTarget.getName() : entityTarget instanceof Player ? entityTarget.getName() :
DisguiseType.getType(entityTarget).toReadable()); DisguiseType.getType(entityTarget).toReadable());

View File

@ -70,7 +70,7 @@ public class UndisguiseRadiusCommand implements CommandExecutor {
} }
if (DisguiseAPI.isDisguised(entity)) { if (DisguiseAPI.isDisguised(entity)) {
DisguiseAPI.undisguiseToAll(entity); DisguiseAPI.undisguiseToAll(sender, entity);
disguisedEntitys++; disguisedEntitys++;
} }
} }

View File

@ -34,6 +34,7 @@ import org.bukkit.NamespacedKey;
import org.bukkit.boss.BarColor; import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle; import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar; import org.bukkit.boss.BossBar;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@ -857,18 +858,26 @@ public abstract class Disguise {
return removeDisguise(false); return removeDisguise(false);
} }
public boolean removeDisguise(CommandSender sender) {
return removeDisguise(sender, false);
}
public boolean removeDisguise(boolean disguiseBeingReplaced) {
return removeDisguise(null, disguiseBeingReplaced);
}
/** /**
* Removes the disguise and undisguises the entity if it's using this disguise. * Removes the disguise and undisguises the entity if it's using this disguise.
* *
* @param disguiseBeingReplaced If the entity's disguise is being replaced with another * @param disguiseBeingReplaced If the entity's disguise is being replaced with another
* @return * @return
*/ */
public boolean removeDisguise(boolean disguiseBeingReplaced) { public boolean removeDisguise(CommandSender sender, boolean disguiseBeingReplaced) {
if (!isDisguiseInUse()) { if (!isDisguiseInUse()) {
return false; return false;
} }
UndisguiseEvent event = new UndisguiseEvent(entity, this, disguiseBeingReplaced); UndisguiseEvent event = new UndisguiseEvent(sender, entity, this, disguiseBeingReplaced);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
@ -1068,6 +1077,10 @@ public abstract class Disguise {
} }
public boolean startDisguise() { public boolean startDisguise() {
return startDisguise(null);
}
public boolean startDisguise(CommandSender commandSender) {
if (isDisguiseInUse() || isDisguiseExpired()) { if (isDisguiseInUse() || isDisguiseExpired()) {
return false; return false;
} }
@ -1111,7 +1124,7 @@ public abstract class Disguise {
DisguiseUtilities.setPluginsUsed(); DisguiseUtilities.setPluginsUsed();
// Fire a disguise event // Fire a disguise event
DisguiseEvent event = new DisguiseEvent(entity, this); DisguiseEvent event = new DisguiseEvent(commandSender, entity, this);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);

View File

@ -13,6 +13,7 @@ import me.libraryaddict.disguise.utilities.reflection.LibsProfileLookup;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@ -177,7 +178,7 @@ public class PlayerDisguise extends TargetedDisguise {
this.nameVisible = nameVisible; this.nameVisible = nameVisible;
sendArmorStands(isNameVisible() ? DisguiseUtilities.reverse(getMultiName()) : new String[0]); sendArmorStands(isNameVisible() ? DisguiseUtilities.reverse(getMultiName()) : new String[0]);
} else if (!DisguiseConfig.isScoreboardNames()) { } else if (!DisguiseConfig.isScoreboardNames()) {
if (stopDisguise()) { if (removeDisguise()) {
this.nameVisible = nameVisible; this.nameVisible = nameVisible;
if (!startDisguise()) { if (!startDisguise()) {
@ -395,7 +396,7 @@ public class PlayerDisguise extends TargetedDisguise {
} }
private void resendDisguise(String name, boolean updateTeams) { private void resendDisguise(String name, boolean updateTeams) {
if (stopDisguise()) { if (removeDisguise()) {
if (getName().isEmpty() && !name.isEmpty()) { if (getName().isEmpty() && !name.isEmpty()) {
setNameVisible(true, true); setNameVisible(true, true);
} else if (!getName().isEmpty() && name.isEmpty()) { } else if (!getName().isEmpty() && name.isEmpty()) {
@ -621,6 +622,11 @@ public class PlayerDisguise extends TargetedDisguise {
@Override @Override
public boolean startDisguise() { public boolean startDisguise() {
return startDisguise(null);
}
@Override
public boolean startDisguise(CommandSender sender) {
if (isDisguiseInUse()) { if (isDisguiseInUse()) {
return false; return false;
} }
@ -666,7 +672,7 @@ public class PlayerDisguise extends TargetedDisguise {
setName(name); setName(name);
} }
boolean result = super.startDisguise(); boolean result = super.startDisguise(sender);
if (result && hasScoreboardName()) { if (result && hasScoreboardName()) {
DisguiseUtilities.registerExtendedName(this); DisguiseUtilities.registerExtendedName(this);

View File

@ -1,48 +1,37 @@
package me.libraryaddict.disguise.events; package me.libraryaddict.disguise.events;
import lombok.Getter;
import lombok.Setter;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@Getter
@Setter
public class DisguiseEvent extends Event implements Cancellable { public class DisguiseEvent extends Event implements Cancellable {
@Getter
private static final HandlerList handlerList = new HandlerList();
private static final HandlerList handlers = new HandlerList(); private final CommandSender commandSender;
private final Disguise disguise;
private final Entity entity;
private boolean cancelled;
public static HandlerList getHandlerList() { public DisguiseEvent(CommandSender sender, Entity entity, Disguise disguise) {
return handlers; commandSender = sender;
} this.entity = entity;
private Disguise disguise;
private Entity disguised;
private boolean isCancelled;
public DisguiseEvent(Entity entity, Disguise disguise) {
this.disguised = entity;
this.disguise = disguise; this.disguise = disguise;
} }
public Disguise getDisguise() { public DisguiseEvent(Entity entity, Disguise disguise) {
return disguise; this(null, entity, disguise);
}
public Entity getEntity() {
return disguised;
} }
@Override @Override
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return handlerList;
}
@Override
public boolean isCancelled() {
return isCancelled;
}
@Override
public void setCancelled(boolean cancelled) {
isCancelled = cancelled;
} }
} }

View File

@ -1,54 +1,39 @@
package me.libraryaddict.disguise.events; package me.libraryaddict.disguise.events;
import lombok.Getter;
import lombok.Setter;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@Getter
@Setter
public class UndisguiseEvent extends Event implements Cancellable { public class UndisguiseEvent extends Event implements Cancellable {
@Getter
private static final HandlerList handlerList = new HandlerList();
private static final HandlerList handlers = new HandlerList(); private final Disguise disguise;
private final Entity disguised;
public static HandlerList getHandlerList() { private final boolean isBeingReplaced;
return handlers; private final CommandSender commandSender;
}
private Disguise disguise;
private Entity disguised;
private boolean isCancelled; private boolean isCancelled;
private boolean isBeingReplaced;
public UndisguiseEvent(Entity entity, Disguise disguise, boolean beingReplaced) { public UndisguiseEvent(Entity entity, Disguise disguise, boolean beingReplaced) {
this(null, entity, disguise, beingReplaced);
}
public UndisguiseEvent(CommandSender sender, Entity entity, Disguise disguise, boolean beingReplaced) {
this.commandSender = sender;
this.disguised = entity; this.disguised = entity;
this.disguise = disguise; this.disguise = disguise;
this.isBeingReplaced = beingReplaced; this.isBeingReplaced = beingReplaced;
} }
public Disguise getDisguise() {
return disguise;
}
public Entity getEntity() {
return disguised;
}
@Override @Override
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return handlerList;
}
@Override
public boolean isCancelled() {
return isCancelled;
}
public boolean isBeingReplaced() {
return isBeingReplaced;
}
@Override
public void setCancelled(boolean cancelled) {
isCancelled = cancelled;
} }
} }

View File

@ -54,7 +54,7 @@ public class ParamInfoBlockData extends ParamInfo {
return null; return null;
} }
return Bukkit.createBlockData(string.toLowerCase()); return Bukkit.createBlockData(string.toLowerCase(Locale.ROOT));
} }
@Override @Override