Change the way entity interaction works for commands to a cleaner method

This commit is contained in:
libraryaddict 2020-04-04 14:17:29 +13:00
parent 7f46b5b512
commit 44012ab58b
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
13 changed files with 381 additions and 263 deletions

View File

@ -14,6 +14,7 @@ import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise; import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsEntityInteract;
import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.UpdateChecker; import me.libraryaddict.disguise.utilities.UpdateChecker;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
@ -51,9 +52,7 @@ import java.util.concurrent.TimeUnit;
public class DisguiseListener implements Listener { public class DisguiseListener implements Listener {
private String currentVersion; private String currentVersion;
private HashMap<String, Boolean[]> disguiseClone = new HashMap<>(); private HashMap<String, LibsEntityInteract> interactions = new HashMap<>();
private HashMap<String, String[]> disguiseEntity = new HashMap<>();
private HashMap<String, String[]> disguiseModify = new HashMap<>();
private HashMap<String, BukkitRunnable> disguiseRunnable = new HashMap<>(); private HashMap<String, BukkitRunnable> disguiseRunnable = new HashMap<>();
private String latestVersion; private String latestVersion;
private LibsMsg updateMessage; private LibsMsg updateMessage;
@ -176,7 +175,7 @@ public class DisguiseListener implements Listener {
r.cancel(); r.cancel();
} }
disguiseClone.clear(); interactions.clear();
updaterTask.cancel(); updaterTask.cancel();
} }
@ -513,8 +512,7 @@ public class DisguiseListener implements Listener {
public void onRightClick(PlayerInteractEntityEvent event) { public void onRightClick(PlayerInteractEntityEvent event) {
Player p = event.getPlayer(); Player p = event.getPlayer();
if (!disguiseEntity.containsKey(p.getName()) && !disguiseClone.containsKey(p.getName()) && if (!interactions.containsKey(p.getName())) {
!disguiseModify.containsKey(p.getName())) {
return; return;
} }
@ -522,154 +520,7 @@ public class DisguiseListener implements Listener {
disguiseRunnable.remove(p.getName()).cancel(); disguiseRunnable.remove(p.getName()).cancel();
Entity entity = event.getRightClicked(); Entity entity = event.getRightClicked();
String entityName; interactions.remove(p.getName()).onInteract(p, entity);
if (entity instanceof Player && !disguiseClone.containsKey(p.getName())) {
entityName = entity.getName();
} else {
entityName = DisguiseType.getType(entity).toReadable();
}
if (disguiseClone.containsKey(p.getName())) {
Boolean[] options = disguiseClone.remove(p.getName());
DisguiseUtilities.createClonedDisguise(p, entity, options);
} else if (disguiseEntity.containsKey(p.getName())) {
String[] disguiseArgs = disguiseEntity.remove(p.getName());
if (disguiseArgs != null) {
Disguise disguise;
try {
disguise = DisguiseParser.parseDisguise(p, entity, "disguiseentity", disguiseArgs,
DisguiseParser.getPermissions(p, "disguiseentity"));
}
catch (DisguiseParseException e) {
if (e.getMessage() != null) {
p.sendMessage(e.getMessage());
}
return;
}
catch (Exception e) {
e.printStackTrace();
return;
}
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() &&
entity instanceof LivingEntity) {
p.sendMessage(LibsMsg.DISABLED_LIVING_TO_MISC.get());
} else {
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise() &&
!entity.hasPermission("libsdisguises.hidename")) {
if (disguise.getWatcher() instanceof LivingWatcher) {
Team team = ((Player) entity).getScoreboard().getEntryTeam(entity.getName());
disguise.getWatcher().setCustomName(
(team == null ? "" : team.getPrefix()) + entity.getName() +
(team == null ? "" : team.getSuffix()));
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
disguise.getWatcher().setCustomNameVisible(true);
}
}
}
DisguiseAPI.disguiseEntity(entity, disguise);
String disguiseName;
if (disguise instanceof PlayerDisguise) {
disguiseName = ((PlayerDisguise) disguise).getName();
} else {
disguiseName = disguise.getType().toReadable();
}
// Jeez, maybe I should redo my messages here
if (disguise.isDisguiseInUse()) {
if (disguise.isPlayerDisguise()) {
if (entity instanceof Player) {
p.sendMessage(LibsMsg.LISTEN_ENTITY_PLAYER_DISG_PLAYER.get(entityName, disguiseName));
} else {
p.sendMessage(LibsMsg.LISTEN_ENTITY_ENTITY_DISG_PLAYER.get(entityName, disguiseName));
}
} else {
if (entity instanceof Player) {
p.sendMessage(LibsMsg.LISTEN_ENTITY_PLAYER_DISG_ENTITY.get(entityName, disguiseName));
} else {
p.sendMessage(LibsMsg.LISTEN_ENTITY_ENTITY_DISG_ENTITY.get(entityName, disguiseName));
}
}
} else {
if (disguise.isPlayerDisguise()) {
if (entity instanceof Player) {
p.sendMessage(
LibsMsg.LISTEN_ENTITY_PLAYER_DISG_PLAYER_FAIL.get(entityName, disguiseName));
} else {
p.sendMessage(
LibsMsg.LISTEN_ENTITY_ENTITY_DISG_PLAYER_FAIL.get(entityName, disguiseName));
}
} else {
if (entity instanceof Player) {
p.sendMessage(
LibsMsg.LISTEN_ENTITY_PLAYER_DISG_ENTITY_FAIL.get(entityName, disguiseName));
} else {
p.sendMessage(
LibsMsg.LISTEN_ENTITY_ENTITY_DISG_ENTITY_FAIL.get(entityName, disguiseName));
}
}
}
}
} else {
if (DisguiseAPI.isDisguised(entity)) {
DisguiseAPI.undisguiseToAll(entity);
if (entity instanceof Player)
p.sendMessage(LibsMsg.LISTEN_UNDISG_PLAYER.get(entityName));
else
p.sendMessage(LibsMsg.LISTEN_UNDISG_ENT.get(entityName));
} else {
if (entity instanceof Player)
p.sendMessage(LibsMsg.LISTEN_UNDISG_PLAYER_FAIL.get(entityName));
else
p.sendMessage(LibsMsg.LISTEN_UNDISG_ENT_FAIL.get(entityName));
}
}
} else if (disguiseModify.containsKey(p.getName())) {
String[] options = disguiseModify.remove(p.getName());
Disguise disguise = DisguiseAPI.getDisguise(p, entity);
if (disguise == null) {
p.sendMessage(LibsMsg.UNDISG_PLAYER_FAIL.get(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))) {
p.sendMessage(LibsMsg.DMODPLAYER_NOPERM.get());
return;
}
try {
DisguiseParser
.callMethods(p, disguise, perms, disguisePerm, new ArrayList<>(Arrays.asList(options)), options,
"DisguiseModifyEntity");
p.sendMessage(LibsMsg.LISTENER_MODIFIED_DISG.get());
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
p.sendMessage(ex.getMessage());
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
} }
@EventHandler @EventHandler
@ -824,66 +675,23 @@ public class DisguiseListener implements Listener {
} }
} }
public void setDisguiseClone(final String player, Boolean[] options) { public void addInteraction(String playerName, LibsEntityInteract interaction, int secondsExpire) {
if (disguiseRunnable.containsKey(player)) { if (disguiseRunnable.containsKey(playerName)) {
BukkitRunnable run = disguiseRunnable.remove(player); disguiseRunnable.get(playerName).cancel();
run.cancel();
run.run();
} }
interactions.put(playerName, interaction);
BukkitRunnable runnable = new BukkitRunnable() { BukkitRunnable runnable = new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
disguiseClone.remove(player); interactions.remove(playerName);
disguiseRunnable.remove(player); disguiseRunnable.remove(playerName);
} }
}; };
runnable.runTaskLater(plugin, 20 * DisguiseConfig.getDisguiseCloneExpire()); runnable.runTaskLater(LibsDisguises.getInstance(), secondsExpire * 20);
disguiseRunnable.put(player, runnable); disguiseRunnable.put(playerName, runnable);
disguiseClone.put(player, options);
}
public void setDisguiseEntity(final String player, String[] disguise) {
if (disguiseRunnable.containsKey(player)) {
BukkitRunnable run = disguiseRunnable.remove(player);
run.cancel();
run.run();
}
BukkitRunnable runnable = new BukkitRunnable() {
@Override
public void run() {
disguiseEntity.remove(player);
disguiseRunnable.remove(player);
}
};
runnable.runTaskLater(plugin, 20 * DisguiseConfig.getDisguiseEntityExpire());
disguiseRunnable.put(player, runnable);
disguiseEntity.put(player, disguise);
}
public void setDisguiseModify(final String player, String[] args) {
if (disguiseRunnable.containsKey(player)) {
BukkitRunnable run = disguiseRunnable.remove(player);
run.cancel();
run.run();
}
BukkitRunnable runnable = new BukkitRunnable() {
@Override
public void run() {
disguiseModify.remove(player);
disguiseRunnable.remove(player);
}
};
runnable.runTaskLater(plugin, 20 * DisguiseConfig.getDisguiseEntityExpire());
disguiseRunnable.put(player, runnable);
disguiseModify.put(player, args);
} }
} }

