Updated Format API

This commit is contained in:
Aust1n46 2020-04-07 20:27:13 -04:00
parent 96edb124f0
commit 3a89d5d6c7
3 changed files with 84 additions and 28 deletions

View File

@ -46,30 +46,10 @@ public class VentureChatGui extends MineverseCommand {
MineverseChatPlayer mcp = MineverseChatAPI.getMineverseChatPlayer((Player) sender);
if(mcp.getPlayer().hasPermission("venturechat.gui")) {
MineverseChatPlayer target = MineverseChatAPI.getMineverseChatPlayer(args[0]);
if(target == null) {
if(target == null && !args[0].equals("Discord")) {
mcp.getPlayer().sendMessage(LocalizedMessage.PLAYER_OFFLINE.toString()
.replace("{args}", args[0]));
return;
/*
UUID uuid = null;
try {
uuid = UUIDFetcher.getUUIDOf(args[0]);
}
catch(Exception e) {
e.printStackTrace();
}
String name = args[0];
ChatChannel current = MineverseChat.ccInfo.getDefaultChannel();
Set<UUID> ignores = new HashSet<UUID>();
Set<String> listening = new HashSet<String>();
listening.add(current.getName());
HashMap<String, Integer> mutes = new HashMap<String, Integer>();
Set<String> blockedCommands = new HashSet<String>();
List<String> mail = new ArrayList<String>();
String jsonFormat = "Default";
target = new MineverseChatPlayer(uuid, name, current, ignores, listening, mutes, blockedCommands, mail, false, null, true, true, name, jsonFormat, false, false, false, true, true, true);
MineverseChat.players.add(target);
*/
}
if(ChatChannel.isChannel(args[1])) {
ChatChannel channel = ChatChannel.getChannel(args[1]);
@ -80,6 +60,10 @@ public class VentureChatGui extends MineverseCommand {
catch(Exception e) {
sender.sendMessage(LocalizedMessage.INVALID_HASH.toString());
return;
}
if(args[0].equals("Discord")) {
this.openInventoryDiscord(mcp, channel, hash);
return;
}
this.openInventory(mcp, target, channel, hash);
return;
@ -151,6 +135,62 @@ public class VentureChatGui extends MineverseCommand {
mcp.getPlayer().openInventory(inv);
}
@SuppressWarnings("deprecation")
private void openInventoryDiscord(MineverseChatPlayer mcp, ChatChannel channel, int hash) {
Inventory inv = Bukkit.createInventory(null, this.getSlots(), "VentureChat: Discord_Message GUI");
ItemStack close = null;
ItemStack skull = null;
if(VersionHandler.is1_7_10()) {
close = new ItemStack(Material.BEDROCK);
}
else {
close = new ItemStack(Material.BARRIER);
}
if(VersionHandler.is1_7() || VersionHandler.is1_8() || VersionHandler.is1_9() || VersionHandler.is1_10() || VersionHandler.is1_11() || VersionHandler.is1_12()) {
skull = new ItemStack(Material.getMaterial("SKULL_ITEM"));
}
else {
skull = new ItemStack(Material.PLAYER_HEAD);
}
ItemMeta closeMeta = close.getItemMeta();
closeMeta.setDisplayName("§oClose GUI");
close.setItemMeta(closeMeta);
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
skullMeta.setOwner("Scarsz");
skullMeta.setDisplayName("§bDiscord_Message");
List<String> skullLore = new ArrayList<String>();
skullLore.add("§7Channel: " + ChatColor.valueOf(channel.getColor().toUpperCase()) + channel.getName());
skullLore.add("§7Hash: " + ChatColor.valueOf(channel.getColor().toUpperCase()) + hash);
skullMeta.setLore(skullLore);
skull.setItemMeta(skullMeta);
skull.setDurability((short) 3);
inv.setItem(0, skull);
for(GuiSlot g : MineverseChat.gsInfo.getGuiSlots()) {
if(!g.hasPermission() || mcp.getPlayer().hasPermission(g.getPermission())) {
if(this.checkSlot(g.getSlot())) {
MineverseChat.getInstance().getServer().getConsoleSender().sendMessage(Format.FormatStringAll("&cGUI: " + g.getName() + " has invalid slot: " + g.getSlot() + "!"));
continue;
}
ItemStack gStack = new ItemStack(g.getIcon());
gStack.setDurability((short) g.getDurability());
ItemMeta gMeta = gStack.getItemMeta();
String displayName = g.getText().replace("{player_name}", "Discord_Message").replace("{channel}", channel.getName()).replace("{hash}", hash + "");
gMeta.setDisplayName(Format.FormatStringAll(displayName));
List<String> gLore = new ArrayList<String>();
gMeta.setLore(gLore);
gStack.setItemMeta(gMeta);
inv.setItem(g.getSlot(), gStack);
}
}
inv.setItem(8, close);
mcp.getPlayer().openInventory(inv);
}
private boolean checkSlot(int slot) {
return slot == 0 || slot == 8;
}

View File

@ -240,7 +240,8 @@ public class CommandListener implements CommandExecutor, Listener {
}
e.setCancelled(true);
MineverseChatPlayer mcp = MineverseChatAPI.getOnlineMineverseChatPlayer((Player) e.getWhoClicked());
MineverseChatPlayer target = MineverseChatAPI.getMineverseChatPlayer(e.getView().getTitle().replace(" GUI", "").replace("VentureChat: ", ""));
String playerName = e.getView().getTitle().replace(" GUI", "").replace("VentureChat: ", "");
MineverseChatPlayer target = MineverseChatAPI.getMineverseChatPlayer(playerName);
ItemStack skull = e.getInventory().getItem(0);
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
ChatChannel channel = ChatChannel.getChannel(ChatColor.stripColor(skullMeta.getLore().get(0)).replace("Channel: ", ""));
@ -257,9 +258,15 @@ public class CommandListener implements CommandExecutor, Listener {
}
for(GuiSlot g : MineverseChat.gsInfo.getGuiSlots()) {
if(g.getIcon() == item.getType() && g.getDurability() == item.getDurability() && g.getSlot() == e.getSlot()) {
String command = g.getCommand().replace("{channel}", channel.getName()).replace("{hash}", hash + "").replace("{player_name}", target.getName());
if(target.isOnline()) {
command = PlaceholderAPI.setBracketPlaceholders(target.getPlayer(), command);
String command = g.getCommand().replace("{channel}", channel.getName()).replace("{hash}", hash + "");
if(target != null) {
command = command.replace("{player_name}", target.getName());
if(target.isOnline()) {
command = PlaceholderAPI.setBracketPlaceholders(target.getPlayer(), command);
}
}
else {
command = command.replace("{player_name}", "Discord_Message");
}
mcp.getPlayer().chat(command);
}

View File

@ -124,7 +124,7 @@ public class Format {
return temp;
}
public static String convertLinks(String s) {
private static String convertLinks(String s) {
String remaining = s;
String temp = "";
int indexLink = -1;
@ -170,11 +170,11 @@ public class Format {
return ts;
}
public static String convertToJsonColors(String s) {
private static String convertToJsonColors(String s) {
return convertToJsonColors(s, "");
}
public static String convertToJsonColors(String s, String extensions) {
private static String convertToJsonColors(String s, String extensions) {
String remaining = s;
String temp = "";
int indexColor = -1;
@ -286,6 +286,15 @@ public class Format {
return "";
}
public static String convertPlainTextToJson(String s, boolean convertURL) {
if(convertURL) {
return "[" + Format.convertLinks(s) + "]";
}
else {
return "[" + convertToJsonColors("§f" + s) + "]";
}
}
public static String formatModerationGUI(String json, Player player, String sender, String channelName, int hash) {
if(player.hasPermission("venturechat.gui")) {
json = json.substring(0, json.length() - 1);