Change the way entity interaction works for commands to a cleaner method
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user