Add mission perms, add /libsdisguises json

This commit is contained in:
libraryaddict 2020-02-05 14:23:53 +13:00
parent dd3017b0f9
commit a92916f112
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
3 changed files with 71 additions and 2 deletions

View File

@ -4,9 +4,11 @@ import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
@ -17,6 +19,8 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.Permissible;
import java.util.ArrayList;
@ -128,6 +132,29 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
} else {
sender.sendMessage(LibsMsg.NORMAL_PERM_CHECK_FAIL.get());
}
} else if (args[0].equalsIgnoreCase("json") || args[0].equalsIgnoreCase("gson") ||
args[0].equalsIgnoreCase("item") || args[0].equalsIgnoreCase("parse") ||
args[0].equalsIgnoreCase("tostring")) {
if (!sender.hasPermission("libsdisguises.json")) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (!(sender instanceof Player)) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
ItemStack item = ((Player) sender).getInventory().getItemInMainHand();
String gson = DisguiseUtilities.getGson().toJson(item);
String simple = ParamInfoManager.toString(item);
sendMessage(sender, LibsMsg.ITEM_SERIALIZED, gson);
if (!gson.equals(simple)) {
sendMessage(sender, LibsMsg.ITEM_SIMPLE_STRING, simple);
}
} else if (args[0].equalsIgnoreCase("metainfo") || args[0].equalsIgnoreCase("meta")) {
if (!sender.hasPermission("libsdisguises.metainfo")) {
sender.sendMessage(LibsMsg.NO_PERM.get());
@ -179,6 +206,37 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
return true;
}
private void sendMessage(CommandSender sender, LibsMsg prefix, String string) {
int start = 0;
int msg = 1;
ComponentBuilder builder = new ComponentBuilder("").appendLegacy(prefix.get());
while (start < string.length()) {
int end = Math.min(256, string.length() - start);
String sub = string.substring(start, start + end);
builder.append(" ");
if (string.length() <= 256) {
builder.appendLegacy(LibsMsg.CLICK_TO_COPY_DATA.get());
} else {
builder.reset();
builder.appendLegacy(LibsMsg.CLICK_COPY.get(msg));
}
start += end;
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, sub));
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new ComponentBuilder(LibsMsg.CLICK_TO_COPY_HOVER.get() + " " + msg).create()));
msg += 1;
}
sender.spigot().sendMessage(builder.create());
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();

View File

@ -113,7 +113,7 @@ public enum LibsMsg {
PLEASE_WAIT(ChatColor.GRAY + "Please wait..."),
INVALID_CLONE(ChatColor.DARK_RED + "Unknown option '%s' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' " +
"'DoSneak' 'DoSprint'"),
LIBS_COMMAND_WRONG_ARG(ChatColor.RED + "[LibsDisguises] Did you mean 'reload', 'permtest' or 'metainfo'?"),
LIBS_COMMAND_WRONG_ARG(ChatColor.RED + "[LibsDisguises] Did you mean 'reload', 'permtest', 'json' or 'metainfo'?"),
LIMITED_RADIUS(ChatColor.RED + "Limited radius to %s! Don't want to make too much lag right?"),
LISTEN_ENTITY_ENTITY_DISG_ENTITY(ChatColor.RED + "Disguised %s as a %s!"),
LISTEN_ENTITY_ENTITY_DISG_ENTITY_FAIL(ChatColor.RED + "Failed to disguise %s as a %s!"),
@ -248,7 +248,9 @@ public enum LibsMsg {
CANT_ATTACK_DISGUISED(ChatColor.RED + "Cannot fight while disguised!"),
CANT_ATTACK_DISGUISED_RECENTLY(ChatColor.RED + "You were disguised recently! Can't attack yet!"),
SWITCH_WORLD_DISGUISE_REMOVED(ChatColor.RED + "Disguise removed as you've switched worlds!"),
ACTION_BAR_MESSAGE(ChatColor.GOLD + "Currently disguised as %s");
ACTION_BAR_MESSAGE(ChatColor.GOLD + "Currently disguised as %s"),
ITEM_SERIALIZED(ChatColor.GOLD + "Serialized, click to copy: "),
ITEM_SIMPLE_STRING(ChatColor.GOLD + "Simple, click to copy: ");
private String string;

View File

@ -98,6 +98,15 @@ permissions:
libsdisguises.pve:
description: Allows player to ignore pve restrictions.
default: false
libsdisguises.permtest:
description: Allows player to test permissions
default: false
libsdisguises.metainfo:
description: Allows player to get meta info
default: false
libsdisguises.json:
description: Allows player to parse held item to json
default: true
libsdisguises.pvp:
description: Allows player to ignore pvp restrictions.
default: false