forked from Upstream/CommandPanels
Merge https://github.com/jman13378/CommandPanels into HEAD
This commit is contained in:
commit
48367ae177
@ -12,7 +12,7 @@
|
||||
</list>
|
||||
</option>
|
||||
</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" />
|
||||
</component>
|
||||
</project>
|
45
README.md
45
README.md
@ -1,25 +1,38 @@
|
||||

|
||||
|
||||
### About
|
||||
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.
|
||||
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.
|
||||
<p align="center">
|
||||
<a href="https://discord.gg/eUWBWh7"><img src="https://i.imgur.com/50KoZcJ.png" alt="Discord"></a>
|
||||
<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
|
||||
- PlaceholderAPI support
|
||||
- Comes with a built in editor
|
||||
- Unlimited GUIs
|
||||
- Create complex panel systems
|
||||
<img align="center" src="https://i.imgur.com/w8UaAP2.png" alt="Screenshot">
|
||||
|
||||
### Discord Support
|
||||
You can join the discord server for support [here](https://discord.gg/eUWBWh7).
|
||||
This is the main and fastest way to receive support for the plugin.
|
||||
## Partner
|
||||
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.
|
||||
|
||||
### Wiki Page
|
||||
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
|
||||
Please report bugs, issues or request features [here](https://github.com/rockyhawk64/CommandPanels/issues).
|
||||
We have proudly partnered with [ReviveNode](http://billing.revivenode.com/aff.php?aff=379)!
|
||||
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
|
||||
You can find the spigot page for the plugin [here](https://www.spigotmc.org/resources/67788/).
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: 3.18.6.2
|
||||
version: 3.19.0.3
|
||||
main: me.rockyhawk.commandpanels.CommandPanels
|
||||
name: CommandPanels
|
||||
author: RockyHawk
|
||||
|
@ -20,13 +20,10 @@ import me.rockyhawk.commandpanels.completetabs.CpTabComplete;
|
||||
import me.rockyhawk.commandpanels.customcommands.Commandpanelcustom;
|
||||
import me.rockyhawk.commandpanels.datamanager.DebugManager;
|
||||
import me.rockyhawk.commandpanels.datamanager.PanelDataLoader;
|
||||
import me.rockyhawk.commandpanels.editor.*;
|
||||
import me.rockyhawk.commandpanels.generatepanels.Commandpanelsgenerate;
|
||||
import me.rockyhawk.commandpanels.generatepanels.GenUtils;
|
||||
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.Commandpanelrefresher;
|
||||
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
|
||||
|
||||
//get alternate classes
|
||||
public CommandPanelsEditorMain editorMain = new CommandPanelsEditorMain(this);
|
||||
public PanelDownloader downloader = new PanelDownloader(this);
|
||||
|
||||
public CommandTags commandTags = new CommandTags(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")).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("commandpaneldebug")).setExecutor(new Commandpanelsdebug(this));
|
||||
@ -203,13 +202,6 @@ public class CommandPanels extends JavaPlugin{
|
||||
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(Objects.requireNonNull(config.getString("config.panel-blocks")).equalsIgnoreCase("true")){
|
||||
Objects.requireNonNull(this.getCommand("commandpanelblock")).setExecutor(new Commandpanelblocks(this));
|
||||
@ -367,13 +359,13 @@ public class CommandPanels extends JavaPlugin{
|
||||
}
|
||||
|
||||
//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()) {
|
||||
//there are duplicate panel names
|
||||
ArrayList<String> opanelsTemp = new ArrayList<String>();
|
||||
ArrayList<String> opanelsTemp = new ArrayList<>();
|
||||
for(String tempName : apanels){
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
opanelsTemp.add(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 [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")) {
|
||||
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")) {
|
||||
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>() {{
|
||||
|
@ -86,16 +86,6 @@ public class Utils implements Listener {
|
||||
//the panels proper 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
|
||||
boolean foundSlot = false;
|
||||
for(String slot : Objects.requireNonNull(panel.getConfig().getConfigurationSection("item")).getKeys(false)){
|
||||
|
@ -4,6 +4,7 @@ import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.classresources.placeholders.PanelPlaceholders;
|
||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelOpenType;
|
||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
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);
|
||||
int slot = -1;
|
||||
String slot = "-1";
|
||||
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);
|
||||
}catch(Exception e) {
|
||||
//return air if null
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
return plugin.nbt.setNBT(s,"CommandPanelsHotbar",panelName + ":" + slot);
|
||||
}
|
||||
public ConfigurationSection getHotbarSection(Player p){
|
||||
String section = plugin.has.hasSection(this,PanelPosition.Top,panelConfig.getConfigurationSection("open-with-item"), p);
|
||||
|
@ -9,9 +9,18 @@ import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
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.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.UUID;
|
||||
|
||||
@ -21,6 +30,10 @@ public class GetCustomHeads {
|
||||
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) {
|
||||
if (plugin.getHeads.ifSkullOrHead(head.getType().toString()) && head.hasItemMeta()) {
|
||||
try {
|
||||
@ -41,20 +54,54 @@ public class GetCustomHeads {
|
||||
return null;
|
||||
}
|
||||
|
||||
//getting the head from a Player
|
||||
//getting the head from a Player Name
|
||||
@SuppressWarnings("deprecation")
|
||||
public ItemStack getPlayerHead(String name) {
|
||||
byte id = 0;
|
||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
|
||||
if (plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
|
||||
id = 3;
|
||||
}
|
||||
ItemStack itemStack = new ItemStack(Material.matchMaterial(plugin.getHeads.playerHeadString()), 1,id);
|
||||
SkullMeta meta = (SkullMeta) itemStack.getItemMeta();
|
||||
meta.setOwner(name);
|
||||
itemStack.setItemMeta(meta);
|
||||
return itemStack;
|
||||
|
||||
//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);
|
||||
SkullMeta meta = (SkullMeta) itemStack.getItemMeta();
|
||||
meta.setOwner(name);
|
||||
itemStack.setItemMeta(meta);
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
|
||||
//used to get heads from Base64 Textures
|
||||
@SuppressWarnings("deprecation")
|
||||
public ItemStack getCustomHead(String b64stringtexture) {
|
||||
//get head from base64
|
||||
|
@ -201,66 +201,22 @@ public class ItemCreation {
|
||||
if(addNBT){
|
||||
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")) {
|
||||
try {
|
||||
ItemMeta EnchantMeta;
|
||||
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();
|
||||
assert EnchantMeta != null;
|
||||
for(String enchantment : itemSection.getStringList("enchanted")){
|
||||
if(enchantment.equalsIgnoreCase("true")) {
|
||||
EnchantMeta.addEnchant(Enchantment.KNOCKBACK, 1, false);
|
||||
EnchantMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
continue;
|
||||
}
|
||||
EnchantMeta.addEnchant(Objects.requireNonNull(EnchantmentWrapper.getByKey(NamespacedKey.minecraft(enchantment.split("\\s")[0].toLowerCase()))), Integer.parseInt(enchantment.split("\\s")[1]), 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.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
s.setItemMeta(EnchantMeta);
|
||||
} else if (!Objects.requireNonNull(itemSection.getString("enchanted")).trim().equalsIgnoreCase("false")) {
|
||||
//if used to ensure enchanted does not equal false but equals something else
|
||||
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);
|
||||
}
|
||||
} catch (Exception ench) {
|
||||
p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " enchanted: " + itemSection.getString("enchanted")));
|
||||
|
@ -8,13 +8,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.EventHandler;
|
||||
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 {
|
||||
CommandPanels plugin;
|
||||
public CommandPanelImport(CommandPanels pl) { this.plugin = pl; }
|
||||
@ -27,8 +20,9 @@ public class CommandPanelImport implements CommandExecutor {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
downloadPanel(sender,args[1],args[0]);
|
||||
plugin.downloader.downloadPanel(sender,args[1],args[0]);
|
||||
plugin.reloadPanelFiles();
|
||||
plugin.hotbar.reloadHotbarSlots();
|
||||
}
|
||||
}.run();
|
||||
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>"));
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -44,49 +44,47 @@ public class Commandpanel implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
//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)) {
|
||||
//do console command
|
||||
if(args.length == 2){
|
||||
if(!args[1].equals("item")){
|
||||
plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel.copy(), PanelPosition.Top, true);
|
||||
}else{
|
||||
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp <panel> [item] [player]"));
|
||||
}
|
||||
return true;
|
||||
}else if(args.length == 3){
|
||||
if (args[1].equals("item")) {
|
||||
plugin.openVoids.giveHotbarItem(sender,plugin.getServer().getPlayer(args[2]),panel.copy(),true);
|
||||
}else{
|
||||
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp <panel> item [player]"));
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.RED + "Please execute command directed to a Player!"));
|
||||
return true;
|
||||
if(!(sender instanceof Player)) {
|
||||
//do console command
|
||||
if(args.length == 2){
|
||||
if(!args[1].equals("item")){
|
||||
plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel.copy(), PanelPosition.Top, true);
|
||||
}else{
|
||||
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp <panel> [item] [player]"));
|
||||
}
|
||||
}else{
|
||||
//get player
|
||||
Player p = (Player) sender;
|
||||
//do player command
|
||||
if (args.length == 1) {
|
||||
return true;
|
||||
}else if(args.length == 3){
|
||||
if (args[1].equals("item")) {
|
||||
plugin.openVoids.giveHotbarItem(sender,plugin.getServer().getPlayer(args[2]),panel.copy(),true);
|
||||
}else{
|
||||
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp <panel> item [player]"));
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.RED + "Please execute command directed to a Player!"));
|
||||
return true;
|
||||
}
|
||||
}else{
|
||||
//get player
|
||||
Player p = (Player) sender;
|
||||
//do player command
|
||||
if (args.length == 1) {
|
||||
if(!disableCommand) {
|
||||
plugin.openVoids.openCommandPanel(sender, p, panel.copy(),PanelPosition.Top, false);
|
||||
}
|
||||
return true;
|
||||
}else if(args.length == 2){
|
||||
if (args[1].equals("item")) {
|
||||
plugin.openVoids.giveHotbarItem(sender, p, panel.copy(), false);
|
||||
}else{
|
||||
if(!disableCommand) {
|
||||
plugin.openVoids.openCommandPanel(sender, p, panel.copy(),PanelPosition.Top, false);
|
||||
plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel.copy(),PanelPosition.Top, true);
|
||||
}
|
||||
return true;
|
||||
}else if(args.length == 2){
|
||||
if (args[1].equals("item")) {
|
||||
plugin.openVoids.giveHotbarItem(sender, p, panel.copy(), false);
|
||||
}else{
|
||||
if(!disableCommand) {
|
||||
plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel.copy(),PanelPosition.Top, true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}else if(args.length == 3){
|
||||
plugin.openVoids.giveHotbarItem(sender, plugin.getServer().getPlayer(args[2]), panel.copy(),true);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}else if(args.length == 3){
|
||||
plugin.openVoids.giveHotbarItem(sender, plugin.getServer().getPlayer(args[2]), panel.copy(),true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp <panel> [player:item] [player]"));
|
||||
|
@ -51,6 +51,9 @@ public class Commandpanelsreload implements CommandExecutor {
|
||||
registerCommands();
|
||||
}
|
||||
|
||||
//clear cached head textures
|
||||
plugin.customHeads.playerHeadTextures.clear();
|
||||
|
||||
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.reload")));
|
||||
}else{
|
||||
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms")));
|
||||
|
@ -200,22 +200,35 @@ public class CommandTags {
|
||||
}
|
||||
}
|
||||
case "item-paywall=": {
|
||||
//if player uses item-paywall= [Material] [Amount] [Id]
|
||||
//player can use item-paywall= [custom-item]
|
||||
//if player uses item-paywall= [Material] [Amount] <id:#> <custom-data:#>
|
||||
//player can use item-paywall= [custom-item] [Amount]
|
||||
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p)));
|
||||
List<ItemStack> remCont = new ArrayList<>();
|
||||
String[] args = command.split("\\s");
|
||||
try {
|
||||
short id = 0;
|
||||
if (command.split("\\s").length == 4) {
|
||||
id = Short.parseShort(command.split("\\s")[3]);
|
||||
byte id = -1;
|
||||
int customData = 0;
|
||||
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
|
||||
ItemStack sellItem;
|
||||
if (Material.matchMaterial(command.split("\\s")[1]) == null) {
|
||||
sellItem = plugin.itemCreate.makeCustomItemFromConfig(panel, PanelPosition.Top, panel.getConfig().getConfigurationSection("custom-item." + command.split("\\s")[1]), p, true, true, false);
|
||||
if (Material.matchMaterial(args[1]) == null) {
|
||||
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 {
|
||||
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
|
||||
PaywallOutput removedItem = PaywallOutput.Blocked;
|
||||
@ -229,9 +242,11 @@ public class CommandTags {
|
||||
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
|
||||
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);
|
||||
remainingAmount -= add.getAmount();
|
||||
remCont.add(add);
|
||||
@ -243,23 +258,23 @@ public class CommandTags {
|
||||
|
||||
//if custom item is a mmo item (1.14+ for the API)
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && panel.getConfig().getString("custom-item." + command.split("\\s")[1] + ".material").startsWith("mmo=")) {
|
||||
String customItemMaterial = panel.getConfig().getString("custom-item." + command.split("\\s")[1] + ".material");
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && panel.getConfig().getString("custom-item." + args[1] + ".material").startsWith("mmo=")) {
|
||||
String customItemMaterial = panel.getConfig().getString("custom-item." + args[1] + ".material");
|
||||
String mmoType = customItemMaterial.split("\\s")[1];
|
||||
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)) {
|
||||
p.getInventory().getItem(f).setAmount(cont.get(f).getAmount() - sellItem.getAmount());
|
||||
p.getInventory().getItem(f).setAmount(itm.getAmount() - sellItem.getAmount());
|
||||
p.updateInventory();
|
||||
} 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])));
|
||||
}
|
||||
removedItem = PaywallOutput.Passed;
|
||||
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);
|
||||
remainingAmount -= add.getAmount();
|
||||
remCont.add(add);
|
||||
@ -275,8 +290,31 @@ public class CommandTags {
|
||||
|
||||
} else {
|
||||
//if the item is a standard material
|
||||
if (cont.get(f).getType() == sellItem.getType()) {
|
||||
ItemStack add = new ItemStack(cont.get(f).getType(), cont.get(f).getAmount(), (short) f);
|
||||
if (itm.getType() == sellItem.getType()) {
|
||||
//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();
|
||||
remCont.add(add);
|
||||
if (remainingAmount <= 0) {
|
||||
@ -291,6 +329,7 @@ public class CommandTags {
|
||||
for (int f = 0; f <= remCont.size() - 1; 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 (plugin.inventorySaver.hasNormalInventory(p)) {
|
||||
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());
|
||||
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)) {
|
||||
p.getInventory().getItem(remItem.getDurability()).setAmount(0);
|
||||
p.updateInventory();
|
||||
|
@ -29,7 +29,7 @@ public class SellItemTags implements Listener {
|
||||
public void commandTag(CommandTagEvent e){
|
||||
if(e.name.equalsIgnoreCase("sell=")){
|
||||
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 {
|
||||
if (plugin.econ != null) {
|
||||
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
|
||||
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p)));
|
||||
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)
|
||||
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;
|
||||
if (itm != null && itm.getType().equals(sellItem.getType())) {
|
||||
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
|
||||
try {
|
||||
if (!potion.equals("false")) {
|
||||
@ -134,11 +135,26 @@ public class SellItemTags implements Listener {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (id != -1) {
|
||||
if (itm.getDurability() != id) {
|
||||
//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 && 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){
|
||||
//skip if it cannot do unless plugin.debug is enabled
|
||||
plugin.debug(exc,p);
|
||||
|
@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class BungeeTags implements Listener {
|
||||
public class BungeeTags implements Listener {
|
||||
CommandPanels plugin;
|
||||
public BungeeTags(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
114
src/me/rockyhawk/commandpanels/editor/CommandPanelsEditor.java
Normal file
114
src/me/rockyhawk/commandpanels/editor/CommandPanelsEditor.java
Normal 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 "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
29
src/me/rockyhawk/commandpanels/editor/EditorTabComplete.java
Normal file
29
src/me/rockyhawk/commandpanels/editor/EditorTabComplete.java
Normal 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;
|
||||
}
|
||||
}
|
83
src/me/rockyhawk/commandpanels/editor/PanelDownloader.java
Normal file
83
src/me/rockyhawk/commandpanels/editor/PanelDownloader.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -59,7 +59,7 @@ public class Commandpanelrefresher implements Listener {
|
||||
public void run() {
|
||||
int animatevalue = -1;
|
||||
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
|
||||
if(c < refreshDelay){
|
||||
|
@ -28,22 +28,17 @@ public class OpenGUI {
|
||||
Inventory i;
|
||||
if(position == PanelPosition.Top) {
|
||||
String title;
|
||||
if (openType != PanelOpenType.Editor) {
|
||||
if(pconfig.contains("custom-title")) {
|
||||
//used for titles in the custom-title section, for has sections
|
||||
String section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("custom-title"), p);
|
||||
title = plugin.tex.placeholders(panel, position, p, pconfig.getString("custom-title" + section + ".title"));
|
||||
}else {
|
||||
//regular inventory title
|
||||
title = plugin.tex.placeholders(panel, position, p, pconfig.getString("title"));
|
||||
}
|
||||
} else {
|
||||
//editor inventory
|
||||
title = "Editing Panel: " + panel.getName();
|
||||
if(pconfig.contains("custom-title")) {
|
||||
//used for titles in the custom-title section, for has sections
|
||||
String section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("custom-title"), p);
|
||||
title = plugin.tex.placeholders(panel, position, p, pconfig.getString("custom-title" + section + ".title"));
|
||||
}else {
|
||||
//regular inventory title
|
||||
title = plugin.tex.placeholders(panel, position, p, pconfig.getString("title"));
|
||||
}
|
||||
|
||||
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 {
|
||||
i = Bukkit.createInventory(p, InventoryType.valueOf(pconfig.getString("rows")), title);
|
||||
}
|
||||
@ -57,27 +52,25 @@ public class OpenGUI {
|
||||
setItem(null, c, i, p, position);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Set<String> itemList = pconfig.getConfigurationSection("item").getKeys(false);
|
||||
HashSet<Integer> takenSlots = new HashSet<>();
|
||||
for (String item : itemList) {
|
||||
String section = "";
|
||||
//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);
|
||||
//This section is for animations below here: VISUAL ONLY
|
||||
section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("item." + Integer.parseInt(item)), p);
|
||||
//This section is for animations below here: VISUAL ONLY
|
||||
|
||||
//check for if there is animations inside the items section
|
||||
//check for if there is animations inside the items section
|
||||
if (pconfig.contains("item." + item + section + ".animate" + animateValue)) {
|
||||
//check for if it contains the animate that has the animvatevalue
|
||||
if (pconfig.contains("item." + item + section + ".animate" + animateValue)) {
|
||||
//check for if it contains the animate that has the animvatevalue
|
||||
if (pconfig.contains("item." + item + section + ".animate" + animateValue)) {
|
||||
section = section + ".animate" + animateValue;
|
||||
}
|
||||
section = section + ".animate" + animateValue;
|
||||
}
|
||||
}
|
||||
|
||||
//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
|
||||
if(pconfig.contains("item." + item + section + ".itemType")) {
|
||||
@ -96,7 +89,7 @@ public class OpenGUI {
|
||||
takenSlots.add(Integer.parseInt(item));
|
||||
//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
|
||||
if(pconfig.contains("item." + item + section + ".duplicate") && openType != PanelOpenType.Editor) {
|
||||
if(pconfig.contains("item." + item + section + ".duplicate")) {
|
||||
try {
|
||||
String[] duplicateItems = pconfig.getString("item." + item + section + ".duplicate").split(",");
|
||||
for (String tempDupe : duplicateItems) {
|
||||
@ -157,10 +150,8 @@ public class OpenGUI {
|
||||
if (empty.getType() != Material.AIR) {
|
||||
for (int c = 0; getInvSize(i,position) > c; ++c) {
|
||||
if (!takenSlots.contains(c)) {
|
||||
//only place empty items if not editing
|
||||
if(openType != PanelOpenType.Editor) {
|
||||
setItem(empty,c,i,p,position);
|
||||
}
|
||||
//place empty item
|
||||
setItem(empty,c,i,p,position);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -181,9 +172,6 @@ public class OpenGUI {
|
||||
p.openInventory(i);
|
||||
}
|
||||
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) {
|
||||
//openType 0 will just refresh the panel
|
||||
if(position == PanelPosition.Top) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package me.rockyhawk.commandpanels.openpanelsmanager;
|
||||
|
||||
public enum PanelOpenType {
|
||||
Editor,
|
||||
Normal,
|
||||
Return,
|
||||
Refresh
|
||||
|
@ -54,7 +54,10 @@ public class UtilsPanelsLoader implements Listener {
|
||||
public void run() {
|
||||
//end the old panel session and copy a new one
|
||||
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;
|
||||
@ -71,6 +74,11 @@ public class UtilsPanelsLoader implements Listener {
|
||||
|
||||
//close panels and run commands for Top panel
|
||||
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
|
||||
|
@ -32,7 +32,7 @@ public class HotbarItemLoader {
|
||||
|
||||
//return true if found
|
||||
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) {
|
||||
try {
|
||||
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){
|
||||
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
|
||||
if(!p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))){
|
||||
return false;
|
||||
@ -136,8 +136,8 @@ public class HotbarItemLoader {
|
||||
if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm")) && panel.hasHotbarItem()) {
|
||||
ItemStack s = panel.getHotbarItem(p);
|
||||
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);
|
||||
p.getInventory().setItem(Integer.parseInt(panel.getHotbarSection(p).getString("stationary")),s);
|
||||
stationaryItems.get(p.getUniqueId()).addSlot(panel.getHotbarSection(p).getString("stationary"),panel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,16 +5,16 @@ import me.rockyhawk.commandpanels.api.Panel;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class HotbarPlayerManager {
|
||||
public HashMap<Integer,Panel> list = new HashMap<>();
|
||||
public HashMap<String,Panel> list = new HashMap<>();
|
||||
|
||||
public HotbarPlayerManager(){
|
||||
}
|
||||
|
||||
public void addSlot(int slot, Panel panel){
|
||||
public void addSlot(String slot, Panel panel){
|
||||
list.put(slot,panel);
|
||||
}
|
||||
|
||||
public Panel getPanel(int slot){
|
||||
public Panel getPanel(String slot){
|
||||
return list.get(slot).copy();
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ public class UtilsChestSortEvent implements Listener {
|
||||
//If the ChestSort plugin triggers an event
|
||||
try {
|
||||
if (e.getInventory().getType() == InventoryType.PLAYER) {
|
||||
for (int slot : plugin.hotbar.stationaryItems.get(e.getPlayer().getUniqueId()).list.keySet()) {
|
||||
e.setUnmovable(slot);
|
||||
for (String slot : plugin.hotbar.stationaryItems.get(e.getPlayer().getUniqueId()).list.keySet()) {
|
||||
e.setUnmovable(Integer.parseInt(slot));
|
||||
}
|
||||
}
|
||||
}catch(NullPointerException ex){
|
||||
|
@ -48,7 +48,7 @@ public class UtilsOpenWithItem implements Listener {
|
||||
}
|
||||
@EventHandler
|
||||
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 none of the panels have open-with-item
|
||||
return;
|
||||
|
@ -84,6 +84,8 @@ public class Updater implements Listener {
|
||||
HttpURLConnection connection;
|
||||
try {
|
||||
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();
|
||||
cachedLatestVersion = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine().split("\\s")[1];
|
||||
connection.disconnect();
|
||||
|
Loading…
Reference in New Issue
Block a user