This commit is contained in:
jman13378 2023-07-06 23:10:35 -04:00
commit 48367ae177
31 changed files with 515 additions and 764 deletions

View File

@ -12,7 +12,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17 (2)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@ -1,25 +1,38 @@
![TitleLogo](https://i.imgur.com/YQMXkoi.png) ![TitleLogo](https://i.imgur.com/YQMXkoi.png)
### About <p align="center">
Minecraft Servers use GUIs for many tasks from lobbies to shops. Command Panels takes a simple approach to YAML scripting to create a powerful yet simple design. <a href="https://discord.gg/eUWBWh7"><img src="https://i.imgur.com/50KoZcJ.png" alt="Discord"></a>
If you don't feel like scripting, Command Panels is one of the few free plugins you will find that provides a powerful in-game editor. Almost every feature that is available when scripting is included in-game. <a href="https://commandpanels.net/wiki"><img src="https://i.imgur.com/kR6n5uw.png" alt="Wiki"></a>
<a href="https://commandpanels.net/editor"><img src="https://i.imgur.com/hg68XFc.png" alt="Editor"></a>
</p>
- Lightweight <img align="center" src="https://i.imgur.com/w8UaAP2.png" alt="Screenshot">
- PlaceholderAPI support
- Comes with a built in editor
- Unlimited GUIs
- Create complex panel systems
### Discord Support ## Partner
You can join the discord server for support [here](https://discord.gg/eUWBWh7). ReviveNode is a leading Minecraft hosting provider that offers affordable and high-quality server hosting solutions. Their focus on performance, reliability, and customer support makes them the perfect partner for CommandPanels.
This is the main and fastest way to receive support for the plugin.
### Wiki Page ![Partner](https://swagalan.dev/revive/partners/revivenode-logo.png)
You can find the CommandPanels Wiki page [here](https://rockyhawk99.gitbook.io/rockyhawk-wiki/commandpanels/wiki).
The wiki page contains all the features and how to use them.
### Bug Reports We have proudly partnered with [ReviveNode](http://billing.revivenode.com/aff.php?aff=379)!
Please report bugs, issues or request features [here](https://github.com/rockyhawk64/CommandPanels/issues). CommandPanels users have been offered 15% off on the first month by using the Promocode: **PANELS**
## About
Minecraft Servers use GUIs for many different tasks from lobbies to shops. Command Panels takes a simple approach to YAML scripting to create a powerful yet simple design. Use variables, data, placeholders and other powerful tools to fully customize your GUIs.
Command Panels treats the inventory as three different sections, you have the Top, Middle and Bottom. Which are the Chest, Player and Hotbar locations. You can have three GUIs running simultaneously, by simply choosing which location you want a panel to open!
Making a plugin? You can use Command Panels as a library to make your own GUIs for your plugins. It's as simple as making a panel, adding the panel YAML file to your plugin and adding one line of code to open the panel.
## Main Features
**Online Editor** Offers simple GUI creation, the layout and logic has been simplified for easier usage.
**Animations, Logic, Data** are some of the powerful YAML tools that can be used in your GUIs!
**Player Inventory** allows you to extend the GUI into the player's inventory area underneath, to make advanced menu experiences!
**Developer API** for easy GUI creation in your own plugins (using this as a dependency) or simply to interact with Command Panels.
### Spigot Page ### Spigot Page
You can find the spigot page for the plugin [here](https://www.spigotmc.org/resources/67788/). You can find the spigot page for the plugin [here](https://www.spigotmc.org/resources/67788/).

View File

@ -1,4 +1,4 @@
version: 3.18.6.2 version: 3.19.0.3
main: me.rockyhawk.commandpanels.CommandPanels main: me.rockyhawk.commandpanels.CommandPanels
name: CommandPanels name: CommandPanels
author: RockyHawk author: RockyHawk

View File

@ -20,13 +20,10 @@ import me.rockyhawk.commandpanels.completetabs.CpTabComplete;
import me.rockyhawk.commandpanels.customcommands.Commandpanelcustom; import me.rockyhawk.commandpanels.customcommands.Commandpanelcustom;
import me.rockyhawk.commandpanels.datamanager.DebugManager; import me.rockyhawk.commandpanels.datamanager.DebugManager;
import me.rockyhawk.commandpanels.datamanager.PanelDataLoader; import me.rockyhawk.commandpanels.datamanager.PanelDataLoader;
import me.rockyhawk.commandpanels.editor.*;
import me.rockyhawk.commandpanels.generatepanels.Commandpanelsgenerate; import me.rockyhawk.commandpanels.generatepanels.Commandpanelsgenerate;
import me.rockyhawk.commandpanels.generatepanels.GenUtils; import me.rockyhawk.commandpanels.generatepanels.GenUtils;
import me.rockyhawk.commandpanels.generatepanels.TabCompleteGenerate; import me.rockyhawk.commandpanels.generatepanels.TabCompleteGenerate;
import me.rockyhawk.commandpanels.editor.CPEventHandler;
import me.rockyhawk.commandpanels.editor.CommandPanelsEditorCommand;
import me.rockyhawk.commandpanels.editor.CommandPanelsEditorMain;
import me.rockyhawk.commandpanels.editor.CommandPanelsEditorTabComplete;
import me.rockyhawk.commandpanels.interactives.input.UserInputUtils; import me.rockyhawk.commandpanels.interactives.input.UserInputUtils;
import me.rockyhawk.commandpanels.interactives.Commandpanelrefresher; import me.rockyhawk.commandpanels.interactives.Commandpanelrefresher;
import me.rockyhawk.commandpanels.interactives.OpenOnJoin; import me.rockyhawk.commandpanels.interactives.OpenOnJoin;
@ -80,7 +77,7 @@ public class CommandPanels extends JavaPlugin{
public List<Panel> panelList = new ArrayList<>(); //contains all the panels that are included in the panels folder public List<Panel> panelList = new ArrayList<>(); //contains all the panels that are included in the panels folder
//get alternate classes //get alternate classes
public CommandPanelsEditorMain editorMain = new CommandPanelsEditorMain(this); public PanelDownloader downloader = new PanelDownloader(this);
public CommandTags commandTags = new CommandTags(this); public CommandTags commandTags = new CommandTags(this);
public PanelDataLoader panelData = new PanelDataLoader(this); public PanelDataLoader panelData = new PanelDataLoader(this);
@ -162,6 +159,8 @@ public class CommandPanels extends JavaPlugin{
Objects.requireNonNull(this.getCommand("commandpanelimport")).setExecutor(new CommandPanelImport(this)); Objects.requireNonNull(this.getCommand("commandpanelimport")).setExecutor(new CommandPanelImport(this));
Objects.requireNonNull(this.getCommand("commandpanelimport")).setTabCompleter(new ImportTabComplete(this)); Objects.requireNonNull(this.getCommand("commandpanelimport")).setTabCompleter(new ImportTabComplete(this));
Objects.requireNonNull(this.getCommand("commandpaneledit")).setExecutor(new CommandPanelsEditor(this));
Objects.requireNonNull(this.getCommand("commandpaneledit")).setTabCompleter(new EditorTabComplete(this));
Objects.requireNonNull(this.getCommand("commandpanelreload")).setExecutor(new Commandpanelsreload(this)); Objects.requireNonNull(this.getCommand("commandpanelreload")).setExecutor(new Commandpanelsreload(this));
Objects.requireNonNull(this.getCommand("commandpaneldebug")).setExecutor(new Commandpanelsdebug(this)); Objects.requireNonNull(this.getCommand("commandpaneldebug")).setExecutor(new Commandpanelsdebug(this));
@ -203,13 +202,6 @@ public class CommandPanels extends JavaPlugin{
this.getServer().getPluginManager().registerEvents(new UtilsOpenWithItem(this), this); this.getServer().getPluginManager().registerEvents(new UtilsOpenWithItem(this), this);
} }
//if ingame-editor set to false, don't load this
if(Objects.requireNonNull(config.getString("config.ingame-editor")).equalsIgnoreCase("true")){
this.getServer().getPluginManager().registerEvents(new CPEventHandler(this), this);
Objects.requireNonNull(this.getCommand("commandpaneledit")).setTabCompleter(new CommandPanelsEditorTabComplete(this));
Objects.requireNonNull(this.getCommand("commandpaneledit")).setExecutor(new CommandPanelsEditorCommand(this));
}
//if panel-blocks set to false, don't load this //if panel-blocks set to false, don't load this
if(Objects.requireNonNull(config.getString("config.panel-blocks")).equalsIgnoreCase("true")){ if(Objects.requireNonNull(config.getString("config.panel-blocks")).equalsIgnoreCase("true")){
Objects.requireNonNull(this.getCommand("commandpanelblock")).setExecutor(new Commandpanelblocks(this)); Objects.requireNonNull(this.getCommand("commandpanelblock")).setExecutor(new Commandpanelblocks(this));
@ -367,10 +359,10 @@ public class CommandPanels extends JavaPlugin{
} }
//names is a list of the titles for the Panels //names is a list of the titles for the Panels
Set<String> oset = new HashSet<String>(apanels); Set<String> oset = new HashSet<>(apanels);
if (oset.size() < apanels.size()) { if (oset.size() < apanels.size()) {
//there are duplicate panel names //there are duplicate panel names
ArrayList<String> opanelsTemp = new ArrayList<String>(); ArrayList<String> opanelsTemp = new ArrayList<>();
for(String tempName : apanels){ for(String tempName : apanels){
if(opanelsTemp.contains(tempName)){ if(opanelsTemp.contains(tempName)){
sender.sendMessage(tex.colour(tag) + ChatColor.RED + "Error duplicate panel name: " + tempName); sender.sendMessage(tex.colour(tag) + ChatColor.RED + "Error duplicate panel name: " + tempName);
@ -452,6 +444,9 @@ public class CommandPanels extends JavaPlugin{
p.sendMessage(ChatColor.GOLD + "/cpv latest " + ChatColor.WHITE + "Download the latest update upon server reload/restart."); p.sendMessage(ChatColor.GOLD + "/cpv latest " + ChatColor.WHITE + "Download the latest update upon server reload/restart.");
p.sendMessage(ChatColor.GOLD + "/cpv [version:cancel] " + ChatColor.WHITE + "Download an update upon server reload/restart."); p.sendMessage(ChatColor.GOLD + "/cpv [version:cancel] " + ChatColor.WHITE + "Download an update upon server reload/restart.");
} }
if (p.hasPermission("commandpanel.edit")) {
p.sendMessage(ChatColor.GOLD + "/cpe <panel file> " + ChatColor.WHITE + "Export panel to the Online Editor.");
}
if (p.hasPermission("commandpanel.import")) { if (p.hasPermission("commandpanel.import")) {
p.sendMessage(ChatColor.GOLD + "/cpi [file name] [URL] " + ChatColor.WHITE + "Downloads a panel from a raw link online."); p.sendMessage(ChatColor.GOLD + "/cpi [file name] [URL] " + ChatColor.WHITE + "Downloads a panel from a raw link online.");
} }
@ -473,9 +468,6 @@ public class CommandPanels extends JavaPlugin{
if (p.hasPermission("commandpanel.block.list")) { if (p.hasPermission("commandpanel.block.list")) {
p.sendMessage(ChatColor.GOLD + "/cpb list " + ChatColor.WHITE + "List blocks that will open panels."); p.sendMessage(ChatColor.GOLD + "/cpb list " + ChatColor.WHITE + "List blocks that will open panels.");
} }
if (p.hasPermission("commandpanel.edit")) {
p.sendMessage(ChatColor.GOLD + "/cpe <panel> " + ChatColor.WHITE + "Edit a panel with the Panel Editor.");
}
} }
public final Map<String, Color> colourCodes = new HashMap<String, Color>() {{ public final Map<String, Color> colourCodes = new HashMap<String, Color>() {{

View File

@ -86,16 +86,6 @@ public class Utils implements Listener {
//the panels proper position //the panels proper position
panel = plugin.openPanels.getOpenPanel(p.getName(),position); panel = plugin.openPanels.getOpenPanel(p.getName(),position);
//this will cancel click on editor open and then change the slot clicked
if(plugin.editorMain.settings.containsKey(p.getUniqueId())) {
if (plugin.editorMain.settings.get(p.getUniqueId()).hasEditorOpen && position == PanelPosition.Top) {
plugin.editorMain.settings.get(p.getUniqueId()).slotSelected = String.valueOf(e.getSlot());
plugin.editorMain.openGuiPage(plugin.editorMain.settings.get(p.getUniqueId()).menuOpen, p, PanelPosition.Middle);
e.setCancelled(true);
return;
}
}
//this loops through all the items in the panel //this loops through all the items in the panel
boolean foundSlot = false; boolean foundSlot = false;
for(String slot : Objects.requireNonNull(panel.getConfig().getConfigurationSection("item")).getKeys(false)){ for(String slot : Objects.requireNonNull(panel.getConfig().getConfigurationSection("item")).getKeys(false)){

View File

@ -4,6 +4,7 @@ import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.classresources.placeholders.PanelPlaceholders; import me.rockyhawk.commandpanels.classresources.placeholders.PanelPlaceholders;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelOpenType; import me.rockyhawk.commandpanels.openpanelsmanager.PanelOpenType;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition; import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -92,11 +93,17 @@ public class Panel{
} }
} }
ItemStack s = plugin.itemCreate.makeItemFromConfig(this,PanelPosition.Top,getHotbarSection(p), p, true, true, false); ItemStack s = plugin.itemCreate.makeItemFromConfig(this,PanelPosition.Top,getHotbarSection(p), p, true, true, false);
int slot = -1; String slot = "-1";
if(getHotbarSection(p).isSet("stationary")){ if(getHotbarSection(p).isSet("stationary")){
slot = getHotbarSection(p).getInt("stationary"); slot = getHotbarSection(p).getString("stationary");
} }
try {
//add NBT to item and return the ItemStack
return plugin.nbt.setNBT(s, "CommandPanelsHotbar", panelName + ":" + slot); return plugin.nbt.setNBT(s, "CommandPanelsHotbar", panelName + ":" + slot);
}catch(Exception e) {
//return air if null
return new ItemStack(Material.AIR);
}
} }
public ConfigurationSection getHotbarSection(Player p){ public ConfigurationSection getHotbarSection(Player p){
String section = plugin.has.hasSection(this,PanelPosition.Top,panelConfig.getConfigurationSection("open-with-item"), p); String section = plugin.has.hasSection(this,PanelPosition.Top,panelConfig.getConfigurationSection("open-with-item"), p);

View File

@ -9,9 +9,18 @@ import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.UUID; import java.util.UUID;
@ -21,6 +30,10 @@ public class GetCustomHeads {
this.plugin = pl; this.plugin = pl;
} }
//contains cached player name and then base64 value (clears on /cpr reload)
//also will clear if the map reaches a length of 1000 which is roughly 135 KB RAM usage
public HashMap<String, String> playerHeadTextures = new HashMap<>();
public String getHeadBase64(ItemStack head) { public String getHeadBase64(ItemStack head) {
if (plugin.getHeads.ifSkullOrHead(head.getType().toString()) && head.hasItemMeta()) { if (plugin.getHeads.ifSkullOrHead(head.getType().toString()) && head.hasItemMeta()) {
try { try {
@ -41,20 +54,54 @@ public class GetCustomHeads {
return null; return null;
} }
//getting the head from a Player //getting the head from a Player Name
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public ItemStack getPlayerHead(String name) { public ItemStack getPlayerHead(String name) {
byte id = 0; byte id = 0;
if (plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) { if (plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
id = 3; id = 3;
} }
//get texture if already cached
if(playerHeadTextures.containsKey(name)) {
return getCustomHead(playerHeadTextures.get(name));
}
try {
// Fetch the player UUID from the Mojang API
URL uuidUrl = new URL("https://api.mojang.com/users/profiles/minecraft/" + name);
URLConnection uuidConnection = uuidUrl.openConnection();
uuidConnection.setConnectTimeout(2000); // Set connection timeout to 2 seconds
uuidConnection.setReadTimeout(2000); // Set read timeout to 2 seconds
Reader uuidReader = new InputStreamReader(uuidConnection.getInputStream(), StandardCharsets.UTF_8);
JSONObject uuidResponse = (JSONObject) new JSONParser().parse(uuidReader);
String uuid = (String) uuidResponse.get("id");
// Fetch the skin texture from the Mojang API using the player UUID
URL texturesUrl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid);
URLConnection texturesConnection = texturesUrl.openConnection();
texturesConnection.setConnectTimeout(2000); // Set connection timeout to 2 seconds
texturesConnection.setReadTimeout(2000); // Set read timeout to 2 seconds
Reader texturesReader = new InputStreamReader(texturesConnection.getInputStream(), StandardCharsets.UTF_8);
JSONObject texturesResponse = (JSONObject) new JSONParser().parse(texturesReader);
JSONArray propertiesArray = (JSONArray) texturesResponse.get("properties");
JSONObject texturesProperty = (JSONObject) propertiesArray.get(0);
String base64Texture = (String) texturesProperty.get("value");
playerHeadTextures.put(name, base64Texture);
// Create a custom head using the Base64 texture string
return getCustomHead(base64Texture);
} catch (Exception e) {
// Fallback to setting the owner if the Mojang API request fails
ItemStack itemStack = new ItemStack(Material.matchMaterial(plugin.getHeads.playerHeadString()), 1, id); ItemStack itemStack = new ItemStack(Material.matchMaterial(plugin.getHeads.playerHeadString()), 1, id);
SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); SkullMeta meta = (SkullMeta) itemStack.getItemMeta();
meta.setOwner(name); meta.setOwner(name);
itemStack.setItemMeta(meta); itemStack.setItemMeta(meta);
return itemStack; return itemStack;
} }
}
//used to get heads from Base64 Textures
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public ItemStack getCustomHead(String b64stringtexture) { public ItemStack getCustomHead(String b64stringtexture) {
//get head from base64 //get head from base64

View File

@ -201,65 +201,21 @@ public class ItemCreation {
if(addNBT){ if(addNBT){
s = plugin.nbt.setNBT(s); s = plugin.nbt.setNBT(s);
} }
if (itemSection.contains("map")) {
/*
This will do maps from custom images
the maps will be in the 'maps' folder, so
CommandPanels/maps/image.png <-- here
CommandPanels/panels/example_top.yml
The images should be 128x128
*/
try{
@SuppressWarnings("deprecation")
MapView map = Bukkit.getServer().getMap(0);
try {
map.getRenderers().clear();
map.setCenterX(30000000);
map.setCenterZ(30000000);
}catch(NullPointerException ignore){
//ignore catch
}
if(new File(plugin.getDataFolder().getPath() + File.separator + "maps" + File.separator + itemSection.getString("map")).exists()) {
map.addRenderer(new MapRenderer() {
public void render(MapView view, MapCanvas canvas, Player player) {
canvas.drawImage(0, 0, new ImageIcon(plugin.getDataFolder().getPath() + File.separator + "maps" + File.separator + itemSection.getString("map")).getImage());
}
});
MapMeta meta = (MapMeta) s.getItemMeta();
meta.setMapView(map);
s.setItemMeta(meta);
}else{
p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " map: File not found."));
}
}catch(Exception map){
p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " map: " + itemSection.getString("map")));
plugin.debug(map,p);
}
}
if (itemSection.contains("enchanted")) { if (itemSection.contains("enchanted")) {
try { try {
ItemMeta EnchantMeta; ItemMeta EnchantMeta;
if(itemSection.isList("enchanted")){ if(itemSection.isList("enchanted")){
//if there is a list of enchantments to add //if list contains true, hide enchanted and add KNOCKBACK
EnchantMeta = s.getItemMeta(); EnchantMeta = s.getItemMeta();
assert EnchantMeta != null; assert EnchantMeta != null;
for(String enchantment : itemSection.getStringList("enchanted")){ for(String enchantment : itemSection.getStringList("enchanted")){
EnchantMeta.addEnchant(Objects.requireNonNull(EnchantmentWrapper.getByKey(NamespacedKey.minecraft(enchantment.split("\\s")[0].toLowerCase()))), Integer.parseInt(enchantment.split("\\s")[1]), true); if(enchantment.equalsIgnoreCase("true")) {
}
s.setItemMeta(EnchantMeta);
}else if (Objects.requireNonNull(itemSection.getString("enchanted")).trim().equalsIgnoreCase("true")) {
//is used if enchanted is set to true
EnchantMeta = s.getItemMeta();
assert EnchantMeta != null;
EnchantMeta.addEnchant(Enchantment.KNOCKBACK, 1, false); EnchantMeta.addEnchant(Enchantment.KNOCKBACK, 1, false);
EnchantMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); EnchantMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
s.setItemMeta(EnchantMeta); continue;
} else if (!Objects.requireNonNull(itemSection.getString("enchanted")).trim().equalsIgnoreCase("false")) { }
//if used to ensure enchanted does not equal false but equals something else EnchantMeta.addEnchant(Objects.requireNonNull(EnchantmentWrapper.getByKey(NamespacedKey.minecraft(enchantment.split("\\s")[0].toLowerCase()))), Integer.parseInt(enchantment.split("\\s")[1]), true);
EnchantMeta = s.getItemMeta(); }
assert EnchantMeta != null;
EnchantMeta.addEnchant(Objects.requireNonNull(EnchantmentWrapper.getByKey(NamespacedKey.minecraft(Objects.requireNonNull(itemSection.getString("enchanted")).split("\\s")[0].toLowerCase()))), Integer.parseInt(Objects.requireNonNull(itemSection.getString("enchanted")).split("\\s")[1]), true);
s.setItemMeta(EnchantMeta); s.setItemMeta(EnchantMeta);
} }
} catch (Exception ench) { } catch (Exception ench) {

View File

@ -8,13 +8,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
public class CommandPanelImport implements CommandExecutor { public class CommandPanelImport implements CommandExecutor {
CommandPanels plugin; CommandPanels plugin;
public CommandPanelImport(CommandPanels pl) { this.plugin = pl; } public CommandPanelImport(CommandPanels pl) { this.plugin = pl; }
@ -27,8 +20,9 @@ public class CommandPanelImport implements CommandExecutor {
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
downloadPanel(sender,args[1],args[0]); plugin.downloader.downloadPanel(sender,args[1],args[0]);
plugin.reloadPanelFiles(); plugin.reloadPanelFiles();
plugin.hotbar.reloadHotbarSlots();
} }
}.run(); }.run();
return true; return true;
@ -39,48 +33,4 @@ public class CommandPanelImport implements CommandExecutor {
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpi <file name> <url>")); sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpi <file name> <url>"));
return true; return true;
} }
private void downloadPanel(CommandSender sender, String url, String fileName) {
BufferedInputStream in = null;
FileOutputStream fout = null;
//add extension if not already added
if(!fileName.endsWith(".yml") && !fileName.endsWith(".yaml")) {
fileName = fileName + ".yml";
}
//download panel from page contents and add to plugin
try {
URL fileUrl = new URL(url);
in = new BufferedInputStream(fileUrl.openStream());
fout = new FileOutputStream(new File(plugin.panelsf, fileName));
byte[] data = new byte[1024];
int count;
while((count = in.read(data, 0, 1024)) != -1) {
fout.write(data, 0, count);
}
sender.sendMessage(plugin.tag + ChatColor.GREEN + "Finished downloading.");
} catch (Exception var22) {
sender.sendMessage(plugin.tag + ChatColor.RED + "Could not download panel.");
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException var21) {
this.plugin.getLogger().log(Level.SEVERE, null, var21);
}
try {
if (fout != null) {
fout.close();
}
} catch (IOException var20) {
this.plugin.getLogger().log(Level.SEVERE, null, var20);
}
}
}
} }

View File

@ -44,7 +44,6 @@ public class Commandpanel implements CommandExecutor {
} }
} }
//below will start the command, once it got the right file and panel //below will start the command, once it got the right file and panel
if (cmd.getName().equalsIgnoreCase("cp") || cmd.getName().equalsIgnoreCase("commandpanel") || cmd.getName().equalsIgnoreCase("cpanel")) {
if(!(sender instanceof Player)) { if(!(sender instanceof Player)) {
//do console command //do console command
if(args.length == 2){ if(args.length == 2){
@ -88,7 +87,6 @@ public class Commandpanel implements CommandExecutor {
return true; return true;
} }
} }
}
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp <panel> [player:item] [player]")); sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp <panel> [player:item] [player]"));
return true; return true;
} }

View File

@ -51,6 +51,9 @@ public class Commandpanelsreload implements CommandExecutor {
registerCommands(); registerCommands();
} }
//clear cached head textures
plugin.customHeads.playerHeadTextures.clear();
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.reload"))); sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.reload")));
}else{ }else{
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms"))); sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms")));

