LibsDisguises/src/main/java/me/libraryaddict/disguise/commands/interactions/DisguiseModifyInteraction.java

71 lines
2.4 KiB
Java
Raw Normal View History

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;
2020-06-27 11:01:58 +02:00
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.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) {
2020-06-27 11:01:58 +02:00
DisguiseUtilities.sendMessage(p, LibsMsg.UNDISG_PLAYER_FAIL, 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))) {
2020-06-27 11:01:58 +02:00
DisguiseUtilities.sendMessage(p, LibsMsg.DMODPLAYER_NOPERM);
return;
}
try {
DisguiseParser
.callMethods(p, disguise, perms, disguisePerm, new ArrayList<>(Arrays.asList(options)), options,
"DisguiseModifyEntity");
2020-06-27 11:01:58 +02:00
DisguiseUtilities.sendMessage(p, LibsMsg.LISTENER_MODIFIED_DISG);
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
p.sendMessage(ex.getMessage());
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}