From 86838e36bd861b8c310e04c635827f479b107d2d Mon Sep 17 00:00:00 2001 From: rockyhawk64 Date: Sun, 9 Aug 2020 17:50:43 +1000 Subject: [PATCH] 3.8.0 Updates --- resource/plugin.yml | 2 +- .../commandPanels/commandpanels.java | 20 +++++++++-- .../generatePanels/newGenUtils.java | 6 ++-- .../premium/commandpanelrefresher.java | 4 +-- src/me/rockyhawk/commandPanels/utils.java | 34 +++++++++++++++---- 5 files changed, 51 insertions(+), 15 deletions(-) diff --git a/resource/plugin.yml b/resource/plugin.yml index 4bd911b..9b2426c 100644 --- a/resource/plugin.yml +++ b/resource/plugin.yml @@ -1,4 +1,4 @@ -version: 3.7.4 +version: 3.8.0 main: me.rockyhawk.commandPanels.commandpanels name: CommandPanels author: RockyHawk diff --git a/src/me/rockyhawk/commandPanels/commandpanels.java b/src/me/rockyhawk/commandPanels/commandpanels.java index 96e1a7b..feab409 100644 --- a/src/me/rockyhawk/commandPanels/commandpanels.java +++ b/src/me/rockyhawk/commandPanels/commandpanels.java @@ -10,6 +10,8 @@ import com.mojang.authlib.properties.PropertyMap; import java.io.*; import java.lang.reflect.Field; import java.net.HttpURLConnection; +import java.net.InetSocketAddress; +import java.net.Socket; import java.net.URL; import java.util.*; import java.util.regex.Matcher; @@ -803,9 +805,23 @@ public class commandpanels extends JavaPlugin { str = str.replaceAll("%cp-player-y%", String.valueOf(Math.round(p.getLocation().getY()))); str = str.replaceAll("%cp-player-z%", String.valueOf(Math.round(p.getLocation().getZ()))); str = str.replaceAll("%cp-online-players%", Integer.toString(Bukkit.getServer().getOnlinePlayers().size())); - if (str.contains("%cp-player-online-")) { + //placeholder to check for server availability + while (str.contains("%cp-server-")) { + int start = str.indexOf("%cp-server-"); + int end = str.indexOf("%", str.indexOf("%cp-server-")+1); + String ip_port = str.substring(start, end).replace("%cp-server-", "").replace("%",""); + Socket s = new Socket(); + try { + s.connect(new InetSocketAddress(ip_port.split(":")[0], Integer.parseInt(ip_port.split(":")[1])), 10); + str = str.replace(str.substring(start, end) + "%", papi(p, "true")); + s.close(); + }catch (IOException ex){ + str = str.replace(str.substring(start, end) + "%", papi(p, "false")); + } + } + while (str.contains("%cp-player-online-")) { int start = str.indexOf("%cp-player-online-"); - int end = str.lastIndexOf("-find%"); + int end = str.indexOf("-find%",str.indexOf("%cp-player-online-")+1); String playerLocation = str.substring(start, end).replace("%cp-player-online-", ""); Player[] playerFind = Bukkit.getOnlinePlayers().toArray(new Player[Bukkit.getOnlinePlayers().size()]); if (Integer.parseInt(playerLocation) > playerFind.length) { diff --git a/src/me/rockyhawk/commandPanels/generatePanels/newGenUtils.java b/src/me/rockyhawk/commandPanels/generatePanels/newGenUtils.java index 62fcac8..ecd3b0f 100644 --- a/src/me/rockyhawk/commandPanels/generatePanels/newGenUtils.java +++ b/src/me/rockyhawk/commandPanels/generatePanels/newGenUtils.java @@ -32,18 +32,16 @@ public class newGenUtils implements Listener { } @EventHandler public void onInventoryClose(InventoryCloseEvent e) { - //reload panel files to avoid conflicts - plugin.reloadPanelFiles(); Player p = (Player)e.getPlayer(); if (!ChatColor.stripColor(e.getView().getTitle()).equals("Generate New Panel")){ return; } + //reload panel files to avoid conflicts + plugin.reloadPanelFiles(); generatePanel(p,e.getInventory()); } @EventHandler public void onPlayerQuit(PlayerQuitEvent e) { - //reload panel files to avoid conflicts - plugin.reloadPanelFiles(); Player p = e.getPlayer(); //if the player is in generate mode, remove generate mode this.plugin.generateMode.remove(p); diff --git a/src/me/rockyhawk/commandPanels/premium/commandpanelrefresher.java b/src/me/rockyhawk/commandPanels/premium/commandpanelrefresher.java index 56ba0f2..407245a 100644 --- a/src/me/rockyhawk/commandPanels/premium/commandpanelrefresher.java +++ b/src/me/rockyhawk/commandPanels/premium/commandpanelrefresher.java @@ -91,8 +91,8 @@ public class commandpanelrefresher implements Listener { final YamlConfiguration cfFinal = cf; final String fpanel = panel; final String fpanelTitle = panelTitle; - ItemStack panelItemList[] = plugin.openGui(fpanel, p, cf,2, -1).getContents(); - ItemStack playerItemList[] = p.getInventory().getStorageContents(); + ItemStack[] panelItemList = plugin.openGui(fpanel, p, cf,2, -1).getContents(); + ItemStack[] playerItemList = p.getInventory().getStorageContents(); new BukkitRunnable(){ @Override public void run() { diff --git a/src/me/rockyhawk/commandPanels/utils.java b/src/me/rockyhawk/commandPanels/utils.java index 7630a41..6965a30 100644 --- a/src/me/rockyhawk/commandPanels/utils.java +++ b/src/me/rockyhawk/commandPanels/utils.java @@ -97,9 +97,9 @@ public class utils implements Listener { o=o-1; } } + redirectPanel(p,cf,panel,section,e.getSlot()); if(cf.contains("panels." + panel + ".item." + e.getSlot() + section + ".commands")) { List commands = cf.getStringList("panels." + panel + ".item." + e.getSlot() + section + ".commands"); - assert commands != null; if (commands.size() != 0) { //this will replace a sequence tag command with the commands from the sequence List commandsAfterSequence = commands; @@ -108,7 +108,6 @@ public class utils implements Listener { String locationOfSequence = commands.get(i).split("\\s")[1]; List commandsSequence = cf.getStringList(locationOfSequence); commandsAfterSequence.remove(i); - assert commandsSequence != null; commandsAfterSequence.addAll(i,commandsSequence); } } @@ -148,14 +147,10 @@ public class utils implements Listener { if (!e.isLeftClick() && !e.isRightClick()) { continue; } - if (clicked == null) { - continue; - } } catch (Exception click) { //skip if you can't do this } try { - assert clicked != null; commands.set(i, commands.get(i).replaceAll("%cp-clicked%", clicked.getType().toString())); } catch (Exception mate) { commands.set(i, commands.get(i).replaceAll("%cp-clicked%", "Air")); @@ -175,6 +170,7 @@ public class utils implements Listener { //stop duplicate p.updateInventory(); } + @EventHandler public void onPlayerJoin(PlayerJoinEvent e){ Player p = e.getPlayer(); @@ -185,4 +181,30 @@ public class utils implements Listener { } } } + + public void redirectPanel(Player p, YamlConfiguration cf, String panel, String section, int slot){ + String tag = plugin.config.getString("config.format.tag") + " "; + if(!cf.contains("panels." + panel + ".item." + slot + section + ".redirect") || !cf.contains("panels." + panel + ".item." + slot + section + ".redirect.panel")) { + return; + } + String panelName = cf.getString("panels." + panel + ".item." + slot + section + ".redirect.panel"); + YamlConfiguration panelConfig = null; + for(String[] tempName : plugin.panelNames){ + if(tempName[0].equals(panelName)){ + panelConfig = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(tempName[1])))); + } + } + if(panelConfig == null){ + p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.nopanel"))); + return; + } + if(cf.contains("panels." + panel + ".item." + slot + section + ".redirect.force")){ + //this will force the panel open without consideration of permissions, world, etc + if(cf.getBoolean("panels." + panel + ".item." + slot + section + ".redirect.force")){ + plugin.openGui(panelName, p, panelConfig, 1, 0); + return; + } + } + plugin.openCommandPanel(p, p, panelName, panelConfig, false); + } }