View File

@ -200,22 +200,35 @@ public class CommandTags {
} }
} }
case "item-paywall=": { case "item-paywall=": {
//if player uses item-paywall= [Material] [Amount] [Id] //if player uses item-paywall= [Material] [Amount] <id:#> <custom-data:#>
//player can use item-paywall= [custom-item] //player can use item-paywall= [custom-item] [Amount]
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p))); List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p)));
List<ItemStack> remCont = new ArrayList<>(); List<ItemStack> remCont = new ArrayList<>();
String[] args = command.split("\\s");
try { try {
short id = 0; byte id = -1;
if (command.split("\\s").length == 4) { int customData = 0;
id = Short.parseShort(command.split("\\s")[3]); boolean noCustom = false;
for(String val : args) {
if(val.startsWith("id:")) {
id = Byte.parseByte(val.substring(3));
continue;
}
if(val.startsWith("custom-data:")) {
customData = Integer.parseInt(val.substring(12));
}
if(val.contains("NOCUSTOMDATA")) {
noCustom = true;
}
} }
//create the item to be removed //create the item to be removed
ItemStack sellItem; ItemStack sellItem;
if (Material.matchMaterial(command.split("\\s")[1]) == null) { if (Material.matchMaterial(args[1]) == null) {
sellItem = plugin.itemCreate.makeCustomItemFromConfig(panel, PanelPosition.Top, panel.getConfig().getConfigurationSection("custom-item." + command.split("\\s")[1]), p, true, true, false); sellItem = plugin.itemCreate.makeCustomItemFromConfig(panel, PanelPosition.Top, panel.getConfig().getConfigurationSection("custom-item." + args[1]), p, true, true, false);
sellItem.setAmount(Integer.parseInt(args[2]));
} else { } else {
sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[1])), Integer.parseInt(command.split("\\s")[2]), id); sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2]));
} }
//this is not a boolean because it needs to return an int //this is not a boolean because it needs to return an int
PaywallOutput removedItem = PaywallOutput.Blocked; PaywallOutput removedItem = PaywallOutput.Blocked;
@ -229,9 +242,11 @@ public class CommandTags {
continue; continue;
} }
if (Material.matchMaterial(command.split("\\s")[1]) == null) { ItemStack itm = cont.get(f);
if (Material.matchMaterial(args[1]) == null) {
//item-paywall is a custom item as it is not a material //item-paywall is a custom item as it is not a material
if (plugin.itemCreate.isIdentical(sellItem, cont.get(f))) { if (plugin.itemCreate.isIdentical(sellItem, itm)) {
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f); ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f);
remainingAmount -= add.getAmount(); remainingAmount -= add.getAmount();
remCont.add(add); remCont.add(add);
@ -243,23 +258,23 @@ public class CommandTags {
//if custom item is a mmo item (1.14+ for the API) //if custom item is a mmo item (1.14+ for the API)
try { try {
if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && panel.getConfig().getString("custom-item." + command.split("\\s")[1] + ".material").startsWith("mmo=")) { if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && panel.getConfig().getString("custom-item." + args[1] + ".material").startsWith("mmo=")) {
String customItemMaterial = panel.getConfig().getString("custom-item." + command.split("\\s")[1] + ".material"); String customItemMaterial = panel.getConfig().getString("custom-item." + args[1] + ".material");
String mmoType = customItemMaterial.split("\\s")[1]; String mmoType = customItemMaterial.split("\\s")[1];
String mmoID = customItemMaterial.split("\\s")[2]; String mmoID = customItemMaterial.split("\\s")[2];
if (plugin.isMMOItem(cont.get(f), mmoType, mmoID) && sellItem.getAmount() <= cont.get(f).getAmount()) { if (plugin.isMMOItem(itm, mmoType, mmoID) && sellItem.getAmount() <= itm.getAmount()) {
if (plugin.inventorySaver.hasNormalInventory(p)) { if (plugin.inventorySaver.hasNormalInventory(p)) {
p.getInventory().getItem(f).setAmount(cont.get(f).getAmount() - sellItem.getAmount()); p.getInventory().getItem(f).setAmount(itm.getAmount() - sellItem.getAmount());
p.updateInventory(); p.updateInventory();
} else { } else {
cont.get(f).setAmount(cont.get(f).getAmount() - sellItem.getAmount()); itm.setAmount(itm.getAmount() - sellItem.getAmount());
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0]))); plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
} }
removedItem = PaywallOutput.Passed; removedItem = PaywallOutput.Passed;
break; break;
} }
if (plugin.isMMOItem(cont.get(f), mmoType, mmoID)) { if (plugin.isMMOItem(itm, mmoType, mmoID)) {
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f); ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f);
remainingAmount -= add.getAmount(); remainingAmount -= add.getAmount();
remCont.add(add); remCont.add(add);
@ -275,8 +290,31 @@ public class CommandTags {
} else { } else {
//if the item is a standard material //if the item is a standard material
if (cont.get(f).getType() == sellItem.getType()) { if (itm.getType() == sellItem.getType()) {
ItemStack add = new ItemStack(cont.get(f).getType(), cont.get(f).getAmount(), (short) f); //Checking for custom model data. If it does not have or not the correct number go to next in loop.
if(customData != 0){
if(!itm.hasItemMeta()){
continue;
}
if(Objects.requireNonNull(itm.getItemMeta()).getCustomModelData() != customData){
continue;
}
}
//Check if the item matches the id set. If not continue to next in loop.
if(id != -1 && itm.getDurability() != id){
continue;
}
//Check if noCustom is set and if the item has custom data. If so continue to next in loop.
if(noCustom && itm.hasItemMeta()){
if(Objects.requireNonNull(itm.getItemMeta()).hasCustomModelData()){
continue;
}
}
//Adding item to the remove list then checking if we have reached the required amount.
ItemStack add = new ItemStack(itm.getType(), itm.getAmount(), (short) f);
remainingAmount -= add.getAmount(); remainingAmount -= add.getAmount();
remCont.add(add); remCont.add(add);
if (remainingAmount <= 0) { if (remainingAmount <= 0) {
@ -291,6 +329,7 @@ public class CommandTags {
for (int f = 0; f <= remCont.size() - 1; f++) { for (int f = 0; f <= remCont.size() - 1; f++) {
ItemStack remItem = remCont.get(f); ItemStack remItem = remCont.get(f);
//Check if its the last item in the loop and only subtract the remaining amount.
if(f == remCont.size() - 1){ if(f == remCont.size() - 1){
if (plugin.inventorySaver.hasNormalInventory(p)) { if (plugin.inventorySaver.hasNormalInventory(p)) {
p.getInventory().getItem((int)remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount()); p.getInventory().getItem((int)remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount());
@ -299,7 +338,7 @@ public class CommandTags {
cont.get((int)remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount()); cont.get((int)remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount());
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0]))); plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
} }
} else { } else { //If its anywhere but the last in loop just get rid of the items.
if (plugin.inventorySaver.hasNormalInventory(p)) { if (plugin.inventorySaver.hasNormalInventory(p)) {
p.getInventory().getItem(remItem.getDurability()).setAmount(0); p.getInventory().getItem(remItem.getDurability()).setAmount(0);
p.updateInventory(); p.updateInventory();

View File

@ -29,7 +29,7 @@ public class SellItemTags implements Listener {
public void commandTag(CommandTagEvent e){ public void commandTag(CommandTagEvent e){
if(e.name.equalsIgnoreCase("sell=")){ if(e.name.equalsIgnoreCase("sell=")){
e.commandTagUsed(); e.commandTagUsed();
//if player uses sell= it will be eg. sell= <total cashback> <item> <amount of item> [enchanted:KNOCKBACK:1] [potion:JUMP] //if player uses sell= it will be eg. sell= <total cashback> <item> <amount of item> [enchanted:KNOCKBACK:1] [potion:JUMP] [custom-data:#]
try { try {
if (plugin.econ != null) { if (plugin.econ != null) {
int sold = removeItem(e.p, e.args, false); int sold = removeItem(e.p, e.args, false);
@ -98,6 +98,24 @@ public class SellItemTags implements Listener {
//get inventory slots and then an empty list to store slots that have the item to sell //get inventory slots and then an empty list to store slots that have the item to sell
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p))); List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p)));
List<ItemStack> remCont = new ArrayList<>(); List<ItemStack> remCont = new ArrayList<>();
byte id = -1;
String potion = "false";
int customData = 0;
boolean noCustom = false;
for(String argsTemp : args){
if(argsTemp.startsWith("potion:")){
potion = argsTemp.replace("potion:","");
}
if (argsTemp.startsWith("id:")) {
id = Byte.parseByte(argsTemp.replace("id:", ""));
}
if (argsTemp.startsWith("custom-data:")) {
customData = Integer.parseInt(argsTemp.replace("custom-data:", ""));
}
if (argsTemp.contains("NOCUSTOMDATA")) {
noCustom = true;
}
}
//create an itemstack of the item to sell and the amount to sell (0 if all as args[2] will not be an amount) //create an itemstack of the item to sell and the amount to sell (0 if all as args[2] will not be an amount)
ItemStack sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), removeAll ? 0 : Integer.parseInt(args[2])); ItemStack sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), removeAll ? 0 : Integer.parseInt(args[2]));
@ -107,23 +125,6 @@ public class SellItemTags implements Listener {
ItemStack remItm; ItemStack remItm;
if (itm != null && itm.getType().equals(sellItem.getType())) { if (itm != null && itm.getType().equals(sellItem.getType())) {
remItm = new ItemStack(itm.getType(), itm.getAmount(), (short)f); remItm = new ItemStack(itm.getType(), itm.getAmount(), (short)f);
//determine if the command contains parameters for extensions
String potion = "false";
for(String argsTemp : args){
if(argsTemp.startsWith("potion:")){
potion = argsTemp.replace("potion:","");
}
}
//legacy ID
byte id = -1;
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
for (String argsTemp : args) {
if (argsTemp.startsWith("id:")) {
id = Byte.parseByte(argsTemp.replace("id:", ""));
break;
}
}
}
//check to ensure any extensions are checked //check to ensure any extensions are checked
try { try {
if (!potion.equals("false")) { if (!potion.equals("false")) {
@ -134,10 +135,25 @@ public class SellItemTags implements Listener {
return 0; return 0;
} }
} }
if (id != -1) { //Check if the item matches the id set. If not continue to next in loop.
if (itm.getDurability() != id) { if(id != -1 && itm.getDurability() != id){
continue; continue;
} }
//Check if noCustom is set and if the item has custom data. If so continue to next in loop.
if(noCustom && cont.get(f).hasItemMeta()){
if(Objects.requireNonNull(cont.get(f).getItemMeta()).hasCustomModelData()){
continue;
}
}
//Check if custom model data is set and if the item has that data. If not continue to next in loop.
if (customData != 0) {
if (!itm.hasItemMeta()) {
continue;
} else {
if(Objects.requireNonNull(itm.getItemMeta()).getCustomModelData() != customData){
continue;
}
}
} }
}catch(Exception exc){ }catch(Exception exc){
//skip if it cannot do unless plugin.debug is enabled //skip if it cannot do unless plugin.debug is enabled

View File

@ -1,337 +0,0 @@
package me.rockyhawk.commandpanels.editor;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.api.PanelCommandEvent;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class CPEventHandler implements Listener {
CommandPanels plugin;
public CPEventHandler(CommandPanels pl) { this.plugin = pl; }
@EventHandler
public void onCommandEventOpen(PanelCommandEvent e){
if(!e.getMessage().startsWith("CommandPanels_")) {
return;
}
if (e.getMessage().equals("CommandPanels_OpenPanelSettings")) {
plugin.editorMain.openGuiPage("PanelEditMenu", e.getPlayer(), PanelPosition.Middle);
plugin.editorMain.settings.get(e.getPlayer().getUniqueId()).setMenuOpen("PanelEditMenu");
return;
}
if (e.getMessage().equals("CommandPanels_OpenItemSettings")) {
plugin.editorMain.openGuiPage("ItemEditMenu", e.getPlayer(), PanelPosition.Middle);
plugin.editorMain.settings.get(e.getPlayer().getUniqueId()).setMenuOpen("ItemEditMenu");
return;
}
if (e.getMessage().equals("CommandPanels_EditorOpened")) {
plugin.editorMain.settings.get(e.getPlayer().getUniqueId()).hasEditorOpen = true;
return;
}
if (e.getMessage().equals("CommandPanels_EditorClosed")) {
plugin.editorMain.settings.get(e.getPlayer().getUniqueId()).hasEditorOpen = false;
}
}
void savePanelFile(Panel p){
try {
YamlConfiguration newConfig = YamlConfiguration.loadConfiguration(p.getFile());
newConfig.set("panels." + p.getName(), p.getConfig());
newConfig.save(p.getFile());
} catch (Exception io) {
plugin.debug(io,null);
}
}
@EventHandler
public void onCommandEventView(PanelCommandEvent e){
if(!e.getMessage().startsWith("CPEditorItem_") && !e.getMessage().startsWith("CPEditorPanel_")){
return;
}
EditorSettings editor = plugin.editorMain.settings.get(e.getPlayer().getUniqueId());
Panel panel = null;
for(Panel pnl : plugin.panelList) {
if (pnl.getName().equals(plugin.editorMain.settings.get(e.getPlayer().getUniqueId()).panelName)) {
panel = pnl.copy();
break;
}
}
assert panel != null;
if(e.getMessage().startsWith("CPEditorItem_")){
String input = e.getMessage().replace("CPEditorItem_","");
viewContents(e.getPlayer(), panel, "item." + editor.slotSelected + "." + input);
}
if(e.getMessage().startsWith("CPEditorPanel_")){
String input = e.getMessage().replace("CPEditorPanel_","");
viewContents(e.getPlayer() , panel, input);
}
}
@EventHandler
public void onCommandEventSettings(PanelCommandEvent e){
if(!e.getMessage().startsWith("CPEditor_")) {
return;
}
String editType = e.getMessage().split("\\s")[0].replace("CPEditor_","");
String playerInput = e.getMessage().replace("CPEditor_" + editType + " ","");
EditorSettings editor = plugin.editorMain.settings.get(e.getPlayer().getUniqueId());
Panel panel = null;
for(Panel pnl : plugin.panelList) {
if (pnl.getName().equals(plugin.editorMain.settings.get(e.getPlayer().getUniqueId()).panelName)) {
panel = pnl.copy();
break;
}
}
assert panel != null;
if(editType.startsWith("item")) {
switch (editType) {
case "itemslot":
plugin.editorMain.settings.get(e.getPlayer().getUniqueId()).slotSelected = playerInput;
break;
case "itemmaterial":
panel.getConfig().set("item." + editor.slotSelected + ".material", playerInput);
break;
case "itemname":
panel.getConfig().set("item." + editor.slotSelected + ".name", playerInput);
break;
case "itemstack":
panel.getConfig().set("item." + editor.slotSelected + ".stack", playerInput);
break;
case "itemdelete":
if (playerInput.toLowerCase().startsWith("c")) {
panel.getConfig().set("item." + editor.slotSelected, null);
}
break;
case "itemmove":
ConfigurationSection oldLocation = panel.getConfig().getConfigurationSection("item." + editor.slotSelected);
if (panel.getConfig().isSet("item." + playerInput)) {
ConfigurationSection newLocation = panel.getConfig().getConfigurationSection("item." + playerInput);
panel.getConfig().set("item." + editor.slotSelected, newLocation);
}
panel.getConfig().set("item." + playerInput, oldLocation);
break;
case "itemmodeldata":
panel.getConfig().set("item." + editor.slotSelected + ".customdata", playerInput);
break;
case "itemdurability":
panel.getConfig().set("item." + editor.slotSelected + ".damage", playerInput);
break;
case "itemarmour":
panel.getConfig().set("item." + editor.slotSelected + ".leatherarmor", playerInput);
break;
case "itemduplicate":
panel.getConfig().set("item." + editor.slotSelected + ".duplicate", playerInput);
break;
case "itempotion":
panel.getConfig().set("item." + editor.slotSelected + ".potion", playerInput);
break;
case "itemid":
panel.getConfig().set("item." + editor.slotSelected + ".ID", playerInput);
break;
case "itemlore":
listChanger(playerInput, panel, "item." + editor.slotSelected + ".lore");
if (!panel.getConfig().isSet("item." + editor.slotSelected + ".name")) {
e.getPlayer().sendMessage(ChatColor.RED + "Your item needs to have a name for your lore to be visible!");
}
break;
case "itemcommands":
listChanger(playerInput, panel, "item." + editor.slotSelected + ".commands");
break;
case "iteminput":
listChanger(playerInput, panel, "item." + editor.slotSelected + ".player-input");
break;
case "itemtypes":
listChanger(playerInput, panel, "item." + editor.slotSelected + ".itemType");
break;
case "itemenchantment":
listChanger(playerInput, panel, "item." + editor.slotSelected + ".enchanted");
break;
case "itemnbt":
if (playerInput.startsWith("add")) {
String[] str = playerInput.split("\\s", 3);
panel.getConfig().set("item." + editor.slotSelected + ".nbt." + str[1], str[2]);
} else if (playerInput.startsWith("remove")) {
String element = playerInput.split("\\s")[1];
panel.getConfig().set("item." + editor.slotSelected + ".nbt." + element, null);
}
break;
}
}else{
switch (editType) {
case "panelpermission":
panel.getConfig().set("perm", playerInput);
break;
case "panelenabledworlds":
listChanger(playerInput, panel, "enabled-worlds");
break;
case "paneldisabledworlds":
listChanger(playerInput, panel, "disabled-worlds");
break;
case "panelopensound":
panel.getConfig().set("sound-on-open", playerInput);
break;
case "panelemptyid":
panel.getConfig().set("emptyID", playerInput);
break;
case "panelempty":
panel.getConfig().set("empty", playerInput);
break;
case "paneltitle":
panel.getConfig().set("title", playerInput);
break;
case "panelrows":
if(isNumeric(playerInput)){
panel.getConfig().set("rows", Integer.parseInt(playerInput));
}else {
panel.getConfig().set("rows", playerInput);
}
break;
case "panelrefreshdelay":
panel.getConfig().set("refresh-delay", playerInput);
break;
case "paneltype":
listChanger(playerInput, panel, "panelType");
break;
case "panelcommands":
listChanger(playerInput, panel, "commands");
break;
case "panelprecommands":
listChanger(playerInput, panel, "pre-load-commands");
break;
case "panelopencommands":
listChanger(playerInput, panel, "commands-on-open");
break;
case "panelclosecommands":
listChanger(playerInput, panel, "commands-on-close");
break;
case "paneloutsidecommands":
listChanger(playerInput, panel, "outside-commands");
break;
case "panelplayerinputmessage":
listChanger(playerInput, panel, "custom-messages.player-input");
break;
case "panelmaxinputmessage":
panel.getConfig().set("custom-messages.input", playerInput);
break;
case "panelpermissionmessage":
panel.getConfig().set("custom-messages.perm", playerInput);
break;
case "paneldelete":
if (!playerInput.toLowerCase().startsWith("c")) {
break;
}
try {
//clear panel from file contents
YamlConfiguration newConfig = YamlConfiguration.loadConfiguration(panel.getFile());
newConfig.set("panels." + panel.getName(), null);
e.getPlayer().sendMessage(ChatColor.GREEN + "Panel deleted!");
if(newConfig.getKeys(true).size() == 1){
//file is empty
if(panel.getFile().delete()){
plugin.reloadPanelFiles();
return;
}
}
newConfig.save(panel.getFile());
} catch (Exception io) {
plugin.debug(io,e.getPlayer());
}
plugin.reloadPanelFiles();
return;
case "panelname":
if(panel.getName().equals(playerInput.split("\\s")[0])) {
e.getPlayer().sendMessage(ChatColor.RED + "Changed name is not different!");
return;
}
YamlConfiguration newConfig = YamlConfiguration.loadConfiguration(panel.getFile());
newConfig.set("panels." + playerInput.split("\\s")[0], panel.getConfig());
newConfig.set("panels." + panel.getName(), null);
try {
newConfig.save(panel.getFile());
} catch (Exception io) {
plugin.debug(io,e.getPlayer());
}
plugin.reloadPanelFiles();
e.getPlayer().sendMessage(ChatColor.GREEN + "Panel name changed!");
return;
}
}
savePanelFile(panel);
//This will open the editor back up
panel.open(e.getPlayer(),PanelPosition.Top);
plugin.editorMain.openGuiPage(plugin.editorMain.settings.get(e.getPlayer().getUniqueId()).menuOpen,e.getPlayer(),PanelPosition.Middle);
plugin.editorMain.openGuiPage("BottomSettings",e.getPlayer(),PanelPosition.Bottom);
}
/*
this will allow for add, edit and remove settings
add msg= test
edit 1 msg= changed
insert 1 msg= new line
remove 1
*/
public void listChanger(String playerInput, Panel panel, String location){
List<String> contents = panel.getConfig().getStringList(location);
if(playerInput.startsWith("add")){
String str = playerInput.split("\\s", 2)[1];
contents.add(str);
}else if(playerInput.startsWith("edit")){
List<String> str = new ArrayList<>(Arrays.asList(playerInput.split("\\s")));
str.subList(0,2).clear();
int element = Integer.parseInt(playerInput.split("\\s")[1])-1;
contents.set(element,String.join(" ",str));
}else if(playerInput.startsWith("insert")){
List<String> str = new ArrayList<>(Arrays.asList(playerInput.split("\\s")));
str.subList(0,2).clear();
int element = Integer.parseInt(playerInput.split("\\s")[1])-1;
contents.add(element,String.join(" ",str));
}else if(playerInput.startsWith("remove")){
int element = Integer.parseInt(playerInput.split("\\s")[1])-1;
contents.remove(element);
}
if(contents.isEmpty()){
panel.getConfig().set(location, null);
}else {
panel.getConfig().set(location, contents);
}
}
public void viewContents(Player player, Panel panel, String location){
if(panel.getConfig().isList(location)){
player.sendMessage("Current Value: ");
int n = 1;
for(String value : panel.getConfig().getStringList(location)){
player.sendMessage("(" + n + ") " + value);
n++;
}
}else{
player.sendMessage("Current Value: " + panel.getConfig().getString(location));
}
}
//if a string is a number
public boolean isNumeric(String str) {
try {
Double.parseDouble(str);
return true;
} catch(NumberFormatException e){
return false;
}
}
}

View File

@ -0,0 +1,114 @@
package me.rockyhawk.commandpanels.editor;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import net.md_5.bungee.api.chat.*;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.scheduler.BukkitRunnable;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class CommandPanelsEditor implements CommandExecutor {
CommandPanels plugin;
public CommandPanelsEditor(CommandPanels pl) {
this.plugin = pl;
}
@EventHandler
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.hasPermission("commandpanel.edit")) {
if (!(sender instanceof Player)) {
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Cannot execute command in Console!"));
return true;
}
//editor website link
if (args.length == 0) {
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.GREEN + "Access the web editor at the link below"));
sender.sendMessage(plugin.tex.colour(ChatColor.YELLOW + "https://CommandPanels.net/editor"));
return true;
}
//export the requested panel
if (args.length == 1) {
for (Panel panel : plugin.panelList) {
if (panel.getFile().getName().equals(args[0])) {
String filePath = panel.getFile().getAbsolutePath(); //remove file name extensions
String fileContents = readFileAsString(filePath);
// Get the relative file path from the root panels folder
Path panelsFolderPath = plugin.panelsf.toPath();
Path panelFilePath = panel.getFile().toPath();
Path relativePanelPath = panelsFolderPath.relativize(panelFilePath);
String relativePath = relativePanelPath.toString();
// Prepend "fileName: {name}" and "filePath: {relativePath}" to the YAML content
String yamlWithFileNameAndPath = "fileName: " + (relativePath.replaceFirst("[.][^.]+$", "")) + "\n" + fileContents;
// Create a clickable text component with the modified YAML content
BaseComponent[] components = new ComponentBuilder(plugin.tag +
net.md_5.bungee.api.ChatColor.GREEN + "Click here to copy " +
net.md_5.bungee.api.ChatColor.WHITE + panel.getFile().getName() +
net.md_5.bungee.api.ChatColor.GREEN + " to the clipboard!")
.event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, yamlWithFileNameAndPath))
.create();
// Send the clickable text to the player
Player player = (Player) sender;
player.spigot().sendMessage(components);
return true;
}
}
// Pass the panel name to the YamlFileHandler
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Could not find panel!"));
return true;
}
//download the requested panel using an import
if (args.length == 3) {
new BukkitRunnable() {
@Override
public void run() {
downloadPanel(sender,args[1],args[0], args[2]);
plugin.reloadPanelFiles();
plugin.hotbar.reloadHotbarSlots();
}
}.run();
return true;
}
}else{
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms")));
}
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpe <parameters>"));
return true;
}
private void downloadPanel(CommandSender sender, String userID, String fileName, String token) {
//get custom editor URL
String url = "https://firebasestorage.googleapis.com/v0/b/commandpanels-website.appspot.com/o/pastes%2F" + userID + "%2F" + fileName + "?alt=media&token=" + token;
plugin.downloader.downloadPanel(sender, url, fileName);
}
private String readFileAsString(String filePath) {
try {
Path path = Paths.get(filePath);
byte[] bytes = Files.readAllBytes(path);
return new String(bytes, StandardCharsets.UTF_8);
} catch (IOException e) {
// Handle the exception if the file cannot be read
e.printStackTrace();
return "";
}
}
}

View File

@ -1,51 +0,0 @@
package me.rockyhawk.commandpanels.editor;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
public class CommandPanelsEditorCommand implements CommandExecutor {
CommandPanels plugin;
public CommandPanelsEditorCommand(CommandPanels pl) {
this.plugin = pl;
}
@EventHandler
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(!sender.hasPermission("commandpanel.edit")){
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms")));
return true;
}
if(!(sender instanceof Player)) {
sender.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.RED + "Please execute command as a Player!"));
return true;
}
Player p = (Player)sender;
//below is going to go through the files and find the right one
if (args.length == 1) { //check to make sure the person hasn't just left it empty
for(Panel panel : plugin.panelList){
if(panel.getName().equals(args[0])) {
if(plugin.editorMain.settings.containsKey(p.getUniqueId())){
plugin.editorMain.settings.get(p.getUniqueId()).setLastPanel(panel.getName());
}else{
plugin.editorMain.settings.put(p.getUniqueId(), new EditorSettings("PanelEditMenu",panel.getName()));
}
//below will start the command, once it got the right file and panel
panel.copy().open(p,PanelPosition.Top);
plugin.editorMain.openGuiPage(plugin.editorMain.settings.get(p.getUniqueId()).menuOpen,p,PanelPosition.Middle);
plugin.editorMain.openGuiPage("BottomSettings",p,PanelPosition.Bottom);
return true;
}
}
}
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpe <panel>"));
return true;
}
}

View File

@ -1,32 +0,0 @@
package me.rockyhawk.commandpanels.editor;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class CommandPanelsEditorMain {
CommandPanels plugin;
public CommandPanelsEditorMain(CommandPanels pl) {
this.plugin = pl;
}
public Map<UUID, EditorSettings> settings = new HashMap<>();
public void openGuiPage(String fileName, Player p, PanelPosition position){
try {
Panel panel = new Panel(YamlConfiguration.loadConfiguration(plugin.getReaderFromStream(plugin.getResource(fileName + ".yml"))), fileName);
panel.placeholders.addPlaceholder("panel-name",settings.get(p.getUniqueId()).panelName);
panel.placeholders.addPlaceholder("item-slot",settings.get(p.getUniqueId()).slotSelected);
panel.open(p, position);
}catch(Exception ex){
ex.printStackTrace();
}
}
}

View File

@ -1,42 +0,0 @@
package me.rockyhawk.commandpanels.editor;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class CommandPanelsEditorTabComplete implements TabCompleter {
CommandPanels plugin;
public CommandPanelsEditorTabComplete(CommandPanels pl) { this.plugin = pl; }
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
if(sender instanceof Player && args.length == 1){
Player p = ((Player) sender).getPlayer();
ArrayList<String> apanels = new ArrayList<String>(); //all panels
try {
for(Panel panel : plugin.panelList) { //will loop through all the files in folder
if(!panel.getName().startsWith(args[0])){
//this will narrow down the panels to what the user types
continue;
}
if(sender.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))) {
if(plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
apanels.add(panel.getName());
}
}
//if file contains opened panel then start
}
}catch(Exception fail){
//could not fetch all panel names (probably no panels exist)
}
return apanels;
}
return null;
}
}

View File

@ -1,21 +0,0 @@
package me.rockyhawk.commandpanels.editor;
public class EditorSettings {
public String panelName;
public String menuOpen;
public String slotSelected = "0";
public boolean hasEditorOpen = false;
public EditorSettings(String menu, String panel){
menuOpen = menu;
panelName = panel;
}
public void setMenuOpen(String menu){
menuOpen = menu;
}
public void setLastPanel(String panel){
panelName = panel;
}
}

View File

@ -0,0 +1,29 @@
package me.rockyhawk.commandpanels.editor;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import java.util.ArrayList;
import java.util.List;
public class EditorTabComplete implements TabCompleter {
CommandPanels plugin;
public EditorTabComplete(CommandPanels pl) { this.plugin = pl; }
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
if(sender.hasPermission("commandpanel.edit")) {
ArrayList<String> output = new ArrayList<>();
if(args.length == 1){
for(Panel panel : plugin.panelList){
output.add(panel.getFile().getName());
}
}
return output;
}
return null;
}
}

