Change the way entity interaction works for commands to a cleaner method
This commit is contained in:
parent
7f46b5b512
commit
44012ab58b
@ -14,6 +14,7 @@ import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsEntityInteract;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.UpdateChecker;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||
@ -51,9 +52,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DisguiseListener implements Listener {
|
||||
private String currentVersion;
|
||||
private HashMap<String, Boolean[]> disguiseClone = new HashMap<>();
|
||||
private HashMap<String, String[]> disguiseEntity = new HashMap<>();
|
||||
private HashMap<String, String[]> disguiseModify = new HashMap<>();
|
||||
private HashMap<String, LibsEntityInteract> interactions = new HashMap<>();
|
||||
private HashMap<String, BukkitRunnable> disguiseRunnable = new HashMap<>();
|
||||
private String latestVersion;
|
||||
private LibsMsg updateMessage;
|
||||
@ -176,7 +175,7 @@ public class DisguiseListener implements Listener {
|
||||
r.cancel();
|
||||
}
|
||||
|
||||
disguiseClone.clear();
|
||||
interactions.clear();
|
||||
updaterTask.cancel();
|
||||
}
|
||||
|
||||
@ -513,8 +512,7 @@ public class DisguiseListener implements Listener {
|
||||
public void onRightClick(PlayerInteractEntityEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
|
||||
if (!disguiseEntity.containsKey(p.getName()) && !disguiseClone.containsKey(p.getName()) &&
|
||||
!disguiseModify.containsKey(p.getName())) {
|
||||
if (!interactions.containsKey(p.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -522,154 +520,7 @@ public class DisguiseListener implements Listener {
|
||||
disguiseRunnable.remove(p.getName()).cancel();
|
||||
|
||||
Entity entity = event.getRightClicked();
|
||||
String entityName;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
interactions.remove(p.getName()).onInteract(p, entity);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -824,66 +675,23 @@ public class DisguiseListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public void setDisguiseClone(final String player, Boolean[] options) {
|
||||
if (disguiseRunnable.containsKey(player)) {
|
||||
BukkitRunnable run = disguiseRunnable.remove(player);
|
||||
run.cancel();
|
||||
run.run();
|
||||
public void addInteraction(String playerName, LibsEntityInteract interaction, int secondsExpire) {
|
||||
if (disguiseRunnable.containsKey(playerName)) {
|
||||
disguiseRunnable.get(playerName).cancel();
|
||||
}
|
||||
|
||||
interactions.put(playerName, interaction);
|
||||
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
disguiseClone.remove(player);
|
||||
disguiseRunnable.remove(player);
|
||||
interactions.remove(playerName);
|
||||
disguiseRunnable.remove(playerName);
|
||||
}
|
||||
};
|
||||
|
||||
runnable.runTaskLater(plugin, 20 * DisguiseConfig.getDisguiseCloneExpire());
|
||||
runnable.runTaskLater(LibsDisguises.getInstance(), secondsExpire * 20);
|
||||
|
||||
disguiseRunnable.put(player, 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);
|
||||
disguiseRunnable.put(playerName, runnable);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ 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;
|
||||
@ -61,7 +62,9 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom
|
||||
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
|
||||
.get(DisguiseConfig.getDisguiseEntityExpire(), testDisguise.getType().toReadable()));
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
@ -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,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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ 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;
|
||||
@ -18,6 +19,7 @@ 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)) {
|
||||
@ -39,8 +41,9 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements
|
||||
|
||||
// TODO Validate if any disguises have this arg
|
||||
|
||||
LibsDisguises.getInstance().getListener()
|
||||
.setDisguiseModify(sender.getName(), DisguiseUtilities.split(StringUtils.join(args, " ")));
|
||||
LibsDisguises.getInstance().getListener().addInteraction(sender.getName(),
|
||||
new DisguiseModifyInteraction(DisguiseUtilities.split(StringUtils.join(args, " "))),
|
||||
DisguiseConfig.getDisguiseEntityExpire());
|
||||
|
||||
sender.sendMessage(LibsMsg.DMODIFYENT_CLICK.get(DisguiseConfig.getDisguiseEntityExpire()));
|
||||
return true;
|
||||
|
@ -1,6 +1,8 @@
|
||||
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;
|
||||
@ -10,10 +12,9 @@ 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()&&
|
||||
if (sender instanceof Player && !sender.isOp() &&
|
||||
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
|
||||
sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands");
|
||||
return true;
|
||||
@ -23,12 +24,16 @@ public class UndisguiseEntityCommand implements CommandExecutor {
|
||||
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("libsdisguises.undisguiseentity")) {
|
||||
LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), null);
|
||||
sender.sendMessage(LibsMsg.UND_ENTITY.get());
|
||||
} else {
|
||||
|
||||
if (!sender.hasPermission("libsdisguises.undisguiseentity")) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
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.commands.interactions.DisguiseModifyInteraction;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
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.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@ -63,22 +68,16 @@ public class CopyDisguiseCommand implements CommandExecutor {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(target);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (disguise instanceof PlayerDisguise) {
|
||||
@ -91,7 +90,7 @@ public class CopyDisguiseCommand implements CommandExecutor {
|
||||
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()) {
|
||||
sender.sendMessage(oldVer.get(string));
|
||||
return;
|
||||
|
@ -3,6 +3,7 @@ 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;
|
||||
@ -17,6 +18,7 @@ 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")) {
|
||||
@ -24,44 +26,48 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender.hasPermission("libsdisguises.disguise.disguiseclone")) {
|
||||
boolean doEquipment = true;
|
||||
boolean doSneak = false;
|
||||
boolean doSprint = false;
|
||||
Player player = null;
|
||||
if (!sender.hasPermission("libsdisguises.disguise.disguiseclone")) {
|
||||
|
||||
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_SNEAKSPRINT.get())) {
|
||||
doSneak = true;
|
||||
doSprint = true;
|
||||
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAK.get())) {
|
||||
doSneak = true;
|
||||
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SPRINT.get())) {
|
||||
doSprint = true;
|
||||
} else {
|
||||
sender.sendMessage(LibsMsg.INVALID_CLONE.get(option));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Boolean[] options = new Boolean[]{doEquipment, doSneak, doSprint};
|
||||
|
||||
if (player != null) {
|
||||
DisguiseUtilities.createClonedDisguise((Player) sender, player, options);
|
||||
} else {
|
||||
LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), options);
|
||||
|
||||
sender.sendMessage(LibsMsg.CLICK_TIMER.get(DisguiseConfig.getDisguiseCloneExpire()));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(LibsMsg.NO_PERM.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean doEquipment = true;
|
||||
boolean doSneak = false;
|
||||
boolean doSprint = 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_SNEAKSPRINT.get())) {
|
||||
doSneak = true;
|
||||
doSprint = true;
|
||||
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAK.get())) {
|
||||
doSneak = true;
|
||||
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SPRINT.get())) {
|
||||
doSprint = true;
|
||||
} else {
|
||||
sender.sendMessage(LibsMsg.INVALID_CLONE.get(option));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Boolean[] options = new Boolean[]{doEquipment, doSneak, doSprint};
|
||||
|
||||
if (player != null) {
|
||||
DisguiseUtilities.createClonedDisguise((Player) sender, player, options);
|
||||
} else {
|
||||
LibsDisguises.getInstance().getListener()
|
||||
.addInteraction(sender.getName(), new DisguiseCloneInteraction(options),
|
||||
DisguiseConfig.getDisguiseCloneExpire());
|
||||
|
||||
sender.sendMessage(LibsMsg.CLICK_TIMER.get(DisguiseConfig.getDisguiseCloneExpire()));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -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);
|
||||
}
|
@ -63,6 +63,7 @@ public enum LibsMsg {
|
||||
DMODIFY_MODIFIED(ChatColor.RED + "Your disguise has been modified!"),
|
||||
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!"),
|
||||
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_MODIFIED(ChatColor.RED + "Modified the disguise of %s!"),
|
||||
DMODPLAYER_NODISGUISE(ChatColor.RED + "The player '%s' is not disguised"),
|
||||
|
Loading…
Reference in New Issue
Block a user