2020-01-02 05:10:36 +01:00
|
|
|
package me.libraryaddict.disguise.commands;
|
|
|
|
|
|
|
|
import me.libraryaddict.disguise.DisguiseAPI;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
|
|
|
import me.libraryaddict.disguise.utilities.LibsPremium;
|
|
|
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
|
|
|
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;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by libraryaddict on 1/01/2020.
|
|
|
|
*/
|
|
|
|
public class CopyDisguiseCommand implements CommandExecutor {
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sender.hasPermission("libsdisguises.copydisguise")) {
|
|
|
|
sender.sendMessage(LibsMsg.NO_PERM.get());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Entity target = sender instanceof Player ? (Entity) sender : null;
|
|
|
|
|
|
|
|
if (args.length > 0) {
|
|
|
|
target = Bukkit.getPlayer(args[0]);
|
|
|
|
|
|
|
|
if (target == null) {
|
|
|
|
if (args[0].contains("-")) {
|
|
|
|
try {
|
|
|
|
target = Bukkit.getEntity(UUID.fromString(args[0]));
|
|
|
|
}
|
|
|
|
catch (Exception ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target == null) {
|
|
|
|
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0]));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Disguise disguise = DisguiseAPI.getDisguise(target);
|
|
|
|
|
|
|
|
if (disguise == null) {
|
|
|
|
sender.sendMessage((sender == target ? LibsMsg.NOT_DISGUISED : LibsMsg.TARGET_NOT_DISGUISED).get());
|
|
|
|
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, disguiseString, false);
|
|
|
|
|
|
|
|
if (disguise instanceof PlayerDisguise) {
|
|
|
|
sendMessage(sender, LibsMsg.CLICK_TO_COPY_WITH_SKIN, DisguiseParser.parseToString(disguise), true);
|
|
|
|
}
|
|
|
|
|
2020-01-03 19:46:02 +01:00
|
|
|
DisguiseUtilities.setCopyDisguiseCommandUsed();
|
|
|
|
|
2020-01-02 05:10:36 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendMessage(CommandSender sender, LibsMsg msg, String string, boolean forceAbbrev) {
|
|
|
|
ComponentBuilder builder = new ComponentBuilder("").appendLegacy(msg.get()).append(" ");
|
|
|
|
|
|
|
|
if (string.length() > 256 || forceAbbrev) {
|
|
|
|
String[] split = DisguiseUtilities.split(string);
|
|
|
|
|
|
|
|
for (int i = 0; i < split.length; i++) {
|
|
|
|
if (split[i].length() <= 256) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
split = Arrays.copyOf(split, split.length + 1);
|
|
|
|
|
|
|
|
for (int a = split.length - 1; a > i; a--) {
|
|
|
|
split[a] = split[a - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
split[i + 1] = split[i].substring(256);
|
|
|
|
split[i] = split[i].substring(0, 256);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sections = 0;
|
|
|
|
StringBuilder current = new StringBuilder();
|
|
|
|
|
|
|
|
for (int i = 0; i < split.length; i++) {
|
|
|
|
if (current.length() > 0) {
|
|
|
|
current.append(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
current.append(split[i]);
|
|
|
|
|
|
|
|
// If the next split would fit
|
|
|
|
if (split.length > i + 1 && split[i + 1].length() + current.length() + 1 <= 256) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sections != 0) {
|
|
|
|
builder.append(" ");
|
|
|
|
builder.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
sections++;
|
|
|
|
|
|
|
|
builder.appendLegacy(LibsMsg.CLICK_COPY.get(sections));
|
|
|
|
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, current.toString()));
|
|
|
|
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
|
|
|
new ComponentBuilder(LibsMsg.CLICK_TO_COPY_HOVER.get() + " " + sections).create()));
|
|
|
|
|
|
|
|
current = new StringBuilder();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
builder.appendLegacy(LibsMsg.CLICK_COPY.get(string));
|
|
|
|
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, string));
|
|
|
|
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
|
|
|
new ComponentBuilder(LibsMsg.CLICK_TO_COPY_HOVER.get()).create()));
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.spigot().sendMessage(builder.create());
|
|
|
|
}
|
|
|
|
}
|