forked from Upstream/CommandPanels
3.19.0.0
This commit is contained in:
parent
39cf3de5ef
commit
3712dc76ff
.idea
resource
src/me/rockyhawk/commandpanels
CommandPanels.javaUtils.java
api
classresources
commands
commandtags/tags/standard
editor
CPEventHandler.javaCommandPanelsEditor.javaCommandPanelsEditorCommand.javaCommandPanelsEditorMain.javaCommandPanelsEditorTabComplete.javaEditorSettings.javaEditorTabComplete.javaPanelDownloader.java
interactives
openpanelsmanager
openwithitem
@ -7,7 +7,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>
|
@ -1,4 +1,4 @@
|
||||
version: 3.18.6.2
|
||||
version: 3.19.0.0
|
||||
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);
|
||||
|
@ -41,7 +41,7 @@ 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;
|
||||
@ -55,6 +55,7 @@ public class GetCustomHeads {
|
||||
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]"));
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
110
src/me/rockyhawk/commandpanels/editor/CommandPanelsEditor.java
Normal file
110
src/me/rockyhawk/commandpanels/editor/CommandPanelsEditor.java
Normal file
@ -0,0 +1,110 @@
|
||||
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")) {
|
||||
//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;
|
||||
}
|
||||
}
|
61
src/me/rockyhawk/commandpanels/editor/PanelDownloader.java
Normal file
61
src/me/rockyhawk/commandpanels/editor/PanelDownloader.java
Normal file
@ -0,0 +1,61 @@
|
||||
package me.rockyhawk.commandpanels.editor;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
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 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";
|
||||
}
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
@ -63,21 +58,19 @@ public class OpenGUI {
|
||||
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,13 +172,14 @@ 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) {
|
||||
plugin.legacy.setStorageContents(p, plugin.legacy.getStorageContents(i));
|
||||
Inventory topInventory = p.getOpenInventory().getTopInventory();
|
||||
ItemStack[] items = p.getOpenInventory().getTopInventory().getContents();
|
||||
for (int slot = 0; slot < items.length; ++slot) {
|
||||
topInventory.setItem(slot, items[slot]);
|
||||
}
|
||||
}
|
||||
} else if (openType == PanelOpenType.Return) {
|
||||
//will return the inventory, not opening it at all
|
||||
|
@ -1,7 +1,6 @@
|
||||
package me.rockyhawk.commandpanels.openpanelsmanager;
|
||||
|
||||
public enum PanelOpenType {
|
||||
Editor,
|
||||
Normal,
|
||||
Return,
|
||||
Refresh
|
||||
|
@ -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){
|
||||
|
Loading…
Reference in New Issue
Block a user