View File

@ -0,0 +1,83 @@
package me.rockyhawk.commandpanels.editor;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import java.io.*;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.logging.Level;
public class PanelDownloader {
CommandPanels plugin;
public PanelDownloader(CommandPanels pl) { this.plugin = pl; }
public void downloadPanel(CommandSender sender, String url, String fileName) {
BufferedInputStream in = null;
FileOutputStream fout = null;
//add extension if not already added
if(!fileName.endsWith(".yml") && !fileName.endsWith(".yaml")) {
fileName = fileName + ".yml";
}
//Check if fileName contains file://
try {
if(URLDecoder.decode(url, StandardCharsets.UTF_8.toString()).contains("file://")) {
sender.sendMessage(plugin.tag + ChatColor.RED + "Invalid URL. Using file:// is not supported.");
return;
}
} catch (UnsupportedEncodingException e) {
sender.sendMessage(plugin.tag + ChatColor.RED + "UTF-8 support not found.");
return;
}
// Create the file object and get its canonical path
File file = new File(plugin.panelsf, fileName);
try {
String canonicalPath = file.getCanonicalPath();
if (!canonicalPath.startsWith(plugin.panelsf.getCanonicalPath())) {
sender.sendMessage(plugin.tag + ChatColor.RED + "Invalid file name or URL.");
return;
}
} catch (IOException e) {
sender.sendMessage(plugin.tag + ChatColor.RED + "Invalid file name or URL.");
return;
}
//download panel from page contents and add to plugin
try {
URL fileUrl = new URL(url);
in = new BufferedInputStream(fileUrl.openStream());
fout = new FileOutputStream(file);
byte[] data = new byte[1024];
int count;
while((count = in.read(data, 0, 1024)) != -1) {
fout.write(data, 0, count);
}
sender.sendMessage(plugin.tag + ChatColor.GREEN + "Finished downloading.");
} catch (Exception var22) {
sender.sendMessage(plugin.tag + ChatColor.RED + "Could not download panel.");
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException var21) {
this.plugin.getLogger().log(Level.SEVERE, null, var21);
}
try {
if (fout != null) {
fout.close();
}
} catch (IOException var20) {
this.plugin.getLogger().log(Level.SEVERE, null, var20);
}
}
}
}

