mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-24 02:56:17 +01:00
Common config editor
This commit is contained in:
parent
7f3ac8f5a2
commit
9ee17cc27e
@ -46,8 +46,8 @@ public class SongodaCore {
|
|||||||
private static SongodaCore INSTANCE = null;
|
private static SongodaCore INSTANCE = null;
|
||||||
private JavaPlugin piggybackedPlugin;
|
private JavaPlugin piggybackedPlugin;
|
||||||
private final CommandManager commandManager;
|
private final CommandManager commandManager;
|
||||||
private final EventListener loginListener = new EventListener();
|
private EventListener loginListener;
|
||||||
private final ShadedEventListener shadingListener = new ShadedEventListener();
|
private ShadedEventListener shadingListener;
|
||||||
|
|
||||||
public static boolean hasShading() {
|
public static boolean hasShading() {
|
||||||
// sneaky hack to check the package name since maven tries to re-shade all references to the package string
|
// sneaky hack to check the package name since maven tries to re-shade all references to the package string
|
||||||
@ -68,7 +68,9 @@ public class SongodaCore {
|
|||||||
clazz.getMethod("registerPlugin", JavaPlugin.class, int.class, String.class).invoke(null, plugin, pluginID, icon);
|
clazz.getMethod("registerPlugin", JavaPlugin.class, int.class, String.class).invoke(null, plugin, pluginID, icon);
|
||||||
|
|
||||||
if(hasShading()) {
|
if(hasShading()) {
|
||||||
Bukkit.getPluginManager().registerEvents(new ShadedEventListener(), plugin);
|
(INSTANCE = new SongodaCore()).piggybackedPlugin = plugin;
|
||||||
|
INSTANCE.shadingListener = new ShadedEventListener();
|
||||||
|
Bukkit.getPluginManager().registerEvents(INSTANCE.shadingListener, plugin);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored) {
|
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored) {
|
||||||
@ -77,23 +79,33 @@ public class SongodaCore {
|
|||||||
}
|
}
|
||||||
// register ourselves as the SongodaCore service!
|
// register ourselves as the SongodaCore service!
|
||||||
INSTANCE = new SongodaCore(plugin);
|
INSTANCE = new SongodaCore(plugin);
|
||||||
|
INSTANCE.init();
|
||||||
Bukkit.getServicesManager().register(SongodaCore.class, INSTANCE, plugin, ServicePriority.Normal);
|
Bukkit.getServicesManager().register(SongodaCore.class, INSTANCE, plugin, ServicePriority.Normal);
|
||||||
}
|
}
|
||||||
INSTANCE.register(plugin, pluginID, icon);
|
INSTANCE.register(plugin, pluginID, icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SongodaCore(JavaPlugin javaPlugin) {
|
SongodaCore() {
|
||||||
|
commandManager = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
SongodaCore(JavaPlugin javaPlugin) {
|
||||||
piggybackedPlugin = javaPlugin;
|
piggybackedPlugin = javaPlugin;
|
||||||
commandManager = new CommandManager(piggybackedPlugin);
|
commandManager = new CommandManager(piggybackedPlugin);
|
||||||
|
loginListener = new EventListener();
|
||||||
|
shadingListener = new ShadedEventListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
commandManager.registerCommandDynamically(new SongodaCoreCommand(this))
|
commandManager.registerCommandDynamically(new SongodaCoreCommand(this))
|
||||||
.addSubCommand(new SongodaCoreDiagCommand(this));
|
.addSubCommand(new SongodaCoreDiagCommand(this));
|
||||||
Bukkit.getPluginManager().registerEvents(loginListener, javaPlugin);
|
Bukkit.getPluginManager().registerEvents(loginListener, piggybackedPlugin);
|
||||||
Bukkit.getPluginManager().registerEvents(shadingListener, javaPlugin);
|
Bukkit.getPluginManager().registerEvents(shadingListener, piggybackedPlugin);
|
||||||
// we aggressevely want to own this command
|
// we aggressevely want to own this command
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(javaPlugin, ()->{CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager);}, 10 * 60 * 1);
|
Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, ()->{CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager);}, 10 * 60 * 1);
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(javaPlugin, ()->{CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager);}, 20 * 60 * 1);
|
Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, ()->{CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager);}, 20 * 60 * 1);
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(javaPlugin, ()->{CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager);}, 20 * 60 * 2);
|
Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, ()->{CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager);}, 20 * 60 * 2);
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(javaPlugin, ()->registerAllPlugins(), 20 * 60 * 2);
|
Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, ()->registerAllPlugins(), 20 * 60 * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,7 +37,6 @@ public class ClientVersion {
|
|||||||
Bukkit.getScheduler().runTaskLater(SongodaCore.getHijackedPlugin(), ()-> {
|
Bukkit.getScheduler().runTaskLater(SongodaCore.getHijackedPlugin(), ()-> {
|
||||||
if(p.isOnline()) {
|
if(p.isOnline()) {
|
||||||
final int version = protocolsupport.api.ProtocolSupportAPI.getProtocolVersion(p).getId();
|
final int version = protocolsupport.api.ProtocolSupportAPI.getProtocolVersion(p).getId();
|
||||||
System.out.println("ProtoLogin" + version);
|
|
||||||
players.put(p.getUniqueId(), protocolToVersion(version));
|
players.put(p.getUniqueId(), protocolToVersion(version));
|
||||||
}
|
}
|
||||||
}, 20);
|
}, 20);
|
||||||
@ -51,7 +50,6 @@ public class ClientVersion {
|
|||||||
Bukkit.getScheduler().runTaskLater(SongodaCore.getHijackedPlugin(), ()-> {
|
Bukkit.getScheduler().runTaskLater(SongodaCore.getHijackedPlugin(), ()-> {
|
||||||
if(p.isOnline()) {
|
if(p.isOnline()) {
|
||||||
final int version = us.myles.ViaVersion.api.Via.getAPI().getPlayerVersion(p.getUniqueId());
|
final int version = us.myles.ViaVersion.api.Via.getAPI().getPlayerVersion(p.getUniqueId());
|
||||||
System.out.println("ViaLogin" + version);
|
|
||||||
players.put(p.getUniqueId(), protocolToVersion(version));
|
players.put(p.getUniqueId(), protocolToVersion(version));
|
||||||
}
|
}
|
||||||
}, 20);
|
}, 20);
|
||||||
|
@ -818,7 +818,7 @@ public enum CompatibleSounds {
|
|||||||
|
|
||||||
protected /*final*/ Sound sound;
|
protected /*final*/ Sound sound;
|
||||||
protected /*final*/ boolean compatibilityMode;
|
protected /*final*/ boolean compatibilityMode;
|
||||||
protected static final boolean DEBUG = true;
|
protected static final boolean DEBUG = false;
|
||||||
|
|
||||||
private CompatibleSounds() {
|
private CompatibleSounds() {
|
||||||
// This could get risky, since we haven't finished this
|
// This could get risky, since we haven't finished this
|
||||||
|
@ -6,6 +6,7 @@ import java.io.Writer;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A comment for a configuration key
|
* A comment for a configuration key
|
||||||
@ -51,6 +52,11 @@ public class Comment {
|
|||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return lines.isEmpty() ? "" : lines.stream().collect(Collectors.joining("\n"));
|
||||||
|
}
|
||||||
|
|
||||||
public void writeComment(Writer output, int offset, CommentStyle defaultStyle) throws IOException {
|
public void writeComment(Writer output, int offset, CommentStyle defaultStyle) throws IOException {
|
||||||
CommentStyle style = commentStyle != null ? commentStyle : defaultStyle;
|
CommentStyle style = commentStyle != null ? commentStyle : defaultStyle;
|
||||||
int minSpacing = 0, borderSpacing = 0;
|
int minSpacing = 0, borderSpacing = 0;
|
||||||
|
@ -177,6 +177,15 @@ public class ConfigSection extends MemoryConfiguration {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getCommentString(@NotNull String path) {
|
||||||
|
Comment result = root.configComments.get(fullPath + path);
|
||||||
|
if (result == null) {
|
||||||
|
result = root.defaultComments.get(fullPath + path);
|
||||||
|
}
|
||||||
|
return result != null ? result.toString() : null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addDefault(@NotNull String path, @Nullable Object value) {
|
public void addDefault(@NotNull String path, @Nullable Object value) {
|
||||||
root.defaults.put(fullPath + path, value);
|
root.defaults.put(fullPath + path, value);
|
||||||
|
@ -1,33 +1,180 @@
|
|||||||
package com.songoda.core.configuration.editor;
|
package com.songoda.core.configuration.editor;
|
||||||
|
|
||||||
|
import com.songoda.core.compatibility.LegacyMaterials;
|
||||||
|
import com.songoda.core.gui.Gui;
|
||||||
|
import com.songoda.core.gui.GuiUtils;
|
||||||
import com.songoda.core.gui.SimplePagedGui;
|
import com.songoda.core.gui.SimplePagedGui;
|
||||||
|
import com.songoda.core.input.ChatPrompt;
|
||||||
|
import com.songoda.core.utils.ItemUtils;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.MemoryConfiguration;
|
import org.bukkit.configuration.MemoryConfiguration;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class ConfigEditorGui extends SimplePagedGui {
|
public class ConfigEditorGui extends SimplePagedGui {
|
||||||
|
|
||||||
|
final JavaPlugin plugin;
|
||||||
|
final String file;
|
||||||
final MemoryConfiguration config;
|
final MemoryConfiguration config;
|
||||||
List<String> keys = new ArrayList();
|
final ConfigurationSection node;
|
||||||
|
Method configSection_getCommentString = null;
|
||||||
List<String> sections = new ArrayList();
|
List<String> sections = new ArrayList();
|
||||||
List<String> settings = new ArrayList();
|
List<String> settings = new ArrayList();
|
||||||
|
|
||||||
public ConfigEditorGui(String file, MemoryConfiguration config) {
|
public ConfigEditorGui(JavaPlugin plugin, Gui parent, String file, MemoryConfiguration config) {
|
||||||
this(file, config, config);
|
this(plugin, parent, file, config, config);
|
||||||
|
setOnClose((gui) -> save());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigEditorGui(String file, MemoryConfiguration config, MemoryConfiguration node) {
|
public ConfigEditorGui(JavaPlugin plugin, Gui parent, String file, MemoryConfiguration config, ConfigurationSection node) {
|
||||||
|
super(parent);
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.file = file;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
this.node = node;
|
||||||
|
this.blankItem = GuiUtils.getBorderItem(LegacyMaterials.LIGHT_GRAY_STAINED_GLASS_PANE);
|
||||||
|
|
||||||
|
// if we have a ConfigSection, we can also grab comments
|
||||||
|
try {
|
||||||
|
configSection_getCommentString = node.getClass().getDeclaredMethod("getCommentString", String.class);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// decorate header
|
||||||
|
this.setTitle(ChatColor.DARK_BLUE + file);
|
||||||
|
this.setUseHeader(true);
|
||||||
|
headerBackItem = footerBackItem = GuiUtils.getBorderItem(LegacyMaterials.GRAY_STAINED_GLASS_PANE.getItem());
|
||||||
|
final String path = node.getCurrentPath();
|
||||||
|
this.setItem(4, configItem(LegacyMaterials.FILLED_MAP, path, config, path, null));
|
||||||
|
this.setButton(8, GuiUtils.createButtonItem(LegacyMaterials.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
|
||||||
|
|
||||||
|
// compile list of settings
|
||||||
for (String key : node.getKeys(false)) {
|
for (String key : node.getKeys(false)) {
|
||||||
if (node.isConfigurationSection(key)) {
|
if (node.isConfigurationSection(key)) {
|
||||||
sections.add(key);
|
sections.add(key);
|
||||||
keys.add(key); // sections listed first
|
|
||||||
} else {
|
} else {
|
||||||
settings.add(key);
|
settings.add(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
keys.addAll(settings); // normal settings next
|
|
||||||
|
|
||||||
// next we need to display the config settings, with the ability to browse more pages
|
// next we need to display the config settings
|
||||||
|
int index = 9;
|
||||||
|
for (final String sectionKey : sections) {
|
||||||
|
this.setButton(index++, configItem(LegacyMaterials.WRITABLE_BOOK, ChatColor.YELLOW + sectionKey, node, sectionKey, "Click to open this section"),
|
||||||
|
(event) -> event.manager.showGUI(event.player, new ConfigEditorGui(plugin, this, file, config, node.getConfigurationSection(sectionKey))));
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo: display values of settings in gui, too
|
||||||
|
// now display individual settings
|
||||||
|
for (final String settingKey : settings) {
|
||||||
|
final Object val = node.get(settingKey);
|
||||||
|
if(val == null) continue;
|
||||||
|
else if(val instanceof Boolean) {
|
||||||
|
// toggle switch
|
||||||
|
this.setButton(index, configItem(LegacyMaterials.LEVER, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf((Boolean) val), "Click to toggle this setting"),
|
||||||
|
(event) -> this.toggle(event.slot, settingKey));
|
||||||
|
if((Boolean) val) {
|
||||||
|
this.highlightItem(index);
|
||||||
|
}
|
||||||
|
} else if (isNumber(val)) {
|
||||||
|
// number dial
|
||||||
|
this.setButton(index, configItem(LegacyMaterials.CLOCK, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf((Number) val), "Click to edit this setting"),
|
||||||
|
(event) -> {
|
||||||
|
event.gui.exit();
|
||||||
|
ChatPrompt prompt = ChatPrompt.showPrompt(plugin, event.player, "Enter your new value.", response -> {
|
||||||
|
if (!setNumber(event.slot, settingKey, response.getMessage().trim())) {
|
||||||
|
event.player.sendMessage(ChatColor.RED + "Error: \"" + response.getMessage().trim() + "\" is not a number!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
prompt.setOnClose(() -> event.manager.showGUI(event.player, this));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void toggle(int clickCell, String path) {
|
||||||
|
boolean val = !node.getBoolean(path);
|
||||||
|
node.set(path, val);
|
||||||
|
if(val) {
|
||||||
|
inventory.setItem(clickCell, ItemUtils.addGlow(inventory.getItem(clickCell)));
|
||||||
|
} else {
|
||||||
|
removeHighlight(clickCell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean setNumber(int clickCell, String path, String input) {
|
||||||
|
try {
|
||||||
|
if (node.isInt(path)) {
|
||||||
|
node.set(path, Integer.parseInt(input));
|
||||||
|
} else if (node.isDouble(path)) {
|
||||||
|
node.set(path, Double.parseDouble(input));
|
||||||
|
} else if (node.isLong(path)) {
|
||||||
|
node.set(path, Long.parseLong(input));
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void save() {
|
||||||
|
// could also check and call saveChanges()
|
||||||
|
if (config instanceof FileConfiguration) {
|
||||||
|
try {
|
||||||
|
((FileConfiguration) config).save(new File(plugin.getDataFolder(), file));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "Failed to save config changes to " + file, ex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
plugin.reloadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isNumber(Object value) {
|
||||||
|
return value != null && (
|
||||||
|
value instanceof Long
|
||||||
|
|| value instanceof Integer
|
||||||
|
|| value instanceof Float
|
||||||
|
|| value instanceof Double);
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack configItem(LegacyMaterials type, String name, ConfigurationSection node, String path, String def) {
|
||||||
|
String[] info = null;
|
||||||
|
if (configSection_getCommentString != null) {
|
||||||
|
try {
|
||||||
|
Object comment = configSection_getCommentString.invoke(config, path);
|
||||||
|
if (comment != null) {
|
||||||
|
info = comment.toString().split("\n");
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return GuiUtils.createButtonItem(LegacyMaterials.FILLED_MAP, path, info != null ? info : (def != null ? def.split("\n") : null));
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack configItem(LegacyMaterials type, String name, ConfigurationSection node, String path, String value, String def) {
|
||||||
|
if(value == null) value = "";
|
||||||
|
String[] info = null;
|
||||||
|
if (configSection_getCommentString != null) {
|
||||||
|
try {
|
||||||
|
Object comment = configSection_getCommentString.invoke(config, path);
|
||||||
|
if (comment != null) {
|
||||||
|
info = (value + "\n" + comment.toString()).split("\n");
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return GuiUtils.createButtonItem(LegacyMaterials.FILLED_MAP, path, info != null ? info : (def != null ? (value + "\n" + def).split("\n") : null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.configuration.MemoryConfiguration;
|
import org.bukkit.configuration.MemoryConfiguration;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit all configuration files for a specific plugin
|
* Edit all configuration files for a specific plugin
|
||||||
@ -25,7 +24,7 @@ import org.bukkit.plugin.Plugin;
|
|||||||
*/
|
*/
|
||||||
public class PluginConfigGui extends SimplePagedGui {
|
public class PluginConfigGui extends SimplePagedGui {
|
||||||
|
|
||||||
final Plugin plugin;
|
final JavaPlugin plugin;
|
||||||
LinkedHashMap<String, MemoryConfiguration> configs = new LinkedHashMap();
|
LinkedHashMap<String, MemoryConfiguration> configs = new LinkedHashMap();
|
||||||
|
|
||||||
public PluginConfigGui(SongodaPlugin plugin) {
|
public PluginConfigGui(SongodaPlugin plugin) {
|
||||||
@ -47,11 +46,11 @@ public class PluginConfigGui extends SimplePagedGui {
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginConfigGui(Plugin plugin) {
|
public PluginConfigGui(JavaPlugin plugin) {
|
||||||
this(plugin, null);
|
this(plugin, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginConfigGui(Plugin plugin, Gui parent) {
|
public PluginConfigGui(JavaPlugin plugin, Gui parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
|
||||||
@ -80,6 +79,7 @@ public class PluginConfigGui extends SimplePagedGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
|
this.blankItem = GuiUtils.getBorderItem(LegacyMaterials.LIGHT_GRAY_STAINED_GLASS_PANE);
|
||||||
|
|
||||||
// decorate header
|
// decorate header
|
||||||
this.setTitle(ChatColor.DARK_BLUE + plugin.getName() + " Plugin Config");
|
this.setTitle(ChatColor.DARK_BLUE + plugin.getName() + " Plugin Config");
|
||||||
@ -91,7 +91,7 @@ public class PluginConfigGui extends SimplePagedGui {
|
|||||||
int i = 9;
|
int i = 9;
|
||||||
for (Map.Entry<String, MemoryConfiguration> config : configs.entrySet()) {
|
for (Map.Entry<String, MemoryConfiguration> config : configs.entrySet()) {
|
||||||
this.setButton(i++, GuiUtils.createButtonItem(LegacyMaterials.BOOK, ChatColor.YELLOW + config.getKey(), "Click to edit this config"),
|
this.setButton(i++, GuiUtils.createButtonItem(LegacyMaterials.BOOK, ChatColor.YELLOW + config.getKey(), "Click to edit this config"),
|
||||||
(event) -> event.manager.showGUI(event.player, new ConfigEditorGui(config.getKey(), config.getValue())));
|
(event) -> event.manager.showGUI(event.player, new ConfigEditorGui(plugin, this, config.getKey(), config.getValue())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ public class GuiManager {
|
|||||||
final Plugin plugin;
|
final Plugin plugin;
|
||||||
final UUID uuid = UUID.randomUUID(); // manager tracking to fix weird bugs from lazy programming
|
final UUID uuid = UUID.randomUUID(); // manager tracking to fix weird bugs from lazy programming
|
||||||
final GuiListener listener = new GuiListener(this);
|
final GuiListener listener = new GuiListener(this);
|
||||||
final Map<Player, Inventory> openInventories = new HashMap();
|
final Map<Player, Gui> openInventories = new HashMap();
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
private boolean shutdown = false;
|
private boolean shutdown = false;
|
||||||
|
|
||||||
@ -70,10 +70,14 @@ public class GuiManager {
|
|||||||
} else if (!initialized) {
|
} else if (!initialized) {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
Gui openInv = openInventories.get(player);
|
||||||
|
if(openInv != null) {
|
||||||
|
openInv.open = false;
|
||||||
|
}
|
||||||
Inventory inv = gui.generateInventory(this);
|
Inventory inv = gui.generateInventory(this);
|
||||||
player.openInventory(inv);
|
player.openInventory(inv);
|
||||||
gui.onOpen(this, player);
|
gui.onOpen(this, player);
|
||||||
openInventories.put(player, inv);
|
openInventories.put(player, gui);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showPopup(Player player, String message) {
|
public void showPopup(Player player, String message) {
|
||||||
@ -160,6 +164,9 @@ public class GuiManager {
|
|||||||
if (openInv.getHolder() != null && openInv.getHolder() instanceof GuiHolder
|
if (openInv.getHolder() != null && openInv.getHolder() instanceof GuiHolder
|
||||||
&& ((GuiHolder) openInv.getHolder()).manager.uuid.equals(manager.uuid)) {
|
&& ((GuiHolder) openInv.getHolder()).manager.uuid.equals(manager.uuid)) {
|
||||||
Gui gui = ((GuiHolder) openInv.getHolder()).getGUI();
|
Gui gui = ((GuiHolder) openInv.getHolder()).getGUI();
|
||||||
|
if(!gui.open) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final Player player = (Player) event.getPlayer();
|
final Player player = (Player) event.getPlayer();
|
||||||
if (!gui.allowDropItems) {
|
if (!gui.allowDropItems) {
|
||||||
player.setItemOnCursor(null);
|
player.setItemOnCursor(null);
|
||||||
|
@ -53,6 +53,23 @@ public class SimplePagedGui extends Gui {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SimplePagedGui setItem(int row, int col, ItemStack item) {
|
||||||
|
return setItem(col + row * 9, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SimplePagedGui setItem(int cell, ItemStack item) {
|
||||||
|
// set the cell relative to the current page
|
||||||
|
int cellIndex = page == 1 || (useHeader && cell < 9) ? cell : (cell + (page - 1) * (rowsPerPage * 9));
|
||||||
|
|
||||||
|
cellItems.put(cellIndex, item);
|
||||||
|
if (open && cell >= 0 && cell < inventory.getSize()) {
|
||||||
|
inventory.setItem(cell, item);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void nextPage() {
|
public void nextPage() {
|
||||||
if (page < pages) {
|
if (page < pages) {
|
||||||
@ -109,7 +126,7 @@ public class SimplePagedGui extends Gui {
|
|||||||
int maxRows = (int) Math.ceil(maxCellSlot / 9.);
|
int maxRows = (int) Math.ceil(maxCellSlot / 9.);
|
||||||
pages = (int) Math.ceil(maxRows / rowsPerPage);
|
pages = (int) Math.ceil(maxRows / rowsPerPage);
|
||||||
page = 1;
|
page = 1;
|
||||||
this.setRows(maxRows + 1);
|
this.setRows(maxRows + (useHeader ? 2 : 1));
|
||||||
|
|
||||||
// create inventory view
|
// create inventory view
|
||||||
final int cells = rows * 9;
|
final int cells = rows * 9;
|
||||||
@ -148,8 +165,7 @@ public class SimplePagedGui extends Gui {
|
|||||||
// footer row
|
// footer row
|
||||||
conditionals = conditionalButtons.get(cell - (rows * 9));
|
conditionals = conditionalButtons.get(cell - (rows * 9));
|
||||||
} else {
|
} else {
|
||||||
int startCell = useHeader ? 9 : 0;
|
int cellIndex = page == 1 || (useHeader && cell < 9) ? cell : (cell + (page - 1) * (rowsPerPage * 9));
|
||||||
int cellIndex = startCell + (page - 1) * rowsPerPage;
|
|
||||||
conditionals = conditionalButtons.get(cellIndex);
|
conditionals = conditionalButtons.get(cellIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user