3.8.0 Updates

This commit is contained in:
rockyhawk64 2020-08-09 17:50:43 +10:00
parent af47603a49
commit 86838e36bd
5 changed files with 51 additions and 15 deletions

View File

@ -1,4 +1,4 @@
version: 3.7.4
version: 3.8.0
main: me.rockyhawk.commandPanels.commandpanels
name: CommandPanels
author: RockyHawk

View File

@ -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) {

View File

@ -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);

View File

@ -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() {

View File

@ -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<String> 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<String> commandsAfterSequence = commands;
@ -108,7 +108,6 @@ public class utils implements Listener {
String locationOfSequence = commands.get(i).split("\\s")[1];
List<String> 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);
}
}