diff --git a/.idea/libraries/PlaceholderAPI_2_10_8.xml b/.idea/libraries/PlaceholderAPI_2_10_9.xml
similarity index 68%
rename from .idea/libraries/PlaceholderAPI_2_10_8.xml
rename to .idea/libraries/PlaceholderAPI_2_10_9.xml
index 7d8b81d..065e41f 100644
--- a/.idea/libraries/PlaceholderAPI_2_10_8.xml
+++ b/.idea/libraries/PlaceholderAPI_2_10_9.xml
@@ -1,7 +1,7 @@
-
+
-
+
diff --git a/Command Panels.iml b/Command Panels.iml
index fd38f3c..c45f53a 100644
--- a/Command Panels.iml
+++ b/Command Panels.iml
@@ -11,7 +11,6 @@
-
@@ -19,5 +18,6 @@
+
\ No newline at end of file
diff --git a/resource/config.yml b/resource/config.yml
index ec090d4..82ddbab 100644
--- a/resource/config.yml
+++ b/resource/config.yml
@@ -7,13 +7,13 @@
# |------------------------------------------------------------------------
config:
refresh-panels: true
+ refresh-delay: 20
panel-blocks: true
ingame-editor: true
hotbar-items: true
custom-commands: true
auto-register-commands: false
auto-update-panels: false
- refresh-delay: 20
server-ping-timeout: 10
stop-sound: true
disabled-world-message: true
@@ -37,6 +37,13 @@ config:
hexcodes:
start_tag: '#'
end_tag: ''
+placeholders:
+ primary:
+ start: '%'
+ end: '%'
+ secondary:
+ start: '{'
+ end: '}'
updater:
auto-update: true
minor-updates-only: true
diff --git a/resource/plugin.yml b/resource/plugin.yml
index 2b545fc..dd54da3 100644
--- a/resource/plugin.yml
+++ b/resource/plugin.yml
@@ -1,4 +1,4 @@
-version: 3.15.7.1
+version: 3.16.0.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 7e65015..aee9fa7 100644
--- a/src/me/rockyhawk/commandpanels/CommandPanels.java
+++ b/src/me/rockyhawk/commandpanels/CommandPanels.java
@@ -287,7 +287,7 @@ public class CommandPanels extends JavaPlugin{
}else{
clore = lore;
}
- renamedMeta.setLore(clore);
+ renamedMeta.setLore(splitListWithEscape(clore));
}
renamed.setItemMeta(renamedMeta);
} catch (Exception ignored) {
@@ -456,6 +456,15 @@ public class CommandPanels extends JavaPlugin{
}
}
+ //split lists using \n escape character
+ public List splitListWithEscape(List list){
+ List output = new ArrayList<>();
+ for(String str : list){
+ output.addAll(Arrays.asList(str.split("\\\\n")));
+ }
+ return output;
+ }
+
public int getRandomNumberInRange(int min, int max) {
if (min >= max) {
diff --git a/src/me/rockyhawk/commandpanels/Utils.java b/src/me/rockyhawk/commandpanels/Utils.java
index 8a8435f..105af57 100644
--- a/src/me/rockyhawk/commandpanels/Utils.java
+++ b/src/me/rockyhawk/commandpanels/Utils.java
@@ -42,6 +42,11 @@ public class Utils implements Listener {
e.setCancelled(true);
}
if(e.getClickedInventory().getType() == InventoryType.PLAYER){
+ if(panel.getConfig().isSet("panelType")){
+ if(panel.getConfig().getStringList("panelType").contains("unmovable")){
+ e.setCancelled(true);
+ }
+ }
return;
}
diff --git a/src/me/rockyhawk/commandpanels/api/CommandPanelsAPI.java b/src/me/rockyhawk/commandpanels/api/CommandPanelsAPI.java
index 22a74ca..4252a16 100644
--- a/src/me/rockyhawk/commandpanels/api/CommandPanelsAPI.java
+++ b/src/me/rockyhawk/commandpanels/api/CommandPanelsAPI.java
@@ -65,9 +65,4 @@ public class CommandPanelsAPI {
public ItemStack makeItem(Player p, ConfigurationSection itemSection){
return plugin.itemCreate.makeCustomItemFromConfig(null,itemSection, p, true, true, false);
}
-
- //will return item slots of hotbar stationary items
- public Set getHotbarItems(){
- return plugin.hotbar.getStationaryItemSlots();
- }
}
\ No newline at end of file
diff --git a/src/me/rockyhawk/commandpanels/api/Panel.java b/src/me/rockyhawk/commandpanels/api/Panel.java
index 463a941..51f5f4d 100644
--- a/src/me/rockyhawk/commandpanels/api/Panel.java
+++ b/src/me/rockyhawk/commandpanels/api/Panel.java
@@ -10,6 +10,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
+import java.util.stream.Collectors;
public class Panel{
CommandPanels plugin = JavaPlugin.getPlugin(CommandPanels.class);
@@ -68,19 +69,28 @@ public class Panel{
}
public ItemStack getItem(Player p, int slot){
- ConfigurationSection itemSection = panelConfig.getConfigurationSection("item." + slot);
+ String section = plugin.itemCreate.hasSection(this,panelConfig.getConfigurationSection("item." + slot), p);
+ ConfigurationSection itemSection = panelConfig.getConfigurationSection("item." + slot + section);
return plugin.itemCreate.makeItemFromConfig(this,itemSection, p, true, true, false);
}
public ItemStack getCustomItem(Player p, String itemName){
- ConfigurationSection itemSection = panelConfig.getConfigurationSection("custom-item." + itemName);
+ String section = plugin.itemCreate.hasSection(this,panelConfig.getConfigurationSection("custom-item." + itemName), p);
+ ConfigurationSection itemSection = panelConfig.getConfigurationSection("custom-item." + itemName + section);
return plugin.itemCreate.makeCustomItemFromConfig(this,itemSection, p, true, true, false);
}
public ItemStack getHotbarItem(Player p){
- ConfigurationSection itemSection = panelConfig.getConfigurationSection("open-with-item");
- ItemStack s = plugin.itemCreate.makeItemFromConfig(this,itemSection, p, true, true, false);
- return plugin.nbt.setNBT(s,"CommandPanelsHotbar",panelName);
+ ItemStack s = plugin.itemCreate.makeItemFromConfig(this,getHotbarSection(p), p, true, true, false);
+ int slot = -1;
+ if(getHotbarSection(p).isSet("stationary")){
+ slot = getHotbarSection(p).getInt("stationary");
+ }
+ return plugin.nbt.setNBT(s,"CommandPanelsHotbar",panelName + ":" + slot);
+ }
+ public ConfigurationSection getHotbarSection(Player p){
+ String section = plugin.itemCreate.hasSection(this,panelConfig.getConfigurationSection("open-with-item"), p);
+ return panelConfig.getConfigurationSection("open-with-item" + section);
}
public boolean hasHotbarItem(){
diff --git a/src/me/rockyhawk/commandpanels/classresources/placeholders/CreateText.java b/src/me/rockyhawk/commandpanels/classresources/placeholders/CreateText.java
index add337d..cfa6aa5 100644
--- a/src/me/rockyhawk/commandpanels/classresources/placeholders/CreateText.java
+++ b/src/me/rockyhawk/commandpanels/classresources/placeholders/CreateText.java
@@ -41,13 +41,9 @@ public class CreateText {
try {
int tempInt = 0;
for (String temp : setpapi) {
- setpapi.set(tempInt, plugin.placeholders.setCpPlaceholders(panel, p, temp));
+ setpapi.set(tempInt, attachPlaceholders(panel, p, temp));
tempInt += 1;
}
- if (plugin.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) {
- OfflinePlayer offp = plugin.getServer().getOfflinePlayer(p.getUniqueId());
- setpapi = PlaceholderAPI.setPlaceholders(offp, setpapi);
- }
}catch(Exception ignore){
//this will be ignored as it is probably a null
return null;
@@ -61,13 +57,9 @@ public class CreateText {
if(placeholder) {
int tempInt = 0;
for (String temp : setpapi) {
- setpapi.set(tempInt, plugin.placeholders.setCpPlaceholders(panel, p, temp));
+ setpapi.set(tempInt, attachPlaceholders(panel, p, temp));
tempInt += 1;
}
- if (plugin.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) {
- OfflinePlayer offp = plugin.getServer().getOfflinePlayer(p.getUniqueId());
- setpapi = PlaceholderAPI.setPlaceholders(offp, setpapi);
- }
}
}catch(Exception ignore){
//this will be ignored as it is probably a null
@@ -98,11 +90,7 @@ public class CreateText {
//string papi with no colours
public String placeholdersNoColour(Panel panel, Player p, String setpapi) {
try {
- setpapi = plugin.placeholders.setCpPlaceholders(panel, p,setpapi);
- if (plugin.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) {
- OfflinePlayer offp = plugin.getServer().getOfflinePlayer(p.getUniqueId());
- setpapi = PlaceholderAPI.setPlaceholders(offp, setpapi);
- }
+ setpapi = attachPlaceholders(panel, p,setpapi);
return setpapi;
}catch(NullPointerException e){
return setpapi;
@@ -112,15 +100,22 @@ public class CreateText {
//regular string papi
public String placeholders(Panel panel, Player p, String setpapi) {
try {
- setpapi = plugin.placeholders.setCpPlaceholders(panel, p,setpapi);
- if (plugin.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) {
- OfflinePlayer offp = plugin.getServer().getOfflinePlayer(p.getUniqueId());
- setpapi = PlaceholderAPI.setPlaceholders(offp, setpapi);
- }
+ setpapi = attachPlaceholders(panel, p,setpapi);
setpapi = plugin.hex.translateHexColorCodes(ChatColor.translateAlternateColorCodes('&', setpapi));
return setpapi;
}catch(NullPointerException e){
return setpapi;
}
}
+
+ public String attachPlaceholders(Panel panel, Player p, String input){
+ //do all the placeholders in order to fill into text
+ input = plugin.placeholders.setPlaceholders(panel, p, input, false);
+ if (plugin.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) {
+ OfflinePlayer offp = plugin.getServer().getOfflinePlayer(p.getUniqueId());
+ input = PlaceholderAPI.setPlaceholders(offp, input);
+ }
+ input = plugin.placeholders.setPlaceholders(panel, p, input, true);
+ return input;
+ }
}
diff --git a/src/me/rockyhawk/commandpanels/classresources/placeholders/HexColours.java b/src/me/rockyhawk/commandpanels/classresources/placeholders/HexColours.java
index d27f207..eadfe39 100644
--- a/src/me/rockyhawk/commandpanels/classresources/placeholders/HexColours.java
+++ b/src/me/rockyhawk/commandpanels/classresources/placeholders/HexColours.java
@@ -20,7 +20,6 @@ public class HexColours {
//used to translate hex colours into ChatColors
private String doTranslation(String message, String startTag, String endTag) {
- //final Pattern hexPattern = Pattern.compile("#" + "([A-Fa-f0-9]{6})");
final Pattern hexPattern = Pattern.compile(startTag + "([A-Fa-f0-9]{6})" + endTag);
Matcher matcher = hexPattern.matcher(message);
StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
diff --git a/src/me/rockyhawk/commandpanels/classresources/placeholders/Placeholders.java b/src/me/rockyhawk/commandpanels/classresources/placeholders/Placeholders.java
index eae39b3..fcc88ad 100644
--- a/src/me/rockyhawk/commandpanels/classresources/placeholders/Placeholders.java
+++ b/src/me/rockyhawk/commandpanels/classresources/placeholders/Placeholders.java
@@ -23,17 +23,60 @@ public class Placeholders {
this.plugin = pl;
}
+ public String setPlaceholders(Panel panel, Player p, String str, boolean primary){
+ String[] HOLDERS = getPlaceholderEnds(panel,primary);
+ while (str.contains(HOLDERS[0] + "cp-")) {
+ try {
+ int start = str.indexOf(HOLDERS[0] + "cp-");
+ int end = str.indexOf(HOLDERS[1], str.indexOf(HOLDERS[0] + "cp-") + 1);
+ String identifier = str.substring(start, end).replace(HOLDERS[0] + "cp-", "").replace(HOLDERS[1], "");
+ String value;
+ try {
+ value = doCpPlaceholders(panel,p,identifier, str);
+ } catch (NullPointerException er) {
+ value = "";
+ }
+ str = str.replace(str.substring(start, end) + HOLDERS[1], value);
+ }catch(Exception ex){
+ plugin.debug(ex,p);
+ break;
+ }
+ }
+ return str;
+ }
+
+ //returns primary then secondary {[start,end],[start,end]}
+ public String[] getPlaceholderEnds(Panel panel, boolean primary){
+ List values = new ArrayList<>();
+ values.add(new String[]{plugin.config.getString("placeholders.primary.start"),plugin.config.getString("placeholders.primary.end")});
+ values.add(new String[]{plugin.config.getString("placeholders.secondary.start"),plugin.config.getString("placeholders.secondary.end")});
+ if(panel.getConfig().isSet("placeholders")){
+ if(panel.getConfig().isSet("placeholders.primary")){
+ values.set(0,new String[]{panel.getConfig().getString("placeholders.primary.start"),panel.getConfig().getString("placeholders.primary.end")});
+ }
+ if(panel.getConfig().isSet("placeholders.secondary")){
+ values.set(1,new String[]{panel.getConfig().getString("placeholders.secondary.start"),panel.getConfig().getString("placeholders.secondary.end")});
+ }
+ }
+ if(primary){
+ return values.get(0);
+ }else{
+ return values.get(1);
+ }
+ }
+
@SuppressWarnings("deprecation")
- public String setCpPlaceholders(Panel panel, Player p, String str){
+ private String doCpPlaceholders(Panel panel, Player p, String identifier, String string){
+
//do player input placeholder first
- if (str.contains("%cp-player-input%")) {
+ if (identifier.equals("player-input")) {
for (String[] key : plugin.userInputStrings) {
if (key[0].equals(p.getName())) {
- plugin.userInputStrings.add(new String[]{p.getName(), str});
+ plugin.userInputStrings.add(new String[]{p.getName(), string});
return "cpc";
}
}
- plugin.userInputStrings.add(new String[]{p.getName(), str});
+ plugin.userInputStrings.add(new String[]{p.getName(), string});
List inputMessages = new ArrayList(plugin.config.getStringList("config.input-message"));
for (String temp : inputMessages) {
temp = temp.replaceAll("%cp-args%", Objects.requireNonNull(plugin.config.getString("config.input-cancel")));
@@ -43,23 +86,39 @@ public class Placeholders {
}
//replace nodes with PlaceHolders
- str = str.replaceAll("%cp-player-displayname%", p.getDisplayName());
- str = str.replaceAll("%cp-player-name%", p.getName());
- str = str.replaceAll("%cp-player-world%", p.getWorld().getName());
- str = str.replaceAll("%cp-player-x%", String.valueOf(Math.round(p.getLocation().getX())));
- 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%", plugin.tex.colour(plugin.tag));
+ switch(identifier){
+ case("player-displayname"): {
+ return p.getDisplayName();
+ }
+ case("player-name"): {
+ return p.getName();
+ }
+ case("player-world"): {
+ return p.getWorld().getName();
+ }
+ case("player-x"): {
+ return String.valueOf(Math.round(p.getLocation().getX()));
+ }
+ case("player-y"): {
+ return String.valueOf(Math.round(p.getLocation().getY()));
+ }
+ case("player-z"): {
+ return String.valueOf(Math.round(p.getLocation().getZ()));
+ }
+ case("online-players"): {
+ return Integer.toString(Bukkit.getServer().getOnlinePlayers().size());
+ }
+ case("tag"): {
+ return plugin.tex.colour(plugin.tag);
+ }
+ }
//set custom placeholders to their values
if(panel != null) {
for (String placeholder : panel.placeholders.keys.keySet()) {
- while (str.contains(placeholder)) {
+ if(identifier.equals(placeholder)) {
try {
- int start = str.indexOf(placeholder);
- int end = start + placeholder.length() - 1;
- str = str.replace(str.substring(start, end) + "%", panel.placeholders.keys.get(placeholder));
+ return panel.placeholders.keys.get(placeholder);
} catch (Exception ex) {
plugin.debug(ex, p);
break;
@@ -69,103 +128,91 @@ public class Placeholders {
}
//placeholder to check for server availability %cp-server-IP:PORT%
- 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("%","");
+ if(identifier.startsWith("server-")) {
+ String ip_port = identifier.replace("server-", "");
Socket s = new Socket();
try {
s.connect(new InetSocketAddress(ip_port.split(":")[0], Integer.parseInt(ip_port.split(":")[1])), plugin.config.getInt("config.server-ping-timeout"));
- str = str.replace(str.substring(start, end) + "%", "true");
s.close();
+ return "true";
}catch (IOException ex){
- str = str.replace(str.substring(start, end) + "%", "false");
+ return "false";
}
}
//placeholder to check if an item has NBT %cp-nbt-slot:key%
- while (str.contains("%cp-nbt-")) {
+ if(identifier.startsWith("nbt-")) {
try {
- int start = str.indexOf("%cp-nbt-");
- int end = str.indexOf("%", str.indexOf("%cp-nbt-")+1);
- String slot_key = str.substring(start, end).replace("%cp-nbt-", "").replace("%","");
+ String slot_key = identifier.replace("nbt-", "");
String value;
value = plugin.nbt.getNBT(p.getOpenInventory().getTopInventory().getItem(Integer.parseInt(slot_key.split(":")[0])),slot_key.split(":")[1]);
if(value == null){
value = "empty";
}
- str = str.replace(str.substring(start, end) + "%", value);
+ return value;
}catch (Exception ex){
plugin.debug(ex,p);
- break;
+ return "";
}
}
//DO placeholders for detection of other items in a panel
//get material value from slot in current open inventory (panel)
- while (str.contains("%cp-material-")) {
+ if(identifier.startsWith("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 matNumber = identifier.replace("material-", "");
String material;
try {
material = p.getOpenInventory().getTopInventory().getItem(Integer.parseInt(matNumber)).getType().toString();
- if (plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
+ if (plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
//add the ID to the end if it is legacy (eg, material:id)
material = material + ":" + p.getOpenInventory().getTopInventory().getItem(Integer.parseInt(matNumber)).getType().getId();
}
} catch (NullPointerException er) {
material = "AIR";
}
- str = str.replace(str.substring(start, end) + "%", material);
+ return material;
} catch (Exception ex) {
plugin.debug(ex,p);
- break;
+ return "";
}
}
//get stack amount from slot in current open inventory (panel)
- while (str.contains("%cp-stack-")) {
+ if(identifier.startsWith("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("%", "");
+ String matNumber = identifier.replace("stack-", "");
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));
+ return String.valueOf(amount);
}catch(Exception ex){
plugin.debug(ex,p);
- break;
+ return "";
}
}
//get stack amount from slot in current open inventory (panel)
- while (str.contains("%cp-modeldata-")) {
+ if(identifier.startsWith("modeldata-")) {
try {
- int start = str.indexOf("%cp-modeldata-");
- int end = str.indexOf("%", str.indexOf("%cp-modeldata-") + 1);
- String matNumber = str.substring(start, end).replace("%cp-modeldata-", "").replace("%", "");
+ String matNumber = identifier.replace("modeldata-", "");
int modelData;
try {
modelData = p.getOpenInventory().getTopInventory().getItem(Integer.parseInt(matNumber)).getItemMeta().getCustomModelData();
} catch (NullPointerException er) {
modelData = 0;
}
- str = str.replace(str.substring(start, end) + "%", String.valueOf(modelData));
+ return String.valueOf(modelData);
}catch(Exception ex){
plugin.debug(ex,p);
- break;
+ return "";
}
}
//is an item damaged
- while (str.contains("%cp-damaged-")) {
+ if(identifier.startsWith("damaged-")) {
try {
- int start = str.indexOf("%cp-damaged-");
- int end = str.indexOf("%", str.indexOf("%cp-damaged-") + 1);
- String matNumber = str.substring(start, end).replace("%cp-damaged-", "").replace("%", "");
+ String matNumber = identifier.replace("damaged-", "");
boolean damaged = false;
ItemStack itm = p.getOpenInventory().getTopInventory().getItem(Integer.parseInt(matNumber));
try {
@@ -180,18 +227,16 @@ public class Placeholders {
} catch (NullPointerException er) {
damaged = false;
}
- str = str.replace(str.substring(start, end) + "%", String.valueOf(damaged));
+ return String.valueOf(damaged);
}catch(Exception ex){
plugin.debug(ex,p);
- break;
+ return "";
}
}
//is an item identical, uses custom-items (custom item, slot)
- while (str.contains("%cp-identical-")) {
+ if(identifier.startsWith("identical-")) {
try {
- int start = str.indexOf("%cp-identical-");
- int end = str.indexOf("%", str.indexOf("%cp-identical-") + 1);
- String matLocSlot = str.substring(start, end).replace("%cp-identical-", "").replace("%", "");
+ String matLocSlot = identifier.replace("identical-", "");
String matLoc = matLocSlot.split(",")[0];
int matSlot = Integer.parseInt(matLocSlot.split(",")[1]);
boolean isIdentical = false;
@@ -199,8 +244,7 @@ public class Placeholders {
if(itm == null){
//continue if material is null
- str = str.replace(str.substring(start, end) + "%", String.valueOf(false));
- continue;
+ return "false";
}
try {
@@ -224,96 +268,88 @@ public class Placeholders {
isIdentical = false;
}
- str = str.replace(str.substring(start, end) + "%", String.valueOf(isIdentical));
+ return String.valueOf(isIdentical);
}catch(Exception ex){
plugin.debug(ex,p);
- break;
+ return "";
}
}
//does %cp-random-MIN,MAX%
- while (str.contains("%cp-random-")) {
+ if(identifier.startsWith("random-")) {
try {
- 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("%", "");
+ String min_max = identifier.replace("random-", "");
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(plugin.getRandomNumberInRange(min, max)));
+ return String.valueOf(plugin.getRandomNumberInRange(min, max));
}catch (Exception ex){
plugin.debug(ex,p);
- break;
+ return "";
}
}
//returns value of stored data
- while (str.contains("%cp-data-")) {
+ if(identifier.startsWith("data-")) {
try {
- int start = str.indexOf("%cp-data-");
- int end = str.indexOf("%", str.indexOf("%cp-data-") + 1);
- String dataPoint = str.substring(start, end).replace("%cp-data-", "").replace("%", "");
+ String dataPoint = identifier.replace("data-", "");
//get data from other user
if(dataPoint.contains(",")){
String dataName = dataPoint.split(",")[0];
String playerName = dataPoint.split(",")[1];
- str = str.replace(str.substring(start, end) + "%", plugin.panelData.getUserData(Bukkit.getOfflinePlayer(playerName).getUniqueId(),dataName));
+ return plugin.panelData.getUserData(Bukkit.getOfflinePlayer(playerName).getUniqueId(),dataName);
}else{
- str = str.replace(str.substring(start, end) + "%", plugin.panelData.getUserData(p.getUniqueId(),dataPoint));
+ return plugin.panelData.getUserData(p.getUniqueId(),dataPoint);
}
}catch (Exception ex){
plugin.debug(ex,p);
- break;
+ return "";
}
}
//edits data via placeholder execution (will return empty output)
- while (str.contains("%cp-setdata-")) {
+ if(identifier.startsWith("setdata-")) {
try {
- int start = str.indexOf("%cp-setdata-");
- int end = str.indexOf("%", str.indexOf("%cp-setdata-") + 1);
- String point_value = str.substring(start, end).replace("%cp-setdata-", "").replace("%", "");
+ String point_value = identifier.replace("cp-setdata-", "");
String command = "set-data= " + point_value.split(",")[0] + " " + point_value.split(",")[1];
plugin.commandTags.runCommand(panel,p, command);
- str = str.replace(str.substring(start, end) + "%", "");
+ return "";
}catch (Exception ex){
plugin.debug(ex,p);
- break;
+ return "";
}
}
//math data via placeholder execution (will return empty output)
- while (str.contains("%cp-mathdata-")) {
+ if(identifier.startsWith("mathdata-")) {
try {
- int start = str.indexOf("%cp-mathdata-");
- int end = str.indexOf("%", str.indexOf("%cp-mathdata-") + 1);
- String point_value = str.substring(start, end).replace("%cp-mathdata-", "").replace("%", "");
+ String point_value = identifier.replace("mathdata-", "");
String command = "math-data= " + point_value.split(",")[0] + " " + point_value.split(",")[1];
plugin.commandTags.runCommand(panel,p,command);
- str = str.replace(str.substring(start, end) + "%", "");
+ return "";
}catch (Exception ex){
plugin.debug(ex,p);
- break;
+ return "";
}
}
//checks for players online
- while (str.contains("%cp-player-online-")) {
+ if(identifier.startsWith("player-online-")) {
try {
- int start = str.indexOf("%cp-player-online-");
- int end = str.indexOf("-find%", str.indexOf("%cp-player-online-") + 1);
- String playerLocation = str.substring(start, end).replace("%cp-player-online-", "");
+ String playerLocation = identifier.replace("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%", plugin.tex.colour(Objects.requireNonNull(plugin.config.getString("config.format.offline"))));
+ return plugin.tex.colour(Objects.requireNonNull(plugin.config.getString("config.format.offline")));
} else {
- str = str.replace(str.substring(start, end) + "-find%", playerFind[Integer.parseInt(playerLocation) - 1].getName());
+ return playerFind[Integer.parseInt(playerLocation) - 1].getName();
}
}catch (Exception ex){
plugin.debug(ex,p);
- break;
+ return "";
}
}
try {
if (plugin.econ != null) {
- str = str.replaceAll("%cp-player-balance%", String.valueOf(Math.round(plugin.econ.getBalance(p))));
+ if(identifier.equals("player-balance")) {
+ return String.valueOf(Math.round(plugin.econ.getBalance(p)));
+ }
}
} catch (Exception place) {
//skip
@@ -321,12 +357,16 @@ public class Placeholders {
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
assert api != null;
- str = str.replaceAll("%cp-tokenmanager-balance%", Long.toString(api.getTokens(p).orElse(0)));
+ if(identifier.equals("tokenmanager-balance")) {
+ return Long.toString(api.getTokens(p).orElse(0));
+ }
}
if (plugin.getServer().getPluginManager().isPluginEnabled("VotingPlugin")) {
- str = str.replaceAll("%cp-votingplugin-points%", String.valueOf(UserManager.getInstance().getVotingPluginUser(p).getPoints()));
+ if(identifier.equals("votingplugin-points")) {
+ return String.valueOf(UserManager.getInstance().getVotingPluginUser(p).getPoints());
+ }
}
//end nodes with PlaceHolders
- return str;
+ return "";
}
}
diff --git a/src/me/rockyhawk/commandpanels/commandtags/CommandTagEvent.java b/src/me/rockyhawk/commandpanels/commandtags/CommandTagEvent.java
index 277d8a8..9c1bad3 100644
--- a/src/me/rockyhawk/commandpanels/commandtags/CommandTagEvent.java
+++ b/src/me/rockyhawk/commandpanels/commandtags/CommandTagEvent.java
@@ -40,9 +40,10 @@ public class CommandTagEvent extends Event {
this.name = split[0].trim();
this.raw = split[1].trim().split("\\s");
if(doApiPlaceholders) {
- this.args = plugin.tex.placeholders(panel1, player, split[1].trim()).split("\\s");
+ this.args = plugin.tex.attachPlaceholders(panel1, player, split[1].trim()).split("\\s");
}else{
- this.args = ChatColor.translateAlternateColorCodes('&',plugin.placeholders.setCpPlaceholders(panel, p,split[1].trim())).split("\\s");
+ this.args = ChatColor.translateAlternateColorCodes('&',plugin.placeholders.setPlaceholders(panel, p,split[1].trim(),false)).split("\\s");
+ this.args = ChatColor.translateAlternateColorCodes('&',plugin.placeholders.setPlaceholders(panel, p,split[1].trim(),true)).split("\\s");
}
}
diff --git a/src/me/rockyhawk/commandpanels/customcommands/Commandpanelcustom.java b/src/me/rockyhawk/commandpanels/customcommands/Commandpanelcustom.java
index 6e56893..affb3bd 100644
--- a/src/me/rockyhawk/commandpanels/customcommands/Commandpanelcustom.java
+++ b/src/me/rockyhawk/commandpanels/customcommands/Commandpanelcustom.java
@@ -29,16 +29,18 @@ public class Commandpanelcustom implements Listener {
boolean correctCommand = true;
ArrayList placeholders = new ArrayList<>(); //should read placeholder,argument
- String[] args = cmd.split("\\s");
- String[] executedCommand = e.getMessage().replace("/", "").split("\\s"); //command split into args
- if(args.length != executedCommand.length){
+ String[] phEnds = plugin.placeholders.getPlaceholderEnds(panel,true); //start and end of placeholder
+ String[] command = cmd.split("\\s");
+ String[] message = e.getMessage().replace("/", "").split("\\s"); //command split into args
+
+ if(command.length != message.length){
continue;
}
for(int i = 0; i < cmd.split("\\s").length; i++){
- if(args[i].startsWith("%cp-")){
- placeholders.add(new String[]{args[i], executedCommand[i]});
- }else if(!args[i].equals(executedCommand[i])){
+ if(command[i].startsWith(phEnds[0])){
+ placeholders.add(new String[]{command[i].replace(phEnds[0],"").replace(phEnds[1],""), message[i]});
+ }else if(!command[i].equals(message[i])){
correctCommand = false;
}
}
diff --git a/src/me/rockyhawk/commandpanels/ingameeditor/EditorUserInput.java b/src/me/rockyhawk/commandpanels/ingameeditor/EditorUserInput.java
index 2ff5a43..b9a7a6b 100644
--- a/src/me/rockyhawk/commandpanels/ingameeditor/EditorUserInput.java
+++ b/src/me/rockyhawk/commandpanels/ingameeditor/EditorUserInput.java
@@ -2,7 +2,6 @@ package me.rockyhawk.commandpanels.ingameeditor;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
-import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
diff --git a/src/me/rockyhawk/commandpanels/ioclasses/nbt/NBT_1_13.java b/src/me/rockyhawk/commandpanels/ioclasses/nbt/NBT_1_13.java
index 93bfe44..d9f5a70 100644
--- a/src/me/rockyhawk/commandpanels/ioclasses/nbt/NBT_1_13.java
+++ b/src/me/rockyhawk/commandpanels/ioclasses/nbt/NBT_1_13.java
@@ -96,8 +96,7 @@ public final class NBT_1_13 {
classCache.put( "GameProfile", Class.forName( "com.mojang.authlib.GameProfile" ) );
classCache.put( "Property", Class.forName( "com.mojang.authlib.properties.Property" ) );
classCache.put( "PropertyMap", Class.forName( "com.mojang.authlib.properties.PropertyMap" ) );
- } catch ( ClassNotFoundException e ) {
- e.printStackTrace();
+ } catch ( ClassNotFoundException ignore ) {
}
NBTClasses = new HashMap< Class< ? >, Class< ? > >();
@@ -126,7 +125,6 @@ public final class NBT_1_13 {
NBTClasses.put( Class.forName( "[I" ), Class.forName( "net.minecraft.nbt.NBTTagIntArray" ) );
}
} catch ( ClassNotFoundException e ) {
- e.printStackTrace();
}
methodCache = new HashMap< String, Method >();
@@ -210,7 +208,6 @@ public final class NBT_1_13 {
methodCache.put( "loadNBTTagCompound", getNMSClass( "MojangsonParser" ).getMethod( "parse", String.class ) );
} catch( Exception e ) {
- e.printStackTrace();
}
try {
@@ -246,8 +243,7 @@ public final class NBT_1_13 {
if ( LOCAL_VERSION == MinecraftVersion.v1_11 || LOCAL_VERSION == MinecraftVersion.v1_12 ) {
constructorCache.put( getNMSClass( "ItemStack" ), getNMSClass( "ItemStack" ).getConstructor( getNMSClass( "NBTTagCompound" ) ) );
}
- } catch( Exception e ) {
- e.printStackTrace();
+ } catch( Exception ignore ) {
}
NBTTagFieldCache = new HashMap< Class< ? >, Field >();
@@ -274,8 +270,7 @@ public final class NBT_1_13 {
field.setAccessible( true );
}
}
- } catch( Exception e ) {
- e.printStackTrace();
+ } catch( Exception ignore ) {
}
try {
@@ -288,8 +283,7 @@ public final class NBT_1_13 {
}
NBTListData.setAccessible( true );
NBTCompoundMap.setAccessible( true );
- } catch( Exception e ) {
- e.printStackTrace();
+ } catch( Exception ignore ) {
}
}
@@ -309,7 +303,6 @@ public final class NBT_1_13 {
return NBTTagFieldCache.get( clazz ).get( object );
}
} catch ( Exception exception ) {
- exception.printStackTrace();
}
return null;
}
@@ -330,7 +323,6 @@ public final class NBT_1_13 {
try {
return Class.forName("net.minecraft.server." + VERSION + "." + name);
} catch (ClassNotFoundException e) {
- e.printStackTrace();
return null;
}
}
@@ -392,27 +384,23 @@ public final class NBT_1_13 {
Object textureProperty = getConstructor( getNMSClass( "Property" ) ).newInstance( "textures", new String( Base64.getEncoder().encode( String.format( "{textures:{SKIN:{\"url\":\"%s\"}}}", skinURL ).getBytes() ) ) );
getMethod( "put" ).invoke( propertyMap, "textures", textureProperty );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException e1 ) {
- e1.printStackTrace();
}
if ( methodCache.containsKey( "setProfile" ) ) {
try {
getMethod( "setProfile" ).invoke( headMeta, profile );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
- e.printStackTrace();
}
} else {
Field profileField = null;
try {
profileField = headMeta.getClass().getDeclaredField("profile");
} catch ( NoSuchFieldException | SecurityException e ) {
- e.printStackTrace();
}
profileField.setAccessible(true);
try {
profileField.set(headMeta, profile);
} catch (IllegalArgumentException | IllegalAccessException e) {
- e.printStackTrace();
}
}
head.setItemMeta(headMeta);
@@ -433,7 +421,6 @@ public final class NBT_1_13 {
try {
profileField = meta.getClass().getDeclaredField("profile");
} catch ( NoSuchFieldException | SecurityException e ) {
- e.printStackTrace();
throw new IllegalArgumentException( "Item is not a player skull!" );
}
profileField.setAccessible(true);
@@ -452,7 +439,6 @@ public final class NBT_1_13 {
}
return null;
} catch ( IllegalArgumentException | IllegalAccessException | SecurityException | InvocationTargetException e) {
- e.printStackTrace();
return null;
}
}
@@ -472,7 +458,6 @@ public final class NBT_1_13 {
try {
return getTag( getCompound( item ), keys );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
- e.printStackTrace();
return null;
}
}
@@ -496,7 +481,6 @@ public final class NBT_1_13 {
return tag;
} catch ( Exception exception ) {
- exception.printStackTrace();
return null;
}
}
@@ -525,7 +509,6 @@ public final class NBT_1_13 {
return getNBTTag( tag, keys );
} catch ( Exception exception ) {
- exception.printStackTrace();
return null;
}
}
@@ -567,7 +550,6 @@ public final class NBT_1_13 {
getMethod( "setTag" ).invoke( stack, tag );
return ( ItemStack ) getMethod( "asBukkitCopy" ).invoke( null, stack );
} catch ( Exception exception ) {
- exception.printStackTrace();
return null;
}
}
@@ -596,7 +578,6 @@ public final class NBT_1_13 {
}
return null;
} catch ( Exception exception ) {
- exception.printStackTrace();
return null;
}
}
@@ -616,7 +597,6 @@ public final class NBT_1_13 {
try {
return getTag( getCompound( entity ), keys );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
- e.printStackTrace();
return null;
}
}
@@ -635,7 +615,6 @@ public final class NBT_1_13 {
return tag;
} catch ( Exception exception ) {
- exception.printStackTrace();
return null;
}
}
@@ -663,7 +642,6 @@ public final class NBT_1_13 {
return getNBTTag( tag, keys );
} catch ( Exception exception ) {
- exception.printStackTrace();
return null;
}
}
@@ -698,7 +676,6 @@ public final class NBT_1_13 {
getMethod( "setEntityTag" ).invoke( NMSEntity, tag );
} catch ( Exception exception ) {
- exception.printStackTrace();
return;
}
}
@@ -718,7 +695,6 @@ public final class NBT_1_13 {
try {
return getTag( getCompound( block ), keys );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
- e.printStackTrace();
return null;
}
}
@@ -743,7 +719,6 @@ public final class NBT_1_13 {
return tag;
} catch( Exception exception ) {
- exception.printStackTrace();
return null;
}
}
@@ -777,7 +752,6 @@ public final class NBT_1_13 {
return getNBTTag( tag, keys );
} catch( Exception exception ) {
- exception.printStackTrace();
return null;
}
}
@@ -822,7 +796,6 @@ public final class NBT_1_13 {
getMethod( "setTileTag" ).invoke( tileEntity, tag );
}
} catch( Exception exception ) {
- exception.printStackTrace();
return;
}
}
@@ -852,7 +825,6 @@ public final class NBT_1_13 {
getMethod( "setGameProfile" ).invoke( tileEntity, profile );
} catch( Exception exception ) {
- exception.printStackTrace();
}
}
@@ -867,7 +839,6 @@ public final class NBT_1_13 {
try {
return getTag( ( ( NBTCompound ) object ).tag, keys );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
- e.printStackTrace();
return null;
}
} else {
@@ -896,14 +867,12 @@ public final class NBT_1_13 {
try {
return getNBTTag( ( ( NBTCompound ) object ).tag, keys );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
- e.printStackTrace();
return null;
}
} else if ( getNMSClass( "NBTTagCompound" ).isInstance( object ) ) {
try {
return getNBTTag( object, keys );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
- e.printStackTrace();
return null;
}
} else {
@@ -1109,8 +1078,7 @@ public final class NBT_1_13 {
return null;
}
- } catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
- e.printStackTrace();
+ } catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException ignore ) {
}
return null;
@@ -1148,7 +1116,6 @@ public final class NBT_1_13 {
return ( int ) getMethod( "size" ).invoke( nbtCompound.tag );
}
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
- e.printStackTrace();
return 0;
}
@@ -1179,8 +1146,7 @@ public final class NBT_1_13 {
} else if ( object instanceof NBTCompound ) {
try {
setTag( ( ( NBTCompound ) object ).tag, value, keys );
- } catch ( InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
- e.printStackTrace();
+ } catch ( InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ignore ) {
}
} else {
throw new IllegalArgumentException( "Object provided must be of type ItemStack, Entity, Block, or NBTCompound!" );
@@ -1210,7 +1176,6 @@ public final class NBT_1_13 {
try {
return new NBTCompound( getNMSClass( "NBTTagCompound" ).newInstance() );
} catch ( InstantiationException | IllegalAccessException e ) {
- e.printStackTrace();
return null;
}
}
@@ -1368,7 +1333,6 @@ public final class NBT_1_13 {
}
return tags;
} catch ( Exception e ) {
- e.printStackTrace();
return tags;
}
}
@@ -1386,8 +1350,7 @@ public final class NBT_1_13 {
public void set( Object value, Object... keys ) {
try {
new NBT_1_13().setTag( tag, value, keys );
- } catch ( Exception e ) {
- e.printStackTrace();
+ } catch ( Exception ignore ) {
}
}
@@ -1405,7 +1368,6 @@ public final class NBT_1_13 {
try {
return new NBTCompound( new NBT_1_13().getMethod( "loadNBTTagCompound" ).invoke( null, json ) );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
- e.printStackTrace();
return null;
}
}
diff --git a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenPanelsLoader.java b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenPanelsLoader.java
index c3e1f5d..add82d7 100644
--- a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenPanelsLoader.java
+++ b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenPanelsLoader.java
@@ -114,9 +114,7 @@ public class OpenPanelsLoader {
public boolean isNBTInjected(ItemStack itm){
if(itm != null){
- if (plugin.nbt.hasNBT(itm)) {
- return true;
- }
+ return plugin.nbt.hasNBT(itm);
}
return false;
}
diff --git a/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java b/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java
index 77ea6dc..62a868b 100644
--- a/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java
+++ b/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java
@@ -8,7 +8,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
-import java.util.Set;
+import java.util.UUID;
public class HotbarItemLoader {
CommandPanels plugin;
@@ -17,52 +17,45 @@ public class HotbarItemLoader {
}
//stationary slots 0-8 are the hotbar, using 9-35 for inside the inventory
- HashMap stationaryItems = new HashMap<>();
+ HashMap stationaryItems = new HashMap<>();
//will compile the ArrayList {slot 0-4, index of panelNames}
public void reloadHotbarSlots() {
stationaryItems.clear();
- for (Panel panel : plugin.panelList) {
- if(panel.getConfig().contains("open-with-item.stationary")){
- stationaryItems.put(panel.getConfig().getInt("open-with-item.stationary"), panel.copy());
- }
- }
//update hotbar items for all players when reloaded
for(Player p : Bukkit.getServer().getOnlinePlayers()){
plugin.hotbar.updateHotbarItems(p);
}
}
- public Set getStationaryItemSlots(){
- return stationaryItems.keySet();
- }
-
//return true if found
public boolean stationaryExecute(int slot, Player p, boolean openPanel){
- for(int temp : stationaryItems.keySet()){
- if(slot == temp){
- if(openPanel) {
- Panel panel = stationaryItems.get(temp);
- //only open panel automatically if there are no commands and player world is not disabled
- if(!p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))){
+ if(stationaryItems.get(p.getUniqueId()).list.containsKey(slot)){
+ if(openPanel) {
+ try {
+ if (!plugin.nbt.getNBT(p.getInventory().getItem(slot), "CommandPanelsHotbar").split(":")[1].equals(String.valueOf(slot))) {
return false;
}
- if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
- return false;
- }
- if(!itemCheckExecute(p.getInventory().getItem(slot),p,false,false)){
- return false;
- }
- if(panel.getConfig().contains("open-with-item.commands")){
- for(String command : panel.getConfig().getStringList("open-with-item.commands")){
- plugin.commandTags.runCommand(panel,p, command);
- }
- return true;
- }
- panel.open(p);
+ }catch(Exception ex){
+ return false;
}
- return true;
+ Panel panel = stationaryItems.get(p.getUniqueId()).getPanel(slot);
+ //only open panel automatically if there are no commands and player world is not disabled
+ if(!p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))){
+ return false;
+ }
+ if(!itemCheckExecute(p.getInventory().getItem(slot),p,false,false)){
+ return false;
+ }
+ if(panel.getConfig().contains("open-with-item.commands")){
+ for(String command : panel.getConfig().getStringList("open-with-item.commands")){
+ plugin.commandTags.runCommand(panel,p, command);
+ }
+ return true;
+ }
+ panel.open(p);
}
+ return true;
}
return false;
}
@@ -78,12 +71,14 @@ public class HotbarItemLoader {
}
for(Panel panel : plugin.panelList) {
if(stationaryOnly){
- if(!panel.getConfig().contains("open-with-item.stationary")){
- continue;
- }
+ try {
+ if (plugin.nbt.getNBT(invItem, "CommandPanelsHotbar").split(":")[1].equals("-1")) {
+ continue;
+ }
+ }catch(NullPointerException | IllegalArgumentException ignore){}
}
if(panel.hasHotbarItem()){
- if(plugin.nbt.getNBT(invItem,"CommandPanelsHotbar").equals(panel.getName())){
+ if(plugin.nbt.getNBT(invItem,"CommandPanelsHotbar").split(":")[0].equals(panel.getName())){
if(openPanel) {
//only open panel automatically if there are no commands and if world is not disabled
if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
@@ -121,6 +116,7 @@ public class HotbarItemLoader {
}
//remove any old hotbar items
+ stationaryItems.put(p.getUniqueId(),new HotbarPlayerManager());
for(int i = 0; i <= 35; i++){
try {
if (plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar") != null) {
@@ -136,8 +132,9 @@ public class HotbarItemLoader {
}
if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm")) && panel.hasHotbarItem()) {
ItemStack s = panel.getHotbarItem(p);
- if(panel.getConfig().contains("open-with-item.stationary")) {
- p.getInventory().setItem(panel.getConfig().getInt("open-with-item.stationary"),s);
+ if(panel.getHotbarSection(p).contains("stationary")) {
+ p.getInventory().setItem(panel.getHotbarSection(p).getInt("stationary"),s);
+ stationaryItems.get(p.getUniqueId()).addSlot(panel.getHotbarSection(p).getInt("stationary"),panel);
}
}
}
diff --git a/src/me/rockyhawk/commandpanels/openwithitem/HotbarPlayerManager.java b/src/me/rockyhawk/commandpanels/openwithitem/HotbarPlayerManager.java
new file mode 100644
index 0000000..d998f57
--- /dev/null
+++ b/src/me/rockyhawk/commandpanels/openwithitem/HotbarPlayerManager.java
@@ -0,0 +1,20 @@
+package me.rockyhawk.commandpanels.openwithitem;
+
+import me.rockyhawk.commandpanels.api.Panel;
+
+import java.util.HashMap;
+
+public class HotbarPlayerManager {
+ public HashMap list = new HashMap<>();
+
+ public HotbarPlayerManager(){
+ }
+
+ public void addSlot(int slot, Panel panel){
+ list.put(slot,panel);
+ }
+
+ public Panel getPanel(int slot){
+ return list.get(slot);
+ }
+}
diff --git a/src/me/rockyhawk/commandpanels/openwithitem/UtilsChestSortEvent.java b/src/me/rockyhawk/commandpanels/openwithitem/UtilsChestSortEvent.java
index ade9b49..36eef65 100644
--- a/src/me/rockyhawk/commandpanels/openwithitem/UtilsChestSortEvent.java
+++ b/src/me/rockyhawk/commandpanels/openwithitem/UtilsChestSortEvent.java
@@ -19,7 +19,7 @@ public class UtilsChestSortEvent implements Listener {
}
//If the ChestSort plugin triggers an event
if(e.getInventory().getType() == InventoryType.PLAYER){
- for(int slot : plugin.hotbar.getStationaryItemSlots()){
+ for(int slot : plugin.hotbar.stationaryItems.get(e.getPlayer().getUniqueId()).list.keySet()){
e.setUnmovable(slot);
}
}
diff --git a/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java b/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java
index ec960c3..57ebe0c 100644
--- a/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java
+++ b/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java
@@ -95,6 +95,10 @@ public class UtilsOpenWithItem implements Listener {
plugin.hotbar.updateHotbarItems(e.getPlayer());
}
@EventHandler
+ public void onPlayerQuit(PlayerQuitEvent e){
+ plugin.hotbar.stationaryItems.remove(e.getPlayer().getUniqueId());
+ }
+ @EventHandler
public void onPlayerDropItem(PlayerDropItemEvent e){
if(!plugin.openWithItem){
//if none of the panels have open-with-item