View File

@ -59,7 +59,7 @@ public class Commandpanelrefresher implements Listener {
public void run() { public void run() {
int animatevalue = -1; int animatevalue = -1;
if(pn.getConfig().contains("animatevalue")){ if(pn.getConfig().contains("animatevalue")){
animatevalue = pn.getConfig().getInt("animatevalue"); animatevalue = Integer.parseInt(pn.getConfig().getString("animatevalue"));
} }
//counter counts to refresh delay (in seconds) then restarts //counter counts to refresh delay (in seconds) then restarts
if(c < refreshDelay){ if(c < refreshDelay){

View File

@ -28,7 +28,6 @@ public class OpenGUI {
Inventory i; Inventory i;
if(position == PanelPosition.Top) { if(position == PanelPosition.Top) {
String title; String title;
if (openType != PanelOpenType.Editor) {
if(pconfig.contains("custom-title")) { if(pconfig.contains("custom-title")) {
//used for titles in the custom-title section, for has sections //used for titles in the custom-title section, for has sections
String section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("custom-title"), p); String section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("custom-title"), p);
@ -37,13 +36,9 @@ public class OpenGUI {
//regular inventory title //regular inventory title
title = plugin.tex.placeholders(panel, position, p, pconfig.getString("title")); title = plugin.tex.placeholders(panel, position, p, pconfig.getString("title"));
} }
} else {
//editor inventory
title = "Editing Panel: " + panel.getName();
}
if (isNumeric(pconfig.getString("rows"))) { if (isNumeric(pconfig.getString("rows"))) {
i = Bukkit.createInventory(p, pconfig.getInt("rows") * 9, title); i = Bukkit.createInventory(p, Integer.parseInt(pconfig.getString("rows")) * 9, title);
} else { } else {
i = Bukkit.createInventory(p, InventoryType.valueOf(pconfig.getString("rows")), title); i = Bukkit.createInventory(p, InventoryType.valueOf(pconfig.getString("rows")), title);
} }
@ -63,7 +58,6 @@ public class OpenGUI {
for (String item : itemList) { for (String item : itemList) {
String section = ""; String section = "";
//openType needs to not be 3 so the editor won't include hasperm and hasvalue, etc items //openType needs to not be 3 so the editor won't include hasperm and hasvalue, etc items
if (openType != PanelOpenType.Editor) {
section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("item." + Integer.parseInt(item)), p); section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("item." + Integer.parseInt(item)), p);
//This section is for animations below here: VISUAL ONLY //This section is for animations below here: VISUAL ONLY
@ -74,10 +68,9 @@ public class OpenGUI {
section = section + ".animate" + animateValue; section = section + ".animate" + animateValue;
} }
} }
}
//will only add NBT if not an editor GUI //will only add NBT if not an editor GUI
ItemStack s = plugin.itemCreate.makeItemFromConfig(panel,position,Objects.requireNonNull(pconfig.getConfigurationSection("item." + item + section)), p, openType != PanelOpenType.Editor, openType != PanelOpenType.Editor, openType != PanelOpenType.Editor); ItemStack s = plugin.itemCreate.makeItemFromConfig(panel,position,Objects.requireNonNull(pconfig.getConfigurationSection("item." + item + section)), p, true, true, true);
//This is for CUSTOM ITEMS //This is for CUSTOM ITEMS
if(pconfig.contains("item." + item + section + ".itemType")) { if(pconfig.contains("item." + item + section + ".itemType")) {
@ -96,7 +89,7 @@ public class OpenGUI {
takenSlots.add(Integer.parseInt(item)); takenSlots.add(Integer.parseInt(item));
//i.setItem(Integer.parseInt(item), s); //i.setItem(Integer.parseInt(item), s);
//only place duplicate items in without the editor mode. These are merely visual and will not carry over commands //only place duplicate items in without the editor mode. These are merely visual and will not carry over commands
if(pconfig.contains("item." + item + section + ".duplicate") && openType != PanelOpenType.Editor) { if(pconfig.contains("item." + item + section + ".duplicate")) {
try { try {
String[] duplicateItems = pconfig.getString("item." + item + section + ".duplicate").split(","); String[] duplicateItems = pconfig.getString("item." + item + section + ".duplicate").split(",");
for (String tempDupe : duplicateItems) { for (String tempDupe : duplicateItems) {
@ -157,13 +150,11 @@ public class OpenGUI {
if (empty.getType() != Material.AIR) { if (empty.getType() != Material.AIR) {
for (int c = 0; getInvSize(i,position) > c; ++c) { for (int c = 0; getInvSize(i,position) > c; ++c) {
if (!takenSlots.contains(c)) { if (!takenSlots.contains(c)) {
//only place empty items if not editing //place empty item
if(openType != PanelOpenType.Editor) {
setItem(empty,c,i,p,position); setItem(empty,c,i,p,position);
} }
} }
} }
}
} catch (IllegalArgumentException | NullPointerException var26) { } catch (IllegalArgumentException | NullPointerException var26) {
plugin.debug(var26,p); plugin.debug(var26,p);
} }
@ -181,9 +172,6 @@ public class OpenGUI {
p.openInventory(i); p.openInventory(i);
} }
plugin.openPanels.skipPanelClose.remove(p.getName()); plugin.openPanels.skipPanelClose.remove(p.getName());
} else if (openType == PanelOpenType.Editor) {
//The editor will always be at panel position top
p.openInventory(i);
} else if (openType == PanelOpenType.Refresh) { } else if (openType == PanelOpenType.Refresh) {
//openType 0 will just refresh the panel //openType 0 will just refresh the panel
if(position == PanelPosition.Top) { if(position == PanelPosition.Top) {

View File

@ -1,7 +1,6 @@
package me.rockyhawk.commandpanels.openpanelsmanager; package me.rockyhawk.commandpanels.openpanelsmanager;
public enum PanelOpenType { public enum PanelOpenType {
Editor,
Normal, Normal,
Return, Return,
Refresh Refresh

View File

@ -54,7 +54,10 @@ public class UtilsPanelsLoader implements Listener {
public void run() { public void run() {
//end the old panel session and copy a new one //end the old panel session and copy a new one
plugin.openPanels.getOpenPanel(playerName,PanelPosition.Top).isOpen = false; plugin.openPanels.getOpenPanel(playerName,PanelPosition.Top).isOpen = false;
plugin.openPanels.getOpenPanel(playerName,PanelPosition.Top).copy().open(Bukkit.getPlayer(playerName), PanelPosition.Top); Panel reopenedPanel = plugin.openPanels.getOpenPanel(playerName,PanelPosition.Top).copy();
//re-add placeholders as they are not transferred in the Panel object
reopenedPanel.placeholders.keys = plugin.openPanels.getOpenPanel(playerName,PanelPosition.Top).placeholders.keys;
reopenedPanel.open(Bukkit.getPlayer(playerName), PanelPosition.Top);
} }
}); });
return; return;
@ -71,6 +74,11 @@ public class UtilsPanelsLoader implements Listener {
//close panels and run commands for Top panel //close panels and run commands for Top panel
plugin.openPanels.closePanelForLoader(e.getPlayer().getName(),PanelPosition.Top); plugin.openPanels.closePanelForLoader(e.getPlayer().getName(),PanelPosition.Top);
//clear cached textures list on length limit
if(plugin.customHeads.playerHeadTextures.size() > 1000) {
plugin.customHeads.playerHeadTextures.clear();
}
} }
@EventHandler @EventHandler

View File

@ -32,7 +32,7 @@ public class HotbarItemLoader {
//return true if found //return true if found
public boolean stationaryExecute(int slot, Player p, ClickType click, boolean openPanel){ public boolean stationaryExecute(int slot, Player p, ClickType click, boolean openPanel){
if(stationaryItems.get(p.getUniqueId()).list.containsKey(slot)){ if(stationaryItems.get(p.getUniqueId()).list.containsKey(String.valueOf(slot))){
if(openPanel) { if(openPanel) {
try { try {
if (!plugin.nbt.getNBT(p.getInventory().getItem(slot), "CommandPanelsHotbar").split(":")[1].equals(String.valueOf(slot))) { if (!plugin.nbt.getNBT(p.getInventory().getItem(slot), "CommandPanelsHotbar").split(":")[1].equals(String.valueOf(slot))) {
@ -41,7 +41,7 @@ public class HotbarItemLoader {
}catch(Exception ex){ }catch(Exception ex){
return false; return false;
} }
Panel panel = stationaryItems.get(p.getUniqueId()).getPanel(slot); Panel panel = stationaryItems.get(p.getUniqueId()).getPanel(String.valueOf(slot));
//only open panel automatically if there are no commands and player world is not disabled //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(!p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))){
return false; return false;
@ -136,8 +136,8 @@ public class HotbarItemLoader {
if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm")) && panel.hasHotbarItem()) { if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm")) && panel.hasHotbarItem()) {
ItemStack s = panel.getHotbarItem(p); ItemStack s = panel.getHotbarItem(p);
if(panel.getHotbarSection(p).contains("stationary")) { if(panel.getHotbarSection(p).contains("stationary")) {
p.getInventory().setItem(panel.getHotbarSection(p).getInt("stationary"),s); p.getInventory().setItem(Integer.parseInt(panel.getHotbarSection(p).getString("stationary")),s);
stationaryItems.get(p.getUniqueId()).addSlot(panel.getHotbarSection(p).getInt("stationary"),panel); stationaryItems.get(p.getUniqueId()).addSlot(panel.getHotbarSection(p).getString("stationary"),panel);
} }
} }
} }

View File

@ -5,16 +5,16 @@ import me.rockyhawk.commandpanels.api.Panel;
import java.util.HashMap; import java.util.HashMap;
public class HotbarPlayerManager { public class HotbarPlayerManager {
public HashMap<Integer,Panel> list = new HashMap<>(); public HashMap<String,Panel> list = new HashMap<>();
public HotbarPlayerManager(){ public HotbarPlayerManager(){
} }
public void addSlot(int slot, Panel panel){ public void addSlot(String slot, Panel panel){
list.put(slot,panel); list.put(slot,panel);
} }
public Panel getPanel(int slot){ public Panel getPanel(String slot){
return list.get(slot).copy(); return list.get(slot).copy();
} }
} }

View File

@ -32,8 +32,8 @@ public class UtilsChestSortEvent implements Listener {
//If the ChestSort plugin triggers an event //If the ChestSort plugin triggers an event
try { try {
if (e.getInventory().getType() == InventoryType.PLAYER) { if (e.getInventory().getType() == InventoryType.PLAYER) {
for (int slot : plugin.hotbar.stationaryItems.get(e.getPlayer().getUniqueId()).list.keySet()) { for (String slot : plugin.hotbar.stationaryItems.get(e.getPlayer().getUniqueId()).list.keySet()) {
e.setUnmovable(slot); e.setUnmovable(Integer.parseInt(slot));
} }
} }
}catch(NullPointerException ex){ }catch(NullPointerException ex){

View File

@ -48,7 +48,7 @@ public class UtilsOpenWithItem implements Listener {
} }
@EventHandler @EventHandler
public void onPlayerUse(PlayerInteractEvent e){ public void onPlayerUse(PlayerInteractEvent e){
//item right clicked only (not left because that causes issues when things are interacted with) //item right-clicked only (not left because that causes issues when things are interacted with)
if(!plugin.openWithItem){ if(!plugin.openWithItem){
//if none of the panels have open-with-item //if none of the panels have open-with-item
return; return;

View File

@ -84,6 +84,8 @@ public class Updater implements Listener {
HttpURLConnection connection; HttpURLConnection connection;
try { try {
connection = (HttpURLConnection) new URL("https://raw.githubusercontent.com/rockyhawk64/CommandPanels/master/resource/plugin.yml").openConnection(); connection = (HttpURLConnection) new URL("https://raw.githubusercontent.com/rockyhawk64/CommandPanels/master/resource/plugin.yml").openConnection();
connection.setConnectTimeout(5000); // 5 seconds
connection.setReadTimeout(5000); // 5 seconds
connection.connect(); connection.connect();
cachedLatestVersion = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine().split("\\s")[1]; cachedLatestVersion = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine().split("\\s")[1];
connection.disconnect(); connection.disconnect();