View File

@ -3,6 +3,7 @@ package me.libraryaddict.disguise.commands.disguise;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.commands.DisguiseBaseCommand; import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
import me.libraryaddict.disguise.commands.interactions.DisguiseEntityInteraction;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
@ -61,7 +62,9 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom
return true; return true;
} }
LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), disguiseArgs); LibsDisguises.getInstance().getListener()
.addInteraction(sender.getName(), new DisguiseEntityInteraction(disguiseArgs),
DisguiseConfig.getDisguiseEntityExpire());
sender.sendMessage(LibsMsg.DISG_ENT_CLICK sender.sendMessage(LibsMsg.DISG_ENT_CLICK
.get(DisguiseConfig.getDisguiseEntityExpire(), testDisguise.getType().toReadable())); .get(DisguiseConfig.getDisguiseEntityExpire(), testDisguise.getType().toReadable()));

View File

@ -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 {
player.sendMessage(LibsMsg.TARGET_NOT_DISGUISED.get());
}
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,114 @@
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.PlayerDisguise;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
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.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Team;
/**
* 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) {
if (e.getMessage() != null) {
p.sendMessage(e.getMessage());
}
return;
}
catch (Exception e) {
e.printStackTrace();
return;
}
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() &&
entity instanceof LivingEntity) {
p.sendMessage(LibsMsg.DISABLED_LIVING_TO_MISC.get());
} else {
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise() &&
!entity.hasPermission("libsdisguises.hidename")) {
if (disguise.getWatcher() instanceof LivingWatcher) {
Team team = ((Player) entity).getScoreboard().getEntryTeam(entity.getName());
disguise.getWatcher().setCustomName((team == null ? "" : team.getPrefix()) + entity.getName() +
(team == null ? "" : team.getSuffix()));
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
disguise.getWatcher().setCustomNameVisible(true);
}
}
}
DisguiseAPI.disguiseEntity(entity, disguise);
String disguiseName;
if (disguise instanceof PlayerDisguise) {
disguiseName = ((PlayerDisguise) disguise).getName();
} else {
disguiseName = disguise.getType().toReadable();
}
// Jeez, maybe I should redo my messages here
if (disguise.isDisguiseInUse()) {
if (disguise.isPlayerDisguise()) {
if (entity instanceof Player) {
p.sendMessage(LibsMsg.LISTEN_ENTITY_PLAYER_DISG_PLAYER.get(entityName, disguiseName));
} else {
p.sendMessage(LibsMsg.LISTEN_ENTITY_ENTITY_DISG_PLAYER.get(entityName, disguiseName));
}
} else {
if (entity instanceof Player) {
p.sendMessage(LibsMsg.LISTEN_ENTITY_PLAYER_DISG_ENTITY.get(entityName, disguiseName));
} else {
p.sendMessage(LibsMsg.LISTEN_ENTITY_ENTITY_DISG_ENTITY.get(entityName, disguiseName));
}
}
} else {
if (disguise.isPlayerDisguise()) {
if (entity instanceof Player) {
p.sendMessage(LibsMsg.LISTEN_ENTITY_PLAYER_DISG_PLAYER_FAIL.get(entityName, disguiseName));
} else {
p.sendMessage(LibsMsg.LISTEN_ENTITY_ENTITY_DISG_PLAYER_FAIL.get(entityName, disguiseName));
}
} else {
if (entity instanceof Player) {
p.sendMessage(LibsMsg.LISTEN_ENTITY_PLAYER_DISG_ENTITY_FAIL.get(entityName, disguiseName));
} else {
p.sendMessage(LibsMsg.LISTEN_ENTITY_ENTITY_DISG_ENTITY_FAIL.get(entityName, disguiseName));
}
}
}
}
}
}

View File

@ -0,0 +1,69 @@
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) {
p.sendMessage(LibsMsg.UNDISG_PLAYER_FAIL.get(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))) {
p.sendMessage(LibsMsg.DMODPLAYER_NOPERM.get());
return;
}
try {
DisguiseParser
.callMethods(p, disguise, perms, disguisePerm, new ArrayList<>(Arrays.asList(options)), options,
"DisguiseModifyEntity");
p.sendMessage(LibsMsg.LISTENER_MODIFIED_DISG.get());
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
p.sendMessage(ex.getMessage());
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}

View File

@ -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(entity);
if (entity instanceof Player)
p.sendMessage(LibsMsg.LISTEN_UNDISG_PLAYER.get(entityName));
else
p.sendMessage(LibsMsg.LISTEN_UNDISG_ENT.get(entityName));
} else {
if (entity instanceof Player)
p.sendMessage(LibsMsg.LISTEN_UNDISG_PLAYER_FAIL.get(entityName));
else
p.sendMessage(LibsMsg.LISTEN_UNDISG_ENT_FAIL.get(entityName));
}
}
}

View File

@ -3,6 +3,7 @@ package me.libraryaddict.disguise.commands.modify;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.commands.DisguiseBaseCommand; import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
import me.libraryaddict.disguise.commands.interactions.DisguiseModifyInteraction;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
@ -18,6 +19,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements TabCompleter { public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements TabCompleter {
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
@ -39,8 +41,9 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements
// TODO Validate if any disguises have this arg // TODO Validate if any disguises have this arg
LibsDisguises.getInstance().getListener() LibsDisguises.getInstance().getListener().addInteraction(sender.getName(),
.setDisguiseModify(sender.getName(), DisguiseUtilities.split(StringUtils.join(args, " "))); new DisguiseModifyInteraction(DisguiseUtilities.split(StringUtils.join(args, " "))),
DisguiseConfig.getDisguiseEntityExpire());
sender.sendMessage(LibsMsg.DMODIFYENT_CLICK.get(DisguiseConfig.getDisguiseEntityExpire())); sender.sendMessage(LibsMsg.DMODIFYENT_CLICK.get(DisguiseConfig.getDisguiseEntityExpire()));
return true; return true;

View File

@ -1,6 +1,8 @@
package me.libraryaddict.disguise.commands.undisguise; package me.libraryaddict.disguise.commands.undisguise;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.commands.interactions.UndisguiseEntityInteraction;
import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -10,10 +12,9 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class UndisguiseEntityCommand implements CommandExecutor { public class UndisguiseEntityCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player && !sender.isOp()&& if (sender instanceof Player && !sender.isOp() &&
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) { (!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands"); sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands");
return true; return true;
@ -23,12 +24,16 @@ public class UndisguiseEntityCommand implements CommandExecutor {
sender.sendMessage(LibsMsg.NO_CONSOLE.get()); sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true; return true;
} }
if (sender.hasPermission("libsdisguises.undisguiseentity")) {
LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), null); if (!sender.hasPermission("libsdisguises.undisguiseentity")) {
sender.sendMessage(LibsMsg.UND_ENTITY.get());
} else {
sender.sendMessage(LibsMsg.NO_PERM.get()); sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
} }
LibsDisguises.getInstance().getListener().addInteraction(sender.getName(), new UndisguiseEntityInteraction(),
DisguiseConfig.getDisguiseEntityExpire());
sender.sendMessage(LibsMsg.UND_ENTITY.get());
return true; return true;
} }
} }

View File

@ -1,6 +1,10 @@
package me.libraryaddict.disguise.commands.utils; package me.libraryaddict.disguise.commands.utils;
import me.libraryaddict.disguise.DisguiseAPI; 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.commands.interactions.DisguiseModifyInteraction;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
@ -11,6 +15,7 @@ import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.HoverEvent;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -63,22 +68,16 @@ public class CopyDisguiseCommand implements CommandExecutor {
Disguise disguise = DisguiseAPI.getDisguise(target); Disguise disguise = DisguiseAPI.getDisguise(target);
if (disguise == null) { if (disguise == null) {
sender.sendMessage((sender == target ? LibsMsg.NOT_DISGUISED : LibsMsg.TARGET_NOT_DISGUISED).get()); LibsDisguises.getInstance().getListener()
.addInteraction(sender.getName(), new CopyDisguiseInteraction(this),
DisguiseConfig.getDisguiseEntityExpire());
sender.sendMessage(LibsMsg.DISGUISECOPY_INTERACT.get(DisguiseConfig.getDisguiseEntityExpire()));
return true; return true;
} }
String disguiseString = DisguiseParser.parseToString(disguise, false); String disguiseString = DisguiseParser.parseToString(disguise, false);
/*if (!(sender instanceof Player)) {
sender.sendMessage(disguiseString);
if (disguise instanceof PlayerDisguise) {
sender.sendMessage(DisguiseParser.parseToString(disguise, false));
}
return true;
}*/
sendMessage(sender, LibsMsg.CLICK_TO_COPY, LibsMsg.COPY_DISGUISE_NO_COPY, disguiseString, false); sendMessage(sender, LibsMsg.CLICK_TO_COPY, LibsMsg.COPY_DISGUISE_NO_COPY, disguiseString, false);
if (disguise instanceof PlayerDisguise) { if (disguise instanceof PlayerDisguise) {
@ -91,7 +90,7 @@ public class CopyDisguiseCommand implements CommandExecutor {
return true; return true;
} }
private void sendMessage(CommandSender sender, LibsMsg msg, LibsMsg oldVer, String string, boolean forceAbbrev) { public void sendMessage(CommandSender sender, LibsMsg msg, LibsMsg oldVer, String string, boolean forceAbbrev) {
if (!NmsVersion.v1_13.isSupported()) { if (!NmsVersion.v1_13.isSupported()) {
sender.sendMessage(oldVer.get(string)); sender.sendMessage(oldVer.get(string));
return; return;

View File

@ -3,6 +3,7 @@ package me.libraryaddict.disguise.commands.utils;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.commands.DisguiseBaseCommand; import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
import me.libraryaddict.disguise.commands.interactions.DisguiseCloneInteraction;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.translations.LibsMsg;
@ -17,6 +18,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabCompleter { public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabCompleter {
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) { if (sender.getName().equals("CONSOLE")) {
@ -24,7 +26,12 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp
return true; return true;
} }
if (sender.hasPermission("libsdisguises.disguise.disguiseclone")) { if (!sender.hasPermission("libsdisguises.disguise.disguiseclone")) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
boolean doEquipment = true; boolean doEquipment = true;
boolean doSneak = false; boolean doSneak = false;
boolean doSprint = false; boolean doSprint = false;
@ -56,13 +63,12 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp
if (player != null) { if (player != null) {
DisguiseUtilities.createClonedDisguise((Player) sender, player, options); DisguiseUtilities.createClonedDisguise((Player) sender, player, options);
} else { } else {
LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), options); LibsDisguises.getInstance().getListener()
.addInteraction(sender.getName(), new DisguiseCloneInteraction(options),
DisguiseConfig.getDisguiseCloneExpire());
sender.sendMessage(LibsMsg.CLICK_TIMER.get(DisguiseConfig.getDisguiseCloneExpire())); sender.sendMessage(LibsMsg.CLICK_TIMER.get(DisguiseConfig.getDisguiseCloneExpire()));
} }
} else {
sender.sendMessage(LibsMsg.NO_PERM.get());
}
return true; return true;
} }

View File

@ -0,0 +1,11 @@
package me.libraryaddict.disguise.utilities;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
/**
* Created by libraryaddict on 2/04/2020.
*/
public interface LibsEntityInteract {
void onInteract(Player player, Entity entity);
}

View File

@ -63,6 +63,7 @@ public enum LibsMsg {
DMODIFY_MODIFIED(ChatColor.RED + "Your disguise has been modified!"), DMODIFY_MODIFIED(ChatColor.RED + "Your disguise has been modified!"),
DMODIFY_NO_PERM(ChatColor.RED + "No permission to modify your disguise!"), DMODIFY_NO_PERM(ChatColor.RED + "No permission to modify your disguise!"),
DMODIFYENT_CLICK(ChatColor.RED + "Right click a disguised entity in the next %s seconds to modify their disguise!"), DMODIFYENT_CLICK(ChatColor.RED + "Right click a disguised entity in the next %s seconds to modify their disguise!"),
DISGUISECOPY_INTERACT(ChatColor.RED + "Right click a disguised entity in the next %s seconds to copy their disguise!"),
DMODPLAYER_HELP1(ChatColor.DARK_GREEN + "Modify the disguise of another player!"), DMODPLAYER_HELP1(ChatColor.DARK_GREEN + "Modify the disguise of another player!"),
DMODPLAYER_MODIFIED(ChatColor.RED + "Modified the disguise of %s!"), DMODPLAYER_MODIFIED(ChatColor.RED + "Modified the disguise of %s!"),
DMODPLAYER_NODISGUISE(ChatColor.RED + "The player '%s' is not disguised"), DMODPLAYER_NODISGUISE(ChatColor.RED + "The player '%s' is not disguised"),