forked from Upstream/CommandPanels
v3.14.1.0
This commit is contained in:
parent
689a8cb0a6
commit
808b27ef8b
@ -29,8 +29,11 @@ config:
|
||||
notitem: '&cPlayer not found.'
|
||||
error: '&cError found in config at'
|
||||
needmoney: '&cInsufficient Funds!'
|
||||
needmoney-token: '&cInsufficient Funds!'
|
||||
needitems: '&cInsufficient Items!'
|
||||
bought: '&aSuccessfully Bought For $%cp-args%'
|
||||
bought-token: '&aSuccessfully Bought For %cp-args% Token/s'
|
||||
sold: '&aSuccessfully Sold Item!'
|
||||
sold-token: '&aSuccessfully Sold Item!'
|
||||
offline: 'Offline'
|
||||
offlineHeadValue: 'eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNmU1Mjg2YzQ3MGY2NmZmYTFhMTgzMzFjYmZmYjlhM2MyYTQ0MjRhOGM3MjU5YzQ0MzZmZDJlMzU1ODJhNTIyIn19fQ=='
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
version: 3.14.0.1
|
||||
version: 3.14.1.0
|
||||
main: me.rockyhawk.commandpanels.CommandPanels
|
||||
name: CommandPanels
|
||||
author: RockyHawk
|
||||
|
||||
@ -4,6 +4,7 @@ import java.io.*;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -190,6 +191,16 @@ public class CommandPanels extends JavaPlugin {
|
||||
//load panelFiles
|
||||
reloadPanelFiles();
|
||||
|
||||
//add custom charts bStats
|
||||
Metrics metrics = new Metrics(this);
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("panels_amount", new Callable<Integer>() {
|
||||
@Override
|
||||
public Integer call() throws Exception {
|
||||
//this is the total panels loaded
|
||||
return panelNames.size();
|
||||
}
|
||||
}));
|
||||
|
||||
//get tag
|
||||
tag = papi(config.getString("config.format.tag") + " ");
|
||||
|
||||
@ -352,6 +363,7 @@ 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()));
|
||||
str = str.replaceAll("%cp-tag%", papi(tag));
|
||||
//placeholder to check for server availability %cp-server-IP:PORT%
|
||||
while (str.contains("%cp-server-")) {
|
||||
int start = str.indexOf("%cp-server-");
|
||||
@ -360,12 +372,14 @@ public class CommandPanels extends JavaPlugin {
|
||||
Socket s = new Socket();
|
||||
try {
|
||||
s.connect(new InetSocketAddress(ip_port.split(":")[0], Integer.parseInt(ip_port.split(":")[1])), config.getInt("config.server-ping-timeout"));
|
||||
str = str.replace(str.substring(start, end) + "%", papi(p, "true"));
|
||||
str = str.replace(str.substring(start, end) + "%", "true");
|
||||
s.close();
|
||||
}catch (IOException ex){
|
||||
str = str.replace(str.substring(start, end) + "%", papi(p, "false"));
|
||||
str = str.replace(str.substring(start, end) + "%", "false");
|
||||
}
|
||||
}
|
||||
|
||||
//set custom placeholders to their values
|
||||
for(String[] placeholder : customCommand.getCCP(p.getName())){
|
||||
while (str.contains(placeholder[0])) {
|
||||
int start = str.indexOf(placeholder[0]);
|
||||
@ -374,14 +388,50 @@ public class CommandPanels extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
//get material value from slot in current open inventory (panel)
|
||||
while (str.contains("%cp-material-")) {
|
||||
try {
|
||||
int start = str.indexOf("%cp-material-");
|
||||
int end = str.indexOf("%", str.indexOf("%cp-material-") + 1);
|
||||
String matNumber = str.substring(start, end).replace("%cp-material-", "").replace("%", "");
|
||||
String material;
|
||||
try {
|
||||
material = p.getOpenInventory().getTopInventory().getItem(Integer.parseInt(matNumber)).getType().toString();
|
||||
} catch (NullPointerException er) {
|
||||
material = "AIR";
|
||||
}
|
||||
str = str.replace(str.substring(start, end) + "%", material);
|
||||
}catch(Exception ex){
|
||||
debug(ex);
|
||||
}
|
||||
}
|
||||
|
||||
//get stack amount from slot in current open inventory (panel)
|
||||
while (str.contains("%cp-stack-")) {
|
||||
try {
|
||||
int start = str.indexOf("%cp-stack-");
|
||||
int end = str.indexOf("%", str.indexOf("%cp-stack-") + 1);
|
||||
String matNumber = str.substring(start, end).replace("%cp-stack-", "").replace("%", "");
|
||||
int amount;
|
||||
try {
|
||||
amount = p.getOpenInventory().getTopInventory().getItem(Integer.parseInt(matNumber)).getAmount();
|
||||
} catch (NullPointerException er) {
|
||||
amount = 0;
|
||||
}
|
||||
str = str.replace(str.substring(start, end) + "%", String.valueOf(amount));
|
||||
}catch(Exception ex){
|
||||
debug(ex);
|
||||
}
|
||||
}
|
||||
|
||||
//does %cp-random-MIN,MAX%
|
||||
while (str.contains("%cp-random-")) {
|
||||
int start = str.indexOf("%cp-random-");
|
||||
int end = str.indexOf("%", str.indexOf("%cp-random-")+1);
|
||||
String min_max = str.substring(start, end).replace("%cp-random-", "").replace("%","");
|
||||
int end = str.indexOf("%", str.indexOf("%cp-random-") + 1);
|
||||
String min_max = str.substring(start, end).replace("%cp-random-", "").replace("%", "");
|
||||
int min = Integer.parseInt(min_max.split(",")[0]);
|
||||
int max = Integer.parseInt(min_max.split(",")[1]);
|
||||
str = str.replace(str.substring(start, end) + "%", String.valueOf(getRandomNumberInRange(min,max)));
|
||||
str = str.replace(str.substring(start, end) + "%", String.valueOf(getRandomNumberInRange(min, max)));
|
||||
}
|
||||
while (str.contains("%cp-player-online-")) {
|
||||
int start = str.indexOf("%cp-player-online-");
|
||||
@ -389,7 +439,7 @@ public class CommandPanels extends JavaPlugin {
|
||||
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) {
|
||||
str = str.replace(str.substring(start, end) + "-find%", papi(p,Objects.requireNonNull(config.getString("config.format.offline"))));
|
||||
str = str.replace(str.substring(start, end) + "-find%", papi(Objects.requireNonNull(config.getString("config.format.offline"))));
|
||||
} else {
|
||||
str = str.replace(str.substring(start, end) + "-find%", playerFind[Integer.parseInt(playerLocation) - 1].getName());
|
||||
}
|
||||
@ -421,7 +471,6 @@ public class CommandPanels extends JavaPlugin {
|
||||
List<String> inputMessages = new ArrayList<String>(config.getStringList("config.input-message"));
|
||||
for (String temp : inputMessages) {
|
||||
temp = temp.replaceAll("%cp-args%", Objects.requireNonNull(config.getString("config.input-cancel")));
|
||||
temp = temp.replaceAll("%cp-tag%", tag);
|
||||
p.sendMessage(papi(p, temp));
|
||||
}
|
||||
str = "commandpanels:commandpanelclose";
|
||||
|
||||
@ -26,8 +26,8 @@ public class Utils implements Listener {
|
||||
ConfigurationSection cf = plugin.openPanels.getOpenPanel(p.getName()); //this is the panel cf section
|
||||
|
||||
if(e.getClickedInventory().getType() == InventoryType.CHEST){
|
||||
e.setCancelled(true);
|
||||
p.updateInventory();
|
||||
//loop through possible hasvalue/hasperm 1,2,3,etc
|
||||
|
||||
//this loops through all the items in the panel
|
||||
boolean foundSlot = false;
|
||||
for(String slot : Objects.requireNonNull(cf.getConfigurationSection("item")).getKeys(false)){
|
||||
@ -36,10 +36,24 @@ public class Utils implements Listener {
|
||||
}
|
||||
}
|
||||
if(!foundSlot){
|
||||
e.setCancelled(true);
|
||||
p.updateInventory();
|
||||
return;
|
||||
}
|
||||
//loop through possible hasvalue/hasperm 1,2,3,etc
|
||||
|
||||
String section = plugin.itemCreate.hasSection(cf.getConfigurationSection("item." + e.getSlot()), p);
|
||||
|
||||
if(cf.contains("item." + e.getSlot() + section + ".itemType")){
|
||||
if(cf.getStringList("item." + e.getSlot() + section + ".itemType").contains("placeable")){
|
||||
//skip if the item is a placeable
|
||||
e.setCancelled(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
e.setCancelled(true);
|
||||
p.updateInventory();
|
||||
|
||||
//this will remove any pending user inputs, if there is already something there from a previous item
|
||||
for(int o = 0; plugin.userInputStrings.size() > o; o++){
|
||||
if(plugin.userInputStrings.get(o)[0].equals(p.getName())){
|
||||
@ -47,6 +61,7 @@ public class Utils implements Listener {
|
||||
o=o-1;
|
||||
}
|
||||
}
|
||||
|
||||
if(cf.contains("item." + e.getSlot() + section + ".commands")) {
|
||||
List<String> commands = cf.getStringList("item." + e.getSlot() + section + ".commands");
|
||||
if (commands.size() != 0) {
|
||||
@ -54,7 +69,7 @@ public class Utils implements Listener {
|
||||
List<String> commandsAfterSequence = commands;
|
||||
for (int i = 0; commands.size() - 1 >= i; i++) {
|
||||
if(commands.get(i).startsWith("sequence=")){
|
||||
String locationOfSequence = plugin.papiNoColour(p,commands.get(i).split("\\s")[1]);
|
||||
String locationOfSequence = commands.get(i).split("\\s")[1];
|
||||
List<String> commandsSequence = cf.getStringList(locationOfSequence);
|
||||
commandsAfterSequence.remove(i);
|
||||
commandsAfterSequence.addAll(i,commandsSequence);
|
||||
@ -99,18 +114,20 @@ public class Utils implements Listener {
|
||||
} catch (Exception click) {
|
||||
//skip if you can't do this
|
||||
}
|
||||
//start custom command placeholders
|
||||
try {
|
||||
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"));
|
||||
}
|
||||
//end custom PlaceHolders
|
||||
int val = plugin.commandTags.commandPayWall(p,commands.get(i));
|
||||
//end custom command PlaceHolders
|
||||
String command = plugin.papi(p,commands.get(i));
|
||||
int val = plugin.commandTags.commandPayWall(p,command);
|
||||
if(val == 0){
|
||||
return;
|
||||
}
|
||||
if(val == 2){
|
||||
plugin.commandTags.commandTags(p, commands.get(i));
|
||||
plugin.commandTags.commandTags(p, command, commands.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,10 +23,8 @@ public class CommandTags {
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void commandTags(Player p, String command) {
|
||||
public void commandTags(Player p, String command, String commandRAW) {
|
||||
//set cp placeholders, commandRAW is without placeholders
|
||||
String commandRAW = command;
|
||||
command = plugin.papi(p, command);
|
||||
if (command.split("\\s")[0].equalsIgnoreCase("server=")) {
|
||||
//this contacts bungee and tells it to send the server change command
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
@ -84,7 +82,7 @@ public class CommandTags {
|
||||
boolean isop = p.isOp();
|
||||
try {
|
||||
p.setOp(true);
|
||||
Bukkit.dispatchCommand(p,plugin.papi(p, command.replace("op=", "").trim()));
|
||||
Bukkit.dispatchCommand(p,command.replace("op=", "").trim());
|
||||
p.setOp(isop);
|
||||
} catch (Exception exc) {
|
||||
p.setOp(isop);
|
||||
@ -98,14 +96,14 @@ public class CommandTags {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
commandTags(p, finalCommand);
|
||||
commandTags(p, finalCommand, commandRAW);
|
||||
this.cancel();
|
||||
}
|
||||
}.runTaskTimer(plugin, 20*delaySeconds, 20); //20 ticks == 1 second
|
||||
} else if (command.split("\\s")[0].equalsIgnoreCase("console=")) {
|
||||
//if player uses console= it will perform command in the console
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), plugin.papi(p, command.replace("console=", "").trim()));
|
||||
} else if (command.split("\\s")[0].equalsIgnoreCase("buy=")) {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replace("console=", "").trim());
|
||||
}else if (command.split("\\s")[0].equalsIgnoreCase("buy=")) {
|
||||
//if player uses buy= it will be eg. buy= <price> <item> <amount of item> <ID>
|
||||
try {
|
||||
if (plugin.econ != null) {
|
||||
@ -150,8 +148,8 @@ public class CommandTags {
|
||||
if (balance >= Double.parseDouble(command.split("\\s")[1])) {
|
||||
api.removeTokens(p, Long.parseLong(command.split("\\s")[1]));
|
||||
//if the message is empty don't send
|
||||
if(!Objects.requireNonNull(plugin.config.getString("config.format.bought")).isEmpty()) {
|
||||
p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.bought")).replaceAll("%cp-args%", command.split("\\s")[1])));
|
||||
if(!Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).isEmpty()) {
|
||||
p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).replaceAll("%cp-args%", command.split("\\s")[1])));
|
||||
}
|
||||
//legacy ID
|
||||
byte id = 0;
|
||||
@ -169,7 +167,7 @@ public class CommandTags {
|
||||
Objects.requireNonNull(p.getLocation().getWorld()).dropItemNaturally(p.getLocation(), new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3]),id));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(plugin.papi( plugin.tag + plugin.config.getString("config.format.needmoney")));
|
||||
p.sendMessage(plugin.papi( plugin.tag + plugin.config.getString("config.format.needmoney-token")));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "Buying Requires TokenManager to work!"));
|
||||
@ -310,8 +308,8 @@ public class CommandTags {
|
||||
p.sendMessage(plugin.papi( plugin.tag + plugin.config.getString("config.format.needitems")));
|
||||
} else {
|
||||
//if the message is empty don't send
|
||||
if(!Objects.requireNonNull(plugin.config.getString("config.format.sold")).isEmpty()) {
|
||||
p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.sold")).replaceAll("%cp-args%", command.split("\\s")[1])));
|
||||
if(!Objects.requireNonNull(plugin.config.getString("config.format.sold-token")).isEmpty()) {
|
||||
p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.sold-token")).replaceAll("%cp-args%", command.split("\\s")[1])));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -323,7 +321,7 @@ public class CommandTags {
|
||||
}
|
||||
} else if (command.split("\\s")[0].equalsIgnoreCase("msg=")) {
|
||||
//if player uses msg= it will send the player a message
|
||||
p.sendMessage(plugin.papi(p, command.replace("msg=", "").trim()));
|
||||
p.sendMessage(command.replace("msg=", "").trim());
|
||||
} else if (command.split("\\s")[0].equalsIgnoreCase("sound=")) {
|
||||
//if player uses sound= it will play a sound (sound= [sound])
|
||||
try {
|
||||
@ -346,13 +344,13 @@ public class CommandTags {
|
||||
commandp = commandp.replace("tokenbuycommand=", "").trim();
|
||||
String price = commandp.split(" ", 2)[0];
|
||||
commandp = commandp.split(" ", 2)[1];
|
||||
commandTags(p,plugin.papi(p, commandp));
|
||||
commandTags(p,commandp,commandRAW);
|
||||
//if the message is empty don't send
|
||||
if(!Objects.requireNonNull(plugin.config.getString("config.format.bought")).isEmpty()) {
|
||||
p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.bought")).replaceAll("%cp-args%", price)));
|
||||
if(!Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).isEmpty()) {
|
||||
p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).replaceAll("%cp-args%", price)));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(plugin.papi( plugin.tag + plugin.config.getString("config.format.needmoney")));
|
||||
p.sendMessage(plugin.papi( plugin.tag + plugin.config.getString("config.format.needmoney-token")));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(plugin.papi( plugin.tag + ChatColor.RED + "Buying Requires Vault and an Economy to work!"));
|
||||
@ -372,7 +370,7 @@ public class CommandTags {
|
||||
commandp = commandp.replace("buycommand=", "").trim();
|
||||
String price = commandp.split(" ", 2)[0];
|
||||
commandp = commandp.split(" ", 2)[1];
|
||||
commandTags(p,plugin.papi(p, commandp));
|
||||
commandTags(p,commandp,commandRAW);
|
||||
//if the message is empty don't send
|
||||
if(!Objects.requireNonNull(plugin.config.getString("config.format.bought")).isEmpty()) {
|
||||
p.sendMessage(plugin.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("config.format.bought")).replaceAll("%cp-args%", price)));
|
||||
@ -391,25 +389,25 @@ public class CommandTags {
|
||||
//if player uses teleport= x y z (optional other player)
|
||||
if (command.split("\\s").length == 6) {
|
||||
float x, y, z, yaw, pitch; //pitch is the heads Y axis and yaw is the X axis
|
||||
x = Float.parseFloat(plugin.papi(p, command.split("\\s")[1]));
|
||||
y = Float.parseFloat(plugin.papi(p, command.split("\\s")[2]));
|
||||
z = Float.parseFloat(plugin.papi(p, command.split("\\s")[3]));
|
||||
yaw = Float.parseFloat(plugin.papi(p, command.split("\\s")[4]));
|
||||
pitch = Float.parseFloat(plugin.papi(p, command.split("\\s")[5]));
|
||||
x = Float.parseFloat(command.split("\\s")[1]);
|
||||
y = Float.parseFloat(command.split("\\s")[2]);
|
||||
z = Float.parseFloat(command.split("\\s")[3]);
|
||||
yaw = Float.parseFloat(command.split("\\s")[4]);
|
||||
pitch = Float.parseFloat(command.split("\\s")[5]);
|
||||
p.teleport(new Location(p.getWorld(), x, y, z, yaw, pitch));
|
||||
} else if (command.split("\\s").length <= 4) {
|
||||
float x, y, z;
|
||||
x = Float.parseFloat(plugin.papi(p, command.split("\\s")[1]));
|
||||
y = Float.parseFloat(plugin.papi(p, command.split("\\s")[2]));
|
||||
z = Float.parseFloat(plugin.papi(p, command.split("\\s")[3]));
|
||||
x = Float.parseFloat(command.split("\\s")[1]);
|
||||
y = Float.parseFloat(command.split("\\s")[2]);
|
||||
z = Float.parseFloat(command.split("\\s")[3]);
|
||||
p.teleport(new Location(p.getWorld(), x, y, z));
|
||||
} else {
|
||||
try {
|
||||
Player otherplayer = Bukkit.getPlayer(plugin.papi(p, command.split("\\s")[4]));
|
||||
Player otherplayer = Bukkit.getPlayer(command.split("\\s")[4]);
|
||||
float x, y, z;
|
||||
x = Float.parseFloat(plugin.papi(p, command.split("\\s")[1]));
|
||||
y = Float.parseFloat(plugin.papi(p, command.split("\\s")[2]));
|
||||
z = Float.parseFloat(plugin.papi(p, command.split("\\s")[3]));
|
||||
x = Float.parseFloat(command.split("\\s")[1]);
|
||||
y = Float.parseFloat(command.split("\\s")[2]);
|
||||
z = Float.parseFloat(command.split("\\s")[3]);
|
||||
assert otherplayer != null;
|
||||
otherplayer.teleport(new Location(otherplayer.getWorld(), x, y, z));
|
||||
} catch (Exception tpe) {
|
||||
@ -426,15 +424,15 @@ public class CommandTags {
|
||||
}
|
||||
} else if (command.split("\\s")[0].equalsIgnoreCase("sudo=")) {
|
||||
//if player uses sudo= [command]
|
||||
p.chat(plugin.papi(p, "/" + command.replaceAll("sudo=", "").trim()));
|
||||
p.chat( "/" + command.replaceAll("sudo=", "").trim());
|
||||
} else {
|
||||
Bukkit.dispatchCommand(p, plugin.papi(p, command));
|
||||
Bukkit.dispatchCommand(p, command);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public int commandPayWall(Player p, String command) { //return 0 means no funds, 1 is they passed and 2 means paywall is not this command
|
||||
String tag = plugin.config.getString("config.format.tag") + " ";
|
||||
command = plugin.papi(p,command);
|
||||
if (command.split("\\s")[0].equalsIgnoreCase("paywall=")) {
|
||||
//if player uses paywall= [price]
|
||||
try {
|
||||
@ -456,7 +454,7 @@ public class CommandTags {
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc);
|
||||
p.sendMessage(plugin.papi(p, tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
return 0;
|
||||
}
|
||||
} else if (command.split("\\s")[0].equalsIgnoreCase("tokenpaywall=")) {
|
||||
@ -469,12 +467,12 @@ public class CommandTags {
|
||||
if (balance >= Double.parseDouble(command.split("\\s")[1])) {
|
||||
api.removeTokens(p, Long.parseLong(command.split("\\s")[1]));
|
||||
//if the message is empty don't send
|
||||
if(!Objects.requireNonNull(plugin.config.getString("config.format.bought")).isEmpty()) {
|
||||
p.sendMessage(plugin.papi( tag + Objects.requireNonNull(plugin.config.getString("config.format.bought")).replaceAll("%cp-args%", command.split("\\s")[1])));
|
||||
if(!Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).isEmpty()) {
|
||||
p.sendMessage(plugin.papi( tag + Objects.requireNonNull(plugin.config.getString("config.format.bought-token")).replaceAll("%cp-args%", command.split("\\s")[1])));
|
||||
}
|
||||
return 1;
|
||||
} else {
|
||||
p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.needmoney")));
|
||||
p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.needmoney-token")));
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
@ -483,13 +481,13 @@ public class CommandTags {
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc);
|
||||
p.sendMessage(plugin.papi(p, tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
return 0;
|
||||
}
|
||||
}else if (command.split("\\s")[0].equalsIgnoreCase("item-paywall=")) {
|
||||
//if player uses item-paywall= [Material] [Amount]
|
||||
//if player uses item-paywall= [Material] [Amount] [Id]
|
||||
try {
|
||||
ItemStack sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[1])),Integer.parseInt(command.split("\\s")[2]));
|
||||
ItemStack sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[1])),Integer.parseInt(command.split("\\s")[2]), Short.parseShort(command.split("\\s")[3]));
|
||||
int sellItemAmount = sellItem.getAmount();
|
||||
sellItem.setAmount(1);
|
||||
int removedItem = 0;
|
||||
@ -522,7 +520,7 @@ public class CommandTags {
|
||||
return removedItem;
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc);
|
||||
p.sendMessage(plugin.papi(p, tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
return 0;
|
||||
}
|
||||
}else if (command.split("\\s")[0].equalsIgnoreCase("xp-paywall=")) {
|
||||
@ -542,7 +540,7 @@ public class CommandTags {
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc);
|
||||
p.sendMessage(plugin.papi(p, tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -65,7 +65,7 @@ public class ExecuteOpenVoids {
|
||||
break;
|
||||
}
|
||||
if(val == 2){
|
||||
plugin.commandTags.commandTags(p, commands.get(i));
|
||||
plugin.commandTags.commandTags(p, plugin.papi(p,commands.get(i)),commands.get(i));
|
||||
}
|
||||
}
|
||||
}catch(Exception s){
|
||||
|
||||
@ -405,8 +405,11 @@ public class ItemCreation {
|
||||
if(cont == null){
|
||||
//remove if items have been removed
|
||||
if(file.contains("panels." + panelName + ".item." + i)){
|
||||
file.set("panels." + panelName + ".item." + i, null);
|
||||
continue;
|
||||
//if the material doesn't equal air (don't delete air materials in the editor)
|
||||
if(!file.getString("panels." + panelName + ".item." + i + ".material").equalsIgnoreCase("AIR")) {
|
||||
file.set("panels." + panelName + ".item." + i, null);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(plugin.legacy.isLegacy()){
|
||||
|
||||
@ -1,14 +1,20 @@
|
||||
package me.rockyhawk.commandpanels.commands;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
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.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Commandpanelsreload implements CommandExecutor {
|
||||
CommandPanels plugin;
|
||||
@ -27,6 +33,9 @@ public class Commandpanelsreload implements CommandExecutor {
|
||||
//check for duplicates
|
||||
plugin.checkDuplicatePanel(sender);
|
||||
|
||||
//add custom commands
|
||||
registerCommands();
|
||||
|
||||
plugin.tag = plugin.papi(plugin.config.getString("config.format.tag") + " ");
|
||||
sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.reload")));
|
||||
}else{
|
||||
@ -37,4 +46,37 @@ public class Commandpanelsreload implements CommandExecutor {
|
||||
sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Usage: /cpr"));
|
||||
return true;
|
||||
}
|
||||
|
||||
//this will require a server restart for new commands
|
||||
public void registerCommands(){
|
||||
ConfigurationSection tempFile;
|
||||
File commandsLoc = new File("commands.yml");
|
||||
YamlConfiguration cmdCF = YamlConfiguration.loadConfiguration(commandsLoc);
|
||||
//remove old commandpanels commands
|
||||
for(String existingCommands : cmdCF.getConfigurationSection("aliases").getKeys(false)){
|
||||
if(cmdCF.getStringList("aliases." + existingCommands).get(0).equals("commandpanel")){
|
||||
cmdCF.set("aliases." + existingCommands,null);
|
||||
}
|
||||
}
|
||||
//make the command 'commandpanels' to identify it
|
||||
ArrayList<String> temp = new ArrayList<>();
|
||||
temp.add("commandpanel");
|
||||
|
||||
for (String[] panelName : plugin.panelNames) {
|
||||
tempFile = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(panelName[1])))).getConfigurationSection("panels." + panelName[0]);
|
||||
|
||||
if(tempFile.contains("commands")){
|
||||
List<String> panelCommands = tempFile.getStringList("commands");
|
||||
for(String command : panelCommands){
|
||||
cmdCF.set("aliases." + command.split("\\s")[0],temp);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
cmdCF.save(commandsLoc);
|
||||
} catch (IOException var10) {
|
||||
Bukkit.getConsoleSender().sendMessage("[CommandPanels]" + ChatColor.RED + " WARNING: Could not register custom commands!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -326,6 +326,7 @@ public class EditorUtils implements Listener {
|
||||
//this is put here to avoid conflicts, close panel if it is closed
|
||||
for(int i = 0; i < plugin.openPanels.openPanelsPN.size(); i++){
|
||||
if(plugin.openPanels.openPanelsPN.get(i)[0].equals(e.getPlayer().getName())){
|
||||
plugin.openPanels.panelCloseCommands(e.getPlayer().getName(),plugin.openPanels.openPanelsPN.get(i)[1]);
|
||||
plugin.customCommand.removeCCP(plugin.openPanels.openPanelsPN.get(i)[1], e.getPlayer().getName());
|
||||
if (plugin.config.contains("config.panel-snooper")) {
|
||||
if (Objects.requireNonNull(plugin.config.getString("config.panel-snooper")).trim().equalsIgnoreCase("true")) {
|
||||
|
||||
@ -35,7 +35,7 @@ public class CommandpanelUserInput implements Listener {
|
||||
e.setCancelled(true);
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
new CommandTags(plugin).commandTags(e.getPlayer(), command); //I have to do this to run regular Bukkit voids in an ASYNC Event
|
||||
new CommandTags(plugin).commandTags(e.getPlayer(), plugin.papi(e.getPlayer(),command), command); //I have to do this to run regular Bukkit voids in an ASYNC Event
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -58,6 +58,16 @@ public class OpenGUI {
|
||||
}
|
||||
}
|
||||
ItemStack s = plugin.itemCreate.makeItemFromConfig(Objects.requireNonNull(pconfig.getConfigurationSection("item." + item.split("\\s")[c] + section)), p, onOpen != 3, onOpen != 3);
|
||||
|
||||
//do itemType for placeable
|
||||
if(pconfig.contains("item." + item.split("\\s")[c] + section + ".itemType")) {
|
||||
if (pconfig.getStringList("item." + item.split("\\s")[c] + section + ".itemType").contains("placeable") && onOpen == 0) {
|
||||
//keep item the same, onOpen == 0 meaning panel is refreshing
|
||||
i.setItem(Integer.parseInt(item.split("\\s")[c]), p.getOpenInventory().getItem(Integer.parseInt(item.split("\\s")[c])));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
//place item into the GUI
|
||||
i.setItem(Integer.parseInt(item.split("\\s")[c]), s);
|
||||
@ -71,7 +81,7 @@ public class OpenGUI {
|
||||
int[] bothNumbers = new int[]{Integer.parseInt(tempDupe.split("-")[0]), Integer.parseInt(tempDupe.split("-")[1])};
|
||||
for(int n = bothNumbers[0]; n <= bothNumbers[1]; n++){
|
||||
try{
|
||||
if(i.getItem(n).getType() == Material.AIR){
|
||||
if(!pconfig.contains("item." + n)){
|
||||
i.setItem(n, s);
|
||||
}
|
||||
}catch(NullPointerException ignore){
|
||||
@ -81,7 +91,7 @@ public class OpenGUI {
|
||||
} else {
|
||||
//if there is only one dupe item
|
||||
try{
|
||||
if(i.getItem(Integer.parseInt(tempDupe)).getType() == Material.AIR){
|
||||
if(!pconfig.contains("item." + Integer.parseInt(tempDupe))){
|
||||
i.setItem(Integer.parseInt(tempDupe), s);
|
||||
}
|
||||
}catch(NullPointerException ignore){
|
||||
@ -142,7 +152,7 @@ public class OpenGUI {
|
||||
empty.setItemMeta(renamedMeta);
|
||||
if (onOpen != 3) {
|
||||
//only place empty items if not editing
|
||||
if(i.getItem(c) == null) {
|
||||
if(i.getItem(c) == null && !pconfig.contains("item." + c)) {
|
||||
i.setItem(c, empty);
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,6 +85,7 @@ public class OpenPanelsLoader {
|
||||
public void closePanelForLoader(String playerName, String panelName){
|
||||
for(int i = 0; i < openPanelsCF.size(); i++){
|
||||
if(Arrays.equals(openPanelsPN.get(i), new String[]{playerName, panelName})){
|
||||
panelCloseCommands(playerName,panelName);
|
||||
openPanelsCF.remove(i);
|
||||
openPanelsPN.remove(i);
|
||||
return;
|
||||
@ -96,4 +97,29 @@ public class OpenPanelsLoader {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void panelCloseCommands(String playerName, String panelName){
|
||||
for(int i = 0; i < openPanelsCF.size(); i++){
|
||||
if(Arrays.equals(openPanelsPN.get(i), new String[]{playerName, panelName})){
|
||||
if (openPanelsCF.get(i).contains("commands-on-close")) {
|
||||
//execute commands on panel close
|
||||
try {
|
||||
List<String> commands = openPanelsCF.get(i).getStringList("commands-on-close");
|
||||
for (String command : commands) {
|
||||
int val = plugin.commandTags.commandPayWall(Bukkit.getPlayer(openPanelsPN.get(i)[0]),command);
|
||||
if(val == 0){
|
||||
break;
|
||||
}
|
||||
if(val == 2){
|
||||
plugin.commandTags.commandTags(Bukkit.getPlayer(openPanelsPN.get(i)[0]), plugin.papi(Bukkit.getPlayer(openPanelsPN.get(i)[0]),command), command);
|
||||
}
|
||||
}
|
||||
}catch(Exception s){
|
||||
plugin.debug(s);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ public class UtilsPanelsLoader implements Listener {
|
||||
public void onPlayerClosePanel(PlayerQuitEvent e){
|
||||
for(int i = 0; i < plugin.openPanels.openPanelsPN.size(); i++){
|
||||
if(plugin.openPanels.openPanelsPN.get(i)[0].equals(e.getPlayer().getName())){
|
||||
plugin.openPanels.panelCloseCommands(e.getPlayer().getName(),plugin.openPanels.openPanelsPN.get(i)[1]);
|
||||
plugin.customCommand.removeCCP(plugin.openPanels.openPanelsPN.get(i)[1], e.getPlayer().getName());
|
||||
if (plugin.config.contains("config.panel-snooper")) {
|
||||
if (Objects.requireNonNull(plugin.config.getString("config.panel-snooper")).trim().equalsIgnoreCase("true")) {
|
||||
@ -33,7 +34,7 @@ public class UtilsPanelsLoader implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
//tell panel loader that player has closed the panel
|
||||
//tell panel loader that player has closed the panel (there is also one of these in EditorUtils)
|
||||
@EventHandler
|
||||
public void onPlayerClosePanel(InventoryCloseEvent e){
|
||||
//only do this if editor is disabled as it will disabled this code
|
||||
@ -41,6 +42,7 @@ public class UtilsPanelsLoader implements Listener {
|
||||
//this is put here to avoid conflicts, close panel if it is closed
|
||||
for (int i = 0; i < plugin.openPanels.openPanelsPN.size(); i++) {
|
||||
if (plugin.openPanels.openPanelsPN.get(i)[0].equals(e.getPlayer().getName())) {
|
||||
plugin.openPanels.panelCloseCommands(e.getPlayer().getName(),plugin.openPanels.openPanelsPN.get(i)[1]);
|
||||
plugin.customCommand.removeCCP(plugin.openPanels.openPanelsPN.get(i)[1], e.getPlayer().getName());
|
||||
if (plugin.config.contains("config.panel-snooper")) {
|
||||
if (Objects.requireNonNull(plugin.config.getString("config.panel-snooper")).trim().equalsIgnoreCase("true")) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user