diff --git a/pom.xml b/pom.xml
index 09229c9b..730d6fc4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -83,6 +83,16 @@
json-simple
1.1
+
+ org.jetbrains
+ annotations
+ 13.0
+
+
+ org.yaml
+ snakeyaml
+ 1.25
+
org.slf4j
slf4j-api
diff --git a/src/main/java/com/songoda/core/gui/GuiUtils.java b/src/main/java/com/songoda/core/gui/GuiUtils.java
index 4baf66dd..d19027b0 100644
--- a/src/main/java/com/songoda/core/gui/GuiUtils.java
+++ b/src/main/java/com/songoda/core/gui/GuiUtils.java
@@ -172,4 +172,17 @@ public class GuiUtils {
item.setItemMeta(meta);
return item;
}
+
+ public static void mirrorFill(Gui gui, int row, int col, boolean mirrorRow, boolean mirrorCol, ItemStack item) {
+ gui.setItem(row, col, item);
+ if (mirrorRow) {
+ gui.setItem(gui.rows - row - 1, col, item);
+ }
+ if (mirrorCol) {
+ gui.setItem(row, 8 - col, item);
+ }
+ if (mirrorRow && mirrorCol) {
+ gui.setItem(gui.rows - row - 1, 8 - col, item);
+ }
+ }
}
diff --git a/src/main/java/com/songoda/core/input/ChatPrompt.java b/src/main/java/com/songoda/core/input/ChatPrompt.java
index efedc714..2b4c3170 100644
--- a/src/main/java/com/songoda/core/input/ChatPrompt.java
+++ b/src/main/java/com/songoda/core/input/ChatPrompt.java
@@ -10,6 +10,9 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
+import java.util.logging.Level;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.Plugin;
public class ChatPrompt implements Listener {
@@ -18,6 +21,7 @@ public class ChatPrompt implements Listener {
private final ChatConfirmHandler handler;
private OnClose onClose = null;
+ private OnCancel onCancel = null;
private Listener listener;
private ChatPrompt(Player player, ChatConfirmHandler hander) {
@@ -54,9 +58,14 @@ public class ChatPrompt implements Listener {
return this;
}
+ public ChatPrompt setOnCancel(OnCancel onCancel) {
+ this.onCancel = onCancel;
+ return this;
+ }
+
private void startListener(Plugin plugin) {
this.listener = new Listener() {
- @EventHandler
+ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
public void onChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
if (!ChatPrompt.isRegistered(player)) return;
@@ -66,7 +75,11 @@ public class ChatPrompt implements Listener {
ChatConfirmEvent chatConfirmEvent = new ChatConfirmEvent(player, event.getMessage());
- handler.onChat(chatConfirmEvent);
+ try {
+ handler.onChat(chatConfirmEvent);
+ } catch (Throwable t) {
+ plugin.getLogger().log(Level.SEVERE, "Failed to process chat prompt", t);
+ }
if (onClose != null) {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () ->
@@ -74,6 +87,25 @@ public class ChatPrompt implements Listener {
}
HandlerList.unregisterAll(listener);
}
+ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
+ public void onCancel(PlayerCommandPreprocessEvent event) {
+ Player player = event.getPlayer();
+ if (!ChatPrompt.isRegistered(player)) return;
+
+ ChatPrompt.unregister(player);
+
+ if(event.getMessage().toLowerCase().startsWith("/cancel"))
+ event.setCancelled(true);
+
+ if (onCancel != null) {
+ plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () ->
+ onCancel.onCancel(), 0L);
+ } else if (onClose != null) {
+ plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () ->
+ onClose.onClose(), 0L);
+ }
+ HandlerList.unregisterAll(listener);
+ }
};
Bukkit.getPluginManager().registerEvents(listener, plugin);
@@ -87,6 +119,10 @@ public class ChatPrompt implements Listener {
void onClose();
}
+ public static interface OnCancel {
+ void onCancel();
+ }
+
public static class ChatConfirmEvent {
private final Player player;
diff --git a/src/main/java/com/songoda/core/settings/Config.java b/src/main/java/com/songoda/core/settings/Config.java
index b23eb33f..4c38963d 100644
--- a/src/main/java/com/songoda/core/settings/Config.java
+++ b/src/main/java/com/songoda/core/settings/Config.java
@@ -301,6 +301,7 @@ public class Config {
if (!plugin.getDataFolder().exists())
plugin.getDataFolder().mkdir();
BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
+
writer.write(config.toString());
writer.flush();
writer.close();
diff --git a/src/main/java/com/songoda/core/settings/editor/ConfigEditorGUI.java b/src/main/java/com/songoda/core/settings/editor/ConfigEditorGUI.java
index 5cb6f44e..20be0c18 100644
--- a/src/main/java/com/songoda/core/settings/editor/ConfigEditorGUI.java
+++ b/src/main/java/com/songoda/core/settings/editor/ConfigEditorGUI.java
@@ -14,6 +14,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import us.myles.viaversion.libs.bungeecordchat.api.ChatColor;
public class ConfigEditorGUI extends AbstractGUI {
@@ -69,12 +70,16 @@ public class ConfigEditorGUI extends AbstractGUI {
material = LegacyMaterials.CLOCK.getMaterial();
registerClickable(j, ((player1, inventory1, cursor, slot, type) -> {
ChatPrompt prompt = ChatPrompt.showPrompt(plugin, player, "Enter your new value.", event -> {
- if (config.isInt(setting.getCompleteKey())) {
- config.set(setting.getCompleteKey(), Integer.parseInt(event.getMessage().trim()));
- } else if (config.isDouble(setting.getCompleteKey())) {
- config.set(setting.getCompleteKey(), Double.parseDouble(event.getMessage().trim()));
- } else if (config.isLong(setting.getCompleteKey())) {
- config.set(setting.getCompleteKey(), Long.parseLong(event.getMessage().trim()));
+ try {
+ if (config.isInt(setting.getCompleteKey())) {
+ config.set(setting.getCompleteKey(), Integer.parseInt(event.getMessage().trim()));
+ } else if (config.isDouble(setting.getCompleteKey())) {
+ config.set(setting.getCompleteKey(), Double.parseDouble(event.getMessage().trim()));
+ } else if (config.isLong(setting.getCompleteKey())) {
+ config.set(setting.getCompleteKey(), Long.parseLong(event.getMessage().trim()));
+ }
+ } catch (NumberFormatException e) {
+ player1.sendMessage(ChatColor.RED + "Error: \"" + event.getMessage().trim() + "\" is not a number!");
}
});
prompt.setOnClose(() -> init("Settings Editor", inventory.getSize()));
diff --git a/src/main/java/com/songoda/core/settings/editor/ConfigListEditorGUI.java b/src/main/java/com/songoda/core/settings/editor/ConfigListEditorGUI.java
index b05ebe82..2e6d01d3 100644
--- a/src/main/java/com/songoda/core/settings/editor/ConfigListEditorGUI.java
+++ b/src/main/java/com/songoda/core/settings/editor/ConfigListEditorGUI.java
@@ -4,7 +4,6 @@ import com.songoda.core.input.ChatPrompt;
import com.songoda.core.compatibility.LegacyMaterials;
import com.songoda.core.settings.Setting;
import com.songoda.core.utils.gui.AbstractGUI;
-import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
diff --git a/src/main/java/com/songoda/core/utils/gui/AbstractGUI.java b/src/main/java/com/songoda/core/utils/gui/AbstractGUI.java
index 85aaa762..8ced3034 100644
--- a/src/main/java/com/songoda/core/utils/gui/AbstractGUI.java
+++ b/src/main/java/com/songoda/core/utils/gui/AbstractGUI.java
@@ -20,6 +20,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.util.*;
+@Deprecated
public abstract class AbstractGUI implements Listener {
private static boolean listenersInitialized = false;
diff --git a/src/main/java/com/songoda/core/utils/gui/Clickable.java b/src/main/java/com/songoda/core/utils/gui/Clickable.java
index fa169be8..a640495f 100644
--- a/src/main/java/com/songoda/core/utils/gui/Clickable.java
+++ b/src/main/java/com/songoda/core/utils/gui/Clickable.java
@@ -5,6 +5,7 @@ import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
+@Deprecated
public interface Clickable {
void Clickable(Player player, Inventory inventory, ItemStack cursor, int slot, ClickType type);
diff --git a/src/main/java/com/songoda/core/utils/gui/OnClose.java b/src/main/java/com/songoda/core/utils/gui/OnClose.java
index 684ce9ce..c02223c7 100644
--- a/src/main/java/com/songoda/core/utils/gui/OnClose.java
+++ b/src/main/java/com/songoda/core/utils/gui/OnClose.java
@@ -3,6 +3,7 @@ package com.songoda.core.utils.gui;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
+@Deprecated
public interface OnClose {
void OnClose(Player player, Inventory inventory);
diff --git a/src/main/java/com/songoda/core/utils/gui/Range.java b/src/main/java/com/songoda/core/utils/gui/Range.java
index 22e0620a..d993c424 100644
--- a/src/main/java/com/songoda/core/utils/gui/Range.java
+++ b/src/main/java/com/songoda/core/utils/gui/Range.java
@@ -1,10 +1,10 @@
package com.songoda.core.utils.gui;
-import com.songoda.core.SongodaCore;
import com.songoda.core.compatibility.ServerVersion;
import org.bukkit.Sound;
import org.bukkit.event.inventory.ClickType;
+@Deprecated
public class Range {
private int min;