From b90c431891f21e873bdc9f12f6ec1fe23a8cf9c6 Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 4 Jun 2020 20:40:21 +0200 Subject: [PATCH 001/213] Rename groupId and main package to "me.filoghost.chestcommands" --- Plugin/pom.xml | 6 +- .../chestcommands/ChestCommands.java | 55 ++++++++++--------- .../filoghost/chestcommands/Permissions.java | 2 +- .../chestcommands/SimpleUpdater.java | 2 +- .../chestcommands/api/ChestCommandsAPI.java | 5 +- .../chestcommands/api/ClickHandler.java | 2 +- .../filoghost/chestcommands/api/Icon.java | 9 +-- .../filoghost/chestcommands/api/IconMenu.java | 11 ++-- .../chestcommands/bridge/BarAPIBridge.java | 2 +- .../chestcommands/bridge/EconomyBridge.java | 5 +- .../bridge/PlaceholderAPIBridge.java | 2 +- .../bridge/bungee/BungeeCordUtils.java | 5 +- .../chestcommands/command/CommandHandler.java | 17 +++--- .../command/framework/CommandException.java | 2 +- .../command/framework/CommandFramework.java | 2 +- .../command/framework/CommandValidate.java | 2 +- .../config/AsciiPlaceholders.java | 13 +++-- .../chestcommands/config/ConfigUtil.java | 4 +- .../filoghost/chestcommands/config/Lang.java | 6 +- .../chestcommands/config/Settings.java | 6 +- .../config/yaml/PluginConfig.java | 2 +- .../config/yaml/SpecialConfig.java | 5 +- .../exception/FormatException.java | 2 +- .../chestcommands/internal/BoundItem.java | 7 ++- .../chestcommands/internal/CachedGetters.java | 4 +- .../internal/CommandsClickHandler.java | 9 +-- .../internal/ExtendedIconMenu.java | 15 ++--- .../chestcommands/internal/MenuData.java | 7 ++- .../internal/MenuInventoryHolder.java | 7 ++- .../chestcommands/internal/RequiredItem.java | 5 +- .../chestcommands/internal/Variable.java | 5 +- .../internal/VariableManager.java | 5 +- .../internal/icon/ExtendedIcon.java | 19 ++++--- .../internal/icon/IconCommand.java | 7 ++- .../icon/command/BroadcastIconCommand.java | 7 ++- .../icon/command/ConsoleIconCommand.java | 5 +- .../icon/command/DragonBarIconCommand.java | 11 ++-- .../icon/command/GiveIconCommand.java | 9 +-- .../icon/command/GiveMoneyIconCommand.java | 9 +-- .../internal/icon/command/OpIconCommand.java | 5 +- .../icon/command/OpenIconCommand.java | 9 +-- .../icon/command/PlayerIconCommand.java | 5 +- .../icon/command/ServerIconCommand.java | 7 ++- .../icon/command/SoundIconCommand.java | 7 ++- .../icon/command/TellIconCommand.java | 7 ++- .../listener/CommandListener.java | 9 +-- .../listener/InventoryListener.java | 17 +++--- .../chestcommands/listener/JoinListener.java | 7 ++- .../chestcommands/listener/SignListener.java | 16 +++--- .../serializer/CommandSerializer.java | 12 ++-- .../serializer/EnchantmentSerializer.java | 7 ++- .../serializer/IconSerializer.java | 38 ++++++------- .../serializer/MenuSerializer.java | 30 +++++----- .../chestcommands/task/ErrorLoggerTask.java | 11 ++-- .../task/ExecuteCommandsTask.java | 5 +- .../chestcommands/task/RefreshMenusTask.java | 9 +-- .../chestcommands/util/BukkitUtils.java | 2 +- .../util/CaseInsensitiveMap.java | 2 +- .../chestcommands/util/ClickType.java | 2 +- .../chestcommands/util/ErrorLogger.java | 2 +- .../chestcommands/util/FormatUtils.java | 5 +- .../chestcommands/util/InventoryUtils.java | 2 +- .../chestcommands/util/ItemStackReader.java | 5 +- .../chestcommands/util/ItemUtils.java | 5 +- .../chestcommands/util/MaterialsRegistry.java | 2 +- .../chestcommands/util/MenuUtils.java | 7 ++- .../chestcommands/util/NMSUtils.java | 2 +- .../chestcommands/util/StringUtils.java | 2 +- .../filoghost/chestcommands/util/Utils.java | 2 +- .../chestcommands/util/Validate.java | 2 +- .../chestcommands/util/nbt/NBTByte.java | 2 +- .../chestcommands/util/nbt/NBTByteArray.java | 2 +- .../chestcommands/util/nbt/NBTCompound.java | 2 +- .../chestcommands/util/nbt/NBTDouble.java | 2 +- .../chestcommands/util/nbt/NBTFloat.java | 2 +- .../chestcommands/util/nbt/NBTInt.java | 2 +- .../chestcommands/util/nbt/NBTIntArray.java | 2 +- .../chestcommands/util/nbt/NBTList.java | 2 +- .../chestcommands/util/nbt/NBTLong.java | 2 +- .../chestcommands/util/nbt/NBTLongArray.java | 2 +- .../chestcommands/util/nbt/NBTShort.java | 2 +- .../chestcommands/util/nbt/NBTString.java | 2 +- .../chestcommands/util/nbt/NBTTag.java | 2 +- .../chestcommands/util/nbt/NBTType.java | 2 +- .../nbt/parser/MojangsonParseException.java | 2 +- .../util/nbt/parser/MojangsonParser.java | 6 +- Plugin/src/main/resources/plugin.yml | 2 +- pom.xml | 4 +- 88 files changed, 313 insertions(+), 270 deletions(-) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/ChestCommands.java (82%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/Permissions.java (92%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/SimpleUpdater.java (96%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/api/ChestCommandsAPI.java (91%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/api/ClickHandler.java (92%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/api/Icon.java (93%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/api/IconMenu.java (86%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/bridge/BarAPIBridge.java (93%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/bridge/EconomyBridge.java (94%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/bridge/PlaceholderAPIBridge.java (95%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/bridge/bungee/BungeeCordUtils.java (91%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/command/CommandHandler.java (88%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/command/framework/CommandException.java (90%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/command/framework/CommandFramework.java (93%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/command/framework/CommandValidate.java (94%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/config/AsciiPlaceholders.java (88%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/config/ConfigUtil.java (92%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/config/Lang.java (87%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/config/Settings.java (84%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/config/yaml/PluginConfig.java (93%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/config/yaml/SpecialConfig.java (93%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/exception/FormatException.java (91%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/BoundItem.java (88%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/CachedGetters.java (88%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/CommandsClickHandler.java (82%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/ExtendedIconMenu.java (87%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/MenuData.java (89%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/MenuInventoryHolder.java (87%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/RequiredItem.java (92%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/Variable.java (90%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/VariableManager.java (87%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/icon/ExtendedIcon.java (88%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/icon/IconCommand.java (83%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/icon/command/BroadcastIconCommand.java (81%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/icon/command/ConsoleIconCommand.java (85%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/icon/command/DragonBarIconCommand.java (80%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/icon/command/GiveIconCommand.java (82%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/icon/command/GiveMoneyIconCommand.java (84%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/icon/command/OpIconCommand.java (85%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java (84%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/icon/command/PlayerIconCommand.java (84%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/icon/command/ServerIconCommand.java (80%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/icon/command/SoundIconCommand.java (87%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/internal/icon/command/TellIconCommand.java (80%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/listener/CommandListener.java (84%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/listener/InventoryListener.java (84%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/listener/JoinListener.java (89%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/listener/SignListener.java (84%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/serializer/CommandSerializer.java (89%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/serializer/EnchantmentSerializer.java (93%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/serializer/IconSerializer.java (85%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/serializer/MenuSerializer.java (83%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/task/ErrorLoggerTask.java (82%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/task/ExecuteCommandsTask.java (87%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/task/RefreshMenusTask.java (84%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/BukkitUtils.java (97%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/CaseInsensitiveMap.java (94%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/ClickType.java (93%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/ErrorLogger.java (92%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/FormatUtils.java (93%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/InventoryUtils.java (94%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/ItemStackReader.java (93%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/ItemUtils.java (97%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/MaterialsRegistry.java (96%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/MenuUtils.java (78%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/NMSUtils.java (93%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/StringUtils.java (94%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/Utils.java (93%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/Validate.java (92%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/nbt/NBTByte.java (94%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/nbt/NBTByteArray.java (95%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/nbt/NBTCompound.java (99%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/nbt/NBTDouble.java (94%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/nbt/NBTFloat.java (94%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/nbt/NBTInt.java (94%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/nbt/NBTIntArray.java (96%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/nbt/NBTList.java (98%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/nbt/NBTLong.java (94%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/nbt/NBTLongArray.java (96%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/nbt/NBTShort.java (94%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/nbt/NBTString.java (95%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/nbt/NBTTag.java (95%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/nbt/NBTType.java (98%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java (91%) rename Plugin/src/main/java/{com/gmail => me}/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java (98%) diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 9c9a47a..4bf959d 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -4,9 +4,9 @@ 4.0.0 - com.gmail.filoghost.chestcommands + me.filoghost.chestcommands chestcommands-parent - 3.3.1 + 4.0-SNAPSHOT chestcommands-plugin @@ -107,7 +107,7 @@ org.bstats - com.gmail.filoghost.chestcommands.metrics + me.filoghost.chestcommands.metrics diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java similarity index 82% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/ChestCommands.java rename to Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 8b3bd89..07e51cd 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -12,34 +12,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands; +package me.filoghost.chestcommands; -import com.gmail.filoghost.chestcommands.SimpleUpdater.ResponseHandler; -import com.gmail.filoghost.chestcommands.bridge.BarAPIBridge; -import com.gmail.filoghost.chestcommands.bridge.EconomyBridge; -import com.gmail.filoghost.chestcommands.bridge.PlaceholderAPIBridge; -import com.gmail.filoghost.chestcommands.command.CommandHandler; -import com.gmail.filoghost.chestcommands.command.framework.CommandFramework; -import com.gmail.filoghost.chestcommands.config.AsciiPlaceholders; -import com.gmail.filoghost.chestcommands.config.Lang; -import com.gmail.filoghost.chestcommands.config.Settings; -import com.gmail.filoghost.chestcommands.config.yaml.PluginConfig; -import com.gmail.filoghost.chestcommands.internal.BoundItem; -import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu; -import com.gmail.filoghost.chestcommands.internal.MenuData; -import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder; -import com.gmail.filoghost.chestcommands.listener.CommandListener; -import com.gmail.filoghost.chestcommands.listener.InventoryListener; -import com.gmail.filoghost.chestcommands.listener.JoinListener; -import com.gmail.filoghost.chestcommands.listener.SignListener; -import com.gmail.filoghost.chestcommands.serializer.CommandSerializer; -import com.gmail.filoghost.chestcommands.serializer.MenuSerializer; -import com.gmail.filoghost.chestcommands.task.ErrorLoggerTask; -import com.gmail.filoghost.chestcommands.task.RefreshMenusTask; -import com.gmail.filoghost.chestcommands.util.BukkitUtils; -import com.gmail.filoghost.chestcommands.util.CaseInsensitiveMap; -import com.gmail.filoghost.chestcommands.util.ErrorLogger; -import com.gmail.filoghost.chestcommands.util.Utils; import org.bstats.bukkit.MetricsLite; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -47,6 +21,33 @@ import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; +import me.filoghost.chestcommands.SimpleUpdater.ResponseHandler; +import me.filoghost.chestcommands.bridge.BarAPIBridge; +import me.filoghost.chestcommands.bridge.EconomyBridge; +import me.filoghost.chestcommands.bridge.PlaceholderAPIBridge; +import me.filoghost.chestcommands.command.CommandHandler; +import me.filoghost.chestcommands.command.framework.CommandFramework; +import me.filoghost.chestcommands.config.AsciiPlaceholders; +import me.filoghost.chestcommands.config.Lang; +import me.filoghost.chestcommands.config.Settings; +import me.filoghost.chestcommands.config.yaml.PluginConfig; +import me.filoghost.chestcommands.internal.BoundItem; +import me.filoghost.chestcommands.internal.ExtendedIconMenu; +import me.filoghost.chestcommands.internal.MenuData; +import me.filoghost.chestcommands.internal.MenuInventoryHolder; +import me.filoghost.chestcommands.listener.CommandListener; +import me.filoghost.chestcommands.listener.InventoryListener; +import me.filoghost.chestcommands.listener.JoinListener; +import me.filoghost.chestcommands.listener.SignListener; +import me.filoghost.chestcommands.serializer.CommandSerializer; +import me.filoghost.chestcommands.serializer.MenuSerializer; +import me.filoghost.chestcommands.task.ErrorLoggerTask; +import me.filoghost.chestcommands.task.RefreshMenusTask; +import me.filoghost.chestcommands.util.BukkitUtils; +import me.filoghost.chestcommands.util.CaseInsensitiveMap; +import me.filoghost.chestcommands.util.ErrorLogger; +import me.filoghost.chestcommands.util.Utils; + import java.io.File; import java.io.IOException; import java.util.List; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/Permissions.java b/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java similarity index 92% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/Permissions.java rename to Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java index c31e15e..aaabcd6 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/Permissions.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands; +package me.filoghost.chestcommands; public class Permissions { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/SimpleUpdater.java b/Plugin/src/main/java/me/filoghost/chestcommands/SimpleUpdater.java similarity index 96% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/SimpleUpdater.java rename to Plugin/src/main/java/me/filoghost/chestcommands/SimpleUpdater.java index 5222d1e..a3273a3 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/SimpleUpdater.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/SimpleUpdater.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands; +package me.filoghost.chestcommands; import com.google.common.primitives.Ints; import org.bukkit.Bukkit; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/api/ChestCommandsAPI.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java similarity index 91% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/api/ChestCommandsAPI.java rename to Plugin/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java index 0b9adbb..838eeaf 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/api/ChestCommandsAPI.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java @@ -12,11 +12,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.api; +package me.filoghost.chestcommands.api; -import com.gmail.filoghost.chestcommands.ChestCommands; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.ChestCommands; + public class ChestCommandsAPI { /** diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/api/ClickHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java similarity index 92% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/api/ClickHandler.java rename to Plugin/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java index 7d268e7..2d32c59 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/api/ClickHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.api; +package me.filoghost.chestcommands.api; import org.bukkit.entity.Player; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/api/Icon.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java similarity index 93% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/api/Icon.java rename to Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java index ab809b5..1ab26ef 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/api/Icon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java @@ -12,11 +12,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.api; +package me.filoghost.chestcommands.api; -import com.gmail.filoghost.chestcommands.ChestCommands; -import com.gmail.filoghost.chestcommands.internal.VariableManager; -import com.gmail.filoghost.chestcommands.util.Utils; import org.bukkit.*; import org.bukkit.block.banner.Pattern; import org.bukkit.enchantments.Enchantment; @@ -27,6 +24,10 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.inventory.meta.SkullMeta; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.internal.VariableManager; +import me.filoghost.chestcommands.util.Utils; + import java.util.Arrays; import java.util.HashMap; import java.util.List; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/api/IconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/IconMenu.java similarity index 86% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/api/IconMenu.java rename to Plugin/src/main/java/me/filoghost/chestcommands/api/IconMenu.java index e1ed886..6902ef2 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/api/IconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/IconMenu.java @@ -12,16 +12,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.api; +package me.filoghost.chestcommands.api; -import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder; -import com.gmail.filoghost.chestcommands.util.ItemUtils; -import com.gmail.filoghost.chestcommands.util.Utils; -import com.gmail.filoghost.chestcommands.util.Validate; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; +import me.filoghost.chestcommands.internal.MenuInventoryHolder; +import me.filoghost.chestcommands.util.ItemUtils; +import me.filoghost.chestcommands.util.Utils; +import me.filoghost.chestcommands.util.Validate; + import java.util.Arrays; /* diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/bridge/BarAPIBridge.java b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/BarAPIBridge.java similarity index 93% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/bridge/BarAPIBridge.java rename to Plugin/src/main/java/me/filoghost/chestcommands/bridge/BarAPIBridge.java index 4be34e4..ed248f9 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/bridge/BarAPIBridge.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/BarAPIBridge.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.bridge; +package me.filoghost.chestcommands.bridge; import me.confuser.barapi.BarAPI; import org.bukkit.Bukkit; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/bridge/EconomyBridge.java b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java similarity index 94% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/bridge/EconomyBridge.java rename to Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java index a13c16c..7cf4d0b 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/bridge/EconomyBridge.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java @@ -12,15 +12,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.bridge; +package me.filoghost.chestcommands.bridge; -import com.gmail.filoghost.chestcommands.util.MenuUtils; import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.EconomyResponse; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.RegisteredServiceProvider; +import me.filoghost.chestcommands.util.MenuUtils; + public class EconomyBridge { private static Economy economy; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/bridge/PlaceholderAPIBridge.java b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/PlaceholderAPIBridge.java similarity index 95% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/bridge/PlaceholderAPIBridge.java rename to Plugin/src/main/java/me/filoghost/chestcommands/bridge/PlaceholderAPIBridge.java index 1f21006..df45f41 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/bridge/PlaceholderAPIBridge.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/PlaceholderAPIBridge.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.bridge; +package me.filoghost.chestcommands.bridge; import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPIPlugin; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/bridge/bungee/BungeeCordUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/bungee/BungeeCordUtils.java similarity index 91% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/bridge/bungee/BungeeCordUtils.java rename to Plugin/src/main/java/me/filoghost/chestcommands/bridge/bungee/BungeeCordUtils.java index 50e20b2..8da537d 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/bridge/bungee/BungeeCordUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/bungee/BungeeCordUtils.java @@ -12,12 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.bridge.bungee; +package me.filoghost.chestcommands.bridge.bungee; -import com.gmail.filoghost.chestcommands.ChestCommands; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.ChestCommands; + import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/command/CommandHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java similarity index 88% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/command/CommandHandler.java rename to Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index f557e37..990a670 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/command/CommandHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -12,21 +12,22 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.command; +package me.filoghost.chestcommands.command; -import com.gmail.filoghost.chestcommands.ChestCommands; -import com.gmail.filoghost.chestcommands.Permissions; -import com.gmail.filoghost.chestcommands.command.framework.CommandFramework; -import com.gmail.filoghost.chestcommands.command.framework.CommandValidate; -import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu; -import com.gmail.filoghost.chestcommands.task.ErrorLoggerTask; -import com.gmail.filoghost.chestcommands.util.ErrorLogger; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.Permissions; +import me.filoghost.chestcommands.command.framework.CommandFramework; +import me.filoghost.chestcommands.command.framework.CommandValidate; +import me.filoghost.chestcommands.internal.ExtendedIconMenu; +import me.filoghost.chestcommands.task.ErrorLoggerTask; +import me.filoghost.chestcommands.util.ErrorLogger; + public class CommandHandler extends CommandFramework { public CommandHandler(String label) { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/command/framework/CommandException.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandException.java similarity index 90% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/command/framework/CommandException.java rename to Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandException.java index 6c0d220..ca6db68 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/command/framework/CommandException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandException.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.command.framework; +package me.filoghost.chestcommands.command.framework; public class CommandException extends RuntimeException { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/command/framework/CommandFramework.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandFramework.java similarity index 93% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/command/framework/CommandFramework.java rename to Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandFramework.java index d9d9a44..0a7c888 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/command/framework/CommandFramework.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandFramework.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.command.framework; +package me.filoghost.chestcommands.command.framework; import org.bukkit.ChatColor; import org.bukkit.command.Command; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/command/framework/CommandValidate.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandValidate.java similarity index 94% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/command/framework/CommandValidate.java rename to Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandValidate.java index e9bc2da..7f74ced 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/command/framework/CommandValidate.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandValidate.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.command.framework; +package me.filoghost.chestcommands.command.framework; public class CommandValidate { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/AsciiPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java similarity index 88% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/AsciiPlaceholders.java rename to Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java index 39ce3e1..b9d6db0 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/AsciiPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java @@ -12,15 +12,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.config; +package me.filoghost.chestcommands.config; -import com.gmail.filoghost.chestcommands.ChestCommands; -import com.gmail.filoghost.chestcommands.util.BukkitUtils; -import com.gmail.filoghost.chestcommands.util.ErrorLogger; -import com.gmail.filoghost.chestcommands.util.FormatUtils; -import com.gmail.filoghost.chestcommands.util.Utils; import org.apache.commons.lang.StringEscapeUtils; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.util.BukkitUtils; +import me.filoghost.chestcommands.util.ErrorLogger; +import me.filoghost.chestcommands.util.FormatUtils; +import me.filoghost.chestcommands.util.Utils; + import java.io.File; import java.io.IOException; import java.util.List; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/ConfigUtil.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java similarity index 92% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/ConfigUtil.java rename to Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java index 99da85f..9f2d214 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/ConfigUtil.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.config; +package me.filoghost.chestcommands.config; import java.util.Collections; import java.util.List; @@ -20,7 +20,7 @@ import java.util.regex.Pattern; import org.bukkit.configuration.ConfigurationSection; -import com.gmail.filoghost.chestcommands.util.Utils; +import me.filoghost.chestcommands.util.Utils; public class ConfigUtil { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/Lang.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java similarity index 87% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/Lang.java rename to Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java index 5f28a29..6e3ae12 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/Lang.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java @@ -12,10 +12,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.config; +package me.filoghost.chestcommands.config; -import com.gmail.filoghost.chestcommands.config.yaml.PluginConfig; -import com.gmail.filoghost.chestcommands.config.yaml.SpecialConfig; +import me.filoghost.chestcommands.config.yaml.PluginConfig; +import me.filoghost.chestcommands.config.yaml.SpecialConfig; public class Lang extends SpecialConfig { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/Settings.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java similarity index 84% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/Settings.java rename to Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java index 610a97b..6cf629a 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/Settings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java @@ -12,10 +12,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.config; +package me.filoghost.chestcommands.config; -import com.gmail.filoghost.chestcommands.config.yaml.PluginConfig; -import com.gmail.filoghost.chestcommands.config.yaml.SpecialConfig; +import me.filoghost.chestcommands.config.yaml.PluginConfig; +import me.filoghost.chestcommands.config.yaml.SpecialConfig; public class Settings extends SpecialConfig { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/yaml/PluginConfig.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/PluginConfig.java similarity index 93% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/yaml/PluginConfig.java rename to Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/PluginConfig.java index 55857de..a7a4f76 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/yaml/PluginConfig.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/PluginConfig.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.config.yaml; +package me.filoghost.chestcommands.config.yaml; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/yaml/SpecialConfig.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/SpecialConfig.java similarity index 93% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/yaml/SpecialConfig.java rename to Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/SpecialConfig.java index de64fcf..0e82145 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/config/yaml/SpecialConfig.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/SpecialConfig.java @@ -12,11 +12,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.config.yaml; +package me.filoghost.chestcommands.config.yaml; -import com.gmail.filoghost.chestcommands.util.FormatUtils; import org.bukkit.configuration.InvalidConfigurationException; +import me.filoghost.chestcommands.util.FormatUtils; + import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Modifier; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/exception/FormatException.java b/Plugin/src/main/java/me/filoghost/chestcommands/exception/FormatException.java similarity index 91% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/exception/FormatException.java rename to Plugin/src/main/java/me/filoghost/chestcommands/exception/FormatException.java index 5b0cdc9..32b9066 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/exception/FormatException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/exception/FormatException.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.exception; +package me.filoghost.chestcommands.exception; public class FormatException extends Exception { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/BoundItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BoundItem.java similarity index 88% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/BoundItem.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/BoundItem.java index 2375f3c..a5fd267 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/BoundItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BoundItem.java @@ -12,14 +12,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.internal; -import com.gmail.filoghost.chestcommands.util.ClickType; -import com.gmail.filoghost.chestcommands.util.Validate; import org.bukkit.Material; import org.bukkit.event.block.Action; import org.bukkit.inventory.ItemStack; +import me.filoghost.chestcommands.util.ClickType; +import me.filoghost.chestcommands.util.Validate; + public class BoundItem { private ExtendedIconMenu menu; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/CachedGetters.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/CachedGetters.java similarity index 88% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/CachedGetters.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/CachedGetters.java index 1563c5a..23fdcfd 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/CachedGetters.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/CachedGetters.java @@ -12,9 +12,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.internal; -import com.gmail.filoghost.chestcommands.util.BukkitUtils; +import me.filoghost.chestcommands.util.BukkitUtils; public class CachedGetters { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/CommandsClickHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/CommandsClickHandler.java similarity index 82% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/CommandsClickHandler.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/CommandsClickHandler.java index a297d1a..8de5282 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/CommandsClickHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/CommandsClickHandler.java @@ -12,13 +12,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.internal; -import com.gmail.filoghost.chestcommands.api.ClickHandler; -import com.gmail.filoghost.chestcommands.internal.icon.IconCommand; -import com.gmail.filoghost.chestcommands.internal.icon.command.OpenIconCommand; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.api.ClickHandler; +import me.filoghost.chestcommands.internal.icon.IconCommand; +import me.filoghost.chestcommands.internal.icon.command.OpenIconCommand; + import java.util.List; public class CommandsClickHandler implements ClickHandler { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/ExtendedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java similarity index 87% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/ExtendedIconMenu.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java index e26f0ca..f7c1426 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/ExtendedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java @@ -12,14 +12,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.internal; -import com.gmail.filoghost.chestcommands.ChestCommands; -import com.gmail.filoghost.chestcommands.Permissions; -import com.gmail.filoghost.chestcommands.api.IconMenu; -import com.gmail.filoghost.chestcommands.internal.icon.ExtendedIcon; -import com.gmail.filoghost.chestcommands.internal.icon.IconCommand; -import com.gmail.filoghost.chestcommands.util.ItemUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -28,6 +22,13 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.Permissions; +import me.filoghost.chestcommands.api.IconMenu; +import me.filoghost.chestcommands.internal.icon.ExtendedIcon; +import me.filoghost.chestcommands.internal.icon.IconCommand; +import me.filoghost.chestcommands.util.ItemUtils; + import java.util.List; public class ExtendedIconMenu extends IconMenu { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/MenuData.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuData.java similarity index 89% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/MenuData.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuData.java index 32142a9..bca2037 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/MenuData.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuData.java @@ -12,12 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.internal; -import com.gmail.filoghost.chestcommands.internal.icon.IconCommand; -import com.gmail.filoghost.chestcommands.util.ClickType; import org.bukkit.Material; +import me.filoghost.chestcommands.internal.icon.IconCommand; +import me.filoghost.chestcommands.util.ClickType; + import java.util.List; public class MenuData { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/MenuInventoryHolder.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java similarity index 87% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/MenuInventoryHolder.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java index a92ac3b..37b15bf 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/MenuInventoryHolder.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java @@ -12,14 +12,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.internal; -import com.gmail.filoghost.chestcommands.api.IconMenu; -import com.gmail.filoghost.chestcommands.util.Validate; import org.bukkit.Bukkit; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; +import me.filoghost.chestcommands.api.IconMenu; +import me.filoghost.chestcommands.util.Validate; + /** * This class links an IconMenu with an Inventory, via InventoryHolder. */ diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/RequiredItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java similarity index 92% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/RequiredItem.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java index ede1316..376edd8 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/RequiredItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java @@ -12,13 +12,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.internal; -import com.gmail.filoghost.chestcommands.util.Validate; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import me.filoghost.chestcommands.util.Validate; + public class RequiredItem { private Material material; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/Variable.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/Variable.java similarity index 90% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/Variable.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/Variable.java index 18fb6aa..ad420e9 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/Variable.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/Variable.java @@ -12,12 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.internal; -import com.gmail.filoghost.chestcommands.bridge.EconomyBridge; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.bridge.EconomyBridge; + public enum Variable { PLAYER("{player}") { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/VariableManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/VariableManager.java similarity index 87% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/VariableManager.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/VariableManager.java index af44dc6..e0496f2 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/VariableManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/VariableManager.java @@ -1,8 +1,9 @@ -package com.gmail.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.internal; -import com.gmail.filoghost.chestcommands.bridge.PlaceholderAPIBridge; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.bridge.PlaceholderAPIBridge; + public class VariableManager { public static boolean hasVariables(String message) { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/ExtendedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/ExtendedIcon.java similarity index 88% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/ExtendedIcon.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/ExtendedIcon.java index d38960c..4cf558e 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/ExtendedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/ExtendedIcon.java @@ -12,21 +12,22 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal.icon; +package me.filoghost.chestcommands.internal.icon; -import com.gmail.filoghost.chestcommands.ChestCommands; -import com.gmail.filoghost.chestcommands.api.Icon; -import com.gmail.filoghost.chestcommands.bridge.EconomyBridge; -import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu; -import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder; -import com.gmail.filoghost.chestcommands.internal.RequiredItem; -import com.gmail.filoghost.chestcommands.util.MaterialsRegistry; -import com.gmail.filoghost.chestcommands.util.StringUtils; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.api.Icon; +import me.filoghost.chestcommands.bridge.EconomyBridge; +import me.filoghost.chestcommands.internal.ExtendedIconMenu; +import me.filoghost.chestcommands.internal.MenuInventoryHolder; +import me.filoghost.chestcommands.internal.RequiredItem; +import me.filoghost.chestcommands.util.MaterialsRegistry; +import me.filoghost.chestcommands.util.StringUtils; + import java.util.List; public class ExtendedIcon extends Icon { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/IconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/IconCommand.java similarity index 83% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/IconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/IconCommand.java index cf9e075..974f559 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/IconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/IconCommand.java @@ -12,12 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal.icon; +package me.filoghost.chestcommands.internal.icon; -import com.gmail.filoghost.chestcommands.config.AsciiPlaceholders; -import com.gmail.filoghost.chestcommands.internal.VariableManager; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.config.AsciiPlaceholders; +import me.filoghost.chestcommands.internal.VariableManager; + public abstract class IconCommand { protected String command; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/BroadcastIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/BroadcastIconCommand.java similarity index 81% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/BroadcastIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/BroadcastIconCommand.java index 3fbe74b..fba1135 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/BroadcastIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/BroadcastIconCommand.java @@ -12,13 +12,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.internal.icon.command; -import com.gmail.filoghost.chestcommands.internal.icon.IconCommand; -import com.gmail.filoghost.chestcommands.util.FormatUtils; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.internal.icon.IconCommand; +import me.filoghost.chestcommands.util.FormatUtils; + public class BroadcastIconCommand extends IconCommand { public BroadcastIconCommand(String command) { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/ConsoleIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/ConsoleIconCommand.java similarity index 85% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/ConsoleIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/ConsoleIconCommand.java index 98aea60..b175c2f 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/ConsoleIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/ConsoleIconCommand.java @@ -12,12 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.internal.icon.command; -import com.gmail.filoghost.chestcommands.internal.icon.IconCommand; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.internal.icon.IconCommand; + public class ConsoleIconCommand extends IconCommand { public ConsoleIconCommand(String command) { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/DragonBarIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/DragonBarIconCommand.java similarity index 80% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/DragonBarIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/DragonBarIconCommand.java index 6420685..2f90627 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/DragonBarIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/DragonBarIconCommand.java @@ -12,14 +12,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.internal.icon.command; -import com.gmail.filoghost.chestcommands.bridge.BarAPIBridge; -import com.gmail.filoghost.chestcommands.internal.icon.IconCommand; -import com.gmail.filoghost.chestcommands.util.FormatUtils; -import com.gmail.filoghost.chestcommands.util.Utils; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.bridge.BarAPIBridge; +import me.filoghost.chestcommands.internal.icon.IconCommand; +import me.filoghost.chestcommands.util.FormatUtils; +import me.filoghost.chestcommands.util.Utils; + public class DragonBarIconCommand extends IconCommand { private String message; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/GiveIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/GiveIconCommand.java similarity index 82% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/GiveIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/GiveIconCommand.java index 70b0ba9..17806f5 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/GiveIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/GiveIconCommand.java @@ -12,15 +12,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.internal.icon.command; -import com.gmail.filoghost.chestcommands.exception.FormatException; -import com.gmail.filoghost.chestcommands.internal.icon.IconCommand; -import com.gmail.filoghost.chestcommands.util.ItemStackReader; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import me.filoghost.chestcommands.exception.FormatException; +import me.filoghost.chestcommands.internal.icon.IconCommand; +import me.filoghost.chestcommands.util.ItemStackReader; + public class GiveIconCommand extends IconCommand { private ItemStack itemToGive; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/GiveMoneyIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/GiveMoneyIconCommand.java similarity index 84% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/GiveMoneyIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/GiveMoneyIconCommand.java index 5764fd4..6ec0a02 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/GiveMoneyIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/GiveMoneyIconCommand.java @@ -12,14 +12,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.internal.icon.command; -import com.gmail.filoghost.chestcommands.bridge.EconomyBridge; -import com.gmail.filoghost.chestcommands.internal.icon.IconCommand; -import com.gmail.filoghost.chestcommands.util.Utils; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.bridge.EconomyBridge; +import me.filoghost.chestcommands.internal.icon.IconCommand; +import me.filoghost.chestcommands.util.Utils; + public class GiveMoneyIconCommand extends IconCommand { private double moneyToGive; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/OpIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpIconCommand.java similarity index 85% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/OpIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpIconCommand.java index 49c23ad..17db2b2 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/OpIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpIconCommand.java @@ -12,11 +12,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.internal.icon.command; -import com.gmail.filoghost.chestcommands.internal.icon.IconCommand; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.internal.icon.IconCommand; + public class OpIconCommand extends IconCommand { public OpIconCommand(String command) { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java similarity index 84% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java index 1512656..d4204a6 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java @@ -12,15 +12,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.internal.icon.command; -import com.gmail.filoghost.chestcommands.ChestCommands; -import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu; -import com.gmail.filoghost.chestcommands.internal.icon.IconCommand; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.internal.ExtendedIconMenu; +import me.filoghost.chestcommands.internal.icon.IconCommand; + public class OpenIconCommand extends IconCommand { public OpenIconCommand(String command) { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/PlayerIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/PlayerIconCommand.java similarity index 84% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/PlayerIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/PlayerIconCommand.java index 061ec38..81e12d7 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/PlayerIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/PlayerIconCommand.java @@ -12,11 +12,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.internal.icon.command; -import com.gmail.filoghost.chestcommands.internal.icon.IconCommand; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.internal.icon.IconCommand; + public class PlayerIconCommand extends IconCommand { public PlayerIconCommand(String command) { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/ServerIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/ServerIconCommand.java similarity index 80% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/ServerIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/ServerIconCommand.java index cdc731c..b4d18db 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/ServerIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/ServerIconCommand.java @@ -12,12 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.internal.icon.command; -import com.gmail.filoghost.chestcommands.bridge.bungee.BungeeCordUtils; -import com.gmail.filoghost.chestcommands.internal.icon.IconCommand; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.bridge.bungee.BungeeCordUtils; +import me.filoghost.chestcommands.internal.icon.IconCommand; + public class ServerIconCommand extends IconCommand { public ServerIconCommand(String command) { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/SoundIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/SoundIconCommand.java similarity index 87% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/SoundIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/SoundIconCommand.java index 01fbe43..01a3e8a 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/SoundIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/SoundIconCommand.java @@ -12,14 +12,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.internal.icon.command; -import com.gmail.filoghost.chestcommands.internal.icon.IconCommand; -import com.gmail.filoghost.chestcommands.util.BukkitUtils; import org.bukkit.ChatColor; import org.bukkit.Sound; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.internal.icon.IconCommand; +import me.filoghost.chestcommands.util.BukkitUtils; + public class SoundIconCommand extends IconCommand { private Sound sound; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/TellIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/TellIconCommand.java similarity index 80% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/TellIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/TellIconCommand.java index 32e6432..ed70fc0 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/internal/icon/command/TellIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/TellIconCommand.java @@ -12,12 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.internal.icon.command; -import com.gmail.filoghost.chestcommands.internal.icon.IconCommand; -import com.gmail.filoghost.chestcommands.util.FormatUtils; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.internal.icon.IconCommand; +import me.filoghost.chestcommands.util.FormatUtils; + public class TellIconCommand extends IconCommand { public TellIconCommand(String command) { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/listener/CommandListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java similarity index 84% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/listener/CommandListener.java rename to Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java index 1617b03..425c977 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/listener/CommandListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java @@ -12,16 +12,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.listener; +package me.filoghost.chestcommands.listener; -import com.gmail.filoghost.chestcommands.ChestCommands; -import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu; -import com.gmail.filoghost.chestcommands.util.StringUtils; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.internal.ExtendedIconMenu; +import me.filoghost.chestcommands.util.StringUtils; + public class CommandListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java similarity index 84% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/listener/InventoryListener.java rename to Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index 66ec965..ef65355 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -12,15 +12,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.listener; +package me.filoghost.chestcommands.listener; -import com.gmail.filoghost.chestcommands.ChestCommands; -import com.gmail.filoghost.chestcommands.api.Icon; -import com.gmail.filoghost.chestcommands.api.IconMenu; -import com.gmail.filoghost.chestcommands.internal.BoundItem; -import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder; -import com.gmail.filoghost.chestcommands.task.ExecuteCommandsTask; -import com.gmail.filoghost.chestcommands.util.Utils; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -31,6 +24,14 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.api.Icon; +import me.filoghost.chestcommands.api.IconMenu; +import me.filoghost.chestcommands.internal.BoundItem; +import me.filoghost.chestcommands.internal.MenuInventoryHolder; +import me.filoghost.chestcommands.task.ExecuteCommandsTask; +import me.filoghost.chestcommands.util.Utils; + import java.util.Map; public class InventoryListener implements Listener { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/listener/JoinListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java similarity index 89% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/listener/JoinListener.java rename to Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java index 7f14b09..3e476b3 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/listener/JoinListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java @@ -12,15 +12,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.listener; +package me.filoghost.chestcommands.listener; -import com.gmail.filoghost.chestcommands.ChestCommands; -import com.gmail.filoghost.chestcommands.Permissions; import org.bukkit.ChatColor; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.Permissions; + public class JoinListener implements Listener { @EventHandler diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/listener/SignListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java similarity index 84% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/listener/SignListener.java rename to Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java index cb37d59..5b8602f 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/listener/SignListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java @@ -12,13 +12,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.listener; +package me.filoghost.chestcommands.listener; -import com.gmail.filoghost.chestcommands.ChestCommands; -import com.gmail.filoghost.chestcommands.Permissions; -import com.gmail.filoghost.chestcommands.api.IconMenu; -import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu; -import com.gmail.filoghost.chestcommands.util.BukkitUtils; import org.bukkit.ChatColor; import org.bukkit.block.Sign; import org.bukkit.event.EventHandler; @@ -28,12 +23,19 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerInteractEvent; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.Permissions; +import me.filoghost.chestcommands.api.IconMenu; +import me.filoghost.chestcommands.internal.ExtendedIconMenu; +import me.filoghost.chestcommands.util.BukkitUtils; +import me.filoghost.chestcommands.util.MaterialsRegistry; + public class SignListener implements Listener { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onInteract(PlayerInteractEvent event) { - if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasBlock() && event.getClickedBlock().getState() instanceof Sign) { + if (event.getAction() == Action.RIGHT_CLICK_BLOCK && MaterialsRegistry.isSign(event.getClickedBlock().getType())) { Sign sign = (Sign) event.getClickedBlock().getState(); if (sign.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[menu]")) { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/serializer/CommandSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java similarity index 89% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/serializer/CommandSerializer.java rename to Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java index fc6b664..8aa808e 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/serializer/CommandSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java @@ -12,18 +12,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.serializer; - -import com.gmail.filoghost.chestcommands.internal.icon.IconCommand; -import com.gmail.filoghost.chestcommands.internal.icon.command.*; -import com.gmail.filoghost.chestcommands.util.ErrorLogger; -import com.gmail.filoghost.chestcommands.util.Utils; +package me.filoghost.chestcommands.serializer; import java.util.Map; import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; +import me.filoghost.chestcommands.internal.icon.IconCommand; +import me.filoghost.chestcommands.internal.icon.command.*; +import me.filoghost.chestcommands.util.ErrorLogger; +import me.filoghost.chestcommands.util.Utils; + public class CommandSerializer { private static Map> commandTypesMap = Utils.newHashMap(); diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/serializer/EnchantmentSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java similarity index 93% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/serializer/EnchantmentSerializer.java rename to Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java index 907f872..4d26dd2 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/serializer/EnchantmentSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java @@ -12,12 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.serializer; +package me.filoghost.chestcommands.serializer; -import com.gmail.filoghost.chestcommands.util.ErrorLogger; -import com.gmail.filoghost.chestcommands.util.StringUtils; import org.bukkit.enchantments.Enchantment; +import me.filoghost.chestcommands.util.ErrorLogger; +import me.filoghost.chestcommands.util.StringUtils; + import java.util.HashMap; import java.util.Map; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/serializer/IconSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java similarity index 85% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/serializer/IconSerializer.java rename to Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java index a68a5e6..858da88 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/serializer/IconSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.serializer; +package me.filoghost.chestcommands.serializer; import java.util.List; import java.util.Map; @@ -20,24 +20,24 @@ import java.util.Map; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.enchantments.Enchantment; -import com.gmail.filoghost.chestcommands.ChestCommands; -import com.gmail.filoghost.chestcommands.api.Icon; -import com.gmail.filoghost.chestcommands.config.AsciiPlaceholders; -import com.gmail.filoghost.chestcommands.config.ConfigUtil; -import com.gmail.filoghost.chestcommands.exception.FormatException; -import com.gmail.filoghost.chestcommands.internal.CommandsClickHandler; -import com.gmail.filoghost.chestcommands.internal.RequiredItem; -import com.gmail.filoghost.chestcommands.internal.icon.ExtendedIcon; -import com.gmail.filoghost.chestcommands.internal.icon.IconCommand; -import com.gmail.filoghost.chestcommands.serializer.EnchantmentSerializer.EnchantmentDetails; -import com.gmail.filoghost.chestcommands.util.ErrorLogger; -import com.gmail.filoghost.chestcommands.util.FormatUtils; -import com.gmail.filoghost.chestcommands.util.ItemStackReader; -import com.gmail.filoghost.chestcommands.util.ItemUtils; -import com.gmail.filoghost.chestcommands.util.Utils; -import com.gmail.filoghost.chestcommands.util.Validate; -import com.gmail.filoghost.chestcommands.util.nbt.parser.MojangsonParseException; -import com.gmail.filoghost.chestcommands.util.nbt.parser.MojangsonParser; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.api.Icon; +import me.filoghost.chestcommands.config.AsciiPlaceholders; +import me.filoghost.chestcommands.config.ConfigUtil; +import me.filoghost.chestcommands.exception.FormatException; +import me.filoghost.chestcommands.internal.CommandsClickHandler; +import me.filoghost.chestcommands.internal.RequiredItem; +import me.filoghost.chestcommands.internal.icon.ExtendedIcon; +import me.filoghost.chestcommands.internal.icon.IconCommand; +import me.filoghost.chestcommands.serializer.EnchantmentSerializer.EnchantmentDetails; +import me.filoghost.chestcommands.util.ErrorLogger; +import me.filoghost.chestcommands.util.FormatUtils; +import me.filoghost.chestcommands.util.ItemStackReader; +import me.filoghost.chestcommands.util.ItemUtils; +import me.filoghost.chestcommands.util.Utils; +import me.filoghost.chestcommands.util.Validate; +import me.filoghost.chestcommands.util.nbt.parser.MojangsonParseException; +import me.filoghost.chestcommands.util.nbt.parser.MojangsonParser; public class IconSerializer { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/serializer/MenuSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java similarity index 83% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/serializer/MenuSerializer.java rename to Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java index 553c8e6..340281f 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/serializer/MenuSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java @@ -12,27 +12,27 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.serializer; +package me.filoghost.chestcommands.serializer; import java.util.List; import org.bukkit.ChatColor; import org.bukkit.configuration.ConfigurationSection; -import com.gmail.filoghost.chestcommands.ChestCommands; -import com.gmail.filoghost.chestcommands.api.Icon; -import com.gmail.filoghost.chestcommands.config.ConfigUtil; -import com.gmail.filoghost.chestcommands.config.yaml.PluginConfig; -import com.gmail.filoghost.chestcommands.exception.FormatException; -import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu; -import com.gmail.filoghost.chestcommands.internal.MenuData; -import com.gmail.filoghost.chestcommands.internal.icon.IconCommand; -import com.gmail.filoghost.chestcommands.serializer.IconSerializer.Coords; -import com.gmail.filoghost.chestcommands.util.ClickType; -import com.gmail.filoghost.chestcommands.util.ErrorLogger; -import com.gmail.filoghost.chestcommands.util.FormatUtils; -import com.gmail.filoghost.chestcommands.util.ItemStackReader; -import com.gmail.filoghost.chestcommands.util.Utils; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.api.Icon; +import me.filoghost.chestcommands.config.ConfigUtil; +import me.filoghost.chestcommands.config.yaml.PluginConfig; +import me.filoghost.chestcommands.exception.FormatException; +import me.filoghost.chestcommands.internal.ExtendedIconMenu; +import me.filoghost.chestcommands.internal.MenuData; +import me.filoghost.chestcommands.internal.icon.IconCommand; +import me.filoghost.chestcommands.serializer.IconSerializer.Coords; +import me.filoghost.chestcommands.util.ClickType; +import me.filoghost.chestcommands.util.ErrorLogger; +import me.filoghost.chestcommands.util.FormatUtils; +import me.filoghost.chestcommands.util.ItemStackReader; +import me.filoghost.chestcommands.util.Utils; public class MenuSerializer { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/task/ErrorLoggerTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/ErrorLoggerTask.java similarity index 82% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/task/ErrorLoggerTask.java rename to Plugin/src/main/java/me/filoghost/chestcommands/task/ErrorLoggerTask.java index 11511e7..6ef461d 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/task/ErrorLoggerTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/ErrorLoggerTask.java @@ -12,15 +12,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.task; +package me.filoghost.chestcommands.task; -import com.gmail.filoghost.chestcommands.ChestCommands; -import com.gmail.filoghost.chestcommands.util.ErrorLogger; -import com.gmail.filoghost.chestcommands.util.StringUtils; -import com.gmail.filoghost.chestcommands.util.Utils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.util.ErrorLogger; +import me.filoghost.chestcommands.util.StringUtils; +import me.filoghost.chestcommands.util.Utils; + import java.util.List; public class ErrorLoggerTask implements Runnable { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/task/ExecuteCommandsTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/ExecuteCommandsTask.java similarity index 87% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/task/ExecuteCommandsTask.java rename to Plugin/src/main/java/me/filoghost/chestcommands/task/ExecuteCommandsTask.java index ea1b612..7766a66 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/task/ExecuteCommandsTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/ExecuteCommandsTask.java @@ -12,11 +12,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.task; +package me.filoghost.chestcommands.task; -import com.gmail.filoghost.chestcommands.api.Icon; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.api.Icon; + public class ExecuteCommandsTask implements Runnable { private Player player; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/task/RefreshMenusTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java similarity index 84% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/task/RefreshMenusTask.java rename to Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java index 2fcad0e..5aedd7d 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/task/RefreshMenusTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java @@ -12,15 +12,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.task; +package me.filoghost.chestcommands.task; -import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu; -import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder; -import com.gmail.filoghost.chestcommands.util.BukkitUtils; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; +import me.filoghost.chestcommands.internal.ExtendedIconMenu; +import me.filoghost.chestcommands.internal.MenuInventoryHolder; +import me.filoghost.chestcommands.util.BukkitUtils; + public class RefreshMenusTask implements Runnable { private long elapsedTenths; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/BukkitUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/BukkitUtils.java similarity index 97% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/BukkitUtils.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/BukkitUtils.java index 294e43c..36e3be5 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/BukkitUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/BukkitUtils.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.util; +package me.filoghost.chestcommands.util; import com.google.common.collect.ImmutableList; import org.bukkit.Bukkit; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/CaseInsensitiveMap.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/CaseInsensitiveMap.java similarity index 94% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/CaseInsensitiveMap.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/CaseInsensitiveMap.java index e1969e1..75d436d 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/CaseInsensitiveMap.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/CaseInsensitiveMap.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.util; +package me.filoghost.chestcommands.util; import java.util.HashMap; import java.util.Map; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/ClickType.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/ClickType.java similarity index 93% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/ClickType.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/ClickType.java index 5ef7ca2..8262ba7 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/ClickType.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/ClickType.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.util; +package me.filoghost.chestcommands.util; import org.bukkit.event.block.Action; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/ErrorLogger.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorLogger.java similarity index 92% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/ErrorLogger.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorLogger.java index 5418c90..a2ceec1 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/ErrorLogger.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorLogger.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.util; +package me.filoghost.chestcommands.util; import java.util.ArrayList; import java.util.List; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/FormatUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/FormatUtils.java similarity index 93% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/FormatUtils.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/FormatUtils.java index c0c58be..647e30d 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/FormatUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/FormatUtils.java @@ -1,8 +1,9 @@ -package com.gmail.filoghost.chestcommands.util; +package me.filoghost.chestcommands.util; -import com.gmail.filoghost.chestcommands.ChestCommands; import org.bukkit.ChatColor; +import me.filoghost.chestcommands.ChestCommands; + import java.text.DecimalFormat; import java.util.List; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/InventoryUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/InventoryUtils.java similarity index 94% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/InventoryUtils.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/InventoryUtils.java index 97cf72a..40ce8c6 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/InventoryUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/InventoryUtils.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.util; +package me.filoghost.chestcommands.util; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/ItemStackReader.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/ItemStackReader.java similarity index 93% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/ItemStackReader.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/ItemStackReader.java index a6f5a67..03d855e 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/ItemStackReader.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/ItemStackReader.java @@ -12,12 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.util; +package me.filoghost.chestcommands.util; -import com.gmail.filoghost.chestcommands.exception.FormatException; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import me.filoghost.chestcommands.exception.FormatException; + public class ItemStackReader { private Material material = Material.STONE; // In the worst case (bad exception handling) we just get stone diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/ItemUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/ItemUtils.java similarity index 97% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/ItemUtils.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/ItemUtils.java index 862cfdd..995c1b4 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/ItemUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/ItemUtils.java @@ -12,9 +12,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.util; +package me.filoghost.chestcommands.util; -import com.gmail.filoghost.chestcommands.exception.FormatException; import org.bukkit.Color; import org.bukkit.DyeColor; import org.bukkit.block.banner.Pattern; @@ -23,6 +22,8 @@ import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import me.filoghost.chestcommands.exception.FormatException; + import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/MaterialsRegistry.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java similarity index 96% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/MaterialsRegistry.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java index 6bf47b7..a4d07eb 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/MaterialsRegistry.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.util; +package me.filoghost.chestcommands.util; import org.bukkit.Material; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/MenuUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/MenuUtils.java similarity index 78% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/MenuUtils.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/MenuUtils.java index b2702e1..2ec1251 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/MenuUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/MenuUtils.java @@ -1,11 +1,12 @@ -package com.gmail.filoghost.chestcommands.util; +package me.filoghost.chestcommands.util; -import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu; -import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; +import me.filoghost.chestcommands.internal.ExtendedIconMenu; +import me.filoghost.chestcommands.internal.MenuInventoryHolder; + public final class MenuUtils { private MenuUtils() { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/NMSUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/NMSUtils.java similarity index 93% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/NMSUtils.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/NMSUtils.java index a3470f4..eaa82e8 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/NMSUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/NMSUtils.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.util; +package me.filoghost.chestcommands.util; import org.bukkit.Bukkit; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/StringUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java similarity index 94% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/StringUtils.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java index 1f22ecf..df72998 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/StringUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.util; +package me.filoghost.chestcommands.util; import java.util.Iterator; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/Utils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java similarity index 93% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/Utils.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java index d41acbc..cc6d4b7 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/Utils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.util; +package me.filoghost.chestcommands.util; import java.io.*; import java.util.*; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/Validate.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Validate.java similarity index 92% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/Validate.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/Validate.java index 825c90f..4098d42 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/Validate.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Validate.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.gmail.filoghost.chestcommands.util; +package me.filoghost.chestcommands.util; public final class Validate { diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTByte.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java similarity index 94% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTByte.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java index e6488b8..ae1f80a 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTByte.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.util.nbt; +package me.filoghost.chestcommands.util.nbt; /** * The {@code TAG_Byte} tag. diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTByteArray.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java similarity index 95% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTByteArray.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java index d58ae18..e1458d3 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTByteArray.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.util.nbt; +package me.filoghost.chestcommands.util.nbt; import java.util.Arrays; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTCompound.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java similarity index 99% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTCompound.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java index aeec997..0d3ff58 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTCompound.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.util.nbt; +package me.filoghost.chestcommands.util.nbt; import java.util.*; import java.util.function.BiConsumer; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTDouble.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java similarity index 94% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTDouble.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java index b5b1e2b..37999b6 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTDouble.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.util.nbt; +package me.filoghost.chestcommands.util.nbt; /** * The {@code TAG_Double} tag. diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTFloat.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java similarity index 94% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTFloat.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java index 11176a3..6ba50ec 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTFloat.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.util.nbt; +package me.filoghost.chestcommands.util.nbt; /** * The {@code TAG_Float} tag. diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTInt.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java similarity index 94% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTInt.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java index c7c459f..f479352 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTInt.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.util.nbt; +package me.filoghost.chestcommands.util.nbt; /** * The {@code TAG_Int} tag. diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTIntArray.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java similarity index 96% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTIntArray.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java index 412d3b1..2643858 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTIntArray.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.util.nbt; +package me.filoghost.chestcommands.util.nbt; import java.util.Arrays; import java.util.Objects; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTList.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java similarity index 98% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTList.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java index 687ab75..fcaa067 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTList.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.util.nbt; +package me.filoghost.chestcommands.util.nbt; import java.util.*; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTLong.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java similarity index 94% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTLong.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java index 0d2a50a..30500e6 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTLong.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.util.nbt; +package me.filoghost.chestcommands.util.nbt; /** * The {@code TAG_Long} tag. diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTLongArray.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java similarity index 96% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTLongArray.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java index 9a4ff37..e5e5a7b 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTLongArray.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.util.nbt; +package me.filoghost.chestcommands.util.nbt; import java.util.Arrays; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTShort.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java similarity index 94% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTShort.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java index c998834..23fdcec 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTShort.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.util.nbt; +package me.filoghost.chestcommands.util.nbt; /** * The {@code TAG_Short} tag. diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTString.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java similarity index 95% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTString.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java index 4c21ec0..d8c8111 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTString.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.util.nbt; +package me.filoghost.chestcommands.util.nbt; /** * The {@code TAG_String} tag. diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTTag.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java similarity index 95% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTTag.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java index 89619ae..a1d331b 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTTag.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.util.nbt; +package me.filoghost.chestcommands.util.nbt; /** * An abstract NBT-Tag. diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTType.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java similarity index 98% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTType.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java index 218e650..d52296b 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/NBTType.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.util.nbt; +package me.filoghost.chestcommands.util.nbt; /** *

diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java similarity index 91% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java index c061619..14f4ef0 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java @@ -1,4 +1,4 @@ -package com.gmail.filoghost.chestcommands.util.nbt.parser; +package me.filoghost.chestcommands.util.nbt.parser; import org.bukkit.ChatColor; diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java similarity index 98% rename from Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java index a08a744..5ecd6f9 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java @@ -1,11 +1,11 @@ -package com.gmail.filoghost.chestcommands.util.nbt.parser; - -import com.gmail.filoghost.chestcommands.util.nbt.*; +package me.filoghost.chestcommands.util.nbt.parser; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; +import me.filoghost.chestcommands.util.nbt.*; + public final class MojangsonParser { private static final Pattern diff --git a/Plugin/src/main/resources/plugin.yml b/Plugin/src/main/resources/plugin.yml index 5ad1b3c..b2fe7e2 100644 --- a/Plugin/src/main/resources/plugin.yml +++ b/Plugin/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: ChestCommands -main: com.gmail.filoghost.chestcommands.ChestCommands +main: me.filoghost.chestcommands.ChestCommands version: ${project.version} api-version: 1.13 diff --git a/pom.xml b/pom.xml index aaba725..cc6598d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,10 +3,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.gmail.filoghost.chestcommands + me.filoghost.chestcommands chestcommands-parent ChestCommands Parent - 3.3.1 + 4.0-SNAPSHOT pom https://dev.bukkit.org/bukkit-plugins/chest-commands From e303d6969c161c38ab6e82949f8fa41af8280e9b Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 5 Jun 2020 18:59:19 +0200 Subject: [PATCH 002/213] Update to Java 8 --- .../chestcommands/ChestCommands.java | 33 ++++------ .../chestcommands/SimpleUpdater.java | 64 +++++++++---------- .../me/filoghost/chestcommands/api/Icon.java | 9 +-- .../config/AsciiPlaceholders.java | 3 +- .../chestcommands/config/ConfigUtil.java | 5 +- .../config/yaml/SpecialConfig.java | 2 +- .../icon/command/OpenIconCommand.java | 12 ++-- .../listener/InventoryListener.java | 5 +- .../serializer/CommandSerializer.java | 4 +- .../serializer/EnchantmentSerializer.java | 2 +- .../serializer/IconSerializer.java | 9 +-- .../serializer/MenuSerializer.java | 4 +- .../chestcommands/task/ErrorLoggerTask.java | 5 +- .../chestcommands/util/ErrorLogger.java | 4 +- .../chestcommands/util/MaterialsRegistry.java | 2 +- .../filoghost/chestcommands/util/Utils.java | 14 +--- pom.xml | 4 +- 17 files changed, 78 insertions(+), 103 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 07e51cd..e1733f3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -21,7 +21,6 @@ import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -import me.filoghost.chestcommands.SimpleUpdater.ResponseHandler; import me.filoghost.chestcommands.bridge.BarAPIBridge; import me.filoghost.chestcommands.bridge.EconomyBridge; import me.filoghost.chestcommands.bridge.PlaceholderAPIBridge; @@ -46,10 +45,10 @@ import me.filoghost.chestcommands.task.RefreshMenusTask; import me.filoghost.chestcommands.util.BukkitUtils; import me.filoghost.chestcommands.util.CaseInsensitiveMap; import me.filoghost.chestcommands.util.ErrorLogger; -import me.filoghost.chestcommands.util.Utils; - import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -80,7 +79,7 @@ public class ChestCommands extends JavaPlugin { instance = this; fileNameToMenuMap = CaseInsensitiveMap.create(); commandsToMenuMap = CaseInsensitiveMap.create(); - boundItems = Utils.newHashSet(); + boundItems = new HashSet<>(); settings = new Settings(new PluginConfig(this, "config.yml")); lang = new Lang(new PluginConfig(this, "lang.yml")); @@ -98,21 +97,17 @@ public class ChestCommands extends JavaPlugin { } if (settings.update_notifications) { - new SimpleUpdater(this, 56919).checkForUpdates(new ResponseHandler() { + new SimpleUpdater(this, 56919).checkForUpdates((String newVersion) -> { + ChestCommands.newVersion = newVersion; - @Override - public void onUpdateFound(String newVersion) { - ChestCommands.newVersion = newVersion; - - if (settings.use_console_colors) { - Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + "Found a new version: " + newVersion + ChatColor.WHITE + " (yours: v" + getDescription().getVersion() + ")"); - Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + ChatColor.WHITE + "Download it on Bukkit Dev:"); - Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + ChatColor.WHITE + "dev.bukkit.org/bukkit-plugins/chest-commands"); - } else { - getLogger().info("Found a new version available: " + newVersion); - getLogger().info("Download it on Bukkit Dev:"); - getLogger().info("dev.bukkit.org/bukkit-plugins/chest-commands"); - } + if (settings.use_console_colors) { + Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + "Found a new version: " + newVersion + ChatColor.WHITE + " (yours: v" + getDescription().getVersion() + ")"); + Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + ChatColor.WHITE + "Download it on Bukkit Dev:"); + Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + ChatColor.WHITE + "dev.bukkit.org/bukkit-plugins/chest-commands"); + } else { + getLogger().info("Found a new version available: " + newVersion); + getLogger().info("Download it on Bukkit Dev:"); + getLogger().info("dev.bukkit.org/bukkit-plugins/chest-commands"); } }); } @@ -256,7 +251,7 @@ public class ChestCommands extends JavaPlugin { * Loads all the configuration files recursively into a list. */ private List loadMenus(File file) { - List list = Utils.newArrayList(); + List list = new ArrayList<>(); if (file.isDirectory()) { for (File subFile : file.listFiles()) { list.addAll(loadMenus(subFile)); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/SimpleUpdater.java b/Plugin/src/main/java/me/filoghost/chestcommands/SimpleUpdater.java index a3273a3..1d8c60d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/SimpleUpdater.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/SimpleUpdater.java @@ -59,44 +59,38 @@ public final class SimpleUpdater { * @param responseHandler the response handler */ public void checkForUpdates(final ResponseHandler responseHandler) { - Thread updaterThread = new Thread(new Runnable() { + Thread updaterThread = new Thread(() -> { + try { + JSONArray filesArray = (JSONArray) readJson("https://api.curseforge.com/servermods/files?projectIds=" + projectId); - @Override - public void run() { - - try { - JSONArray filesArray = (JSONArray) readJson("https://api.curseforge.com/servermods/files?projectIds=" + projectId); - - if (filesArray.size() == 0) { - // The array cannot be empty, there must be at least one file. - // The project ID is not valid or curse returned a wrong response. - return; - } - - String updateName = (String) ((JSONObject) filesArray.get(filesArray.size() - 1)).get("name"); - final PluginVersion remoteVersion = new PluginVersion(updateName); - PluginVersion localVersion = new PluginVersion(plugin.getDescription().getVersion()); - - if (remoteVersion.isNewerThan(localVersion)) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - - @Override - public void run() { - responseHandler.onUpdateFound(remoteVersion.toString()); - } - }); - } - - } catch (IOException e) { - plugin.getLogger().warning("Could not contact BukkitDev to check for updates."); - } catch (InvalidVersionException e) { - plugin.getLogger().warning("Could not check for updates because of a version format error: " + e.getMessage() + "."); - plugin.getLogger().warning("Please notify the author of this error."); - } catch (Exception e) { - e.printStackTrace(); - plugin.getLogger().warning("Unable to check for updates: unhandled exception."); + if (filesArray.size() == 0) { + // The array cannot be empty, there must be at least one file. + // The project ID is not valid or curse returned a wrong response. + return; } + String updateName = (String) ((JSONObject) filesArray.get(filesArray.size() - 1)).get("name"); + final PluginVersion remoteVersion = new PluginVersion(updateName); + PluginVersion localVersion = new PluginVersion(plugin.getDescription().getVersion()); + + if (remoteVersion.isNewerThan(localVersion)) { + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + + @Override + public void run() { + responseHandler.onUpdateFound(remoteVersion.toString()); + } + }); + } + + } catch (IOException e) { + plugin.getLogger().warning("Could not contact BukkitDev to check for updates."); + } catch (InvalidVersionException e) { + plugin.getLogger().warning("Could not check for updates because of a version format error: " + e.getMessage() + "."); + plugin.getLogger().warning("Please notify the author of this error."); + } catch (Exception e) { + e.printStackTrace(); + plugin.getLogger().warning("Unable to check for updates: unhandled exception."); } }); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java index 1ab26ef..590e8e8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java @@ -28,6 +28,7 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.internal.VariableManager; import me.filoghost.chestcommands.util.Utils; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -59,7 +60,7 @@ public class Icon { private ItemStack cachedItem; // When there are no variables, we don't recreate the item public Icon() { - enchantments = new HashMap(); + enchantments = new HashMap<>(); closeOnClick = true; amount = 1; } @@ -154,7 +155,7 @@ public class Icon { } public Map getEnchantments() { - return new HashMap(enchantments); + return new HashMap<>(enchantments); } public void addEnchantment(Enchantment ench) { @@ -244,7 +245,7 @@ public class Icon { if (hasLore()) { - output = Utils.newArrayList(); + output = new ArrayList<>(); if (pov != null && loreLinesWithVariables != null) { for (int i = 0; i < lore.size(); i++) { @@ -263,7 +264,7 @@ public class Icon { if (material == null) { if (output == null) { - output = Utils.newArrayList(); + output = new ArrayList<>(); } // Add an error message diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java index b9d6db0..fecbf82 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java @@ -24,6 +24,7 @@ import me.filoghost.chestcommands.util.Utils; import java.io.File; import java.io.IOException; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -33,7 +34,7 @@ import java.util.Map.Entry; */ public class AsciiPlaceholders { - private static Map placeholders = Utils.newHashMap(); + private static Map placeholders = new HashMap<>(); public static void load(ErrorLogger errorLogger) throws IOException, Exception { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java index 9f2d214..7706f5d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java @@ -14,14 +14,13 @@ */ package me.filoghost.chestcommands.config; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.regex.Pattern; import org.bukkit.configuration.ConfigurationSection; -import me.filoghost.chestcommands.util.Utils; - public class ConfigUtil { public static String getAnyString(ConfigurationSection config, String... paths) { @@ -75,7 +74,7 @@ public class ConfigUtil { } String[] splitValues = input.split(Pattern.quote(separator)); - List values = Utils.newArrayList(); + List values = new ArrayList<>(); for (String value : splitValues) { String trimmedValue = value.trim(); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/SpecialConfig.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/SpecialConfig.java index 0e82145..80498a1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/SpecialConfig.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/SpecialConfig.java @@ -47,7 +47,7 @@ public class SpecialConfig { // Check if the configuration was initialized if (defaultValuesMap == null) { - defaultValuesMap = new HashMap(); + defaultValuesMap = new HashMap<>(); // Put the values in the default values map for (Field field : getClass().getDeclaredFields()) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java index d4204a6..fd9c31f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java @@ -38,13 +38,11 @@ public class OpenIconCommand extends IconCommand { * Delay the task, since this command is executed in ClickInventoryEvent * and opening another inventory in the same moment is not a good idea. */ - Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), new Runnable() { - public void run() { - if (player.hasPermission(menu.getPermission())) { - menu.open(player); - } else { - menu.sendNoPermissionMessage(player); - } + Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), () -> { + if (player.hasPermission(menu.getPermission())) { + menu.open(player); + } else { + menu.sendNoPermissionMessage(player); } }); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index ef65355..4ec8883 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -30,13 +30,12 @@ import me.filoghost.chestcommands.api.IconMenu; import me.filoghost.chestcommands.internal.BoundItem; import me.filoghost.chestcommands.internal.MenuInventoryHolder; import me.filoghost.chestcommands.task.ExecuteCommandsTask; -import me.filoghost.chestcommands.util.Utils; - +import java.util.HashMap; import java.util.Map; public class InventoryListener implements Listener { - private static Map antiClickSpam = Utils.newHashMap(); + private static Map antiClickSpam = new HashMap<>(); @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false) public void onInteract(PlayerInteractEvent event) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java index 8aa808e..726d3bc 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java @@ -14,6 +14,7 @@ */ package me.filoghost.chestcommands.serializer; +import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.regex.Matcher; @@ -22,11 +23,10 @@ import java.util.regex.Pattern; import me.filoghost.chestcommands.internal.icon.IconCommand; import me.filoghost.chestcommands.internal.icon.command.*; import me.filoghost.chestcommands.util.ErrorLogger; -import me.filoghost.chestcommands.util.Utils; public class CommandSerializer { - private static Map> commandTypesMap = Utils.newHashMap(); + private static Map> commandTypesMap = new HashMap<>(); static { commandTypesMap.put(commandPattern("console:"), ConsoleIconCommand.class); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java index 4d26dd2..11ec9e0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java @@ -24,7 +24,7 @@ import java.util.Map; public class EnchantmentSerializer { - private static Map enchantmentsMap = new HashMap(); + private static Map enchantmentsMap = new HashMap<>(); static { enchantmentsMap.put(formatLowercase("Protection"), Enchantment.PROTECTION_ENVIRONMENTAL); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java index 858da88..eea2661 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java @@ -14,6 +14,8 @@ */ package me.filoghost.chestcommands.serializer; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -34,7 +36,6 @@ import me.filoghost.chestcommands.util.ErrorLogger; import me.filoghost.chestcommands.util.FormatUtils; import me.filoghost.chestcommands.util.ItemStackReader; import me.filoghost.chestcommands.util.ItemUtils; -import me.filoghost.chestcommands.util.Utils; import me.filoghost.chestcommands.util.Validate; import me.filoghost.chestcommands.util.nbt.parser.MojangsonParseException; import me.filoghost.chestcommands.util.nbt.parser.MojangsonParser; @@ -137,7 +138,7 @@ public class IconSerializer { List serializedEnchantments = ConfigUtil.getStringListOrInlineList(section, ";", Nodes.ENCHANTMENTS); if (serializedEnchantments != null && !serializedEnchantments.isEmpty()) { - Map enchantments = Utils.newHashMap(); + Map enchantments = new HashMap<>(); for (String serializedEnchantment : serializedEnchantments) { if (serializedEnchantment != null && !serializedEnchantment.isEmpty()) { @@ -190,7 +191,7 @@ public class IconSerializer { List serializedCommands = ConfigUtil.getStringListOrInlineList(section, ChestCommands.getSettings().multiple_commands_separator, Nodes.ACTIONS); if (serializedCommands != null && !serializedCommands.isEmpty()) { - List commands = Utils.newArrayList(); + List commands = new ArrayList<>(); for (String serializedCommand : serializedCommands) { if (serializedCommand != null && !serializedCommand.isEmpty()) { @@ -220,7 +221,7 @@ public class IconSerializer { List serializedRequiredItems = ConfigUtil.getStringListOrSingle(section, Nodes.REQUIRED_ITEMS); if (serializedRequiredItems != null && !serializedRequiredItems.isEmpty()) { - List requiredItems = Utils.newArrayList(); + List requiredItems = new ArrayList<>(); for (String serializedItem : serializedRequiredItems) { try { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java index 340281f..cfd2ad0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java @@ -14,6 +14,7 @@ */ package me.filoghost.chestcommands.serializer; +import java.util.ArrayList; import java.util.List; import org.bukkit.ChatColor; @@ -32,7 +33,6 @@ import me.filoghost.chestcommands.util.ClickType; import me.filoghost.chestcommands.util.ErrorLogger; import me.filoghost.chestcommands.util.FormatUtils; import me.filoghost.chestcommands.util.ItemStackReader; -import me.filoghost.chestcommands.util.Utils; public class MenuSerializer { @@ -119,7 +119,7 @@ public class MenuSerializer { List serializedOpenCommands = ConfigUtil.getStringListOrInlineList(config, ChestCommands.getSettings().multiple_commands_separator, Nodes.OPEN_ACTIONS); if (serializedOpenCommands != null && !serializedOpenCommands.isEmpty()) { - List openCommands = Utils.newArrayList(); + List openCommands = new ArrayList<>(); for (String serializedCommand : serializedOpenCommands) { if (serializedCommand != null && !serializedCommand.isEmpty()) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/ErrorLoggerTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/ErrorLoggerTask.java index 6ef461d..ecea034 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/ErrorLoggerTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/ErrorLoggerTask.java @@ -20,8 +20,7 @@ import org.bukkit.ChatColor; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.util.ErrorLogger; import me.filoghost.chestcommands.util.StringUtils; -import me.filoghost.chestcommands.util.Utils; - +import java.util.ArrayList; import java.util.List; public class ErrorLoggerTask implements Runnable { @@ -35,7 +34,7 @@ public class ErrorLoggerTask implements Runnable { @Override public void run() { - List lines = Utils.newArrayList(); + List lines = new ArrayList<>(); lines.add(" "); lines.add(ChatColor.RED + "#------------------- Chest Commands Errors -------------------#"); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorLogger.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorLogger.java index a2ceec1..9dc5484 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorLogger.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorLogger.java @@ -22,14 +22,14 @@ import java.util.List; */ public class ErrorLogger { - private List errors = new ArrayList(); + private List errors = new ArrayList<>(); public void addError(String error) { errors.add(error); } public List getErrors() { - return new ArrayList(errors); + return new ArrayList<>(errors); } public boolean hasErrors() { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java index a4d07eb..e64877d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java @@ -31,7 +31,7 @@ public final class MaterialsRegistry { private static final char[] IGNORE_CHARS = {'-', '_', ' '}; // Default material names are ugly - private static final Map MATERIALS_BY_ALIAS = new HashMap(); + private static final Map MATERIALS_BY_ALIAS = new HashMap<>(); // Materials that are considered air (with 1.13+ compatibility) private static final Collection AIR_MATERIALS = getExistingMaterials("AIR", "CAVE_AIR", "VOID_AIR"); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java index cc6d4b7..036639a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java @@ -64,7 +64,7 @@ public final class Utils { BufferedReader br = null; try { - List lines = newArrayList(); + List lines = new ArrayList<>(); if (!file.exists()) { throw new FileNotFoundException(); @@ -89,18 +89,6 @@ public final class Utils { } } - public static Set newHashSet() { - return new HashSet(); - } - - public static Map newHashMap() { - return new HashMap(); - } - - public static List newArrayList() { - return new ArrayList(); - } - public static boolean isClassLoaded(String name) { try { Class.forName(name); diff --git a/pom.xml b/pom.xml index cc6598d..b0df1f8 100644 --- a/pom.xml +++ b/pom.xml @@ -19,8 +19,8 @@ UTF-8 - 1.6 - 1.6 + 1.8 + 1.8 true 1.8.8-R0.1-SNAPSHOT From 500a2699f331f1a21ea17b2be212097664e5cccb Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 5 Jun 2020 19:59:13 +0200 Subject: [PATCH 003/213] Require Bukkit 1.8 as minimum version --- Plugin/pom.xml | 6 +- .../chestcommands/ChestCommands.java | 33 ++- .../chestcommands/internal/CachedGetters.java | 4 +- .../chestcommands/task/RefreshMenusTask.java | 4 +- .../chestcommands/util/BukkitUtils.java | 114 +++---- .../chestcommands/util/ItemUtils.java | 278 ++++++------------ .../chestcommands/util/NMSUtils.java | 29 -- pom.xml | 2 +- 8 files changed, 179 insertions(+), 291 deletions(-) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/util/NMSUtils.java diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 4bf959d..66e8f36 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -41,9 +41,9 @@ - org.spigotmc - spigot-api - ${spigot-api.version} + org.bukkit + bukkit + ${bukkit.version} provided diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index e1733f3..57af845 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -45,6 +45,8 @@ import me.filoghost.chestcommands.task.RefreshMenusTask; import me.filoghost.chestcommands.util.BukkitUtils; import me.filoghost.chestcommands.util.CaseInsensitiveMap; import me.filoghost.chestcommands.util.ErrorLogger; +import me.filoghost.chestcommands.util.Utils; + import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -83,6 +85,15 @@ public class ChestCommands extends JavaPlugin { settings = new Settings(new PluginConfig(this, "config.yml")); lang = new Lang(new PluginConfig(this, "lang.yml")); + + if (!Utils.isClassLoaded("org.bukkit.inventory.ItemFlag")) { // ItemFlag was added in 1.8 + if (Bukkit.getVersion().contains("(MC: 1.8)")) { + criticalShutdown("ChestCommands requires a more recent version of Bukkit 1.8 to run."); + } else { + criticalShutdown("ChestCommands requires at least Bukkit 1.8 to run."); + } + return; + } if (!EconomyBridge.setupEconomy()) { getLogger().warning("Vault with a compatible economy plugin was not found! Icons with a PRICE or commands that give money will not work."); @@ -266,7 +277,7 @@ public class ChestCommands extends JavaPlugin { public static void closeAllMenus() { - for (Player player : BukkitUtils.getOnlinePlayers()) { + for (Player player : Bukkit.getOnlinePlayers()) { if (player.getOpenInventory() != null) { if (player.getOpenInventory().getTopInventory().getHolder() instanceof MenuInventoryHolder || player.getOpenInventory().getBottomInventory().getHolder() instanceof MenuInventoryHolder) { player.closeInventory(); @@ -315,5 +326,25 @@ public class ChestCommands extends JavaPlugin { public static void setLastReloadErrors(int lastReloadErrors) { ChestCommands.lastReloadErrors = lastReloadErrors; } + + private static void criticalShutdown(String... errorMessage) { + String separator = "****************************************************************************"; + StringBuffer output = new StringBuffer("\n "); + output.append("\n" + separator); + for (String line : errorMessage) { + output.append("\n " + line); + } + output.append("\n "); + output.append("\n This plugin has been disabled."); + output.append("\n" + separator); + output.append("\n "); + + System.out.println(output); + + try { + Thread.sleep(5000); + } catch (InterruptedException ex) {} + instance.setEnabled(false); + } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/CachedGetters.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/CachedGetters.java index 23fdcfd..5410a0f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/CachedGetters.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/CachedGetters.java @@ -14,7 +14,7 @@ */ package me.filoghost.chestcommands.internal; -import me.filoghost.chestcommands.util.BukkitUtils; +import org.bukkit.Bukkit; public class CachedGetters { @@ -27,7 +27,7 @@ public class CachedGetters { if (lastOnlinePlayersRefresh == 0 || now - lastOnlinePlayersRefresh > 1000) { // getOnlinePlayers() could be expensive if called frequently lastOnlinePlayersRefresh = now; - onlinePlayers = BukkitUtils.getOnlinePlayers().size(); + onlinePlayers = Bukkit.getOnlinePlayers().size(); } return onlinePlayers; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java index 5aedd7d..53d97f1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java @@ -14,13 +14,13 @@ */ package me.filoghost.chestcommands.task; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; import me.filoghost.chestcommands.internal.ExtendedIconMenu; import me.filoghost.chestcommands.internal.MenuInventoryHolder; -import me.filoghost.chestcommands.util.BukkitUtils; public class RefreshMenusTask implements Runnable { @@ -29,7 +29,7 @@ public class RefreshMenusTask implements Runnable { @Override public void run() { - for (Player player : BukkitUtils.getOnlinePlayers()) { + for (Player player : Bukkit.getOnlinePlayers()) { InventoryView view = player.getOpenInventory(); if (view == null) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/BukkitUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/BukkitUtils.java index 36e3be5..0bb347b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/BukkitUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/BukkitUtils.java @@ -1,73 +1,41 @@ -package me.filoghost.chestcommands.util; - -import com.google.common.collect.ImmutableList; -import org.bukkit.Bukkit; -import org.bukkit.Sound; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.Collections; - -public final class BukkitUtils { - - private static final Method LEGACY_GET_ONLINE_PLAYERS; - - static { - try { - Method method = Bukkit.class.getDeclaredMethod("getOnlinePlayers"); - LEGACY_GET_ONLINE_PLAYERS = method.getReturnType() == Player[].class ? method : null; - } catch (NoSuchMethodException e) { - // This should NEVER happen! - throw new IllegalStateException("Missing Bukkit.getOnlinePlayers() method!"); - } - } - - private BukkitUtils() { - } - - public static Collection getOnlinePlayers() { - try { - if (LEGACY_GET_ONLINE_PLAYERS == null) { - return Bukkit.getOnlinePlayers(); - } else { - Player[] playersArray = (Player[]) LEGACY_GET_ONLINE_PLAYERS.invoke(null); - return ImmutableList.copyOf(playersArray); - } - } catch (Exception e) { - e.printStackTrace(); - return Collections.emptyList(); - } - } - - public static String addYamlExtension(String input) { - if (input == null) { - return null; - } - return input.toLowerCase().endsWith(".yml") ? input : input + ".yml"; - } - - public static void saveResourceSafe(Plugin plugin, String name) { - try { - plugin.saveResource(name, false); - } catch (Exception ignored) { - } - } - - public static Sound matchSound(String input) { - if (input == null) { - return null; - } - - input = StringUtils.stripChars(input.toLowerCase(), " _-"); - - for (Sound sound : Sound.values()) { - if (StringUtils.stripChars(sound.toString().toLowerCase(), "_").equals(input)) { - return sound; - } - } - return null; - } - -} +package me.filoghost.chestcommands.util; + +import org.bukkit.Sound; +import org.bukkit.plugin.Plugin; + +public final class BukkitUtils { + + + private BukkitUtils() {} + + + public static String addYamlExtension(String input) { + if (input == null) { + return null; + } + return input.toLowerCase().endsWith(".yml") ? input : input + ".yml"; + } + + public static void saveResourceSafe(Plugin plugin, String name) { + try { + plugin.saveResource(name, false); + } catch (Exception ignored) { + } + } + + public static Sound matchSound(String input) { + if (input == null) { + return null; + } + + input = StringUtils.stripChars(input.toLowerCase(), " _-"); + + for (Sound sound : Sound.values()) { + if (StringUtils.stripChars(sound.toString().toLowerCase(), "_").equals(input)) { + return sound; + } + } + return null; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/ItemUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/ItemUtils.java index 995c1b4..32ec573 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/ItemUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/ItemUtils.java @@ -1,180 +1,98 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.util; - -import org.bukkit.Color; -import org.bukkit.DyeColor; -import org.bukkit.block.banner.Pattern; -import org.bukkit.block.banner.PatternType; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import me.filoghost.chestcommands.exception.FormatException; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -public final class ItemUtils { - - private static final boolean USE_ITEM_FLAGS_API; - private static final boolean USE_ITEM_FLAGS_REFLECTION; - - // Reflection stuff - private static Class nbtTagCompoundClass; - private static Class nbtTagListClass; - private static Class nmsItemstackClass; - private static Method asNmsCopyMethod; - private static Method asCraftMirrorMethod; - private static Method hasTagMethod; - private static Method getTagMethod; - private static Method setTagMethod; - private static Method nbtSetMethod; - - static { - if (Utils.isClassLoaded("org.bukkit.inventory.ItemFlag")) { - // We can use the new Bukkit API (1.8.3+) - USE_ITEM_FLAGS_API = true; - USE_ITEM_FLAGS_REFLECTION = false; - - } else { - USE_ITEM_FLAGS_API = false; - // Try to get the NMS methods and classes - boolean success; - try { - nbtTagCompoundClass = NMSUtils.getNMSClass("NBTTagCompound"); - nbtTagListClass = NMSUtils.getNMSClass("NBTTagList"); - nmsItemstackClass = NMSUtils.getNMSClass("ItemStack"); - - asNmsCopyMethod = NMSUtils.getCraftBukkitClass("inventory.CraftItemStack").getMethod("asNMSCopy", ItemStack.class); - asCraftMirrorMethod = NMSUtils.getCraftBukkitClass("inventory.CraftItemStack").getMethod("asCraftMirror", nmsItemstackClass); - - hasTagMethod = nmsItemstackClass.getMethod("hasTag"); - getTagMethod = nmsItemstackClass.getMethod("getTag"); - setTagMethod = nmsItemstackClass.getMethod("setTag", nbtTagCompoundClass); - - nbtSetMethod = nbtTagCompoundClass.getMethod("set", String.class, NMSUtils.getNMSClass("NBTBase")); - - success = true; - } catch (Exception e) { - new IllegalStateException("Could not enable the attribute remover for this version." + - "Attributes will show up on items.", e).printStackTrace(); - success = false; - } - USE_ITEM_FLAGS_REFLECTION = success; - } - } - - private ItemUtils() { - } - - public static ItemStack hideAttributes(ItemStack item) { - if (item == null) { - return null; - } - - if (USE_ITEM_FLAGS_API) { - ItemMeta meta = item.getItemMeta(); - if (Utils.isNullOrEmpty(meta.getItemFlags())) { - // Add them only if necessary - meta.addItemFlags(ItemFlag.values()); - item.setItemMeta(meta); - } - return item; - - } else if (USE_ITEM_FLAGS_REFLECTION) { - try { - - Object nmsItemstack = asNmsCopyMethod.invoke(null, item); - if (nmsItemstack == null) { - return item; - } - - Object nbtCompound; - if ((Boolean) hasTagMethod.invoke(nmsItemstack)) { - nbtCompound = getTagMethod.invoke(nmsItemstack); - } else { - nbtCompound = nbtTagCompoundClass.newInstance(); - setTagMethod.invoke(nmsItemstack, nbtCompound); - } - - if (nbtCompound == null) { - return item; - } - - Object nbtList = nbtTagListClass.newInstance(); - nbtSetMethod.invoke(nbtCompound, "AttributeModifiers", nbtList); - return (ItemStack) asCraftMirrorMethod.invoke(null, nmsItemstack); - - } catch (Throwable t) { - // Ignore - } - } - - // On failure just return the item - return item; - } - - public static Color parseColor(String input) throws FormatException { - String[] split = StringUtils.stripChars(input, " ").split(","); - - if (split.length != 3) { - throw new FormatException("it must be in the format \"red, green, blue\"."); - } - - int red, green, blue; - - try { - red = Integer.parseInt(split[0]); - green = Integer.parseInt(split[1]); - blue = Integer.parseInt(split[2]); - } catch (NumberFormatException ex) { - throw new FormatException("it contains invalid numbers."); - } - - if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) { - throw new FormatException("it should only contain numbers between 0 and 255."); - } - - return Color.fromRGB(red, green, blue); - } - - public static DyeColor parseDyeColor(String input) throws FormatException { - DyeColor color; - try { - color = DyeColor.valueOf(input.toUpperCase()); - } catch (IllegalArgumentException e) { - throw new FormatException("it must be a valid color."); - } - return color; - } - - public static List parseBannerPatternList(List input) throws FormatException { - List patterns = new ArrayList(); - for (String str : input) { - String[] split = str.split(":"); - if (split.length != 2) { - throw new FormatException("it must be in the format \"pattern:color\"."); - } - try { - patterns.add(new Pattern(parseDyeColor(split[1]), PatternType.valueOf(split[0].toUpperCase()))); - } catch (IllegalArgumentException e) { - throw new FormatException("it must be a valid pattern type."); - } - } - return patterns; - } -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.util; + +import org.bukkit.Color; +import org.bukkit.DyeColor; +import org.bukkit.block.banner.Pattern; +import org.bukkit.block.banner.PatternType; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import me.filoghost.chestcommands.exception.FormatException; + +import java.util.ArrayList; +import java.util.List; + +public final class ItemUtils { + + private ItemUtils() { + } + + public static ItemStack hideAttributes(ItemStack item) { + if (item == null) { + return null; + } + + ItemMeta meta = item.getItemMeta(); + if (Utils.isNullOrEmpty(meta.getItemFlags())) { + // Add them only if no flag was already set + meta.addItemFlags(ItemFlag.values()); + item.setItemMeta(meta); + } + return item; + } + + public static Color parseColor(String input) throws FormatException { + String[] split = StringUtils.stripChars(input, " ").split(","); + + if (split.length != 3) { + throw new FormatException("it must be in the format \"red, green, blue\"."); + } + + int red, green, blue; + + try { + red = Integer.parseInt(split[0]); + green = Integer.parseInt(split[1]); + blue = Integer.parseInt(split[2]); + } catch (NumberFormatException ex) { + throw new FormatException("it contains invalid numbers."); + } + + if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) { + throw new FormatException("it should only contain numbers between 0 and 255."); + } + + return Color.fromRGB(red, green, blue); + } + + public static DyeColor parseDyeColor(String input) throws FormatException { + DyeColor color; + try { + color = DyeColor.valueOf(input.toUpperCase()); + } catch (IllegalArgumentException e) { + throw new FormatException("it must be a valid color."); + } + return color; + } + + public static List parseBannerPatternList(List input) throws FormatException { + List patterns = new ArrayList(); + for (String str : input) { + String[] split = str.split(":"); + if (split.length != 2) { + throw new FormatException("it must be in the format \"pattern:color\"."); + } + try { + patterns.add(new Pattern(parseDyeColor(split[1]), PatternType.valueOf(split[0].toUpperCase()))); + } catch (IllegalArgumentException e) { + throw new FormatException("it must be a valid pattern type."); + } + } + return patterns; + } +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/NMSUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/NMSUtils.java deleted file mode 100644 index eaa82e8..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/NMSUtils.java +++ /dev/null @@ -1,29 +0,0 @@ -package me.filoghost.chestcommands.util; - -import org.bukkit.Bukkit; - -public final class NMSUtils { - - private static final String NMS_VERSION; - - static { - String packageName = Bukkit.getServer().getClass().getPackage().getName(); - NMS_VERSION = packageName.substring(packageName.lastIndexOf('.') + 1); - } - - private NMSUtils() { - } - - public static String getNMSVersion() { - return NMS_VERSION; - } - - public static Class getNMSClass(String name) throws ClassNotFoundException { - return Class.forName("net.minecraft.server." + NMSUtils.getNMSVersion() + "." + name); - } - - public static Class getCraftBukkitClass(String name) throws ClassNotFoundException { - return Class.forName("org.bukkit.craftbukkit." + NMSUtils.getNMSVersion() + "." + name); - } - -} diff --git a/pom.xml b/pom.xml index b0df1f8..9ae9475 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ 1.8 1.8 true - 1.8.8-R0.1-SNAPSHOT + 1.8-R0.1-SNAPSHOT From 0e11620fd544307f4f7fad5c5f01a954783f365a Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 09:18:05 +0200 Subject: [PATCH 004/213] Update bStats metrics --- Plugin/pom.xml | 250 +++++++++--------- .../chestcommands/ChestCommands.java | 3 +- 2 files changed, 127 insertions(+), 126 deletions(-) diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 66e8f36..98d2702 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -1,126 +1,126 @@ - - - 4.0.0 - - - me.filoghost.chestcommands - chestcommands-parent - 4.0-SNAPSHOT - - - chestcommands-plugin - ChestCommands Plugin - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/groups/public/ - - - - vault-repo - http://nexus.hc.to/content/repositories/pub_releases - - - - confuser-repo - https://ci.frostcast.net/plugin/repository/everything/ - - - - bstats-repo - https://repo.codemc.org/repository/maven-public/ - - - - placeholderapi-repo - http://repo.extendedclip.com/content/repositories/placeholderapi/ - - - - - - org.bukkit - bukkit - ${bukkit.version} - provided - - - - net.milkbowl.vault - VaultAPI - 1.6 - provided - - - - me.confuser - BarAPI - 3.5 - provided - - - - me.clip - placeholderapi - 2.9.2 - provided - - - - org.bstats - bstats-bukkit-lite - 1.4 - - - - - - - src/main/resources - true - - - .. - - LICENSE.txt - THIRD-PARTY.txt - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.1 - - false - - - *:* - - META-INF/ - - - - - - org.bstats - me.filoghost.chestcommands.metrics - - - - - - package - - shade - - - - - - - + + + 4.0.0 + + + me.filoghost.chestcommands + chestcommands-parent + 4.0-SNAPSHOT + + + chestcommands-plugin + ChestCommands Plugin + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + + vault-repo + http://nexus.hc.to/content/repositories/pub_releases + + + + confuser-repo + https://ci.frostcast.net/plugin/repository/everything/ + + + + codemc-repo + https://repo.codemc.io/repository/maven-public/ + + + + placeholderapi-repo + http://repo.extendedclip.com/content/repositories/placeholderapi/ + + + + + + org.bukkit + bukkit + ${bukkit.version} + provided + + + + net.milkbowl.vault + VaultAPI + 1.6 + provided + + + + me.confuser + BarAPI + 3.5 + provided + + + + me.clip + placeholderapi + 2.9.2 + provided + + + + org.bstats + bstats-bukkit-lite + 1.7 + + + + + + + src/main/resources + true + + + .. + + LICENSE.txt + THIRD-PARTY.txt + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + false + + + *:* + + META-INF/ + + + + + + org.bstats + me.filoghost.chestcommands.metrics + + + + + + package + + shade + + + + + + + \ No newline at end of file diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 57af845..2999aa7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -124,7 +124,8 @@ public class ChestCommands extends JavaPlugin { } // Start bStats metrics - new MetricsLite(this); + int pluginID = 3658; + new MetricsLite(this, pluginID); Bukkit.getPluginManager().registerEvents(new CommandListener(), this); Bukkit.getPluginManager().registerEvents(new InventoryListener(), this); From 1a22b1dc7023dc510183ed411ebc257e88df259f Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 09:20:45 +0200 Subject: [PATCH 005/213] Use newer Vault economy methods --- .../me/filoghost/chestcommands/bridge/EconomyBridge.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java index 7cf4d0b..127491e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java @@ -49,14 +49,14 @@ public class EconomyBridge { public static double getMoney(Player player) { if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!"); - return economy.getBalance(player.getName(), player.getWorld().getName()); + return economy.getBalance(player, player.getWorld().getName()); } public static boolean hasMoney(Player player, double minimum) { if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!"); if (minimum < 0.0) throw new IllegalArgumentException("Invalid amount of money: " + minimum); - double balance = economy.getBalance(player.getName(), player.getWorld().getName()); + double balance = economy.getBalance(player, player.getWorld().getName()); if (balance < minimum) { return false; @@ -72,7 +72,7 @@ public class EconomyBridge { if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!"); if (amount < 0.0) throw new IllegalArgumentException("Invalid amount of money: " + amount); - EconomyResponse response = economy.withdrawPlayer(player.getName(), player.getWorld().getName(), amount); + EconomyResponse response = economy.withdrawPlayer(player, player.getWorld().getName(), amount); boolean result = response.transactionSuccess(); MenuUtils.refreshMenu(player); @@ -84,7 +84,7 @@ public class EconomyBridge { if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!"); if (amount < 0.0) throw new IllegalArgumentException("Invalid amount of money: " + amount); - EconomyResponse response = economy.depositPlayer(player.getName(), player.getWorld().getName(), amount); + EconomyResponse response = economy.depositPlayer(player, player.getWorld().getName(), amount); boolean result = response.transactionSuccess(); MenuUtils.refreshMenu(player); From 98150cead205010c11ad8a7005e5123aa65f1363 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 09:27:26 +0200 Subject: [PATCH 006/213] Use new plugin updater --- Plugin/pom.xml | 10 + .../chestcommands/ChestCommands.java | 23 +- .../chestcommands/SimpleUpdater.java | 215 ------------------ 3 files changed, 22 insertions(+), 226 deletions(-) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/SimpleUpdater.java diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 98d2702..787bae8 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -73,6 +73,12 @@ bstats-bukkit-lite 1.7 + + + me.filoghost.updatechecker + updatechecker + 1.0.0 + @@ -109,6 +115,10 @@ org.bstats me.filoghost.chestcommands.metrics + + me.filoghost.updatechecker + me.filoghost.chestcommands.updater + diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 2999aa7..06cfb2a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -14,6 +14,14 @@ */ package me.filoghost.chestcommands; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + import org.bstats.bukkit.MetricsLite; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -46,14 +54,7 @@ import me.filoghost.chestcommands.util.BukkitUtils; import me.filoghost.chestcommands.util.CaseInsensitiveMap; import me.filoghost.chestcommands.util.ErrorLogger; import me.filoghost.chestcommands.util.Utils; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import me.filoghost.updatechecker.UpdateChecker; public class ChestCommands extends JavaPlugin { @@ -108,17 +109,17 @@ public class ChestCommands extends JavaPlugin { } if (settings.update_notifications) { - new SimpleUpdater(this, 56919).checkForUpdates((String newVersion) -> { + UpdateChecker.run(this, 56919, (String newVersion) -> { ChestCommands.newVersion = newVersion; if (settings.use_console_colors) { Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + "Found a new version: " + newVersion + ChatColor.WHITE + " (yours: v" + getDescription().getVersion() + ")"); Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + ChatColor.WHITE + "Download it on Bukkit Dev:"); - Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + ChatColor.WHITE + "dev.bukkit.org/bukkit-plugins/chest-commands"); + Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + ChatColor.WHITE + "https://dev.bukkit.org/projects/chest-commands"); } else { getLogger().info("Found a new version available: " + newVersion); getLogger().info("Download it on Bukkit Dev:"); - getLogger().info("dev.bukkit.org/bukkit-plugins/chest-commands"); + getLogger().info("https://dev.bukkit.org/projects/chest-commands"); } }); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/SimpleUpdater.java b/Plugin/src/main/java/me/filoghost/chestcommands/SimpleUpdater.java deleted file mode 100644 index 1d8c60d..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/SimpleUpdater.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands; - -import com.google.common.primitives.Ints; -import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * A very simple and lightweight updater, without download features. - * - * @author filoghost - */ -public final class SimpleUpdater { - - private static Pattern VERSION_PATTERN = Pattern.compile("v?([0-9\\.]+)"); - - private Plugin plugin; - private int projectId; - - - public SimpleUpdater(Plugin plugin, int projectId) { - if (plugin == null) { - throw new NullPointerException("Plugin cannot be null"); - } - - this.plugin = plugin; - this.projectId = projectId; - } - - - /** - * This method creates a new async thread to check for updates. - * - * @param responseHandler the response handler - */ - public void checkForUpdates(final ResponseHandler responseHandler) { - Thread updaterThread = new Thread(() -> { - try { - JSONArray filesArray = (JSONArray) readJson("https://api.curseforge.com/servermods/files?projectIds=" + projectId); - - if (filesArray.size() == 0) { - // The array cannot be empty, there must be at least one file. - // The project ID is not valid or curse returned a wrong response. - return; - } - - String updateName = (String) ((JSONObject) filesArray.get(filesArray.size() - 1)).get("name"); - final PluginVersion remoteVersion = new PluginVersion(updateName); - PluginVersion localVersion = new PluginVersion(plugin.getDescription().getVersion()); - - if (remoteVersion.isNewerThan(localVersion)) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - - @Override - public void run() { - responseHandler.onUpdateFound(remoteVersion.toString()); - } - }); - } - - } catch (IOException e) { - plugin.getLogger().warning("Could not contact BukkitDev to check for updates."); - } catch (InvalidVersionException e) { - plugin.getLogger().warning("Could not check for updates because of a version format error: " + e.getMessage() + "."); - plugin.getLogger().warning("Please notify the author of this error."); - } catch (Exception e) { - e.printStackTrace(); - plugin.getLogger().warning("Unable to check for updates: unhandled exception."); - } - }); - - updaterThread.start(); - } - - - private Object readJson(String url) throws MalformedURLException, IOException { - URLConnection conn = new URL(url).openConnection(); - conn.setConnectTimeout(5000); - conn.setReadTimeout(8000); - conn.addRequestProperty("User-Agent", "Updater (by filoghost)"); - conn.setDoOutput(true); - - return JSONValue.parse(new BufferedReader(new InputStreamReader(conn.getInputStream()))); - } - - - private static class PluginVersion { - - // The version extracted from a string, e.g. "Chest Commands v1.3" becomes [1, 3] - private int[] versionNumbers; - private boolean isDevBuild; - - - public PluginVersion(String input) throws InvalidVersionException { - if (input == null) { - throw new InvalidVersionException("input was null"); - } - - Matcher matcher = VERSION_PATTERN.matcher(input); - - if (!matcher.find()) { - throw new InvalidVersionException("version pattern not found in \"" + input + "\""); - } - - // Get the first group of the matcher (without the "v") - String version = matcher.group(1); - - // Replace multiple full stops (probably typos) with a single full stop, and split the version with them - String[] versionParts = version.replaceAll("[\\.]{2,}", ".").split("\\."); - - // Convert the strings to integers in order to compare them - this.versionNumbers = new int[versionParts.length]; - for (int i = 0; i < versionParts.length; i++) { - try { - this.versionNumbers[i] = Integer.parseInt(versionParts[i]); - } catch (NumberFormatException e) { - throw new InvalidVersionException("invalid number in \"" + input + "\""); - } - } - - this.isDevBuild = input.contains("SNAPSHOT"); - } - - - /** - * Compares this version with another version, using the array "versionNumbers". - * Examples: - * v1.12 is newer than v1.2 ([1, 12] is newer than [1, 2]) - * v2.01 is equal to v2.1 ([2, 1] is equal to [2, 1]) - * - * @return true if this version is newer than the other, false if equal or older - */ - public boolean isNewerThan(PluginVersion other) { - int longest = Math.max(this.versionNumbers.length, other.versionNumbers.length); - - for (int i = 0; i < longest; i++) { - int thisVersionPart = i < this.versionNumbers.length ? this.versionNumbers[i] : 0; - int otherVersionPart = i < other.versionNumbers.length ? other.versionNumbers[i] : 0; - int diff = thisVersionPart - otherVersionPart; - - if (diff > 0) { - return true; - } else if (diff < 0) { - return false; - } - - // Continue the loop until diff = 0 - } - - // If we get here, they're the same version, check dev builds. - // This version is newer only if it's not a dev build and the other is. - if (other.isDevBuild && !this.isDevBuild) { - return true; - } - - return false; - } - - - @Override - public String toString() { - return "v" + Ints.join(".", versionNumbers); - } - - } - - - private static class InvalidVersionException extends Exception { - - private static final long serialVersionUID = 1L; - - public InvalidVersionException(String message) { - super(message); - } - - } - - - public interface ResponseHandler { - - /** - * Called when the updater finds a new version. - * - * @param newVersion - the new version - */ - public void onUpdateFound(final String newVersion); - - } - -} From aa43cd2dc757ee44015ec580bbf09b9ba44b365a Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 09:59:46 +0200 Subject: [PATCH 007/213] Improve error collector --- .../chestcommands/ChestCommands.java | 49 ++++++------ .../chestcommands/command/CommandHandler.java | 15 ++-- .../config/AsciiPlaceholders.java | 24 +++--- .../chestcommands/listener/JoinListener.java | 4 +- .../serializer/CommandSerializer.java | 6 +- .../serializer/EnchantmentSerializer.java | 16 ++-- .../serializer/IconSerializer.java | 22 +++--- .../serializer/MenuSerializer.java | 18 ++--- .../chestcommands/task/ErrorLoggerTask.java | 56 -------------- .../chestcommands/util/ErrorCollector.java | 77 +++++++++++++++++++ .../chestcommands/util/ErrorLogger.java | 43 ----------- 11 files changed, 155 insertions(+), 175 deletions(-) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/task/ErrorLoggerTask.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorCollector.java delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorLogger.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 06cfb2a..552ce96 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -48,18 +48,19 @@ import me.filoghost.chestcommands.listener.JoinListener; import me.filoghost.chestcommands.listener.SignListener; import me.filoghost.chestcommands.serializer.CommandSerializer; import me.filoghost.chestcommands.serializer.MenuSerializer; -import me.filoghost.chestcommands.task.ErrorLoggerTask; import me.filoghost.chestcommands.task.RefreshMenusTask; import me.filoghost.chestcommands.util.BukkitUtils; import me.filoghost.chestcommands.util.CaseInsensitiveMap; -import me.filoghost.chestcommands.util.ErrorLogger; +import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.Utils; import me.filoghost.updatechecker.UpdateChecker; public class ChestCommands extends JavaPlugin { + public static final String CHAT_PREFIX = ChatColor.DARK_GREEN + "[" + ChatColor.GREEN + "ChestCommands" + ChatColor.DARK_GREEN + "] " + ChatColor.GREEN; + private static ChestCommands instance; private static Settings settings; private static Lang lang; @@ -69,7 +70,7 @@ public class ChestCommands extends JavaPlugin { private static Set boundItems; - private static int lastReloadErrors; + private static ErrorCollector lastLoadErrors; private static String newVersion; @Override @@ -135,12 +136,14 @@ public class ChestCommands extends JavaPlugin { CommandFramework.register(this, new CommandHandler("chestcommands")); - ErrorLogger errorLogger = new ErrorLogger(); - load(errorLogger); + ErrorCollector errorCollector = new ErrorCollector(); + load(errorCollector); - lastReloadErrors = errorLogger.getSize(); - if (errorLogger.hasErrors()) { - Bukkit.getScheduler().scheduleSyncDelayedTask(this, new ErrorLoggerTask(errorLogger), 10L); + lastLoadErrors = errorCollector; + if (errorCollector.hasWarningsOrErrors()) { + Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> { + errorCollector.logToConsole(); + }, 10L); } Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new RefreshMenusTask(), 2L, 2L); @@ -153,12 +156,12 @@ public class ChestCommands extends JavaPlugin { } - public void load(ErrorLogger errorLogger) { + public void load(ErrorCollector errorCollector) { fileNameToMenuMap.clear(); commandsToMenuMap.clear(); boundItems.clear(); - CommandSerializer.checkClassConstructors(errorLogger); + CommandSerializer.checkClassConstructors(errorCollector); try { settings.load(); @@ -187,7 +190,7 @@ public class ChestCommands extends JavaPlugin { } try { - AsciiPlaceholders.load(errorLogger); + AsciiPlaceholders.load(errorCollector); } catch (IOException e) { e.printStackTrace(); getLogger().warning("I/O error while reading the placeholders. They will not work."); @@ -211,19 +214,19 @@ public class ChestCommands extends JavaPlugin { menuConfig.load(); } catch (IOException e) { e.printStackTrace(); - errorLogger.addError("I/O error while loading the menu \"" + menuConfig.getFileName() + "\". Is the file in use?"); + errorCollector.addError("I/O error while loading the menu \"" + menuConfig.getFileName() + "\". Is the file in use?"); continue; } catch (InvalidConfigurationException e) { e.printStackTrace(); - errorLogger.addError("Invalid YAML configuration for the menu \"" + menuConfig.getFileName() + "\". Please look at the error above, or use an online YAML parser (google is your friend)."); + errorCollector.addError("Invalid YAML configuration for the menu \"" + menuConfig.getFileName() + "\". Please look at the error above, or use an online YAML parser (google is your friend)."); continue; } - MenuData data = MenuSerializer.loadMenuData(menuConfig, errorLogger); - ExtendedIconMenu iconMenu = MenuSerializer.loadMenu(menuConfig, data.getTitle(), data.getRows(), errorLogger); + MenuData data = MenuSerializer.loadMenuData(menuConfig, errorCollector); + ExtendedIconMenu iconMenu = MenuSerializer.loadMenu(menuConfig, data.getTitle(), data.getRows(), errorCollector); if (fileNameToMenuMap.containsKey(menuConfig.getFileName())) { - errorLogger.addError("Two menus have the same file name \"" + menuConfig.getFileName() + "\" with different cases. There will be problems opening one of these two menus."); + errorCollector.addError("Two menus have the same file name \"" + menuConfig.getFileName() + "\" with different cases. There will be problems opening one of these two menus."); } fileNameToMenuMap.put(menuConfig.getFileName(), iconMenu); @@ -231,7 +234,7 @@ public class ChestCommands extends JavaPlugin { for (String command : data.getCommands()) { if (!command.isEmpty()) { if (commandsToMenuMap.containsKey(command)) { - errorLogger.addError("The menus \"" + commandsToMenuMap.get(command).getFileName() + "\" and \"" + menuConfig.getFileName() + "\" have the same command \"" + command + "\". Only one will be opened."); + errorCollector.addError("The menus \"" + commandsToMenuMap.get(command).getFileName() + "\" and \"" + menuConfig.getFileName() + "\" have the same command \"" + command + "\". Only one will be opened."); } commandsToMenuMap.put(command, iconMenu); } @@ -321,14 +324,14 @@ public class ChestCommands extends JavaPlugin { return boundItems; } - public static int getLastReloadErrors() { - return lastReloadErrors; - } - - public static void setLastReloadErrors(int lastReloadErrors) { - ChestCommands.lastReloadErrors = lastReloadErrors; + public static void setLastReloadErrors(ErrorCollector lastLoadErrors) { + ChestCommands.lastLoadErrors = lastLoadErrors; } + public static ErrorCollector getLastLoadErrors() { + return lastLoadErrors; + } + private static void criticalShutdown(String... errorMessage) { String separator = "****************************************************************************"; StringBuffer output = new StringBuffer("\n "); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index 990a670..05e45a7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -25,8 +25,7 @@ import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.command.framework.CommandFramework; import me.filoghost.chestcommands.command.framework.CommandValidate; import me.filoghost.chestcommands.internal.ExtendedIconMenu; -import me.filoghost.chestcommands.task.ErrorLoggerTask; -import me.filoghost.chestcommands.util.ErrorLogger; +import me.filoghost.chestcommands.util.ErrorCollector; public class CommandHandler extends CommandFramework { @@ -61,16 +60,16 @@ public class CommandHandler extends CommandFramework { ChestCommands.closeAllMenus(); - ErrorLogger errorLogger = new ErrorLogger(); - ChestCommands.getInstance().load(errorLogger); + ErrorCollector errorCollector = new ErrorCollector(); + ChestCommands.getInstance().load(errorCollector); - ChestCommands.setLastReloadErrors(errorLogger.getSize()); + ChestCommands.setLastReloadErrors(errorCollector); - if (!errorLogger.hasErrors()) { + if (!errorCollector.hasWarningsOrErrors()) { sender.sendMessage(ChestCommands.CHAT_PREFIX + "Plugin reloaded."); } else { - new ErrorLoggerTask(errorLogger).run(); - sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Plugin reloaded with " + errorLogger.getSize() + " error(s)."); + errorCollector.logToConsole(); + sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Plugin reloaded with " + errorCollector.getWarningsCount() + " warning(s) and " + errorCollector.getErrorsCount() + " error(s)."); if (!(sender instanceof ConsoleCommandSender)) { sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Please check the console."); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java index fecbf82..5d4d3c0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java @@ -14,14 +14,6 @@ */ package me.filoghost.chestcommands.config; -import org.apache.commons.lang.StringEscapeUtils; - -import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.util.BukkitUtils; -import me.filoghost.chestcommands.util.ErrorLogger; -import me.filoghost.chestcommands.util.FormatUtils; -import me.filoghost.chestcommands.util.Utils; - import java.io.File; import java.io.IOException; import java.util.HashMap; @@ -29,6 +21,14 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import org.apache.commons.lang.StringEscapeUtils; + +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.util.BukkitUtils; +import me.filoghost.chestcommands.util.ErrorCollector; +import me.filoghost.chestcommands.util.FormatUtils; +import me.filoghost.chestcommands.util.Utils; + /** * This is not a real YAML file ;) */ @@ -37,7 +37,7 @@ public class AsciiPlaceholders { private static Map placeholders = new HashMap<>(); - public static void load(ErrorLogger errorLogger) throws IOException, Exception { + public static void load(ErrorCollector errorCollector) throws IOException, Exception { placeholders.clear(); File file = new File(ChestCommands.getInstance().getDataFolder(), "placeholders.yml"); @@ -55,7 +55,7 @@ public class AsciiPlaceholders { } if (!line.contains(":")) { - errorLogger.addError("Unable to parse a line(" + line + ") from placeholders.yml: it must contain ':' to separate the placeholder and the replacement."); + errorCollector.addError("Unable to parse a line(" + line + ") from placeholders.yml: it must contain ':' to separate the placeholder and the replacement."); continue; } @@ -64,12 +64,12 @@ public class AsciiPlaceholders { String replacement = FormatUtils.addColors(StringEscapeUtils.unescapeJava(unquote(line.substring(indexOf + 1, line.length()).trim()))); if (placeholder.length() == 0 || replacement.length() == 0) { - errorLogger.addError("Unable to parse a line(" + line + ") from placeholders.yml: the placeholder and the replacement must have both at least 1 character."); + errorCollector.addError("Unable to parse a line(" + line + ") from placeholders.yml: the placeholder and the replacement must have both at least 1 character."); continue; } if (placeholder.length() > 100) { - errorLogger.addError("Unable to parse a line(" + line + ") from placeholders.yml: the placeholder cannot be longer than 100 characters."); + errorCollector.addError("Unable to parse a line(" + line + ") from placeholders.yml: the placeholder cannot be longer than 100 characters."); continue; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java index 3e476b3..d39cf31 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java @@ -27,8 +27,8 @@ public class JoinListener implements Listener { @EventHandler public void onJoin(PlayerJoinEvent event) { - if (ChestCommands.getLastReloadErrors() > 0 && event.getPlayer().hasPermission(Permissions.SEE_ERRORS)) { - event.getPlayer().sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "The plugin found " + ChestCommands.getLastReloadErrors() + " error(s) last time it was loaded. You can see them by doing \"/cc reload\" in the console."); + if (ChestCommands.getLastLoadErrors().hasWarningsOrErrors() && event.getPlayer().hasPermission(Permissions.SEE_ERRORS)) { + event.getPlayer().sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "The plugin found " + ChestCommands.getLastLoadErrors().getWarningsCount() + " warning(s) and " + ChestCommands.getLastLoadErrors().getErrorsCount() + " error(s) last time it was loaded. You can see them by doing \"/cc reload\" in the console."); } if (ChestCommands.hasNewVersion() && ChestCommands.getSettings().update_notifications && event.getPlayer().hasPermission(Permissions.UPDATE_NOTIFICATIONS)) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java index 726d3bc..08cf657 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java @@ -22,7 +22,7 @@ import java.util.regex.Pattern; import me.filoghost.chestcommands.internal.icon.IconCommand; import me.filoghost.chestcommands.internal.icon.command.*; -import me.filoghost.chestcommands.util.ErrorLogger; +import me.filoghost.chestcommands.util.ErrorCollector; public class CommandSerializer { @@ -45,14 +45,14 @@ public class CommandSerializer { return Pattern.compile("^(?i)" + regex); // Case insensitive and only at the beginning } - public static void checkClassConstructors(ErrorLogger errorLogger) { + public static void checkClassConstructors(ErrorCollector errorCollector) { for (Class clazz : commandTypesMap.values()) { try { clazz.getDeclaredConstructor(String.class).newInstance(""); } catch (Exception ex) { String className = clazz.getName().replace("Command", ""); className = className.substring(className.lastIndexOf('.') + 1, className.length()); - errorLogger.addError("Unable to register the \"" + className + "\" command type(" + ex.getClass().getName() + "), please inform the developer (filoghost). The plugin will still work, but all the \"" + className + "\" commands will be treated as normal commands."); + errorCollector.addError("Unable to register the \"" + className + "\" command type(" + ex.getClass().getName() + "), please inform the developer (filoghost). The plugin will still work, but all the \"" + className + "\" commands will be treated as normal commands."); } } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java index 11ec9e0..11cab71 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java @@ -14,14 +14,14 @@ */ package me.filoghost.chestcommands.serializer; -import org.bukkit.enchantments.Enchantment; - -import me.filoghost.chestcommands.util.ErrorLogger; -import me.filoghost.chestcommands.util.StringUtils; - import java.util.HashMap; import java.util.Map; +import org.bukkit.enchantments.Enchantment; + +import me.filoghost.chestcommands.util.ErrorCollector; +import me.filoghost.chestcommands.util.StringUtils; + public class EnchantmentSerializer { private static Map enchantmentsMap = new HashMap<>(); @@ -64,7 +64,7 @@ public class EnchantmentSerializer { return StringUtils.stripChars(string, " _-").toLowerCase(); } - public static EnchantmentDetails parseEnchantment(String input, String iconName, String menuFileName, ErrorLogger errorLogger) { + public static EnchantmentDetails parseEnchantment(String input, String iconName, String menuFileName, ErrorCollector errorCollector) { int level = 1; if (input.contains(",")) { @@ -73,7 +73,7 @@ public class EnchantmentSerializer { try { level = Integer.parseInt(levelSplit[1].trim()); } catch (NumberFormatException ex) { - errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid enchantment level: " + levelSplit[1]); + errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid enchantment level: " + levelSplit[1]); } input = levelSplit[0]; } @@ -81,7 +81,7 @@ public class EnchantmentSerializer { Enchantment ench = matchEnchantment(input); if (ench == null) { - errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid enchantment: " + input); + errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid enchantment: " + input); } else { return new EnchantmentDetails(ench, level); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java index eea2661..879bb2d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java @@ -32,7 +32,7 @@ import me.filoghost.chestcommands.internal.RequiredItem; import me.filoghost.chestcommands.internal.icon.ExtendedIcon; import me.filoghost.chestcommands.internal.icon.IconCommand; import me.filoghost.chestcommands.serializer.EnchantmentSerializer.EnchantmentDetails; -import me.filoghost.chestcommands.util.ErrorLogger; +import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.FormatUtils; import me.filoghost.chestcommands.util.ItemStackReader; import me.filoghost.chestcommands.util.ItemUtils; @@ -94,7 +94,7 @@ public class IconSerializer { } - public static Icon loadIconFromSection(ConfigurationSection section, String iconName, String menuFileName, ErrorLogger errorLogger) { + public static Icon loadIconFromSection(ConfigurationSection section, String iconName, String menuFileName, ErrorCollector errorCollector) { Validate.notNull(section, "ConfigurationSection cannot be null"); // The icon is valid even without a Material @@ -108,7 +108,7 @@ public class IconSerializer { icon.setDataValue(itemReader.getDataValue()); icon.setAmount(itemReader.getAmount()); } catch (FormatException e) { - errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid ID: " + e.getMessage()); + errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid ID: " + e.getMessage()); } } @@ -128,7 +128,7 @@ public class IconSerializer { MojangsonParser.parse(nbtData); icon.setNBTData(nbtData); } catch (MojangsonParseException e) { - errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid NBT-DATA: " + e.getMessage()); + errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid NBT-DATA: " + e.getMessage()); } } @@ -142,7 +142,7 @@ public class IconSerializer { for (String serializedEnchantment : serializedEnchantments) { if (serializedEnchantment != null && !serializedEnchantment.isEmpty()) { - EnchantmentDetails enchantment = EnchantmentSerializer.parseEnchantment(serializedEnchantment, iconName, menuFileName, errorLogger); + EnchantmentDetails enchantment = EnchantmentSerializer.parseEnchantment(serializedEnchantment, iconName, menuFileName, errorCollector); if (enchantment != null) { enchantments.put(enchantment.getEnchantment(), enchantment.getLevel()); } @@ -158,7 +158,7 @@ public class IconSerializer { try { icon.setColor(ItemUtils.parseColor(section.getString(Nodes.COLOR))); } catch (FormatException e) { - errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid COLOR: " + e.getMessage()); + errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid COLOR: " + e.getMessage()); } } @@ -169,7 +169,7 @@ public class IconSerializer { try { icon.setBannerColor(ItemUtils.parseDyeColor(bannerColor)); } catch (FormatException e) { - errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid BANNER-COLOR: " + e.getMessage()); + errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid BANNER-COLOR: " + e.getMessage()); } } @@ -177,7 +177,7 @@ public class IconSerializer { try { icon.setBannerPatterns(ItemUtils.parseBannerPatternList(section.getStringList(Nodes.BANNER_PATTERNS))); } catch (FormatException e) { - errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid BANNER-PATTERNS: " + e.getMessage()); + errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid BANNER-PATTERNS: " + e.getMessage()); } } @@ -208,14 +208,14 @@ public class IconSerializer { if (price > 0.0) { icon.setMoneyPrice(price); } else if (price < 0.0) { - errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has a negative PRICE: " + price); + errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has a negative PRICE: " + price); } int levels = section.getInt(Nodes.EXP_LEVELS); if (levels > 0) { icon.setExpLevelsPrice(levels); } else if (levels < 0) { - errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has negative LEVELS: " + levels); + errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has negative LEVELS: " + levels); } List serializedRequiredItems = ConfigUtil.getStringListOrSingle(section, Nodes.REQUIRED_ITEMS); @@ -232,7 +232,7 @@ public class IconSerializer { } requiredItems.add(requiredItem); } catch (FormatException e) { - errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has invalid REQUIRED-ITEMS: " + e.getMessage()); + errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has invalid REQUIRED-ITEMS: " + e.getMessage()); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java index cfd2ad0..47e0b84 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java @@ -30,7 +30,7 @@ import me.filoghost.chestcommands.internal.MenuData; import me.filoghost.chestcommands.internal.icon.IconCommand; import me.filoghost.chestcommands.serializer.IconSerializer.Coords; import me.filoghost.chestcommands.util.ClickType; -import me.filoghost.chestcommands.util.ErrorLogger; +import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.FormatUtils; import me.filoghost.chestcommands.util.ItemStackReader; @@ -52,7 +52,7 @@ public class MenuSerializer { } - public static ExtendedIconMenu loadMenu(PluginConfig config, String title, int rows, ErrorLogger errorLogger) { + public static ExtendedIconMenu loadMenu(PluginConfig config, String title, int rows, ErrorCollector errorCollector) { ExtendedIconMenu iconMenu = new ExtendedIconMenu(title, rows, config.getFileName()); for (String subSectionName : config.getKeys(false)) { @@ -62,16 +62,16 @@ public class MenuSerializer { ConfigurationSection iconSection = config.getConfigurationSection(subSectionName); - Icon icon = IconSerializer.loadIconFromSection(iconSection, subSectionName, config.getFileName(), errorLogger); + Icon icon = IconSerializer.loadIconFromSection(iconSection, subSectionName, config.getFileName(), errorCollector); Coords coords = IconSerializer.loadCoordsFromSection(iconSection); if (!coords.isSetX() || !coords.isSetY()) { - errorLogger.addError("The icon \"" + subSectionName + "\" in the menu \"" + config.getFileName() + " is missing POSITION-X and/or POSITION-Y."); + errorCollector.addError("The icon \"" + subSectionName + "\" in the menu \"" + config.getFileName() + " is missing POSITION-X and/or POSITION-Y."); continue; } if (iconMenu.getIcon(coords.getX(), coords.getY()) != null) { - errorLogger.addError("The icon \"" + subSectionName + "\" in the menu \"" + config.getFileName() + " is overriding another icon with the same position."); + errorCollector.addError("The icon \"" + subSectionName + "\" in the menu \"" + config.getFileName() + " is overriding another icon with the same position."); } iconMenu.setIcon(coords.getX(), coords.getY(), icon); @@ -83,13 +83,13 @@ public class MenuSerializer { /** * Reads all the settings of a menu. It will never return a null title, even if not set. */ - public static MenuData loadMenuData(PluginConfig config, ErrorLogger errorLogger) { + public static MenuData loadMenuData(PluginConfig config, ErrorCollector errorCollector) { String title = FormatUtils.addColors(config.getString(Nodes.MENU_NAME)); int rows; if (title == null) { - errorLogger.addError("The menu \"" + config.getFileName() + "\" doesn't have a name set."); + errorCollector.addError("The menu \"" + config.getFileName() + "\" doesn't have a name set."); title = ChatColor.DARK_RED + "No title set"; } @@ -106,7 +106,7 @@ public class MenuSerializer { } else { rows = 6; // Defaults to 6 rows - errorLogger.addError("The menu \"" + config.getFileName() + "\" doesn't have a the number of rows set, it will have 6 rows by default."); + errorCollector.addError("The menu \"" + config.getFileName() + "\" doesn't have a the number of rows set, it will have 6 rows by default."); } MenuData menuData = new MenuData(title, rows); @@ -142,7 +142,7 @@ public class MenuSerializer { menuData.setBoundDataValue(itemReader.getDataValue()); } } catch (FormatException e) { - errorLogger.addError("The item \"" + openItemMaterial + "\" used to open the menu \"" + config.getFileName() + "\" is invalid: " + e.getMessage()); + errorCollector.addError("The item \"" + openItemMaterial + "\" used to open the menu \"" + config.getFileName() + "\" is invalid: " + e.getMessage()); } boolean leftClick = config.getBoolean(Nodes.OPEN_ITEM_LEFT_CLICK); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/ErrorLoggerTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/ErrorLoggerTask.java deleted file mode 100644 index ecea034..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/ErrorLoggerTask.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.task; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; - -import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.util.ErrorLogger; -import me.filoghost.chestcommands.util.StringUtils; -import java.util.ArrayList; -import java.util.List; - -public class ErrorLoggerTask implements Runnable { - - private ErrorLogger errorLogger; - - public ErrorLoggerTask(ErrorLogger errorLogger) { - this.errorLogger = errorLogger; - } - - @Override - public void run() { - - List lines = new ArrayList<>(); - - lines.add(" "); - lines.add(ChatColor.RED + "#------------------- Chest Commands Errors -------------------#"); - int count = 1; - for (String error : errorLogger.getErrors()) { - lines.add(ChatColor.GRAY + "" + (count++) + ") " + ChatColor.WHITE + error); - } - lines.add(ChatColor.RED + "#-------------------------------------------------------------#"); - - String output = StringUtils.join(lines, "\n"); - - if (ChestCommands.getSettings().use_console_colors) { - Bukkit.getConsoleSender().sendMessage(output); - } else { - System.out.println(ChatColor.stripColor(output)); - } - } - -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorCollector.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorCollector.java new file mode 100644 index 0000000..c3b1bfd --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorCollector.java @@ -0,0 +1,77 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.util; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; + +/** + * This is a class to collect all the errors found while loading the plugin. + */ +public class ErrorCollector { + + private List errors = new ArrayList<>(); + private List warnings = new ArrayList<>(); + + public void addError(String error) { + errors.add(error); + } + + public void addWarning(String warning) { + warnings.add(warning); + } + + public int getErrorsCount() { + return errors.size(); + } + + public int getWarningsCount() { + return warnings.size(); + } + + public boolean hasWarningsOrErrors() { + return errors.size() > 0 || warnings.size() > 0; + } + + public void logToConsole() { + StringBuilder msg = new StringBuilder(200); + msg.append(" \n \n"); + + if (errors.size() > 0) { + msg.append(ChatColor.RED + "[ChestCommands] Encountered " + errors.size() + " error(s) on load:\n"); + appendNumberedList(msg, errors); + } + + if (warnings.size() > 0) { + msg.append(ChatColor.YELLOW + "[ChestCommands] Encountered " + warnings.size() + " warnings(s) on load:\n"); + appendNumberedList(msg, warnings); + } + + Bukkit.getConsoleSender().sendMessage(msg.toString()); + } + + private void appendNumberedList(StringBuilder output, List lines) { + int count = 1; + for (String line : lines) { + output.append(ChatColor.WHITE).append(count).append(") ").append(line); + output.append("\n"); + count++; + } + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorLogger.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorLogger.java deleted file mode 100644 index 9dc5484..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorLogger.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.util; - -import java.util.ArrayList; -import java.util.List; - -/** - * This is a class to collect all the errors found while loading the plugin. - */ -public class ErrorLogger { - - private List errors = new ArrayList<>(); - - public void addError(String error) { - errors.add(error); - } - - public List getErrors() { - return new ArrayList<>(errors); - } - - public boolean hasErrors() { - return errors.size() > 0; - } - - public int getSize() { - return errors.size(); - } - -} From 73c338ea887135d22265177024b5be6ffc8975a7 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 10:08:02 +0200 Subject: [PATCH 008/213] Improve command parsing --- .../chestcommands/ChestCommands.java | 3 -- .../serializer/CommandSerializer.java | 53 +++++++------------ 2 files changed, 20 insertions(+), 36 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 552ce96..db6d1ba 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -46,7 +46,6 @@ import me.filoghost.chestcommands.listener.CommandListener; import me.filoghost.chestcommands.listener.InventoryListener; import me.filoghost.chestcommands.listener.JoinListener; import me.filoghost.chestcommands.listener.SignListener; -import me.filoghost.chestcommands.serializer.CommandSerializer; import me.filoghost.chestcommands.serializer.MenuSerializer; import me.filoghost.chestcommands.task.RefreshMenusTask; import me.filoghost.chestcommands.util.BukkitUtils; @@ -161,8 +160,6 @@ public class ChestCommands extends JavaPlugin { commandsToMenuMap.clear(); boundItems.clear(); - CommandSerializer.checkClassConstructors(errorCollector); - try { settings.load(); } catch (IOException e) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java index 08cf657..e6ae712 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java @@ -22,59 +22,46 @@ import java.util.regex.Pattern; import me.filoghost.chestcommands.internal.icon.IconCommand; import me.filoghost.chestcommands.internal.icon.command.*; -import me.filoghost.chestcommands.util.ErrorCollector; public class CommandSerializer { - private static Map> commandTypesMap = new HashMap<>(); + private static Map commandTypesMap = new HashMap<>(); static { - commandTypesMap.put(commandPattern("console:"), ConsoleIconCommand.class); - commandTypesMap.put(commandPattern("op:"), OpIconCommand.class); - commandTypesMap.put(commandPattern("(open|menu):"), OpenIconCommand.class); - commandTypesMap.put(commandPattern("server:?"), ServerIconCommand.class); // The colon is optional - commandTypesMap.put(commandPattern("tell:"), TellIconCommand.class); - commandTypesMap.put(commandPattern("broadcast:"), BroadcastIconCommand.class); - commandTypesMap.put(commandPattern("give:"), GiveIconCommand.class); - commandTypesMap.put(commandPattern("give-?money:"), GiveMoneyIconCommand.class); - commandTypesMap.put(commandPattern("sound:"), SoundIconCommand.class); - commandTypesMap.put(commandPattern("dragon-?bar:"), DragonBarIconCommand.class); + commandTypesMap.put(commandPattern("console:"), ConsoleIconCommand::new); + commandTypesMap.put(commandPattern("op:"), OpIconCommand::new); + commandTypesMap.put(commandPattern("(open|menu):"), OpenIconCommand::new); + commandTypesMap.put(commandPattern("server:?"), ServerIconCommand::new); // The colon is optional + commandTypesMap.put(commandPattern("tell:"), TellIconCommand::new); + commandTypesMap.put(commandPattern("broadcast:"), BroadcastIconCommand::new); + commandTypesMap.put(commandPattern("give:"), GiveIconCommand::new); + commandTypesMap.put(commandPattern("give-?money:"), GiveMoneyIconCommand::new); + commandTypesMap.put(commandPattern("sound:"), SoundIconCommand::new); + commandTypesMap.put(commandPattern("dragon-?bar:"), DragonBarIconCommand::new); } private static Pattern commandPattern(String regex) { return Pattern.compile("^(?i)" + regex); // Case insensitive and only at the beginning } - public static void checkClassConstructors(ErrorCollector errorCollector) { - for (Class clazz : commandTypesMap.values()) { - try { - clazz.getDeclaredConstructor(String.class).newInstance(""); - } catch (Exception ex) { - String className = clazz.getName().replace("Command", ""); - className = className.substring(className.lastIndexOf('.') + 1, className.length()); - errorCollector.addError("Unable to register the \"" + className + "\" command type(" + ex.getClass().getName() + "), please inform the developer (filoghost). The plugin will still work, but all the \"" + className + "\" commands will be treated as normal commands."); - } - } - } - - public static IconCommand matchCommand(String input) { - - for (Entry> entry : commandTypesMap.entrySet()) { + for (Entry entry : commandTypesMap.entrySet()) { Matcher matcher = entry.getKey().matcher(input); if (matcher.find()) { // Remove the command prefix and trim the spaces String cleanCommand = matcher.replaceFirst("").trim(); - - try { - return entry.getValue().getDeclaredConstructor(String.class).newInstance(cleanCommand); - } catch (Exception e) { - // Checked at startup - } + return entry.getValue().create(cleanCommand); } } return new PlayerIconCommand(input); // Normal command, no match found } + + + public static interface IconCommandFactory { + + IconCommand create(String commandString); + + } } From 1bfa684658edf2143e12b22aa3c20c82ad0d985c Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 10:10:34 +0200 Subject: [PATCH 009/213] Clarify regex --- .../filoghost/chestcommands/serializer/CommandSerializer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java index e6ae712..cce0d22 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java @@ -41,7 +41,7 @@ public class CommandSerializer { } private static Pattern commandPattern(String regex) { - return Pattern.compile("^(?i)" + regex); // Case insensitive and only at the beginning + return Pattern.compile("^" + regex, Pattern.CASE_INSENSITIVE); // Case insensitive and only at the beginning } public static IconCommand matchCommand(String input) { From ae37d54d10e3e2d19b89ed6bad45493cb3f68f13 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 10:28:18 +0200 Subject: [PATCH 010/213] Fully rename "click commands" to "actions" --- .../IconCommand.java => action/Action.java} | 16 ++++----- .../BroadcastAction.java} | 12 +++---- .../ChangeServerAction.java} | 11 +++--- .../ConsoleCommandAction.java} | 12 +++---- .../DragonBarAction.java} | 19 +++++----- .../GiveItemAction.java} | 17 +++++---- .../GiveMoneyAction.java} | 21 ++++++----- .../OpCommandAction.java} | 14 ++++---- .../OpenMenuAction.java} | 13 ++++--- .../PlaySoundAction.java} | 17 +++++---- .../action/PlayerCommandAction.java | 30 ++++++++++++++++ .../SendMessageAction.java} | 12 +++---- .../internal/ExtendedIconMenu.java | 10 +++--- .../chestcommands/internal/MenuData.java | 8 ++--- ...ndler.java => RunActionsClickHandler.java} | 24 ++++++------- .../internal/icon/ExtendedIcon.java | 2 +- .../icon/command/BroadcastIconCommand.java | 34 ------------------ .../listener/InventoryListener.java | 6 ++-- ...dSerializer.java => ActionSerializer.java} | 35 +++++++++---------- .../serializer/IconSerializer.java | 20 +++++------ .../serializer/MenuSerializer.java | 18 +++++----- ...mandsTask.java => ExecuteActionsTask.java} | 4 +-- Plugin/src/main/resources/menu/example.yml | 10 +++--- 23 files changed, 175 insertions(+), 190 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal/icon/IconCommand.java => action/Action.java} (66%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal/icon/command/TellIconCommand.java => action/BroadcastAction.java} (70%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal/icon/command/ServerIconCommand.java => action/ChangeServerAction.java} (69%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal/icon/command/ConsoleIconCommand.java => action/ConsoleCommandAction.java} (69%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal/icon/command/DragonBarIconCommand.java => action/DragonBarAction.java} (73%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal/icon/command/GiveIconCommand.java => action/GiveItemAction.java} (74%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal/icon/command/GiveMoneyIconCommand.java => action/GiveMoneyAction.java} (70%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal/icon/command/OpIconCommand.java => action/OpCommandAction.java} (69%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal/icon/command/OpenIconCommand.java => action/OpenMenuAction.java} (77%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal/icon/command/SoundIconCommand.java => action/PlaySoundAction.java} (78%) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java rename Plugin/src/main/java/me/filoghost/chestcommands/{internal/icon/command/PlayerIconCommand.java => action/SendMessageAction.java} (70%) rename Plugin/src/main/java/me/filoghost/chestcommands/internal/{CommandsClickHandler.java => RunActionsClickHandler.java} (63%) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/BroadcastIconCommand.java rename Plugin/src/main/java/me/filoghost/chestcommands/serializer/{CommandSerializer.java => ActionSerializer.java} (52%) rename Plugin/src/main/java/me/filoghost/chestcommands/task/{ExecuteCommandsTask.java => ExecuteActionsTask.java} (86%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/IconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java similarity index 66% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/IconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java index 974f559..9838529 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/IconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java @@ -12,25 +12,25 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal.icon; +package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; import me.filoghost.chestcommands.config.AsciiPlaceholders; import me.filoghost.chestcommands.internal.VariableManager; -public abstract class IconCommand { +public abstract class Action { - protected String command; + protected String action; protected boolean hasVariables; - public IconCommand(String command) { - this.command = AsciiPlaceholders.placeholdersToSymbols(command).trim(); - this.hasVariables = VariableManager.hasVariables(command); + public Action(String action) { + this.action = AsciiPlaceholders.placeholdersToSymbols(action).trim(); + this.hasVariables = VariableManager.hasVariables(action); } - public String getParsedCommand(Player executor) { - return hasVariables ? VariableManager.setVariables(command, executor) : command; + public String getParsedAction(Player executor) { + return hasVariables ? VariableManager.setVariables(action, executor) : action; } public abstract void execute(Player player); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/TellIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java similarity index 70% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/TellIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java index ed70fc0..226ba13 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/TellIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java @@ -12,22 +12,22 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.action; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.internal.icon.IconCommand; import me.filoghost.chestcommands.util.FormatUtils; -public class TellIconCommand extends IconCommand { +public class BroadcastAction extends Action { - public TellIconCommand(String command) { - super(FormatUtils.addColors(command)); + public BroadcastAction(String action) { + super(FormatUtils.addColors(action)); } @Override public void execute(Player player) { - player.sendMessage(getParsedCommand(player)); + Bukkit.broadcastMessage(getParsedAction(player)); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/ServerIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java similarity index 69% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/ServerIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java index b4d18db..ede31c2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/ServerIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java @@ -12,22 +12,21 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; import me.filoghost.chestcommands.bridge.bungee.BungeeCordUtils; -import me.filoghost.chestcommands.internal.icon.IconCommand; -public class ServerIconCommand extends IconCommand { +public class ChangeServerAction extends Action { - public ServerIconCommand(String command) { - super(command); + public ChangeServerAction(String action) { + super(action); } @Override public void execute(Player player) { - BungeeCordUtils.connect(player, hasVariables ? getParsedCommand(player) : command); + BungeeCordUtils.connect(player, hasVariables ? getParsedAction(player) : action); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/ConsoleIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java similarity index 69% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/ConsoleIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java index b175c2f..f3832f3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/ConsoleIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java @@ -12,22 +12,20 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.action; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.internal.icon.IconCommand; +public class ConsoleCommandAction extends Action { -public class ConsoleIconCommand extends IconCommand { - - public ConsoleIconCommand(String command) { - super(command); + public ConsoleCommandAction(String action) { + super(action); } @Override public void execute(Player player) { - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), getParsedCommand(player)); + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), getParsedAction(player)); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/DragonBarIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java similarity index 73% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/DragonBarIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java index 2f90627..8efd0da 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/DragonBarIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java @@ -12,32 +12,31 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; import me.filoghost.chestcommands.bridge.BarAPIBridge; -import me.filoghost.chestcommands.internal.icon.IconCommand; import me.filoghost.chestcommands.util.FormatUtils; import me.filoghost.chestcommands.util.Utils; -public class DragonBarIconCommand extends IconCommand { +public class DragonBarAction extends Action { private String message; private int seconds; - public DragonBarIconCommand(String command) { - super(command); + public DragonBarAction(String action) { + super(action); if (!hasVariables) { - parseBar(super.command); + parseBar(super.action); } } - private void parseBar(String command) { + private void parseBar(String action) { seconds = 1; - message = command; + message = action; - String[] split = command.split("\\|", 2); // Max of 2 pieces + String[] split = action.split("\\|", 2); // Max of 2 pieces if (split.length > 1 && Utils.isValidPositiveInteger(split[0].trim())) { seconds = Integer.parseInt(split[0].trim()); message = split[1].trim(); @@ -49,7 +48,7 @@ public class DragonBarIconCommand extends IconCommand { @Override public void execute(Player player) { if (hasVariables) { - parseBar(getParsedCommand(player)); + parseBar(getParsedAction(player)); } if (BarAPIBridge.hasValidPlugin()) { BarAPIBridge.setMessage(player, message, seconds); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/GiveIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java similarity index 74% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/GiveIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java index 17806f5..03088f9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/GiveIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java @@ -12,31 +12,30 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.action; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import me.filoghost.chestcommands.exception.FormatException; -import me.filoghost.chestcommands.internal.icon.IconCommand; import me.filoghost.chestcommands.util.ItemStackReader; -public class GiveIconCommand extends IconCommand { +public class GiveItemAction extends Action { private ItemStack itemToGive; private String errorMessage; - public GiveIconCommand(String command) { - super(command); + public GiveItemAction(String action) { + super(action); if (!hasVariables) { - parseItem(super.command); + parseItem(super.action); } } - private void parseItem(String command) { + private void parseItem(String action) { try { - ItemStackReader reader = new ItemStackReader(command, true); + ItemStackReader reader = new ItemStackReader(action, true); itemToGive = reader.createStack(); errorMessage = null; } catch (FormatException e) { @@ -47,7 +46,7 @@ public class GiveIconCommand extends IconCommand { @Override public void execute(Player player) { if (hasVariables) { - parseItem(getParsedCommand(player)); + parseItem(getParsedAction(player)); } if (errorMessage != null) { player.sendMessage(errorMessage); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/GiveMoneyIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java similarity index 70% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/GiveMoneyIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java index 6ec0a02..b46d8bf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/GiveMoneyIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java @@ -12,40 +12,39 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.action; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import me.filoghost.chestcommands.bridge.EconomyBridge; -import me.filoghost.chestcommands.internal.icon.IconCommand; import me.filoghost.chestcommands.util.Utils; -public class GiveMoneyIconCommand extends IconCommand { +public class GiveMoneyAction extends Action { private double moneyToGive; private String errorMessage; - public GiveMoneyIconCommand(String command) { - super(command); + public GiveMoneyAction(String action) { + super(action); if (!hasVariables) { - parseMoney(super.command); + parseMoney(super.action); } } - private void parseMoney(String command) { - if (!Utils.isValidPositiveDouble(command)) { - errorMessage = ChatColor.RED + "Invalid money amount: " + command; + private void parseMoney(String action) { + if (!Utils.isValidPositiveDouble(action)) { + errorMessage = ChatColor.RED + "Invalid money amount: " + action; return; } errorMessage = null; - moneyToGive = Double.parseDouble(command); + moneyToGive = Double.parseDouble(action); } @Override public void execute(Player player) { if (hasVariables) { - parseMoney(getParsedCommand(player)); + parseMoney(getParsedAction(player)); } if (errorMessage != null) { player.sendMessage(errorMessage); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java similarity index 69% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java index 17db2b2..51c26cd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java @@ -12,27 +12,25 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.internal.icon.IconCommand; +public class OpCommandAction extends Action { -public class OpIconCommand extends IconCommand { - - public OpIconCommand(String command) { - super(command); + public OpCommandAction(String action) { + super(action); } @Override public void execute(Player player) { if (player.isOp()) { - player.chat("/" + getParsedCommand(player)); + player.chat("/" + getParsedAction(player)); } else { player.setOp(true); - player.chat("/" + getParsedCommand(player)); + player.chat("/" + getParsedAction(player)); player.setOp(false); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java similarity index 77% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java index fd9c31f..b8d7a78 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.action; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -20,22 +20,21 @@ import org.bukkit.entity.Player; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.internal.ExtendedIconMenu; -import me.filoghost.chestcommands.internal.icon.IconCommand; -public class OpenIconCommand extends IconCommand { +public class OpenMenuAction extends Action { - public OpenIconCommand(String command) { - super(command); + public OpenMenuAction(String action) { + super(action); } @Override public void execute(final Player player) { - String target = hasVariables ? getParsedCommand(player) : command; + String target = hasVariables ? getParsedAction(player) : action; final ExtendedIconMenu menu = ChestCommands.getFileNameToMenuMap().get(target.toLowerCase()); if (menu != null) { /* - * Delay the task, since this command is executed in ClickInventoryEvent + * Delay the task, since this action is executed in ClickInventoryEvent * and opening another inventory in the same moment is not a good idea. */ Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), () -> { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/SoundIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java similarity index 78% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/SoundIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java index 01a3e8a..e69cfeb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/SoundIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java @@ -12,35 +12,34 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.action; import org.bukkit.ChatColor; import org.bukkit.Sound; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.internal.icon.IconCommand; import me.filoghost.chestcommands.util.BukkitUtils; -public class SoundIconCommand extends IconCommand { +public class PlaySoundAction extends Action { private Sound sound; private float pitch; private float volume; private String errorMessage; - public SoundIconCommand(String command) { - super(command); + public PlaySoundAction(String action) { + super(action); if (!hasVariables) { - parseSound(super.command); + parseSound(super.action); } } - private void parseSound(String command) { + private void parseSound(String action) { errorMessage = null; pitch = 1.0f; volume = 1.0f; - String[] split = command.split(","); + String[] split = action.split(","); sound = BukkitUtils.matchSound(split[0]); if (sound == null) { @@ -66,7 +65,7 @@ public class SoundIconCommand extends IconCommand { @Override public void execute(Player player) { if (hasVariables) { - parseSound(getParsedCommand(player)); + parseSound(getParsedAction(player)); } if (errorMessage != null) { player.sendMessage(errorMessage); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java new file mode 100644 index 0000000..ccc541b --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java @@ -0,0 +1,30 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.action; + +import org.bukkit.entity.Player; + +public class PlayerCommandAction extends Action { + + public PlayerCommandAction(String action) { + super(action); + } + + @Override + public void execute(Player player) { + player.chat('/' + getParsedAction(player)); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/PlayerIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java similarity index 70% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/PlayerIconCommand.java rename to Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java index 81e12d7..715cb0a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/PlayerIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java @@ -12,21 +12,21 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal.icon.command; +package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.internal.icon.IconCommand; +import me.filoghost.chestcommands.util.FormatUtils; -public class PlayerIconCommand extends IconCommand { +public class SendMessageAction extends Action { - public PlayerIconCommand(String command) { - super(command); + public SendMessageAction(String action) { + super(FormatUtils.addColors(action)); } @Override public void execute(Player player) { - player.chat('/' + getParsedCommand(player)); + player.sendMessage(getParsedAction(player)); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java index f7c1426..920f78c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java @@ -24,9 +24,9 @@ import org.bukkit.inventory.meta.ItemMeta; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; +import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.api.IconMenu; import me.filoghost.chestcommands.internal.icon.ExtendedIcon; -import me.filoghost.chestcommands.internal.icon.IconCommand; import me.filoghost.chestcommands.util.ItemUtils; import java.util.List; @@ -35,7 +35,7 @@ public class ExtendedIconMenu extends IconMenu { private String fileName; private String permission; - private List openActions; + private List openActions; private int refreshTicks; @@ -45,11 +45,11 @@ public class ExtendedIconMenu extends IconMenu { this.permission = Permissions.OPEN_MENU_BASE + fileName; } - public List getOpenActions() { + public List getOpenActions() { return openActions; } - public void setOpenActions(List openAction) { + public void setOpenActions(List openAction) { this.openActions = openAction; } @@ -73,7 +73,7 @@ public class ExtendedIconMenu extends IconMenu { public void open(Player player) { try { if (openActions != null) { - for (IconCommand openAction : openActions) { + for (Action openAction : openActions) { openAction.execute(player); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuData.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuData.java index bca2037..fce0303 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuData.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuData.java @@ -16,7 +16,7 @@ package me.filoghost.chestcommands.internal; import org.bukkit.Material; -import me.filoghost.chestcommands.internal.icon.IconCommand; +import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.util.ClickType; import java.util.List; @@ -32,7 +32,7 @@ public class MenuData { private Material boundMaterial; private short boundDataValue; private ClickType clickType; - private List openActions; + private List openActions; private int refreshTenths; public MenuData(String title, int rows) { @@ -93,11 +93,11 @@ public class MenuData { this.clickType = clickType; } - public List getOpenActions() { + public List getOpenActions() { return openActions; } - public void setOpenActions(List openAction) { + public void setOpenActions(List openAction) { this.openActions = openAction; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/CommandsClickHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/RunActionsClickHandler.java similarity index 63% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/CommandsClickHandler.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/RunActionsClickHandler.java index 8de5282..387826b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/CommandsClickHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/RunActionsClickHandler.java @@ -16,24 +16,24 @@ package me.filoghost.chestcommands.internal; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.action.Action; +import me.filoghost.chestcommands.action.OpenMenuAction; import me.filoghost.chestcommands.api.ClickHandler; -import me.filoghost.chestcommands.internal.icon.IconCommand; -import me.filoghost.chestcommands.internal.icon.command.OpenIconCommand; import java.util.List; -public class CommandsClickHandler implements ClickHandler { +public class RunActionsClickHandler implements ClickHandler { - private List commands; + private List actions; private boolean closeOnClick; - public CommandsClickHandler(List commands, boolean closeOnClick) { - this.commands = commands; + public RunActionsClickHandler(List actions, boolean closeOnClick) { + this.actions = actions; this.closeOnClick = closeOnClick; - if (commands != null && commands.size() > 0) { - for (IconCommand command : commands) { - if (command instanceof OpenIconCommand) { + if (actions != null && actions.size() > 0) { + for (Action action : actions) { + if (action instanceof OpenMenuAction) { // Fix GUI closing if KEEP-OPEN is not set, and a command should open another GUI this.closeOnClick = false; } @@ -43,9 +43,9 @@ public class CommandsClickHandler implements ClickHandler { @Override public boolean onClick(Player player) { - if (commands != null && commands.size() > 0) { - for (IconCommand command : commands) { - command.execute(player); + if (actions != null && actions.size() > 0) { + for (Action action : actions) { + action.execute(player); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/ExtendedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/ExtendedIcon.java index 4cf558e..890066d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/ExtendedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/ExtendedIcon.java @@ -159,7 +159,7 @@ public class ExtendedIcon extends Icon { if (moneyPrice > 0) { if (!EconomyBridge.hasValidEconomy()) { - player.sendMessage(ChatColor.RED + "This command has a price, but Vault with a compatible economy plugin was not found. For security, the command has been blocked. Please inform the staff."); + player.sendMessage(ChatColor.RED + "This action has a price, but Vault with a compatible economy plugin was not found. For security, the action has been blocked. Please inform the staff."); return closeOnClick; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/BroadcastIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/BroadcastIconCommand.java deleted file mode 100644 index fba1135..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/BroadcastIconCommand.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.internal.icon.command; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import me.filoghost.chestcommands.internal.icon.IconCommand; -import me.filoghost.chestcommands.util.FormatUtils; - -public class BroadcastIconCommand extends IconCommand { - - public BroadcastIconCommand(String command) { - super(FormatUtils.addColors(command)); - } - - @Override - public void execute(Player player) { - Bukkit.broadcastMessage(getParsedCommand(player)); - } - -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index 4ec8883..7571863 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -29,7 +29,7 @@ import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.api.IconMenu; import me.filoghost.chestcommands.internal.BoundItem; import me.filoghost.chestcommands.internal.MenuInventoryHolder; -import me.filoghost.chestcommands.task.ExecuteCommandsTask; +import me.filoghost.chestcommands.task.ExecuteActionsTask; import java.util.HashMap; import java.util.Map; @@ -80,8 +80,8 @@ public class InventoryListener implements Listener { } } - // Closes the inventory and executes commands AFTER the event - Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), new ExecuteCommandsTask(clicker, icon)); + // Closes the inventory and executes actions AFTER the event + Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), new ExecuteActionsTask(clicker, icon)); } } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/ActionSerializer.java similarity index 52% rename from Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java rename to Plugin/src/main/java/me/filoghost/chestcommands/serializer/ActionSerializer.java index cce0d22..fd4dd25 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/ActionSerializer.java @@ -20,47 +20,46 @@ import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; -import me.filoghost.chestcommands.internal.icon.IconCommand; -import me.filoghost.chestcommands.internal.icon.command.*; +import me.filoghost.chestcommands.action.*; -public class CommandSerializer { +public class ActionSerializer { private static Map commandTypesMap = new HashMap<>(); static { - commandTypesMap.put(commandPattern("console:"), ConsoleIconCommand::new); - commandTypesMap.put(commandPattern("op:"), OpIconCommand::new); - commandTypesMap.put(commandPattern("(open|menu):"), OpenIconCommand::new); - commandTypesMap.put(commandPattern("server:?"), ServerIconCommand::new); // The colon is optional - commandTypesMap.put(commandPattern("tell:"), TellIconCommand::new); - commandTypesMap.put(commandPattern("broadcast:"), BroadcastIconCommand::new); - commandTypesMap.put(commandPattern("give:"), GiveIconCommand::new); - commandTypesMap.put(commandPattern("give-?money:"), GiveMoneyIconCommand::new); - commandTypesMap.put(commandPattern("sound:"), SoundIconCommand::new); - commandTypesMap.put(commandPattern("dragon-?bar:"), DragonBarIconCommand::new); + commandTypesMap.put(actionPattern("console:"), ConsoleCommandAction::new); + commandTypesMap.put(actionPattern("op:"), OpCommandAction::new); + commandTypesMap.put(actionPattern("(open|menu):"), OpenMenuAction::new); + commandTypesMap.put(actionPattern("server:?"), ChangeServerAction::new); // The colon is optional + commandTypesMap.put(actionPattern("tell:"), SendMessageAction::new); + commandTypesMap.put(actionPattern("broadcast:"), BroadcastAction::new); + commandTypesMap.put(actionPattern("give:"), GiveItemAction::new); + commandTypesMap.put(actionPattern("give-?money:"), GiveMoneyAction::new); + commandTypesMap.put(actionPattern("sound:"), PlaySoundAction::new); + commandTypesMap.put(actionPattern("dragon-?bar:"), DragonBarAction::new); } - private static Pattern commandPattern(String regex) { + private static Pattern actionPattern(String regex) { return Pattern.compile("^" + regex, Pattern.CASE_INSENSITIVE); // Case insensitive and only at the beginning } - public static IconCommand matchCommand(String input) { + public static Action matchAction(String input) { for (Entry entry : commandTypesMap.entrySet()) { Matcher matcher = entry.getKey().matcher(input); if (matcher.find()) { - // Remove the command prefix and trim the spaces + // Remove the action prefix and trim the spaces String cleanCommand = matcher.replaceFirst("").trim(); return entry.getValue().create(cleanCommand); } } - return new PlayerIconCommand(input); // Normal command, no match found + return new PlayerCommandAction(input); // Default action, no match found } public static interface IconCommandFactory { - IconCommand create(String commandString); + Action create(String actionString); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java index 879bb2d..3e3ae84 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java @@ -23,14 +23,14 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.enchantments.Enchantment; import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.config.AsciiPlaceholders; import me.filoghost.chestcommands.config.ConfigUtil; import me.filoghost.chestcommands.exception.FormatException; -import me.filoghost.chestcommands.internal.CommandsClickHandler; +import me.filoghost.chestcommands.internal.RunActionsClickHandler; import me.filoghost.chestcommands.internal.RequiredItem; import me.filoghost.chestcommands.internal.icon.ExtendedIcon; -import me.filoghost.chestcommands.internal.icon.IconCommand; import me.filoghost.chestcommands.serializer.EnchantmentSerializer.EnchantmentDetails; import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.FormatUtils; @@ -188,19 +188,19 @@ public class IconSerializer { boolean closeOnClick = !section.getBoolean(Nodes.KEEP_OPEN); icon.setCloseOnClick(closeOnClick); - List serializedCommands = ConfigUtil.getStringListOrInlineList(section, ChestCommands.getSettings().multiple_commands_separator, Nodes.ACTIONS); + List serializedActions = ConfigUtil.getStringListOrInlineList(section, ChestCommands.getSettings().multiple_commands_separator, Nodes.ACTIONS); - if (serializedCommands != null && !serializedCommands.isEmpty()) { - List commands = new ArrayList<>(); + if (serializedActions != null && !serializedActions.isEmpty()) { + List actions = new ArrayList<>(); - for (String serializedCommand : serializedCommands) { - if (serializedCommand != null && !serializedCommand.isEmpty()) { - commands.add(CommandSerializer.matchCommand(serializedCommand)); + for (String serializedAction : serializedActions) { + if (serializedAction != null && !serializedAction.isEmpty()) { + actions.add(ActionSerializer.matchAction(serializedAction)); } } - if (!commands.isEmpty()) { - icon.setClickHandler(new CommandsClickHandler(commands, closeOnClick)); + if (!actions.isEmpty()) { + icon.setClickHandler(new RunActionsClickHandler(actions, closeOnClick)); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java index 47e0b84..7cbf436 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java @@ -21,13 +21,13 @@ import org.bukkit.ChatColor; import org.bukkit.configuration.ConfigurationSection; import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.config.ConfigUtil; import me.filoghost.chestcommands.config.yaml.PluginConfig; import me.filoghost.chestcommands.exception.FormatException; import me.filoghost.chestcommands.internal.ExtendedIconMenu; import me.filoghost.chestcommands.internal.MenuData; -import me.filoghost.chestcommands.internal.icon.IconCommand; import me.filoghost.chestcommands.serializer.IconSerializer.Coords; import me.filoghost.chestcommands.util.ClickType; import me.filoghost.chestcommands.util.ErrorCollector; @@ -116,19 +116,19 @@ public class MenuSerializer { menuData.setCommands(triggeringCommands.toArray(new String[0])); } - List serializedOpenCommands = ConfigUtil.getStringListOrInlineList(config, ChestCommands.getSettings().multiple_commands_separator, Nodes.OPEN_ACTIONS); + List serializedOpenActions = ConfigUtil.getStringListOrInlineList(config, ChestCommands.getSettings().multiple_commands_separator, Nodes.OPEN_ACTIONS); - if (serializedOpenCommands != null && !serializedOpenCommands.isEmpty()) { - List openCommands = new ArrayList<>(); + if (serializedOpenActions != null && !serializedOpenActions.isEmpty()) { + List openActions = new ArrayList<>(); - for (String serializedCommand : serializedOpenCommands) { - if (serializedCommand != null && !serializedCommand.isEmpty()) { - openCommands.add(CommandSerializer.matchCommand(serializedCommand)); + for (String serializedAction : serializedOpenActions) { + if (serializedAction != null && !serializedAction.isEmpty()) { + openActions.add(ActionSerializer.matchAction(serializedAction)); } } - if (!openCommands.isEmpty()) { - menuData.setOpenActions(openCommands); + if (!openActions.isEmpty()) { + menuData.setOpenActions(openActions); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/ExecuteCommandsTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/ExecuteActionsTask.java similarity index 86% rename from Plugin/src/main/java/me/filoghost/chestcommands/task/ExecuteCommandsTask.java rename to Plugin/src/main/java/me/filoghost/chestcommands/task/ExecuteActionsTask.java index 7766a66..ac6e403 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/ExecuteCommandsTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/ExecuteActionsTask.java @@ -18,13 +18,13 @@ import org.bukkit.entity.Player; import me.filoghost.chestcommands.api.Icon; -public class ExecuteCommandsTask implements Runnable { +public class ExecuteActionsTask implements Runnable { private Player player; private Icon icon; - public ExecuteCommandsTask(Player player, Icon icon) { + public ExecuteActionsTask(Player player, Icon icon) { this.player = player; this.icon = icon; } diff --git a/Plugin/src/main/resources/menu/example.yml b/Plugin/src/main/resources/menu/example.yml index e33680e..a6b6470 100644 --- a/Plugin/src/main/resources/menu/example.yml +++ b/Plugin/src/main/resources/menu/example.yml @@ -25,8 +25,8 @@ menu-settings: auto-refresh: 5 # OPTIONAL - # This command command will be executed when the menu is opened. - # Supports all the icon command types. + # These actions will be executed when the menu is opened. + # Supports all the icon action types. open-actions: - 'tell: &eYou opened the example menu.' @@ -129,9 +129,9 @@ economy-give: MATERIAL: gold ingot POSITION-X: 8 POSITION-Y: 1 - NAME: '&eEconomy & Give command' + NAME: '&eEconomy & Give action' LORE: - - 'This command will be executed' + - 'This action will be executed' - 'only if you have at least 50$.' - 'It gives you a gold ingot.' PRICE: 50 @@ -146,7 +146,7 @@ economy-take: POSITION-Y: 1 NAME: '&eEconomy & Required item' LORE: - - 'This command is the opposite of the previous.' + - 'This icon is the opposite of the previous.' - 'It will take you a gold ingot and give you $50.' REQUIRED-ITEMS: - gold ingot From 418b1a60c36309551d42c563aaff670b54dbd204 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 10:32:01 +0200 Subject: [PATCH 011/213] Remove bad option "use-only-commands-without-args" --- .../java/me/filoghost/chestcommands/config/Settings.java | 1 - .../me/filoghost/chestcommands/listener/CommandListener.java | 5 ----- 2 files changed, 6 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java index 6cf629a..4f9be98 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java @@ -25,7 +25,6 @@ public class Settings extends SpecialConfig { public String multiple_commands_separator = ";"; public boolean update_notifications = true; public int anti_click_spam_delay = 200; - public boolean use_only_commands_without_args = true; public Settings(PluginConfig config) { super(config); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java index 425c977..9e8dd37 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java @@ -27,11 +27,6 @@ public class CommandListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onCommand(PlayerCommandPreprocessEvent event) { - - if (ChestCommands.getSettings().use_only_commands_without_args && event.getMessage().contains(" ")) { - return; - } - // Very fast method compared to split & substring String command = StringUtils.getCleanCommand(event.getMessage()); From e4e3d74969744fb9de58eae972f371cb9c10b5ae Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 10:36:07 +0200 Subject: [PATCH 012/213] Rename "serializers" to "parsers" --- .../me/filoghost/chestcommands/ChestCommands.java | 6 +++--- .../chestcommands/action/GiveItemAction.java | 4 ++-- .../ActionParser.java} | 6 +++--- .../EnchantmentParser.java} | 4 ++-- .../IconParser.java} | 15 +++++++-------- .../ItemStackParser.java} | 10 +++++++--- .../MenuParser.java} | 15 +++++++-------- 7 files changed, 31 insertions(+), 29 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/{serializer/ActionSerializer.java => parser/ActionParser.java} (92%) rename Plugin/src/main/java/me/filoghost/chestcommands/{serializer/EnchantmentSerializer.java => parser/EnchantmentParser.java} (95%) rename Plugin/src/main/java/me/filoghost/chestcommands/{serializer/IconSerializer.java => parser/IconParser.java} (91%) rename Plugin/src/main/java/me/filoghost/chestcommands/{util/ItemStackReader.java => parser/ItemStackParser.java} (86%) rename Plugin/src/main/java/me/filoghost/chestcommands/{serializer/MenuSerializer.java => parser/MenuParser.java} (89%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index db6d1ba..ff57943 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -46,7 +46,7 @@ import me.filoghost.chestcommands.listener.CommandListener; import me.filoghost.chestcommands.listener.InventoryListener; import me.filoghost.chestcommands.listener.JoinListener; import me.filoghost.chestcommands.listener.SignListener; -import me.filoghost.chestcommands.serializer.MenuSerializer; +import me.filoghost.chestcommands.parser.MenuParser; import me.filoghost.chestcommands.task.RefreshMenusTask; import me.filoghost.chestcommands.util.BukkitUtils; import me.filoghost.chestcommands.util.CaseInsensitiveMap; @@ -219,8 +219,8 @@ public class ChestCommands extends JavaPlugin { continue; } - MenuData data = MenuSerializer.loadMenuData(menuConfig, errorCollector); - ExtendedIconMenu iconMenu = MenuSerializer.loadMenu(menuConfig, data.getTitle(), data.getRows(), errorCollector); + MenuData data = MenuParser.loadMenuData(menuConfig, errorCollector); + ExtendedIconMenu iconMenu = MenuParser.loadMenu(menuConfig, data.getTitle(), data.getRows(), errorCollector); if (fileNameToMenuMap.containsKey(menuConfig.getFileName())) { errorCollector.addError("Two menus have the same file name \"" + menuConfig.getFileName() + "\" with different cases. There will be problems opening one of these two menus."); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java index 03088f9..636cd23 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java @@ -19,7 +19,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import me.filoghost.chestcommands.exception.FormatException; -import me.filoghost.chestcommands.util.ItemStackReader; +import me.filoghost.chestcommands.parser.ItemStackParser; public class GiveItemAction extends Action { @@ -35,7 +35,7 @@ public class GiveItemAction extends Action { private void parseItem(String action) { try { - ItemStackReader reader = new ItemStackReader(action, true); + ItemStackParser reader = new ItemStackParser(action, true); itemToGive = reader.createStack(); errorMessage = null; } catch (FormatException e) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/ActionSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ActionParser.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/serializer/ActionSerializer.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parser/ActionParser.java index fd4dd25..e6508f0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/ActionSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ActionParser.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.serializer; +package me.filoghost.chestcommands.parser; import java.util.HashMap; import java.util.Map; @@ -22,7 +22,7 @@ import java.util.regex.Pattern; import me.filoghost.chestcommands.action.*; -public class ActionSerializer { +public class ActionParser { private static Map commandTypesMap = new HashMap<>(); @@ -43,7 +43,7 @@ public class ActionSerializer { return Pattern.compile("^" + regex, Pattern.CASE_INSENSITIVE); // Case insensitive and only at the beginning } - public static Action matchAction(String input) { + public static Action parseAction(String input) { for (Entry entry : commandTypesMap.entrySet()) { Matcher matcher = entry.getKey().matcher(input); if (matcher.find()) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/EnchantmentParser.java similarity index 95% rename from Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parser/EnchantmentParser.java index 11cab71..6185708 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/EnchantmentParser.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.serializer; +package me.filoghost.chestcommands.parser; import java.util.HashMap; import java.util.Map; @@ -22,7 +22,7 @@ import org.bukkit.enchantments.Enchantment; import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.StringUtils; -public class EnchantmentSerializer { +public class EnchantmentParser { private static Map enchantmentsMap = new HashMap<>(); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java similarity index 91% rename from Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index 3e3ae84..2749de6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.serializer; +package me.filoghost.chestcommands.parser; import java.util.ArrayList; import java.util.HashMap; @@ -31,16 +31,15 @@ import me.filoghost.chestcommands.exception.FormatException; import me.filoghost.chestcommands.internal.RunActionsClickHandler; import me.filoghost.chestcommands.internal.RequiredItem; import me.filoghost.chestcommands.internal.icon.ExtendedIcon; -import me.filoghost.chestcommands.serializer.EnchantmentSerializer.EnchantmentDetails; +import me.filoghost.chestcommands.parser.EnchantmentParser.EnchantmentDetails; import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.FormatUtils; -import me.filoghost.chestcommands.util.ItemStackReader; import me.filoghost.chestcommands.util.ItemUtils; import me.filoghost.chestcommands.util.Validate; import me.filoghost.chestcommands.util.nbt.parser.MojangsonParseException; import me.filoghost.chestcommands.util.nbt.parser.MojangsonParser; -public class IconSerializer { +public class IconParser { private static class Nodes { @@ -103,7 +102,7 @@ public class IconSerializer { String material = ConfigUtil.getAnyString(section, Nodes.MATERIAL); if (material != null) { try { - ItemStackReader itemReader = new ItemStackReader(material, true); + ItemStackParser itemReader = new ItemStackParser(material, true); icon.setMaterial(itemReader.getMaterial()); icon.setDataValue(itemReader.getDataValue()); icon.setAmount(itemReader.getAmount()); @@ -142,7 +141,7 @@ public class IconSerializer { for (String serializedEnchantment : serializedEnchantments) { if (serializedEnchantment != null && !serializedEnchantment.isEmpty()) { - EnchantmentDetails enchantment = EnchantmentSerializer.parseEnchantment(serializedEnchantment, iconName, menuFileName, errorCollector); + EnchantmentDetails enchantment = EnchantmentParser.parseEnchantment(serializedEnchantment, iconName, menuFileName, errorCollector); if (enchantment != null) { enchantments.put(enchantment.getEnchantment(), enchantment.getLevel()); } @@ -195,7 +194,7 @@ public class IconSerializer { for (String serializedAction : serializedActions) { if (serializedAction != null && !serializedAction.isEmpty()) { - actions.add(ActionSerializer.matchAction(serializedAction)); + actions.add(ActionParser.parseAction(serializedAction)); } } @@ -225,7 +224,7 @@ public class IconSerializer { for (String serializedItem : serializedRequiredItems) { try { - ItemStackReader itemReader = new ItemStackReader(serializedItem, true); + ItemStackParser itemReader = new ItemStackParser(serializedItem, true); RequiredItem requiredItem = new RequiredItem(itemReader.getMaterial(), itemReader.getAmount()); if (itemReader.hasExplicitDataValue()) { requiredItem.setRestrictiveDataValue(itemReader.getDataValue()); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/ItemStackReader.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java similarity index 86% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/ItemStackReader.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java index 03d855e..3552ec1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/ItemStackReader.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java @@ -12,14 +12,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.util; +package me.filoghost.chestcommands.parser; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import me.filoghost.chestcommands.exception.FormatException; +import me.filoghost.chestcommands.util.MaterialsRegistry; +import me.filoghost.chestcommands.util.StringUtils; +import me.filoghost.chestcommands.util.Utils; +import me.filoghost.chestcommands.util.Validate; -public class ItemStackReader { +public class ItemStackParser { private Material material = Material.STONE; // In the worst case (bad exception handling) we just get stone private int amount = 1; @@ -31,7 +35,7 @@ public class ItemStackReader { * id can be either the id of the material or its name. * for example wool:5, 3 is a valid input. */ - public ItemStackReader(String input, boolean parseAmount) throws FormatException { + public ItemStackParser(String input, boolean parseAmount) throws FormatException { Validate.notNull(input, "input cannot be null"); // Remove spaces, they're not needed diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java similarity index 89% rename from Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java index 7cbf436..049fd44 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.serializer; +package me.filoghost.chestcommands.parser; import java.util.ArrayList; import java.util.List; @@ -28,13 +28,12 @@ import me.filoghost.chestcommands.config.yaml.PluginConfig; import me.filoghost.chestcommands.exception.FormatException; import me.filoghost.chestcommands.internal.ExtendedIconMenu; import me.filoghost.chestcommands.internal.MenuData; -import me.filoghost.chestcommands.serializer.IconSerializer.Coords; +import me.filoghost.chestcommands.parser.IconParser.Coords; import me.filoghost.chestcommands.util.ClickType; import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.FormatUtils; -import me.filoghost.chestcommands.util.ItemStackReader; -public class MenuSerializer { +public class MenuParser { private static class Nodes { @@ -62,8 +61,8 @@ public class MenuSerializer { ConfigurationSection iconSection = config.getConfigurationSection(subSectionName); - Icon icon = IconSerializer.loadIconFromSection(iconSection, subSectionName, config.getFileName(), errorCollector); - Coords coords = IconSerializer.loadCoordsFromSection(iconSection); + Icon icon = IconParser.loadIconFromSection(iconSection, subSectionName, config.getFileName(), errorCollector); + Coords coords = IconParser.loadCoordsFromSection(iconSection); if (!coords.isSetX() || !coords.isSetY()) { errorCollector.addError("The icon \"" + subSectionName + "\" in the menu \"" + config.getFileName() + " is missing POSITION-X and/or POSITION-Y."); @@ -123,7 +122,7 @@ public class MenuSerializer { for (String serializedAction : serializedOpenActions) { if (serializedAction != null && !serializedAction.isEmpty()) { - openActions.add(ActionSerializer.matchAction(serializedAction)); + openActions.add(ActionParser.parseAction(serializedAction)); } } @@ -135,7 +134,7 @@ public class MenuSerializer { String openItemMaterial = ConfigUtil.getAnyString(config, Nodes.OPEN_ITEM_MATERIAL); if (openItemMaterial != null) { try { - ItemStackReader itemReader = new ItemStackReader(openItemMaterial, false); + ItemStackParser itemReader = new ItemStackParser(openItemMaterial, false); menuData.setBoundMaterial(itemReader.getMaterial()); if (itemReader.hasExplicitDataValue()) { From f06ebd46ed896604efaea4caad4427f6558be61a Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 10:45:01 +0200 Subject: [PATCH 013/213] Remove unused methods and reduce method visibility where possible --- .../chestcommands/bridge/EconomyBridge.java | 5 - .../command/framework/CommandValidate.java | 48 --------- .../config/AsciiPlaceholders.java | 8 -- .../chestcommands/config/ConfigUtil.java | 2 +- .../chestcommands/internal/RequiredItem.java | 6 +- .../internal/icon/ExtendedIcon.java | 2 +- .../chestcommands/parser/ActionParser.java | 2 +- .../parser/EnchantmentParser.java | 4 +- .../chestcommands/util/FormatUtils.java | 101 ++++++++---------- .../chestcommands/util/InventoryUtils.java | 52 --------- .../chestcommands/util/MaterialsRegistry.java | 11 +- .../chestcommands/util/StringUtils.java | 21 +--- .../chestcommands/util/Validate.java | 6 -- 13 files changed, 57 insertions(+), 211 deletions(-) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/util/InventoryUtils.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java index 127491e..9a63553 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java @@ -42,11 +42,6 @@ public class EconomyBridge { return economy != null; } - public static Economy getEconomy() { - if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!"); - return economy; - } - public static double getMoney(Player player) { if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!"); return economy.getBalance(player, player.getWorld().getName()); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandValidate.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandValidate.java index 7f74ced..81c6c09 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandValidate.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandValidate.java @@ -28,54 +28,6 @@ public class CommandValidate { } } - public static int getPositiveInteger(String input) { - try { - int i = Integer.parseInt(input); - if (i < 0) { - throw new CommandException("The number must be 0 or positive."); - } - return i; - } catch (NumberFormatException e) { - throw new CommandException("Invalid number \"" + input + "\"."); - } - } - - public static int getPositiveIntegerNotZero(String input) { - try { - int i = Integer.parseInt(input); - if (i <= 0) { - throw new CommandException("The number must be positive."); - } - return i; - } catch (NumberFormatException e) { - throw new CommandException("Invalid number \"" + input + "\"."); - } - } - - public static double getPositiveDouble(String input) { - try { - double d = Double.parseDouble(input); - if (d < 0) { - throw new CommandException("The number must be 0 or positive."); - } - return d; - } catch (NumberFormatException e) { - throw new CommandException("Invalid number \"" + input + "\"."); - } - } - - public static double getPositiveDoubleNotZero(String input) { - try { - double d = Integer.parseInt(input); - if (d <= 0) { - throw new CommandException("The number must be positive."); - } - return d; - } catch (NumberFormatException e) { - throw new CommandException("Invalid number \"" + input + "\"."); - } - } - public static void minLength(Object[] array, int minLength, String msg) { if (array.length < minLength) { throw new CommandException(msg); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java index 5d4d3c0..eff5685 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java @@ -93,14 +93,6 @@ public class AsciiPlaceholders { return input; } - public static String symbolsToPlaceholders(String input) { - if (input == null) return null; - for (Entry entry : placeholders.entrySet()) { - input = input.replace(entry.getValue(), entry.getKey()); - } - return input; - } - private static String unquote(String input) { if (input.length() < 2) { // Cannot be quoted diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java index 7706f5d..a5c513d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java @@ -68,7 +68,7 @@ public class ConfigUtil { return null; } - public static List getSeparatedValues(String input, String separator) { + private static List getSeparatedValues(String input, String separator) { if (separator == null || separator.length() == 0) { separator = ";"; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java index 376edd8..25683ea 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java @@ -35,10 +35,6 @@ public class RequiredItem { this.amount = amount; } - public ItemStack createItemStack() { - return new ItemStack(material, amount, dataValue); - } - public Material getMaterial() { return material; } @@ -62,7 +58,7 @@ public class RequiredItem { return isDurabilityRestrictive; } - public boolean isValidDataValue(short data) { + private boolean isValidDataValue(short data) { if (!isDurabilityRestrictive) return true; return data == this.dataValue; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/ExtendedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/ExtendedIcon.java index 890066d..1ad61d4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/ExtendedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/ExtendedIcon.java @@ -47,7 +47,7 @@ public class ExtendedIcon extends Icon { super(); } - public boolean canClickIcon(Player player) { + private boolean canClickIcon(Player player) { if (permission == null) { return true; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ActionParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ActionParser.java index e6508f0..f8ac383 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ActionParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ActionParser.java @@ -57,7 +57,7 @@ public class ActionParser { } - public static interface IconCommandFactory { + private static interface IconCommandFactory { Action create(String actionString); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/EnchantmentParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/EnchantmentParser.java index 6185708..b18dc2a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/EnchantmentParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/EnchantmentParser.java @@ -89,7 +89,7 @@ public class EnchantmentParser { return null; } - public static Enchantment matchEnchantment(String input) { + private static Enchantment matchEnchantment(String input) { if (input == null) { return null; } @@ -103,7 +103,7 @@ public class EnchantmentParser { private final Enchantment enchantment; private final int level; - public EnchantmentDetails(Enchantment enchantment, int level) { + private EnchantmentDetails(Enchantment enchantment, int level) { this.enchantment = enchantment; this.level = level; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/FormatUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/FormatUtils.java index 647e30d..40087a8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/FormatUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/FormatUtils.java @@ -1,58 +1,43 @@ -package me.filoghost.chestcommands.util; - -import org.bukkit.ChatColor; - -import me.filoghost.chestcommands.ChestCommands; - -import java.text.DecimalFormat; -import java.util.List; - -public final class FormatUtils { - - private static DecimalFormat decimalFormat = new DecimalFormat("0.##"); - - public static String decimalFormat(double number) { - return decimalFormat.format(number); - } - - public static String addColors(String input) { - if (input == null || input.isEmpty()) return input; - return ChatColor.translateAlternateColorCodes('&', input); - } - - public static List addColors(List input) { - if (input == null || input.isEmpty()) return input; - for (int i = 0; i < input.size(); i++) { - input.set(i, addColors(input.get(i))); - } - return input; - } - - public static String colorizeName(String input) { - if (input == null || input.isEmpty()) return input; - - if (input.charAt(0) != ChatColor.COLOR_CHAR) { - return ChestCommands.getSettings().default_color__name + addColors(input); - } else { - return addColors(input); - } - } - - public static List colorizeLore(List input) { - if (input == null || input.isEmpty()) return input; - - for (int i = 0; i < input.size(); i++) { - - String line = input.get(i); - - if (line.isEmpty()) continue; - - if (line.charAt(0) != ChatColor.COLOR_CHAR) { - input.set(i, ChestCommands.getSettings().default_color__lore + addColors(line)); - } else { - input.set(i, addColors(line)); - } - } - return input; - } -} +package me.filoghost.chestcommands.util; + +import org.bukkit.ChatColor; + +import me.filoghost.chestcommands.ChestCommands; + +import java.util.List; + +public final class FormatUtils { + + public static String addColors(String input) { + if (input == null || input.isEmpty()) return input; + return ChatColor.translateAlternateColorCodes('&', input); + } + + public static String colorizeName(String input) { + if (input == null || input.isEmpty()) return input; + + if (input.charAt(0) != ChatColor.COLOR_CHAR) { + return ChestCommands.getSettings().default_color__name + addColors(input); + } else { + return addColors(input); + } + } + + public static List colorizeLore(List input) { + if (input == null || input.isEmpty()) return input; + + for (int i = 0; i < input.size(); i++) { + + String line = input.get(i); + + if (line.isEmpty()) continue; + + if (line.charAt(0) != ChatColor.COLOR_CHAR) { + input.set(i, ChestCommands.getSettings().default_color__lore + addColors(line)); + } else { + input.set(i, addColors(line)); + } + } + return input; + } +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/InventoryUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/InventoryUtils.java deleted file mode 100644 index 40ce8c6..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/InventoryUtils.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.util; - -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; - -public class InventoryUtils { - - public static boolean hasInventoryFull(Player player) { - return player.getInventory().firstEmpty() == -1; - } - - public static boolean containsAtLeast(Inventory inv, Material material, int minAmount) { - int contained = 0; - - for (ItemStack item : inv.getContents()) { - if (item != null && item.getType() == material) { - contained += item.getAmount(); - } - } - - return contained >= minAmount; - } - - public static boolean containsAtLeast(Inventory inv, Material material, int minAmount, short data) { - int contained = 0; - - for (ItemStack item : inv.getContents()) { - if (item != null && item.getType() == material && item.getDurability() == data) { - contained += item.getAmount(); - } - } - - return contained >= minAmount; - } - -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java index e64877d..8543714 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java @@ -36,6 +36,9 @@ public final class MaterialsRegistry { // Materials that are considered air (with 1.13+ compatibility) private static final Collection AIR_MATERIALS = getExistingMaterials("AIR", "CAVE_AIR", "VOID_AIR"); + // Materials that have a "Sign" block state (with 1.13+ compatibility) + private static final Collection SIGN_MATERIALS = getExistingMaterials("SIGN", "SIGN_POST", "WALL_SIGN"); + private MaterialsRegistry() { } @@ -63,7 +66,7 @@ public final class MaterialsRegistry { return StringUtils.capitalizeFully(material.toString().replace("_", " ")); } - public static Collection getExistingMaterials(String... materialEnumNames) { + private static Collection getExistingMaterials(String... materialEnumNames) { Collection existingMaterials = new HashSet(); for (String materialEnumName : materialEnumNames) { @@ -81,15 +84,15 @@ public final class MaterialsRegistry { return AIR_MATERIALS.contains(material); } - public static boolean useNewMaterialNames() { - return USE_NEW_MATERIAL_NAMES; + public static boolean isSign(Material material) { + return SIGN_MATERIALS.contains(material); } static { for (Material material : Material.values()) { addMaterialAlias(material.toString(), material); - if (!useNewMaterialNames()) { + if (!USE_NEW_MATERIAL_NAMES) { // Add numerical IDs in versions before 1.13 addMaterialAlias(String.valueOf(material.getId()), material); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java index df72998..1b74d64 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java @@ -103,24 +103,5 @@ public final class StringUtils { public static boolean isNullOrEmpty(String s) { return s == null || s.isEmpty(); } - - public static String join(Iterable iterable, String separator) { - StringBuilder builder = new StringBuilder(); - Iterator iter = iterable.iterator(); - - boolean first = true; - - while (iter.hasNext()) { - if (first) { - first = false; - } else { - builder.append(separator); - } - - builder.append(iter.next()); - } - - return builder.toString(); - } - + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Validate.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Validate.java index 4098d42..b29fbf6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Validate.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Validate.java @@ -31,10 +31,4 @@ public final class Validate { } } - public static void isFalse(boolean statement, String error) { - if (statement) { - throw new IllegalArgumentException(error); - } - } - } From e04394f15f40bfcecfe1f703b612a60f0c78ef99 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 11:02:49 +0200 Subject: [PATCH 014/213] Code cleanup --- .../java/me/filoghost/chestcommands/ChestCommands.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index ff57943..dddccd6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -27,6 +27,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.bukkit.plugin.java.JavaPlugin; import me.filoghost.chestcommands.bridge.BarAPIBridge; @@ -280,8 +281,10 @@ public class ChestCommands extends JavaPlugin { public static void closeAllMenus() { for (Player player : Bukkit.getOnlinePlayers()) { - if (player.getOpenInventory() != null) { - if (player.getOpenInventory().getTopInventory().getHolder() instanceof MenuInventoryHolder || player.getOpenInventory().getBottomInventory().getHolder() instanceof MenuInventoryHolder) { + InventoryView openInventory = player.getOpenInventory(); + if (openInventory != null) { + if (openInventory.getTopInventory().getHolder() instanceof MenuInventoryHolder + || openInventory.getBottomInventory().getHolder() instanceof MenuInventoryHolder) { player.closeInventory(); } } From 71439303b9547a134ed3d770a01a36cc9fcadc86 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 11:04:58 +0200 Subject: [PATCH 015/213] Use new scheduler methods --- .../main/java/me/filoghost/chestcommands/ChestCommands.java | 4 ++-- .../me/filoghost/chestcommands/action/OpenMenuAction.java | 2 +- .../filoghost/chestcommands/listener/InventoryListener.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index dddccd6..6d7c3ff 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -141,12 +141,12 @@ public class ChestCommands extends JavaPlugin { lastLoadErrors = errorCollector; if (errorCollector.hasWarningsOrErrors()) { - Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> { + Bukkit.getScheduler().runTaskLater(this, () -> { errorCollector.logToConsole(); }, 10L); } - Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new RefreshMenusTask(), 2L, 2L); + Bukkit.getScheduler().runTaskTimer(this, new RefreshMenusTask(), 2L, 2L); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java index b8d7a78..d61751a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java @@ -37,7 +37,7 @@ public class OpenMenuAction extends Action { * Delay the task, since this action is executed in ClickInventoryEvent * and opening another inventory in the same moment is not a good idea. */ - Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), () -> { + Bukkit.getScheduler().runTask(ChestCommands.getInstance(), () -> { if (player.hasPermission(menu.getPermission())) { menu.open(player); } else { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index 7571863..e818cb9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -81,7 +81,7 @@ public class InventoryListener implements Listener { } // Closes the inventory and executes actions AFTER the event - Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), new ExecuteActionsTask(clicker, icon)); + Bukkit.getScheduler().runTask(ChestCommands.getInstance(), new ExecuteActionsTask(clicker, icon)); } } } From 5afcca3682846dfa1503d7ace4895eefe635e89c Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 11:17:05 +0200 Subject: [PATCH 016/213] Formatting --- .../src/main/java/me/filoghost/chestcommands/Permissions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java b/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java index aaabcd6..aeed75b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java @@ -22,7 +22,7 @@ public class Permissions { SEE_ERRORS = "chestcommands.errors", SIGN_CREATE = "chestcommands.sign", - COMMAND_BASE = "chestcommands.command.", + COMMAND_BASE = "chestcommands.command.", OPEN_MENU_BASE = "chestcommands.open."; } From 123bedfbd87712cafc92df66f4490a988ee5bcb8 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 11:50:54 +0200 Subject: [PATCH 017/213] Refactoring --- .../chestcommands/ChestCommands.java | 62 +++------- .../filoghost/chestcommands/MenuManager.java | 109 ++++++++++++++++++ .../chestcommands/action/OpenMenuAction.java | 2 +- .../chestcommands/api/ChestCommandsAPI.java | 4 +- .../chestcommands/command/CommandHandler.java | 12 +- .../listener/CommandListener.java | 10 +- .../listener/InventoryListener.java | 72 ++++++------ .../chestcommands/listener/SignListener.java | 11 +- 8 files changed, 186 insertions(+), 96 deletions(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 6d7c3ff..b40eb75 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -17,11 +17,7 @@ package me.filoghost.chestcommands; import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Map; -import java.util.Set; - import org.bstats.bukkit.MetricsLite; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -50,7 +46,6 @@ import me.filoghost.chestcommands.listener.SignListener; import me.filoghost.chestcommands.parser.MenuParser; import me.filoghost.chestcommands.task.RefreshMenusTask; import me.filoghost.chestcommands.util.BukkitUtils; -import me.filoghost.chestcommands.util.CaseInsensitiveMap; import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.Utils; import me.filoghost.updatechecker.UpdateChecker; @@ -62,14 +57,10 @@ public class ChestCommands extends JavaPlugin { private static ChestCommands instance; + private MenuManager menuManager; private static Settings settings; private static Lang lang; - private static Map fileNameToMenuMap; - private static Map commandsToMenuMap; - - private static Set boundItems; - private static ErrorCollector lastLoadErrors; private static String newVersion; @@ -81,10 +72,7 @@ public class ChestCommands extends JavaPlugin { } instance = this; - fileNameToMenuMap = CaseInsensitiveMap.create(); - commandsToMenuMap = CaseInsensitiveMap.create(); - boundItems = new HashSet<>(); - + menuManager = new MenuManager(); settings = new Settings(new PluginConfig(this, "config.yml")); lang = new Lang(new PluginConfig(this, "lang.yml")); @@ -129,12 +117,12 @@ public class ChestCommands extends JavaPlugin { int pluginID = 3658; new MetricsLite(this, pluginID); - Bukkit.getPluginManager().registerEvents(new CommandListener(), this); - Bukkit.getPluginManager().registerEvents(new InventoryListener(), this); + Bukkit.getPluginManager().registerEvents(new CommandListener(menuManager), this); + Bukkit.getPluginManager().registerEvents(new InventoryListener(menuManager), this); Bukkit.getPluginManager().registerEvents(new JoinListener(), this); - Bukkit.getPluginManager().registerEvents(new SignListener(), this); + Bukkit.getPluginManager().registerEvents(new SignListener(menuManager), this); - CommandFramework.register(this, new CommandHandler("chestcommands")); + CommandFramework.register(this, new CommandHandler(menuManager, "chestcommands")); ErrorCollector errorCollector = new ErrorCollector(); load(errorCollector); @@ -157,9 +145,7 @@ public class ChestCommands extends JavaPlugin { public void load(ErrorCollector errorCollector) { - fileNameToMenuMap.clear(); - commandsToMenuMap.clear(); - boundItems.clear(); + menuManager.clear(); try { settings.load(); @@ -223,21 +209,7 @@ public class ChestCommands extends JavaPlugin { MenuData data = MenuParser.loadMenuData(menuConfig, errorCollector); ExtendedIconMenu iconMenu = MenuParser.loadMenu(menuConfig, data.getTitle(), data.getRows(), errorCollector); - if (fileNameToMenuMap.containsKey(menuConfig.getFileName())) { - errorCollector.addError("Two menus have the same file name \"" + menuConfig.getFileName() + "\" with different cases. There will be problems opening one of these two menus."); - } - fileNameToMenuMap.put(menuConfig.getFileName(), iconMenu); - - if (data.hasCommands()) { - for (String command : data.getCommands()) { - if (!command.isEmpty()) { - if (commandsToMenuMap.containsKey(command)) { - errorCollector.addError("The menus \"" + commandsToMenuMap.get(command).getFileName() + "\" and \"" + menuConfig.getFileName() + "\" have the same command \"" + command + "\". Only one will be opened."); - } - commandsToMenuMap.put(command, iconMenu); - } - } - } + menuManager.registerMenu(menuConfig.getFileName(), data.getCommands(), iconMenu, errorCollector); iconMenu.setRefreshTicks(data.getRefreshTenths()); @@ -250,7 +222,7 @@ public class ChestCommands extends JavaPlugin { if (data.hasBoundDataValue()) { boundItem.setRestrictiveData(data.getBoundDataValue()); } - boundItems.add(boundItem); + menuManager.registerTriggerItem(boundItem); } } @@ -295,6 +267,10 @@ public class ChestCommands extends JavaPlugin { public static ChestCommands getInstance() { return instance; } + + public MenuManager getMenuManager() { + return menuManager; + } public static Settings getSettings() { return settings; @@ -312,18 +288,6 @@ public class ChestCommands extends JavaPlugin { return newVersion; } - public static Map getFileNameToMenuMap() { - return fileNameToMenuMap; - } - - public static Map getCommandToMenuMap() { - return commandsToMenuMap; - } - - public static Set getBoundItems() { - return boundItems; - } - public static void setLastReloadErrors(ErrorCollector lastLoadErrors) { ChestCommands.lastLoadErrors = lastLoadErrors; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java new file mode 100644 index 0000000..d42dd20 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java @@ -0,0 +1,109 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import me.filoghost.chestcommands.api.IconMenu; +import me.filoghost.chestcommands.internal.BoundItem; +import me.filoghost.chestcommands.internal.ExtendedIconMenu; +import me.filoghost.chestcommands.internal.MenuInventoryHolder; +import me.filoghost.chestcommands.util.CaseInsensitiveMap; +import me.filoghost.chestcommands.util.ErrorCollector; + +public class MenuManager { + + private static Map fileNameToMenuMap; + private static Map commandsToMenuMap; + + private static Set boundItems; + + public MenuManager() { + fileNameToMenuMap = CaseInsensitiveMap.create(); + commandsToMenuMap = CaseInsensitiveMap.create(); + boundItems = new HashSet<>(); + } + + public void clear() { + fileNameToMenuMap.clear(); + commandsToMenuMap.clear(); + boundItems.clear(); + } + + public ExtendedIconMenu getMenuByFileName(String fileName) { + return fileNameToMenuMap.get(fileName); + } + + public void registerMenu(String fileName, String[] triggerCommands, ExtendedIconMenu menu, ErrorCollector errorCollector) { + if (fileNameToMenuMap.containsKey(fileName)) { + errorCollector.addError("Two menus have the same file name \"" + fileName + "\" with different cases. There will be problems opening one of these two menus."); + } + + fileNameToMenuMap.put(fileName, menu); + + for (String triggerCommand : triggerCommands) { + if (!triggerCommand.isEmpty()) { + if (commandsToMenuMap.containsKey(triggerCommand)) { + errorCollector.addError("The menus \"" + commandsToMenuMap.get(triggerCommand).getFileName() + "\" and \"" + fileName + "\" have the same command \"" + triggerCommand + "\". Only one will be opened."); + } + commandsToMenuMap.put(triggerCommand, menu); + } + } + } + + public void registerTriggerItem(BoundItem boundItem) { + boundItems.add(boundItem); + } + + public void openMenuByItem(Player player, ItemStack itemInHand, Action clickAction) { + for (BoundItem boundItem : boundItems) { + if (boundItem.isValidTrigger(itemInHand, clickAction)) { + if (player.hasPermission(boundItem.getMenu().getPermission())) { + boundItem.getMenu().open(player); + } else { + boundItem.getMenu().sendNoPermissionMessage(player); + } + } + } + } + + public IconMenu getIconMenu(Inventory inventory) { + if (inventory.getHolder() instanceof MenuInventoryHolder) { + return ((MenuInventoryHolder) inventory.getHolder()).getIconMenu(); + } else { + return null; + } + } + + public ExtendedIconMenu getMenuByCommand(String command) { + return commandsToMenuMap.get(command); + } + + public Collection getMenuFileNames() { + return Collections.unmodifiableCollection(fileNameToMenuMap.keySet()); + } + + + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java index d61751a..56472e0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java @@ -30,7 +30,7 @@ public class OpenMenuAction extends Action { @Override public void execute(final Player player) { String target = hasVariables ? getParsedAction(player) : action; - final ExtendedIconMenu menu = ChestCommands.getFileNameToMenuMap().get(target.toLowerCase()); + final ExtendedIconMenu menu = ChestCommands.getInstance().getMenuManager().getMenuByFileName(target.toLowerCase()); if (menu != null) { /* diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java index 838eeaf..dc0957e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java @@ -26,7 +26,7 @@ public class ChestCommandsAPI { * @return true - if the menu was found. */ public static boolean isPluginMenu(String yamlFile) { - return ChestCommands.getFileNameToMenuMap().containsKey(yamlFile); + return ChestCommands.getInstance().getMenuManager().getMenuByFileName(yamlFile) != null; } /** @@ -38,7 +38,7 @@ public class ChestCommandsAPI { * @return true - if the menu was found and opened, false if not. */ public static boolean openPluginMenu(Player player, String yamlFile) { - IconMenu menu = ChestCommands.getFileNameToMenuMap().get(yamlFile); + IconMenu menu = ChestCommands.getInstance().getMenuManager().getMenuByFileName(yamlFile); if (menu != null) { menu.open(player); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index 05e45a7..a67a21a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -21,6 +21,7 @@ import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.command.framework.CommandFramework; import me.filoghost.chestcommands.command.framework.CommandValidate; @@ -28,9 +29,12 @@ import me.filoghost.chestcommands.internal.ExtendedIconMenu; import me.filoghost.chestcommands.util.ErrorCollector; public class CommandHandler extends CommandFramework { - - public CommandHandler(String label) { + + private MenuManager menuManager; + + public CommandHandler(MenuManager menuManager, String label) { super(label); + this.menuManager = menuManager; } @Override @@ -100,7 +104,7 @@ public class CommandHandler extends CommandFramework { CommandValidate.notNull(target, "That player is not online."); String menuName = args[1].toLowerCase().endsWith(".yml") ? args[1] : args[1] + ".yml"; - ExtendedIconMenu menu = ChestCommands.getFileNameToMenuMap().get(menuName); + ExtendedIconMenu menu = menuManager.getMenuByFileName(menuName); CommandValidate.notNull(menu, "The menu \"" + menuName + "\" was not found."); if (!sender.hasPermission(menu.getPermission())) { @@ -126,7 +130,7 @@ public class CommandHandler extends CommandFramework { if (args[0].equalsIgnoreCase("list")) { CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "list"), "You don't have permission."); sender.sendMessage(ChestCommands.CHAT_PREFIX + " Loaded menus:"); - for (String file : ChestCommands.getFileNameToMenuMap().keySet()) { + for (String file : menuManager.getMenuFileNames()) { sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.WHITE + file); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java index 9e8dd37..158a9f3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java @@ -19,11 +19,17 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.internal.ExtendedIconMenu; import me.filoghost.chestcommands.util.StringUtils; public class CommandListener implements Listener { + + private MenuManager menuManager; + + public CommandListener(MenuManager menuManager) { + this.menuManager = menuManager; + } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onCommand(PlayerCommandPreprocessEvent event) { @@ -34,7 +40,7 @@ public class CommandListener implements Listener { return; } - ExtendedIconMenu menu = ChestCommands.getCommandToMenuMap().get(command); + ExtendedIconMenu menu = menuManager.getMenuByCommand(command); if (menu != null) { event.setCancelled(true); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index e818cb9..3ae3667 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -25,66 +25,66 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.api.IconMenu; -import me.filoghost.chestcommands.internal.BoundItem; -import me.filoghost.chestcommands.internal.MenuInventoryHolder; import me.filoghost.chestcommands.task.ExecuteActionsTask; import java.util.HashMap; import java.util.Map; public class InventoryListener implements Listener { - + private static Map antiClickSpam = new HashMap<>(); + + private MenuManager menuManager; + + public InventoryListener(MenuManager menuManager) { + this.menuManager = menuManager; + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false) public void onInteract(PlayerInteractEvent event) { if (event.hasItem() && event.getAction() != Action.PHYSICAL) { - for (BoundItem boundItem : ChestCommands.getBoundItems()) { - if (boundItem.isValidTrigger(event.getItem(), event.getAction())) { - if (event.getPlayer().hasPermission(boundItem.getMenu().getPermission())) { - boundItem.getMenu().open(event.getPlayer()); - } else { - boundItem.getMenu().sendNoPermissionMessage(event.getPlayer()); - } - } - } + menuManager.openMenuByItem(event.getPlayer(), event.getItem(), event.getAction()); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false) public void onInventoryClick(InventoryClickEvent event) { - if (event.getInventory().getHolder() instanceof MenuInventoryHolder) { + IconMenu menu = menuManager.getIconMenu(event.getInventory()); + if (menu == null) { + return; + } + + event.setCancelled(true); // First thing to do, if an exception is thrown at least the player doesn't take the item - event.setCancelled(true); // First thing to do, if an exception is thrown at least the player doesn't take the item + int slot = event.getRawSlot(); + if (slot < 0 || slot >= menu.getSize()) { + return; + } - IconMenu menu = ((MenuInventoryHolder) event.getInventory().getHolder()).getIconMenu(); - int slot = event.getRawSlot(); + Icon icon = menu.getIconRaw(slot); + if (icon == null || event.getInventory().getItem(slot) == null) { + return; + } - if (slot >= 0 && slot < menu.getSize()) { + Player clicker = (Player) event.getWhoClicked(); - Icon icon = menu.getIconRaw(slot); + Long cooldownUntil = antiClickSpam.get(clicker); + long now = System.currentTimeMillis(); + int minDelay = ChestCommands.getSettings().anti_click_spam_delay; - if (icon != null && event.getInventory().getItem(slot) != null) { - Player clicker = (Player) event.getWhoClicked(); - - Long cooldownUntil = antiClickSpam.get(clicker); - long now = System.currentTimeMillis(); - int minDelay = ChestCommands.getSettings().anti_click_spam_delay; - - if (minDelay > 0) { - if (cooldownUntil != null && cooldownUntil > now) { - return; - } else { - antiClickSpam.put(clicker, now + minDelay); - } - } - - // Closes the inventory and executes actions AFTER the event - Bukkit.getScheduler().runTask(ChestCommands.getInstance(), new ExecuteActionsTask(clicker, icon)); - } + if (minDelay > 0) { + if (cooldownUntil != null && cooldownUntil > now) { + return; + } else { + antiClickSpam.put(clicker, now + minDelay); } } + + // Closes the inventory and executes actions AFTER the event + Bukkit.getScheduler().runTask(ChestCommands.getInstance(), new ExecuteActionsTask(clicker, icon)); } @EventHandler diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java index 5b8602f..15d593e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java @@ -24,6 +24,7 @@ import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerInteractEvent; import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.api.IconMenu; import me.filoghost.chestcommands.internal.ExtendedIconMenu; @@ -31,6 +32,12 @@ import me.filoghost.chestcommands.util.BukkitUtils; import me.filoghost.chestcommands.util.MaterialsRegistry; public class SignListener implements Listener { + + private MenuManager menuManager; + + public SignListener(MenuManager menuManager) { + this.menuManager = menuManager; + } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onInteract(PlayerInteractEvent event) { @@ -41,7 +48,7 @@ public class SignListener implements Listener { if (sign.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[menu]")) { sign.getLine(1); - ExtendedIconMenu iconMenu = ChestCommands.getFileNameToMenuMap().get(BukkitUtils.addYamlExtension(sign.getLine(1))); + ExtendedIconMenu iconMenu = menuManager.getMenuByFileName(BukkitUtils.addYamlExtension(sign.getLine(1))); if (iconMenu != null) { if (event.getPlayer().hasPermission(iconMenu.getPermission())) { @@ -68,7 +75,7 @@ public class SignListener implements Listener { return; } - IconMenu iconMenu = ChestCommands.getFileNameToMenuMap().get(BukkitUtils.addYamlExtension(event.getLine(1))); + IconMenu iconMenu = menuManager.getMenuByFileName(BukkitUtils.addYamlExtension(event.getLine(1))); if (iconMenu == null) { event.setLine(0, ChatColor.RED + event.getLine(0)); event.getPlayer().sendMessage(ChatColor.RED + "That menu was not found."); From 6bd1e9d3f94a824f542820510d676637fdd72252 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 20:21:38 +0200 Subject: [PATCH 018/213] Improve SignListener --- .../chestcommands/listener/SignListener.java | 109 ++++++++++++------ .../chestcommands/util/MaterialsRegistry.java | 10 +- 2 files changed, 72 insertions(+), 47 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java index 15d593e..368a25e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java @@ -15,7 +15,9 @@ package me.filoghost.chestcommands.listener; import org.bukkit.ChatColor; +import org.bukkit.block.BlockState; import org.bukkit.block.Sign; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -29,10 +31,17 @@ import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.api.IconMenu; import me.filoghost.chestcommands.internal.ExtendedIconMenu; import me.filoghost.chestcommands.util.BukkitUtils; -import me.filoghost.chestcommands.util.MaterialsRegistry; public class SignListener implements Listener { + private static final int HEADER_LINE = 0; + private static final int FILENAME_LINE = 1; + + private static final String SIGN_CREATION_TRIGGER = "[menu]"; + + private static final ChatColor VALID_SIGN_COLOR = ChatColor.DARK_BLUE; + private static final String VALID_SIGN_HEADER = VALID_SIGN_COLOR + SIGN_CREATION_TRIGGER; + private MenuManager menuManager; public SignListener(MenuManager menuManager) { @@ -40,59 +49,83 @@ public class SignListener implements Listener { } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void onInteract(PlayerInteractEvent event) { + public void onSignClick(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { + return; + } + + BlockState clickedBlockState = event.getClickedBlock().getState(); + + if (!(clickedBlockState instanceof Sign)) { + return; + } + + Sign sign = (Sign) clickedBlockState; + + if (!sign.getLine(HEADER_LINE).equalsIgnoreCase(VALID_SIGN_HEADER)) { + return; + } - if (event.getAction() == Action.RIGHT_CLICK_BLOCK && MaterialsRegistry.isSign(event.getClickedBlock().getType())) { - - Sign sign = (Sign) event.getClickedBlock().getState(); - if (sign.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[menu]")) { - - sign.getLine(1); - ExtendedIconMenu iconMenu = menuManager.getMenuByFileName(BukkitUtils.addYamlExtension(sign.getLine(1))); - if (iconMenu != null) { - - if (event.getPlayer().hasPermission(iconMenu.getPermission())) { - iconMenu.open(event.getPlayer()); - } else { - iconMenu.sendNoPermissionMessage(event.getPlayer()); - } - - } else { - sign.setLine(0, ChatColor.RED + ChatColor.stripColor(sign.getLine(0))); - event.getPlayer().sendMessage(ChestCommands.getLang().menu_not_found); - } - } + String menuFileName = BukkitUtils.addYamlExtension(sign.getLine(FILENAME_LINE).trim()); + ExtendedIconMenu menu = menuManager.getMenuByFileName(menuFileName); + + if (menu == null) { + event.getPlayer().sendMessage(ChestCommands.getLang().menu_not_found); + return; + } + + if (event.getPlayer().hasPermission(menu.getPermission())) { + menu.open(event.getPlayer()); + } else { + menu.sendNoPermissionMessage(event.getPlayer()); } } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void onSignChange(SignChangeEvent event) { - if (event.getLine(0).equalsIgnoreCase("[menu]") && event.getPlayer().hasPermission(Permissions.SIGN_CREATE)) { - - if (event.getLine(1).isEmpty()) { - event.setLine(0, ChatColor.RED + event.getLine(0)); - event.getPlayer().sendMessage(ChatColor.RED + "You must set a valid menu name in the second line."); + public void onCreateMenuSign(SignChangeEvent event) { + if (isCreatingMenuSign(event.getLine(HEADER_LINE)) && canCreateMenuSign(event.getPlayer())) { + String menuFileName = event.getLine(FILENAME_LINE).trim(); + + if (menuFileName.isEmpty()) { + event.setCancelled(true); + event.getPlayer().sendMessage(ChatColor.RED + "You must write a menu name in the second line."); return; } - - IconMenu iconMenu = menuManager.getMenuByFileName(BukkitUtils.addYamlExtension(event.getLine(1))); + + menuFileName = BukkitUtils.addYamlExtension(menuFileName); + + IconMenu iconMenu = menuManager.getMenuByFileName(menuFileName); if (iconMenu == null) { - event.setLine(0, ChatColor.RED + event.getLine(0)); - event.getPlayer().sendMessage(ChatColor.RED + "That menu was not found."); + event.setCancelled(true); + event.getPlayer().sendMessage(ChatColor.RED + "Menu \"" + menuFileName + "\" was not found."); return; } - - event.setLine(0, ChatColor.DARK_BLUE + event.getLine(0)); - event.getPlayer().sendMessage(ChatColor.GREEN + "Successfully created a sign for the menu " + BukkitUtils.addYamlExtension(event.getLine(1)) + "."); + + event.setLine(HEADER_LINE, VALID_SIGN_COLOR + event.getLine(HEADER_LINE)); + event.getPlayer().sendMessage(ChatColor.GREEN + "Successfully created a sign for the menu " + menuFileName + "."); } } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onSignChangeMonitor(SignChangeEvent event) { - // Prevent players with permissions for creating colored signs from creating menu signs - if (event.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[menu]") && !event.getPlayer().hasPermission(Permissions.SIGN_CREATE)) { - event.setLine(0, ChatColor.stripColor(event.getLine(0))); + // Prevent players without permissions from creating menu signs + if (isValidMenuSign(event.getLine(HEADER_LINE)) && !canCreateMenuSign(event.getPlayer())) { + event.setLine(HEADER_LINE, ChatColor.stripColor(event.getLine(HEADER_LINE))); } } + + private boolean isCreatingMenuSign(String headerLine) { + return headerLine.equalsIgnoreCase(SIGN_CREATION_TRIGGER); + } + + private boolean isValidMenuSign(String headerLine) { + return headerLine.equalsIgnoreCase(VALID_SIGN_HEADER); + } + + private boolean canCreateMenuSign(Player player) { + return player.hasPermission(Permissions.SIGN_CREATE); + } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java index 8543714..f06a753 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java @@ -15,7 +15,6 @@ package me.filoghost.chestcommands.util; import org.bukkit.Material; - import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -36,9 +35,6 @@ public final class MaterialsRegistry { // Materials that are considered air (with 1.13+ compatibility) private static final Collection AIR_MATERIALS = getExistingMaterials("AIR", "CAVE_AIR", "VOID_AIR"); - // Materials that have a "Sign" block state (with 1.13+ compatibility) - private static final Collection SIGN_MATERIALS = getExistingMaterials("SIGN", "SIGN_POST", "WALL_SIGN"); - private MaterialsRegistry() { } @@ -83,11 +79,7 @@ public final class MaterialsRegistry { public static boolean isAir(Material material) { return AIR_MATERIALS.contains(material); } - - public static boolean isSign(Material material) { - return SIGN_MATERIALS.contains(material); - } - + static { for (Material material : Material.values()) { addMaterialAlias(material.toString(), material); From 7410d89f3cf3c4a4f1c61fdbd740f7a531c2dd6d Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 20:28:44 +0200 Subject: [PATCH 019/213] Code cleanup --- .../chestcommands/util/MaterialsRegistry.java | 151 +++++++++--------- .../chestcommands/util/StringUtils.java | 2 - 2 files changed, 77 insertions(+), 76 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java index f06a753..46602e4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java @@ -20,7 +20,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; -@SuppressWarnings("deprecation") public final class MaterialsRegistry { // Material names have been changed in 1.13, when dolphins were added @@ -30,25 +29,93 @@ public final class MaterialsRegistry { private static final char[] IGNORE_CHARS = {'-', '_', ' '}; // Default material names are ugly - private static final Map MATERIALS_BY_ALIAS = new HashMap<>(); + private static final Map MATERIALS_BY_ALIAS = initMaterialsByAlias(); // Materials that are considered air (with 1.13+ compatibility) private static final Collection AIR_MATERIALS = getExistingMaterials("AIR", "CAVE_AIR", "VOID_AIR"); - private MaterialsRegistry() { + private MaterialsRegistry() {} + + @SuppressWarnings("deprecation") + private static Map initMaterialsByAlias() { + Map materialsByAlias = new HashMap<>(); + + for (Material material : Material.values()) { + addMaterialAlias(materialsByAlias, material.toString(), material); + + if (!USE_NEW_MATERIAL_NAMES) { + // Add numerical IDs in versions before 1.13 + addMaterialAlias(materialsByAlias, String.valueOf(material.getId()), material); + } + } + + // Add some default useful aliases (when present) + tryAddMaterialAlias(materialsByAlias, "iron bar", "IRON_FENCE"); + tryAddMaterialAlias(materialsByAlias, "iron bars", "IRON_FENCE"); + tryAddMaterialAlias(materialsByAlias, "glass pane", "THIN_GLASS"); + tryAddMaterialAlias(materialsByAlias, "nether wart", "NETHER_STALK"); + tryAddMaterialAlias(materialsByAlias, "nether warts", "NETHER_STALK"); + tryAddMaterialAlias(materialsByAlias, "slab", "STEP"); + tryAddMaterialAlias(materialsByAlias, "double slab", "DOUBLE_STEP"); + tryAddMaterialAlias(materialsByAlias, "stone brick", "SMOOTH_BRICK"); + tryAddMaterialAlias(materialsByAlias, "stone bricks", "SMOOTH_BRICK"); + tryAddMaterialAlias(materialsByAlias, "stone stair", "SMOOTH_STAIRS"); + tryAddMaterialAlias(materialsByAlias, "stone stairs", "SMOOTH_STAIRS"); + tryAddMaterialAlias(materialsByAlias, "potato", "POTATO_ITEM"); + tryAddMaterialAlias(materialsByAlias, "carrot", "CARROT_ITEM"); + tryAddMaterialAlias(materialsByAlias, "brewing stand", "BREWING_STAND_ITEM"); + tryAddMaterialAlias(materialsByAlias, "cauldron", "CAULDRON_ITEM"); + tryAddMaterialAlias(materialsByAlias, "carrot on stick", "CARROT_STICK"); + tryAddMaterialAlias(materialsByAlias, "carrot on a stick", "CARROT_STICK"); + tryAddMaterialAlias(materialsByAlias, "cobblestone wall", "COBBLE_WALL"); + tryAddMaterialAlias(materialsByAlias, "acacia wood stairs", "ACACIA_STAIRS"); + tryAddMaterialAlias(materialsByAlias, "dark oak wood stairs", "DARK_OAK_STAIRS"); + tryAddMaterialAlias(materialsByAlias, "wood slab", "WOOD_STEP"); + tryAddMaterialAlias(materialsByAlias, "double wood slab", "WOOD_DOUBLE_STEP"); + tryAddMaterialAlias(materialsByAlias, "repeater", "DIODE"); + tryAddMaterialAlias(materialsByAlias, "piston", "PISTON_BASE"); + tryAddMaterialAlias(materialsByAlias, "sticky piston", "PISTON_STICKY_BASE"); + tryAddMaterialAlias(materialsByAlias, "flower pot", "FLOWER_POT_ITEM"); + tryAddMaterialAlias(materialsByAlias, "wood showel", "WOOD_SPADE"); + tryAddMaterialAlias(materialsByAlias, "stone showel", "STONE_SPADE"); + tryAddMaterialAlias(materialsByAlias, "gold showel", "GOLD_SPADE"); + tryAddMaterialAlias(materialsByAlias, "iron showel", "IRON_SPADE"); + tryAddMaterialAlias(materialsByAlias, "diamond showel", "DIAMOND_SPADE"); + tryAddMaterialAlias(materialsByAlias, "steak", "COOKED_BEEF"); + tryAddMaterialAlias(materialsByAlias, "cooked porkchop", "GRILLED_PORK"); + tryAddMaterialAlias(materialsByAlias, "raw porkchop", "PORK"); + tryAddMaterialAlias(materialsByAlias, "hardened clay", "HARD_CLAY"); + tryAddMaterialAlias(materialsByAlias, "huge brown mushroom", "HUGE_MUSHROOM_1"); + tryAddMaterialAlias(materialsByAlias, "huge red mushroom", "HUGE_MUSHROOM_2"); + tryAddMaterialAlias(materialsByAlias, "mycelium", "MYCEL"); + tryAddMaterialAlias(materialsByAlias, "poppy", "RED_ROSE"); + tryAddMaterialAlias(materialsByAlias, "comparator", "REDSTONE_COMPARATOR"); + tryAddMaterialAlias(materialsByAlias, "skull", "SKULL_ITEM"); + tryAddMaterialAlias(materialsByAlias, "head", "SKULL_ITEM"); + tryAddMaterialAlias(materialsByAlias, "redstone torch", "REDSTONE_TORCH_ON"); + tryAddMaterialAlias(materialsByAlias, "redstone lamp", "REDSTONE_LAMP_OFF"); + tryAddMaterialAlias(materialsByAlias, "glistering melon", "SPECKLED_MELON"); + tryAddMaterialAlias(materialsByAlias, "acacia leaves", "LEAVES_2"); + tryAddMaterialAlias(materialsByAlias, "acacia log", "LOG_2"); + tryAddMaterialAlias(materialsByAlias, "gunpowder", "SULPHUR"); + tryAddMaterialAlias(materialsByAlias, "lilypad", "WATER_LILY"); + tryAddMaterialAlias(materialsByAlias, "command block", "COMMAND"); + tryAddMaterialAlias(materialsByAlias, "dye", "INK_SACK"); + + return materialsByAlias; } - private static void addMaterialAlias(String name, Material material) { - MATERIALS_BY_ALIAS.put(StringUtils.stripChars(name, IGNORE_CHARS).toLowerCase(), material); - } - - private static void tryAddMaterialAlias(String name, String materialEnumName) { + private static void tryAddMaterialAlias(Map materialsByAlias, String name, String materialEnumName) { try { - addMaterialAlias(name, Material.valueOf(materialEnumName)); + addMaterialAlias(materialsByAlias, name, Material.valueOf(materialEnumName)); } catch (IllegalArgumentException e) { // Ignore, do not add a new alias } } + + private static void addMaterialAlias(Map materialsByAlias, String name, Material material) { + materialsByAlias.put(StringUtils.stripChars(name, IGNORE_CHARS).toLowerCase(), material); + } public static Material matchMaterial(String alias) { if (alias == null) { @@ -63,7 +130,7 @@ public final class MaterialsRegistry { } private static Collection getExistingMaterials(String... materialEnumNames) { - Collection existingMaterials = new HashSet(); + Collection existingMaterials = new HashSet<>(); for (String materialEnumName : materialEnumNames) { try { @@ -79,69 +146,5 @@ public final class MaterialsRegistry { public static boolean isAir(Material material) { return AIR_MATERIALS.contains(material); } - - static { - for (Material material : Material.values()) { - addMaterialAlias(material.toString(), material); - - if (!USE_NEW_MATERIAL_NAMES) { - // Add numerical IDs in versions before 1.13 - addMaterialAlias(String.valueOf(material.getId()), material); - } - } - - // Add some default useful aliases (when present) - tryAddMaterialAlias("iron bar", "IRON_FENCE"); - tryAddMaterialAlias("iron bars", "IRON_FENCE"); - tryAddMaterialAlias("glass pane", "THIN_GLASS"); - tryAddMaterialAlias("nether wart", "NETHER_STALK"); - tryAddMaterialAlias("nether warts", "NETHER_STALK"); - tryAddMaterialAlias("slab", "STEP"); - tryAddMaterialAlias("double slab", "DOUBLE_STEP"); - tryAddMaterialAlias("stone brick", "SMOOTH_BRICK"); - tryAddMaterialAlias("stone bricks", "SMOOTH_BRICK"); - tryAddMaterialAlias("stone stair", "SMOOTH_STAIRS"); - tryAddMaterialAlias("stone stairs", "SMOOTH_STAIRS"); - tryAddMaterialAlias("potato", "POTATO_ITEM"); - tryAddMaterialAlias("carrot", "CARROT_ITEM"); - tryAddMaterialAlias("brewing stand", "BREWING_STAND_ITEM"); - tryAddMaterialAlias("cauldron", "CAULDRON_ITEM"); - tryAddMaterialAlias("carrot on stick", "CARROT_STICK"); - tryAddMaterialAlias("carrot on a stick", "CARROT_STICK"); - tryAddMaterialAlias("cobblestone wall", "COBBLE_WALL"); - tryAddMaterialAlias("acacia wood stairs", "ACACIA_STAIRS"); - tryAddMaterialAlias("dark oak wood stairs", "DARK_OAK_STAIRS"); - tryAddMaterialAlias("wood slab", "WOOD_STEP"); - tryAddMaterialAlias("double wood slab", "WOOD_DOUBLE_STEP"); - tryAddMaterialAlias("repeater", "DIODE"); - tryAddMaterialAlias("piston", "PISTON_BASE"); - tryAddMaterialAlias("sticky piston", "PISTON_STICKY_BASE"); - tryAddMaterialAlias("flower pot", "FLOWER_POT_ITEM"); - tryAddMaterialAlias("wood showel", "WOOD_SPADE"); - tryAddMaterialAlias("stone showel", "STONE_SPADE"); - tryAddMaterialAlias("gold showel", "GOLD_SPADE"); - tryAddMaterialAlias("iron showel", "IRON_SPADE"); - tryAddMaterialAlias("diamond showel", "DIAMOND_SPADE"); - tryAddMaterialAlias("steak", "COOKED_BEEF"); - tryAddMaterialAlias("cooked porkchop", "GRILLED_PORK"); - tryAddMaterialAlias("raw porkchop", "PORK"); - tryAddMaterialAlias("hardened clay", "HARD_CLAY"); - tryAddMaterialAlias("huge brown mushroom", "HUGE_MUSHROOM_1"); - tryAddMaterialAlias("huge red mushroom", "HUGE_MUSHROOM_2"); - tryAddMaterialAlias("mycelium", "MYCEL"); - tryAddMaterialAlias("poppy", "RED_ROSE"); - tryAddMaterialAlias("comparator", "REDSTONE_COMPARATOR"); - tryAddMaterialAlias("skull", "SKULL_ITEM"); - tryAddMaterialAlias("head", "SKULL_ITEM"); - tryAddMaterialAlias("redstone torch", "REDSTONE_TORCH_ON"); - tryAddMaterialAlias("redstone lamp", "REDSTONE_LAMP_OFF"); - tryAddMaterialAlias("glistering melon", "SPECKLED_MELON"); - tryAddMaterialAlias("acacia leaves", "LEAVES_2"); - tryAddMaterialAlias("acacia log", "LOG_2"); - tryAddMaterialAlias("gunpowder", "SULPHUR"); - tryAddMaterialAlias("lilypad", "WATER_LILY"); - tryAddMaterialAlias("command block", "COMMAND"); - tryAddMaterialAlias("dye", "INK_SACK"); - } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java index 1b74d64..c7ca72f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java @@ -14,8 +14,6 @@ */ package me.filoghost.chestcommands.util; -import java.util.Iterator; - public final class StringUtils { private StringUtils() { From 6261c318b095e8aaaf5bc5684107b97552a18950 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 21:23:19 +0200 Subject: [PATCH 020/213] Separate variables in new package --- .../chestcommands/action/Action.java | 2 +- .../me/filoghost/chestcommands/api/Icon.java | 2 +- .../{internal => variable}/CachedGetters.java | 2 +- .../{internal => variable}/Variable.java | 2 +- .../VariableManager.java | 72 +++++++++---------- 5 files changed, 40 insertions(+), 40 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal => variable}/CachedGetters.java (93%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal => variable}/Variable.java (93%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal => variable}/VariableManager.java (91%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java index 9838529..b336658 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java @@ -17,7 +17,7 @@ package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; import me.filoghost.chestcommands.config.AsciiPlaceholders; -import me.filoghost.chestcommands.internal.VariableManager; +import me.filoghost.chestcommands.variable.VariableManager; public abstract class Action { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java index 590e8e8..96d9559 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java @@ -25,8 +25,8 @@ import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.inventory.meta.SkullMeta; import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.internal.VariableManager; import me.filoghost.chestcommands.util.Utils; +import me.filoghost.chestcommands.variable.VariableManager; import java.util.ArrayList; import java.util.Arrays; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/CachedGetters.java b/Plugin/src/main/java/me/filoghost/chestcommands/variable/CachedGetters.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/CachedGetters.java rename to Plugin/src/main/java/me/filoghost/chestcommands/variable/CachedGetters.java index 5410a0f..73d1de0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/CachedGetters.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/variable/CachedGetters.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.variable; import org.bukkit.Bukkit; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/Variable.java b/Plugin/src/main/java/me/filoghost/chestcommands/variable/Variable.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/Variable.java rename to Plugin/src/main/java/me/filoghost/chestcommands/variable/Variable.java index ad420e9..8b986b9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/Variable.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/variable/Variable.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.variable; import org.bukkit.Bukkit; import org.bukkit.entity.Player; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/VariableManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/variable/VariableManager.java similarity index 91% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/VariableManager.java rename to Plugin/src/main/java/me/filoghost/chestcommands/variable/VariableManager.java index e0496f2..ac7b3f8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/VariableManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/variable/VariableManager.java @@ -1,36 +1,36 @@ -package me.filoghost.chestcommands.internal; - -import org.bukkit.entity.Player; - -import me.filoghost.chestcommands.bridge.PlaceholderAPIBridge; - -public class VariableManager { - - public static boolean hasVariables(String message) { - if(message == null) { - return false; - } - for (Variable variable : Variable.values()) { - if (message.contains(variable.getText())) { - return true; - } - } - if (PlaceholderAPIBridge.hasValidPlugin() && PlaceholderAPIBridge.hasPlaceholders(message)) { - return true; - } - return false; - } - - public static String setVariables(String message, Player executor) { - for (Variable variable : Variable.values()) { - if (message.contains(variable.getText())) { - message = message.replace(variable.getText(), variable.getReplacement(executor)); - } - } - if (PlaceholderAPIBridge.hasValidPlugin()) { - message = PlaceholderAPIBridge.setPlaceholders(message, executor); - } - return message; - } - -} +package me.filoghost.chestcommands.variable; + +import org.bukkit.entity.Player; + +import me.filoghost.chestcommands.bridge.PlaceholderAPIBridge; + +public class VariableManager { + + public static boolean hasVariables(String message) { + if(message == null) { + return false; + } + for (Variable variable : Variable.values()) { + if (message.contains(variable.getText())) { + return true; + } + } + if (PlaceholderAPIBridge.hasValidPlugin() && PlaceholderAPIBridge.hasPlaceholders(message)) { + return true; + } + return false; + } + + public static String setVariables(String message, Player executor) { + for (Variable variable : Variable.values()) { + if (message.contains(variable.getText())) { + message = message.replace(variable.getText(), variable.getReplacement(executor)); + } + } + if (PlaceholderAPIBridge.hasValidPlugin()) { + message = PlaceholderAPIBridge.setPlaceholders(message, executor); + } + return message; + } + +} From f37cad51859664ba6d5e6e815031b71f91ea287c Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 21:37:17 +0200 Subject: [PATCH 021/213] Move classes --- .../java/me/filoghost/chestcommands/internal/BoundItem.java | 1 - .../chestcommands/{util => internal}/ClickType.java | 2 +- .../chestcommands/internal/{icon => }/ExtendedIcon.java | 5 +---- .../filoghost/chestcommands/internal/ExtendedIconMenu.java | 1 - .../java/me/filoghost/chestcommands/internal/MenuData.java | 1 - .../java/me/filoghost/chestcommands/parser/IconParser.java | 2 +- .../java/me/filoghost/chestcommands/parser/MenuParser.java | 2 +- 7 files changed, 4 insertions(+), 10 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/{util => internal}/ClickType.java (93%) rename Plugin/src/main/java/me/filoghost/chestcommands/internal/{icon => }/ExtendedIcon.java (93%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BoundItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BoundItem.java index a5fd267..859c514 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BoundItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BoundItem.java @@ -18,7 +18,6 @@ import org.bukkit.Material; import org.bukkit.event.block.Action; import org.bukkit.inventory.ItemStack; -import me.filoghost.chestcommands.util.ClickType; import me.filoghost.chestcommands.util.Validate; public class BoundItem { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/ClickType.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ClickType.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/ClickType.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/ClickType.java index 8262ba7..434d75d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/ClickType.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ClickType.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.util; +package me.filoghost.chestcommands.internal; import org.bukkit.event.block.Action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/ExtendedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/ExtendedIcon.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java index 1ad61d4..4920ab7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/ExtendedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal.icon; +package me.filoghost.chestcommands.internal; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -22,9 +22,6 @@ import org.bukkit.inventory.InventoryView; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.bridge.EconomyBridge; -import me.filoghost.chestcommands.internal.ExtendedIconMenu; -import me.filoghost.chestcommands.internal.MenuInventoryHolder; -import me.filoghost.chestcommands.internal.RequiredItem; import me.filoghost.chestcommands.util.MaterialsRegistry; import me.filoghost.chestcommands.util.StringUtils; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java index 920f78c..4f4e8aa 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java @@ -26,7 +26,6 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.api.IconMenu; -import me.filoghost.chestcommands.internal.icon.ExtendedIcon; import me.filoghost.chestcommands.util.ItemUtils; import java.util.List; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuData.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuData.java index fce0303..d2945f3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuData.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuData.java @@ -17,7 +17,6 @@ package me.filoghost.chestcommands.internal; import org.bukkit.Material; import me.filoghost.chestcommands.action.Action; -import me.filoghost.chestcommands.util.ClickType; import java.util.List; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index 2749de6..d928efa 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -29,8 +29,8 @@ import me.filoghost.chestcommands.config.AsciiPlaceholders; import me.filoghost.chestcommands.config.ConfigUtil; import me.filoghost.chestcommands.exception.FormatException; import me.filoghost.chestcommands.internal.RunActionsClickHandler; +import me.filoghost.chestcommands.internal.ExtendedIcon; import me.filoghost.chestcommands.internal.RequiredItem; -import me.filoghost.chestcommands.internal.icon.ExtendedIcon; import me.filoghost.chestcommands.parser.EnchantmentParser.EnchantmentDetails; import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.FormatUtils; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java index 049fd44..5417d82 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java @@ -26,10 +26,10 @@ import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.config.ConfigUtil; import me.filoghost.chestcommands.config.yaml.PluginConfig; import me.filoghost.chestcommands.exception.FormatException; +import me.filoghost.chestcommands.internal.ClickType; import me.filoghost.chestcommands.internal.ExtendedIconMenu; import me.filoghost.chestcommands.internal.MenuData; import me.filoghost.chestcommands.parser.IconParser.Coords; -import me.filoghost.chestcommands.util.ClickType; import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.FormatUtils; From 5b4d011fb2b1b40edb8eb24fae8055f6da7b0ac7 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 6 Jun 2020 22:43:51 +0200 Subject: [PATCH 022/213] Refactoring --- .../main/java/me/filoghost/chestcommands/MenuManager.java | 6 +----- .../me/filoghost/chestcommands/action/OpenMenuAction.java | 6 +----- .../chestcommands/internal/ExtendedIconMenu.java | 8 ++++++++ .../filoghost/chestcommands/listener/CommandListener.java | 7 +------ .../me/filoghost/chestcommands/listener/SignListener.java | 6 +----- 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java index d42dd20..f9f783f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java @@ -79,11 +79,7 @@ public class MenuManager { public void openMenuByItem(Player player, ItemStack itemInHand, Action clickAction) { for (BoundItem boundItem : boundItems) { if (boundItem.isValidTrigger(itemInHand, clickAction)) { - if (player.hasPermission(boundItem.getMenu().getPermission())) { - boundItem.getMenu().open(player); - } else { - boundItem.getMenu().sendNoPermissionMessage(player); - } + boundItem.getMenu().openCheckingPermission(player); } } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java index 56472e0..01026ad 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java @@ -38,11 +38,7 @@ public class OpenMenuAction extends Action { * and opening another inventory in the same moment is not a good idea. */ Bukkit.getScheduler().runTask(ChestCommands.getInstance(), () -> { - if (player.hasPermission(menu.getPermission())) { - menu.open(player); - } else { - menu.sendNoPermissionMessage(player); - } + menu.openCheckingPermission(player); }); } else { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java index 4f4e8aa..96b4d4c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java @@ -96,6 +96,14 @@ public class ExtendedIconMenu extends IconMenu { player.sendMessage(ChatColor.RED + "An internal error occurred while opening the menu. The staff should check the console for errors."); } } + + public void openCheckingPermission(Player player) { + if (player.hasPermission(getPermission())) { + open(player); + } else { + sendNoPermissionMessage(player); + } + } public void refresh(Player player, Inventory inventory) { try { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java index 158a9f3..d10f92b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java @@ -44,12 +44,7 @@ public class CommandListener implements Listener { if (menu != null) { event.setCancelled(true); - - if (event.getPlayer().hasPermission(menu.getPermission())) { - menu.open(event.getPlayer()); - } else { - menu.sendNoPermissionMessage(event.getPlayer()); - } + menu.openCheckingPermission(event.getPlayer()); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java index 368a25e..6d7e9ef 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java @@ -74,11 +74,7 @@ public class SignListener implements Listener { return; } - if (event.getPlayer().hasPermission(menu.getPermission())) { - menu.open(event.getPlayer()); - } else { - menu.sendNoPermissionMessage(event.getPlayer()); - } + menu.openCheckingPermission(event.getPlayer()); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) From 76b1fc6b8deaa8d745fca22df5e3406af1a2cb66 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 11:41:52 +0200 Subject: [PATCH 023/213] Unify Enum parsing --- .../chestcommands/action/PlaySoundAction.java | 6 +- .../chestcommands/internal/ExtendedIcon.java | 4 +- .../parser/EnchantmentParser.java | 79 ++++----- .../chestcommands/parser/ItemStackParser.java | 9 +- .../chestcommands/util/BukkitUtils.java | 16 -- .../chestcommands/util/ItemUtils.java | 23 ++- .../chestcommands/util/MaterialsHelper.java | 127 +++++++++++++++ .../chestcommands/util/MaterialsRegistry.java | 150 ------------------ .../chestcommands/util/Registry.java | 90 +++++++++++ .../chestcommands/util/StringUtils.java | 11 +- 10 files changed, 273 insertions(+), 242 deletions(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/util/Registry.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java index e69cfeb..74abe55 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java @@ -18,9 +18,11 @@ import org.bukkit.ChatColor; import org.bukkit.Sound; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.util.BukkitUtils; +import me.filoghost.chestcommands.util.Registry; public class PlaySoundAction extends Action { + + private static Registry SOUNDS_REGISTRY = Registry.fromEnumValues(Sound.class); private Sound sound; private float pitch; @@ -41,7 +43,7 @@ public class PlaySoundAction extends Action { String[] split = action.split(","); - sound = BukkitUtils.matchSound(split[0]); + sound = SOUNDS_REGISTRY.find(split[0]); if (sound == null) { errorMessage = ChatColor.RED + "Invalid sound \"" + split[0].trim() + "\"."; return; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java index 4920ab7..85e0b31 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java @@ -22,7 +22,7 @@ import org.bukkit.inventory.InventoryView; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.bridge.EconomyBridge; -import me.filoghost.chestcommands.util.MaterialsRegistry; +import me.filoghost.chestcommands.util.MaterialsHelper; import me.filoghost.chestcommands.util.StringUtils; import java.util.List; @@ -179,7 +179,7 @@ public class ExtendedIcon extends Icon { if (!item.hasItem(player)) { notHasItem = true; player.sendMessage(ChestCommands.getLang().no_required_item - .replace("{material}", MaterialsRegistry.formatMaterial(item.getMaterial())) + .replace("{material}", MaterialsHelper.formatMaterial(item.getMaterial())) .replace("{amount}", Integer.toString(item.getAmount())) .replace("{datavalue}", item.hasRestrictiveDataValue() ? Short.toString(item.getDataValue()) : ChestCommands.getLang().any) ); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/EnchantmentParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/EnchantmentParser.java index b18dc2a..b21e387 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/EnchantmentParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/EnchantmentParser.java @@ -14,54 +14,43 @@ */ package me.filoghost.chestcommands.parser; -import java.util.HashMap; -import java.util.Map; - import org.bukkit.enchantments.Enchantment; +import me.filoghost.chestcommands.util.Registry; import me.filoghost.chestcommands.util.ErrorCollector; -import me.filoghost.chestcommands.util.StringUtils; public class EnchantmentParser { - private static Map enchantmentsMap = new HashMap<>(); + private static Registry ENCHANTMENTS_REGISTRY; static { - enchantmentsMap.put(formatLowercase("Protection"), Enchantment.PROTECTION_ENVIRONMENTAL); - enchantmentsMap.put(formatLowercase("Fire Protection"), Enchantment.PROTECTION_FIRE); - enchantmentsMap.put(formatLowercase("Feather Falling"), Enchantment.PROTECTION_FALL); - enchantmentsMap.put(formatLowercase("Blast Protection"), Enchantment.PROTECTION_EXPLOSIONS); - enchantmentsMap.put(formatLowercase("Projectile Protection"), Enchantment.PROTECTION_PROJECTILE); - enchantmentsMap.put(formatLowercase("Respiration"), Enchantment.OXYGEN); - enchantmentsMap.put(formatLowercase("Aqua Affinity"), Enchantment.WATER_WORKER); - enchantmentsMap.put(formatLowercase("Thorns"), Enchantment.THORNS); - enchantmentsMap.put(formatLowercase("Sharpness"), Enchantment.DAMAGE_ALL); - enchantmentsMap.put(formatLowercase("Smite"), Enchantment.DAMAGE_UNDEAD); - enchantmentsMap.put(formatLowercase("Bane Of Arthropods"), Enchantment.DAMAGE_ARTHROPODS); - enchantmentsMap.put(formatLowercase("Knockback"), Enchantment.KNOCKBACK); - enchantmentsMap.put(formatLowercase("Fire Aspect"), Enchantment.FIRE_ASPECT); - enchantmentsMap.put(formatLowercase("Looting"), Enchantment.LOOT_BONUS_MOBS); - enchantmentsMap.put(formatLowercase("Efficiency"), Enchantment.DIG_SPEED); - enchantmentsMap.put(formatLowercase("Silk Touch"), Enchantment.SILK_TOUCH); - enchantmentsMap.put(formatLowercase("Unbreaking"), Enchantment.DURABILITY); - enchantmentsMap.put(formatLowercase("Fortune"), Enchantment.LOOT_BONUS_BLOCKS); - enchantmentsMap.put(formatLowercase("Power"), Enchantment.ARROW_DAMAGE); - enchantmentsMap.put(formatLowercase("Punch"), Enchantment.ARROW_KNOCKBACK); - enchantmentsMap.put(formatLowercase("Flame"), Enchantment.ARROW_FIRE); - enchantmentsMap.put(formatLowercase("Infinity"), Enchantment.ARROW_INFINITE); - enchantmentsMap.put(formatLowercase("Lure"), Enchantment.LURE); - enchantmentsMap.put(formatLowercase("Luck Of The Sea"), Enchantment.LUCK); - - for (Enchantment enchant : Enchantment.values()) { - if (enchant != null) { - // Accepts the ugly default names too - enchantmentsMap.put(formatLowercase(enchant.getName()), enchant); - } - } - } - - private static String formatLowercase(String string) { - return StringUtils.stripChars(string, " _-").toLowerCase(); + ENCHANTMENTS_REGISTRY = Registry.fromValues(Enchantment.values(), Enchantment::getName); + + // Add aliases + ENCHANTMENTS_REGISTRY.put("Protection", Enchantment.PROTECTION_ENVIRONMENTAL); + ENCHANTMENTS_REGISTRY.put("Fire Protection", Enchantment.PROTECTION_FIRE); + ENCHANTMENTS_REGISTRY.put("Feather Falling", Enchantment.PROTECTION_FALL); + ENCHANTMENTS_REGISTRY.put("Blast Protection", Enchantment.PROTECTION_EXPLOSIONS); + ENCHANTMENTS_REGISTRY.put("Projectile Protection", Enchantment.PROTECTION_PROJECTILE); + ENCHANTMENTS_REGISTRY.put("Respiration", Enchantment.OXYGEN); + ENCHANTMENTS_REGISTRY.put("Aqua Affinity", Enchantment.WATER_WORKER); + ENCHANTMENTS_REGISTRY.put("Thorns", Enchantment.THORNS); + ENCHANTMENTS_REGISTRY.put("Sharpness", Enchantment.DAMAGE_ALL); + ENCHANTMENTS_REGISTRY.put("Smite", Enchantment.DAMAGE_UNDEAD); + ENCHANTMENTS_REGISTRY.put("Bane Of Arthropods", Enchantment.DAMAGE_ARTHROPODS); + ENCHANTMENTS_REGISTRY.put("Knockback", Enchantment.KNOCKBACK); + ENCHANTMENTS_REGISTRY.put("Fire Aspect", Enchantment.FIRE_ASPECT); + ENCHANTMENTS_REGISTRY.put("Looting", Enchantment.LOOT_BONUS_MOBS); + ENCHANTMENTS_REGISTRY.put("Efficiency", Enchantment.DIG_SPEED); + ENCHANTMENTS_REGISTRY.put("Silk Touch", Enchantment.SILK_TOUCH); + ENCHANTMENTS_REGISTRY.put("Unbreaking", Enchantment.DURABILITY); + ENCHANTMENTS_REGISTRY.put("Fortune", Enchantment.LOOT_BONUS_BLOCKS); + ENCHANTMENTS_REGISTRY.put("Power", Enchantment.ARROW_DAMAGE); + ENCHANTMENTS_REGISTRY.put("Punch", Enchantment.ARROW_KNOCKBACK); + ENCHANTMENTS_REGISTRY.put("Flame", Enchantment.ARROW_FIRE); + ENCHANTMENTS_REGISTRY.put("Infinity", Enchantment.ARROW_INFINITE); + ENCHANTMENTS_REGISTRY.put("Lure", Enchantment.LURE); + ENCHANTMENTS_REGISTRY.put("Luck Of The Sea", Enchantment.LUCK); } public static EnchantmentDetails parseEnchantment(String input, String iconName, String menuFileName, ErrorCollector errorCollector) { @@ -78,7 +67,7 @@ public class EnchantmentParser { input = levelSplit[0]; } - Enchantment ench = matchEnchantment(input); + Enchantment ench = ENCHANTMENTS_REGISTRY.find(input); if (ench == null) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid enchantment: " + input); @@ -88,14 +77,6 @@ public class EnchantmentParser { return null; } - - private static Enchantment matchEnchantment(String input) { - if (input == null) { - return null; - } - - return enchantmentsMap.get(formatLowercase(input)); - } public static class EnchantmentDetails { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java index 3552ec1..bff594c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java @@ -18,8 +18,7 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import me.filoghost.chestcommands.exception.FormatException; -import me.filoghost.chestcommands.util.MaterialsRegistry; -import me.filoghost.chestcommands.util.StringUtils; +import me.filoghost.chestcommands.util.MaterialsHelper; import me.filoghost.chestcommands.util.Utils; import me.filoghost.chestcommands.util.Validate; @@ -39,7 +38,7 @@ public class ItemStackParser { Validate.notNull(input, "input cannot be null"); // Remove spaces, they're not needed - input = StringUtils.stripChars(input, " _-"); + input = input.replace(" ", ""); if (parseAmount) { // Read the optional amount @@ -82,9 +81,9 @@ public class ItemStackParser { input = splitByColons[0]; } - Material material = MaterialsRegistry.matchMaterial(input); + Material material = MaterialsHelper.matchMaterial(input); - if (material == null || MaterialsRegistry.isAir(material)) { + if (material == null || MaterialsHelper.isAir(material)) { throw new FormatException("invalid material \"" + input + "\""); } this.material = material; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/BukkitUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/BukkitUtils.java index 0bb347b..17dd974 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/BukkitUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/BukkitUtils.java @@ -1,6 +1,5 @@ package me.filoghost.chestcommands.util; -import org.bukkit.Sound; import org.bukkit.plugin.Plugin; public final class BukkitUtils { @@ -23,19 +22,4 @@ public final class BukkitUtils { } } - public static Sound matchSound(String input) { - if (input == null) { - return null; - } - - input = StringUtils.stripChars(input.toLowerCase(), " _-"); - - for (Sound sound : Sound.values()) { - if (StringUtils.stripChars(sound.toString().toLowerCase(), "_").equals(input)) { - return sound; - } - } - return null; - } - } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/ItemUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/ItemUtils.java index 32ec573..0ae6b03 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/ItemUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/ItemUtils.java @@ -28,6 +28,10 @@ import java.util.ArrayList; import java.util.List; public final class ItemUtils { + + private static Registry DYE_COLORS_REGISTRY = Registry.fromEnumValues(DyeColor.class); + private static Registry PATTERN_TYPES_REGISTRY = Registry.fromEnumValues(PatternType.class); + private ItemUtils() { } @@ -47,7 +51,7 @@ public final class ItemUtils { } public static Color parseColor(String input) throws FormatException { - String[] split = StringUtils.stripChars(input, " ").split(","); + String[] split = input.replace(" ", "").split(","); if (split.length != 3) { throw new FormatException("it must be in the format \"red, green, blue\"."); @@ -71,10 +75,9 @@ public final class ItemUtils { } public static DyeColor parseDyeColor(String input) throws FormatException { - DyeColor color; - try { - color = DyeColor.valueOf(input.toUpperCase()); - } catch (IllegalArgumentException e) { + DyeColor color = DYE_COLORS_REGISTRY.find(input); + + if (color == null) { throw new FormatException("it must be a valid color."); } return color; @@ -87,11 +90,15 @@ public final class ItemUtils { if (split.length != 2) { throw new FormatException("it must be in the format \"pattern:color\"."); } - try { - patterns.add(new Pattern(parseDyeColor(split[1]), PatternType.valueOf(split[0].toUpperCase()))); - } catch (IllegalArgumentException e) { + + PatternType patternType = PATTERN_TYPES_REGISTRY.find(split[0]); + DyeColor patternColor = parseDyeColor(split[1]); + + if (patternType == null) { throw new FormatException("it must be a valid pattern type."); } + + patterns.add(new Pattern(patternColor, patternType)); } return patterns; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java new file mode 100644 index 0000000..eca7e9c --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java @@ -0,0 +1,127 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.util; + +import org.bukkit.Material; +import java.util.Collection; +import java.util.HashSet; + +public final class MaterialsHelper { + + // Material names have been changed in 1.13, when dolphins were added + private static final boolean USE_NEW_MATERIAL_NAMES = Utils.isClassLoaded("org.bukkit.entity.Dolphin"); + + // Default material names are ugly + private static final Registry MATERIALS_REGISTRY = initMaterialsRegistry(); + + // Materials that are considered air (with 1.13+ compatibility) + private static final Collection AIR_MATERIALS = getExistingMaterials("AIR", "CAVE_AIR", "VOID_AIR"); + + private MaterialsHelper() {} + + @SuppressWarnings("deprecation") + private static Registry initMaterialsRegistry() { + Registry materialsRegistry = Registry.fromEnumValues(Material.class); + + if (!USE_NEW_MATERIAL_NAMES) { + // Add numerical IDs in versions before 1.13 + for (Material material : Material.values()) { + materialsRegistry.put(String.valueOf(material.getId()), material); + } + } + + // Add some default useful aliases (when present) + materialsRegistry.putIfEnumExists("iron bar", "IRON_FENCE"); + materialsRegistry.putIfEnumExists("iron bars", "IRON_FENCE"); + materialsRegistry.putIfEnumExists("glass pane", "THIN_GLASS"); + materialsRegistry.putIfEnumExists("nether wart", "NETHER_STALK"); + materialsRegistry.putIfEnumExists("nether warts", "NETHER_STALK"); + materialsRegistry.putIfEnumExists("slab", "STEP"); + materialsRegistry.putIfEnumExists("double slab", "DOUBLE_STEP"); + materialsRegistry.putIfEnumExists("stone brick", "SMOOTH_BRICK"); + materialsRegistry.putIfEnumExists("stone bricks", "SMOOTH_BRICK"); + materialsRegistry.putIfEnumExists("stone stair", "SMOOTH_STAIRS"); + materialsRegistry.putIfEnumExists("stone stairs", "SMOOTH_STAIRS"); + materialsRegistry.putIfEnumExists("potato", "POTATO_ITEM"); + materialsRegistry.putIfEnumExists("carrot", "CARROT_ITEM"); + materialsRegistry.putIfEnumExists("brewing stand", "BREWING_STAND_ITEM"); + materialsRegistry.putIfEnumExists("cauldron", "CAULDRON_ITEM"); + materialsRegistry.putIfEnumExists("carrot on stick", "CARROT_STICK"); + materialsRegistry.putIfEnumExists("carrot on a stick", "CARROT_STICK"); + materialsRegistry.putIfEnumExists("cobblestone wall", "COBBLE_WALL"); + materialsRegistry.putIfEnumExists("acacia wood stairs", "ACACIA_STAIRS"); + materialsRegistry.putIfEnumExists("dark oak wood stairs", "DARK_OAK_STAIRS"); + materialsRegistry.putIfEnumExists("wood slab", "WOOD_STEP"); + materialsRegistry.putIfEnumExists("double wood slab", "WOOD_DOUBLE_STEP"); + materialsRegistry.putIfEnumExists("repeater", "DIODE"); + materialsRegistry.putIfEnumExists("piston", "PISTON_BASE"); + materialsRegistry.putIfEnumExists("sticky piston", "PISTON_STICKY_BASE"); + materialsRegistry.putIfEnumExists("flower pot", "FLOWER_POT_ITEM"); + materialsRegistry.putIfEnumExists("wood showel", "WOOD_SPADE"); + materialsRegistry.putIfEnumExists("stone showel", "STONE_SPADE"); + materialsRegistry.putIfEnumExists("gold showel", "GOLD_SPADE"); + materialsRegistry.putIfEnumExists("iron showel", "IRON_SPADE"); + materialsRegistry.putIfEnumExists("diamond showel", "DIAMOND_SPADE"); + materialsRegistry.putIfEnumExists("steak", "COOKED_BEEF"); + materialsRegistry.putIfEnumExists("cooked porkchop", "GRILLED_PORK"); + materialsRegistry.putIfEnumExists("raw porkchop", "PORK"); + materialsRegistry.putIfEnumExists("hardened clay", "HARD_CLAY"); + materialsRegistry.putIfEnumExists("huge brown mushroom", "HUGE_MUSHROOM_1"); + materialsRegistry.putIfEnumExists("huge red mushroom", "HUGE_MUSHROOM_2"); + materialsRegistry.putIfEnumExists("mycelium", "MYCEL"); + materialsRegistry.putIfEnumExists("poppy", "RED_ROSE"); + materialsRegistry.putIfEnumExists("comparator", "REDSTONE_COMPARATOR"); + materialsRegistry.putIfEnumExists("skull", "SKULL_ITEM"); + materialsRegistry.putIfEnumExists("head", "SKULL_ITEM"); + materialsRegistry.putIfEnumExists("redstone torch", "REDSTONE_TORCH_ON"); + materialsRegistry.putIfEnumExists("redstone lamp", "REDSTONE_LAMP_OFF"); + materialsRegistry.putIfEnumExists("glistering melon", "SPECKLED_MELON"); + materialsRegistry.putIfEnumExists("acacia leaves", "LEAVES_2"); + materialsRegistry.putIfEnumExists("acacia log", "LOG_2"); + materialsRegistry.putIfEnumExists("gunpowder", "SULPHUR"); + materialsRegistry.putIfEnumExists("lilypad", "WATER_LILY"); + materialsRegistry.putIfEnumExists("command block", "COMMAND"); + materialsRegistry.putIfEnumExists("dye", "INK_SACK"); + + return materialsRegistry; + } + + public static Material matchMaterial(String materialName) { + return MATERIALS_REGISTRY.find(materialName); + } + + public static String formatMaterial(Material material) { + return StringUtils.capitalizeFully(material.toString().replace("_", " ")); + } + + private static Collection getExistingMaterials(String... materialEnumNames) { + Collection existingMaterials = new HashSet<>(); + + for (String materialEnumName : materialEnumNames) { + try { + existingMaterials.add(Material.valueOf(materialEnumName)); + } catch (IllegalArgumentException e) { + // Ignore, not existing + } + } + + return existingMaterials; + } + + public static boolean isAir(Material material) { + return AIR_MATERIALS.contains(material); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java deleted file mode 100644 index 46602e4..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.util; - -import org.bukkit.Material; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; - -public final class MaterialsRegistry { - - // Material names have been changed in 1.13, when dolphins were added - private static final boolean USE_NEW_MATERIAL_NAMES = Utils.isClassLoaded("org.bukkit.entity.Dolphin"); - - // Characters to ignore when searching materials by name - private static final char[] IGNORE_CHARS = {'-', '_', ' '}; - - // Default material names are ugly - private static final Map MATERIALS_BY_ALIAS = initMaterialsByAlias(); - - // Materials that are considered air (with 1.13+ compatibility) - private static final Collection AIR_MATERIALS = getExistingMaterials("AIR", "CAVE_AIR", "VOID_AIR"); - - private MaterialsRegistry() {} - - @SuppressWarnings("deprecation") - private static Map initMaterialsByAlias() { - Map materialsByAlias = new HashMap<>(); - - for (Material material : Material.values()) { - addMaterialAlias(materialsByAlias, material.toString(), material); - - if (!USE_NEW_MATERIAL_NAMES) { - // Add numerical IDs in versions before 1.13 - addMaterialAlias(materialsByAlias, String.valueOf(material.getId()), material); - } - } - - // Add some default useful aliases (when present) - tryAddMaterialAlias(materialsByAlias, "iron bar", "IRON_FENCE"); - tryAddMaterialAlias(materialsByAlias, "iron bars", "IRON_FENCE"); - tryAddMaterialAlias(materialsByAlias, "glass pane", "THIN_GLASS"); - tryAddMaterialAlias(materialsByAlias, "nether wart", "NETHER_STALK"); - tryAddMaterialAlias(materialsByAlias, "nether warts", "NETHER_STALK"); - tryAddMaterialAlias(materialsByAlias, "slab", "STEP"); - tryAddMaterialAlias(materialsByAlias, "double slab", "DOUBLE_STEP"); - tryAddMaterialAlias(materialsByAlias, "stone brick", "SMOOTH_BRICK"); - tryAddMaterialAlias(materialsByAlias, "stone bricks", "SMOOTH_BRICK"); - tryAddMaterialAlias(materialsByAlias, "stone stair", "SMOOTH_STAIRS"); - tryAddMaterialAlias(materialsByAlias, "stone stairs", "SMOOTH_STAIRS"); - tryAddMaterialAlias(materialsByAlias, "potato", "POTATO_ITEM"); - tryAddMaterialAlias(materialsByAlias, "carrot", "CARROT_ITEM"); - tryAddMaterialAlias(materialsByAlias, "brewing stand", "BREWING_STAND_ITEM"); - tryAddMaterialAlias(materialsByAlias, "cauldron", "CAULDRON_ITEM"); - tryAddMaterialAlias(materialsByAlias, "carrot on stick", "CARROT_STICK"); - tryAddMaterialAlias(materialsByAlias, "carrot on a stick", "CARROT_STICK"); - tryAddMaterialAlias(materialsByAlias, "cobblestone wall", "COBBLE_WALL"); - tryAddMaterialAlias(materialsByAlias, "acacia wood stairs", "ACACIA_STAIRS"); - tryAddMaterialAlias(materialsByAlias, "dark oak wood stairs", "DARK_OAK_STAIRS"); - tryAddMaterialAlias(materialsByAlias, "wood slab", "WOOD_STEP"); - tryAddMaterialAlias(materialsByAlias, "double wood slab", "WOOD_DOUBLE_STEP"); - tryAddMaterialAlias(materialsByAlias, "repeater", "DIODE"); - tryAddMaterialAlias(materialsByAlias, "piston", "PISTON_BASE"); - tryAddMaterialAlias(materialsByAlias, "sticky piston", "PISTON_STICKY_BASE"); - tryAddMaterialAlias(materialsByAlias, "flower pot", "FLOWER_POT_ITEM"); - tryAddMaterialAlias(materialsByAlias, "wood showel", "WOOD_SPADE"); - tryAddMaterialAlias(materialsByAlias, "stone showel", "STONE_SPADE"); - tryAddMaterialAlias(materialsByAlias, "gold showel", "GOLD_SPADE"); - tryAddMaterialAlias(materialsByAlias, "iron showel", "IRON_SPADE"); - tryAddMaterialAlias(materialsByAlias, "diamond showel", "DIAMOND_SPADE"); - tryAddMaterialAlias(materialsByAlias, "steak", "COOKED_BEEF"); - tryAddMaterialAlias(materialsByAlias, "cooked porkchop", "GRILLED_PORK"); - tryAddMaterialAlias(materialsByAlias, "raw porkchop", "PORK"); - tryAddMaterialAlias(materialsByAlias, "hardened clay", "HARD_CLAY"); - tryAddMaterialAlias(materialsByAlias, "huge brown mushroom", "HUGE_MUSHROOM_1"); - tryAddMaterialAlias(materialsByAlias, "huge red mushroom", "HUGE_MUSHROOM_2"); - tryAddMaterialAlias(materialsByAlias, "mycelium", "MYCEL"); - tryAddMaterialAlias(materialsByAlias, "poppy", "RED_ROSE"); - tryAddMaterialAlias(materialsByAlias, "comparator", "REDSTONE_COMPARATOR"); - tryAddMaterialAlias(materialsByAlias, "skull", "SKULL_ITEM"); - tryAddMaterialAlias(materialsByAlias, "head", "SKULL_ITEM"); - tryAddMaterialAlias(materialsByAlias, "redstone torch", "REDSTONE_TORCH_ON"); - tryAddMaterialAlias(materialsByAlias, "redstone lamp", "REDSTONE_LAMP_OFF"); - tryAddMaterialAlias(materialsByAlias, "glistering melon", "SPECKLED_MELON"); - tryAddMaterialAlias(materialsByAlias, "acacia leaves", "LEAVES_2"); - tryAddMaterialAlias(materialsByAlias, "acacia log", "LOG_2"); - tryAddMaterialAlias(materialsByAlias, "gunpowder", "SULPHUR"); - tryAddMaterialAlias(materialsByAlias, "lilypad", "WATER_LILY"); - tryAddMaterialAlias(materialsByAlias, "command block", "COMMAND"); - tryAddMaterialAlias(materialsByAlias, "dye", "INK_SACK"); - - return materialsByAlias; - } - - private static void tryAddMaterialAlias(Map materialsByAlias, String name, String materialEnumName) { - try { - addMaterialAlias(materialsByAlias, name, Material.valueOf(materialEnumName)); - } catch (IllegalArgumentException e) { - // Ignore, do not add a new alias - } - } - - private static void addMaterialAlias(Map materialsByAlias, String name, Material material) { - materialsByAlias.put(StringUtils.stripChars(name, IGNORE_CHARS).toLowerCase(), material); - } - - public static Material matchMaterial(String alias) { - if (alias == null) { - return null; - } - - return MATERIALS_BY_ALIAS.get(StringUtils.stripChars(alias, IGNORE_CHARS).toLowerCase()); - } - - public static String formatMaterial(Material material) { - return StringUtils.capitalizeFully(material.toString().replace("_", " ")); - } - - private static Collection getExistingMaterials(String... materialEnumNames) { - Collection existingMaterials = new HashSet<>(); - - for (String materialEnumName : materialEnumNames) { - try { - existingMaterials.add(Material.valueOf(materialEnumName)); - } catch (IllegalArgumentException e) { - // Ignore, not existing - } - } - - return existingMaterials; - } - - public static boolean isAir(Material material) { - return AIR_MATERIALS.contains(material); - } - -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Registry.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Registry.java new file mode 100644 index 0000000..90465c2 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Registry.java @@ -0,0 +1,90 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.util; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +public class Registry { + + // Characters to ignore when searching enums by name + private static final char[] KEY_IGNORE_CHARS = {'-', '_', ' '}; + + private final Class valuesType; + private final Map valuesMap; + + + + public static > Registry fromEnumValues(Class enumClass) { + Registry registry = new Registry<>(enumClass); + registry.putAll(enumClass.getEnumConstants(), Enum::name); + return registry; + } + + + public static Registry fromValues(X[] values, Function toKeyFunction) { + Registry registry = new Registry<>(null); + registry.putAll(values, toKeyFunction); + return registry; + } + + + private Registry(Class valuesType) { + this.valuesType = valuesType; + this.valuesMap = new HashMap<>(); + } + + public T find(String key) { + if (key == null) { + return null; + } + return valuesMap.get(toKeyFormat(key)); + } + + public void putIfEnumExists(String key, String enumValueName) { + if (!valuesType.isEnum()) { + throw new IllegalArgumentException("Value type is not an enum"); + } + + try { + @SuppressWarnings({ "unchecked", "rawtypes" }) + T enumValue = (T) Enum.valueOf((Class) valuesType, enumValueName); + put(key, enumValue); + } catch (IllegalArgumentException e) { + // Ignore, enum value doesn't exist + } + } + + public void putAll(T[] enumValues, Function toKeyFunction) { + for (T enumValue : enumValues) { + valuesMap.put(toKeyFormat(toKeyFunction.apply(enumValue)), enumValue); + } + } + + public void put(String key, T enumValue) { + valuesMap.put(toKeyFormat(key), enumValue); + } + + private String toKeyFormat(String enumValueName) { + return StringUtils.stripChars(enumValueName, KEY_IGNORE_CHARS).toLowerCase(); + } + + @Override + public String toString() { + return "Registry [type=" + valuesType + ", values=" + valuesMap + "]"; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java index c7ca72f..4b0cb2c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java @@ -16,16 +16,7 @@ package me.filoghost.chestcommands.util; public final class StringUtils { - private StringUtils() { - } - - public static String stripChars(String input, String removed) { - if (removed == null || removed.isEmpty()) { - return input; - } - - return stripChars(input, removed.toCharArray()); - } + private StringUtils() {} // Removes the first slash, and returns the all the chars until a space is encontered public static String getCleanCommand(String message) { From 15a6774acefc3b78e558edd41caab94405074af0 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 11:55:09 +0200 Subject: [PATCH 024/213] Refactoring --- .../listener/CommandListener.java | 31 +++++++++++++------ .../chestcommands/util/StringUtils.java | 19 ------------ 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java index d10f92b..cd18f1d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java @@ -21,7 +21,6 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.internal.ExtendedIconMenu; -import me.filoghost.chestcommands.util.StringUtils; public class CommandListener implements Listener { @@ -33,18 +32,32 @@ public class CommandListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onCommand(PlayerCommandPreprocessEvent event) { - // Very fast method compared to split & substring - String command = StringUtils.getCleanCommand(event.getMessage()); - - if (command.isEmpty()) { + String command = getCommandName(event.getMessage()); + + if (command == null) { return; } ExtendedIconMenu menu = menuManager.getMenuByCommand(command); - - if (menu != null) { - event.setCancelled(true); - menu.openCheckingPermission(event.getPlayer()); + + if (menu == null) { + return; + } + + event.setCancelled(true); + menu.openCheckingPermission(event.getPlayer()); + } + + private static String getCommandName(String fullCommand) { + if (!fullCommand.startsWith("/")) { + return null; + } + + int firstSpace = fullCommand.indexOf(' '); + if (firstSpace >= 1) { + return fullCommand.substring(1, firstSpace); + } else { + return fullCommand.substring(1); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java index 4b0cb2c..3d31cff 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java @@ -18,25 +18,6 @@ public final class StringUtils { private StringUtils() {} - // Removes the first slash, and returns the all the chars until a space is encontered - public static String getCleanCommand(String message) { - char[] chars = message.toCharArray(); - - if (chars.length <= 1) { - return ""; - } - - int pos = 0; - for (int i = 1; i < chars.length; i++) { - if (chars[i] == ' ') { - break; - } - - chars[(pos++)] = chars[i]; - } - - return new String(chars, 0, pos); - } public static String stripChars(String input, char... removed) { if (input == null || input.isEmpty() || removed.length == 0) { From d4d3df1232bbf54ed68fe18bb5efd3716b970a7a Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 11:56:57 +0200 Subject: [PATCH 025/213] Cleanup Registry --- .../java/me/filoghost/chestcommands/util/Registry.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Registry.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Registry.java index 90465c2..98dc8cc 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Registry.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Registry.java @@ -28,15 +28,15 @@ public class Registry { - public static > Registry fromEnumValues(Class enumClass) { - Registry registry = new Registry<>(enumClass); + public static > Registry fromEnumValues(Class enumClass) { + Registry registry = new Registry<>(enumClass); registry.putAll(enumClass.getEnumConstants(), Enum::name); return registry; } - public static Registry fromValues(X[] values, Function toKeyFunction) { - Registry registry = new Registry<>(null); + public static Registry fromValues(T[] values, Function toKeyFunction) { + Registry registry = new Registry<>(null); registry.putAll(values, toKeyFunction); return registry; } @@ -68,7 +68,7 @@ public class Registry { } } - public void putAll(T[] enumValues, Function toKeyFunction) { + private void putAll(T[] enumValues, Function toKeyFunction) { for (T enumValue : enumValues) { valuesMap.put(toKeyFormat(toKeyFunction.apply(enumValue)), enumValue); } From 3fc9ad62d899932863e3c7b29d72427af21bdd71 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 11:59:18 +0200 Subject: [PATCH 026/213] Remove console colors option --- .../me/filoghost/chestcommands/ChestCommands.java | 14 ++++---------- .../filoghost/chestcommands/config/Settings.java | 1 - 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index b40eb75..d03f201 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -100,16 +100,10 @@ public class ChestCommands extends JavaPlugin { if (settings.update_notifications) { UpdateChecker.run(this, 56919, (String newVersion) -> { ChestCommands.newVersion = newVersion; - - if (settings.use_console_colors) { - Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + "Found a new version: " + newVersion + ChatColor.WHITE + " (yours: v" + getDescription().getVersion() + ")"); - Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + ChatColor.WHITE + "Download it on Bukkit Dev:"); - Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + ChatColor.WHITE + "https://dev.bukkit.org/projects/chest-commands"); - } else { - getLogger().info("Found a new version available: " + newVersion); - getLogger().info("Download it on Bukkit Dev:"); - getLogger().info("https://dev.bukkit.org/projects/chest-commands"); - } + + getLogger().info("Found a new version: " + newVersion + " (yours: v" + getDescription().getVersion() + ")"); + getLogger().info("Download the update on Bukkit Dev:"); + getLogger().info("https://dev.bukkit.org/projects/chest-commands"); }); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java index 4f9be98..0026e1d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java @@ -19,7 +19,6 @@ import me.filoghost.chestcommands.config.yaml.SpecialConfig; public class Settings extends SpecialConfig { - public boolean use_console_colors = true; public String default_color__name = "&f"; public String default_color__lore = "&7"; public String multiple_commands_separator = ";"; From 40f0851884e492a8d0e87bec872d18b99bc6559f Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 12:23:15 +0200 Subject: [PATCH 027/213] Refactoring --- .../chestcommands/ChestCommands.java | 10 +--- .../filoghost/chestcommands/MenuManager.java | 57 +++++++++++++++++++ .../chestcommands/bridge/EconomyBridge.java | 10 ++-- .../chestcommands/internal/ExtendedIcon.java | 18 ++---- .../chestcommands/task/RefreshMenusTask.java | 29 +++------- .../chestcommands/util/MenuUtils.java | 28 --------- 6 files changed, 75 insertions(+), 77 deletions(-) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/util/MenuUtils.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index d03f201..19931d3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -23,7 +23,6 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryView; import org.bukkit.plugin.java.JavaPlugin; import me.filoghost.chestcommands.bridge.BarAPIBridge; @@ -38,7 +37,6 @@ import me.filoghost.chestcommands.config.yaml.PluginConfig; import me.filoghost.chestcommands.internal.BoundItem; import me.filoghost.chestcommands.internal.ExtendedIconMenu; import me.filoghost.chestcommands.internal.MenuData; -import me.filoghost.chestcommands.internal.MenuInventoryHolder; import me.filoghost.chestcommands.listener.CommandListener; import me.filoghost.chestcommands.listener.InventoryListener; import me.filoghost.chestcommands.listener.JoinListener; @@ -247,12 +245,8 @@ public class ChestCommands extends JavaPlugin { public static void closeAllMenus() { for (Player player : Bukkit.getOnlinePlayers()) { - InventoryView openInventory = player.getOpenInventory(); - if (openInventory != null) { - if (openInventory.getTopInventory().getHolder() instanceof MenuInventoryHolder - || openInventory.getBottomInventory().getHolder() instanceof MenuInventoryHolder) { - player.closeInventory(); - } + if (MenuManager.getOpenMenu(player) != null) { + player.closeInventory(); } } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java index f9f783f..8aef9da 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java @@ -23,6 +23,7 @@ import java.util.Set; import org.bukkit.entity.Player; import org.bukkit.event.block.Action; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; import me.filoghost.chestcommands.api.IconMenu; @@ -101,5 +102,61 @@ public class MenuManager { } + public static void refreshOpenMenu(Player player) { + MenuView openMenu = getOpenMenu(player); + if (openMenu != null) { + openMenu.getMenu().refresh(player, openMenu.getInventory()); + } + } + + + public static MenuView getOpenMenu(Player player) { + InventoryView view = player.getOpenInventory(); + if (view == null) { + return null; + } + + MenuView openMenu = getOpenMenu(view.getTopInventory()); + if (openMenu == null) { + openMenu = getOpenMenu(view.getBottomInventory()); + } + + return openMenu; + } + + + private static MenuView getOpenMenu(Inventory inventory) { + if (!(inventory.getHolder() instanceof MenuInventoryHolder)) { + return null; + } + + MenuInventoryHolder menuInventoryHolder = (MenuInventoryHolder) inventory.getHolder(); + if (!(menuInventoryHolder.getIconMenu() instanceof ExtendedIconMenu)) { + return null; + } + + return new MenuView((ExtendedIconMenu) menuInventoryHolder.getIconMenu(), inventory); + } + + + public static class MenuView { + + private final ExtendedIconMenu menu; + private final Inventory inventory; + + public MenuView(ExtendedIconMenu menu, Inventory inventory) { + this.menu = menu; + this.inventory = inventory; + } + + public ExtendedIconMenu getMenu() { + return menu; + } + + public Inventory getInventory() { + return inventory; + } + + } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java index 9a63553..c0d68eb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java @@ -14,13 +14,13 @@ */ package me.filoghost.chestcommands.bridge; -import net.milkbowl.vault.economy.Economy; -import net.milkbowl.vault.economy.EconomyResponse; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.RegisteredServiceProvider; -import me.filoghost.chestcommands.util.MenuUtils; +import me.filoghost.chestcommands.MenuManager; +import net.milkbowl.vault.economy.Economy; +import net.milkbowl.vault.economy.EconomyResponse; public class EconomyBridge { @@ -70,7 +70,7 @@ public class EconomyBridge { EconomyResponse response = economy.withdrawPlayer(player, player.getWorld().getName(), amount); boolean result = response.transactionSuccess(); - MenuUtils.refreshMenu(player); + MenuManager.refreshOpenMenu(player); return result; } @@ -82,7 +82,7 @@ public class EconomyBridge { EconomyResponse response = economy.depositPlayer(player, player.getWorld().getName(), amount); boolean result = response.transactionSuccess(); - MenuUtils.refreshMenu(player); + MenuManager.refreshOpenMenu(player); return result; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java index 85e0b31..b5fac25 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java @@ -16,10 +16,8 @@ package me.filoghost.chestcommands.internal; import org.bukkit.ChatColor; import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryView; - import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.bridge.EconomyBridge; import me.filoghost.chestcommands.util.MaterialsHelper; @@ -132,10 +130,12 @@ public class ExtendedIcon extends Icon { this.requiredItems = requiredItems; } + @Override public String calculateName(Player pov) { return super.calculateName(pov); } + @Override public List calculateLore(Player pov) { return super.calculateLore(pov); } @@ -213,17 +213,7 @@ public class ExtendedIcon extends Icon { } if (changedVariables) { - InventoryView view = player.getOpenInventory(); - if (view != null) { - Inventory topInventory = view.getTopInventory(); - if (topInventory.getHolder() instanceof MenuInventoryHolder) { - MenuInventoryHolder menuHolder = (MenuInventoryHolder) topInventory.getHolder(); - - if (menuHolder.getIconMenu() instanceof ExtendedIconMenu) { - ((ExtendedIconMenu) menuHolder.getIconMenu()).refresh(player, topInventory); - } - } - } + MenuManager.refreshOpenMenu(player); } return super.onClick(player); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java index 53d97f1..13cdbde 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java @@ -16,11 +16,8 @@ package me.filoghost.chestcommands.task; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryView; - -import me.filoghost.chestcommands.internal.ExtendedIconMenu; -import me.filoghost.chestcommands.internal.MenuInventoryHolder; +import me.filoghost.chestcommands.MenuManager; +import me.filoghost.chestcommands.MenuManager.MenuView; public class RefreshMenusTask implements Runnable { @@ -30,25 +27,13 @@ public class RefreshMenusTask implements Runnable { public void run() { for (Player player : Bukkit.getOnlinePlayers()) { - - InventoryView view = player.getOpenInventory(); - if (view == null) { + MenuView openMenu = MenuManager.getOpenMenu(player); + if (openMenu == null) { return; } - - Inventory topInventory = view.getTopInventory(); - if (topInventory.getHolder() instanceof MenuInventoryHolder) { - MenuInventoryHolder menuHolder = (MenuInventoryHolder) topInventory.getHolder(); - - if (menuHolder.getIconMenu() instanceof ExtendedIconMenu) { - ExtendedIconMenu extMenu = (ExtendedIconMenu) menuHolder.getIconMenu(); - - if (extMenu.getRefreshTicks() > 0) { - if (elapsedTenths % extMenu.getRefreshTicks() == 0) { - extMenu.refresh(player, topInventory); - } - } - } + + if (elapsedTenths % openMenu.getMenu().getRefreshTicks() == 0) { + openMenu.getMenu().refresh(player, openMenu.getInventory()); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/MenuUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/MenuUtils.java deleted file mode 100644 index 2ec1251..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/MenuUtils.java +++ /dev/null @@ -1,28 +0,0 @@ -package me.filoghost.chestcommands.util; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryView; - -import me.filoghost.chestcommands.internal.ExtendedIconMenu; -import me.filoghost.chestcommands.internal.MenuInventoryHolder; - -public final class MenuUtils { - - private MenuUtils() { - } - - public static void refreshMenu(Player player) { - InventoryView view = player.getOpenInventory(); - if (view != null) { - Inventory topInventory = view.getTopInventory(); - if (topInventory.getHolder() instanceof MenuInventoryHolder) { - MenuInventoryHolder menuHolder = (MenuInventoryHolder) topInventory.getHolder(); - - if (menuHolder.getIconMenu() instanceof ExtendedIconMenu) { - ((ExtendedIconMenu) menuHolder.getIconMenu()).refresh(player, topInventory); - } - } - } - } -} From e5135056636aaa20fbbeeace2e1d9c259d3c3175 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 12:24:02 +0200 Subject: [PATCH 028/213] Cleanup --- Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java | 1 - .../java/me/filoghost/chestcommands/bridge/BarAPIBridge.java | 1 + .../java/me/filoghost/chestcommands/command/CommandHandler.java | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java index 96d9559..146c078 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java @@ -25,7 +25,6 @@ import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.inventory.meta.SkullMeta; import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.util.Utils; import me.filoghost.chestcommands.variable.VariableManager; import java.util.ArrayList; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/BarAPIBridge.java b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/BarAPIBridge.java index ed248f9..eb944e8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/BarAPIBridge.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/BarAPIBridge.java @@ -38,6 +38,7 @@ public class BarAPIBridge { return barAPI != null; } + @SuppressWarnings("deprecation") public static void setMessage(Player player, String message, int seconds) { if (!hasValidPlugin()) throw new IllegalStateException("BarAPI plugin was not found!"); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index a67a21a..eccf3a8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -37,6 +37,7 @@ public class CommandHandler extends CommandFramework { this.menuManager = menuManager; } + @SuppressWarnings("deprecation") @Override public void execute(CommandSender sender, String label, String[] args) { if (args.length == 0) { From d4463e699438037163f5de7f8672a9bd15fb75de Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 12:38:31 +0200 Subject: [PATCH 029/213] Refactoring --- .../filoghost/chestcommands/MenuManager.java | 44 +++++++++++++------ .../internal/MenuInventoryHolder.java | 8 +--- .../listener/InventoryListener.java | 2 +- .../chestcommands/task/RefreshMenusTask.java | 9 ++-- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java index 8aef9da..92dbabf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java @@ -84,14 +84,6 @@ public class MenuManager { } } } - - public IconMenu getIconMenu(Inventory inventory) { - if (inventory.getHolder() instanceof MenuInventoryHolder) { - return ((MenuInventoryHolder) inventory.getHolder()).getIconMenu(); - } else { - return null; - } - } public ExtendedIconMenu getMenuByCommand(String command) { return commandsToMenuMap.get(command); @@ -103,20 +95,20 @@ public class MenuManager { public static void refreshOpenMenu(Player player) { - MenuView openMenu = getOpenMenu(player); - if (openMenu != null) { - openMenu.getMenu().refresh(player, openMenu.getInventory()); + MenuView openMenuView = getOpenMenuView(player); + if (openMenuView != null) { + openMenuView.getMenu().refresh(player, openMenuView.getInventory()); } } - public static MenuView getOpenMenu(Player player) { + public static IconMenu getOpenMenu(Player player) { InventoryView view = player.getOpenInventory(); if (view == null) { return null; } - MenuView openMenu = getOpenMenu(view.getTopInventory()); + IconMenu openMenu = getOpenMenu(view.getTopInventory()); if (openMenu == null) { openMenu = getOpenMenu(view.getBottomInventory()); } @@ -125,7 +117,31 @@ public class MenuManager { } - private static MenuView getOpenMenu(Inventory inventory) { + public static IconMenu getOpenMenu(Inventory inventory) { + if (!(inventory.getHolder() instanceof MenuInventoryHolder)) { + return null; + } + + return ((MenuInventoryHolder) inventory.getHolder()).getIconMenu(); + } + + + public static MenuView getOpenMenuView(Player player) { + InventoryView view = player.getOpenInventory(); + if (view == null) { + return null; + } + + MenuView openMenuView = getOpenMenuView(view.getTopInventory()); + if (openMenuView == null) { + openMenuView = getOpenMenuView(view.getBottomInventory()); + } + + return openMenuView; + } + + + private static MenuView getOpenMenuView(Inventory inventory) { if (!(inventory.getHolder() instanceof MenuInventoryHolder)) { return null; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java index 37b15bf..e44de40 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java @@ -19,14 +19,13 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import me.filoghost.chestcommands.api.IconMenu; -import me.filoghost.chestcommands.util.Validate; /** * This class links an IconMenu with an Inventory, via InventoryHolder. */ public class MenuInventoryHolder implements InventoryHolder { - private IconMenu iconMenu; + private final IconMenu iconMenu; public MenuInventoryHolder(IconMenu iconMenu) { this.iconMenu = iconMenu; @@ -47,9 +46,4 @@ public class MenuInventoryHolder implements InventoryHolder { return iconMenu; } - public void setIconMenu(IconMenu iconMenu) { - Validate.notNull(iconMenu, "IconMenu cannot be null"); - this.iconMenu = iconMenu; - } - } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index 3ae3667..ef46cdf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -52,7 +52,7 @@ public class InventoryListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false) public void onInventoryClick(InventoryClickEvent event) { - IconMenu menu = menuManager.getIconMenu(event.getInventory()); + IconMenu menu = MenuManager.getOpenMenu(event.getInventory()); if (menu == null) { return; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java index 13cdbde..6cccad1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java @@ -25,15 +25,14 @@ public class RefreshMenusTask implements Runnable { @Override public void run() { - for (Player player : Bukkit.getOnlinePlayers()) { - MenuView openMenu = MenuManager.getOpenMenu(player); - if (openMenu == null) { + MenuView openMenuView = MenuManager.getOpenMenuView(player); + if (openMenuView == null) { return; } - if (elapsedTenths % openMenu.getMenu().getRefreshTicks() == 0) { - openMenu.getMenu().refresh(player, openMenu.getInventory()); + if (elapsedTenths % openMenuView.getMenu().getRefreshTicks() == 0) { + openMenuView.getMenu().refresh(player, openMenuView.getInventory()); } } From 98ee458bc093d1343150f08bfc7b35ea501877ec Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 12:52:39 +0200 Subject: [PATCH 030/213] Use two separate listener levels for InventoryClickEvent --- .../listener/InventoryListener.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index ef46cdf..0af02e0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -49,15 +49,27 @@ public class InventoryListener implements Listener { menuManager.openMenuByItem(event.getPlayer(), event.getItem(), event.getAction()); } } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false) - public void onInventoryClick(InventoryClickEvent event) { + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) + public void onEarlyInventoryClick(InventoryClickEvent event) { IconMenu menu = MenuManager.getOpenMenu(event.getInventory()); if (menu == null) { return; } - event.setCancelled(true); // First thing to do, if an exception is thrown at least the player doesn't take the item + // Cancel the event as early as possible + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) + public void onLateInventoryClick(InventoryClickEvent event) { + IconMenu menu = MenuManager.getOpenMenu(event.getInventory()); + if (menu == null) { + return; + } + + // Make sure the event is still cancelled (in case another plugin wrongly uncancels it) + event.setCancelled(true); int slot = event.getRawSlot(); if (slot < 0 || slot >= menu.getSize()) { From 85bdcd64082dda25052940bfd16fce8491a3c5cd Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 12:55:00 +0200 Subject: [PATCH 031/213] Refactoring --- .../listener/InventoryListener.java | 11 +++-- .../task/ExecuteActionsTask.java | 43 ------------------- 2 files changed, 8 insertions(+), 46 deletions(-) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/task/ExecuteActionsTask.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index 0af02e0..d93b9f3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -28,7 +28,6 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.api.IconMenu; -import me.filoghost.chestcommands.task.ExecuteActionsTask; import java.util.HashMap; import java.util.Map; @@ -95,8 +94,14 @@ public class InventoryListener implements Listener { } } - // Closes the inventory and executes actions AFTER the event - Bukkit.getScheduler().runTask(ChestCommands.getInstance(), new ExecuteActionsTask(clicker, icon)); + // Only handle the click AFTER the event has finished + Bukkit.getScheduler().runTask(ChestCommands.getInstance(), () -> { + boolean close = icon.onClick(clicker); + + if (close) { + clicker.closeInventory(); + } + }); } @EventHandler diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/ExecuteActionsTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/ExecuteActionsTask.java deleted file mode 100644 index ac6e403..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/ExecuteActionsTask.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.task; - -import org.bukkit.entity.Player; - -import me.filoghost.chestcommands.api.Icon; - -public class ExecuteActionsTask implements Runnable { - - private Player player; - private Icon icon; - - - public ExecuteActionsTask(Player player, Icon icon) { - this.player = player; - this.icon = icon; - } - - - @Override - public void run() { - boolean close = icon.onClick(player); - - if (close) { - player.closeInventory(); - } - } - - -} From 8dc0a5dcdd1ff963540fe1dcaa40ae18baabebc7 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 12:57:12 +0200 Subject: [PATCH 032/213] Rename MenuData to MenuSettings --- .../chestcommands/ChestCommands.java | 4 ++-- .../{MenuData.java => MenuSettings.java} | 19 ++++++++++--------- .../chestcommands/parser/MenuParser.java | 6 +++--- 3 files changed, 15 insertions(+), 14 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/internal/{MenuData.java => MenuSettings.java} (89%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 19931d3..00b9f63 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -36,7 +36,7 @@ import me.filoghost.chestcommands.config.Settings; import me.filoghost.chestcommands.config.yaml.PluginConfig; import me.filoghost.chestcommands.internal.BoundItem; import me.filoghost.chestcommands.internal.ExtendedIconMenu; -import me.filoghost.chestcommands.internal.MenuData; +import me.filoghost.chestcommands.internal.MenuSettings; import me.filoghost.chestcommands.listener.CommandListener; import me.filoghost.chestcommands.listener.InventoryListener; import me.filoghost.chestcommands.listener.JoinListener; @@ -198,7 +198,7 @@ public class ChestCommands extends JavaPlugin { continue; } - MenuData data = MenuParser.loadMenuData(menuConfig, errorCollector); + MenuSettings data = MenuParser.loadMenuData(menuConfig, errorCollector); ExtendedIconMenu iconMenu = MenuParser.loadMenu(menuConfig, data.getTitle(), data.getRows(), errorCollector); menuManager.registerMenu(menuConfig.getFileName(), data.getCommands(), iconMenu, errorCollector); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuData.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuSettings.java similarity index 89% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuData.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuSettings.java index d2945f3..bfb295e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuData.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuSettings.java @@ -20,21 +20,22 @@ import me.filoghost.chestcommands.action.Action; import java.util.List; -public class MenuData { +public class MenuSettings { - // Required data - private String title; - private int rows; + // Required settings + private final String title; + private final int rows; - // Optional data + // Optional settings private String[] commands; - private Material boundMaterial; - private short boundDataValue; - private ClickType clickType; private List openActions; private int refreshTenths; - public MenuData(String title, int rows) { + private Material boundMaterial; + private short boundDataValue; + private ClickType clickType; + + public MenuSettings(String title, int rows) { this.title = title; this.rows = rows; boundDataValue = -1; // -1 = any diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java index 5417d82..15410c4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java @@ -28,7 +28,7 @@ import me.filoghost.chestcommands.config.yaml.PluginConfig; import me.filoghost.chestcommands.exception.FormatException; import me.filoghost.chestcommands.internal.ClickType; import me.filoghost.chestcommands.internal.ExtendedIconMenu; -import me.filoghost.chestcommands.internal.MenuData; +import me.filoghost.chestcommands.internal.MenuSettings; import me.filoghost.chestcommands.parser.IconParser.Coords; import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.FormatUtils; @@ -82,7 +82,7 @@ public class MenuParser { /** * Reads all the settings of a menu. It will never return a null title, even if not set. */ - public static MenuData loadMenuData(PluginConfig config, ErrorCollector errorCollector) { + public static MenuSettings loadMenuData(PluginConfig config, ErrorCollector errorCollector) { String title = FormatUtils.addColors(config.getString(Nodes.MENU_NAME)); int rows; @@ -108,7 +108,7 @@ public class MenuParser { errorCollector.addError("The menu \"" + config.getFileName() + "\" doesn't have a the number of rows set, it will have 6 rows by default."); } - MenuData menuData = new MenuData(title, rows); + MenuSettings menuData = new MenuSettings(title, rows); List triggeringCommands = ConfigUtil.getStringListOrInlineList(config, ";", Nodes.MENU_COMMANDS); if (triggeringCommands != null) { From c6461386d9338b8366f42e9fe3dcbf6b3d288a2b Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 13:53:57 +0200 Subject: [PATCH 033/213] Refactor BoundItem --- .../chestcommands/ChestCommands.java | 9 +--- .../filoghost/chestcommands/MenuManager.java | 23 +++++---- .../chestcommands/internal/MenuSettings.java | 48 ++++--------------- .../{BoundItem.java => OpenTrigger.java} | 33 ++++++------- .../chestcommands/parser/MenuParser.java | 28 ++++++----- 5 files changed, 53 insertions(+), 88 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/internal/{BoundItem.java => OpenTrigger.java} (65%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 00b9f63..64c6acb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -34,7 +34,6 @@ import me.filoghost.chestcommands.config.AsciiPlaceholders; import me.filoghost.chestcommands.config.Lang; import me.filoghost.chestcommands.config.Settings; import me.filoghost.chestcommands.config.yaml.PluginConfig; -import me.filoghost.chestcommands.internal.BoundItem; import me.filoghost.chestcommands.internal.ExtendedIconMenu; import me.filoghost.chestcommands.internal.MenuSettings; import me.filoghost.chestcommands.listener.CommandListener; @@ -209,12 +208,8 @@ public class ChestCommands extends JavaPlugin { iconMenu.setOpenActions(data.getOpenActions()); } - if (data.hasBoundMaterial() && data.getClickType() != null) { - BoundItem boundItem = new BoundItem(iconMenu, data.getBoundMaterial(), data.getClickType()); - if (data.hasBoundDataValue()) { - boundItem.setRestrictiveData(data.getBoundDataValue()); - } - menuManager.registerTriggerItem(boundItem); + if (data.getOpenTrigger() != null) { + menuManager.registerTriggerItem(data.getOpenTrigger(), iconMenu); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java index 92dbabf..9cfe029 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java @@ -16,9 +16,8 @@ package me.filoghost.chestcommands; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; +import java.util.HashMap; import java.util.Map; -import java.util.Set; import org.bukkit.entity.Player; import org.bukkit.event.block.Action; @@ -27,9 +26,9 @@ import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; import me.filoghost.chestcommands.api.IconMenu; -import me.filoghost.chestcommands.internal.BoundItem; import me.filoghost.chestcommands.internal.ExtendedIconMenu; import me.filoghost.chestcommands.internal.MenuInventoryHolder; +import me.filoghost.chestcommands.internal.OpenTrigger; import me.filoghost.chestcommands.util.CaseInsensitiveMap; import me.filoghost.chestcommands.util.ErrorCollector; @@ -38,18 +37,18 @@ public class MenuManager { private static Map fileNameToMenuMap; private static Map commandsToMenuMap; - private static Set boundItems; + private static Map openTriggers; public MenuManager() { fileNameToMenuMap = CaseInsensitiveMap.create(); commandsToMenuMap = CaseInsensitiveMap.create(); - boundItems = new HashSet<>(); + openTriggers = new HashMap<>(); } public void clear() { fileNameToMenuMap.clear(); commandsToMenuMap.clear(); - boundItems.clear(); + openTriggers.clear(); } public ExtendedIconMenu getMenuByFileName(String fileName) { @@ -73,16 +72,16 @@ public class MenuManager { } } - public void registerTriggerItem(BoundItem boundItem) { - boundItems.add(boundItem); + public void registerTriggerItem(OpenTrigger openTrigger, ExtendedIconMenu menu) { + openTriggers.put(openTrigger, menu); } public void openMenuByItem(Player player, ItemStack itemInHand, Action clickAction) { - for (BoundItem boundItem : boundItems) { - if (boundItem.isValidTrigger(itemInHand, clickAction)) { - boundItem.getMenu().openCheckingPermission(player); + openTriggers.forEach((openTrigger, menu) -> { + if (openTrigger.matches(itemInHand, clickAction)) { + menu.openCheckingPermission(player); } - } + }); } public ExtendedIconMenu getMenuByCommand(String command) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuSettings.java index bfb295e..756d1eb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuSettings.java @@ -14,8 +14,6 @@ */ package me.filoghost.chestcommands.internal; -import org.bukkit.Material; - import me.filoghost.chestcommands.action.Action; import java.util.List; @@ -31,14 +29,11 @@ public class MenuSettings { private List openActions; private int refreshTenths; - private Material boundMaterial; - private short boundDataValue; - private ClickType clickType; + private OpenTrigger openTrigger; public MenuSettings(String title, int rows) { this.title = title; this.rows = rows; - boundDataValue = -1; // -1 = any } public String getTitle() { @@ -61,38 +56,6 @@ public class MenuSettings { return commands; } - public boolean hasBoundMaterial() { - return boundMaterial != null; - } - - public Material getBoundMaterial() { - return boundMaterial; - } - - public void setBoundMaterial(Material boundMaterial) { - this.boundMaterial = boundMaterial; - } - - public boolean hasBoundDataValue() { - return boundDataValue > -1; - } - - public short getBoundDataValue() { - return boundDataValue; - } - - public void setBoundDataValue(short boundDataValue) { - this.boundDataValue = boundDataValue; - } - - public ClickType getClickType() { - return clickType; - } - - public void setClickType(ClickType clickType) { - this.clickType = clickType; - } - public List getOpenActions() { return openActions; } @@ -108,4 +71,13 @@ public class MenuSettings { public void setRefreshTenths(int refreshTenths) { this.refreshTenths = refreshTenths; } + + public OpenTrigger getOpenTrigger() { + return openTrigger; + } + + public void setOpenTrigger(OpenTrigger openTrigger) { + this.openTrigger = openTrigger; + } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BoundItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/OpenTrigger.java similarity index 65% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/BoundItem.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/OpenTrigger.java index 859c514..e940112 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BoundItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/OpenTrigger.java @@ -20,47 +20,44 @@ import org.bukkit.inventory.ItemStack; import me.filoghost.chestcommands.util.Validate; -public class BoundItem { +public class OpenTrigger { - private ExtendedIconMenu menu; private Material material; - private short data; private ClickType clickType; + private short durability; + private boolean isRestrictiveDurability; - public BoundItem(ExtendedIconMenu menu, Material material, ClickType clickType) { + public OpenTrigger(Material material, ClickType clickType) { Validate.notNull(material, "Material cannot be null"); Validate.notNull(material, "ClickType cannot be null"); Validate.isTrue(material != Material.AIR, "Material cannot be AIR"); - this.menu = menu; this.material = material; this.clickType = clickType; - data = -1; // -1 = any } - public void setRestrictiveData(short data) { - this.data = data; + public void setRestrictiveDurability(short durability) { + this.durability = durability; + this.isRestrictiveDurability = true; } - public ExtendedIconMenu getMenu() { - return menu; - } - - public boolean isValidTrigger(ItemStack item, Action action) { + public boolean matches(ItemStack item, Action action) { if (item == null) { return false; } - // First, they must have the same material if (this.material != item.getType()) { return false; } - // Check if the data value is valid (-1 = any data value) - if (this.data != -1 && this.data != item.getDurability()) { + + if (isRestrictiveDurability && this.durability != item.getDurability()) { return false; } - // Finally checks the action - return clickType.isValidInteract(action); + if (!clickType.isValidInteract(action)) { + return false; + } + + return true; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java index 15410c4..651f4cd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java @@ -29,6 +29,7 @@ import me.filoghost.chestcommands.exception.FormatException; import me.filoghost.chestcommands.internal.ClickType; import me.filoghost.chestcommands.internal.ExtendedIconMenu; import me.filoghost.chestcommands.internal.MenuSettings; +import me.filoghost.chestcommands.internal.OpenTrigger; import me.filoghost.chestcommands.parser.IconParser.Coords; import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.FormatUtils; @@ -133,22 +134,23 @@ public class MenuParser { String openItemMaterial = ConfigUtil.getAnyString(config, Nodes.OPEN_ITEM_MATERIAL); if (openItemMaterial != null) { - try { - ItemStackParser itemReader = new ItemStackParser(openItemMaterial, false); - menuData.setBoundMaterial(itemReader.getMaterial()); - - if (itemReader.hasExplicitDataValue()) { - menuData.setBoundDataValue(itemReader.getDataValue()); - } - } catch (FormatException e) { - errorCollector.addError("The item \"" + openItemMaterial + "\" used to open the menu \"" + config.getFileName() + "\" is invalid: " + e.getMessage()); - } - boolean leftClick = config.getBoolean(Nodes.OPEN_ITEM_LEFT_CLICK); boolean rightClick = config.getBoolean(Nodes.OPEN_ITEM_RIGHT_CLICK); - + if (leftClick || rightClick) { - menuData.setClickType(ClickType.fromOptions(leftClick, rightClick)); + try { + ItemStackParser itemReader = new ItemStackParser(openItemMaterial, false); + ClickType clickType = ClickType.fromOptions(leftClick, rightClick); + + OpenTrigger openTrigger = new OpenTrigger(itemReader.getMaterial(), clickType); + + if (itemReader.hasExplicitDataValue()) { + openTrigger.setRestrictiveDurability(itemReader.getDataValue()); + } + + } catch (FormatException e) { + errorCollector.addError("The item \"" + openItemMaterial + "\" used to open the menu \"" + config.getFileName() + "\" is invalid: " + e.getMessage()); + } } } From 0cb309d449000b449ced8ee5a07a5b92fbe54a81 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 13:57:40 +0200 Subject: [PATCH 034/213] Refactoring --- .../filoghost/chestcommands/ChestCommands.java | 16 ++++++++-------- .../chestcommands/parser/MenuParser.java | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 64c6acb..fd3c436 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -197,19 +197,19 @@ public class ChestCommands extends JavaPlugin { continue; } - MenuSettings data = MenuParser.loadMenuData(menuConfig, errorCollector); - ExtendedIconMenu iconMenu = MenuParser.loadMenu(menuConfig, data.getTitle(), data.getRows(), errorCollector); + MenuSettings menuSettings = MenuParser.loadMenuSettings(menuConfig, errorCollector); + ExtendedIconMenu iconMenu = MenuParser.loadMenu(menuConfig, menuSettings.getTitle(), menuSettings.getRows(), errorCollector); - menuManager.registerMenu(menuConfig.getFileName(), data.getCommands(), iconMenu, errorCollector); + menuManager.registerMenu(menuConfig.getFileName(), menuSettings.getCommands(), iconMenu, errorCollector); - iconMenu.setRefreshTicks(data.getRefreshTenths()); + iconMenu.setRefreshTicks(menuSettings.getRefreshTenths()); - if (data.getOpenActions() != null) { - iconMenu.setOpenActions(data.getOpenActions()); + if (menuSettings.getOpenActions() != null) { + iconMenu.setOpenActions(menuSettings.getOpenActions()); } - if (data.getOpenTrigger() != null) { - menuManager.registerTriggerItem(data.getOpenTrigger(), iconMenu); + if (menuSettings.getOpenTrigger() != null) { + menuManager.registerTriggerItem(menuSettings.getOpenTrigger(), iconMenu); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java index 651f4cd..9b27206 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java @@ -83,7 +83,7 @@ public class MenuParser { /** * Reads all the settings of a menu. It will never return a null title, even if not set. */ - public static MenuSettings loadMenuData(PluginConfig config, ErrorCollector errorCollector) { + public static MenuSettings loadMenuSettings(PluginConfig config, ErrorCollector errorCollector) { String title = FormatUtils.addColors(config.getString(Nodes.MENU_NAME)); int rows; @@ -109,11 +109,11 @@ public class MenuParser { errorCollector.addError("The menu \"" + config.getFileName() + "\" doesn't have a the number of rows set, it will have 6 rows by default."); } - MenuSettings menuData = new MenuSettings(title, rows); + MenuSettings menuSettings = new MenuSettings(title, rows); List triggeringCommands = ConfigUtil.getStringListOrInlineList(config, ";", Nodes.MENU_COMMANDS); if (triggeringCommands != null) { - menuData.setCommands(triggeringCommands.toArray(new String[0])); + menuSettings.setCommands(triggeringCommands.toArray(new String[0])); } List serializedOpenActions = ConfigUtil.getStringListOrInlineList(config, ChestCommands.getSettings().multiple_commands_separator, Nodes.OPEN_ACTIONS); @@ -128,7 +128,7 @@ public class MenuParser { } if (!openActions.isEmpty()) { - menuData.setOpenActions(openActions); + menuSettings.setOpenActions(openActions); } } @@ -159,10 +159,10 @@ public class MenuParser { if (tenthsToRefresh < 1) { tenthsToRefresh = 1; } - menuData.setRefreshTenths(tenthsToRefresh); + menuSettings.setRefreshTenths(tenthsToRefresh); } - return menuData; + return menuSettings; } } From e5591ed97c69a5ae90af794c729fdad32f2dded3 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 14:22:25 +0200 Subject: [PATCH 035/213] Refactoring --- .../chestcommands/bridge/EconomyBridge.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java index c0d68eb..fdbf556 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java @@ -43,13 +43,13 @@ public class EconomyBridge { } public static double getMoney(Player player) { - if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!"); + checkValidEconomy(); return economy.getBalance(player, player.getWorld().getName()); } public static boolean hasMoney(Player player, double minimum) { - if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!"); - if (minimum < 0.0) throw new IllegalArgumentException("Invalid amount of money: " + minimum); + checkValidEconomy(); + checkPositiveAmount(minimum); double balance = economy.getBalance(player, player.getWorld().getName()); @@ -64,8 +64,8 @@ public class EconomyBridge { * @return true if the operation was successful. */ public static boolean takeMoney(Player player, double amount) { - if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!"); - if (amount < 0.0) throw new IllegalArgumentException("Invalid amount of money: " + amount); + checkValidEconomy(); + checkPositiveAmount(amount); EconomyResponse response = economy.withdrawPlayer(player, player.getWorld().getName(), amount); boolean result = response.transactionSuccess(); @@ -76,8 +76,8 @@ public class EconomyBridge { } public static boolean giveMoney(Player player, double amount) { - if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!"); - if (amount < 0.0) throw new IllegalArgumentException("Invalid amount of money: " + amount); + checkValidEconomy(); + checkPositiveAmount(amount); EconomyResponse response = economy.depositPlayer(player, player.getWorld().getName(), amount); boolean result = response.transactionSuccess(); @@ -87,6 +87,18 @@ public class EconomyBridge { return result; } + private static void checkValidEconomy() { + if (!hasValidEconomy()) { + throw new IllegalStateException("Economy plugin was not found!"); + } + } + + private static void checkPositiveAmount(double amount) { + if (amount < 0.0) { + throw new IllegalArgumentException("Invalid amount of money: " + amount); + } + } + public static String formatMoney(double amount) { if (hasValidEconomy()) { return economy.format(amount); From 80f1cca3d4e3e4e5e7281306ea7faf95f236e1bf Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 14:39:54 +0200 Subject: [PATCH 036/213] Refactor Validate class, rename to Preconditions --- .../filoghost/chestcommands/api/IconMenu.java | 4 +- .../chestcommands/bridge/BarAPIBridge.java | 6 +- .../chestcommands/bridge/EconomyBridge.java | 15 ++-- .../bridge/PlaceholderAPIBridge.java | 86 +++++++++---------- .../chestcommands/internal/OpenTrigger.java | 9 +- .../chestcommands/internal/RequiredItem.java | 7 +- .../chestcommands/parser/IconParser.java | 6 +- .../chestcommands/parser/ItemStackParser.java | 4 +- .../chestcommands/util/Preconditions.java | 48 +++++++++++ .../chestcommands/util/Registry.java | 4 +- .../chestcommands/util/Validate.java | 34 -------- 11 files changed, 115 insertions(+), 108 deletions(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/util/Preconditions.java delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/util/Validate.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/IconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/IconMenu.java index 6902ef2..bcc0f67 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/IconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/IconMenu.java @@ -21,7 +21,7 @@ import org.bukkit.inventory.Inventory; import me.filoghost.chestcommands.internal.MenuInventoryHolder; import me.filoghost.chestcommands.util.ItemUtils; import me.filoghost.chestcommands.util.Utils; -import me.filoghost.chestcommands.util.Validate; +import me.filoghost.chestcommands.util.Preconditions; import java.util.Arrays; @@ -87,7 +87,7 @@ public class IconMenu { } public void open(Player player) { - Validate.notNull(player, "Player cannot be null"); + Preconditions.notNull(player, "player"); Inventory inventory = Bukkit.createInventory(new MenuInventoryHolder(this), icons.length, title); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/BarAPIBridge.java b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/BarAPIBridge.java index eb944e8..751f6ac 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/BarAPIBridge.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/BarAPIBridge.java @@ -15,6 +15,8 @@ package me.filoghost.chestcommands.bridge; import me.confuser.barapi.BarAPI; +import me.filoghost.chestcommands.util.Preconditions; + import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -40,8 +42,8 @@ public class BarAPIBridge { @SuppressWarnings("deprecation") public static void setMessage(Player player, String message, int seconds) { - if (!hasValidPlugin()) throw new IllegalStateException("BarAPI plugin was not found!"); - + Preconditions.checkState(hasValidPlugin(), "BarAPI plugin not found"); + BarAPI.setMessage(player, message, seconds); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java index fdbf556..c97e91b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java @@ -19,6 +19,7 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.RegisteredServiceProvider; import me.filoghost.chestcommands.MenuManager; +import me.filoghost.chestcommands.util.Preconditions; import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.EconomyResponse; @@ -30,11 +31,11 @@ public class EconomyBridge { if (Bukkit.getPluginManager().getPlugin("Vault") == null) { return false; } - RegisteredServiceProvider rsp = Bukkit.getServicesManager().getRegistration(Economy.class); - if (rsp == null) { + RegisteredServiceProvider economyServiceProvider = Bukkit.getServicesManager().getRegistration(Economy.class); + if (economyServiceProvider == null) { return false; } - economy = rsp.getProvider(); + economy = economyServiceProvider.getProvider(); return economy != null; } @@ -88,15 +89,11 @@ public class EconomyBridge { } private static void checkValidEconomy() { - if (!hasValidEconomy()) { - throw new IllegalStateException("Economy plugin was not found!"); - } + Preconditions.checkState(hasValidEconomy(), "economy plugin not found"); } private static void checkPositiveAmount(double amount) { - if (amount < 0.0) { - throw new IllegalArgumentException("Invalid amount of money: " + amount); - } + Preconditions.checkArgument(amount >= 0.0, "amount cannot be negative"); } public static String formatMoney(double amount) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/PlaceholderAPIBridge.java b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/PlaceholderAPIBridge.java index df45f41..8be6220 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/PlaceholderAPIBridge.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/PlaceholderAPIBridge.java @@ -1,44 +1,42 @@ -package me.filoghost.chestcommands.bridge; - -import me.clip.placeholderapi.PlaceholderAPI; -import me.clip.placeholderapi.PlaceholderAPIPlugin; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -public class PlaceholderAPIBridge { - - private static PlaceholderAPIPlugin placeholderAPI; - - public static boolean setupPlugin() { - Plugin placeholderPlugin = Bukkit.getPluginManager().getPlugin("PlaceholderAPI"); - - if (placeholderPlugin == null) { - return false; - } - - placeholderAPI = (PlaceholderAPIPlugin) placeholderPlugin; - return true; - } - - public static boolean hasValidPlugin() { - return placeholderAPI != null; - } - - public static boolean hasPlaceholders(String message) { - if (!hasValidPlugin()) { - throw new IllegalStateException("PlaceholderAPI plugin was not found!"); - } - - return PlaceholderAPI.containsPlaceholders(message); - } - - public static String setPlaceholders(String message, Player executor) { - if (!hasValidPlugin()) { - throw new IllegalStateException("PlaceholderAPI plugin was not found!"); - } - - return PlaceholderAPI.setPlaceholders(executor, message); - } - -} +package me.filoghost.chestcommands.bridge; + +import me.clip.placeholderapi.PlaceholderAPI; +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.filoghost.chestcommands.util.Preconditions; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +public class PlaceholderAPIBridge { + + private static PlaceholderAPIPlugin placeholderAPI; + + public static boolean setupPlugin() { + Plugin placeholderPlugin = Bukkit.getPluginManager().getPlugin("PlaceholderAPI"); + + if (placeholderPlugin == null) { + return false; + } + + placeholderAPI = (PlaceholderAPIPlugin) placeholderPlugin; + return true; + } + + public static boolean hasValidPlugin() { + return placeholderAPI != null; + } + + public static boolean hasPlaceholders(String message) { + Preconditions.checkState(hasValidPlugin(), "PlaceholderAPI plugin not found"); + + return PlaceholderAPI.containsPlaceholders(message); + } + + public static String setPlaceholders(String message, Player executor) { + Preconditions.checkState(hasValidPlugin(), "PlaceholderAPI plugin not found"); + + return PlaceholderAPI.setPlaceholders(executor, message); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/OpenTrigger.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/OpenTrigger.java index e940112..1ba0be9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/OpenTrigger.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/OpenTrigger.java @@ -18,7 +18,7 @@ import org.bukkit.Material; import org.bukkit.event.block.Action; import org.bukkit.inventory.ItemStack; -import me.filoghost.chestcommands.util.Validate; +import me.filoghost.chestcommands.util.Preconditions; public class OpenTrigger { @@ -28,10 +28,9 @@ public class OpenTrigger { private boolean isRestrictiveDurability; public OpenTrigger(Material material, ClickType clickType) { - Validate.notNull(material, "Material cannot be null"); - Validate.notNull(material, "ClickType cannot be null"); - Validate.isTrue(material != Material.AIR, "Material cannot be AIR"); - + Preconditions.checkArgumentNotAir(material, "material"); + Preconditions.notNull(clickType, "clickType"); + this.material = material; this.clickType = clickType; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java index 25683ea..306b94f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java @@ -18,7 +18,7 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import me.filoghost.chestcommands.util.Validate; +import me.filoghost.chestcommands.util.Preconditions; public class RequiredItem { @@ -28,8 +28,7 @@ public class RequiredItem { private boolean isDurabilityRestrictive = false; public RequiredItem(Material material, int amount) { - Validate.notNull(material, "Material cannot be null"); - Validate.isTrue(material != Material.AIR, "Material cannot be air"); + Preconditions.checkArgumentNotAir(material, "material"); this.material = material; this.amount = amount; @@ -48,7 +47,7 @@ public class RequiredItem { } public void setRestrictiveDataValue(short data) { - Validate.isTrue(data >= 0, "Data value cannot be negative"); + Preconditions.checkArgument(data >= 0, "Data value cannot be negative"); this.dataValue = data; isDurabilityRestrictive = true; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index d928efa..5088311 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -35,7 +35,7 @@ import me.filoghost.chestcommands.parser.EnchantmentParser.EnchantmentDetails; import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.FormatUtils; import me.filoghost.chestcommands.util.ItemUtils; -import me.filoghost.chestcommands.util.Validate; +import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.nbt.parser.MojangsonParseException; import me.filoghost.chestcommands.util.nbt.parser.MojangsonParser; @@ -94,7 +94,7 @@ public class IconParser { public static Icon loadIconFromSection(ConfigurationSection section, String iconName, String menuFileName, ErrorCollector errorCollector) { - Validate.notNull(section, "ConfigurationSection cannot be null"); + Preconditions.notNull(section, "section"); // The icon is valid even without a Material ExtendedIcon icon = new ExtendedIcon(); @@ -245,7 +245,7 @@ public class IconParser { public static Coords loadCoordsFromSection(ConfigurationSection section) { - Validate.notNull(section, "ConfigurationSection cannot be null"); + Preconditions.notNull(section, "section"); Integer x = null; Integer y = null; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java index bff594c..8fca825 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java @@ -20,7 +20,7 @@ import org.bukkit.inventory.ItemStack; import me.filoghost.chestcommands.exception.FormatException; import me.filoghost.chestcommands.util.MaterialsHelper; import me.filoghost.chestcommands.util.Utils; -import me.filoghost.chestcommands.util.Validate; +import me.filoghost.chestcommands.util.Preconditions; public class ItemStackParser { @@ -35,7 +35,7 @@ public class ItemStackParser { * for example wool:5, 3 is a valid input. */ public ItemStackParser(String input, boolean parseAmount) throws FormatException { - Validate.notNull(input, "input cannot be null"); + Preconditions.notNull(input, "input"); // Remove spaces, they're not needed input = input.replace(" ", ""); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Preconditions.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Preconditions.java new file mode 100644 index 0000000..d662fe7 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Preconditions.java @@ -0,0 +1,48 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.util; + +import org.bukkit.Material; + +public final class Preconditions { + + private Preconditions() {} + + public static void notNull(Object object, String objectName) { + if (object == null) { + throw new NullPointerException(objectName + " cannot be null"); + } + } + + public static void checkArgument(boolean expression, String errorMessage) { + if (!expression) { + throw new IllegalArgumentException(errorMessage); + } + } + + public static void checkState(boolean expression, String errorMessage) { + if (!expression) { + throw new IllegalStateException(errorMessage); + } + } + + public static void checkArgumentNotAir(Material material, String objectName) { + notNull(material, objectName); + if (MaterialsHelper.isAir(material)) { + throw new IllegalArgumentException(objectName + " cannot be " + material); + } + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Registry.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Registry.java index 98dc8cc..4663753 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Registry.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Registry.java @@ -55,9 +55,7 @@ public class Registry { } public void putIfEnumExists(String key, String enumValueName) { - if (!valuesType.isEnum()) { - throw new IllegalArgumentException("Value type is not an enum"); - } + Preconditions.checkState(valuesType.isEnum(), "value type is not an enum"); try { @SuppressWarnings({ "unchecked", "rawtypes" }) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Validate.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Validate.java deleted file mode 100644 index b29fbf6..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Validate.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.util; - -public final class Validate { - - private Validate() { - } - - public static void notNull(Object object, String error) { - if (object == null) { - throw new NullPointerException(error); - } - } - - public static void isTrue(boolean statement, String error) { - if (!statement) { - throw new IllegalArgumentException(error); - } - } - -} From 9020fafe81af91ac7fb5b0496584c5d960b9e6e5 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 15:00:01 +0200 Subject: [PATCH 037/213] Refactor ItemUtils, rename to ItemMetaParser --- .../filoghost/chestcommands/api/IconMenu.java | 20 +++++++++++-- .../internal/ExtendedIconMenu.java | 8 ++--- .../chestcommands/parser/IconParser.java | 7 ++--- .../ItemMetaParser.java} | 29 ++++--------------- 4 files changed, 29 insertions(+), 35 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/{util/ItemUtils.java => parser/ItemMetaParser.java} (80%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/IconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/IconMenu.java index bcc0f67..38999ce 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/IconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/IconMenu.java @@ -17,9 +17,11 @@ package me.filoghost.chestcommands.api; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import me.filoghost.chestcommands.internal.MenuInventoryHolder; -import me.filoghost.chestcommands.util.ItemUtils; import me.filoghost.chestcommands.util.Utils; import me.filoghost.chestcommands.util.Preconditions; @@ -93,12 +95,26 @@ public class IconMenu { for (int i = 0; i < icons.length; i++) { if (icons[i] != null) { - inventory.setItem(i, ItemUtils.hideAttributes(icons[i].createItemstack(player))); + inventory.setItem(i, hideAttributes(icons[i].createItemstack(player))); } } player.openInventory(inventory); } + + protected ItemStack hideAttributes(ItemStack item) { + if (item == null) { + return null; + } + + ItemMeta meta = item.getItemMeta(); + if (Utils.isNullOrEmpty(meta.getItemFlags())) { + // Add them only if no flag was already set + meta.addItemFlags(ItemFlag.values()); + item.setItemMeta(meta); + } + return item; + } @Override public String toString() { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java index 96b4d4c..65a414b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java @@ -26,8 +26,6 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.api.IconMenu; -import me.filoghost.chestcommands.util.ItemUtils; - import java.util.List; public class ExtendedIconMenu extends IconMenu { @@ -86,7 +84,7 @@ public class ExtendedIconMenu extends IconMenu { continue; } - inventory.setItem(i, ItemUtils.hideAttributes(icons[i].createItemstack(player))); + inventory.setItem(i, hideAttributes(icons[i].createItemstack(player))); } } @@ -116,11 +114,11 @@ public class ExtendedIconMenu extends IconMenu { if (extIcon.canViewIcon(player)) { if (inventory.getItem(i) == null) { - ItemStack newItem = ItemUtils.hideAttributes(extIcon.createItemstack(player)); + ItemStack newItem = hideAttributes(extIcon.createItemstack(player)); inventory.setItem(i, newItem); } else { // Performance, only update name and lore - ItemStack oldItem = ItemUtils.hideAttributes(inventory.getItem(i)); + ItemStack oldItem = hideAttributes(inventory.getItem(i)); ItemMeta meta = oldItem.getItemMeta(); meta.setDisplayName(extIcon.calculateName(player)); meta.setLore(extIcon.calculateLore(player)); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index 5088311..c1c009b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -34,7 +34,6 @@ import me.filoghost.chestcommands.internal.RequiredItem; import me.filoghost.chestcommands.parser.EnchantmentParser.EnchantmentDetails; import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.FormatUtils; -import me.filoghost.chestcommands.util.ItemUtils; import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.nbt.parser.MojangsonParseException; import me.filoghost.chestcommands.util.nbt.parser.MojangsonParser; @@ -155,7 +154,7 @@ public class IconParser { if (section.isSet(Nodes.COLOR)) { try { - icon.setColor(ItemUtils.parseColor(section.getString(Nodes.COLOR))); + icon.setColor(ItemMetaParser.parseColor(section.getString(Nodes.COLOR))); } catch (FormatException e) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid COLOR: " + e.getMessage()); } @@ -166,7 +165,7 @@ public class IconParser { String bannerColor = ConfigUtil.getAnyString(section, Nodes.BANNER_COLOR); if (bannerColor != null) { try { - icon.setBannerColor(ItemUtils.parseDyeColor(bannerColor)); + icon.setBannerColor(ItemMetaParser.parseDyeColor(bannerColor)); } catch (FormatException e) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid BANNER-COLOR: " + e.getMessage()); } @@ -174,7 +173,7 @@ public class IconParser { if (section.isSet(Nodes.BANNER_PATTERNS)) { try { - icon.setBannerPatterns(ItemUtils.parseBannerPatternList(section.getStringList(Nodes.BANNER_PATTERNS))); + icon.setBannerPatterns(ItemMetaParser.parseBannerPatternList(section.getStringList(Nodes.BANNER_PATTERNS))); } catch (FormatException e) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid BANNER-PATTERNS: " + e.getMessage()); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/ItemUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java similarity index 80% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/ItemUtils.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java index 0ae6b03..770d1e3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/ItemUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java @@ -12,44 +12,25 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.util; +package me.filoghost.chestcommands.parser; import org.bukkit.Color; import org.bukkit.DyeColor; import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.PatternType; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - import me.filoghost.chestcommands.exception.FormatException; - +import me.filoghost.chestcommands.util.Registry; import java.util.ArrayList; import java.util.List; -public final class ItemUtils { +public final class ItemMetaParser { private static Registry DYE_COLORS_REGISTRY = Registry.fromEnumValues(DyeColor.class); private static Registry PATTERN_TYPES_REGISTRY = Registry.fromEnumValues(PatternType.class); + private ItemMetaParser() {} - private ItemUtils() { - } - - public static ItemStack hideAttributes(ItemStack item) { - if (item == null) { - return null; - } - - ItemMeta meta = item.getItemMeta(); - if (Utils.isNullOrEmpty(meta.getItemFlags())) { - // Add them only if no flag was already set - meta.addItemFlags(ItemFlag.values()); - item.setItemMeta(meta); - } - return item; - } - + public static Color parseColor(String input) throws FormatException { String[] split = input.replace(" ", "").split(","); From d0d4be2b8f2fac94c608ffeb10dab20b0fb3b2dc Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 15:00:51 +0200 Subject: [PATCH 038/213] Move FormatException to correct package --- .../java/me/filoghost/chestcommands/action/GiveItemAction.java | 2 +- .../chestcommands/{exception => parser}/FormatException.java | 2 +- .../main/java/me/filoghost/chestcommands/parser/IconParser.java | 1 - .../java/me/filoghost/chestcommands/parser/ItemMetaParser.java | 2 +- .../java/me/filoghost/chestcommands/parser/ItemStackParser.java | 1 - .../main/java/me/filoghost/chestcommands/parser/MenuParser.java | 1 - 6 files changed, 3 insertions(+), 6 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/{exception => parser}/FormatException.java (92%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java index 636cd23..d59fb1c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java @@ -18,7 +18,7 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import me.filoghost.chestcommands.exception.FormatException; +import me.filoghost.chestcommands.parser.FormatException; import me.filoghost.chestcommands.parser.ItemStackParser; public class GiveItemAction extends Action { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/exception/FormatException.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/FormatException.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/exception/FormatException.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parser/FormatException.java index 32b9066..d98eac3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/exception/FormatException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/FormatException.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.exception; +package me.filoghost.chestcommands.parser; public class FormatException extends Exception { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index c1c009b..fdd6fab 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -27,7 +27,6 @@ import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.config.AsciiPlaceholders; import me.filoghost.chestcommands.config.ConfigUtil; -import me.filoghost.chestcommands.exception.FormatException; import me.filoghost.chestcommands.internal.RunActionsClickHandler; import me.filoghost.chestcommands.internal.ExtendedIcon; import me.filoghost.chestcommands.internal.RequiredItem; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java index 770d1e3..f22c41d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java @@ -18,7 +18,7 @@ import org.bukkit.Color; import org.bukkit.DyeColor; import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.PatternType; -import me.filoghost.chestcommands.exception.FormatException; + import me.filoghost.chestcommands.util.Registry; import java.util.ArrayList; import java.util.List; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java index 8fca825..eb3a22d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java @@ -17,7 +17,6 @@ package me.filoghost.chestcommands.parser; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import me.filoghost.chestcommands.exception.FormatException; import me.filoghost.chestcommands.util.MaterialsHelper; import me.filoghost.chestcommands.util.Utils; import me.filoghost.chestcommands.util.Preconditions; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java index 9b27206..663fc86 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java @@ -25,7 +25,6 @@ import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.config.ConfigUtil; import me.filoghost.chestcommands.config.yaml.PluginConfig; -import me.filoghost.chestcommands.exception.FormatException; import me.filoghost.chestcommands.internal.ClickType; import me.filoghost.chestcommands.internal.ExtendedIconMenu; import me.filoghost.chestcommands.internal.MenuSettings; From 0f999dbb5da6ae8d9b4a7948eb1ce41332734919 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 15:10:22 +0200 Subject: [PATCH 039/213] Refactoring and move BukkitUtils to FileUtils --- .../chestcommands/ChestCommands.java | 4 +-- .../config/AsciiPlaceholders.java | 8 ++--- .../chestcommands/listener/SignListener.java | 6 ++-- .../util/{BukkitUtils.java => FileUtils.java} | 9 +++--- .../filoghost/chestcommands/util/Utils.java | 30 ------------------- 5 files changed, 13 insertions(+), 44 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/util/{BukkitUtils.java => FileUtils.java} (75%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index fd3c436..ecb6a05 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -42,7 +42,7 @@ import me.filoghost.chestcommands.listener.JoinListener; import me.filoghost.chestcommands.listener.SignListener; import me.filoghost.chestcommands.parser.MenuParser; import me.filoghost.chestcommands.task.RefreshMenusTask; -import me.filoghost.chestcommands.util.BukkitUtils; +import me.filoghost.chestcommands.util.FileUtils; import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.Utils; import me.filoghost.updatechecker.UpdateChecker; @@ -180,7 +180,7 @@ public class ChestCommands extends JavaPlugin { if (!menusFolder.isDirectory()) { // Create the directory with the default menu menusFolder.mkdirs(); - BukkitUtils.saveResourceSafe(this, "menu" + File.separator + "example.yml"); + FileUtils.saveResourceSafe(this, "menu" + File.separator + "example.yml"); } List menusList = loadMenus(menusFolder); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java index eff5685..45f6572 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java @@ -16,6 +16,7 @@ package me.filoghost.chestcommands.config; import java.io.File; import java.io.IOException; +import java.nio.file.Files; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -24,10 +25,9 @@ import java.util.Map.Entry; import org.apache.commons.lang.StringEscapeUtils; import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.util.BukkitUtils; import me.filoghost.chestcommands.util.ErrorCollector; +import me.filoghost.chestcommands.util.FileUtils; import me.filoghost.chestcommands.util.FormatUtils; -import me.filoghost.chestcommands.util.Utils; /** * This is not a real YAML file ;) @@ -43,10 +43,10 @@ public class AsciiPlaceholders { File file = new File(ChestCommands.getInstance().getDataFolder(), "placeholders.yml"); if (!file.exists()) { - BukkitUtils.saveResourceSafe(ChestCommands.getInstance(), "placeholders.yml"); + FileUtils.saveResourceSafe(ChestCommands.getInstance(), "placeholders.yml"); } - List lines = Utils.readLines(file); + List lines = Files.readAllLines(file.toPath()); for (String line : lines) { // Comment or empty line diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java index 6d7e9ef..b2208c5 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java @@ -30,7 +30,7 @@ import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.api.IconMenu; import me.filoghost.chestcommands.internal.ExtendedIconMenu; -import me.filoghost.chestcommands.util.BukkitUtils; +import me.filoghost.chestcommands.util.FileUtils; public class SignListener implements Listener { @@ -66,7 +66,7 @@ public class SignListener implements Listener { return; } - String menuFileName = BukkitUtils.addYamlExtension(sign.getLine(FILENAME_LINE).trim()); + String menuFileName = FileUtils.addYamlExtension(sign.getLine(FILENAME_LINE).trim()); ExtendedIconMenu menu = menuManager.getMenuByFileName(menuFileName); if (menu == null) { @@ -88,7 +88,7 @@ public class SignListener implements Listener { return; } - menuFileName = BukkitUtils.addYamlExtension(menuFileName); + menuFileName = FileUtils.addYamlExtension(menuFileName); IconMenu iconMenu = menuManager.getMenuByFileName(menuFileName); if (iconMenu == null) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/BukkitUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/FileUtils.java similarity index 75% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/BukkitUtils.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/FileUtils.java index 17dd974..f87dd67 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/BukkitUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/FileUtils.java @@ -2,10 +2,10 @@ package me.filoghost.chestcommands.util; import org.bukkit.plugin.Plugin; -public final class BukkitUtils { +public final class FileUtils { - private BukkitUtils() {} + private FileUtils() {} public static String addYamlExtension(String input) { @@ -18,8 +18,7 @@ public final class BukkitUtils { public static void saveResourceSafe(Plugin plugin, String name) { try { plugin.saveResource(name, false); - } catch (Exception ignored) { - } + } catch (Exception ignored) {} } - + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java index 036639a..da14556 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java @@ -14,7 +14,6 @@ */ package me.filoghost.chestcommands.util; -import java.io.*; import java.util.*; public final class Utils { @@ -60,35 +59,6 @@ public final class Utils { } } - public static List readLines(File file) throws IOException, Exception { - BufferedReader br = null; - - try { - List lines = new ArrayList<>(); - - if (!file.exists()) { - throw new FileNotFoundException(); - } - - br = new BufferedReader(new FileReader(file)); - String line = br.readLine(); - - while (line != null) { - lines.add(line); - line = br.readLine(); - } - - return lines; - } finally { - if (br != null) { - try { - br.close(); - } catch (IOException e) { - } - } - } - } - public static boolean isClassLoaded(String name) { try { Class.forName(name); From 1da614aa293658116a4dd0bc752d55584cec6cb1 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 15:31:23 +0200 Subject: [PATCH 040/213] Separate number parsing and refactoring --- .../chestcommands/action/DragonBarAction.java | 14 +++- .../chestcommands/action/GiveMoneyAction.java | 10 +-- .../chestcommands/parser/ItemStackParser.java | 20 +---- .../chestcommands/parser/NumberParser.java | 75 +++++++++++++++++++ .../filoghost/chestcommands/util/Utils.java | 37 +-------- 5 files changed, 93 insertions(+), 63 deletions(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/parser/NumberParser.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java index 8efd0da..cff1fd4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java @@ -17,8 +17,9 @@ package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; import me.filoghost.chestcommands.bridge.BarAPIBridge; +import me.filoghost.chestcommands.parser.FormatException; +import me.filoghost.chestcommands.parser.NumberParser; import me.filoghost.chestcommands.util.FormatUtils; -import me.filoghost.chestcommands.util.Utils; public class DragonBarAction extends Action { @@ -37,9 +38,14 @@ public class DragonBarAction extends Action { message = action; String[] split = action.split("\\|", 2); // Max of 2 pieces - if (split.length > 1 && Utils.isValidPositiveInteger(split[0].trim())) { - seconds = Integer.parseInt(split[0].trim()); - message = split[1].trim(); + if (split.length > 1) { + try { + seconds = NumberParser.getStrictlyPositiveInteger(split[0].trim()); + message = split[1].trim(); + } catch (FormatException ex) { + // Ignore + // TODO: notify with message + } } message = FormatUtils.addColors(message); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java index b46d8bf..25165f6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java @@ -18,7 +18,8 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import me.filoghost.chestcommands.bridge.EconomyBridge; -import me.filoghost.chestcommands.util.Utils; +import me.filoghost.chestcommands.parser.FormatException; +import me.filoghost.chestcommands.parser.NumberParser; public class GiveMoneyAction extends Action { @@ -33,12 +34,11 @@ public class GiveMoneyAction extends Action { } private void parseMoney(String action) { - if (!Utils.isValidPositiveDouble(action)) { + try { + moneyToGive = NumberParser.getStrictlyPositiveDouble(action); + } catch (FormatException e) { errorMessage = ChatColor.RED + "Invalid money amount: " + action; - return; } - errorMessage = null; - moneyToGive = Double.parseDouble(action); } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java index eb3a22d..39ff42f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java @@ -18,7 +18,6 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import me.filoghost.chestcommands.util.MaterialsHelper; -import me.filoghost.chestcommands.util.Utils; import me.filoghost.chestcommands.util.Preconditions; public class ItemStackParser { @@ -44,14 +43,7 @@ public class ItemStackParser { String[] splitAmount = input.split(","); if (splitAmount.length > 1) { - - if (!Utils.isValidInteger(splitAmount[1])) { - throw new FormatException("invalid amount \"" + splitAmount[1] + "\""); - } - - int amount = Integer.parseInt(splitAmount[1]); - if (amount <= 0) throw new FormatException("invalid amount \"" + splitAmount[1] + "\""); - this.amount = amount; + this.amount = NumberParser.getStrictlyPositiveInteger(splitAmount[1], "invalid amount \"" + splitAmount[1] + "\""); // Only keep the first part as input input = splitAmount[0]; @@ -63,15 +55,7 @@ public class ItemStackParser { String[] splitByColons = input.split(":"); if (splitByColons.length > 1) { - - if (!Utils.isValidShort(splitByColons[1])) { - throw new FormatException("invalid data value \"" + splitByColons[1] + "\""); - } - - short dataValue = Short.parseShort(splitByColons[1]); - if (dataValue < 0) { - throw new FormatException("invalid data value \"" + splitByColons[1] + "\""); - } + short dataValue = NumberParser.getPositiveShort(splitByColons[1], "invalid data value \"" + splitByColons[1] + "\""); this.explicitDataValue = true; this.dataValue = dataValue; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/NumberParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/NumberParser.java new file mode 100644 index 0000000..2e7db8f --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/NumberParser.java @@ -0,0 +1,75 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.parser; + +public class NumberParser { + + public static double getStrictlyPositiveDouble(String input) throws FormatException { + return getStrictlyPositiveDouble(input, "number must be a valid decimal and greater than 0"); + } + + public static double getStrictlyPositiveDouble(String input, String errorMessage) throws FormatException { + double value = getDouble(input, errorMessage); + check(value > 0.0, errorMessage); + return value; + } + + private static double getDouble(String input, String errorMessage) throws FormatException { + try { + return Double.parseDouble(input); + } catch (NumberFormatException ex) { + throw new FormatException(errorMessage); + } + } + + public static short getPositiveShort(String input, String errorMessage) throws FormatException { + short value = getShort(input, errorMessage); + check(value >= 0, errorMessage); + return value; + } + + public static short getShort(String input, String errorMessage) throws FormatException { + try { + return Short.parseShort(input); + } catch (NumberFormatException ex) { + throw new FormatException(errorMessage); + } + } + + public static int getStrictlyPositiveInteger(String input) throws FormatException { + return getStrictlyPositiveInteger(input, "number must be a valid integer and greater than 0"); + } + + public static int getStrictlyPositiveInteger(String input, String errorMessage) throws FormatException { + int value = getInteger(input, errorMessage); + check(value > 0, errorMessage); + return value; + } + + public static int getInteger(String input, String errorMessage) throws FormatException { + try { + return Integer.parseInt(input); + } catch (NumberFormatException ex) { + throw new FormatException(errorMessage); + } + } + + private static void check(boolean expression, String errorMessage) throws FormatException { + if (!expression) { + throw new FormatException(errorMessage); + } + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java index da14556..77d824b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java @@ -18,47 +18,12 @@ import java.util.*; public final class Utils { - private Utils() { - } + private Utils() {} public static int makePositive(int i) { return i < 0 ? 0 : i; } - public static boolean isValidInteger(String input) { - try { - Integer.parseInt(input); - return true; - } catch (NumberFormatException ex) { - return false; - } - } - - public static boolean isValidPositiveInteger(String input) { - try { - return Integer.parseInt(input) > 0; - } catch (NumberFormatException ex) { - return false; - } - } - - public static boolean isValidShort(String input) { - try { - Short.parseShort(input); - return true; - } catch (NumberFormatException ex) { - return false; - } - } - - public static boolean isValidPositiveDouble(String input) { - try { - return Double.parseDouble(input) > 0.0; - } catch (NumberFormatException ex) { - return false; - } - } - public static boolean isClassLoaded(String name) { try { Class.forName(name); From 7132893423c15672167d6d6daa7a3020c881a8d7 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 15:34:48 +0200 Subject: [PATCH 041/213] Refactoring --- .../bridge/bungee/BungeeCordUtils.java | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/bungee/BungeeCordUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/bungee/BungeeCordUtils.java index 8da537d..5cd4b4b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/bungee/BungeeCordUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/bungee/BungeeCordUtils.java @@ -21,33 +21,27 @@ import me.filoghost.chestcommands.ChestCommands; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; +import java.io.IOException; public class BungeeCordUtils { public static boolean connect(Player player, String server) { - - try { - - if (server.length() == 0) { - player.sendMessage("§cTarget server was \"\" (empty string) cannot connect to it."); - return false; - } - - ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); - DataOutputStream out = new DataOutputStream(byteArray); - - out.writeUTF("Connect"); - out.writeUTF(server); // Target Server - - player.sendPluginMessage(ChestCommands.getInstance(), "BungeeCord", byteArray.toByteArray()); - - } catch (Exception ex) { - player.sendMessage(ChatColor.RED + "An unexpected exception has occurred. Please notify the server's staff about this. (They should look at the console)."); - ex.printStackTrace(); - ChestCommands.getInstance().getLogger().warning("Could not connect \"" + player.getName() + "\" to the server \"" + server + "\"."); + if (server.length() == 0) { + player.sendMessage(ChatColor.RED + "Target server was an empty string, cannot connect to it."); return false; } + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); + + try { + dataOutputStream.writeUTF("Connect"); + dataOutputStream.writeUTF(server); // Target Server + } catch (IOException ex) { + throw new AssertionError(); + } + + player.sendPluginMessage(ChestCommands.getInstance(), "BungeeCord", byteArrayOutputStream.toByteArray()); return true; } From 5282611ce54597f17894753440ddb9d1d82e0602 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 16:21:00 +0200 Subject: [PATCH 042/213] Separate API in different module --- API/pom.xml | 31 ++++++ .../chestcommands/api/ChestCommandsAPI.java | 8 +- .../chestcommands/api/ClickHandler.java | 0 .../me/filoghost/chestcommands/api/Icon.java | 98 +++++++++++++++++++ .../filoghost/chestcommands/api/IconMenu.java | 37 +++++++ .../api/internal/BackendAPI.java | 37 +++++++ Plugin/pom.xml | 6 ++ .../filoghost/chestcommands/MenuManager.java | 3 +- .../chestcommands/StandardBackendAPI.java | 27 +++++ .../Icon.java => internal/BasicIcon.java} | 42 +++++++- .../BasicIconMenu.java} | 25 +++-- .../chestcommands/internal/ExtendedIcon.java | 3 +- .../internal/ExtendedIconMenu.java | 4 +- .../internal/MenuInventoryHolder.java | 8 +- .../listener/InventoryListener.java | 8 +- .../chestcommands/parser/IconParser.java | 4 +- .../chestcommands/parser/MenuParser.java | 4 +- pom.xml | 1 + 18 files changed, 315 insertions(+), 31 deletions(-) create mode 100644 API/pom.xml rename {Plugin => API}/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java (82%) rename {Plugin => API}/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java (100%) create mode 100644 API/src/main/java/me/filoghost/chestcommands/api/Icon.java create mode 100644 API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java create mode 100644 API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/StandardBackendAPI.java rename Plugin/src/main/java/me/filoghost/chestcommands/{api/Icon.java => internal/BasicIcon.java} (89%) rename Plugin/src/main/java/me/filoghost/chestcommands/{api/IconMenu.java => internal/BasicIconMenu.java} (85%) diff --git a/API/pom.xml b/API/pom.xml new file mode 100644 index 0000000..2863e7f --- /dev/null +++ b/API/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + + me.filoghost.chestcommands + chestcommands-parent + 4.0-SNAPSHOT + + + chestcommands-api + ChestCommands API + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + + + + org.bukkit + bukkit + ${bukkit.version} + provided + + + + \ No newline at end of file diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java similarity index 82% rename from Plugin/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java rename to API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java index dc0957e..d36940c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java @@ -16,9 +16,11 @@ package me.filoghost.chestcommands.api; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.api.internal.BackendAPI; public class ChestCommandsAPI { + + private ChestCommandsAPI() {} /** * Checks if a menu with a given file name was loaded by the plugin. @@ -26,7 +28,7 @@ public class ChestCommandsAPI { * @return true - if the menu was found. */ public static boolean isPluginMenu(String yamlFile) { - return ChestCommands.getInstance().getMenuManager().getMenuByFileName(yamlFile) != null; + return BackendAPI.getImplementation().getMenuByFileName(yamlFile) != null; } /** @@ -38,7 +40,7 @@ public class ChestCommandsAPI { * @return true - if the menu was found and opened, false if not. */ public static boolean openPluginMenu(Player player, String yamlFile) { - IconMenu menu = ChestCommands.getInstance().getMenuManager().getMenuByFileName(yamlFile); + IconMenu menu = BackendAPI.getImplementation().getMenuByFileName(yamlFile); if (menu != null) { menu.open(player); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java b/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java rename to API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java diff --git a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java new file mode 100644 index 0000000..89ba2af --- /dev/null +++ b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java @@ -0,0 +1,98 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.api; + +import java.util.List; +import java.util.Map; + +import org.bukkit.Color; +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.block.banner.Pattern; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public interface Icon { + + boolean hasVariables(); + + void setMaterial(Material material); + + Material getMaterial(); + + void setAmount(int amount); + + int getAmount(); + + void setDataValue(short dataValue); + + short getDataValue(); + + void setNBTData(String nbtData); + + String getNBTData(); + + void setName(String name); + + boolean hasName(); + + void setLore(String... lore); + + void setLore(List lore); + + boolean hasLore(); + + List getLore(); + + void setEnchantments(Map enchantments); + + Map getEnchantments(); + + void addEnchantment(Enchantment ench); + + void addEnchantment(Enchantment ench, Integer level); + + void removeEnchantment(Enchantment ench); + + void clearEnchantments(); + + Color getColor(); + + void setColor(Color color); + + String getSkullOwner(); + + void setSkullOwner(String skullOwner); + + DyeColor getBannerColor(); + + void setBannerColor(DyeColor bannerColor); + + List getBannerPatterns(); + + void setBannerPatterns(List bannerPatterns); + + void setCloseOnClick(boolean closeOnClick); + + void setClickHandler(ClickHandler clickHandler); + + ClickHandler getClickHandler(); + + ItemStack createItemstack(Player pov); + + boolean onClick(Player whoClicked); + +} \ No newline at end of file diff --git a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java new file mode 100644 index 0000000..3006e48 --- /dev/null +++ b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java @@ -0,0 +1,37 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.api; + +import org.bukkit.entity.Player; + +public interface IconMenu { + + void setIcon(int x, int y, Icon icon); + + void setIconRaw(int slot, Icon icon); + + Icon getIcon(int x, int y); + + Icon getIconRaw(int slot); + + int getRows(); + + int getSize(); + + String getTitle(); + + void open(Player player); + +} \ No newline at end of file diff --git a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java new file mode 100644 index 0000000..8d38b6a --- /dev/null +++ b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java @@ -0,0 +1,37 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.api.internal; + +import me.filoghost.chestcommands.api.IconMenu; + +public abstract class BackendAPI { + + private static BackendAPI implementation; + + public static void setImplementation(BackendAPI implementation) { + BackendAPI.implementation = implementation; + } + + public static BackendAPI getImplementation() { + if (implementation == null) { + throw new IllegalStateException("no implementation set"); + } + + return implementation; + } + + public abstract IconMenu getMenuByFileName(String yamlFile); + +} diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 787bae8..02c9c6c 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -79,6 +79,12 @@ updatechecker 1.0.0 + + + ${project.groupId} + chestcommands-api + ${project.version} + diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java index 9cfe029..94a7a97 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java @@ -27,6 +27,7 @@ import org.bukkit.inventory.ItemStack; import me.filoghost.chestcommands.api.IconMenu; import me.filoghost.chestcommands.internal.ExtendedIconMenu; +import me.filoghost.chestcommands.internal.BasicIconMenu; import me.filoghost.chestcommands.internal.MenuInventoryHolder; import me.filoghost.chestcommands.internal.OpenTrigger; import me.filoghost.chestcommands.util.CaseInsensitiveMap; @@ -116,7 +117,7 @@ public class MenuManager { } - public static IconMenu getOpenMenu(Inventory inventory) { + public static BasicIconMenu getOpenMenu(Inventory inventory) { if (!(inventory.getHolder() instanceof MenuInventoryHolder)) { return null; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/StandardBackendAPI.java b/Plugin/src/main/java/me/filoghost/chestcommands/StandardBackendAPI.java new file mode 100644 index 0000000..9eca817 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/StandardBackendAPI.java @@ -0,0 +1,27 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands; + +import me.filoghost.chestcommands.api.IconMenu; +import me.filoghost.chestcommands.api.internal.BackendAPI; + +public class StandardBackendAPI extends BackendAPI { + + @Override + public IconMenu getMenuByFileName(String yamlFile) { + return ChestCommands.getInstance().getMenuManager().getMenuByFileName(yamlFile); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIcon.java similarity index 89% rename from Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIcon.java index 146c078..138d7db 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIcon.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.api; +package me.filoghost.chestcommands.internal; import org.bukkit.*; import org.bukkit.block.banner.Pattern; @@ -25,6 +25,8 @@ import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.inventory.meta.SkullMeta; import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.api.ClickHandler; +import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.variable.VariableManager; import java.util.ArrayList; @@ -35,7 +37,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.logging.Level; -public class Icon { +public class BasicIcon implements Icon { private Material material; private int amount; @@ -58,25 +60,29 @@ public class Icon { private boolean skullOwnerHasVariables; private ItemStack cachedItem; // When there are no variables, we don't recreate the item - public Icon() { + public BasicIcon() { enchantments = new HashMap<>(); closeOnClick = true; amount = 1; } + @Override public boolean hasVariables() { return nameHasVariables || loreLinesWithVariables != null || skullOwnerHasVariables; } + @Override public void setMaterial(Material material) { if (material == Material.AIR) material = null; this.material = material; } + @Override public Material getMaterial() { return material; } + @Override public void setAmount(int amount) { if (amount < 1) amount = 1; else if (amount > 127) amount = 127; @@ -84,43 +90,52 @@ public class Icon { this.amount = amount; } + @Override public int getAmount() { return amount; } + @Override public void setDataValue(short dataValue) { if (dataValue < 0) dataValue = 0; this.dataValue = dataValue; } + @Override public short getDataValue() { return dataValue; } + @Override public void setNBTData(String nbtData) { this.nbtData = nbtData; } + @Override public String getNBTData() { return nbtData; } + @Override public void setName(String name) { this.name = name; this.nameHasVariables = VariableManager.hasVariables(name); } + @Override public boolean hasName() { return name != null; } + @Override public void setLore(String... lore) { if (lore != null) { setLore(Arrays.asList(lore)); } } + @Override public void setLore(List lore) { this.lore = lore; this.loreLinesWithVariables = null; @@ -137,14 +152,17 @@ public class Icon { } } + @Override public boolean hasLore() { return lore != null && lore.size() > 0; } + @Override public List getLore() { return lore; } + @Override public void setEnchantments(Map enchantments) { if (enchantments == null) { this.enchantments.clear(); @@ -153,67 +171,83 @@ public class Icon { this.enchantments = enchantments; } + @Override public Map getEnchantments() { return new HashMap<>(enchantments); } + @Override public void addEnchantment(Enchantment ench) { addEnchantment(ench, 1); } + @Override public void addEnchantment(Enchantment ench, Integer level) { enchantments.put(ench, level); } + @Override public void removeEnchantment(Enchantment ench) { enchantments.remove(ench); } + @Override public void clearEnchantments() { enchantments.clear(); } + @Override public Color getColor() { return color; } + @Override public void setColor(Color color) { this.color = color; } + @Override public String getSkullOwner() { return skullOwner; } + @Override public void setSkullOwner(String skullOwner) { this.skullOwner = skullOwner; this.skullOwnerHasVariables = VariableManager.hasVariables(skullOwner); } + @Override public DyeColor getBannerColor() { return bannerColor; } + @Override public void setBannerColor(DyeColor bannerColor) { this.bannerColor = bannerColor; } + @Override public List getBannerPatterns() { return bannerPatterns; } + @Override public void setBannerPatterns(List bannerPatterns) { this.bannerPatterns = bannerPatterns; } + @Override public void setCloseOnClick(boolean closeOnClick) { this.closeOnClick = closeOnClick; } + @Override public void setClickHandler(ClickHandler clickHandler) { this.clickHandler = clickHandler; } + @Override public ClickHandler getClickHandler() { return clickHandler; } @@ -273,6 +307,7 @@ public class Icon { return output; } + @Override @SuppressWarnings("deprecation") public ItemStack createItemstack(Player pov) { @@ -341,6 +376,7 @@ public class Icon { return itemStack; } + @Override public boolean onClick(Player whoClicked) { if (clickHandler != null) { return clickHandler.onClick(whoClicked); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/IconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIconMenu.java similarity index 85% rename from Plugin/src/main/java/me/filoghost/chestcommands/api/IconMenu.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIconMenu.java index 38999ce..c656d80 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/IconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIconMenu.java @@ -12,7 +12,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.api; +package me.filoghost.chestcommands.internal; + +import java.util.Arrays; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -21,11 +23,10 @@ import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import me.filoghost.chestcommands.internal.MenuInventoryHolder; -import me.filoghost.chestcommands.util.Utils; +import me.filoghost.chestcommands.api.Icon; +import me.filoghost.chestcommands.api.IconMenu; import me.filoghost.chestcommands.util.Preconditions; - -import java.util.Arrays; +import me.filoghost.chestcommands.util.Utils; /* * MEMO: Raw slot numbers @@ -35,17 +36,18 @@ import java.util.Arrays; * ... * */ -public class IconMenu { +public class BasicIconMenu implements IconMenu { protected final String title; protected final Icon[] icons; - public IconMenu(String title, int rows) { + public BasicIconMenu(String title, int rows) { this.title = title; - icons = new Icon[rows * 9]; + icons = new BasicIcon[rows * 9]; } + @Override public void setIcon(int x, int y, Icon icon) { int slot = Utils.makePositive(y - 1) * 9 + Utils.makePositive(x - 1); if (slot >= 0 && slot < icons.length) { @@ -53,12 +55,14 @@ public class IconMenu { } } + @Override public void setIconRaw(int slot, Icon icon) { if (slot >= 0 && slot < icons.length) { icons[slot] = icon; } } + @Override public Icon getIcon(int x, int y) { int slot = Utils.makePositive(y - 1) * 9 + Utils.makePositive(x - 1); if (slot >= 0 && slot < icons.length) { @@ -68,6 +72,7 @@ public class IconMenu { return null; } + @Override public Icon getIconRaw(int slot) { if (slot >= 0 && slot < icons.length) { return icons[slot]; @@ -76,18 +81,22 @@ public class IconMenu { return null; } + @Override public int getRows() { return icons.length / 9; } + @Override public int getSize() { return icons.length; } + @Override public String getTitle() { return title; } + @Override public void open(Player player) { Preconditions.notNull(player, "player"); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java index b5fac25..96b27a2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java @@ -18,14 +18,13 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.MenuManager; -import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.bridge.EconomyBridge; import me.filoghost.chestcommands.util.MaterialsHelper; import me.filoghost.chestcommands.util.StringUtils; import java.util.List; -public class ExtendedIcon extends Icon { +public class ExtendedIcon extends BasicIcon { private String permission; private String permissionMessage; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java index 65a414b..531cbe3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java @@ -25,10 +25,10 @@ import org.bukkit.inventory.meta.ItemMeta; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.action.Action; -import me.filoghost.chestcommands.api.IconMenu; + import java.util.List; -public class ExtendedIconMenu extends IconMenu { +public class ExtendedIconMenu extends BasicIconMenu { private String fileName; private String permission; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java index e44de40..c0f2c90 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java @@ -18,16 +18,14 @@ import org.bukkit.Bukkit; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import me.filoghost.chestcommands.api.IconMenu; - /** * This class links an IconMenu with an Inventory, via InventoryHolder. */ public class MenuInventoryHolder implements InventoryHolder { - private final IconMenu iconMenu; + private final BasicIconMenu iconMenu; - public MenuInventoryHolder(IconMenu iconMenu) { + public MenuInventoryHolder(BasicIconMenu iconMenu) { this.iconMenu = iconMenu; } @@ -42,7 +40,7 @@ public class MenuInventoryHolder implements InventoryHolder { return Bukkit.createInventory(null, iconMenu.getSize()); } - public IconMenu getIconMenu() { + public BasicIconMenu getIconMenu() { return iconMenu; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index d93b9f3..747ba75 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -14,6 +14,9 @@ */ package me.filoghost.chestcommands.listener; +import java.util.HashMap; +import java.util.Map; + import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -28,8 +31,7 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.api.IconMenu; -import java.util.HashMap; -import java.util.Map; +import me.filoghost.chestcommands.internal.BasicIconMenu; public class InventoryListener implements Listener { @@ -62,7 +64,7 @@ public class InventoryListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) public void onLateInventoryClick(InventoryClickEvent event) { - IconMenu menu = MenuManager.getOpenMenu(event.getInventory()); + BasicIconMenu menu = MenuManager.getOpenMenu(event.getInventory()); if (menu == null) { return; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index fdd6fab..ccfc285 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -24,11 +24,11 @@ import org.bukkit.enchantments.Enchantment; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.action.Action; -import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.config.AsciiPlaceholders; import me.filoghost.chestcommands.config.ConfigUtil; import me.filoghost.chestcommands.internal.RunActionsClickHandler; import me.filoghost.chestcommands.internal.ExtendedIcon; +import me.filoghost.chestcommands.internal.BasicIcon; import me.filoghost.chestcommands.internal.RequiredItem; import me.filoghost.chestcommands.parser.EnchantmentParser.EnchantmentDetails; import me.filoghost.chestcommands.util.ErrorCollector; @@ -91,7 +91,7 @@ public class IconParser { } - public static Icon loadIconFromSection(ConfigurationSection section, String iconName, String menuFileName, ErrorCollector errorCollector) { + public static BasicIcon loadIconFromSection(ConfigurationSection section, String iconName, String menuFileName, ErrorCollector errorCollector) { Preconditions.notNull(section, "section"); // The icon is valid even without a Material diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java index 663fc86..f50901d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java @@ -22,11 +22,11 @@ import org.bukkit.configuration.ConfigurationSection; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.action.Action; -import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.config.ConfigUtil; import me.filoghost.chestcommands.config.yaml.PluginConfig; import me.filoghost.chestcommands.internal.ClickType; import me.filoghost.chestcommands.internal.ExtendedIconMenu; +import me.filoghost.chestcommands.internal.BasicIcon; import me.filoghost.chestcommands.internal.MenuSettings; import me.filoghost.chestcommands.internal.OpenTrigger; import me.filoghost.chestcommands.parser.IconParser.Coords; @@ -61,7 +61,7 @@ public class MenuParser { ConfigurationSection iconSection = config.getConfigurationSection(subSectionName); - Icon icon = IconParser.loadIconFromSection(iconSection, subSectionName, config.getFileName(), errorCollector); + BasicIcon icon = IconParser.loadIconFromSection(iconSection, subSectionName, config.getFileName(), errorCollector); Coords coords = IconParser.loadCoordsFromSection(iconSection); if (!coords.isSetX() || !coords.isSetY()) { diff --git a/pom.xml b/pom.xml index 9ae9475..6f417fe 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,7 @@ + API Plugin From ad009d5bc8be499112c22785153fb7dd8d02ff9d Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 20:46:40 +0200 Subject: [PATCH 043/213] Initial API rework --- .../chestcommands/api/ClickHandler.java | 5 +- .../me/filoghost/chestcommands/api/Icon.java | 16 +++-- .../filoghost/chestcommands/api/IconMenu.java | 18 +++--- .../api/internal/BackendAPI.java | 7 +++ .../chestcommands/StandardBackendAPI.java | 17 ++++++ .../chestcommands/internal/BasicIcon.java | 27 ++++----- .../chestcommands/internal/BasicIconMenu.java | 60 +++++++++---------- .../chestcommands/internal/ExtendedIcon.java | 10 ---- .../listener/InventoryListener.java | 2 +- .../chestcommands/parser/IconParser.java | 4 +- .../chestcommands/parser/MenuParser.java | 17 +++++- .../chestcommands/util/Preconditions.java | 11 ++++ .../filoghost/chestcommands/util/Utils.java | 4 -- 13 files changed, 117 insertions(+), 81 deletions(-) diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java b/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java index 2d32c59..f49176c 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java @@ -16,11 +16,12 @@ package me.filoghost.chestcommands.api; import org.bukkit.entity.Player; +@FunctionalInterface public interface ClickHandler { /** - * @param player - the player that clicked on the icon. - * @return true if the menu should be closed, false otherwise. + * @param player the player that clicked on the icon + * @return true if the menu should be closed right after, false otherwise */ public boolean onClick(Player player); diff --git a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java index 89ba2af..10f8e41 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java @@ -25,9 +25,13 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -public interface Icon { +import me.filoghost.chestcommands.api.internal.BackendAPI; - boolean hasVariables(); +public interface Icon { + + public static Icon create(Material material) { + return BackendAPI.getImplementation().createIcon(material); + } void setMaterial(Material material); @@ -37,9 +41,9 @@ public interface Icon { int getAmount(); - void setDataValue(short dataValue); + void setDurability(short durability); - short getDataValue(); + short getDurability(); void setNBTData(String nbtData); @@ -91,8 +95,8 @@ public interface Icon { ClickHandler getClickHandler(); - ItemStack createItemstack(Player pov); + ItemStack createItemstack(Player viewer); - boolean onClick(Player whoClicked); + boolean onClick(Player clicker); } \ No newline at end of file diff --git a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java index 3006e48..b5c3775 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java @@ -16,21 +16,23 @@ package me.filoghost.chestcommands.api; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.api.internal.BackendAPI; + public interface IconMenu { + + public static IconMenu create(String title, int rowCount) { + return BackendAPI.getImplementation().createIconMenu(title, rowCount); + } void setIcon(int x, int y, Icon icon); - void setIconRaw(int slot, Icon icon); - Icon getIcon(int x, int y); - Icon getIconRaw(int slot); - - int getRows(); - - int getSize(); - String getTitle(); + + int getRowCount(); + + int getColumnCount(); void open(Player player); diff --git a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java index 8d38b6a..96807ea 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java @@ -14,6 +14,9 @@ */ package me.filoghost.chestcommands.api.internal; +import org.bukkit.Material; + +import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.api.IconMenu; public abstract class BackendAPI { @@ -34,4 +37,8 @@ public abstract class BackendAPI { public abstract IconMenu getMenuByFileName(String yamlFile); + public abstract Icon createIcon(Material material); + + public abstract IconMenu createIconMenu(String title, int rows); + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/StandardBackendAPI.java b/Plugin/src/main/java/me/filoghost/chestcommands/StandardBackendAPI.java index 9eca817..4a969da 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/StandardBackendAPI.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/StandardBackendAPI.java @@ -14,8 +14,13 @@ */ package me.filoghost.chestcommands; +import org.bukkit.Material; + +import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.api.IconMenu; import me.filoghost.chestcommands.api.internal.BackendAPI; +import me.filoghost.chestcommands.internal.BasicIcon; +import me.filoghost.chestcommands.internal.BasicIconMenu; public class StandardBackendAPI extends BackendAPI { @@ -24,4 +29,16 @@ public class StandardBackendAPI extends BackendAPI { return ChestCommands.getInstance().getMenuManager().getMenuByFileName(yamlFile); } + @Override + public Icon createIcon(Material material) { + BasicIcon icon = new BasicIcon(); + icon.setMaterial(material); + return icon; + } + + @Override + public IconMenu createIconMenu(String title, int rows) { + return new BasicIconMenu(title, rows); + } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIcon.java index 138d7db..5a63ca3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIcon.java @@ -66,7 +66,6 @@ public class BasicIcon implements Icon { amount = 1; } - @Override public boolean hasVariables() { return nameHasVariables || loreLinesWithVariables != null || skullOwnerHasVariables; } @@ -96,14 +95,14 @@ public class BasicIcon implements Icon { } @Override - public void setDataValue(short dataValue) { + public void setDurability(short dataValue) { if (dataValue < 0) dataValue = 0; this.dataValue = dataValue; } @Override - public short getDataValue() { + public short getDurability() { return dataValue; } @@ -252,13 +251,13 @@ public class BasicIcon implements Icon { return clickHandler; } - protected String calculateName(Player pov) { + protected String calculateName(Player viewer) { if (hasName()) { String name = this.name; - if (pov != null && nameHasVariables) { - name = VariableManager.setVariables(name, pov); + if (viewer != null && nameHasVariables) { + name = VariableManager.setVariables(name, viewer); } if (name.isEmpty()) { @@ -272,7 +271,7 @@ public class BasicIcon implements Icon { return null; } - protected List calculateLore(Player pov) { + protected List calculateLore(Player viewer) { List output = null; @@ -280,11 +279,11 @@ public class BasicIcon implements Icon { output = new ArrayList<>(); - if (pov != null && loreLinesWithVariables != null) { + if (viewer != null && loreLinesWithVariables != null) { for (int i = 0; i < lore.size(); i++) { String line = lore.get(i); if (loreLinesWithVariables[i]) { - line = VariableManager.setVariables(line, pov); + line = VariableManager.setVariables(line, viewer); } output.add(line); } @@ -307,9 +306,8 @@ public class BasicIcon implements Icon { return output; } - @Override @SuppressWarnings("deprecation") - public ItemStack createItemstack(Player pov) { + public ItemStack createItemstack(Player viewer) { if (!this.hasVariables() && cachedItem != null) { // Performance @@ -334,10 +332,10 @@ public class BasicIcon implements Icon { ItemMeta itemMeta = itemStack.getItemMeta(); if (hasName()) { - itemMeta.setDisplayName(calculateName(pov)); + itemMeta.setDisplayName(calculateName(viewer)); } if (hasLore()) { - itemMeta.setLore(calculateLore(pov)); + itemMeta.setLore(calculateLore(viewer)); } if (color != null && itemMeta instanceof LeatherArmorMeta) { @@ -347,7 +345,7 @@ public class BasicIcon implements Icon { if (skullOwner != null && itemMeta instanceof SkullMeta) { String skullOwner = this.skullOwner; if(skullOwnerHasVariables) { - skullOwner = VariableManager.setVariables(skullOwner, pov); + skullOwner = VariableManager.setVariables(skullOwner, viewer); } ((SkullMeta) itemMeta).setOwner(skullOwner); } @@ -376,7 +374,6 @@ public class BasicIcon implements Icon { return itemStack; } - @Override public boolean onClick(Player whoClicked) { if (clickHandler != null) { return clickHandler.onClick(whoClicked); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIconMenu.java index c656d80..042f18e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIconMenu.java @@ -38,55 +38,53 @@ import me.filoghost.chestcommands.util.Utils; */ public class BasicIconMenu implements IconMenu { + + private static final int COLUMNS = 9; + private final int rows; protected final String title; protected final Icon[] icons; public BasicIconMenu(String title, int rows) { this.title = title; - icons = new BasicIcon[rows * 9]; + this.rows = rows; + icons = new BasicIcon[rows * COLUMNS]; } @Override public void setIcon(int x, int y, Icon icon) { - int slot = Utils.makePositive(y - 1) * 9 + Utils.makePositive(x - 1); - if (slot >= 0 && slot < icons.length) { - icons[slot] = icon; - } - } - - @Override - public void setIconRaw(int slot, Icon icon) { - if (slot >= 0 && slot < icons.length) { - icons[slot] = icon; - } + icons[getSlotIndex(x, y)] = icon; } @Override public Icon getIcon(int x, int y) { - int slot = Utils.makePositive(y - 1) * 9 + Utils.makePositive(x - 1); - if (slot >= 0 && slot < icons.length) { - return icons[slot]; - } + return getIconAtSlot(getSlotIndex(x, y)); + } + + public Icon getIconAtSlot(int slot) { + Preconditions.checkIndex(slot, getSize(), "slot"); + return icons[slot]; + } - return null; + public int getSlotIndex(int x, int y) { + Preconditions.checkIndex(x, getColumnCount(), "x"); + Preconditions.checkIndex(y, getRowCount(), "y"); + + int slot = y * getColumnCount() + x; + Preconditions.checkIndex(slot, getSize(), "slot"); + return slot; } @Override - public Icon getIconRaw(int slot) { - if (slot >= 0 && slot < icons.length) { - return icons[slot]; - } - - return null; + public int getRowCount() { + return rows; + } + + @Override + public int getColumnCount() { + return COLUMNS; } - @Override - public int getRows() { - return icons.length / 9; - } - - @Override public int getSize() { return icons.length; } @@ -100,7 +98,7 @@ public class BasicIconMenu implements IconMenu { public void open(Player player) { Preconditions.notNull(player, "player"); - Inventory inventory = Bukkit.createInventory(new MenuInventoryHolder(this), icons.length, title); + Inventory inventory = Bukkit.createInventory(new MenuInventoryHolder(this), getSize(), title); for (int i = 0; i < icons.length; i++) { if (icons[i] != null) { @@ -129,4 +127,6 @@ public class BasicIconMenu implements IconMenu { public String toString() { return "IconMenu [title=" + title + ", icons=" + Arrays.toString(icons) + "]"; } + + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java index 96b27a2..4f5e60a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java @@ -129,16 +129,6 @@ public class ExtendedIcon extends BasicIcon { this.requiredItems = requiredItems; } - @Override - public String calculateName(Player pov) { - return super.calculateName(pov); - } - - @Override - public List calculateLore(Player pov) { - return super.calculateLore(pov); - } - @Override public boolean onClick(Player player) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index 747ba75..392a096 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -77,7 +77,7 @@ public class InventoryListener implements Listener { return; } - Icon icon = menu.getIconRaw(slot); + Icon icon = menu.getIconAtSlot(slot); if (icon == null || event.getInventory().getItem(slot) == null) { return; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index ccfc285..d5009a1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -102,7 +102,7 @@ public class IconParser { try { ItemStackParser itemReader = new ItemStackParser(material, true); icon.setMaterial(itemReader.getMaterial()); - icon.setDataValue(itemReader.getDataValue()); + icon.setDurability(itemReader.getDataValue()); icon.setAmount(itemReader.getAmount()); } catch (FormatException e) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid ID: " + e.getMessage()); @@ -115,7 +115,7 @@ public class IconParser { Integer durability = ConfigUtil.getAnyInt(section, Nodes.DURABILITY); if (durability != null) { - icon.setDataValue(durability.shortValue()); + icon.setDurability(durability.shortValue()); } String nbtData = ConfigUtil.getAnyString(section, Nodes.NBT_DATA); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java index f50901d..4bdc323 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java @@ -63,17 +63,28 @@ public class MenuParser { BasicIcon icon = IconParser.loadIconFromSection(iconSection, subSectionName, config.getFileName(), errorCollector); Coords coords = IconParser.loadCoordsFromSection(iconSection); + + int actualX = coords.getX() - 1; + int actualY = coords.getY() - 1; if (!coords.isSetX() || !coords.isSetY()) { errorCollector.addError("The icon \"" + subSectionName + "\" in the menu \"" + config.getFileName() + " is missing POSITION-X and/or POSITION-Y."); continue; + } + if (actualX < 0 || actualX >= iconMenu.getColumnCount()) { + errorCollector.addError("The icon \"" + subSectionName + "\" in the menu \"" + config.getFileName() + " has an invalid POSITION-X: it must be between 1 and " + iconMenu.getColumnCount() + " (was " + coords.getX() + ")."); + continue; } - - if (iconMenu.getIcon(coords.getX(), coords.getY()) != null) { + if (actualY < 0 || actualY >= iconMenu.getRowCount()) { + errorCollector.addError("The icon \"" + subSectionName + "\" in the menu \"" + config.getFileName() + " has an invalid POSITION-Y: it must be between 1 and " + iconMenu.getRowCount() + " (was " + coords.getY() + ")."); + continue; + } + + if (iconMenu.getIcon(actualX, actualY) != null) { errorCollector.addError("The icon \"" + subSectionName + "\" in the menu \"" + config.getFileName() + " is overriding another icon with the same position."); } - iconMenu.setIcon(coords.getX(), coords.getY(), icon); + iconMenu.setIcon(actualX, actualY, icon); } return iconMenu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Preconditions.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Preconditions.java index d662fe7..e4d434b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Preconditions.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Preconditions.java @@ -37,6 +37,17 @@ public final class Preconditions { throw new IllegalStateException(errorMessage); } } + + public static void checkIndex(int index, int size, String objectName) { + checkArgument(size >= 0, "size cannot be negative"); + + if (index < 0) { + throw new IndexOutOfBoundsException(objectName + " (" + index + ") cannot be negative"); + } + if (index >= size) { + throw new IndexOutOfBoundsException(objectName + " (" + index + ") must be less than size (" + size + ")"); + } + } public static void checkArgumentNotAir(Material material, String objectName) { notNull(material, objectName); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java index 77d824b..c300d0c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java @@ -20,10 +20,6 @@ public final class Utils { private Utils() {} - public static int makePositive(int i) { - return i < 0 ? 0 : i; - } - public static boolean isClassLoaded(String name) { try { Class.forName(name); From f7fdca0d07f4ed5918a98108f325e0a8cc18b730 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 20:49:35 +0200 Subject: [PATCH 044/213] Remove unnecessary try-catch block --- .../internal/ExtendedIconMenu.java | 83 ++++++++----------- 1 file changed, 36 insertions(+), 47 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java index 531cbe3..795d4f0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java @@ -15,7 +15,6 @@ package me.filoghost.chestcommands.internal; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; @@ -68,31 +67,26 @@ public class ExtendedIconMenu extends BasicIconMenu { @Override public void open(Player player) { - try { - if (openActions != null) { - for (Action openAction : openActions) { - openAction.execute(player); - } + if (openActions != null) { + for (Action openAction : openActions) { + openAction.execute(player); } - - Inventory inventory = Bukkit.createInventory(new MenuInventoryHolder(this), icons.length, title); - - for (int i = 0; i < icons.length; i++) { - if (icons[i] != null) { - - if (icons[i] instanceof ExtendedIcon && !((ExtendedIcon) icons[i]).canViewIcon(player)) { - continue; - } - - inventory.setItem(i, hideAttributes(icons[i].createItemstack(player))); - } - } - - player.openInventory(inventory); - } catch (Exception e) { - e.printStackTrace(); - player.sendMessage(ChatColor.RED + "An internal error occurred while opening the menu. The staff should check the console for errors."); } + + Inventory inventory = Bukkit.createInventory(new MenuInventoryHolder(this), icons.length, title); + + for (int i = 0; i < icons.length; i++) { + if (icons[i] != null) { + + if (icons[i] instanceof ExtendedIcon && !((ExtendedIcon) icons[i]).canViewIcon(player)) { + continue; + } + + inventory.setItem(i, hideAttributes(icons[i].createItemstack(player))); + } + } + + player.openInventory(inventory); } public void openCheckingPermission(Player player) { @@ -104,36 +98,31 @@ public class ExtendedIconMenu extends BasicIconMenu { } public void refresh(Player player, Inventory inventory) { - try { - for (int i = 0; i < icons.length; i++) { - if (icons[i] != null && icons[i] instanceof ExtendedIcon) { - ExtendedIcon extIcon = (ExtendedIcon) icons[i]; + for (int i = 0; i < icons.length; i++) { + if (icons[i] != null && icons[i] instanceof ExtendedIcon) { + ExtendedIcon extIcon = (ExtendedIcon) icons[i]; - if (extIcon.hasViewPermission() || extIcon.hasVariables()) { - // Then we have to refresh it - if (extIcon.canViewIcon(player)) { - - if (inventory.getItem(i) == null) { - ItemStack newItem = hideAttributes(extIcon.createItemstack(player)); - inventory.setItem(i, newItem); - } else { - // Performance, only update name and lore - ItemStack oldItem = hideAttributes(inventory.getItem(i)); - ItemMeta meta = oldItem.getItemMeta(); - meta.setDisplayName(extIcon.calculateName(player)); - meta.setLore(extIcon.calculateLore(player)); - oldItem.setItemMeta(meta); - } + if (extIcon.hasViewPermission() || extIcon.hasVariables()) { + // Then we have to refresh it + if (extIcon.canViewIcon(player)) { + if (inventory.getItem(i) == null) { + ItemStack newItem = hideAttributes(extIcon.createItemstack(player)); + inventory.setItem(i, newItem); } else { - inventory.setItem(i, null); + // Performance, only update name and lore + ItemStack oldItem = hideAttributes(inventory.getItem(i)); + ItemMeta meta = oldItem.getItemMeta(); + meta.setDisplayName(extIcon.calculateName(player)); + meta.setLore(extIcon.calculateLore(player)); + oldItem.setItemMeta(meta); } + + } else { + inventory.setItem(i, null); } } } - } catch (Exception e) { - e.printStackTrace(); - player.sendMessage(ChatColor.RED + "An internal error occurred while refreshing the menu. The staff should check the console for errors."); } } From 10a1b8522a961e080a98cd9202adc5e5e603e6bf Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 20:52:39 +0200 Subject: [PATCH 045/213] Cleanup Javadocs --- .../me/filoghost/chestcommands/api/ChestCommandsAPI.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java index d36940c..ee9e52c 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java @@ -25,7 +25,7 @@ public class ChestCommandsAPI { /** * Checks if a menu with a given file name was loaded by the plugin. * - * @return true - if the menu was found. + * @return if the menu was found */ public static boolean isPluginMenu(String yamlFile) { return BackendAPI.getImplementation().getMenuByFileName(yamlFile) != null; @@ -35,9 +35,9 @@ public class ChestCommandsAPI { * Opens a menu loaded by ChestCommands to a player. * NOTE: this method ignores permissions. * - * @param player - the player that will see the GUI. - * @param yamlFile - the file name of the menu to open. The .yml extension CANNOT be omitted. - * @return true - if the menu was found and opened, false if not. + * @param player the player that will see the menu + * @param yamlFile the file name of the menu to open (with the .yml extension) + * @return if the menu was found and opened */ public static boolean openPluginMenu(Player player, String yamlFile) { IconMenu menu = BackendAPI.getImplementation().getMenuByFileName(yamlFile); From 02b915021d9fe3a7fb7da190564e76e5e072fa0b Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Jun 2020 20:57:45 +0200 Subject: [PATCH 046/213] Change method name --- .../java/me/filoghost/chestcommands/api/Icon.java | 4 ++-- .../chestcommands/internal/BasicIcon.java | 14 +++++++------- .../filoghost/chestcommands/parser/IconParser.java | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java index 10f8e41..cdde85a 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java @@ -73,9 +73,9 @@ public interface Icon { void clearEnchantments(); - Color getColor(); + Color getLeatherColor(); - void setColor(Color color); + void setLeatherColor(Color leatherColor); String getSkullOwner(); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIcon.java index 5a63ca3..40db3a0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIcon.java @@ -47,7 +47,7 @@ public class BasicIcon implements Icon { private String name; private List lore; private Map enchantments; - private Color color; + private Color leatherColor; private String skullOwner; private DyeColor bannerColor; private List bannerPatterns; @@ -196,13 +196,13 @@ public class BasicIcon implements Icon { } @Override - public Color getColor() { - return color; + public Color getLeatherColor() { + return leatherColor; } @Override - public void setColor(Color color) { - this.color = color; + public void setLeatherColor(Color leatherColor) { + this.leatherColor = leatherColor; } @Override @@ -338,8 +338,8 @@ public class BasicIcon implements Icon { itemMeta.setLore(calculateLore(viewer)); } - if (color != null && itemMeta instanceof LeatherArmorMeta) { - ((LeatherArmorMeta) itemMeta).setColor(color); + if (leatherColor != null && itemMeta instanceof LeatherArmorMeta) { + ((LeatherArmorMeta) itemMeta).setColor(leatherColor); } if (skullOwner != null && itemMeta instanceof SkullMeta) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index d5009a1..687e725 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -153,7 +153,7 @@ public class IconParser { if (section.isSet(Nodes.COLOR)) { try { - icon.setColor(ItemMetaParser.parseColor(section.getString(Nodes.COLOR))); + icon.setLeatherColor(ItemMetaParser.parseColor(section.getString(Nodes.COLOR))); } catch (FormatException e) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid COLOR: " + e.getMessage()); } From 37d46e6124b5fb6dbb4041453b39816a32060c09 Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 11 Jun 2020 18:19:54 +0200 Subject: [PATCH 047/213] API improvements --- .../chestcommands/api/ChestCommandsAPI.java | 11 +-- .../chestcommands/api/ClickHandler.java | 2 +- .../chestcommands/api/ClickResult.java | 23 +++++ .../chestcommands/api/ConfigurableIcon.java | 96 +++++++++++++++++++ .../me/filoghost/chestcommands/api/Icon.java | 80 +--------------- .../chestcommands/api/StaticIcon.java | 27 ++++++ .../api/internal/BackendAPI.java | 17 +++- .../chestcommands/ChestCommands.java | 4 +- .../filoghost/chestcommands/MenuManager.java | 35 ++++--- .../chestcommands/action/OpenMenuAction.java | 4 +- .../api/impl/BackendAPIImpl.java | 78 +++++++++++++++ .../impl/ConfigurableIconImpl.java} | 33 ++++--- .../impl/IconMenuImpl.java} | 33 ++----- .../chestcommands/command/CommandHandler.java | 4 +- .../{ExtendedIcon.java => AdvancedIcon.java} | 15 ++- ...dedIconMenu.java => AdvancedIconMenu.java} | 86 ++++++++--------- .../{BasicIconMenu.java => BaseIconMenu.java} | 75 +++++---------- .../chestcommands/internal/Grid.java | 82 ++++++++++++++++ .../internal/MenuInventoryHolder.java | 8 +- .../internal/RunActionsClickHandler.java | 16 ++-- .../listener/CommandListener.java | 4 +- .../listener/InventoryListener.java | 7 +- .../chestcommands/listener/SignListener.java | 7 +- .../chestcommands/parser/IconParser.java | 9 +- .../chestcommands/parser/MenuParser.java | 10 +- 25 files changed, 480 insertions(+), 286 deletions(-) create mode 100644 API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java create mode 100644 API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java create mode 100644 API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/api/impl/BackendAPIImpl.java rename Plugin/src/main/java/me/filoghost/chestcommands/{internal/BasicIcon.java => api/impl/ConfigurableIconImpl.java} (88%) rename Plugin/src/main/java/me/filoghost/chestcommands/{StandardBackendAPI.java => api/impl/IconMenuImpl.java} (50%) rename Plugin/src/main/java/me/filoghost/chestcommands/internal/{ExtendedIcon.java => AdvancedIcon.java} (94%) rename Plugin/src/main/java/me/filoghost/chestcommands/internal/{ExtendedIconMenu.java => AdvancedIconMenu.java} (60%) rename Plugin/src/main/java/me/filoghost/chestcommands/internal/{BasicIconMenu.java => BaseIconMenu.java} (56%) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/internal/Grid.java diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java index ee9e52c..a0a9c5c 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java @@ -28,7 +28,7 @@ public class ChestCommandsAPI { * @return if the menu was found */ public static boolean isPluginMenu(String yamlFile) { - return BackendAPI.getImplementation().getMenuByFileName(yamlFile) != null; + return BackendAPI.getImplementation().isPluginMenu(yamlFile); } /** @@ -40,13 +40,6 @@ public class ChestCommandsAPI { * @return if the menu was found and opened */ public static boolean openPluginMenu(Player player, String yamlFile) { - IconMenu menu = BackendAPI.getImplementation().getMenuByFileName(yamlFile); - - if (menu != null) { - menu.open(player); - return true; - } else { - return false; - } + return BackendAPI.getImplementation().openPluginMenu(player, yamlFile); } } diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java b/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java index f49176c..0292ea6 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java @@ -23,6 +23,6 @@ public interface ClickHandler { * @param player the player that clicked on the icon * @return true if the menu should be closed right after, false otherwise */ - public boolean onClick(Player player); + ClickResult onClick(Player player); } diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java b/API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java new file mode 100644 index 0000000..19f2c8e --- /dev/null +++ b/API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java @@ -0,0 +1,23 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.api; + +public enum ClickResult { + + DEFAULT, + KEEP_OPEN, + CLOSE + +} diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java b/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java new file mode 100644 index 0000000..5d2dbcb --- /dev/null +++ b/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java @@ -0,0 +1,96 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.api; + +import java.util.List; +import java.util.Map; + +import org.bukkit.Color; +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.block.banner.Pattern; +import org.bukkit.enchantments.Enchantment; + +import me.filoghost.chestcommands.api.internal.BackendAPI; + +public interface ConfigurableIcon extends Icon { + + public static ConfigurableIcon create(Material material) { + return BackendAPI.getImplementation().createConfigurableIcon(material); + } + + void setMaterial(Material material); + + Material getMaterial(); + + void setAmount(int amount); + + int getAmount(); + + void setDurability(short durability); + + short getDurability(); + + void setNBTData(String nbtData); + + String getNBTData(); + + void setName(String name); + + boolean hasName(); + + void setLore(String... lore); + + void setLore(List lore); + + boolean hasLore(); + + List getLore(); + + void setEnchantments(Map enchantments); + + Map getEnchantments(); + + void addEnchantment(Enchantment ench); + + void addEnchantment(Enchantment ench, Integer level); + + void removeEnchantment(Enchantment ench); + + void clearEnchantments(); + + Color getLeatherColor(); + + void setLeatherColor(Color leatherColor); + + String getSkullOwner(); + + void setSkullOwner(String skullOwner); + + DyeColor getBannerColor(); + + void setBannerColor(DyeColor bannerColor); + + List getBannerPatterns(); + + void setBannerPatterns(List bannerPatterns); + + void setCloseOnClick(boolean closeOnClick); + + void setClickHandler(ClickHandler clickHandler); + + ClickHandler getClickHandler(); + +} diff --git a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java index cdde85a..f07afce 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java @@ -14,89 +14,13 @@ */ package me.filoghost.chestcommands.api; -import java.util.List; -import java.util.Map; - -import org.bukkit.Color; -import org.bukkit.DyeColor; -import org.bukkit.Material; -import org.bukkit.block.banner.Pattern; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import me.filoghost.chestcommands.api.internal.BackendAPI; - public interface Icon { - - public static Icon create(Material material) { - return BackendAPI.getImplementation().createIcon(material); - } - void setMaterial(Material material); + ItemStack createItemStack(Player viewer); - Material getMaterial(); - - void setAmount(int amount); - - int getAmount(); - - void setDurability(short durability); - - short getDurability(); - - void setNBTData(String nbtData); - - String getNBTData(); - - void setName(String name); - - boolean hasName(); - - void setLore(String... lore); - - void setLore(List lore); - - boolean hasLore(); - - List getLore(); - - void setEnchantments(Map enchantments); - - Map getEnchantments(); - - void addEnchantment(Enchantment ench); - - void addEnchantment(Enchantment ench, Integer level); - - void removeEnchantment(Enchantment ench); - - void clearEnchantments(); - - Color getLeatherColor(); - - void setLeatherColor(Color leatherColor); - - String getSkullOwner(); - - void setSkullOwner(String skullOwner); - - DyeColor getBannerColor(); - - void setBannerColor(DyeColor bannerColor); - - List getBannerPatterns(); - - void setBannerPatterns(List bannerPatterns); - - void setCloseOnClick(boolean closeOnClick); - - void setClickHandler(ClickHandler clickHandler); - - ClickHandler getClickHandler(); - - ItemStack createItemstack(Player viewer); - - boolean onClick(Player clicker); + boolean onClick(Player clicker); } \ No newline at end of file diff --git a/API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java b/API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java new file mode 100644 index 0000000..dcf695f --- /dev/null +++ b/API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java @@ -0,0 +1,27 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.api; + +import org.bukkit.inventory.ItemStack; + +import me.filoghost.chestcommands.api.internal.BackendAPI; + +public interface StaticIcon extends Icon { + + public static StaticIcon create(ItemStack itemStack, boolean closeOnClick) { + return BackendAPI.getImplementation().createStaticIcon(itemStack, closeOnClick); + } + +} diff --git a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java index 96807ea..c2ffd62 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java @@ -15,9 +15,12 @@ package me.filoghost.chestcommands.api.internal; import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; -import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.api.IconMenu; +import me.filoghost.chestcommands.api.StaticIcon; +import me.filoghost.chestcommands.api.ConfigurableIcon; public abstract class BackendAPI { @@ -34,11 +37,17 @@ public abstract class BackendAPI { return implementation; } + + public abstract boolean isPluginMenu(String yamlFile); - public abstract IconMenu getMenuByFileName(String yamlFile); - - public abstract Icon createIcon(Material material); + public abstract boolean openPluginMenu(Player player, String yamlFile); public abstract IconMenu createIconMenu(String title, int rows); + + public abstract ConfigurableIcon createConfigurableIcon(Material material); + + public abstract StaticIcon createStaticIcon(ItemStack itemStack, boolean closeOnClick); + + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index ecb6a05..b6d5dfa 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -34,7 +34,7 @@ import me.filoghost.chestcommands.config.AsciiPlaceholders; import me.filoghost.chestcommands.config.Lang; import me.filoghost.chestcommands.config.Settings; import me.filoghost.chestcommands.config.yaml.PluginConfig; -import me.filoghost.chestcommands.internal.ExtendedIconMenu; +import me.filoghost.chestcommands.internal.AdvancedIconMenu; import me.filoghost.chestcommands.internal.MenuSettings; import me.filoghost.chestcommands.listener.CommandListener; import me.filoghost.chestcommands.listener.InventoryListener; @@ -198,7 +198,7 @@ public class ChestCommands extends JavaPlugin { } MenuSettings menuSettings = MenuParser.loadMenuSettings(menuConfig, errorCollector); - ExtendedIconMenu iconMenu = MenuParser.loadMenu(menuConfig, menuSettings.getTitle(), menuSettings.getRows(), errorCollector); + AdvancedIconMenu iconMenu = MenuParser.loadMenu(menuConfig, menuSettings.getTitle(), menuSettings.getRows(), errorCollector); menuManager.registerMenu(menuConfig.getFileName(), menuSettings.getCommands(), iconMenu, errorCollector); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java index 94a7a97..68fff64 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java @@ -25,9 +25,8 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; -import me.filoghost.chestcommands.api.IconMenu; -import me.filoghost.chestcommands.internal.ExtendedIconMenu; -import me.filoghost.chestcommands.internal.BasicIconMenu; +import me.filoghost.chestcommands.internal.AdvancedIconMenu; +import me.filoghost.chestcommands.internal.BaseIconMenu; import me.filoghost.chestcommands.internal.MenuInventoryHolder; import me.filoghost.chestcommands.internal.OpenTrigger; import me.filoghost.chestcommands.util.CaseInsensitiveMap; @@ -35,10 +34,10 @@ import me.filoghost.chestcommands.util.ErrorCollector; public class MenuManager { - private static Map fileNameToMenuMap; - private static Map commandsToMenuMap; + private static Map fileNameToMenuMap; + private static Map commandsToMenuMap; - private static Map openTriggers; + private static Map openTriggers; public MenuManager() { fileNameToMenuMap = CaseInsensitiveMap.create(); @@ -52,11 +51,11 @@ public class MenuManager { openTriggers.clear(); } - public ExtendedIconMenu getMenuByFileName(String fileName) { + public AdvancedIconMenu getMenuByFileName(String fileName) { return fileNameToMenuMap.get(fileName); } - public void registerMenu(String fileName, String[] triggerCommands, ExtendedIconMenu menu, ErrorCollector errorCollector) { + public void registerMenu(String fileName, String[] triggerCommands, AdvancedIconMenu menu, ErrorCollector errorCollector) { if (fileNameToMenuMap.containsKey(fileName)) { errorCollector.addError("Two menus have the same file name \"" + fileName + "\" with different cases. There will be problems opening one of these two menus."); } @@ -73,7 +72,7 @@ public class MenuManager { } } - public void registerTriggerItem(OpenTrigger openTrigger, ExtendedIconMenu menu) { + public void registerTriggerItem(OpenTrigger openTrigger, AdvancedIconMenu menu) { openTriggers.put(openTrigger, menu); } @@ -85,7 +84,7 @@ public class MenuManager { }); } - public ExtendedIconMenu getMenuByCommand(String command) { + public AdvancedIconMenu getMenuByCommand(String command) { return commandsToMenuMap.get(command); } @@ -102,13 +101,13 @@ public class MenuManager { } - public static IconMenu getOpenMenu(Player player) { + public static BaseIconMenu getOpenMenu(Player player) { InventoryView view = player.getOpenInventory(); if (view == null) { return null; } - IconMenu openMenu = getOpenMenu(view.getTopInventory()); + BaseIconMenu openMenu = getOpenMenu(view.getTopInventory()); if (openMenu == null) { openMenu = getOpenMenu(view.getBottomInventory()); } @@ -117,7 +116,7 @@ public class MenuManager { } - public static BasicIconMenu getOpenMenu(Inventory inventory) { + public static BaseIconMenu getOpenMenu(Inventory inventory) { if (!(inventory.getHolder() instanceof MenuInventoryHolder)) { return null; } @@ -147,25 +146,25 @@ public class MenuManager { } MenuInventoryHolder menuInventoryHolder = (MenuInventoryHolder) inventory.getHolder(); - if (!(menuInventoryHolder.getIconMenu() instanceof ExtendedIconMenu)) { + if (!(menuInventoryHolder.getIconMenu() instanceof AdvancedIconMenu)) { return null; } - return new MenuView((ExtendedIconMenu) menuInventoryHolder.getIconMenu(), inventory); + return new MenuView((AdvancedIconMenu) menuInventoryHolder.getIconMenu(), inventory); } public static class MenuView { - private final ExtendedIconMenu menu; + private final AdvancedIconMenu menu; private final Inventory inventory; - public MenuView(ExtendedIconMenu menu, Inventory inventory) { + public MenuView(AdvancedIconMenu menu, Inventory inventory) { this.menu = menu; this.inventory = inventory; } - public ExtendedIconMenu getMenu() { + public AdvancedIconMenu getMenu() { return menu; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java index 01026ad..9710acd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java @@ -19,7 +19,7 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.internal.ExtendedIconMenu; +import me.filoghost.chestcommands.internal.AdvancedIconMenu; public class OpenMenuAction extends Action { @@ -30,7 +30,7 @@ public class OpenMenuAction extends Action { @Override public void execute(final Player player) { String target = hasVariables ? getParsedAction(player) : action; - final ExtendedIconMenu menu = ChestCommands.getInstance().getMenuManager().getMenuByFileName(target.toLowerCase()); + final AdvancedIconMenu menu = ChestCommands.getInstance().getMenuManager().getMenuByFileName(target.toLowerCase()); if (menu != null) { /* diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/BackendAPIImpl.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/BackendAPIImpl.java new file mode 100644 index 0000000..9b81f91 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/BackendAPIImpl.java @@ -0,0 +1,78 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.api.impl; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import me.filoghost.chestcommands.api.IconMenu; +import me.filoghost.chestcommands.api.StaticIcon; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.api.ConfigurableIcon; +import me.filoghost.chestcommands.api.internal.BackendAPI; +import me.filoghost.chestcommands.internal.AdvancedIconMenu; + +public class BackendAPIImpl extends BackendAPI { + + @Override + public boolean isPluginMenu(String yamlFile) { + return ChestCommands.getInstance().getMenuManager().getMenuByFileName(yamlFile) != null; + } + + @Override + public boolean openPluginMenu(Player player, String yamlFile) { + AdvancedIconMenu menu = ChestCommands.getInstance().getMenuManager().getMenuByFileName(yamlFile); + + if (menu != null) { + menu.open(player); + return true; + } else { + return false; + } + } + + @Override + public ConfigurableIcon createConfigurableIcon(Material material) { + ConfigurableIconImpl icon = new ConfigurableIconImpl(); + icon.setMaterial(material); + return icon; + } + + @Override + public IconMenu createIconMenu(String title, int rows) { + return new IconMenuImpl(title, rows); + } + + @Override + public StaticIcon createStaticIcon(ItemStack itemStack, boolean closeOnClick) { + ItemStack itemStackCopy = itemStack.clone(); + + return new StaticIcon() { + + @Override + public ItemStack createItemStack(Player viewer) { + return itemStackCopy; + } + + @Override + public boolean onClick(Player clicker) { + return closeOnClick; + } + + }; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java similarity index 88% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIcon.java rename to Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java index 40db3a0..565a327 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.api.impl; import org.bukkit.*; import org.bukkit.block.banner.Pattern; @@ -26,7 +26,8 @@ import org.bukkit.inventory.meta.SkullMeta; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.api.ClickHandler; -import me.filoghost.chestcommands.api.Icon; +import me.filoghost.chestcommands.api.ClickResult; +import me.filoghost.chestcommands.api.ConfigurableIcon; import me.filoghost.chestcommands.variable.VariableManager; import java.util.ArrayList; @@ -37,7 +38,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.logging.Level; -public class BasicIcon implements Icon { +public class ConfigurableIconImpl implements ConfigurableIcon { private Material material; private int amount; @@ -60,7 +61,7 @@ public class BasicIcon implements Icon { private boolean skullOwnerHasVariables; private ItemStack cachedItem; // When there are no variables, we don't recreate the item - public BasicIcon() { + public ConfigurableIconImpl() { enchantments = new HashMap<>(); closeOnClick = true; amount = 1; @@ -251,7 +252,7 @@ public class BasicIcon implements Icon { return clickHandler; } - protected String calculateName(Player viewer) { + public String calculateName(Player viewer) { if (hasName()) { String name = this.name; @@ -271,7 +272,7 @@ public class BasicIcon implements Icon { return null; } - protected List calculateLore(Player viewer) { + public List calculateLore(Player viewer) { List output = null; @@ -306,8 +307,9 @@ public class BasicIcon implements Icon { return output; } + @Override @SuppressWarnings("deprecation") - public ItemStack createItemstack(Player viewer) { + public ItemStack createItemStack(Player viewer) { if (!this.hasVariables() && cachedItem != null) { // Performance @@ -374,11 +376,20 @@ public class BasicIcon implements Icon { return itemStack; } + @Override public boolean onClick(Player whoClicked) { - if (clickHandler != null) { - return clickHandler.onClick(whoClicked); + if (clickHandler == null) { + return closeOnClick; + } + + ClickResult result = clickHandler.onClick(whoClicked); + switch (result) { + case CLOSE: + return true; + case KEEP_OPEN: + return false; + default: + return closeOnClick; } - - return closeOnClick; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/StandardBackendAPI.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/IconMenuImpl.java similarity index 50% rename from Plugin/src/main/java/me/filoghost/chestcommands/StandardBackendAPI.java rename to Plugin/src/main/java/me/filoghost/chestcommands/api/impl/IconMenuImpl.java index 4a969da..bc940d4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/StandardBackendAPI.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/IconMenuImpl.java @@ -3,42 +3,27 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands; - -import org.bukkit.Material; +package me.filoghost.chestcommands.api.impl; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.api.IconMenu; -import me.filoghost.chestcommands.api.internal.BackendAPI; -import me.filoghost.chestcommands.internal.BasicIcon; -import me.filoghost.chestcommands.internal.BasicIconMenu; +import me.filoghost.chestcommands.internal.BaseIconMenu; -public class StandardBackendAPI extends BackendAPI { +public class IconMenuImpl extends BaseIconMenu implements IconMenu { - @Override - public IconMenu getMenuByFileName(String yamlFile) { - return ChestCommands.getInstance().getMenuManager().getMenuByFileName(yamlFile); - } - - @Override - public Icon createIcon(Material material) { - BasicIcon icon = new BasicIcon(); - icon.setMaterial(material); - return icon; - } - - @Override - public IconMenu createIconMenu(String title, int rows) { - return new BasicIconMenu(title, rows); + + public IconMenuImpl(String title, int rows) { + super(title, rows); } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index eccf3a8..0c8b386 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -25,7 +25,7 @@ import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.command.framework.CommandFramework; import me.filoghost.chestcommands.command.framework.CommandValidate; -import me.filoghost.chestcommands.internal.ExtendedIconMenu; +import me.filoghost.chestcommands.internal.AdvancedIconMenu; import me.filoghost.chestcommands.util.ErrorCollector; public class CommandHandler extends CommandFramework { @@ -105,7 +105,7 @@ public class CommandHandler extends CommandFramework { CommandValidate.notNull(target, "That player is not online."); String menuName = args[1].toLowerCase().endsWith(".yml") ? args[1] : args[1] + ".yml"; - ExtendedIconMenu menu = menuManager.getMenuByFileName(menuName); + AdvancedIconMenu menu = menuManager.getMenuByFileName(menuName); CommandValidate.notNull(menu, "The menu \"" + menuName + "\" was not found."); if (!sender.hasPermission(menu.getPermission())) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIcon.java similarity index 94% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIcon.java index 4f5e60a..b9f4b24 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIcon.java @@ -18,29 +18,26 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.MenuManager; +import me.filoghost.chestcommands.api.impl.ConfigurableIconImpl; import me.filoghost.chestcommands.bridge.EconomyBridge; import me.filoghost.chestcommands.util.MaterialsHelper; import me.filoghost.chestcommands.util.StringUtils; import java.util.List; -public class ExtendedIcon extends BasicIcon { +public class AdvancedIcon extends ConfigurableIconImpl { private String permission; - private String permissionMessage; - private String viewPermission; - private boolean permissionNegated; + private String permissionMessage; + + private String viewPermission; private boolean viewPermissionNegated; private double moneyPrice; private int expLevelsPrice; private List requiredItems; - - public ExtendedIcon() { - super(); - } - + private boolean canClickIcon(Player player) { if (permission == null) { return true; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIconMenu.java similarity index 60% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIconMenu.java index 795d4f0..b24e8c3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ExtendedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIconMenu.java @@ -14,7 +14,8 @@ */ package me.filoghost.chestcommands.internal; -import org.bukkit.Bukkit; +import java.util.List; + import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; @@ -24,22 +25,25 @@ import org.bukkit.inventory.meta.ItemMeta; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.action.Action; +import me.filoghost.chestcommands.api.Icon; -import java.util.List; +public class AdvancedIconMenu extends BaseIconMenu { -public class ExtendedIconMenu extends BasicIconMenu { - - private String fileName; + private final String fileName; + private String permission; private List openActions; - private int refreshTicks; - public ExtendedIconMenu(String title, int rows, String fileName) { + public AdvancedIconMenu(String title, int rows, String fileName) { super(title, rows); this.fileName = fileName; this.permission = Permissions.OPEN_MENU_BASE + fileName; } + + public String getFileName() { + return fileName; + } public List getOpenActions() { return openActions; @@ -53,10 +57,6 @@ public class ExtendedIconMenu extends BasicIconMenu { return permission; } - public String getFileName() { - return fileName; - } - public int getRefreshTicks() { return refreshTicks; } @@ -72,25 +72,21 @@ public class ExtendedIconMenu extends BasicIconMenu { openAction.execute(player); } } - - Inventory inventory = Bukkit.createInventory(new MenuInventoryHolder(this), icons.length, title); - - for (int i = 0; i < icons.length; i++) { - if (icons[i] != null) { - - if (icons[i] instanceof ExtendedIcon && !((ExtendedIcon) icons[i]).canViewIcon(player)) { - continue; - } - - inventory.setItem(i, hideAttributes(icons[i].createItemstack(player))); - } + + super.open(player); + } + + @Override + protected boolean canViewIcon(Player player, Icon icon) { + if (icon instanceof AdvancedIcon) { + return true; } - - player.openInventory(inventory); + + return ((AdvancedIcon) icon).canViewIcon(player); } public void openCheckingPermission(Player player) { - if (player.hasPermission(getPermission())) { + if (player.hasPermission(permission)) { open(player); } else { sendNoPermissionMessage(player); @@ -98,29 +94,27 @@ public class ExtendedIconMenu extends BasicIconMenu { } public void refresh(Player player, Inventory inventory) { - for (int i = 0; i < icons.length; i++) { - if (icons[i] != null && icons[i] instanceof ExtendedIcon) { - ExtendedIcon extIcon = (ExtendedIcon) icons[i]; - - if (extIcon.hasViewPermission() || extIcon.hasVariables()) { - // Then we have to refresh it - if (extIcon.canViewIcon(player)) { - - if (inventory.getItem(i) == null) { - ItemStack newItem = hideAttributes(extIcon.createItemstack(player)); - inventory.setItem(i, newItem); - } else { - // Performance, only update name and lore - ItemStack oldItem = hideAttributes(inventory.getItem(i)); - ItemMeta meta = oldItem.getItemMeta(); - meta.setDisplayName(extIcon.calculateName(player)); - meta.setLore(extIcon.calculateLore(player)); - oldItem.setItemMeta(meta); - } + for (int i = 0; i < inventoryGrid.getSize(); i++) { + AdvancedIcon icon = inventoryGrid.getElementAtIndex(i); + + if (icon.hasViewPermission() || icon.hasVariables()) { + // Then we have to refresh it + if (icon.canViewIcon(player)) { + if (inventory.getItem(i) == null) { + ItemStack newItem = hideAttributes(icon.createItemStack(player)); + inventory.setItem(i, newItem); } else { - inventory.setItem(i, null); + // Performance, only update name and lore + ItemStack oldItem = hideAttributes(inventory.getItem(i)); + ItemMeta meta = oldItem.getItemMeta(); + meta.setDisplayName(icon.calculateName(player)); + meta.setLore(icon.calculateLore(player)); + oldItem.setItemMeta(meta); } + + } else { + inventory.setItem(i, null); } } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BaseIconMenu.java similarity index 56% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIconMenu.java rename to Plugin/src/main/java/me/filoghost/chestcommands/internal/BaseIconMenu.java index 042f18e..0389aa0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BasicIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BaseIconMenu.java @@ -14,8 +14,6 @@ */ package me.filoghost.chestcommands.internal; -import java.util.Arrays; - import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; @@ -24,91 +22,69 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import me.filoghost.chestcommands.api.Icon; -import me.filoghost.chestcommands.api.IconMenu; import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.Utils; -/* - * MEMO: Raw slot numbers - * - * | 0| 1| 2| 3| 4| 5| 6| 7| 8| - * | 9|10|11|12|13|14|15|16|17| - * ... - * - */ -public class BasicIconMenu implements IconMenu { +public class BaseIconMenu { - private static final int COLUMNS = 9; - private final int rows; protected final String title; - protected final Icon[] icons; + protected final Grid inventoryGrid; - public BasicIconMenu(String title, int rows) { + public BaseIconMenu(String title, int rows) { this.title = title; - this.rows = rows; - icons = new BasicIcon[rows * COLUMNS]; + this.inventoryGrid = new Grid<>(rows, 9); } - @Override - public void setIcon(int x, int y, Icon icon) { - icons[getSlotIndex(x, y)] = icon; + public void setIcon(int x, int y, T icon) { + inventoryGrid.setElement(x, y, icon); } - @Override - public Icon getIcon(int x, int y) { - return getIconAtSlot(getSlotIndex(x, y)); + public T getIcon(int x, int y) { + return inventoryGrid.getElement(x, y); } - public Icon getIconAtSlot(int slot) { - Preconditions.checkIndex(slot, getSize(), "slot"); - return icons[slot]; + public T getIconAtSlot(int slot) { + return inventoryGrid.getElementAtIndex(slot); } - - public int getSlotIndex(int x, int y) { - Preconditions.checkIndex(x, getColumnCount(), "x"); - Preconditions.checkIndex(y, getRowCount(), "y"); - - int slot = y * getColumnCount() + x; - Preconditions.checkIndex(slot, getSize(), "slot"); - return slot; - } - - @Override + public int getRowCount() { - return rows; + return inventoryGrid.getRows(); } - @Override public int getColumnCount() { - return COLUMNS; + return inventoryGrid.getColumns(); } - + public int getSize() { - return icons.length; + return inventoryGrid.getSize(); } - @Override public String getTitle() { return title; } - @Override + public void open(Player player) { Preconditions.notNull(player, "player"); Inventory inventory = Bukkit.createInventory(new MenuInventoryHolder(this), getSize(), title); - for (int i = 0; i < icons.length; i++) { - if (icons[i] != null) { - inventory.setItem(i, hideAttributes(icons[i].createItemstack(player))); + for (int i = 0; i < inventoryGrid.getSize(); i++) { + Icon icon = inventoryGrid.getElementAtIndex(i); + if (icon != null && canViewIcon(player, icon)) { + inventory.setItem(i, hideAttributes(icon.createItemStack(player))); } } player.openInventory(inventory); } + protected boolean canViewIcon(Player player, Icon icon) { + return true; + } + protected ItemStack hideAttributes(ItemStack item) { if (item == null) { return null; @@ -125,8 +101,7 @@ public class BasicIconMenu implements IconMenu { @Override public String toString() { - return "IconMenu [title=" + title + ", icons=" + Arrays.toString(icons) + "]"; + return "IconMenu [title=" + title + ", icons=" + inventoryGrid + "]"; } - } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/Grid.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/Grid.java new file mode 100644 index 0000000..a0a97a6 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/Grid.java @@ -0,0 +1,82 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.internal; + +import me.filoghost.chestcommands.util.Preconditions; + +/* + * Example: + * There 3 rows and 9 columns. The number inside the cells is the index. + * + * <--- Column ---> + * + * 0 1 2 3 4 5 6 7 8 + * ^ +--------------------------------------------+ + * | 0 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | + * |----+----+----+----+----+----+----+----+----| + * Row 1 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | + * |----+----+----+----+----+----+----+----+----| + * | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | + * v +--------------------------------------------+ + * + */ +public class Grid { + + private final int rows, columns; + private final T[] elements; + + + @SuppressWarnings("unchecked") + public Grid(int rows, int columns) { + this.rows = rows; + this.columns = columns; + elements = (T[]) new Object[rows * columns]; + } + + public void setElement(int x, int y, T element) { + elements[getOrdinalIndex(x, y)] = element; + } + + public T getElement(int x, int y) { + return getElementAtIndex(getOrdinalIndex(x, y)); + } + + public T getElementAtIndex(int ordinalIndex) { + Preconditions.checkIndex(ordinalIndex, getSize(), "ordinalIndex"); + return elements[ordinalIndex]; + } + + private int getOrdinalIndex(int x, int y) { + Preconditions.checkIndex(x, getColumns(), "x"); + Preconditions.checkIndex(y, getRows(), "y"); + + int ordinalIndex = y * getColumns() + x; + Preconditions.checkIndex(ordinalIndex, getSize(), "ordinalIndex"); + return ordinalIndex; + } + + public int getRows() { + return rows; + } + + public int getColumns() { + return columns; + } + + public int getSize() { + return elements.length; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java index c0f2c90..6076956 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java @@ -23,9 +23,9 @@ import org.bukkit.inventory.InventoryHolder; */ public class MenuInventoryHolder implements InventoryHolder { - private final BasicIconMenu iconMenu; + private final BaseIconMenu iconMenu; - public MenuInventoryHolder(BasicIconMenu iconMenu) { + public MenuInventoryHolder(BaseIconMenu iconMenu) { this.iconMenu = iconMenu; } @@ -37,10 +37,10 @@ public class MenuInventoryHolder implements InventoryHolder { * because the only way you can get here is using InventoryClickEvent, * that is cancelled by ChestCommands, or using InventoryOpenEvent. */ - return Bukkit.createInventory(null, iconMenu.getSize()); + return Bukkit.createInventory(null, 9); } - public BasicIconMenu getIconMenu() { + public BaseIconMenu getIconMenu() { return iconMenu; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/RunActionsClickHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/RunActionsClickHandler.java index 387826b..7cdb14c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/RunActionsClickHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/RunActionsClickHandler.java @@ -19,37 +19,41 @@ import org.bukkit.entity.Player; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.OpenMenuAction; import me.filoghost.chestcommands.api.ClickHandler; +import me.filoghost.chestcommands.api.ClickResult; import java.util.List; public class RunActionsClickHandler implements ClickHandler { private List actions; - private boolean closeOnClick; + private boolean forceClose; - public RunActionsClickHandler(List actions, boolean closeOnClick) { + public RunActionsClickHandler(List actions) { this.actions = actions; - this.closeOnClick = closeOnClick; if (actions != null && actions.size() > 0) { for (Action action : actions) { if (action instanceof OpenMenuAction) { // Fix GUI closing if KEEP-OPEN is not set, and a command should open another GUI - this.closeOnClick = false; + this.forceClose = true; } } } } @Override - public boolean onClick(Player player) { + public ClickResult onClick(Player player) { if (actions != null && actions.size() > 0) { for (Action action : actions) { action.execute(player); } } + + if (forceClose) { + return ClickResult.CLOSE; + } - return closeOnClick; + return ClickResult.DEFAULT; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java index cd18f1d..2e4e7de 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java @@ -20,7 +20,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import me.filoghost.chestcommands.MenuManager; -import me.filoghost.chestcommands.internal.ExtendedIconMenu; +import me.filoghost.chestcommands.internal.AdvancedIconMenu; public class CommandListener implements Listener { @@ -38,7 +38,7 @@ public class CommandListener implements Listener { return; } - ExtendedIconMenu menu = menuManager.getMenuByCommand(command); + AdvancedIconMenu menu = menuManager.getMenuByCommand(command); if (menu == null) { return; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index 392a096..fd1ecb4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -30,8 +30,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.api.Icon; -import me.filoghost.chestcommands.api.IconMenu; -import me.filoghost.chestcommands.internal.BasicIconMenu; +import me.filoghost.chestcommands.internal.BaseIconMenu; public class InventoryListener implements Listener { @@ -53,7 +52,7 @@ public class InventoryListener implements Listener { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) public void onEarlyInventoryClick(InventoryClickEvent event) { - IconMenu menu = MenuManager.getOpenMenu(event.getInventory()); + BaseIconMenu menu = MenuManager.getOpenMenu(event.getInventory()); if (menu == null) { return; } @@ -64,7 +63,7 @@ public class InventoryListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) public void onLateInventoryClick(InventoryClickEvent event) { - BasicIconMenu menu = MenuManager.getOpenMenu(event.getInventory()); + BaseIconMenu menu = MenuManager.getOpenMenu(event.getInventory()); if (menu == null) { return; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java index b2208c5..6c02376 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java @@ -28,8 +28,7 @@ import org.bukkit.event.player.PlayerInteractEvent; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.Permissions; -import me.filoghost.chestcommands.api.IconMenu; -import me.filoghost.chestcommands.internal.ExtendedIconMenu; +import me.filoghost.chestcommands.internal.AdvancedIconMenu; import me.filoghost.chestcommands.util.FileUtils; public class SignListener implements Listener { @@ -67,7 +66,7 @@ public class SignListener implements Listener { } String menuFileName = FileUtils.addYamlExtension(sign.getLine(FILENAME_LINE).trim()); - ExtendedIconMenu menu = menuManager.getMenuByFileName(menuFileName); + AdvancedIconMenu menu = menuManager.getMenuByFileName(menuFileName); if (menu == null) { event.getPlayer().sendMessage(ChestCommands.getLang().menu_not_found); @@ -90,7 +89,7 @@ public class SignListener implements Listener { menuFileName = FileUtils.addYamlExtension(menuFileName); - IconMenu iconMenu = menuManager.getMenuByFileName(menuFileName); + AdvancedIconMenu iconMenu = menuManager.getMenuByFileName(menuFileName); if (iconMenu == null) { event.setCancelled(true); event.getPlayer().sendMessage(ChatColor.RED + "Menu \"" + menuFileName + "\" was not found."); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index 687e725..84fa08c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -27,8 +27,7 @@ import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.config.AsciiPlaceholders; import me.filoghost.chestcommands.config.ConfigUtil; import me.filoghost.chestcommands.internal.RunActionsClickHandler; -import me.filoghost.chestcommands.internal.ExtendedIcon; -import me.filoghost.chestcommands.internal.BasicIcon; +import me.filoghost.chestcommands.internal.AdvancedIcon; import me.filoghost.chestcommands.internal.RequiredItem; import me.filoghost.chestcommands.parser.EnchantmentParser.EnchantmentDetails; import me.filoghost.chestcommands.util.ErrorCollector; @@ -91,11 +90,11 @@ public class IconParser { } - public static BasicIcon loadIconFromSection(ConfigurationSection section, String iconName, String menuFileName, ErrorCollector errorCollector) { + public static AdvancedIcon loadIconFromSection(ConfigurationSection section, String iconName, String menuFileName, ErrorCollector errorCollector) { Preconditions.notNull(section, "section"); // The icon is valid even without a Material - ExtendedIcon icon = new ExtendedIcon(); + AdvancedIcon icon = new AdvancedIcon(); String material = ConfigUtil.getAnyString(section, Nodes.MATERIAL); if (material != null) { @@ -197,7 +196,7 @@ public class IconParser { } if (!actions.isEmpty()) { - icon.setClickHandler(new RunActionsClickHandler(actions, closeOnClick)); + icon.setClickHandler(new RunActionsClickHandler(actions)); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java index 4bdc323..3d77792 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java @@ -24,9 +24,9 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.config.ConfigUtil; import me.filoghost.chestcommands.config.yaml.PluginConfig; +import me.filoghost.chestcommands.internal.AdvancedIcon; +import me.filoghost.chestcommands.internal.AdvancedIconMenu; import me.filoghost.chestcommands.internal.ClickType; -import me.filoghost.chestcommands.internal.ExtendedIconMenu; -import me.filoghost.chestcommands.internal.BasicIcon; import me.filoghost.chestcommands.internal.MenuSettings; import me.filoghost.chestcommands.internal.OpenTrigger; import me.filoghost.chestcommands.parser.IconParser.Coords; @@ -51,8 +51,8 @@ public class MenuParser { } - public static ExtendedIconMenu loadMenu(PluginConfig config, String title, int rows, ErrorCollector errorCollector) { - ExtendedIconMenu iconMenu = new ExtendedIconMenu(title, rows, config.getFileName()); + public static AdvancedIconMenu loadMenu(PluginConfig config, String title, int rows, ErrorCollector errorCollector) { + AdvancedIconMenu iconMenu = new AdvancedIconMenu(title, rows, config.getFileName()); for (String subSectionName : config.getKeys(false)) { if (subSectionName.equals("menu-settings")) { @@ -61,7 +61,7 @@ public class MenuParser { ConfigurationSection iconSection = config.getConfigurationSection(subSectionName); - BasicIcon icon = IconParser.loadIconFromSection(iconSection, subSectionName, config.getFileName(), errorCollector); + AdvancedIcon icon = IconParser.loadIconFromSection(iconSection, subSectionName, config.getFileName(), errorCollector); Coords coords = IconParser.loadCoordsFromSection(iconSection); int actualX = coords.getX() - 1; From a48121dbad047ec5bf2314626a3ef50109c192f9 Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 11 Jun 2020 18:24:58 +0200 Subject: [PATCH 048/213] Rename BungeeCordBridge --- .../me/filoghost/chestcommands/action/ChangeServerAction.java | 4 ++-- .../{bungee/BungeeCordUtils.java => BungeeCordBridge.java} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/bridge/{bungee/BungeeCordUtils.java => BungeeCordBridge.java} (92%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java index ede31c2..a7233f0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java @@ -16,7 +16,7 @@ package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.bridge.bungee.BungeeCordUtils; +import me.filoghost.chestcommands.bridge.BungeeCordBridge; public class ChangeServerAction extends Action { @@ -26,7 +26,7 @@ public class ChangeServerAction extends Action { @Override public void execute(Player player) { - BungeeCordUtils.connect(player, hasVariables ? getParsedAction(player) : action); + BungeeCordBridge.connect(player, hasVariables ? getParsedAction(player) : action); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/bungee/BungeeCordUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/BungeeCordBridge.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/bridge/bungee/BungeeCordUtils.java rename to Plugin/src/main/java/me/filoghost/chestcommands/bridge/BungeeCordBridge.java index 5cd4b4b..a4a1939 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/bungee/BungeeCordUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/BungeeCordBridge.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.bridge.bungee; +package me.filoghost.chestcommands.bridge; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -23,7 +23,7 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; -public class BungeeCordUtils { +public class BungeeCordBridge { public static boolean connect(Player player, String server) { if (server.length() == 0) { From 27c05ece6acdf63fc5c9fbf3ac6ba73d184b73b5 Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 11 Jun 2020 18:29:09 +0200 Subject: [PATCH 049/213] Cleanup --- .../chestcommands/internal/AdvancedIconMenu.java | 9 ++------- .../filoghost/chestcommands/internal/BaseIconMenu.java | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIconMenu.java index b24e8c3..5a94e07 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIconMenu.java @@ -25,7 +25,6 @@ import org.bukkit.inventory.meta.ItemMeta; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.action.Action; -import me.filoghost.chestcommands.api.Icon; public class AdvancedIconMenu extends BaseIconMenu { @@ -77,12 +76,8 @@ public class AdvancedIconMenu extends BaseIconMenu { } @Override - protected boolean canViewIcon(Player player, Icon icon) { - if (icon instanceof AdvancedIcon) { - return true; - } - - return ((AdvancedIcon) icon).canViewIcon(player); + protected boolean canViewIcon(Player player, AdvancedIcon icon) { + return icon.canViewIcon(player); } public void openCheckingPermission(Player player) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BaseIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BaseIconMenu.java index 0389aa0..f5264a0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BaseIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/BaseIconMenu.java @@ -72,7 +72,7 @@ public class BaseIconMenu { Inventory inventory = Bukkit.createInventory(new MenuInventoryHolder(this), getSize(), title); for (int i = 0; i < inventoryGrid.getSize(); i++) { - Icon icon = inventoryGrid.getElementAtIndex(i); + T icon = inventoryGrid.getElementAtIndex(i); if (icon != null && canViewIcon(player, icon)) { inventory.setItem(i, hideAttributes(icon.createItemStack(player))); } @@ -81,7 +81,7 @@ public class BaseIconMenu { player.openInventory(inventory); } - protected boolean canViewIcon(Player player, Icon icon) { + protected boolean canViewIcon(Player player, T icon) { return true; } From 93724b50964141c552a966fc005dfb3ef0e4244b Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 11 Jun 2020 18:39:10 +0200 Subject: [PATCH 050/213] Refactoring --- .../chestcommands/command/CommandHandler.java | 9 ++- .../chestcommands/internal/AdvancedIcon.java | 36 ++++++++++- .../chestcommands/internal/RequiredItem.java | 12 ++-- .../internal/RunActionsClickHandler.java | 59 ------------------- .../chestcommands/parser/IconParser.java | 3 +- 5 files changed, 45 insertions(+), 74 deletions(-) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/internal/RunActionsClickHandler.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index 0c8b386..fa10621 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -89,17 +89,16 @@ public class CommandHandler extends CommandFramework { Player target = null; - if (!(sender instanceof Player)) { - CommandValidate.minLength(args, 3, "You must specify a player from the console."); - target = Bukkit.getPlayerExact(args[2]); - } else { + if (sender instanceof Player) { if (args.length > 2) { CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "open.others"), "You don't have permission to open menus for others."); target = Bukkit.getPlayerExact(args[2]); } else { target = (Player) sender; } - + } else { + CommandValidate.minLength(args, 3, "You must specify a player from the console."); + target = Bukkit.getPlayerExact(args[2]); } CommandValidate.notNull(target, "That player is not online."); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIcon.java index b9f4b24..fe88417 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIcon.java @@ -18,6 +18,8 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.MenuManager; +import me.filoghost.chestcommands.action.Action; +import me.filoghost.chestcommands.action.OpenMenuAction; import me.filoghost.chestcommands.api.impl.ConfigurableIconImpl; import me.filoghost.chestcommands.bridge.EconomyBridge; import me.filoghost.chestcommands.util.MaterialsHelper; @@ -37,6 +39,8 @@ public class AdvancedIcon extends ConfigurableIconImpl { private double moneyPrice; private int expLevelsPrice; private List requiredItems; + private List clickActions; + private boolean hasOpenMenuAction; private boolean canClickIcon(Player player) { if (permission == null) { @@ -126,6 +130,24 @@ public class AdvancedIcon extends ConfigurableIconImpl { this.requiredItems = requiredItems; } + public List getClickActions() { + return clickActions; + } + + public void setClickActions(List clickActions) { + this.clickActions = clickActions; + + hasOpenMenuAction = false; + if (clickActions != null) { + for (Action action : clickActions) { + if (action instanceof OpenMenuAction) { + // Fix GUI closing if KEEP-OPEN is not set, and a command should open another GUI + hasOpenMenuAction = true; + } + } + } + } + @Override public boolean onClick(Player player) { @@ -162,7 +184,7 @@ public class AdvancedIcon extends ConfigurableIconImpl { if (requiredItems != null) { boolean notHasItem = false; for (RequiredItem item : requiredItems) { - if (!item.hasItem(player)) { + if (!item.isItemContainedIn(player.getInventory())) { notHasItem = true; player.sendMessage(ChestCommands.getLang().no_required_item .replace("{material}", MaterialsHelper.formatMaterial(item.getMaterial())) @@ -194,13 +216,23 @@ public class AdvancedIcon extends ConfigurableIconImpl { if (requiredItems != null) { for (RequiredItem item : requiredItems) { - item.takeItem(player); + item.takeItemFrom(player.getInventory()); } } if (changedVariables) { MenuManager.refreshOpenMenu(player); } + + if (clickActions != null) { + for (Action action : clickActions) { + action.execute(player); + } + } + + if (hasOpenMenuAction) { + return false; + } return super.onClick(player); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java index 306b94f..b45ea3b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java @@ -15,7 +15,7 @@ package me.filoghost.chestcommands.internal; import org.bukkit.Material; -import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import me.filoghost.chestcommands.util.Preconditions; @@ -62,10 +62,10 @@ public class RequiredItem { return data == this.dataValue; } - public boolean hasItem(Player player) { + public boolean isItemContainedIn(Inventory inventory) { int amountFound = 0; - for (ItemStack item : player.getInventory().getContents()) { + for (ItemStack item : inventory.getContents()) { if (item != null && item.getType() == material && isValidDataValue(item.getDurability())) { amountFound += item.getAmount(); } @@ -74,14 +74,14 @@ public class RequiredItem { return amountFound >= amount; } - public boolean takeItem(Player player) { + public boolean takeItemFrom(Inventory inventory) { if (amount <= 0) { return true; } int itemsToTake = amount; //start from amount and decrease - ItemStack[] contents = player.getInventory().getContents(); + ItemStack[] contents = inventory.getContents(); ItemStack current = null; @@ -95,7 +95,7 @@ public class RequiredItem { return true; } else { itemsToTake -= current.getAmount(); - player.getInventory().setItem(i, new ItemStack(Material.AIR)); + inventory.setItem(i, new ItemStack(Material.AIR)); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/RunActionsClickHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/RunActionsClickHandler.java deleted file mode 100644 index 7cdb14c..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/RunActionsClickHandler.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.internal; - -import org.bukkit.entity.Player; - -import me.filoghost.chestcommands.action.Action; -import me.filoghost.chestcommands.action.OpenMenuAction; -import me.filoghost.chestcommands.api.ClickHandler; -import me.filoghost.chestcommands.api.ClickResult; - -import java.util.List; - -public class RunActionsClickHandler implements ClickHandler { - - private List actions; - private boolean forceClose; - - public RunActionsClickHandler(List actions) { - this.actions = actions; - - if (actions != null && actions.size() > 0) { - for (Action action : actions) { - if (action instanceof OpenMenuAction) { - // Fix GUI closing if KEEP-OPEN is not set, and a command should open another GUI - this.forceClose = true; - } - } - } - } - - @Override - public ClickResult onClick(Player player) { - if (actions != null && actions.size() > 0) { - for (Action action : actions) { - action.execute(player); - } - } - - if (forceClose) { - return ClickResult.CLOSE; - } - - return ClickResult.DEFAULT; - } - -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index 84fa08c..e210962 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -26,7 +26,6 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.config.AsciiPlaceholders; import me.filoghost.chestcommands.config.ConfigUtil; -import me.filoghost.chestcommands.internal.RunActionsClickHandler; import me.filoghost.chestcommands.internal.AdvancedIcon; import me.filoghost.chestcommands.internal.RequiredItem; import me.filoghost.chestcommands.parser.EnchantmentParser.EnchantmentDetails; @@ -196,7 +195,7 @@ public class IconParser { } if (!actions.isEmpty()) { - icon.setClickHandler(new RunActionsClickHandler(actions)); + icon.setClickActions(actions); } } From d1ab1fefc7de0d352f72bc7bcf7ebfbe6dbed8c5 Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 11 Jun 2020 20:36:36 +0200 Subject: [PATCH 051/213] Rename data value to durability --- .../api/impl/ConfigurableIconImpl.java | 12 +++++----- .../filoghost/chestcommands/config/Lang.java | 4 ++-- .../chestcommands/internal/AdvancedIcon.java | 2 +- .../chestcommands/internal/RequiredItem.java | 22 +++++++++---------- .../chestcommands/parser/IconParser.java | 6 ++--- .../chestcommands/parser/ItemStackParser.java | 22 +++++++++---------- .../chestcommands/parser/MenuParser.java | 4 ++-- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java index 565a327..02a83ff 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java @@ -42,7 +42,7 @@ public class ConfigurableIconImpl implements ConfigurableIcon { private Material material; private int amount; - private short dataValue; + private short durability; private String nbtData; private String name; @@ -96,15 +96,15 @@ public class ConfigurableIconImpl implements ConfigurableIcon { } @Override - public void setDurability(short dataValue) { - if (dataValue < 0) dataValue = 0; + public void setDurability(short durability) { + if (durability < 0) durability = 0; - this.dataValue = dataValue; + this.durability = durability; } @Override public short getDurability() { - return dataValue; + return durability; } @Override @@ -317,7 +317,7 @@ public class ConfigurableIconImpl implements ConfigurableIcon { } // If the material is not set, display BEDROCK - ItemStack itemStack = (material != null) ? new ItemStack(material, amount, dataValue) : new ItemStack(Material.BEDROCK, amount); + ItemStack itemStack = (material != null) ? new ItemStack(material, amount, durability) : new ItemStack(Material.BEDROCK, amount); // First try to apply NBT data if (nbtData != null) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java index 6e3ae12..863ea51 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java @@ -21,13 +21,13 @@ public class Lang extends SpecialConfig { public String no_open_permission = "&cYou don't have permission &e{permission} &cto use this menu."; public String default_no_icon_permission = "&cYou don't have permission for this icon."; - public String no_required_item = "&cYou must have &e{amount}x {material} &c(data value: {datavalue}) for this."; + public String no_required_item = "&cYou must have &e{amount}x {material} &c(durability: {datavalue}) for this."; public String no_money = "&cYou need {money}$ for this."; public String no_exp = "&cYou need {levels} XP levels for this."; public String menu_not_found = "&cMenu not found! Please inform the staff."; public String open_menu = "&aOpening the menu \"{menu}\"."; public String open_menu_others = "&aOpening the menu \"{menu}\" to {player}."; - public String any = "any"; // Used in no_required_item when data value is not restrictive + public String any = "any"; // Used in no_required_item when durability is not restrictive public Lang(PluginConfig config) { super(config); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIcon.java index fe88417..a47fcdb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIcon.java @@ -189,7 +189,7 @@ public class AdvancedIcon extends ConfigurableIconImpl { player.sendMessage(ChestCommands.getLang().no_required_item .replace("{material}", MaterialsHelper.formatMaterial(item.getMaterial())) .replace("{amount}", Integer.toString(item.getAmount())) - .replace("{datavalue}", item.hasRestrictiveDataValue() ? Short.toString(item.getDataValue()) : ChestCommands.getLang().any) + .replace("{datavalue}", item.hasRestrictiveDurability() ? Short.toString(item.getDurability()) : ChestCommands.getLang().any) ); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java index b45ea3b..b3a8867 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java @@ -24,7 +24,7 @@ public class RequiredItem { private Material material; private int amount; - private short dataValue; + private short durability; private boolean isDurabilityRestrictive = false; public RequiredItem(Material material, int amount) { @@ -42,31 +42,31 @@ public class RequiredItem { return amount; } - public short getDataValue() { - return dataValue; + public short getDurability() { + return durability; } - public void setRestrictiveDataValue(short data) { - Preconditions.checkArgument(data >= 0, "Data value cannot be negative"); + public void setRestrictiveDurability(short durability) { + Preconditions.checkArgument(durability >= 0, "Durability cannot be negative"); - this.dataValue = data; + this.durability = durability; isDurabilityRestrictive = true; } - public boolean hasRestrictiveDataValue() { + public boolean hasRestrictiveDurability() { return isDurabilityRestrictive; } - private boolean isValidDataValue(short data) { + private boolean isMatchingDurability(short data) { if (!isDurabilityRestrictive) return true; - return data == this.dataValue; + return data == this.durability; } public boolean isItemContainedIn(Inventory inventory) { int amountFound = 0; for (ItemStack item : inventory.getContents()) { - if (item != null && item.getType() == material && isValidDataValue(item.getDurability())) { + if (item != null && item.getType() == material && isMatchingDurability(item.getDurability())) { amountFound += item.getAmount(); } } @@ -89,7 +89,7 @@ public class RequiredItem { current = contents[i]; - if (current != null && current.getType() == material && isValidDataValue(current.getDurability())) { + if (current != null && current.getType() == material && isMatchingDurability(current.getDurability())) { if (current.getAmount() > itemsToTake) { current.setAmount(current.getAmount() - itemsToTake); return true; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index e210962..3030393 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -100,7 +100,7 @@ public class IconParser { try { ItemStackParser itemReader = new ItemStackParser(material, true); icon.setMaterial(itemReader.getMaterial()); - icon.setDurability(itemReader.getDataValue()); + icon.setDurability(itemReader.getDurability()); icon.setAmount(itemReader.getAmount()); } catch (FormatException e) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid ID: " + e.getMessage()); @@ -222,8 +222,8 @@ public class IconParser { try { ItemStackParser itemReader = new ItemStackParser(serializedItem, true); RequiredItem requiredItem = new RequiredItem(itemReader.getMaterial(), itemReader.getAmount()); - if (itemReader.hasExplicitDataValue()) { - requiredItem.setRestrictiveDataValue(itemReader.getDataValue()); + if (itemReader.hasExplicitDurability()) { + requiredItem.setRestrictiveDurability(itemReader.getDurability()); } requiredItems.add(requiredItem); } catch (FormatException e) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java index 39ff42f..cd69254 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java @@ -24,8 +24,8 @@ public class ItemStackParser { private Material material = Material.STONE; // In the worst case (bad exception handling) we just get stone private int amount = 1; - private short dataValue = 0; - private boolean explicitDataValue = false; + private short durability = 0; + private boolean hasExplicitDurability = false; /** * Reads item in the format "id:data, amount" @@ -51,14 +51,14 @@ public class ItemStackParser { } - // Read the optional data value + // Read the optional durability String[] splitByColons = input.split(":"); if (splitByColons.length > 1) { - short dataValue = NumberParser.getPositiveShort(splitByColons[1], "invalid data value \"" + splitByColons[1] + "\""); + short durability = NumberParser.getPositiveShort(splitByColons[1], "invalid durability \"" + splitByColons[1] + "\""); - this.explicitDataValue = true; - this.dataValue = dataValue; + this.hasExplicitDurability = true; + this.durability = durability; // Only keep the first part as input input = splitByColons[0]; @@ -80,16 +80,16 @@ public class ItemStackParser { return amount; } - public short getDataValue() { - return dataValue; + public short getDurability() { + return durability; } - public boolean hasExplicitDataValue() { - return explicitDataValue; + public boolean hasExplicitDurability() { + return hasExplicitDurability; } public ItemStack createStack() { - return new ItemStack(material, amount, dataValue); + return new ItemStack(material, amount, durability); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java index 3d77792..b5b5bb2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java @@ -154,8 +154,8 @@ public class MenuParser { OpenTrigger openTrigger = new OpenTrigger(itemReader.getMaterial(), clickType); - if (itemReader.hasExplicitDataValue()) { - openTrigger.setRestrictiveDurability(itemReader.getDataValue()); + if (itemReader.hasExplicitDurability()) { + openTrigger.setRestrictiveDurability(itemReader.getDurability()); } } catch (FormatException e) { From 2b0dbfb00c0b81a9ef91ff92b7f472bf456570ac Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 11 Jun 2020 20:41:29 +0200 Subject: [PATCH 052/213] Change some class packages --- .../java/me/filoghost/chestcommands/ChestCommands.java | 4 ++-- .../java/me/filoghost/chestcommands/MenuManager.java | 8 ++++---- .../filoghost/chestcommands/action/OpenMenuAction.java | 2 +- .../chestcommands/api/impl/BackendAPIImpl.java | 2 +- .../filoghost/chestcommands/api/impl/IconMenuImpl.java | 2 +- .../chestcommands/command/CommandHandler.java | 2 +- .../chestcommands/listener/CommandListener.java | 2 +- .../chestcommands/listener/InventoryListener.java | 2 +- .../filoghost/chestcommands/listener/SignListener.java | 2 +- .../chestcommands/{internal => menu}/AdvancedIcon.java | 2 +- .../{internal => menu}/AdvancedIconMenu.java | 2 +- .../chestcommands/{internal => menu}/BaseIconMenu.java | 2 +- .../chestcommands/{internal => menu}/Grid.java | 2 +- .../{internal => menu}/MenuInventoryHolder.java | 2 +- .../chestcommands/{internal => menu}/RequiredItem.java | 2 +- .../{internal => menu/settings}/ClickType.java | 2 +- .../{internal => menu/settings}/MenuSettings.java | 2 +- .../{internal => menu/settings}/OpenTrigger.java | 2 +- .../me/filoghost/chestcommands/parser/IconParser.java | 4 ++-- .../me/filoghost/chestcommands/parser/MenuParser.java | 10 +++++----- 20 files changed, 29 insertions(+), 29 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal => menu}/AdvancedIcon.java (95%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal => menu}/AdvancedIconMenu.java (95%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal => menu}/BaseIconMenu.java (94%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal => menu}/Grid.java (95%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal => menu}/MenuInventoryHolder.java (94%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal => menu}/RequiredItem.java (94%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal => menu/settings}/ClickType.java (93%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal => menu/settings}/MenuSettings.java (93%) rename Plugin/src/main/java/me/filoghost/chestcommands/{internal => menu/settings}/OpenTrigger.java (93%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index b6d5dfa..a4b1d21 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -34,12 +34,12 @@ import me.filoghost.chestcommands.config.AsciiPlaceholders; import me.filoghost.chestcommands.config.Lang; import me.filoghost.chestcommands.config.Settings; import me.filoghost.chestcommands.config.yaml.PluginConfig; -import me.filoghost.chestcommands.internal.AdvancedIconMenu; -import me.filoghost.chestcommands.internal.MenuSettings; import me.filoghost.chestcommands.listener.CommandListener; import me.filoghost.chestcommands.listener.InventoryListener; import me.filoghost.chestcommands.listener.JoinListener; import me.filoghost.chestcommands.listener.SignListener; +import me.filoghost.chestcommands.menu.AdvancedIconMenu; +import me.filoghost.chestcommands.menu.settings.MenuSettings; import me.filoghost.chestcommands.parser.MenuParser; import me.filoghost.chestcommands.task.RefreshMenusTask; import me.filoghost.chestcommands.util.FileUtils; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java index 68fff64..b2f50d3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java @@ -25,10 +25,10 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; -import me.filoghost.chestcommands.internal.AdvancedIconMenu; -import me.filoghost.chestcommands.internal.BaseIconMenu; -import me.filoghost.chestcommands.internal.MenuInventoryHolder; -import me.filoghost.chestcommands.internal.OpenTrigger; +import me.filoghost.chestcommands.menu.AdvancedIconMenu; +import me.filoghost.chestcommands.menu.BaseIconMenu; +import me.filoghost.chestcommands.menu.MenuInventoryHolder; +import me.filoghost.chestcommands.menu.settings.OpenTrigger; import me.filoghost.chestcommands.util.CaseInsensitiveMap; import me.filoghost.chestcommands.util.ErrorCollector; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java index 9710acd..52e9ad9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java @@ -19,7 +19,7 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.internal.AdvancedIconMenu; +import me.filoghost.chestcommands.menu.AdvancedIconMenu; public class OpenMenuAction extends Action { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/BackendAPIImpl.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/BackendAPIImpl.java index 9b81f91..9d5edfe 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/BackendAPIImpl.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/BackendAPIImpl.java @@ -23,7 +23,7 @@ import me.filoghost.chestcommands.api.StaticIcon; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.api.ConfigurableIcon; import me.filoghost.chestcommands.api.internal.BackendAPI; -import me.filoghost.chestcommands.internal.AdvancedIconMenu; +import me.filoghost.chestcommands.menu.AdvancedIconMenu; public class BackendAPIImpl extends BackendAPI { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/IconMenuImpl.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/IconMenuImpl.java index bc940d4..2092527 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/IconMenuImpl.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/IconMenuImpl.java @@ -16,7 +16,7 @@ package me.filoghost.chestcommands.api.impl; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.api.IconMenu; -import me.filoghost.chestcommands.internal.BaseIconMenu; +import me.filoghost.chestcommands.menu.BaseIconMenu; public class IconMenuImpl extends BaseIconMenu implements IconMenu { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index fa10621..85e861c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -25,7 +25,7 @@ import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.command.framework.CommandFramework; import me.filoghost.chestcommands.command.framework.CommandValidate; -import me.filoghost.chestcommands.internal.AdvancedIconMenu; +import me.filoghost.chestcommands.menu.AdvancedIconMenu; import me.filoghost.chestcommands.util.ErrorCollector; public class CommandHandler extends CommandFramework { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java index 2e4e7de..df81549 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java @@ -20,7 +20,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import me.filoghost.chestcommands.MenuManager; -import me.filoghost.chestcommands.internal.AdvancedIconMenu; +import me.filoghost.chestcommands.menu.AdvancedIconMenu; public class CommandListener implements Listener { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index fd1ecb4..5646a99 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -30,7 +30,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.api.Icon; -import me.filoghost.chestcommands.internal.BaseIconMenu; +import me.filoghost.chestcommands.menu.BaseIconMenu; public class InventoryListener implements Listener { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java index 6c02376..5f0acda 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java @@ -28,7 +28,7 @@ import org.bukkit.event.player.PlayerInteractEvent; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.Permissions; -import me.filoghost.chestcommands.internal.AdvancedIconMenu; +import me.filoghost.chestcommands.menu.AdvancedIconMenu; import me.filoghost.chestcommands.util.FileUtils; public class SignListener implements Listener { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java similarity index 95% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIcon.java rename to Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java index a47fcdb..b6471ac 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.menu; import org.bukkit.ChatColor; import org.bukkit.entity.Player; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java similarity index 95% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIconMenu.java rename to Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java index 5a94e07..5ea2d03 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/AdvancedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.menu; import java.util.List; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BaseIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java similarity index 94% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/BaseIconMenu.java rename to Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java index f5264a0..569c614 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/BaseIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.menu; import org.bukkit.Bukkit; import org.bukkit.entity.Player; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/Grid.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/Grid.java similarity index 95% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/Grid.java rename to Plugin/src/main/java/me/filoghost/chestcommands/menu/Grid.java index a0a97a6..d76714a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/Grid.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/Grid.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.menu; import me.filoghost.chestcommands.util.Preconditions; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuInventoryHolder.java similarity index 94% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java rename to Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuInventoryHolder.java index 6076956..d413341 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuInventoryHolder.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuInventoryHolder.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.menu; import org.bukkit.Bukkit; import org.bukkit.inventory.Inventory; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/RequiredItem.java similarity index 94% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java rename to Plugin/src/main/java/me/filoghost/chestcommands/menu/RequiredItem.java index b3a8867..b6be637 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/RequiredItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/RequiredItem.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.menu; import org.bukkit.Material; import org.bukkit.inventory.Inventory; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ClickType.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/ClickType.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/ClickType.java rename to Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/ClickType.java index 434d75d..6765eb6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/ClickType.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/ClickType.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.menu.settings; import org.bukkit.event.block.Action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/MenuSettings.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuSettings.java rename to Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/MenuSettings.java index 756d1eb..aa9b365 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/MenuSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/MenuSettings.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.menu.settings; import me.filoghost.chestcommands.action.Action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/OpenTrigger.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/OpenTrigger.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/internal/OpenTrigger.java rename to Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/OpenTrigger.java index 1ba0be9..fd8c23a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/OpenTrigger.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/OpenTrigger.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.internal; +package me.filoghost.chestcommands.menu.settings; import org.bukkit.Material; import org.bukkit.event.block.Action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index 3030393..edd1b6e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -26,8 +26,8 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.config.AsciiPlaceholders; import me.filoghost.chestcommands.config.ConfigUtil; -import me.filoghost.chestcommands.internal.AdvancedIcon; -import me.filoghost.chestcommands.internal.RequiredItem; +import me.filoghost.chestcommands.menu.AdvancedIcon; +import me.filoghost.chestcommands.menu.RequiredItem; import me.filoghost.chestcommands.parser.EnchantmentParser.EnchantmentDetails; import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.FormatUtils; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java index b5b5bb2..824eb2d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java @@ -24,11 +24,11 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.config.ConfigUtil; import me.filoghost.chestcommands.config.yaml.PluginConfig; -import me.filoghost.chestcommands.internal.AdvancedIcon; -import me.filoghost.chestcommands.internal.AdvancedIconMenu; -import me.filoghost.chestcommands.internal.ClickType; -import me.filoghost.chestcommands.internal.MenuSettings; -import me.filoghost.chestcommands.internal.OpenTrigger; +import me.filoghost.chestcommands.menu.AdvancedIcon; +import me.filoghost.chestcommands.menu.AdvancedIconMenu; +import me.filoghost.chestcommands.menu.settings.ClickType; +import me.filoghost.chestcommands.menu.settings.MenuSettings; +import me.filoghost.chestcommands.menu.settings.OpenTrigger; import me.filoghost.chestcommands.parser.IconParser.Coords; import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.FormatUtils; From e4a29bae1f10ff8dcc3041b99567a466289fe4ed Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 11 Jun 2020 20:57:00 +0200 Subject: [PATCH 053/213] Refactoring --- .../me/filoghost/chestcommands/api/Icon.java | 3 +- .../filoghost/chestcommands/MenuManager.java | 8 ---- .../api/impl/BackendAPIImpl.java | 7 +-- .../api/impl/ConfigurableIconImpl.java | 27 +++++++----- .../chestcommands/bridge/EconomyBridge.java | 5 --- .../listener/InventoryListener.java | 6 ++- .../chestcommands/menu/AdvancedIcon.java | 44 ++++++++++--------- 7 files changed, 50 insertions(+), 50 deletions(-) diff --git a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java index f07afce..d1e7f07 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java @@ -15,12 +15,13 @@ package me.filoghost.chestcommands.api; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; public interface Icon { ItemStack createItemStack(Player viewer); - boolean onClick(Player clicker); + boolean onClick(Inventory inventory, Player clicker); } \ No newline at end of file diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java index b2f50d3..3ec6fd6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java @@ -93,14 +93,6 @@ public class MenuManager { } - public static void refreshOpenMenu(Player player) { - MenuView openMenuView = getOpenMenuView(player); - if (openMenuView != null) { - openMenuView.getMenu().refresh(player, openMenuView.getInventory()); - } - } - - public static BaseIconMenu getOpenMenu(Player player) { InventoryView view = player.getOpenInventory(); if (view == null) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/BackendAPIImpl.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/BackendAPIImpl.java index 9d5edfe..b7d4004 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/BackendAPIImpl.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/BackendAPIImpl.java @@ -16,12 +16,13 @@ package me.filoghost.chestcommands.api.impl; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -import me.filoghost.chestcommands.api.IconMenu; -import me.filoghost.chestcommands.api.StaticIcon; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.api.ConfigurableIcon; +import me.filoghost.chestcommands.api.IconMenu; +import me.filoghost.chestcommands.api.StaticIcon; import me.filoghost.chestcommands.api.internal.BackendAPI; import me.filoghost.chestcommands.menu.AdvancedIconMenu; @@ -68,7 +69,7 @@ public class BackendAPIImpl extends BackendAPI { } @Override - public boolean onClick(Player clicker) { + public boolean onClick(Inventory inventory, Player clicker) { return closeOnClick; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java index 02a83ff..446a143 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java @@ -14,10 +14,23 @@ */ package me.filoghost.chestcommands.api.impl; -import org.bukkit.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.logging.Level; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Color; +import org.bukkit.DyeColor; +import org.bukkit.Material; import org.bukkit.block.banner.Pattern; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BannerMeta; import org.bukkit.inventory.meta.ItemMeta; @@ -30,14 +43,6 @@ import me.filoghost.chestcommands.api.ClickResult; import me.filoghost.chestcommands.api.ConfigurableIcon; import me.filoghost.chestcommands.variable.VariableManager; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.logging.Level; - public class ConfigurableIconImpl implements ConfigurableIcon { private Material material; @@ -377,12 +382,12 @@ public class ConfigurableIconImpl implements ConfigurableIcon { } @Override - public boolean onClick(Player whoClicked) { + public boolean onClick(Inventory inventory, Player clicker) { if (clickHandler == null) { return closeOnClick; } - ClickResult result = clickHandler.onClick(whoClicked); + ClickResult result = clickHandler.onClick(clicker); switch (result) { case CLOSE: return true; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java index c97e91b..8ed17f3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java @@ -18,7 +18,6 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.RegisteredServiceProvider; -import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.util.Preconditions; import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.EconomyResponse; @@ -71,8 +70,6 @@ public class EconomyBridge { EconomyResponse response = economy.withdrawPlayer(player, player.getWorld().getName(), amount); boolean result = response.transactionSuccess(); - MenuManager.refreshOpenMenu(player); - return result; } @@ -83,8 +80,6 @@ public class EconomyBridge { EconomyResponse response = economy.depositPlayer(player, player.getWorld().getName(), amount); boolean result = response.transactionSuccess(); - MenuManager.refreshOpenMenu(player); - return result; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index 5646a99..8e4a73a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -26,6 +26,7 @@ import org.bukkit.event.block.Action; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.Inventory; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.MenuManager; @@ -63,7 +64,8 @@ public class InventoryListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) public void onLateInventoryClick(InventoryClickEvent event) { - BaseIconMenu menu = MenuManager.getOpenMenu(event.getInventory()); + Inventory inventory = event.getInventory(); + BaseIconMenu menu = MenuManager.getOpenMenu(inventory); if (menu == null) { return; } @@ -97,7 +99,7 @@ public class InventoryListener implements Listener { // Only handle the click AFTER the event has finished Bukkit.getScheduler().runTask(ChestCommands.getInstance(), () -> { - boolean close = icon.onClick(clicker); + boolean close = icon.onClick(inventory, clicker); if (close) { clicker.closeInventory(); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java index b6471ac..813749c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java @@ -14,19 +14,22 @@ */ package me.filoghost.chestcommands.menu; +import java.util.List; + import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.action.Action; +import me.filoghost.chestcommands.action.GiveMoneyAction; import me.filoghost.chestcommands.action.OpenMenuAction; import me.filoghost.chestcommands.api.impl.ConfigurableIconImpl; import me.filoghost.chestcommands.bridge.EconomyBridge; import me.filoghost.chestcommands.util.MaterialsHelper; import me.filoghost.chestcommands.util.StringUtils; -import java.util.List; - public class AdvancedIcon extends ConfigurableIconImpl { private String permission; @@ -40,7 +43,6 @@ public class AdvancedIcon extends ConfigurableIconImpl { private int expLevelsPrice; private List requiredItems; private List clickActions; - private boolean hasOpenMenuAction; private boolean canClickIcon(Player player) { if (permission == null) { @@ -136,20 +138,10 @@ public class AdvancedIcon extends ConfigurableIconImpl { public void setClickActions(List clickActions) { this.clickActions = clickActions; - - hasOpenMenuAction = false; - if (clickActions != null) { - for (Action action : clickActions) { - if (action instanceof OpenMenuAction) { - // Fix GUI closing if KEEP-OPEN is not set, and a command should open another GUI - hasOpenMenuAction = true; - } - } - } } @Override - public boolean onClick(Player player) { + public boolean onClick(Inventory inventory, Player player) { // Check all the requirements @@ -219,22 +211,34 @@ public class AdvancedIcon extends ConfigurableIconImpl { item.takeItemFrom(player.getInventory()); } } - - if (changedVariables) { - MenuManager.refreshOpenMenu(player); - } + + boolean hasOpenMenuAction = false; if (clickActions != null) { for (Action action : clickActions) { action.execute(player); + + if (action instanceof OpenMenuAction) { + hasOpenMenuAction = true; + } else if (action instanceof GiveMoneyAction) { + changedVariables = true; + } } } + if (changedVariables) { + BaseIconMenu menu = MenuManager.getOpenMenu(inventory); + if (menu instanceof AdvancedIconMenu) { + ((AdvancedIconMenu) menu).refresh(player, inventory); + } + } + + // Force menu to stay open if actions open another menu if (hasOpenMenuAction) { return false; + } else { + return closeOnClick; } - - return super.onClick(player); } From e9961833aec38724fb6e5f3e520e18dee9cba37c Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 13 Jun 2020 19:14:45 +0200 Subject: [PATCH 054/213] Move classes --- .../chestcommands/ChestCommands.java | 1 + .../chestcommands/command/CommandHandler.java | 2 +- .../listener/CommandListener.java | 2 +- .../listener/InventoryListener.java | 2 +- .../chestcommands/listener/SignListener.java | 2 +- .../chestcommands/menu/AdvancedIcon.java | 1 - .../chestcommands/{ => menu}/MenuManager.java | 26 +------------ .../chestcommands/menu/MenuView.java | 37 +++++++++++++++++++ .../chestcommands/task/RefreshMenusTask.java | 5 ++- 9 files changed, 46 insertions(+), 32 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/{ => menu}/MenuManager.java (85%) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuView.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index a4b1d21..a8a865c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -39,6 +39,7 @@ import me.filoghost.chestcommands.listener.InventoryListener; import me.filoghost.chestcommands.listener.JoinListener; import me.filoghost.chestcommands.listener.SignListener; import me.filoghost.chestcommands.menu.AdvancedIconMenu; +import me.filoghost.chestcommands.menu.MenuManager; import me.filoghost.chestcommands.menu.settings.MenuSettings; import me.filoghost.chestcommands.parser.MenuParser; import me.filoghost.chestcommands.task.RefreshMenusTask; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index 85e861c..70f086d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -21,11 +21,11 @@ import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.command.framework.CommandFramework; import me.filoghost.chestcommands.command.framework.CommandValidate; import me.filoghost.chestcommands.menu.AdvancedIconMenu; +import me.filoghost.chestcommands.menu.MenuManager; import me.filoghost.chestcommands.util.ErrorCollector; public class CommandHandler extends CommandFramework { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java index df81549..50f3ca2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java @@ -19,8 +19,8 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.menu.AdvancedIconMenu; +import me.filoghost.chestcommands.menu.MenuManager; public class CommandListener implements Listener { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index 8e4a73a..0b888df 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -29,9 +29,9 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.Inventory; import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.menu.BaseIconMenu; +import me.filoghost.chestcommands.menu.MenuManager; public class InventoryListener implements Listener { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java index 5f0acda..de22e2d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java @@ -26,9 +26,9 @@ import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerInteractEvent; import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.menu.AdvancedIconMenu; +import me.filoghost.chestcommands.menu.MenuManager; import me.filoghost.chestcommands.util.FileUtils; public class SignListener implements Listener { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java index 813749c..70e6dab 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java @@ -21,7 +21,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.MenuManager; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.GiveMoneyAction; import me.filoghost.chestcommands.action.OpenMenuAction; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java similarity index 85% rename from Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java rename to Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java index 3ec6fd6..aa1c7f9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands; +package me.filoghost.chestcommands.menu; import java.util.Collection; import java.util.Collections; @@ -25,9 +25,6 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; -import me.filoghost.chestcommands.menu.AdvancedIconMenu; -import me.filoghost.chestcommands.menu.BaseIconMenu; -import me.filoghost.chestcommands.menu.MenuInventoryHolder; import me.filoghost.chestcommands.menu.settings.OpenTrigger; import me.filoghost.chestcommands.util.CaseInsensitiveMap; import me.filoghost.chestcommands.util.ErrorCollector; @@ -144,26 +141,5 @@ public class MenuManager { return new MenuView((AdvancedIconMenu) menuInventoryHolder.getIconMenu(), inventory); } - - - public static class MenuView { - - private final AdvancedIconMenu menu; - private final Inventory inventory; - - public MenuView(AdvancedIconMenu menu, Inventory inventory) { - this.menu = menu; - this.inventory = inventory; - } - - public AdvancedIconMenu getMenu() { - return menu; - } - - public Inventory getInventory() { - return inventory; - } - - } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuView.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuView.java new file mode 100644 index 0000000..62a272f --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuView.java @@ -0,0 +1,37 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.menu; + +import org.bukkit.inventory.Inventory; + +public class MenuView { + + private final AdvancedIconMenu menu; + private final Inventory inventory; + + public MenuView(AdvancedIconMenu menu, Inventory inventory) { + this.menu = menu; + this.inventory = inventory; + } + + public AdvancedIconMenu getMenu() { + return menu; + } + + public Inventory getInventory() { + return inventory; + } + +} \ No newline at end of file diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java index 6cccad1..7e0aa0e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java @@ -16,8 +16,9 @@ package me.filoghost.chestcommands.task; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.MenuManager; -import me.filoghost.chestcommands.MenuManager.MenuView; + +import me.filoghost.chestcommands.menu.MenuManager; +import me.filoghost.chestcommands.menu.MenuView; public class RefreshMenusTask implements Runnable { From da14e8bbc9f783870149e3ab6fe7026726a45ee2 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 13 Jun 2020 19:42:03 +0200 Subject: [PATCH 055/213] Refactor permission checking --- .../chestcommands/menu/AdvancedIcon.java | 79 +++++-------------- .../chestcommands/menu/PermissionChecker.java | 63 +++++++++++++++ 2 files changed, 83 insertions(+), 59 deletions(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/menu/PermissionChecker.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java index 70e6dab..a768649 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java @@ -27,16 +27,13 @@ import me.filoghost.chestcommands.action.OpenMenuAction; import me.filoghost.chestcommands.api.impl.ConfigurableIconImpl; import me.filoghost.chestcommands.bridge.EconomyBridge; import me.filoghost.chestcommands.util.MaterialsHelper; -import me.filoghost.chestcommands.util.StringUtils; public class AdvancedIcon extends ConfigurableIconImpl { - private String permission; - private boolean permissionNegated; - private String permissionMessage; + private PermissionChecker clickPermissionChecker; + private String clickNoPermissionMessage; - private String viewPermission; - private boolean viewPermissionNegated; + private PermissionChecker viewPermissionChecker; private double moneyPrice; private int expLevelsPrice; @@ -44,67 +41,31 @@ public class AdvancedIcon extends ConfigurableIconImpl { private List clickActions; private boolean canClickIcon(Player player) { - if (permission == null) { - return true; - } - - if (permissionNegated) { - return !player.hasPermission(permission); - } else { - return player.hasPermission(permission); - } + return clickPermissionChecker == null || clickPermissionChecker.hasPermission(player); + } + + public boolean canViewIcon(Player player) { + return viewPermissionChecker == null || viewPermissionChecker.hasPermission(player); + } + + public boolean hasViewPermission() { + return viewPermissionChecker != null && !viewPermissionChecker.isEmpty(); } public void setPermission(String permission) { - if (StringUtils.isNullOrEmpty(permission)) { - permission = null; - } - - if (permission != null) { - if (permission.startsWith("-")) { - permissionNegated = true; - permission = permission.substring(1, permission.length()).trim(); - } - } - this.permission = permission; + clickPermissionChecker = new PermissionChecker(permission); } public String getPermissionMessage() { - return permissionMessage; + return clickNoPermissionMessage; } - public void setPermissionMessage(String permissionMessage) { - this.permissionMessage = permissionMessage; + public void setPermissionMessage(String clickNoPermissionMessage) { + this.clickNoPermissionMessage = clickNoPermissionMessage; } - - public boolean hasViewPermission() { - return viewPermission != null; - } - - public boolean canViewIcon(Player player) { - if (viewPermission == null) { - return true; - } - - if (viewPermissionNegated) { - return !player.hasPermission(viewPermission); - } else { - return player.hasPermission(viewPermission); - } - } - + public void setViewPermission(String viewPermission) { - if (StringUtils.isNullOrEmpty(viewPermission)) { - viewPermission = null; - } - - if (viewPermission != null) { - if (viewPermission.startsWith("-")) { - viewPermissionNegated = true; - viewPermission = viewPermission.substring(1, viewPermission.length()).trim(); - } - } - this.viewPermission = viewPermission; + viewPermissionChecker = new PermissionChecker(viewPermission); } public double getMoneyPrice() { @@ -145,8 +106,8 @@ public class AdvancedIcon extends ConfigurableIconImpl { // Check all the requirements if (!canClickIcon(player)) { - if (permissionMessage != null) { - player.sendMessage(permissionMessage); + if (clickNoPermissionMessage != null) { + player.sendMessage(clickNoPermissionMessage); } else { player.sendMessage(ChestCommands.getLang().default_no_icon_permission); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/PermissionChecker.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/PermissionChecker.java new file mode 100644 index 0000000..f51cef4 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/PermissionChecker.java @@ -0,0 +1,63 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.menu; + +import org.bukkit.entity.Player; + +import me.filoghost.chestcommands.util.StringUtils; + +public class PermissionChecker { + + private final String permission; + private final boolean negated; + + public PermissionChecker(String permission) { + if (permission != null) { + permission = permission.trim(); + } + + if (StringUtils.isNullOrEmpty(permission)) { + this.permission = null; + negated = false; + } else { + if (permission.startsWith("-")) { + this.permission = permission.substring(1, permission.length()); + negated = true; + } else { + this.permission = permission; + negated = false; + } + } + } + + public boolean hasPermission(Player player) { + if (isEmpty()) { + return true; + } + + if (negated) { + return !player.hasPermission(permission); + } else { + return player.hasPermission(permission); + } + } + + public boolean isEmpty() { + return this.permission == null; + } + + + +} From f667f967eab2a4e47c58bb21cc33940a4b3baffb Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 13 Jun 2020 19:43:10 +0200 Subject: [PATCH 056/213] Create icon package --- .../me/filoghost/chestcommands/menu/AdvancedIconMenu.java | 1 + .../chestcommands/menu/{ => icon}/AdvancedIcon.java | 5 ++++- .../chestcommands/menu/{ => icon}/PermissionChecker.java | 2 +- .../chestcommands/menu/{ => icon}/RequiredItem.java | 2 +- .../java/me/filoghost/chestcommands/parser/IconParser.java | 4 ++-- .../java/me/filoghost/chestcommands/parser/MenuParser.java | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/menu/{ => icon}/AdvancedIcon.java (93%) rename Plugin/src/main/java/me/filoghost/chestcommands/menu/{ => icon}/PermissionChecker.java (93%) rename Plugin/src/main/java/me/filoghost/chestcommands/menu/{ => icon}/RequiredItem.java (94%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java index 5ea2d03..aa8fcdf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java @@ -25,6 +25,7 @@ import org.bukkit.inventory.meta.ItemMeta; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.action.Action; +import me.filoghost.chestcommands.menu.icon.AdvancedIcon; public class AdvancedIconMenu extends BaseIconMenu { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java rename to Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java index a768649..94ca3c7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.menu; +package me.filoghost.chestcommands.menu.icon; import java.util.List; @@ -26,6 +26,9 @@ import me.filoghost.chestcommands.action.GiveMoneyAction; import me.filoghost.chestcommands.action.OpenMenuAction; import me.filoghost.chestcommands.api.impl.ConfigurableIconImpl; import me.filoghost.chestcommands.bridge.EconomyBridge; +import me.filoghost.chestcommands.menu.AdvancedIconMenu; +import me.filoghost.chestcommands.menu.BaseIconMenu; +import me.filoghost.chestcommands.menu.MenuManager; import me.filoghost.chestcommands.util.MaterialsHelper; public class AdvancedIcon extends ConfigurableIconImpl { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/PermissionChecker.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/PermissionChecker.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/menu/PermissionChecker.java rename to Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/PermissionChecker.java index f51cef4..032b7c4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/PermissionChecker.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/PermissionChecker.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.menu; +package me.filoghost.chestcommands.menu.icon; import org.bukkit.entity.Player; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/RequiredItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItem.java similarity index 94% rename from Plugin/src/main/java/me/filoghost/chestcommands/menu/RequiredItem.java rename to Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItem.java index b6be637..37cbdc5 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/RequiredItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItem.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.menu; +package me.filoghost.chestcommands.menu.icon; import org.bukkit.Material; import org.bukkit.inventory.Inventory; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index edd1b6e..4c22c4b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -26,8 +26,8 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.config.AsciiPlaceholders; import me.filoghost.chestcommands.config.ConfigUtil; -import me.filoghost.chestcommands.menu.AdvancedIcon; -import me.filoghost.chestcommands.menu.RequiredItem; +import me.filoghost.chestcommands.menu.icon.AdvancedIcon; +import me.filoghost.chestcommands.menu.icon.RequiredItem; import me.filoghost.chestcommands.parser.EnchantmentParser.EnchantmentDetails; import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.FormatUtils; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java index 824eb2d..143ec66 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java @@ -24,8 +24,8 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.config.ConfigUtil; import me.filoghost.chestcommands.config.yaml.PluginConfig; -import me.filoghost.chestcommands.menu.AdvancedIcon; import me.filoghost.chestcommands.menu.AdvancedIconMenu; +import me.filoghost.chestcommands.menu.icon.AdvancedIcon; import me.filoghost.chestcommands.menu.settings.ClickType; import me.filoghost.chestcommands.menu.settings.MenuSettings; import me.filoghost.chestcommands.menu.settings.OpenTrigger; From 4e35757194f5d9e9483c6ea42127d57acf5ba26d Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 13 Jun 2020 19:43:48 +0200 Subject: [PATCH 057/213] Rename utility class --- .../filoghost/chestcommands/menu/icon/PermissionChecker.java | 4 ++-- .../java/me/filoghost/chestcommands/util/MaterialsHelper.java | 2 +- .../main/java/me/filoghost/chestcommands/util/Registry.java | 2 +- .../chestcommands/util/{StringUtils.java => Strings.java} | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/util/{StringUtils.java => Strings.java} (93%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/PermissionChecker.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/PermissionChecker.java index 032b7c4..c356cad 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/PermissionChecker.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/PermissionChecker.java @@ -16,7 +16,7 @@ package me.filoghost.chestcommands.menu.icon; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.util.StringUtils; +import me.filoghost.chestcommands.util.Strings; public class PermissionChecker { @@ -28,7 +28,7 @@ public class PermissionChecker { permission = permission.trim(); } - if (StringUtils.isNullOrEmpty(permission)) { + if (Strings.isNullOrEmpty(permission)) { this.permission = null; negated = false; } else { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java index eca7e9c..80e2303 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java @@ -103,7 +103,7 @@ public final class MaterialsHelper { } public static String formatMaterial(Material material) { - return StringUtils.capitalizeFully(material.toString().replace("_", " ")); + return Strings.capitalizeFully(material.toString().replace("_", " ")); } private static Collection getExistingMaterials(String... materialEnumNames) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Registry.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Registry.java index 4663753..e2d19f7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Registry.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Registry.java @@ -77,7 +77,7 @@ public class Registry { } private String toKeyFormat(String enumValueName) { - return StringUtils.stripChars(enumValueName, KEY_IGNORE_CHARS).toLowerCase(); + return Strings.stripChars(enumValueName, KEY_IGNORE_CHARS).toLowerCase(); } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Strings.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/Strings.java index 3d31cff..d5815c7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/StringUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Strings.java @@ -14,9 +14,9 @@ */ package me.filoghost.chestcommands.util; -public final class StringUtils { +public final class Strings { - private StringUtils() {} + private Strings() {} public static String stripChars(String input, char... removed) { From 6300ae887037372d3f638b56c372e5d043f025d4 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 13 Jun 2020 19:50:07 +0200 Subject: [PATCH 058/213] Move method --- .../chestcommands/listener/SignListener.java | 16 +++++++++++++--- .../filoghost/chestcommands/util/FileUtils.java | 7 ------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java index de22e2d..9217e2d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java @@ -29,7 +29,6 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.menu.AdvancedIconMenu; import me.filoghost.chestcommands.menu.MenuManager; -import me.filoghost.chestcommands.util.FileUtils; public class SignListener implements Listener { @@ -65,7 +64,7 @@ public class SignListener implements Listener { return; } - String menuFileName = FileUtils.addYamlExtension(sign.getLine(FILENAME_LINE).trim()); + String menuFileName = addYamlExtension(sign.getLine(FILENAME_LINE).trim()); AdvancedIconMenu menu = menuManager.getMenuByFileName(menuFileName); if (menu == null) { @@ -87,7 +86,7 @@ public class SignListener implements Listener { return; } - menuFileName = FileUtils.addYamlExtension(menuFileName); + menuFileName = addYamlExtension(menuFileName); AdvancedIconMenu iconMenu = menuManager.getMenuByFileName(menuFileName); if (iconMenu == null) { @@ -122,5 +121,16 @@ public class SignListener implements Listener { private boolean canCreateMenuSign(Player player) { return player.hasPermission(Permissions.SIGN_CREATE); } + + private String addYamlExtension(String fileName) { + if (fileName == null) { + return null; + } + if (fileName.toLowerCase().endsWith(".yml")) { + return fileName; + } else { + return fileName + ".yml"; + } + } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/FileUtils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/FileUtils.java index f87dd67..8c461b1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/FileUtils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/FileUtils.java @@ -8,13 +8,6 @@ public final class FileUtils { private FileUtils() {} - public static String addYamlExtension(String input) { - if (input == null) { - return null; - } - return input.toLowerCase().endsWith(".yml") ? input : input + ".yml"; - } - public static void saveResourceSafe(Plugin plugin, String name) { try { plugin.saveResource(name, false); From c88a35cc0d2132bb2236db85c22621ad29378fc2 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 14 Jun 2020 12:06:32 +0200 Subject: [PATCH 059/213] Refactoring: Requirements class --- .../chestcommands/menu/icon/AdvancedIcon.java | 155 +++++------------- .../menu/icon/PermissionChecker.java | 33 +++- .../menu/icon/RequiredExpLevel.java | 57 +++++++ .../menu/icon/RequiredItems.java | 72 ++++++++ .../menu/icon/RequiredMoney.java | 64 ++++++++ .../chestcommands/menu/icon/Requirement.java | 48 ++++++ .../chestcommands/parser/IconParser.java | 8 +- .../chestcommands/util/Preconditions.java | 9 + 8 files changed, 321 insertions(+), 125 deletions(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredExpLevel.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItems.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredMoney.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/Requirement.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java index 94ca3c7..f95a0f7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java @@ -16,37 +16,27 @@ package me.filoghost.chestcommands.menu.icon; import java.util.List; -import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.action.Action; -import me.filoghost.chestcommands.action.GiveMoneyAction; import me.filoghost.chestcommands.action.OpenMenuAction; import me.filoghost.chestcommands.api.impl.ConfigurableIconImpl; -import me.filoghost.chestcommands.bridge.EconomyBridge; import me.filoghost.chestcommands.menu.AdvancedIconMenu; import me.filoghost.chestcommands.menu.BaseIconMenu; import me.filoghost.chestcommands.menu.MenuManager; -import me.filoghost.chestcommands.util.MaterialsHelper; +import me.filoghost.chestcommands.util.Utils; public class AdvancedIcon extends ConfigurableIconImpl { - private PermissionChecker clickPermissionChecker; - private String clickNoPermissionMessage; - private PermissionChecker viewPermissionChecker; - private double moneyPrice; - private int expLevelsPrice; - private List requiredItems; + private PermissionChecker requiredPermission; + private RequiredMoney requiredMoney; + private RequiredExpLevel requiredExpLevel; + private RequiredItems requiredItems; private List clickActions; - private boolean canClickIcon(Player player) { - return clickPermissionChecker == null || clickPermissionChecker.hasPermission(player); - } - public boolean canViewIcon(Player player) { return viewPermissionChecker == null || viewPermissionChecker.hasPermission(player); } @@ -55,48 +45,40 @@ public class AdvancedIcon extends ConfigurableIconImpl { return viewPermissionChecker != null && !viewPermissionChecker.isEmpty(); } - public void setPermission(String permission) { - clickPermissionChecker = new PermissionChecker(permission); + public void setClickPermission(String permission) { + this.requiredPermission = new PermissionChecker(permission); } - - public String getPermissionMessage() { - return clickNoPermissionMessage; - } - - public void setPermissionMessage(String clickNoPermissionMessage) { - this.clickNoPermissionMessage = clickNoPermissionMessage; + + public void setNoClickPermissionMessage(String clickNoPermissionMessage) { + requiredPermission.setNoPermissionMessage(clickNoPermissionMessage); } public void setViewPermission(String viewPermission) { - viewPermissionChecker = new PermissionChecker(viewPermission); + this.viewPermissionChecker = new PermissionChecker(viewPermission); } - public double getMoneyPrice() { - return moneyPrice; + public void setRequiredMoney(double requiredMoney) { + if (requiredMoney > 0.0) { + this.requiredMoney = new RequiredMoney(requiredMoney); + } else { + this.requiredMoney = null; + } } - public void setMoneyPrice(double moneyPrice) { - this.moneyPrice = moneyPrice; - } - - public int getExpLevelsPrice() { - return expLevelsPrice; - } - - public void setExpLevelsPrice(int expLevelsPrice) { - this.expLevelsPrice = expLevelsPrice; - } - - public List getRequiredItems() { - return requiredItems; + public void setRequiredExpLevel(int requiredLevels) { + if (requiredLevels > 0) { + this.requiredExpLevel = new RequiredExpLevel(requiredLevels); + } else { + this.requiredExpLevel = null; + } } public void setRequiredItems(List requiredItems) { - this.requiredItems = requiredItems; - } - - public List getClickActions() { - return clickActions; + if (!Utils.isNullOrEmpty(requiredItems)) { + this.requiredItems = new RequiredItems(requiredItems); + } else { + this.requiredItems = null; + } } public void setClickActions(List clickActions) { @@ -105,74 +87,16 @@ public class AdvancedIcon extends ConfigurableIconImpl { @Override public boolean onClick(Inventory inventory, Player player) { - // Check all the requirements - - if (!canClickIcon(player)) { - if (clickNoPermissionMessage != null) { - player.sendMessage(clickNoPermissionMessage); - } else { - player.sendMessage(ChestCommands.getLang().default_no_icon_permission); - } + boolean hasAllRequirements = Requirement.checkAll(player, requiredPermission, requiredMoney, requiredExpLevel, requiredItems); + if (!hasAllRequirements) { return closeOnClick; } - if (moneyPrice > 0) { - if (!EconomyBridge.hasValidEconomy()) { - player.sendMessage(ChatColor.RED + "This action has a price, but Vault with a compatible economy plugin was not found. For security, the action has been blocked. Please inform the staff."); - return closeOnClick; - } - - if (!EconomyBridge.hasMoney(player, moneyPrice)) { - player.sendMessage(ChestCommands.getLang().no_money.replace("{money}", EconomyBridge.formatMoney(moneyPrice))); - return closeOnClick; - } - } - - if (expLevelsPrice > 0) { - if (player.getLevel() < expLevelsPrice) { - player.sendMessage(ChestCommands.getLang().no_exp.replace("{levels}", Integer.toString(expLevelsPrice))); - return closeOnClick; - } - } - - if (requiredItems != null) { - boolean notHasItem = false; - for (RequiredItem item : requiredItems) { - if (!item.isItemContainedIn(player.getInventory())) { - notHasItem = true; - player.sendMessage(ChestCommands.getLang().no_required_item - .replace("{material}", MaterialsHelper.formatMaterial(item.getMaterial())) - .replace("{amount}", Integer.toString(item.getAmount())) - .replace("{datavalue}", item.hasRestrictiveDurability() ? Short.toString(item.getDurability()) : ChestCommands.getLang().any) - ); - } - } - if (notHasItem) { - return closeOnClick; - } - } - - // Take the money and the required item - - boolean changedVariables = false; // To update the placeholders - - if (moneyPrice > 0) { - if (!EconomyBridge.takeMoney(player, moneyPrice)) { - player.sendMessage(ChatColor.RED + "Error: the transaction couldn't be executed. Please inform the staff."); - return closeOnClick; - } - changedVariables = true; - } - - if (expLevelsPrice > 0) { - player.setLevel(player.getLevel() - expLevelsPrice); - } - - if (requiredItems != null) { - for (RequiredItem item : requiredItems) { - item.takeItemFrom(player.getInventory()); - } + // If all requirements are satisfied, take their cost + boolean takenAllCosts = Requirement.takeAll(player, requiredPermission, requiredMoney, requiredExpLevel, requiredItems); + if (!takenAllCosts) { + return closeOnClick; } boolean hasOpenMenuAction = false; @@ -183,17 +107,14 @@ public class AdvancedIcon extends ConfigurableIconImpl { if (action instanceof OpenMenuAction) { hasOpenMenuAction = true; - } else if (action instanceof GiveMoneyAction) { - changedVariables = true; } } } - if (changedVariables) { - BaseIconMenu menu = MenuManager.getOpenMenu(inventory); - if (menu instanceof AdvancedIconMenu) { - ((AdvancedIconMenu) menu).refresh(player, inventory); - } + // Update the menu after taking requirement costs and executing all actions + BaseIconMenu menu = MenuManager.getOpenMenu(inventory); + if (menu instanceof AdvancedIconMenu) { + ((AdvancedIconMenu) menu).refresh(player, inventory); } // Force menu to stay open if actions open another menu diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/PermissionChecker.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/PermissionChecker.java index c356cad..9ad5f36 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/PermissionChecker.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/PermissionChecker.java @@ -16,12 +16,14 @@ package me.filoghost.chestcommands.menu.icon; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.util.Strings; -public class PermissionChecker { +public class PermissionChecker implements Requirement { private final String permission; private final boolean negated; + private String noPermissionMessage; public PermissionChecker(String permission) { if (permission != null) { @@ -42,6 +44,26 @@ public class PermissionChecker { } } + + public void setNoPermissionMessage(String noPermissionMessage) { + this.noPermissionMessage = noPermissionMessage; + } + + + @Override + public boolean hasRequirement(Player player) { + if (hasPermission(player)) { + return true; + } else { + if (noPermissionMessage != null) { + player.sendMessage(noPermissionMessage); + } else { + player.sendMessage(ChestCommands.getLang().default_no_icon_permission); + } + return false; + } + } + public boolean hasPermission(Player player) { if (isEmpty()) { return true; @@ -53,11 +75,14 @@ public class PermissionChecker { return player.hasPermission(permission); } } + + @Override + public boolean takeCost(Player player) { + return true; + } public boolean isEmpty() { return this.permission == null; - } - - + } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredExpLevel.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredExpLevel.java new file mode 100644 index 0000000..3b8bf21 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredExpLevel.java @@ -0,0 +1,57 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.menu.icon; + +import org.bukkit.entity.Player; + +import com.google.common.base.Preconditions; + +import me.filoghost.chestcommands.ChestCommands; + +public class RequiredExpLevel implements Requirement { + + private final int levels; + + public RequiredExpLevel(int levels) { + Preconditions.checkArgument(levels > 0, "levels must be positive"); + this.levels = levels; + } + + public int getLevels() { + return levels; + } + + @Override + public boolean hasRequirement(Player player) { + if (player.getLevel() < levels) { + player.sendMessage(ChestCommands.getLang().no_exp.replace("{levels}", Integer.toString(levels))); + return false; + } + + return true; + } + + @Override + public boolean takeCost(Player player) { + int newLevel = player.getLevel() - levels; + if (newLevel < 0) { + newLevel = 0; + } + + player.setLevel(newLevel); + return true; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItems.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItems.java new file mode 100644 index 0000000..faef290 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItems.java @@ -0,0 +1,72 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.menu.icon; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.bukkit.entity.Player; + +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.util.MaterialsHelper; +import me.filoghost.chestcommands.util.Preconditions; + +public class RequiredItems implements Requirement { + + private final List items; + + public RequiredItems(List items) { + Preconditions.notEmpty(items, "items"); + this.items = new ArrayList<>(items); + } + + public List geItems() { + return Collections.unmodifiableList(items); + } + + @Override + public boolean hasRequirement(Player player) { + boolean missingItems = false; + + for (RequiredItem item : items) { + if (!item.isItemContainedIn(player.getInventory())) { + missingItems = true; + player.sendMessage(ChestCommands.getLang().no_required_item + .replace("{material}", MaterialsHelper.formatMaterial(item.getMaterial())) + .replace("{amount}", Integer.toString(item.getAmount())) + .replace("{datavalue}", item.hasRestrictiveDurability() ? Short.toString(item.getDurability()) : ChestCommands.getLang().any) + ); + } + } + + return !missingItems; + } + + @Override + public boolean takeCost(Player player) { + boolean missingItems = false; + + for (RequiredItem item : items) { + boolean success = item.takeItemFrom(player.getInventory()); + if (!success) { + missingItems = true; + } + } + + return !missingItems; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredMoney.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredMoney.java new file mode 100644 index 0000000..082e768 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredMoney.java @@ -0,0 +1,64 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.menu.icon; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.google.common.base.Preconditions; + +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.bridge.EconomyBridge; + +public class RequiredMoney implements Requirement { + + private final double moneyAmount; + + public RequiredMoney(double moneyAmount) { + Preconditions.checkArgument(moneyAmount > 0.0, "money amount must be positive"); + this.moneyAmount = moneyAmount; + } + + public double getAmount() { + return moneyAmount; + } + + @Override + public boolean hasRequirement(Player player) { + if (!EconomyBridge.hasValidEconomy()) { + player.sendMessage(ChatColor.RED + "This action has a price, but Vault with a compatible economy plugin was not found. For security, the action has been blocked. Please inform the staff."); + return false; + } + + if (!EconomyBridge.hasMoney(player, moneyAmount)) { + player.sendMessage(ChestCommands.getLang().no_money.replace("{money}", EconomyBridge.formatMoney(moneyAmount))); + return false; + } + + return true; + } + + @Override + public boolean takeCost(Player player) { + boolean success = EconomyBridge.takeMoney(player, moneyAmount); + + if (!success) { + player.sendMessage(ChatColor.RED + "Error: a money transaction couldn't be executed. Please inform the staff."); + } + + return success; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/Requirement.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/Requirement.java new file mode 100644 index 0000000..e589d9c --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/Requirement.java @@ -0,0 +1,48 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.menu.icon; + +import org.bukkit.entity.Player; + +public interface Requirement { + + boolean hasRequirement(Player player); + + boolean takeCost(Player player); + + public static boolean checkAll(Player player, Requirement... requirements) { + for (Requirement requirement : requirements) { + if (requirement != null && !requirement.hasRequirement(player)) { + return false; + } + } + + return true; + } + + public static boolean takeAll(Player player, Requirement... requirements) { + for (Requirement requirement : requirements) { + if (requirement != null) { + boolean success = requirement.takeCost(player); + if (!success) { + return false; + } + } + } + + return true; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index 4c22c4b..095945b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -176,8 +176,8 @@ public class IconParser { } } - icon.setPermission(section.getString(Nodes.PERMISSION)); - icon.setPermissionMessage(FormatUtils.addColors(section.getString(Nodes.PERMISSION_MESSAGE))); + icon.setClickPermission(section.getString(Nodes.PERMISSION)); + icon.setNoClickPermissionMessage(FormatUtils.addColors(section.getString(Nodes.PERMISSION_MESSAGE))); icon.setViewPermission(section.getString(Nodes.VIEW_PERMISSION)); boolean closeOnClick = !section.getBoolean(Nodes.KEEP_OPEN); @@ -201,14 +201,14 @@ public class IconParser { double price = section.getDouble(Nodes.PRICE); if (price > 0.0) { - icon.setMoneyPrice(price); + icon.setRequiredMoney(price); } else if (price < 0.0) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has a negative PRICE: " + price); } int levels = section.getInt(Nodes.EXP_LEVELS); if (levels > 0) { - icon.setExpLevelsPrice(levels); + icon.setRequiredExpLevel(levels); } else if (levels < 0) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has negative LEVELS: " + levels); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Preconditions.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Preconditions.java index e4d434b..ce7db9b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Preconditions.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Preconditions.java @@ -14,6 +14,8 @@ */ package me.filoghost.chestcommands.util; +import java.util.Collection; + import org.bukkit.Material; public final class Preconditions { @@ -26,6 +28,13 @@ public final class Preconditions { } } + public static void notEmpty(Collection collection, String objectName) { + notNull(collection, objectName); + if (collection.isEmpty()) { + throw new IllegalArgumentException(objectName + " cannot be empty"); + } + } + public static void checkArgument(boolean expression, String errorMessage) { if (!expression) { throw new IllegalArgumentException(errorMessage); From e42edad8bef2f3ac13bb00fda64d2cbc9e1eea30 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 14 Jun 2020 12:08:17 +0200 Subject: [PATCH 060/213] Fix NPE --- .../java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java index aa8fcdf..33639af 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java @@ -92,6 +92,9 @@ public class AdvancedIconMenu extends BaseIconMenu { public void refresh(Player player, Inventory inventory) { for (int i = 0; i < inventoryGrid.getSize(); i++) { AdvancedIcon icon = inventoryGrid.getElementAtIndex(i); + if (icon == null) { + continue; + } if (icon.hasViewPermission() || icon.hasVariables()) { // Then we have to refresh it From c6636890dfc85e72110df601ea1ff55c6c627c7d Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 14 Jun 2020 12:17:38 +0200 Subject: [PATCH 061/213] Use immutable collections where possible --- .../filoghost/chestcommands/menu/icon/AdvancedIcon.java | 4 +++- .../filoghost/chestcommands/menu/icon/RequiredItems.java | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java index f95a0f7..e2a797e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java @@ -19,6 +19,8 @@ import java.util.List; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; +import com.google.common.collect.ImmutableList; + import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.OpenMenuAction; import me.filoghost.chestcommands.api.impl.ConfigurableIconImpl; @@ -82,7 +84,7 @@ public class AdvancedIcon extends ConfigurableIconImpl { } public void setClickActions(List clickActions) { - this.clickActions = clickActions; + this.clickActions = ImmutableList.copyOf(clickActions); } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItems.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItems.java index faef290..59a034e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItems.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItems.java @@ -14,12 +14,12 @@ */ package me.filoghost.chestcommands.menu.icon; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import org.bukkit.entity.Player; +import com.google.common.collect.ImmutableList; + import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.util.MaterialsHelper; import me.filoghost.chestcommands.util.Preconditions; @@ -30,11 +30,11 @@ public class RequiredItems implements Requirement { public RequiredItems(List items) { Preconditions.notEmpty(items, "items"); - this.items = new ArrayList<>(items); + this.items = ImmutableList.copyOf(items); } public List geItems() { - return Collections.unmodifiableList(items); + return items; } @Override From e9bbbbdf89ca4dcaec8b4af4ee757859b05a0571 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 14 Jun 2020 12:21:46 +0200 Subject: [PATCH 062/213] Use list instead of array --- .../me/filoghost/chestcommands/menu/MenuManager.java | 2 +- .../chestcommands/menu/settings/MenuSettings.java | 9 +++++---- .../me/filoghost/chestcommands/parser/MenuParser.java | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java index aa1c7f9..1d57452 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java @@ -52,7 +52,7 @@ public class MenuManager { return fileNameToMenuMap.get(fileName); } - public void registerMenu(String fileName, String[] triggerCommands, AdvancedIconMenu menu, ErrorCollector errorCollector) { + public void registerMenu(String fileName, Collection triggerCommands, AdvancedIconMenu menu, ErrorCollector errorCollector) { if (fileNameToMenuMap.containsKey(fileName)) { errorCollector.addError("Two menus have the same file name \"" + fileName + "\" with different cases. There will be problems opening one of these two menus."); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/MenuSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/MenuSettings.java index aa9b365..d527035 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/MenuSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/MenuSettings.java @@ -15,6 +15,7 @@ package me.filoghost.chestcommands.menu.settings; import me.filoghost.chestcommands.action.Action; +import me.filoghost.chestcommands.util.Utils; import java.util.List; @@ -25,7 +26,7 @@ public class MenuSettings { private final int rows; // Optional settings - private String[] commands; + private List commands; private List openActions; private int refreshTenths; @@ -45,14 +46,14 @@ public class MenuSettings { } public boolean hasCommands() { - return commands != null && commands.length > 0; + return !Utils.isNullOrEmpty(commands); } - public void setCommands(String[] commands) { + public void setCommands(List commands) { this.commands = commands; } - public String[] getCommands() { + public List getCommands() { return commands; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java index 143ec66..122cedc 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java @@ -123,7 +123,7 @@ public class MenuParser { List triggeringCommands = ConfigUtil.getStringListOrInlineList(config, ";", Nodes.MENU_COMMANDS); if (triggeringCommands != null) { - menuSettings.setCommands(triggeringCommands.toArray(new String[0])); + menuSettings.setCommands(triggeringCommands); } List serializedOpenActions = ConfigUtil.getStringListOrInlineList(config, ChestCommands.getSettings().multiple_commands_separator, Nodes.OPEN_ACTIONS); From c31216f56939bc78054f3386655f8c1831399b21 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 14 Jun 2020 12:53:25 +0200 Subject: [PATCH 063/213] Use modifiable and nullable collections where possible --- .../chestcommands/api/ConfigurableIcon.java | 2 -- .../api/impl/ConfigurableIconImpl.java | 29 +++++++++---------- .../chestcommands/menu/AdvancedIconMenu.java | 7 ++--- .../chestcommands/menu/icon/AdvancedIcon.java | 4 +-- .../menu/settings/MenuSettings.java | 5 ---- .../filoghost/chestcommands/util/Utils.java | 22 +++++++++++++- 6 files changed, 37 insertions(+), 32 deletions(-) diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java b/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java index 5d2dbcb..5f6429d 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java @@ -69,8 +69,6 @@ public interface ConfigurableIcon extends Icon { void removeEnchantment(Enchantment ench); - void clearEnchantments(); - Color getLeatherColor(); void setLeatherColor(Color leatherColor); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java index 446a143..1d39611 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java @@ -41,6 +41,7 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.api.ClickHandler; import me.filoghost.chestcommands.api.ClickResult; import me.filoghost.chestcommands.api.ConfigurableIcon; +import me.filoghost.chestcommands.util.Utils; import me.filoghost.chestcommands.variable.VariableManager; public class ConfigurableIconImpl implements ConfigurableIcon { @@ -67,7 +68,6 @@ public class ConfigurableIconImpl implements ConfigurableIcon { private ItemStack cachedItem; // When there are no variables, we don't recreate the item public ConfigurableIconImpl() { - enchantments = new HashMap<>(); closeOnClick = true; amount = 1; } @@ -142,7 +142,7 @@ public class ConfigurableIconImpl implements ConfigurableIcon { @Override public void setLore(List lore) { - this.lore = lore; + this.lore = Utils.nullableCopy(lore); this.loreLinesWithVariables = null; if (lore != null) { @@ -159,7 +159,7 @@ public class ConfigurableIconImpl implements ConfigurableIcon { @Override public boolean hasLore() { - return lore != null && lore.size() > 0; + return !Utils.isNullOrEmpty(lore); } @Override @@ -169,16 +169,12 @@ public class ConfigurableIconImpl implements ConfigurableIcon { @Override public void setEnchantments(Map enchantments) { - if (enchantments == null) { - this.enchantments.clear(); - return; - } - this.enchantments = enchantments; + this.enchantments = Utils.nullableCopy(enchantments); } @Override public Map getEnchantments() { - return new HashMap<>(enchantments); + return enchantments; } @Override @@ -188,19 +184,20 @@ public class ConfigurableIconImpl implements ConfigurableIcon { @Override public void addEnchantment(Enchantment ench, Integer level) { + if (enchantments == null) { + enchantments = new HashMap<>(); + } enchantments.put(ench, level); } @Override public void removeEnchantment(Enchantment ench) { + if (enchantments == null) { + return; + } enchantments.remove(ench); } - @Override - public void clearEnchantments() { - enchantments.clear(); - } - @Override public Color getLeatherColor() { return leatherColor; @@ -239,7 +236,7 @@ public class ConfigurableIconImpl implements ConfigurableIcon { @Override public void setBannerPatterns(List bannerPatterns) { - this.bannerPatterns = bannerPatterns; + this.bannerPatterns = Utils.nullableCopy(bannerPatterns); } @Override @@ -367,7 +364,7 @@ public class ConfigurableIconImpl implements ConfigurableIcon { itemStack.setItemMeta(itemMeta); - if (enchantments.size() > 0) { + if (enchantments != null) { for (Entry entry : enchantments.entrySet()) { itemStack.addUnsafeEnchantment(entry.getKey(), entry.getValue()); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java index 33639af..c8ccd32 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java @@ -26,6 +26,7 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.menu.icon.AdvancedIcon; +import me.filoghost.chestcommands.util.Utils; public class AdvancedIconMenu extends BaseIconMenu { @@ -45,12 +46,8 @@ public class AdvancedIconMenu extends BaseIconMenu { return fileName; } - public List getOpenActions() { - return openActions; - } - public void setOpenActions(List openAction) { - this.openActions = openAction; + this.openActions = Utils.nullableCopy(openAction); } public String getPermission() { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java index e2a797e..f29c8a6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java @@ -19,8 +19,6 @@ import java.util.List; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.google.common.collect.ImmutableList; - import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.OpenMenuAction; import me.filoghost.chestcommands.api.impl.ConfigurableIconImpl; @@ -84,7 +82,7 @@ public class AdvancedIcon extends ConfigurableIconImpl { } public void setClickActions(List clickActions) { - this.clickActions = ImmutableList.copyOf(clickActions); + this.clickActions = Utils.nullableCopy(clickActions); } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/MenuSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/MenuSettings.java index d527035..3058679 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/MenuSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/MenuSettings.java @@ -15,7 +15,6 @@ package me.filoghost.chestcommands.menu.settings; import me.filoghost.chestcommands.action.Action; -import me.filoghost.chestcommands.util.Utils; import java.util.List; @@ -45,10 +44,6 @@ public class MenuSettings { return rows; } - public boolean hasCommands() { - return !Utils.isNullOrEmpty(commands); - } - public void setCommands(List commands) { this.commands = commands; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java index c300d0c..bc1d3e1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java @@ -14,7 +14,11 @@ */ package me.filoghost.chestcommands.util; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public final class Utils { @@ -33,4 +37,20 @@ public final class Utils { return collection == null || collection.isEmpty(); } + public static List nullableCopy(List list) { + if (isNullOrEmpty(list)) { + return null; + } else { + return new ArrayList<>(list); + } + } + + public static Map nullableCopy(Map map) { + if (map == null || map.isEmpty()) { + return null; + } else { + return new HashMap<>(map); + } + } + } From b49788965025ef1cff5e7f98f410cfdfea849531 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 14 Jun 2020 13:43:07 +0200 Subject: [PATCH 064/213] Refactoring --- .../api/impl/ConfigurableIconImpl.java | 11 +++-- .../chestcommands/command/CommandHandler.java | 4 +- .../chestcommands/menu/AdvancedIconMenu.java | 44 ++++++++++--------- .../chestcommands/menu/MenuManager.java | 39 ++++++++-------- .../chestcommands/menu/icon/AdvancedIcon.java | 2 +- .../menu/icon/PermissionChecker.java | 2 +- .../menu/icon/RequiredExpLevel.java | 2 +- .../chestcommands/menu/icon/RequiredItem.java | 35 ++++++++------- .../menu/icon/RequiredItems.java | 2 +- .../menu/icon/RequiredMoney.java | 2 +- .../chestcommands/menu/icon/Requirement.java | 6 +-- .../menu/settings/OpenTrigger.java | 4 +- 12 files changed, 78 insertions(+), 75 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java index 1d39611..2bdc273 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java @@ -37,6 +37,8 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.inventory.meta.SkullMeta; +import com.google.common.base.Preconditions; + import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.api.ClickHandler; import me.filoghost.chestcommands.api.ClickResult; @@ -89,10 +91,8 @@ public class ConfigurableIconImpl implements ConfigurableIcon { @Override public void setAmount(int amount) { - if (amount < 1) amount = 1; - else if (amount > 127) amount = 127; - - this.amount = amount; + Preconditions.checkArgument(amount >= 1, "Amount must 1 or greater"); + this.amount = Math.min(amount, 127); } @Override @@ -102,8 +102,7 @@ public class ConfigurableIconImpl implements ConfigurableIcon { @Override public void setDurability(short durability) { - if (durability < 0) durability = 0; - + Preconditions.checkArgument(durability >= 0, "Durability must not be negative"); this.durability = durability; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index 70f086d..4a7b04a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -107,8 +107,8 @@ public class CommandHandler extends CommandFramework { AdvancedIconMenu menu = menuManager.getMenuByFileName(menuName); CommandValidate.notNull(menu, "The menu \"" + menuName + "\" was not found."); - if (!sender.hasPermission(menu.getPermission())) { - menu.sendNoPermissionMessage(sender); + if (!sender.hasPermission(menu.getOpenPermission())) { + menu.sendNoOpenPermissionMessage(sender); return; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java index c8ccd32..7b5572f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java @@ -31,8 +31,8 @@ import me.filoghost.chestcommands.util.Utils; public class AdvancedIconMenu extends BaseIconMenu { private final String fileName; + private final String permission; - private String permission; private List openActions; private int refreshTicks; @@ -50,7 +50,7 @@ public class AdvancedIconMenu extends BaseIconMenu { this.openActions = Utils.nullableCopy(openAction); } - public String getPermission() { + public String getOpenPermission() { return permission; } @@ -82,7 +82,7 @@ public class AdvancedIconMenu extends BaseIconMenu { if (player.hasPermission(permission)) { open(player); } else { - sendNoPermissionMessage(player); + sendNoOpenPermissionMessage(player); } } @@ -95,28 +95,30 @@ public class AdvancedIconMenu extends BaseIconMenu { if (icon.hasViewPermission() || icon.hasVariables()) { // Then we have to refresh it - if (icon.canViewIcon(player)) { - - if (inventory.getItem(i) == null) { - ItemStack newItem = hideAttributes(icon.createItemStack(player)); - inventory.setItem(i, newItem); - } else { - // Performance, only update name and lore - ItemStack oldItem = hideAttributes(inventory.getItem(i)); - ItemMeta meta = oldItem.getItemMeta(); - meta.setDisplayName(icon.calculateName(player)); - meta.setLore(icon.calculateLore(player)); - oldItem.setItemMeta(meta); - } - - } else { - inventory.setItem(i, null); - } + refreshIcon(player, inventory, icon, i); } } } - public void sendNoPermissionMessage(CommandSender sender) { + private void refreshIcon(Player player, Inventory inventory, AdvancedIcon icon, int inventorySlot) { + if (icon.canViewIcon(player)) { + if (inventory.getItem(inventorySlot) == null) { + ItemStack newItem = hideAttributes(icon.createItemStack(player)); + inventory.setItem(inventorySlot, newItem); + } else { + // Performance, only update name and lore + ItemStack oldItem = hideAttributes(inventory.getItem(inventorySlot)); + ItemMeta meta = oldItem.getItemMeta(); + meta.setDisplayName(icon.calculateName(player)); + meta.setLore(icon.calculateLore(player)); + oldItem.setItemMeta(meta); + } + } else { + inventory.setItem(inventorySlot, null); + } + } + + public void sendNoOpenPermissionMessage(CommandSender sender) { String noPermMessage = ChestCommands.getLang().no_open_permission; if (noPermMessage != null && !noPermMessage.isEmpty()) { sender.sendMessage(noPermMessage.replace("{permission}", this.permission)); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java index 1d57452..dce645b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java @@ -31,50 +31,49 @@ import me.filoghost.chestcommands.util.ErrorCollector; public class MenuManager { - private static Map fileNameToMenuMap; - private static Map commandsToMenuMap; - - private static Map openTriggers; + private static Map menusByFile; + private static Map menusByCommand; + private static Map menusByOpenTrigger; public MenuManager() { - fileNameToMenuMap = CaseInsensitiveMap.create(); - commandsToMenuMap = CaseInsensitiveMap.create(); - openTriggers = new HashMap<>(); + menusByFile = CaseInsensitiveMap.create(); + menusByCommand = CaseInsensitiveMap.create(); + menusByOpenTrigger = new HashMap<>(); } public void clear() { - fileNameToMenuMap.clear(); - commandsToMenuMap.clear(); - openTriggers.clear(); + menusByFile.clear(); + menusByCommand.clear(); + menusByOpenTrigger.clear(); } public AdvancedIconMenu getMenuByFileName(String fileName) { - return fileNameToMenuMap.get(fileName); + return menusByFile.get(fileName); } public void registerMenu(String fileName, Collection triggerCommands, AdvancedIconMenu menu, ErrorCollector errorCollector) { - if (fileNameToMenuMap.containsKey(fileName)) { + if (menusByFile.containsKey(fileName)) { errorCollector.addError("Two menus have the same file name \"" + fileName + "\" with different cases. There will be problems opening one of these two menus."); } - fileNameToMenuMap.put(fileName, menu); + menusByFile.put(fileName, menu); for (String triggerCommand : triggerCommands) { if (!triggerCommand.isEmpty()) { - if (commandsToMenuMap.containsKey(triggerCommand)) { - errorCollector.addError("The menus \"" + commandsToMenuMap.get(triggerCommand).getFileName() + "\" and \"" + fileName + "\" have the same command \"" + triggerCommand + "\". Only one will be opened."); + if (menusByCommand.containsKey(triggerCommand)) { + errorCollector.addError("The menus \"" + menusByCommand.get(triggerCommand).getFileName() + "\" and \"" + fileName + "\" have the same command \"" + triggerCommand + "\". Only one will be opened."); } - commandsToMenuMap.put(triggerCommand, menu); + menusByCommand.put(triggerCommand, menu); } } } public void registerTriggerItem(OpenTrigger openTrigger, AdvancedIconMenu menu) { - openTriggers.put(openTrigger, menu); + menusByOpenTrigger.put(openTrigger, menu); } public void openMenuByItem(Player player, ItemStack itemInHand, Action clickAction) { - openTriggers.forEach((openTrigger, menu) -> { + menusByOpenTrigger.forEach((openTrigger, menu) -> { if (openTrigger.matches(itemInHand, clickAction)) { menu.openCheckingPermission(player); } @@ -82,11 +81,11 @@ public class MenuManager { } public AdvancedIconMenu getMenuByCommand(String command) { - return commandsToMenuMap.get(command); + return menusByCommand.get(command); } public Collection getMenuFileNames() { - return Collections.unmodifiableCollection(fileNameToMenuMap.keySet()); + return Collections.unmodifiableCollection(menusByFile.keySet()); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java index f29c8a6..a017422 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java @@ -94,7 +94,7 @@ public class AdvancedIcon extends ConfigurableIconImpl { } // If all requirements are satisfied, take their cost - boolean takenAllCosts = Requirement.takeAll(player, requiredPermission, requiredMoney, requiredExpLevel, requiredItems); + boolean takenAllCosts = Requirement.takeCostAll(player, requiredPermission, requiredMoney, requiredExpLevel, requiredItems); if (!takenAllCosts) { return closeOnClick; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/PermissionChecker.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/PermissionChecker.java index 9ad5f36..9fef005 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/PermissionChecker.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/PermissionChecker.java @@ -51,7 +51,7 @@ public class PermissionChecker implements Requirement { @Override - public boolean hasRequirement(Player player) { + public boolean check(Player player) { if (hasPermission(player)) { return true; } else { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredExpLevel.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredExpLevel.java index 3b8bf21..7be12e3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredExpLevel.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredExpLevel.java @@ -34,7 +34,7 @@ public class RequiredExpLevel implements Requirement { } @Override - public boolean hasRequirement(Player player) { + public boolean check(Player player) { if (player.getLevel() < levels) { player.sendMessage(ChestCommands.getLang().no_exp.replace("{levels}", Integer.toString(levels))); return false; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItem.java index 37cbdc5..b979b52 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItem.java @@ -22,8 +22,8 @@ import me.filoghost.chestcommands.util.Preconditions; public class RequiredItem { - private Material material; - private int amount; + private final Material material; + private final int amount; private short durability; private boolean isDurabilityRestrictive = false; @@ -57,16 +57,11 @@ public class RequiredItem { return isDurabilityRestrictive; } - private boolean isMatchingDurability(short data) { - if (!isDurabilityRestrictive) return true; - return data == this.durability; - } - public boolean isItemContainedIn(Inventory inventory) { int amountFound = 0; for (ItemStack item : inventory.getContents()) { - if (item != null && item.getType() == material && isMatchingDurability(item.getDurability())) { + if (isMatchingType(item)) { amountFound += item.getAmount(); } } @@ -78,18 +73,14 @@ public class RequiredItem { if (amount <= 0) { return true; } - - int itemsToTake = amount; //start from amount and decrease - + + int itemsToTake = amount; // Start from amount and decrease ItemStack[] contents = inventory.getContents(); - ItemStack current = null; - for (int i = 0; i < contents.length; i++) { + ItemStack current = contents[i]; - current = contents[i]; - - if (current != null && current.getType() == material && isMatchingDurability(current.getDurability())) { + if (isMatchingType(current)) { if (current.getAmount() > itemsToTake) { current.setAmount(current.getAmount() - itemsToTake); return true; @@ -105,4 +96,16 @@ public class RequiredItem { return false; } + + private boolean isMatchingType(ItemStack item) { + return item != null && item.getType() == material && isMatchingDurability(item.getDurability()); + } + + private boolean isMatchingDurability(short data) { + if (!isDurabilityRestrictive) { + return true; + } + return data == this.durability; + } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItems.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItems.java index 59a034e..ed768a1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItems.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredItems.java @@ -38,7 +38,7 @@ public class RequiredItems implements Requirement { } @Override - public boolean hasRequirement(Player player) { + public boolean check(Player player) { boolean missingItems = false; for (RequiredItem item : items) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredMoney.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredMoney.java index 082e768..38bfef3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredMoney.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredMoney.java @@ -36,7 +36,7 @@ public class RequiredMoney implements Requirement { } @Override - public boolean hasRequirement(Player player) { + public boolean check(Player player) { if (!EconomyBridge.hasValidEconomy()) { player.sendMessage(ChatColor.RED + "This action has a price, but Vault with a compatible economy plugin was not found. For security, the action has been blocked. Please inform the staff."); return false; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/Requirement.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/Requirement.java index e589d9c..6631a8e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/Requirement.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/Requirement.java @@ -18,13 +18,13 @@ import org.bukkit.entity.Player; public interface Requirement { - boolean hasRequirement(Player player); + boolean check(Player player); boolean takeCost(Player player); public static boolean checkAll(Player player, Requirement... requirements) { for (Requirement requirement : requirements) { - if (requirement != null && !requirement.hasRequirement(player)) { + if (requirement != null && !requirement.check(player)) { return false; } } @@ -32,7 +32,7 @@ public interface Requirement { return true; } - public static boolean takeAll(Player player, Requirement... requirements) { + public static boolean takeCostAll(Player player, Requirement... requirements) { for (Requirement requirement : requirements) { if (requirement != null) { boolean success = requirement.takeCost(player); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/OpenTrigger.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/OpenTrigger.java index fd8c23a..0d01487 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/OpenTrigger.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/settings/OpenTrigger.java @@ -22,8 +22,8 @@ import me.filoghost.chestcommands.util.Preconditions; public class OpenTrigger { - private Material material; - private ClickType clickType; + private final Material material; + private final ClickType clickType; private short durability; private boolean isRestrictiveDurability; From f0474e1a623bd7cb775c8f47d5fa577e1f8ac6e3 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 14 Jun 2020 15:47:47 +0200 Subject: [PATCH 065/213] Refactoring: RelativeString --- .../chestcommands/api/ConfigurableIcon.java | 2 + .../api/impl/ConfigurableIconImpl.java | 114 ++++++++---------- .../filoghost/chestcommands/util/Utils.java | 9 ++ .../variable/RelativeString.java | 39 ++++++ .../variable/RelativeStringList.java | 45 +++++++ .../variable/VariableManager.java | 3 + 6 files changed, 146 insertions(+), 66 deletions(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/variable/RelativeString.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/variable/RelativeStringList.java diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java b/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java index 5f6429d..1a8e1c2 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java @@ -50,6 +50,8 @@ public interface ConfigurableIcon extends Icon { void setName(String name); boolean hasName(); + + String getName(); void setLore(String... lore); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java index 2bdc273..1bb7470 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java @@ -44,7 +44,8 @@ import me.filoghost.chestcommands.api.ClickHandler; import me.filoghost.chestcommands.api.ClickResult; import me.filoghost.chestcommands.api.ConfigurableIcon; import me.filoghost.chestcommands.util.Utils; -import me.filoghost.chestcommands.variable.VariableManager; +import me.filoghost.chestcommands.variable.RelativeString; +import me.filoghost.chestcommands.variable.RelativeStringList; public class ConfigurableIconImpl implements ConfigurableIcon { @@ -53,20 +54,17 @@ public class ConfigurableIconImpl implements ConfigurableIcon { private short durability; private String nbtData; - private String name; - private List lore; + private RelativeString name; + private RelativeStringList lore; private Map enchantments; private Color leatherColor; - private String skullOwner; + private RelativeString skullOwner; private DyeColor bannerColor; private List bannerPatterns; protected boolean closeOnClick; private ClickHandler clickHandler; - - private boolean nameHasVariables; - private boolean[] loreLinesWithVariables; - private boolean skullOwnerHasVariables; + private ItemStack cachedItem; // When there are no variables, we don't recreate the item public ConfigurableIconImpl() { @@ -75,7 +73,9 @@ public class ConfigurableIconImpl implements ConfigurableIcon { } public boolean hasVariables() { - return nameHasVariables || loreLinesWithVariables != null || skullOwnerHasVariables; + return (name != null && name.hasVariables()) + || (lore != null && lore.hasVariables()) + || (skullOwner != null && skullOwner.hasVariables()); } @Override @@ -123,14 +123,21 @@ public class ConfigurableIconImpl implements ConfigurableIcon { @Override public void setName(String name) { - this.name = name; - this.nameHasVariables = VariableManager.hasVariables(name); + this.name = RelativeString.of(name); } @Override public boolean hasName() { return name != null; } + + public String getName() { + if (name != null) { + return name.getRawValue(); + } else { + return null; + } + } @Override public void setLore(String... lore) { @@ -141,29 +148,25 @@ public class ConfigurableIconImpl implements ConfigurableIcon { @Override public void setLore(List lore) { - this.lore = Utils.nullableCopy(lore); - this.loreLinesWithVariables = null; - - if (lore != null) { - for (int i = 0; i < lore.size(); i++) { - if (VariableManager.hasVariables(lore.get(i))) { - if (this.loreLinesWithVariables == null) { - this.loreLinesWithVariables = new boolean[lore.size()]; - } - loreLinesWithVariables[i] = true; - } - } + if (!Utils.isNullOrEmpty(lore)) { + this.lore = new RelativeStringList(lore); + } else { + this.lore = null; } } @Override public boolean hasLore() { - return !Utils.isNullOrEmpty(lore); + return lore != null; } @Override public List getLore() { - return lore; + if (lore != null) { + return new ArrayList<>(lore.getRawValue()); + } else { + return null; + } } @Override @@ -173,7 +176,7 @@ public class ConfigurableIconImpl implements ConfigurableIcon { @Override public Map getEnchantments() { - return enchantments; + return Utils.nullableCopy(enchantments); } @Override @@ -209,13 +212,16 @@ public class ConfigurableIconImpl implements ConfigurableIcon { @Override public String getSkullOwner() { - return skullOwner; + if (skullOwner != null) { + return skullOwner.getRawValue(); + } else { + return null; + } } @Override public void setSkullOwner(String skullOwner) { - this.skullOwner = skullOwner; - this.skullOwnerHasVariables = VariableManager.hasVariables(skullOwner); + this.skullOwner = RelativeString.of(skullOwner); } @Override @@ -230,7 +236,7 @@ public class ConfigurableIconImpl implements ConfigurableIcon { @Override public List getBannerPatterns() { - return bannerPatterns; + return Utils.nullableCopy(bannerPatterns); } @Override @@ -254,49 +260,28 @@ public class ConfigurableIconImpl implements ConfigurableIcon { } public String calculateName(Player viewer) { - if (hasName()) { - - String name = this.name; - - if (viewer != null && nameHasVariables) { - name = VariableManager.setVariables(name, viewer); - } - - if (name.isEmpty()) { - // Add a color to display the name empty - return ChatColor.WHITE.toString(); - } else { - return name; - } + if (!hasName()) { + return null; } - return null; + String name = this.name.getValue(viewer); + + if (name.isEmpty()) { + // Add a color to display the name empty + return ChatColor.WHITE.toString(); + } else { + return name; + } } public List calculateLore(Player viewer) { - List output = null; if (hasLore()) { - - output = new ArrayList<>(); - - if (viewer != null && loreLinesWithVariables != null) { - for (int i = 0; i < lore.size(); i++) { - String line = lore.get(i); - if (loreLinesWithVariables[i]) { - line = VariableManager.setVariables(line, viewer); - } - output.add(line); - } - } else { - // Otherwise just copy the lines - output.addAll(lore); - } + output = lore.getValue(viewer); } if (material == null) { - if (output == null) { output = new ArrayList<>(); } @@ -346,10 +331,7 @@ public class ConfigurableIconImpl implements ConfigurableIcon { } if (skullOwner != null && itemMeta instanceof SkullMeta) { - String skullOwner = this.skullOwner; - if(skullOwnerHasVariables) { - skullOwner = VariableManager.setVariables(skullOwner, viewer); - } + String skullOwner = this.skullOwner.getValue(viewer); ((SkullMeta) itemMeta).setOwner(skullOwner); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java index bc1d3e1..68d66fe 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java @@ -19,6 +19,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; public final class Utils { @@ -53,4 +54,12 @@ public final class Utils { } } + public static List transform(List list, Function transformFunction) { + List result = new ArrayList<>(list.size()); + for (A element : list) { + result.add(transformFunction.apply(element)); + } + return result; + } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/variable/RelativeString.java b/Plugin/src/main/java/me/filoghost/chestcommands/variable/RelativeString.java new file mode 100644 index 0000000..ba0f59c --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/variable/RelativeString.java @@ -0,0 +1,39 @@ +package me.filoghost.chestcommands.variable; + +import org.bukkit.entity.Player; + +public class RelativeString { + + private final String string; + private final boolean hasVariables; + + public static RelativeString of(String string) { + if (string != null) { + return new RelativeString(string); + } else { + return null; + } + } + + private RelativeString(String string) { + this.string = string; + this.hasVariables = VariableManager.hasVariables(string); + } + + public String getRawValue() { + return string; + } + + public String getValue(Player player) { + if (hasVariables) { + return VariableManager.setVariables(string, player); + } else { + return string; + } + } + + public boolean hasVariables() { + return hasVariables; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/variable/RelativeStringList.java b/Plugin/src/main/java/me/filoghost/chestcommands/variable/RelativeStringList.java new file mode 100644 index 0000000..b2862b8 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/variable/RelativeStringList.java @@ -0,0 +1,45 @@ +package me.filoghost.chestcommands.variable; + +import java.util.List; + +import org.bukkit.entity.Player; + +import com.google.common.collect.ImmutableList; + +import me.filoghost.chestcommands.util.Utils; + +public class RelativeStringList { + + private final ImmutableList originalList; + private final List relativeList; + private final boolean hasVariables; + + public RelativeStringList(List list) { + if (list != null) { + this.originalList = ImmutableList.copyOf(list); + this.relativeList = Utils.transform(list, RelativeString::of); + this.hasVariables = this.relativeList.stream().anyMatch(element -> element.hasVariables()); + } else { + this.originalList = null; + this.relativeList = null; + this.hasVariables = false; + } + } + + public ImmutableList getRawValue() { + return originalList; + } + + public List getValue(Player player) { + if (hasVariables) { + return Utils.transform(relativeList, element -> element.getValue(player)); + } else { + return originalList; + } + } + + public boolean hasVariables() { + return hasVariables; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/variable/VariableManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/variable/VariableManager.java index ac7b3f8..8462eb1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/variable/VariableManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/variable/VariableManager.java @@ -22,6 +22,9 @@ public class VariableManager { } public static String setVariables(String message, Player executor) { + if (message == null) { + return null; + } for (Variable variable : Variable.values()) { if (message.contains(variable.getText())) { message = message.replace(variable.getText(), variable.getReplacement(executor)); From b4817bb657ac0a61552e289f2efc7ce2c6774378 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 14 Jun 2020 16:06:41 +0200 Subject: [PATCH 066/213] Require non-null and non-air material for icons --- .../api/impl/BackendAPIImpl.java | 4 +-- .../api/impl/ConfigurableIconImpl.java | 30 +++++++------------ .../chestcommands/menu/icon/AdvancedIcon.java | 5 ++++ .../chestcommands/parser/IconParser.java | 8 ++--- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/BackendAPIImpl.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/BackendAPIImpl.java index b7d4004..68455b7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/BackendAPIImpl.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/BackendAPIImpl.java @@ -47,9 +47,7 @@ public class BackendAPIImpl extends BackendAPI { @Override public ConfigurableIcon createConfigurableIcon(Material material) { - ConfigurableIconImpl icon = new ConfigurableIconImpl(); - icon.setMaterial(material); - return icon; + return new ConfigurableIconImpl(material); } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java index 1bb7470..f50f2fb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java @@ -37,12 +37,11 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.inventory.meta.SkullMeta; -import com.google.common.base.Preconditions; - import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.api.ClickHandler; import me.filoghost.chestcommands.api.ClickResult; import me.filoghost.chestcommands.api.ConfigurableIcon; +import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.Utils; import me.filoghost.chestcommands.variable.RelativeString; import me.filoghost.chestcommands.variable.RelativeStringList; @@ -67,9 +66,11 @@ public class ConfigurableIconImpl implements ConfigurableIcon { private ItemStack cachedItem; // When there are no variables, we don't recreate the item - public ConfigurableIconImpl() { - closeOnClick = true; - amount = 1; + public ConfigurableIconImpl(Material material) { + Preconditions.checkArgumentNotAir(material, "material"); + this.material = material; + this.amount = 1; + this.closeOnClick = true; } public boolean hasVariables() { @@ -80,7 +81,7 @@ public class ConfigurableIconImpl implements ConfigurableIcon { @Override public void setMaterial(Material material) { - if (material == Material.AIR) material = null; + Preconditions.checkArgumentNotAir(material, "material"); this.material = material; } @@ -275,22 +276,11 @@ public class ConfigurableIconImpl implements ConfigurableIcon { } public List calculateLore(Player viewer) { - List output = null; - if (hasLore()) { - output = lore.getValue(viewer); + return lore.getValue(viewer); + } else { + return null; } - - if (material == null) { - if (output == null) { - output = new ArrayList<>(); - } - - // Add an error message - output.add(ChatColor.RED + "(Invalid material)"); - } - - return output; } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java index a017422..1cd7e93 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java @@ -16,6 +16,7 @@ package me.filoghost.chestcommands.menu.icon; import java.util.List; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; @@ -37,6 +38,10 @@ public class AdvancedIcon extends ConfigurableIconImpl { private RequiredItems requiredItems; private List clickActions; + public AdvancedIcon(Material material) { + super(material); + } + public boolean canViewIcon(Player player) { return viewPermissionChecker == null || viewPermissionChecker.hasPermission(player); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index 095945b..9903308 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -19,6 +19,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.enchantments.Enchantment; @@ -92,9 +93,8 @@ public class IconParser { public static AdvancedIcon loadIconFromSection(ConfigurationSection section, String iconName, String menuFileName, ErrorCollector errorCollector) { Preconditions.notNull(section, "section"); - // The icon is valid even without a Material - AdvancedIcon icon = new AdvancedIcon(); - + AdvancedIcon icon = new AdvancedIcon(Material.BEDROCK); + String material = ConfigUtil.getAnyString(section, Nodes.MATERIAL); if (material != null) { try { @@ -103,7 +103,7 @@ public class IconParser { icon.setDurability(itemReader.getDurability()); icon.setAmount(itemReader.getAmount()); } catch (FormatException e) { - errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid ID: " + e.getMessage()); + errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid MATERIAL: " + e.getMessage()); } } From 99665821ec3407dec51196a941e8cf3e11fcc875 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 14 Jun 2020 21:05:07 +0200 Subject: [PATCH 067/213] Refactoring: make actions use RelativeString --- .../chestcommands/action/Action.java | 23 +++++++------ .../chestcommands/action/BroadcastAction.java | 9 ++++-- .../action/ChangeServerAction.java | 11 ++++--- .../action/ConsoleCommandAction.java | 12 ++++--- .../chestcommands/action/DragonBarAction.java | 32 +++++++------------ .../chestcommands/action/GiveItemAction.java | 25 +++------------ .../chestcommands/action/GiveMoneyAction.java | 20 ++---------- .../chestcommands/action/OpCommandAction.java | 16 ++++++---- .../chestcommands/action/OpenMenuAction.java | 14 ++++---- .../chestcommands/action/PlaySoundAction.java | 25 +++------------ .../action/PlayerCommandAction.java | 14 +++++--- .../action/SendMessageAction.java | 9 ++++-- .../chestcommands/parser/ActionParser.java | 7 ++-- 13 files changed, 90 insertions(+), 127 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java index b336658..c82657c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java @@ -16,23 +16,22 @@ package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.config.AsciiPlaceholders; -import me.filoghost.chestcommands.variable.VariableManager; - public abstract class Action { - protected String action; - protected boolean hasVariables; + private String errorMessage; - public Action(String action) { - this.action = AsciiPlaceholders.placeholdersToSymbols(action).trim(); - this.hasVariables = VariableManager.hasVariables(action); + protected void disable(String errorMessage) { + this.errorMessage = errorMessage; } - public String getParsedAction(Player executor) { - return hasVariables ? VariableManager.setVariables(action, executor) : action; + public void execute(Player player) { + if (errorMessage != null) { + player.sendMessage(errorMessage); + } else { + executeInner(player); + } } - - public abstract void execute(Player player); + + protected abstract void executeInner(Player player); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java index 226ba13..bf19312 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java @@ -18,16 +18,19 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import me.filoghost.chestcommands.util.FormatUtils; +import me.filoghost.chestcommands.variable.RelativeString; public class BroadcastAction extends Action { + + private RelativeString message; public BroadcastAction(String action) { - super(FormatUtils.addColors(action)); + message = RelativeString.of(FormatUtils.addColors(action)); } @Override - public void execute(Player player) { - Bukkit.broadcastMessage(getParsedAction(player)); + protected void executeInner(Player player) { + Bukkit.broadcastMessage(message.getValue(player)); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java index a7233f0..fde0e6d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java @@ -17,16 +17,19 @@ package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; import me.filoghost.chestcommands.bridge.BungeeCordBridge; +import me.filoghost.chestcommands.variable.RelativeString; public class ChangeServerAction extends Action { - public ChangeServerAction(String action) { - super(action); + private RelativeString targetServer; + + public ChangeServerAction(String serializedAction) { + targetServer = RelativeString.of(serializedAction); } @Override - public void execute(Player player) { - BungeeCordBridge.connect(player, hasVariables ? getParsedAction(player) : action); + protected void executeInner(Player player) { + BungeeCordBridge.connect(player, targetServer.getValue(player)); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java index f3832f3..d4aa20c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java @@ -17,15 +17,19 @@ package me.filoghost.chestcommands.action; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.variable.RelativeString; + public class ConsoleCommandAction extends Action { - public ConsoleCommandAction(String action) { - super(action); + private RelativeString command; + + public ConsoleCommandAction(String serializedAction) { + command = RelativeString.of(serializedAction); } @Override - public void execute(Player player) { - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), getParsedAction(player)); + protected void executeInner(Player player) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.getValue(player)); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java index cff1fd4..866a7b2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java @@ -14,50 +14,42 @@ */ package me.filoghost.chestcommands.action; +import org.bukkit.ChatColor; import org.bukkit.entity.Player; import me.filoghost.chestcommands.bridge.BarAPIBridge; import me.filoghost.chestcommands.parser.FormatException; import me.filoghost.chestcommands.parser.NumberParser; import me.filoghost.chestcommands.util.FormatUtils; +import me.filoghost.chestcommands.variable.RelativeString; public class DragonBarAction extends Action { - private String message; + private RelativeString message; private int seconds; - public DragonBarAction(String action) { - super(action); - if (!hasVariables) { - parseBar(super.action); - } - } - - private void parseBar(String action) { + public DragonBarAction(String serialiazedAction) { seconds = 1; - message = action; - - String[] split = action.split("\\|", 2); // Max of 2 pieces + String message = serialiazedAction; + + String[] split = serialiazedAction.split("\\|", 2); // Max of 2 pieces if (split.length > 1) { try { seconds = NumberParser.getStrictlyPositiveInteger(split[0].trim()); message = split[1].trim(); } catch (FormatException ex) { - // Ignore - // TODO: notify with message + disable(ChatColor.RED + "Invalid dragon bar time: " + split[0]); + return; } } - message = FormatUtils.addColors(message); + this.message = RelativeString.of(FormatUtils.addColors(message)); } @Override - public void execute(Player player) { - if (hasVariables) { - parseBar(getParsedAction(player)); - } + protected void executeInner(Player player) { if (BarAPIBridge.hasValidPlugin()) { - BarAPIBridge.setMessage(player, message, seconds); + BarAPIBridge.setMessage(player, message.getValue(player), seconds); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java index d59fb1c..ab8f30f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java @@ -24,35 +24,18 @@ import me.filoghost.chestcommands.parser.ItemStackParser; public class GiveItemAction extends Action { private ItemStack itemToGive; - private String errorMessage; - public GiveItemAction(String action) { - super(action); - if (!hasVariables) { - parseItem(super.action); - } - } - - private void parseItem(String action) { + public GiveItemAction(String serializedAction) { try { - ItemStackParser reader = new ItemStackParser(action, true); + ItemStackParser reader = new ItemStackParser(serializedAction, true); itemToGive = reader.createStack(); - errorMessage = null; } catch (FormatException e) { - errorMessage = ChatColor.RED + "Invalid item to give: " + e.getMessage(); + disable(ChatColor.RED + "Invalid item to give: " + e.getMessage()); } } @Override - public void execute(Player player) { - if (hasVariables) { - parseItem(getParsedAction(player)); - } - if (errorMessage != null) { - player.sendMessage(errorMessage); - return; - } - + protected void executeInner(Player player) { player.getInventory().addItem(itemToGive.clone()); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java index 25165f6..2e5c8d7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java @@ -24,33 +24,17 @@ import me.filoghost.chestcommands.parser.NumberParser; public class GiveMoneyAction extends Action { private double moneyToGive; - private String errorMessage; public GiveMoneyAction(String action) { - super(action); - if (!hasVariables) { - parseMoney(super.action); - } - } - - private void parseMoney(String action) { try { moneyToGive = NumberParser.getStrictlyPositiveDouble(action); } catch (FormatException e) { - errorMessage = ChatColor.RED + "Invalid money amount: " + action; + disable(ChatColor.RED + "Invalid money amount: " + action); } } @Override - public void execute(Player player) { - if (hasVariables) { - parseMoney(getParsedAction(player)); - } - if (errorMessage != null) { - player.sendMessage(errorMessage); - return; - } - + protected void executeInner(Player player) { if (EconomyBridge.hasValidEconomy()) { EconomyBridge.giveMoney(player, moneyToGive); } else { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java index 51c26cd..b5165e4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java @@ -16,21 +16,23 @@ package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.variable.RelativeString; + public class OpCommandAction extends Action { - public OpCommandAction(String action) { - super(action); + private RelativeString command; + + public OpCommandAction(String serializedAction) { + command = RelativeString.of(serializedAction); } @Override - public void execute(Player player) { - + protected void executeInner(Player player) { if (player.isOp()) { - player.chat("/" + getParsedAction(player)); - + player.chat("/" + command.getValue(player)); } else { player.setOp(true); - player.chat("/" + getParsedAction(player)); + player.chat("/" + command.getValue(player)); player.setOp(false); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java index 52e9ad9..614e224 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java @@ -20,19 +20,21 @@ import org.bukkit.entity.Player; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.menu.AdvancedIconMenu; +import me.filoghost.chestcommands.variable.RelativeString; public class OpenMenuAction extends Action { - public OpenMenuAction(String action) { - super(action); + private RelativeString targetMenu; + + public OpenMenuAction(String serializedAction) { + targetMenu = RelativeString.of(serializedAction); } @Override - public void execute(final Player player) { - String target = hasVariables ? getParsedAction(player) : action; - final AdvancedIconMenu menu = ChestCommands.getInstance().getMenuManager().getMenuByFileName(target.toLowerCase()); + protected void executeInner(final Player player) { + final AdvancedIconMenu menu = ChestCommands.getInstance().getMenuManager().getMenuByFileName(targetMenu.getValue(player)); + if (menu != null) { - /* * Delay the task, since this action is executed in ClickInventoryEvent * and opening another inventory in the same moment is not a good idea. diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java index 74abe55..ed85568 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java @@ -27,25 +27,16 @@ public class PlaySoundAction extends Action { private Sound sound; private float pitch; private float volume; - private String errorMessage; - public PlaySoundAction(String action) { - super(action); - if (!hasVariables) { - parseSound(super.action); - } - } - - private void parseSound(String action) { - errorMessage = null; + public PlaySoundAction(String serializedAction) { pitch = 1.0f; volume = 1.0f; - String[] split = action.split(","); + String[] split = serializedAction.split(","); sound = SOUNDS_REGISTRY.find(split[0]); if (sound == null) { - errorMessage = ChatColor.RED + "Invalid sound \"" + split[0].trim() + "\"."; + disable(ChatColor.RED + "Invalid sound \"" + split[0].trim() + "\"."); return; } @@ -65,15 +56,7 @@ public class PlaySoundAction extends Action { } @Override - public void execute(Player player) { - if (hasVariables) { - parseSound(getParsedAction(player)); - } - if (errorMessage != null) { - player.sendMessage(errorMessage); - return; - } - + protected void executeInner(Player player) { player.playSound(player.getLocation(), sound, volume, pitch); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java index ccc541b..72fddda 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java @@ -16,15 +16,19 @@ package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; -public class PlayerCommandAction extends Action { +import me.filoghost.chestcommands.variable.RelativeString; - public PlayerCommandAction(String action) { - super(action); +public class PlayerCommandAction extends Action { + + private RelativeString command; + + public PlayerCommandAction(String serializedAction) { + command = RelativeString.of(serializedAction); } @Override - public void execute(Player player) { - player.chat('/' + getParsedAction(player)); + protected void executeInner(Player player) { + player.chat('/' + command.getValue(player)); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java index 715cb0a..533e106 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java @@ -17,16 +17,19 @@ package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; import me.filoghost.chestcommands.util.FormatUtils; +import me.filoghost.chestcommands.variable.RelativeString; public class SendMessageAction extends Action { + + private RelativeString message; public SendMessageAction(String action) { - super(FormatUtils.addColors(action)); + message = RelativeString.of(FormatUtils.addColors(action)); } @Override - public void execute(Player player) { - player.sendMessage(getParsedAction(player)); + protected void executeInner(Player player) { + player.sendMessage(message.getValue(player)); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ActionParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ActionParser.java index f8ac383..ac5dc6c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ActionParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ActionParser.java @@ -21,6 +21,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import me.filoghost.chestcommands.action.*; +import me.filoghost.chestcommands.config.AsciiPlaceholders; public class ActionParser { @@ -48,12 +49,12 @@ public class ActionParser { Matcher matcher = entry.getKey().matcher(input); if (matcher.find()) { // Remove the action prefix and trim the spaces - String cleanCommand = matcher.replaceFirst("").trim(); - return entry.getValue().create(cleanCommand); + String serializedAction = matcher.replaceFirst("").trim(); + return entry.getValue().create(AsciiPlaceholders.placeholdersToSymbols(serializedAction)); } } - return new PlayerCommandAction(input); // Default action, no match found + return new PlayerCommandAction(AsciiPlaceholders.placeholdersToSymbols(input)); // Default action, no match found } From 3aa6bcf7c61ae8648988e7e8aeeef8d5bbd2671a Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 14 Jun 2020 21:06:31 +0200 Subject: [PATCH 068/213] Rename FormatException to ParseException --- .../chestcommands/action/DragonBarAction.java | 4 +-- .../chestcommands/action/GiveItemAction.java | 4 +-- .../chestcommands/action/GiveMoneyAction.java | 4 +-- .../chestcommands/parser/IconParser.java | 10 +++---- .../chestcommands/parser/ItemMetaParser.java | 18 ++++++------- .../chestcommands/parser/ItemStackParser.java | 4 +-- .../chestcommands/parser/MenuParser.java | 2 +- .../chestcommands/parser/NumberParser.java | 26 +++++++++---------- ...rmatException.java => ParseException.java} | 4 +-- 9 files changed, 38 insertions(+), 38 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/parser/{FormatException.java => ParseException.java} (87%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java index 866a7b2..921d047 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java @@ -18,7 +18,7 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import me.filoghost.chestcommands.bridge.BarAPIBridge; -import me.filoghost.chestcommands.parser.FormatException; +import me.filoghost.chestcommands.parser.ParseException; import me.filoghost.chestcommands.parser.NumberParser; import me.filoghost.chestcommands.util.FormatUtils; import me.filoghost.chestcommands.variable.RelativeString; @@ -37,7 +37,7 @@ public class DragonBarAction extends Action { try { seconds = NumberParser.getStrictlyPositiveInteger(split[0].trim()); message = split[1].trim(); - } catch (FormatException ex) { + } catch (ParseException ex) { disable(ChatColor.RED + "Invalid dragon bar time: " + split[0]); return; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java index ab8f30f..9dcff14 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java @@ -18,7 +18,7 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import me.filoghost.chestcommands.parser.FormatException; +import me.filoghost.chestcommands.parser.ParseException; import me.filoghost.chestcommands.parser.ItemStackParser; public class GiveItemAction extends Action { @@ -29,7 +29,7 @@ public class GiveItemAction extends Action { try { ItemStackParser reader = new ItemStackParser(serializedAction, true); itemToGive = reader.createStack(); - } catch (FormatException e) { + } catch (ParseException e) { disable(ChatColor.RED + "Invalid item to give: " + e.getMessage()); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java index 2e5c8d7..2dc578f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java @@ -18,7 +18,7 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import me.filoghost.chestcommands.bridge.EconomyBridge; -import me.filoghost.chestcommands.parser.FormatException; +import me.filoghost.chestcommands.parser.ParseException; import me.filoghost.chestcommands.parser.NumberParser; public class GiveMoneyAction extends Action { @@ -28,7 +28,7 @@ public class GiveMoneyAction extends Action { public GiveMoneyAction(String action) { try { moneyToGive = NumberParser.getStrictlyPositiveDouble(action); - } catch (FormatException e) { + } catch (ParseException e) { disable(ChatColor.RED + "Invalid money amount: " + action); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index 9903308..6cbb1f6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -102,7 +102,7 @@ public class IconParser { icon.setMaterial(itemReader.getMaterial()); icon.setDurability(itemReader.getDurability()); icon.setAmount(itemReader.getAmount()); - } catch (FormatException e) { + } catch (ParseException e) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid MATERIAL: " + e.getMessage()); } } @@ -152,7 +152,7 @@ public class IconParser { if (section.isSet(Nodes.COLOR)) { try { icon.setLeatherColor(ItemMetaParser.parseColor(section.getString(Nodes.COLOR))); - } catch (FormatException e) { + } catch (ParseException e) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid COLOR: " + e.getMessage()); } } @@ -163,7 +163,7 @@ public class IconParser { if (bannerColor != null) { try { icon.setBannerColor(ItemMetaParser.parseDyeColor(bannerColor)); - } catch (FormatException e) { + } catch (ParseException e) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid BANNER-COLOR: " + e.getMessage()); } } @@ -171,7 +171,7 @@ public class IconParser { if (section.isSet(Nodes.BANNER_PATTERNS)) { try { icon.setBannerPatterns(ItemMetaParser.parseBannerPatternList(section.getStringList(Nodes.BANNER_PATTERNS))); - } catch (FormatException e) { + } catch (ParseException e) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid BANNER-PATTERNS: " + e.getMessage()); } } @@ -226,7 +226,7 @@ public class IconParser { requiredItem.setRestrictiveDurability(itemReader.getDurability()); } requiredItems.add(requiredItem); - } catch (FormatException e) { + } catch (ParseException e) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has invalid REQUIRED-ITEMS: " + e.getMessage()); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java index f22c41d..676ebde 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java @@ -31,11 +31,11 @@ public final class ItemMetaParser { private ItemMetaParser() {} - public static Color parseColor(String input) throws FormatException { + public static Color parseColor(String input) throws ParseException { String[] split = input.replace(" ", "").split(","); if (split.length != 3) { - throw new FormatException("it must be in the format \"red, green, blue\"."); + throw new ParseException("it must be in the format \"red, green, blue\"."); } int red, green, blue; @@ -45,38 +45,38 @@ public final class ItemMetaParser { green = Integer.parseInt(split[1]); blue = Integer.parseInt(split[2]); } catch (NumberFormatException ex) { - throw new FormatException("it contains invalid numbers."); + throw new ParseException("it contains invalid numbers."); } if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) { - throw new FormatException("it should only contain numbers between 0 and 255."); + throw new ParseException("it should only contain numbers between 0 and 255."); } return Color.fromRGB(red, green, blue); } - public static DyeColor parseDyeColor(String input) throws FormatException { + public static DyeColor parseDyeColor(String input) throws ParseException { DyeColor color = DYE_COLORS_REGISTRY.find(input); if (color == null) { - throw new FormatException("it must be a valid color."); + throw new ParseException("it must be a valid color."); } return color; } - public static List parseBannerPatternList(List input) throws FormatException { + public static List parseBannerPatternList(List input) throws ParseException { List patterns = new ArrayList(); for (String str : input) { String[] split = str.split(":"); if (split.length != 2) { - throw new FormatException("it must be in the format \"pattern:color\"."); + throw new ParseException("it must be in the format \"pattern:color\"."); } PatternType patternType = PATTERN_TYPES_REGISTRY.find(split[0]); DyeColor patternColor = parseDyeColor(split[1]); if (patternType == null) { - throw new FormatException("it must be a valid pattern type."); + throw new ParseException("it must be a valid pattern type."); } patterns.add(new Pattern(patternColor, patternType)); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java index cd69254..d6ee3bd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java @@ -32,7 +32,7 @@ public class ItemStackParser { * id can be either the id of the material or its name. * for example wool:5, 3 is a valid input. */ - public ItemStackParser(String input, boolean parseAmount) throws FormatException { + public ItemStackParser(String input, boolean parseAmount) throws ParseException { Preconditions.notNull(input, "input"); // Remove spaces, they're not needed @@ -67,7 +67,7 @@ public class ItemStackParser { Material material = MaterialsHelper.matchMaterial(input); if (material == null || MaterialsHelper.isAir(material)) { - throw new FormatException("invalid material \"" + input + "\""); + throw new ParseException("invalid material \"" + input + "\""); } this.material = material; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java index 122cedc..d920f34 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java @@ -158,7 +158,7 @@ public class MenuParser { openTrigger.setRestrictiveDurability(itemReader.getDurability()); } - } catch (FormatException e) { + } catch (ParseException e) { errorCollector.addError("The item \"" + openItemMaterial + "\" used to open the menu \"" + config.getFileName() + "\" is invalid: " + e.getMessage()); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/NumberParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/NumberParser.java index 2e7db8f..b047c0c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/NumberParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/NumberParser.java @@ -16,59 +16,59 @@ package me.filoghost.chestcommands.parser; public class NumberParser { - public static double getStrictlyPositiveDouble(String input) throws FormatException { + public static double getStrictlyPositiveDouble(String input) throws ParseException { return getStrictlyPositiveDouble(input, "number must be a valid decimal and greater than 0"); } - public static double getStrictlyPositiveDouble(String input, String errorMessage) throws FormatException { + public static double getStrictlyPositiveDouble(String input, String errorMessage) throws ParseException { double value = getDouble(input, errorMessage); check(value > 0.0, errorMessage); return value; } - private static double getDouble(String input, String errorMessage) throws FormatException { + private static double getDouble(String input, String errorMessage) throws ParseException { try { return Double.parseDouble(input); } catch (NumberFormatException ex) { - throw new FormatException(errorMessage); + throw new ParseException(errorMessage); } } - public static short getPositiveShort(String input, String errorMessage) throws FormatException { + public static short getPositiveShort(String input, String errorMessage) throws ParseException { short value = getShort(input, errorMessage); check(value >= 0, errorMessage); return value; } - public static short getShort(String input, String errorMessage) throws FormatException { + public static short getShort(String input, String errorMessage) throws ParseException { try { return Short.parseShort(input); } catch (NumberFormatException ex) { - throw new FormatException(errorMessage); + throw new ParseException(errorMessage); } } - public static int getStrictlyPositiveInteger(String input) throws FormatException { + public static int getStrictlyPositiveInteger(String input) throws ParseException { return getStrictlyPositiveInteger(input, "number must be a valid integer and greater than 0"); } - public static int getStrictlyPositiveInteger(String input, String errorMessage) throws FormatException { + public static int getStrictlyPositiveInteger(String input, String errorMessage) throws ParseException { int value = getInteger(input, errorMessage); check(value > 0, errorMessage); return value; } - public static int getInteger(String input, String errorMessage) throws FormatException { + public static int getInteger(String input, String errorMessage) throws ParseException { try { return Integer.parseInt(input); } catch (NumberFormatException ex) { - throw new FormatException(errorMessage); + throw new ParseException(errorMessage); } } - private static void check(boolean expression, String errorMessage) throws FormatException { + private static void check(boolean expression, String errorMessage) throws ParseException { if (!expression) { - throw new FormatException(errorMessage); + throw new ParseException(errorMessage); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/FormatException.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ParseException.java similarity index 87% rename from Plugin/src/main/java/me/filoghost/chestcommands/parser/FormatException.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parser/ParseException.java index d98eac3..5f62736 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/FormatException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ParseException.java @@ -14,11 +14,11 @@ */ package me.filoghost.chestcommands.parser; -public class FormatException extends Exception { +public class ParseException extends Exception { private static final long serialVersionUID = 1L; - public FormatException(String message) { + public ParseException(String message) { super(message); } } From 090eec55099add17395c5465e07afc88b6259c77 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 15 Jun 2020 17:40:40 +0200 Subject: [PATCH 069/213] Refactoring --- .../chestcommands/action/DragonBarAction.java | 7 ++++--- .../chestcommands/action/PlaySoundAction.java | 9 +++++---- .../chestcommands/config/AsciiPlaceholders.java | 7 ++++--- .../chestcommands/config/ConfigUtil.java | 10 +++++----- .../chestcommands/parser/EnchantmentParser.java | 3 ++- .../chestcommands/parser/ItemMetaParser.java | 6 ++++-- .../chestcommands/parser/ItemStackParser.java | 8 +++----- .../me/filoghost/chestcommands/util/Strings.java | 16 +++++++++++++++- 8 files changed, 42 insertions(+), 24 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java index 921d047..19bfbfa 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java @@ -21,6 +21,7 @@ import me.filoghost.chestcommands.bridge.BarAPIBridge; import me.filoghost.chestcommands.parser.ParseException; import me.filoghost.chestcommands.parser.NumberParser; import me.filoghost.chestcommands.util.FormatUtils; +import me.filoghost.chestcommands.util.Strings; import me.filoghost.chestcommands.variable.RelativeString; public class DragonBarAction extends Action { @@ -32,11 +33,11 @@ public class DragonBarAction extends Action { seconds = 1; String message = serialiazedAction; - String[] split = serialiazedAction.split("\\|", 2); // Max of 2 pieces + String[] split = Strings.trimmedSplit(serialiazedAction, "\\|", 2); // Max of 2 pieces if (split.length > 1) { try { - seconds = NumberParser.getStrictlyPositiveInteger(split[0].trim()); - message = split[1].trim(); + seconds = NumberParser.getStrictlyPositiveInteger(split[0]); + message = split[1]; } catch (ParseException ex) { disable(ChatColor.RED + "Invalid dragon bar time: " + split[0]); return; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java index ed85568..bb038b1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java @@ -19,6 +19,7 @@ import org.bukkit.Sound; import org.bukkit.entity.Player; import me.filoghost.chestcommands.util.Registry; +import me.filoghost.chestcommands.util.Strings; public class PlaySoundAction extends Action { @@ -32,24 +33,24 @@ public class PlaySoundAction extends Action { pitch = 1.0f; volume = 1.0f; - String[] split = serializedAction.split(","); + String[] split = Strings.trimmedSplit(serializedAction, ",", 3); sound = SOUNDS_REGISTRY.find(split[0]); if (sound == null) { - disable(ChatColor.RED + "Invalid sound \"" + split[0].trim() + "\"."); + disable(ChatColor.RED + "Invalid sound \"" + split[0] + "\"."); return; } if (split.length > 1) { try { - pitch = Float.parseFloat(split[1].trim()); + pitch = Float.parseFloat(split[1]); } catch (NumberFormatException e) { } } if (split.length > 2) { try { - volume = Float.parseFloat(split[2].trim()); + volume = Float.parseFloat(split[2]); } catch (NumberFormatException e) { } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java index 45f6572..6db3dc4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java @@ -28,6 +28,7 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.util.ErrorCollector; import me.filoghost.chestcommands.util.FileUtils; import me.filoghost.chestcommands.util.FormatUtils; +import me.filoghost.chestcommands.util.Strings; /** * This is not a real YAML file ;) @@ -59,9 +60,9 @@ public class AsciiPlaceholders { continue; } - int indexOf = line.indexOf(':'); - String placeholder = unquote(line.substring(0, indexOf).trim()); - String replacement = FormatUtils.addColors(StringEscapeUtils.unescapeJava(unquote(line.substring(indexOf + 1, line.length()).trim()))); + String[] parts = Strings.trimmedSplit(line, ":", 2); + String placeholder = unquote(parts[0]); + String replacement = FormatUtils.addColors(StringEscapeUtils.unescapeJava(unquote(parts[1]))); if (placeholder.length() == 0 || replacement.length() == 0) { errorCollector.addError("Unable to parse a line(" + line + ") from placeholders.yml: the placeholder and the replacement must have both at least 1 character."); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java index a5c513d..436714e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java @@ -21,6 +21,8 @@ import java.util.regex.Pattern; import org.bukkit.configuration.ConfigurationSection; +import me.filoghost.chestcommands.util.Strings; + public class ConfigUtil { public static String getAnyString(ConfigurationSection config, String... paths) { @@ -73,14 +75,12 @@ public class ConfigUtil { separator = ";"; } - String[] splitValues = input.split(Pattern.quote(separator)); + String[] splitValues = Strings.trimmedSplit(input, Pattern.quote(separator)); List values = new ArrayList<>(); for (String value : splitValues) { - String trimmedValue = value.trim(); - - if (!trimmedValue.isEmpty()) { - values.add(trimmedValue); + if (!value.isEmpty()) { + values.add(value); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/EnchantmentParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/EnchantmentParser.java index b21e387..6c710b7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/EnchantmentParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/EnchantmentParser.java @@ -17,6 +17,7 @@ package me.filoghost.chestcommands.parser; import org.bukkit.enchantments.Enchantment; import me.filoghost.chestcommands.util.Registry; +import me.filoghost.chestcommands.util.Strings; import me.filoghost.chestcommands.util.ErrorCollector; public class EnchantmentParser { @@ -57,7 +58,7 @@ public class EnchantmentParser { int level = 1; if (input.contains(",")) { - String[] levelSplit = input.split(","); + String[] levelSplit = Strings.trimmedSplit(input, ",", 2); try { level = Integer.parseInt(levelSplit[1].trim()); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java index 676ebde..c98183c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java @@ -20,6 +20,8 @@ import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.PatternType; import me.filoghost.chestcommands.util.Registry; +import me.filoghost.chestcommands.util.Strings; + import java.util.ArrayList; import java.util.List; @@ -32,7 +34,7 @@ public final class ItemMetaParser { public static Color parseColor(String input) throws ParseException { - String[] split = input.replace(" ", "").split(","); + String[] split = Strings.trimmedSplit(input, ","); if (split.length != 3) { throw new ParseException("it must be in the format \"red, green, blue\"."); @@ -67,7 +69,7 @@ public final class ItemMetaParser { public static List parseBannerPatternList(List input) throws ParseException { List patterns = new ArrayList(); for (String str : input) { - String[] split = str.split(":"); + String[] split = Strings.trimmedSplit(str, ":"); if (split.length != 2) { throw new ParseException("it must be in the format \"pattern:color\"."); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java index d6ee3bd..2ef0734 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java @@ -19,6 +19,7 @@ import org.bukkit.inventory.ItemStack; import me.filoghost.chestcommands.util.MaterialsHelper; import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.chestcommands.util.Strings; public class ItemStackParser { @@ -35,12 +36,9 @@ public class ItemStackParser { public ItemStackParser(String input, boolean parseAmount) throws ParseException { Preconditions.notNull(input, "input"); - // Remove spaces, they're not needed - input = input.replace(" ", ""); - if (parseAmount) { // Read the optional amount - String[] splitAmount = input.split(","); + String[] splitAmount = Strings.trimmedSplit(input, ",", 2); if (splitAmount.length > 1) { this.amount = NumberParser.getStrictlyPositiveInteger(splitAmount[1], "invalid amount \"" + splitAmount[1] + "\""); @@ -52,7 +50,7 @@ public class ItemStackParser { // Read the optional durability - String[] splitByColons = input.split(":"); + String[] splitByColons = Strings.trimmedSplit(input, ":", 2); if (splitByColons.length > 1) { short durability = NumberParser.getPositiveShort(splitByColons[1], "invalid durability \"" + splitByColons[1] + "\""); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Strings.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Strings.java index d5815c7..3a3fdc0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Strings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Strings.java @@ -17,7 +17,21 @@ package me.filoghost.chestcommands.util; public final class Strings { private Strings() {} - + + + public static String[] trimmedSplit(String input, String splitPattern) { + return trimmedSplit(input, splitPattern, 0); + } + + + public static String[] trimmedSplit(String input, String splitPattern, int splitLimit) { + String[] output = input.split(splitPattern, splitLimit); + for (int i = 0; i < output.length; i++) { + output[i] = output[i].trim(); + } + return output; + } + public static String stripChars(String input, char... removed) { if (input == null || input.isEmpty() || removed.length == 0) { From 66d959664c417bbdec005435e9fd6c6818fa379e Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 15 Jun 2020 18:24:39 +0200 Subject: [PATCH 070/213] Add API version getter --- .../chestcommands/api/ChestCommandsAPI.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java index a0a9c5c..6cdd64a 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java @@ -20,7 +20,21 @@ import me.filoghost.chestcommands.api.internal.BackendAPI; public class ChestCommandsAPI { + private ChestCommandsAPI() {} + + + /** + * The API version is increased every time the API is modified. + * You can use it to require a minimum version, as features may + * be added (rarely removed) in future versions. + * + * @return the API version + */ + public static int getAPIVersion() { + return 1; + } + /** * Checks if a menu with a given file name was loaded by the plugin. @@ -30,6 +44,7 @@ public class ChestCommandsAPI { public static boolean isPluginMenu(String yamlFile) { return BackendAPI.getImplementation().isPluginMenu(yamlFile); } + /** * Opens a menu loaded by ChestCommands to a player. From 31742879ec5d442d1bc5dcecd0d16ba9cd2c9e8c Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 15 Jun 2020 19:00:24 +0200 Subject: [PATCH 071/213] Refactor external plugin hooks --- .../chestcommands/ChestCommands.java | 22 +++++---- .../action/ChangeServerAction.java | 4 +- .../chestcommands/action/DragonBarAction.java | 6 +-- .../chestcommands/action/GiveMoneyAction.java | 6 +-- .../bridge/PlaceholderAPIBridge.java | 42 ----------------- .../BarAPIHook.java} | 34 ++++++-------- .../BungeeCordHook.java} | 22 +++++++-- .../hook/PlaceholderAPIHook.java | 35 ++++++++++++++ .../chestcommands/hook/PluginHook.java | 31 ++++++++++++ .../VaultEconomyHook.java} | 47 ++++++++++--------- .../menu/icon/RequiredMoney.java | 10 ++-- .../chestcommands/variable/Variable.java | 6 +-- .../variable/VariableManager.java | 8 ++-- 13 files changed, 156 insertions(+), 117 deletions(-) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/bridge/PlaceholderAPIBridge.java rename Plugin/src/main/java/me/filoghost/chestcommands/{bridge/BarAPIBridge.java => hook/BarAPIHook.java} (61%) rename Plugin/src/main/java/me/filoghost/chestcommands/{bridge/BungeeCordBridge.java => hook/BungeeCordHook.java} (83%) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java rename Plugin/src/main/java/me/filoghost/chestcommands/{bridge/EconomyBridge.java => hook/VaultEconomyHook.java} (68%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index a8a865c..a447b77 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -25,15 +25,16 @@ import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -import me.filoghost.chestcommands.bridge.BarAPIBridge; -import me.filoghost.chestcommands.bridge.EconomyBridge; -import me.filoghost.chestcommands.bridge.PlaceholderAPIBridge; import me.filoghost.chestcommands.command.CommandHandler; import me.filoghost.chestcommands.command.framework.CommandFramework; import me.filoghost.chestcommands.config.AsciiPlaceholders; import me.filoghost.chestcommands.config.Lang; import me.filoghost.chestcommands.config.Settings; import me.filoghost.chestcommands.config.yaml.PluginConfig; +import me.filoghost.chestcommands.hook.BarAPIHook; +import me.filoghost.chestcommands.hook.BungeeCordHook; +import me.filoghost.chestcommands.hook.PlaceholderAPIHook; +import me.filoghost.chestcommands.hook.VaultEconomyHook; import me.filoghost.chestcommands.listener.CommandListener; import me.filoghost.chestcommands.listener.InventoryListener; import me.filoghost.chestcommands.listener.JoinListener; @@ -82,16 +83,21 @@ public class ChestCommands extends JavaPlugin { } return; } - - if (!EconomyBridge.setupEconomy()) { - getLogger().warning("Vault with a compatible economy plugin was not found! Icons with a PRICE or commands that give money will not work."); + + VaultEconomyHook.INSTANCE.setup(); + BarAPIHook.INSTANCE.setup(); + PlaceholderAPIHook.INSTANCE.setup(); + BungeeCordHook.INSTANCE.setup(); + + if (!VaultEconomyHook.INSTANCE.isEnabled()) { + getLogger().warning("Couldn't find Vault and a compatible economy plugin! Money-related features will not work."); } - if (BarAPIBridge.setupPlugin()) { + if (BarAPIHook.INSTANCE.isEnabled()) { getLogger().info("Hooked BarAPI"); } - if (PlaceholderAPIBridge.setupPlugin()) { + if (PlaceholderAPIHook.INSTANCE.isEnabled()) { getLogger().info("Hooked PlaceholderAPI"); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java index fde0e6d..2395644 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java @@ -16,7 +16,7 @@ package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.bridge.BungeeCordBridge; +import me.filoghost.chestcommands.hook.BungeeCordHook; import me.filoghost.chestcommands.variable.RelativeString; public class ChangeServerAction extends Action { @@ -29,7 +29,7 @@ public class ChangeServerAction extends Action { @Override protected void executeInner(Player player) { - BungeeCordBridge.connect(player, targetServer.getValue(player)); + BungeeCordHook.connect(player, targetServer.getValue(player)); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java index 19bfbfa..025c7f3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java @@ -17,8 +17,8 @@ package me.filoghost.chestcommands.action; import org.bukkit.ChatColor; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.bridge.BarAPIBridge; import me.filoghost.chestcommands.parser.ParseException; +import me.filoghost.chestcommands.hook.BarAPIHook; import me.filoghost.chestcommands.parser.NumberParser; import me.filoghost.chestcommands.util.FormatUtils; import me.filoghost.chestcommands.util.Strings; @@ -49,8 +49,8 @@ public class DragonBarAction extends Action { @Override protected void executeInner(Player player) { - if (BarAPIBridge.hasValidPlugin()) { - BarAPIBridge.setMessage(player, message.getValue(player), seconds); + if (BarAPIHook.INSTANCE.isEnabled()) { + BarAPIHook.setMessage(player, message.getValue(player), seconds); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java index 2dc578f..d9b8df5 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java @@ -17,8 +17,8 @@ package me.filoghost.chestcommands.action; import org.bukkit.ChatColor; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.bridge.EconomyBridge; import me.filoghost.chestcommands.parser.ParseException; +import me.filoghost.chestcommands.hook.VaultEconomyHook; import me.filoghost.chestcommands.parser.NumberParser; public class GiveMoneyAction extends Action { @@ -35,8 +35,8 @@ public class GiveMoneyAction extends Action { @Override protected void executeInner(Player player) { - if (EconomyBridge.hasValidEconomy()) { - EconomyBridge.giveMoney(player, moneyToGive); + if (VaultEconomyHook.INSTANCE.isEnabled()) { + VaultEconomyHook.giveMoney(player, moneyToGive); } else { player.sendMessage(ChatColor.RED + "Vault with a compatible economy plugin not found. Please inform the staff."); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/PlaceholderAPIBridge.java b/Plugin/src/main/java/me/filoghost/chestcommands/bridge/PlaceholderAPIBridge.java deleted file mode 100644 index 8be6220..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/PlaceholderAPIBridge.java +++ /dev/null @@ -1,42 +0,0 @@ -package me.filoghost.chestcommands.bridge; - -import me.clip.placeholderapi.PlaceholderAPI; -import me.clip.placeholderapi.PlaceholderAPIPlugin; -import me.filoghost.chestcommands.util.Preconditions; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -public class PlaceholderAPIBridge { - - private static PlaceholderAPIPlugin placeholderAPI; - - public static boolean setupPlugin() { - Plugin placeholderPlugin = Bukkit.getPluginManager().getPlugin("PlaceholderAPI"); - - if (placeholderPlugin == null) { - return false; - } - - placeholderAPI = (PlaceholderAPIPlugin) placeholderPlugin; - return true; - } - - public static boolean hasValidPlugin() { - return placeholderAPI != null; - } - - public static boolean hasPlaceholders(String message) { - Preconditions.checkState(hasValidPlugin(), "PlaceholderAPI plugin not found"); - - return PlaceholderAPI.containsPlaceholders(message); - } - - public static String setPlaceholders(String message, Player executor) { - Preconditions.checkState(hasValidPlugin(), "PlaceholderAPI plugin not found"); - - return PlaceholderAPI.setPlaceholders(executor, message); - } - -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/BarAPIBridge.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java similarity index 61% rename from Plugin/src/main/java/me/filoghost/chestcommands/bridge/BarAPIBridge.java rename to Plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java index 751f6ac..dc64e39 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/BarAPIBridge.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java @@ -12,37 +12,31 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.bridge; +package me.filoghost.chestcommands.hook; import me.confuser.barapi.BarAPI; -import me.filoghost.chestcommands.util.Preconditions; - import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -public class BarAPIBridge { +public enum BarAPIHook implements PluginHook { - private static BarAPI barAPI; + INSTANCE; + + private boolean enabled; - public static boolean setupPlugin() { - Plugin barPlugin = Bukkit.getPluginManager().getPlugin("BarAPI"); - - if (barPlugin == null) { - return false; - } - - barAPI = (BarAPI) barPlugin; - return true; + @Override + public void setup() { + enabled = Bukkit.getPluginManager().getPlugin("BarAPI") != null; } - - public static boolean hasValidPlugin() { - return barAPI != null; + + @Override + public boolean isEnabled() { + return enabled; } - + @SuppressWarnings("deprecation") public static void setMessage(Player player, String message, int seconds) { - Preconditions.checkState(hasValidPlugin(), "BarAPI plugin not found"); + INSTANCE.checkEnabledState(); BarAPI.setMessage(player, message, seconds); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/BungeeCordBridge.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java similarity index 83% rename from Plugin/src/main/java/me/filoghost/chestcommands/bridge/BungeeCordBridge.java rename to Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java index a4a1939..8728d25 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/BungeeCordBridge.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java @@ -12,20 +12,32 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.bridge; +package me.filoghost.chestcommands.hook; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import me.filoghost.chestcommands.ChestCommands; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; +public enum BungeeCordHook implements PluginHook { + + INSTANCE; -public class BungeeCordBridge { + @Override + public void setup() {} + @Override + public boolean isEnabled() { + return true; + } + public static boolean connect(Player player, String server) { + INSTANCE.checkEnabledState(); + if (server.length() == 0) { player.sendMessage(ChatColor.RED + "Target server was an empty string, cannot connect to it."); return false; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java new file mode 100644 index 0000000..0a0ead6 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java @@ -0,0 +1,35 @@ +package me.filoghost.chestcommands.hook; + +import me.clip.placeholderapi.PlaceholderAPI; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public enum PlaceholderAPIHook implements PluginHook { + + INSTANCE; + + private boolean enabled; + + @Override + public void setup() { + enabled = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null; + } + + @Override + public boolean isEnabled() { + return enabled; + } + + public static boolean hasPlaceholders(String message) { + INSTANCE.checkEnabledState(); + + return PlaceholderAPI.containsPlaceholders(message); + } + + public static String setPlaceholders(String message, Player executor) { + INSTANCE.checkEnabledState(); + + return PlaceholderAPI.setPlaceholders(executor, message); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java new file mode 100644 index 0000000..4e92bbc --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java @@ -0,0 +1,31 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.hook; + +import me.filoghost.chestcommands.util.Preconditions; + +public interface PluginHook { + + + void setup(); + + boolean isEnabled(); + + public default void checkEnabledState() { + Preconditions.checkState(isEnabled(), "Plugin hook " + getClass().getSimpleName() + " is not enabled"); + } + + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java similarity index 68% rename from Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java rename to Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java index 8ed17f3..d673387 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/bridge/EconomyBridge.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.bridge; +package me.filoghost.chestcommands.hook; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -22,36 +22,43 @@ import me.filoghost.chestcommands.util.Preconditions; import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.EconomyResponse; -public class EconomyBridge { +public enum VaultEconomyHook implements PluginHook { - private static Economy economy; + INSTANCE; + + private Economy economy; - public static boolean setupEconomy() { + @Override + public void setup() { + economy = null; + if (Bukkit.getPluginManager().getPlugin("Vault") == null) { - return false; + return; } + RegisteredServiceProvider economyServiceProvider = Bukkit.getServicesManager().getRegistration(Economy.class); if (economyServiceProvider == null) { - return false; + return; } + economy = economyServiceProvider.getProvider(); - return economy != null; } - public static boolean hasValidEconomy() { + @Override + public boolean isEnabled() { return economy != null; } public static double getMoney(Player player) { - checkValidEconomy(); - return economy.getBalance(player, player.getWorld().getName()); + INSTANCE.checkEnabledState(); + return INSTANCE.economy.getBalance(player, player.getWorld().getName()); } public static boolean hasMoney(Player player, double minimum) { - checkValidEconomy(); + INSTANCE.checkEnabledState(); checkPositiveAmount(minimum); - double balance = economy.getBalance(player, player.getWorld().getName()); + double balance = INSTANCE.economy.getBalance(player, player.getWorld().getName()); if (balance < minimum) { return false; @@ -64,36 +71,32 @@ public class EconomyBridge { * @return true if the operation was successful. */ public static boolean takeMoney(Player player, double amount) { - checkValidEconomy(); + INSTANCE.checkEnabledState(); checkPositiveAmount(amount); - EconomyResponse response = economy.withdrawPlayer(player, player.getWorld().getName(), amount); + EconomyResponse response = INSTANCE.economy.withdrawPlayer(player, player.getWorld().getName(), amount); boolean result = response.transactionSuccess(); return result; } public static boolean giveMoney(Player player, double amount) { - checkValidEconomy(); + INSTANCE.checkEnabledState(); checkPositiveAmount(amount); - EconomyResponse response = economy.depositPlayer(player, player.getWorld().getName(), amount); + EconomyResponse response = INSTANCE.economy.depositPlayer(player, player.getWorld().getName(), amount); boolean result = response.transactionSuccess(); return result; } - - private static void checkValidEconomy() { - Preconditions.checkState(hasValidEconomy(), "economy plugin not found"); - } private static void checkPositiveAmount(double amount) { Preconditions.checkArgument(amount >= 0.0, "amount cannot be negative"); } public static String formatMoney(double amount) { - if (hasValidEconomy()) { - return economy.format(amount); + if (INSTANCE.economy != null) { + return INSTANCE.economy.format(amount); } else { return Double.toString(amount); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredMoney.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredMoney.java index 38bfef3..98741a3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredMoney.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/RequiredMoney.java @@ -20,7 +20,7 @@ import org.bukkit.entity.Player; import com.google.common.base.Preconditions; import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.bridge.EconomyBridge; +import me.filoghost.chestcommands.hook.VaultEconomyHook; public class RequiredMoney implements Requirement { @@ -37,13 +37,13 @@ public class RequiredMoney implements Requirement { @Override public boolean check(Player player) { - if (!EconomyBridge.hasValidEconomy()) { + if (!VaultEconomyHook.INSTANCE.isEnabled()) { player.sendMessage(ChatColor.RED + "This action has a price, but Vault with a compatible economy plugin was not found. For security, the action has been blocked. Please inform the staff."); return false; } - if (!EconomyBridge.hasMoney(player, moneyAmount)) { - player.sendMessage(ChestCommands.getLang().no_money.replace("{money}", EconomyBridge.formatMoney(moneyAmount))); + if (!VaultEconomyHook.hasMoney(player, moneyAmount)) { + player.sendMessage(ChestCommands.getLang().no_money.replace("{money}", VaultEconomyHook.formatMoney(moneyAmount))); return false; } @@ -52,7 +52,7 @@ public class RequiredMoney implements Requirement { @Override public boolean takeCost(Player player) { - boolean success = EconomyBridge.takeMoney(player, moneyAmount); + boolean success = VaultEconomyHook.takeMoney(player, moneyAmount); if (!success) { player.sendMessage(ChatColor.RED + "Error: a money transaction couldn't be executed. Please inform the staff."); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/variable/Variable.java b/Plugin/src/main/java/me/filoghost/chestcommands/variable/Variable.java index 8b986b9..275af28 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/variable/Variable.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/variable/Variable.java @@ -17,7 +17,7 @@ package me.filoghost.chestcommands.variable; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.bridge.EconomyBridge; +import me.filoghost.chestcommands.hook.VaultEconomyHook; public enum Variable { @@ -41,8 +41,8 @@ public enum Variable { MONEY("{money}") { public String getReplacement(Player executor) { - if (EconomyBridge.hasValidEconomy()) { - return EconomyBridge.formatMoney(EconomyBridge.getMoney(executor)); + if (VaultEconomyHook.INSTANCE.isEnabled()) { + return VaultEconomyHook.formatMoney(VaultEconomyHook.getMoney(executor)); } else { return "[ECONOMY PLUGIN NOT FOUND]"; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/variable/VariableManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/variable/VariableManager.java index 8462eb1..07f75e2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/variable/VariableManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/variable/VariableManager.java @@ -2,7 +2,7 @@ package me.filoghost.chestcommands.variable; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.bridge.PlaceholderAPIBridge; +import me.filoghost.chestcommands.hook.PlaceholderAPIHook; public class VariableManager { @@ -15,7 +15,7 @@ public class VariableManager { return true; } } - if (PlaceholderAPIBridge.hasValidPlugin() && PlaceholderAPIBridge.hasPlaceholders(message)) { + if (PlaceholderAPIHook.INSTANCE.isEnabled() && PlaceholderAPIHook.hasPlaceholders(message)) { return true; } return false; @@ -30,8 +30,8 @@ public class VariableManager { message = message.replace(variable.getText(), variable.getReplacement(executor)); } } - if (PlaceholderAPIBridge.hasValidPlugin()) { - message = PlaceholderAPIBridge.setPlaceholders(message, executor); + if (PlaceholderAPIHook.INSTANCE.isEnabled()) { + message = PlaceholderAPIHook.setPlaceholders(message, executor); } return message; } From ea4232f44d550640cd4d9a0a234fd49a2c48a6ae Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 15 Jun 2020 19:03:42 +0200 Subject: [PATCH 072/213] Refactoring --- .../chestcommands/ChestCommands.java | 24 ++++++++++--------- .../chestcommands/command/CommandHandler.java | 11 ++++----- .../chestcommands/hook/BungeeCordHook.java | 7 +++++- .../chestcommands/menu/AdvancedIconMenu.java | 10 ++++---- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index a447b77..66f8696 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -122,10 +122,8 @@ public class ChestCommands extends JavaPlugin { CommandFramework.register(this, new CommandHandler(menuManager, "chestcommands")); - ErrorCollector errorCollector = new ErrorCollector(); - load(errorCollector); - - lastLoadErrors = errorCollector; + ErrorCollector errorCollector = load(); + if (errorCollector.hasWarningsOrErrors()) { Bukkit.getScheduler().runTaskLater(this, () -> { errorCollector.logToConsole(); @@ -142,7 +140,8 @@ public class ChestCommands extends JavaPlugin { } - public void load(ErrorCollector errorCollector) { + public ErrorCollector load() { + ErrorCollector errors = new ErrorCollector(); menuManager.clear(); try { @@ -172,7 +171,7 @@ public class ChestCommands extends JavaPlugin { } try { - AsciiPlaceholders.load(errorCollector); + AsciiPlaceholders.load(errors); } catch (IOException e) { e.printStackTrace(); getLogger().warning("I/O error while reading the placeholders. They will not work."); @@ -196,18 +195,18 @@ public class ChestCommands extends JavaPlugin { menuConfig.load(); } catch (IOException e) { e.printStackTrace(); - errorCollector.addError("I/O error while loading the menu \"" + menuConfig.getFileName() + "\". Is the file in use?"); + errors.addError("I/O error while loading the menu \"" + menuConfig.getFileName() + "\". Is the file in use?"); continue; } catch (InvalidConfigurationException e) { e.printStackTrace(); - errorCollector.addError("Invalid YAML configuration for the menu \"" + menuConfig.getFileName() + "\". Please look at the error above, or use an online YAML parser (google is your friend)."); + errors.addError("Invalid YAML configuration for the menu \"" + menuConfig.getFileName() + "\". Please look at the error above, or use an online YAML parser (google is your friend)."); continue; } - MenuSettings menuSettings = MenuParser.loadMenuSettings(menuConfig, errorCollector); - AdvancedIconMenu iconMenu = MenuParser.loadMenu(menuConfig, menuSettings.getTitle(), menuSettings.getRows(), errorCollector); + MenuSettings menuSettings = MenuParser.loadMenuSettings(menuConfig, errors); + AdvancedIconMenu iconMenu = MenuParser.loadMenu(menuConfig, menuSettings.getTitle(), menuSettings.getRows(), errors); - menuManager.registerMenu(menuConfig.getFileName(), menuSettings.getCommands(), iconMenu, errorCollector); + menuManager.registerMenu(menuConfig.getFileName(), menuSettings.getCommands(), iconMenu, errors); iconMenu.setRefreshTicks(menuSettings.getRefreshTenths()); @@ -224,6 +223,9 @@ public class ChestCommands extends JavaPlugin { if (!Bukkit.getMessenger().isOutgoingChannelRegistered(this, "BungeeCord")) { Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); } + + ChestCommands.lastLoadErrors = errors; + return errors; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index 4a7b04a..ab13883 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -65,16 +65,13 @@ public class CommandHandler extends CommandFramework { ChestCommands.closeAllMenus(); - ErrorCollector errorCollector = new ErrorCollector(); - ChestCommands.getInstance().load(errorCollector); + ErrorCollector errors = ChestCommands.getInstance().load(); - ChestCommands.setLastReloadErrors(errorCollector); - - if (!errorCollector.hasWarningsOrErrors()) { + if (!errors.hasWarningsOrErrors()) { sender.sendMessage(ChestCommands.CHAT_PREFIX + "Plugin reloaded."); } else { - errorCollector.logToConsole(); - sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Plugin reloaded with " + errorCollector.getWarningsCount() + " warning(s) and " + errorCollector.getErrorsCount() + " error(s)."); + errors.logToConsole(); + sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Plugin reloaded with " + errors.getWarningsCount() + " warning(s) and " + errors.getErrorsCount() + " error(s)."); if (!(sender instanceof ConsoleCommandSender)) { sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Please check the console."); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java index 8728d25..7ab2144 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java @@ -18,6 +18,7 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -28,7 +29,11 @@ public enum BungeeCordHook implements PluginHook { INSTANCE; @Override - public void setup() {} + public void setup() { + if (!Bukkit.getMessenger().isOutgoingChannelRegistered(ChestCommands.getInstance(), "BungeeCord")) { + Bukkit.getMessenger().registerOutgoingPluginChannel(ChestCommands.getInstance(), "BungeeCord"); + } + } @Override public boolean isEnabled() { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java index 7b5572f..09039cf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java @@ -31,7 +31,7 @@ import me.filoghost.chestcommands.util.Utils; public class AdvancedIconMenu extends BaseIconMenu { private final String fileName; - private final String permission; + private final String openPermission; private List openActions; private int refreshTicks; @@ -39,7 +39,7 @@ public class AdvancedIconMenu extends BaseIconMenu { public AdvancedIconMenu(String title, int rows, String fileName) { super(title, rows); this.fileName = fileName; - this.permission = Permissions.OPEN_MENU_BASE + fileName; + this.openPermission = Permissions.OPEN_MENU_BASE + fileName; } public String getFileName() { @@ -51,7 +51,7 @@ public class AdvancedIconMenu extends BaseIconMenu { } public String getOpenPermission() { - return permission; + return openPermission; } public int getRefreshTicks() { @@ -79,7 +79,7 @@ public class AdvancedIconMenu extends BaseIconMenu { } public void openCheckingPermission(Player player) { - if (player.hasPermission(permission)) { + if (player.hasPermission(openPermission)) { open(player); } else { sendNoOpenPermissionMessage(player); @@ -121,7 +121,7 @@ public class AdvancedIconMenu extends BaseIconMenu { public void sendNoOpenPermissionMessage(CommandSender sender) { String noPermMessage = ChestCommands.getLang().no_open_permission; if (noPermMessage != null && !noPermMessage.isEmpty()) { - sender.sendMessage(noPermMessage.replace("{permission}", this.permission)); + sender.sendMessage(noPermMessage.replace("{permission}", this.openPermission)); } } From d9ef031ff16816f22a2b30018ba62ef60fcdf313 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 15 Jun 2020 19:07:21 +0200 Subject: [PATCH 073/213] Move classes --- .../java/me/filoghost/chestcommands/menu/BaseIconMenu.java | 2 ++ .../java/me/filoghost/chestcommands/menu/MenuManager.java | 1 + .../me/filoghost/chestcommands/menu/{ => inventory}/Grid.java | 2 +- .../menu/{ => inventory}/MenuInventoryHolder.java | 4 +++- 4 files changed, 7 insertions(+), 2 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/menu/{ => inventory}/Grid.java (94%) rename Plugin/src/main/java/me/filoghost/chestcommands/menu/{ => inventory}/MenuInventoryHolder.java (90%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java index 569c614..7f372a7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java @@ -22,6 +22,8 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import me.filoghost.chestcommands.api.Icon; +import me.filoghost.chestcommands.menu.inventory.Grid; +import me.filoghost.chestcommands.menu.inventory.MenuInventoryHolder; import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.Utils; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java index dce645b..fa421f8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java @@ -25,6 +25,7 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; +import me.filoghost.chestcommands.menu.inventory.MenuInventoryHolder; import me.filoghost.chestcommands.menu.settings.OpenTrigger; import me.filoghost.chestcommands.util.CaseInsensitiveMap; import me.filoghost.chestcommands.util.ErrorCollector; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/Grid.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/inventory/Grid.java similarity index 94% rename from Plugin/src/main/java/me/filoghost/chestcommands/menu/Grid.java rename to Plugin/src/main/java/me/filoghost/chestcommands/menu/inventory/Grid.java index d76714a..816aec9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/Grid.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/inventory/Grid.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.menu; +package me.filoghost.chestcommands.menu.inventory; import me.filoghost.chestcommands.util.Preconditions; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuInventoryHolder.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/inventory/MenuInventoryHolder.java similarity index 90% rename from Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuInventoryHolder.java rename to Plugin/src/main/java/me/filoghost/chestcommands/menu/inventory/MenuInventoryHolder.java index d413341..05946c8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuInventoryHolder.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/inventory/MenuInventoryHolder.java @@ -12,12 +12,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.menu; +package me.filoghost.chestcommands.menu.inventory; import org.bukkit.Bukkit; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; +import me.filoghost.chestcommands.menu.BaseIconMenu; + /** * This class links an IconMenu with an Inventory, via InventoryHolder. */ From 2e2d6ad75fa23530a3c44861f553b03800d81378 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 15 Jun 2020 19:12:06 +0200 Subject: [PATCH 074/213] Remove unused method --- .../main/java/me/filoghost/chestcommands/ChestCommands.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 66f8696..7d51d94 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -279,10 +279,6 @@ public class ChestCommands extends JavaPlugin { public static String getNewVersion() { return newVersion; } - - public static void setLastReloadErrors(ErrorCollector lastLoadErrors) { - ChestCommands.lastLoadErrors = lastLoadErrors; - } public static ErrorCollector getLastLoadErrors() { return lastLoadErrors; From 8f098fc961ae3cb032314ec1a65d6c2881ef81be Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 15 Jun 2020 19:53:59 +0200 Subject: [PATCH 075/213] Refactoring --- .../listener/InventoryListener.java | 15 +++---- .../chestcommands/menu/AdvancedIconMenu.java | 16 ++++--- .../chestcommands/menu/MenuManager.java | 43 ++++++++++--------- .../chestcommands/menu/MenuView.java | 6 +-- .../menu/inventory/MenuInventoryHolder.java | 2 + .../chestcommands/task/RefreshMenusTask.java | 11 ++++- 6 files changed, 51 insertions(+), 42 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index 0b888df..973eb4f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -53,23 +53,20 @@ public class InventoryListener implements Listener { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) public void onEarlyInventoryClick(InventoryClickEvent event) { - BaseIconMenu menu = MenuManager.getOpenMenu(event.getInventory()); - if (menu == null) { - return; + if (MenuManager.isMenuInventory(event.getInventory())) { + // Cancel the event as early as possible + event.setCancelled(true); } - - // Cancel the event as early as possible - event.setCancelled(true); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) public void onLateInventoryClick(InventoryClickEvent event) { Inventory inventory = event.getInventory(); - BaseIconMenu menu = MenuManager.getOpenMenu(inventory); - if (menu == null) { + BaseIconMenu menu = MenuManager.getOpenMenu(inventory); + if (menu == null) { return; } - + // Make sure the event is still cancelled (in case another plugin wrongly uncancels it) event.setCancelled(true); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java index 09039cf..c1514fa 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java @@ -95,26 +95,28 @@ public class AdvancedIconMenu extends BaseIconMenu { if (icon.hasViewPermission() || icon.hasVariables()) { // Then we have to refresh it - refreshIcon(player, inventory, icon, i); + ItemStack currentItem = inventory.getItem(i); + ItemStack newItem = refreshIcon(player, icon, currentItem); + inventory.setItem(i, newItem); } } } - private void refreshIcon(Player player, Inventory inventory, AdvancedIcon icon, int inventorySlot) { + private ItemStack refreshIcon(Player player, AdvancedIcon icon, ItemStack currentItem) { if (icon.canViewIcon(player)) { - if (inventory.getItem(inventorySlot) == null) { - ItemStack newItem = hideAttributes(icon.createItemStack(player)); - inventory.setItem(inventorySlot, newItem); + if (currentItem == null) { + return hideAttributes(icon.createItemStack(player)); } else { // Performance, only update name and lore - ItemStack oldItem = hideAttributes(inventory.getItem(inventorySlot)); + ItemStack oldItem = hideAttributes(currentItem); ItemMeta meta = oldItem.getItemMeta(); meta.setDisplayName(icon.calculateName(player)); meta.setLore(icon.calculateLore(player)); oldItem.setItemMeta(meta); + return oldItem; } } else { - inventory.setItem(inventorySlot, null); + return null; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java index fa421f8..52b32d8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java @@ -89,31 +89,28 @@ public class MenuManager { return Collections.unmodifiableCollection(menusByFile.keySet()); } + public static boolean isMenuInventory(Inventory inventory) { + return getMenuInventoryHolder(inventory) != null; + } public static BaseIconMenu getOpenMenu(Player player) { - InventoryView view = player.getOpenInventory(); - if (view == null) { + MenuView menuView = getOpenMenuView(player); + if (menuView != null) { + return menuView.getMenu(); + } else { return null; } - - BaseIconMenu openMenu = getOpenMenu(view.getTopInventory()); - if (openMenu == null) { - openMenu = getOpenMenu(view.getBottomInventory()); - } - - return openMenu; } - public static BaseIconMenu getOpenMenu(Inventory inventory) { - if (!(inventory.getHolder() instanceof MenuInventoryHolder)) { + MenuView menuView = getOpenMenuView(inventory); + if (menuView != null) { + return menuView.getMenu(); + } else { return null; } - - return ((MenuInventoryHolder) inventory.getHolder()).getIconMenu(); } - public static MenuView getOpenMenuView(Player player) { InventoryView view = player.getOpenInventory(); if (view == null) { @@ -129,17 +126,21 @@ public class MenuManager { } - private static MenuView getOpenMenuView(Inventory inventory) { - if (!(inventory.getHolder() instanceof MenuInventoryHolder)) { + public static MenuView getOpenMenuView(Inventory inventory) { + MenuInventoryHolder inventoryHolder = getMenuInventoryHolder(inventory); + if (inventoryHolder != null) { + return new MenuView(inventoryHolder.getIconMenu(), inventory); + } else { return null; } - - MenuInventoryHolder menuInventoryHolder = (MenuInventoryHolder) inventory.getHolder(); - if (!(menuInventoryHolder.getIconMenu() instanceof AdvancedIconMenu)) { + } + + private static MenuInventoryHolder getMenuInventoryHolder(Inventory inventory) { + if (inventory.getHolder() instanceof MenuInventoryHolder) { + return (MenuInventoryHolder) inventory.getHolder(); + } else { return null; } - - return new MenuView((AdvancedIconMenu) menuInventoryHolder.getIconMenu(), inventory); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuView.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuView.java index 62a272f..3df406a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuView.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuView.java @@ -18,15 +18,15 @@ import org.bukkit.inventory.Inventory; public class MenuView { - private final AdvancedIconMenu menu; + private final BaseIconMenu menu; private final Inventory inventory; - public MenuView(AdvancedIconMenu menu, Inventory inventory) { + public MenuView(BaseIconMenu menu, Inventory inventory) { this.menu = menu; this.inventory = inventory; } - public AdvancedIconMenu getMenu() { + public BaseIconMenu getMenu() { return menu; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/inventory/MenuInventoryHolder.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/inventory/MenuInventoryHolder.java index 05946c8..66c52ed 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/inventory/MenuInventoryHolder.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/inventory/MenuInventoryHolder.java @@ -19,6 +19,7 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import me.filoghost.chestcommands.menu.BaseIconMenu; +import me.filoghost.chestcommands.util.Preconditions; /** * This class links an IconMenu with an Inventory, via InventoryHolder. @@ -28,6 +29,7 @@ public class MenuInventoryHolder implements InventoryHolder { private final BaseIconMenu iconMenu; public MenuInventoryHolder(BaseIconMenu iconMenu) { + Preconditions.notNull(iconMenu, "iconMenu"); this.iconMenu = iconMenu; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java index 7e0aa0e..8a6c206 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java @@ -17,6 +17,7 @@ package me.filoghost.chestcommands.task; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import me.filoghost.chestcommands.menu.AdvancedIconMenu; import me.filoghost.chestcommands.menu.MenuManager; import me.filoghost.chestcommands.menu.MenuView; @@ -32,8 +33,14 @@ public class RefreshMenusTask implements Runnable { return; } - if (elapsedTenths % openMenuView.getMenu().getRefreshTicks() == 0) { - openMenuView.getMenu().refresh(player, openMenuView.getInventory()); + if (!(openMenuView.getMenu() instanceof AdvancedIconMenu)) { + return; + } + + AdvancedIconMenu iconMenu = (AdvancedIconMenu) openMenuView.getMenu(); + + if (elapsedTenths % iconMenu.getRefreshTicks() == 0) { + iconMenu.refresh(player, openMenuView.getInventory()); } } From 9e3f329ca0142c8853427e3f101a442c12ccfcde Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 15 Jun 2020 21:14:34 +0200 Subject: [PATCH 076/213] Refactoring: remove hideAttributes --- .../api/impl/ConfigurableIconImpl.java | 7 +++++++ .../chestcommands/menu/AdvancedIconMenu.java | 9 ++++---- .../chestcommands/menu/BaseIconMenu.java | 21 +------------------ 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java index f50f2fb..5ec1faf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java @@ -31,6 +31,7 @@ import org.bukkit.block.banner.Pattern; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BannerMeta; import org.bukkit.inventory.meta.ItemMeta; @@ -332,6 +333,11 @@ public class ConfigurableIconImpl implements ConfigurableIcon { ((BannerMeta) itemMeta).setPatterns(bannerPatterns); } } + + // Hide all text details (damage, enchantments, potions, etc,) + if (Utils.isNullOrEmpty(itemMeta.getItemFlags())) { + itemMeta.addItemFlags(ItemFlag.values()); + } itemStack.setItemMeta(itemMeta); @@ -341,6 +347,7 @@ public class ConfigurableIconImpl implements ConfigurableIcon { } } + if (!this.hasVariables()) { // If there are no variables, cache the item cachedItem = itemStack; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java index c1514fa..dc7e0b3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java @@ -105,15 +105,14 @@ public class AdvancedIconMenu extends BaseIconMenu { private ItemStack refreshIcon(Player player, AdvancedIcon icon, ItemStack currentItem) { if (icon.canViewIcon(player)) { if (currentItem == null) { - return hideAttributes(icon.createItemStack(player)); + return icon.createItemStack(player); } else { // Performance, only update name and lore - ItemStack oldItem = hideAttributes(currentItem); - ItemMeta meta = oldItem.getItemMeta(); + ItemMeta meta = currentItem.getItemMeta(); meta.setDisplayName(icon.calculateName(player)); meta.setLore(icon.calculateLore(player)); - oldItem.setItemMeta(meta); - return oldItem; + currentItem.setItemMeta(meta); + return currentItem; } } else { return null; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java index 7f372a7..c794149 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java @@ -17,15 +17,10 @@ package me.filoghost.chestcommands.menu; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.menu.inventory.Grid; import me.filoghost.chestcommands.menu.inventory.MenuInventoryHolder; import me.filoghost.chestcommands.util.Preconditions; -import me.filoghost.chestcommands.util.Utils; public class BaseIconMenu { @@ -76,7 +71,7 @@ public class BaseIconMenu { for (int i = 0; i < inventoryGrid.getSize(); i++) { T icon = inventoryGrid.getElementAtIndex(i); if (icon != null && canViewIcon(player, icon)) { - inventory.setItem(i, hideAttributes(icon.createItemStack(player))); + inventory.setItem(i, icon.createItemStack(player)); } } @@ -86,20 +81,6 @@ public class BaseIconMenu { protected boolean canViewIcon(Player player, T icon) { return true; } - - protected ItemStack hideAttributes(ItemStack item) { - if (item == null) { - return null; - } - - ItemMeta meta = item.getItemMeta(); - if (Utils.isNullOrEmpty(meta.getItemFlags())) { - // Add them only if no flag was already set - meta.addItemFlags(ItemFlag.values()); - item.setItemMeta(meta); - } - return item; - } @Override public String toString() { From 9d30458c5f0bb9119b8c59bfc8c44338a0eab9f0 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 15 Jun 2020 21:24:38 +0200 Subject: [PATCH 077/213] Refactoring: icon refresh improvements --- .../chestcommands/menu/AdvancedIconMenu.java | 30 +-------------- .../chestcommands/menu/BaseIconMenu.java | 17 ++++++--- .../chestcommands/menu/icon/AdvancedIcon.java | 38 +++++++++++++++++++ 3 files changed, 51 insertions(+), 34 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java index dc7e0b3..0634ee5 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java @@ -20,7 +20,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; @@ -73,11 +72,6 @@ public class AdvancedIconMenu extends BaseIconMenu { super.open(player); } - @Override - protected boolean canViewIcon(Player player, AdvancedIcon icon) { - return icon.canViewIcon(player); - } - public void openCheckingPermission(Player player) { if (player.hasPermission(openPermission)) { open(player); @@ -93,31 +87,11 @@ public class AdvancedIconMenu extends BaseIconMenu { continue; } - if (icon.hasViewPermission() || icon.hasVariables()) { - // Then we have to refresh it - ItemStack currentItem = inventory.getItem(i); - ItemStack newItem = refreshIcon(player, icon, currentItem); - inventory.setItem(i, newItem); - } + ItemStack newItemStack = icon.refreshItemStack(player, inventory.getItem(i)); + inventory.setItem(i, newItemStack); } } - private ItemStack refreshIcon(Player player, AdvancedIcon icon, ItemStack currentItem) { - if (icon.canViewIcon(player)) { - if (currentItem == null) { - return icon.createItemStack(player); - } else { - // Performance, only update name and lore - ItemMeta meta = currentItem.getItemMeta(); - meta.setDisplayName(icon.calculateName(player)); - meta.setLore(icon.calculateLore(player)); - currentItem.setItemMeta(meta); - return currentItem; - } - } else { - return null; - } - } public void sendNoOpenPermissionMessage(CommandSender sender) { String noPermMessage = ChestCommands.getLang().no_open_permission; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java index c794149..9ab7e01 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java @@ -17,6 +17,8 @@ package me.filoghost.chestcommands.menu; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.menu.inventory.Grid; import me.filoghost.chestcommands.menu.inventory.MenuInventoryHolder; @@ -70,17 +72,20 @@ public class BaseIconMenu { for (int i = 0; i < inventoryGrid.getSize(); i++) { T icon = inventoryGrid.getElementAtIndex(i); - if (icon != null && canViewIcon(player, icon)) { - inventory.setItem(i, icon.createItemStack(player)); + if (icon == null) { + continue; } + + ItemStack itemStack = icon.createItemStack(player); + if (itemStack == null) { + continue; + } + + inventory.setItem(i, itemStack); } player.openInventory(inventory); } - - protected boolean canViewIcon(Player player, T icon) { - return true; - } @Override public String toString() { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java index 1cd7e93..ae3e41d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java @@ -19,6 +19,8 @@ import java.util.List; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.OpenMenuAction; @@ -89,6 +91,42 @@ public class AdvancedIcon extends ConfigurableIconImpl { public void setClickActions(List clickActions) { this.clickActions = Utils.nullableCopy(clickActions); } + + + @Override + public ItemStack createItemStack(Player viewer) { + if (canViewIcon(viewer)) { + return super.createItemStack(viewer); + } else { + return null; + } + } + + + public ItemStack refreshItemStack(Player viewer, ItemStack currentItemStack) { + if (!hasViewPermission() && !hasVariables()) { + // Icon is not dynamic, no need to refresh + return currentItemStack; + } + + if (!canViewIcon(viewer)) { + // Player can't view the icon + return null; + } + + if (currentItemStack == null) { + // Create item from scratch + return createItemStack(viewer); + } else { + // Performance: only update name and lore + ItemMeta meta = currentItemStack.getItemMeta(); + meta.setDisplayName(calculateName(viewer)); + meta.setLore(calculateLore(viewer)); + currentItemStack.setItemMeta(meta); + return currentItemStack; + } + } + @Override public boolean onClick(Inventory inventory, Player player) { From 283fe8aa24ae5c102124bb14e5f3abf4107a7c78 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 15 Jun 2020 22:38:22 +0200 Subject: [PATCH 078/213] Refactoring --- .../chestcommands/api/impl/ConfigurableIconImpl.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java index 5ec1faf..a927703 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java @@ -289,12 +289,11 @@ public class ConfigurableIconImpl implements ConfigurableIcon { public ItemStack createItemStack(Player viewer) { if (!this.hasVariables() && cachedItem != null) { - // Performance + // Performance: return a static item return cachedItem; } - // If the material is not set, display BEDROCK - ItemStack itemStack = (material != null) ? new ItemStack(material, amount, durability) : new ItemStack(Material.BEDROCK, amount); + ItemStack itemStack = new ItemStack(material, amount, durability); // First try to apply NBT data if (nbtData != null) { From d0cdf67e96a982b1201dd8736cee1ddd18346ae9 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 20 Jun 2020 15:18:42 +0200 Subject: [PATCH 079/213] Renaming --- .../chestcommands/parser/ActionParser.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ActionParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ActionParser.java index ac5dc6c..ab526a5 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ActionParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ActionParser.java @@ -25,19 +25,19 @@ import me.filoghost.chestcommands.config.AsciiPlaceholders; public class ActionParser { - private static Map commandTypesMap = new HashMap<>(); + private static Map actionsByPrefix = new HashMap<>(); static { - commandTypesMap.put(actionPattern("console:"), ConsoleCommandAction::new); - commandTypesMap.put(actionPattern("op:"), OpCommandAction::new); - commandTypesMap.put(actionPattern("(open|menu):"), OpenMenuAction::new); - commandTypesMap.put(actionPattern("server:?"), ChangeServerAction::new); // The colon is optional - commandTypesMap.put(actionPattern("tell:"), SendMessageAction::new); - commandTypesMap.put(actionPattern("broadcast:"), BroadcastAction::new); - commandTypesMap.put(actionPattern("give:"), GiveItemAction::new); - commandTypesMap.put(actionPattern("give-?money:"), GiveMoneyAction::new); - commandTypesMap.put(actionPattern("sound:"), PlaySoundAction::new); - commandTypesMap.put(actionPattern("dragon-?bar:"), DragonBarAction::new); + actionsByPrefix.put(actionPattern("console:"), ConsoleCommandAction::new); + actionsByPrefix.put(actionPattern("op:"), OpCommandAction::new); + actionsByPrefix.put(actionPattern("(open|menu):"), OpenMenuAction::new); + actionsByPrefix.put(actionPattern("server:?"), ChangeServerAction::new); // The colon is optional + actionsByPrefix.put(actionPattern("tell:"), SendMessageAction::new); + actionsByPrefix.put(actionPattern("broadcast:"), BroadcastAction::new); + actionsByPrefix.put(actionPattern("give:"), GiveItemAction::new); + actionsByPrefix.put(actionPattern("give-?money:"), GiveMoneyAction::new); + actionsByPrefix.put(actionPattern("sound:"), PlaySoundAction::new); + actionsByPrefix.put(actionPattern("dragon-?bar:"), DragonBarAction::new); } private static Pattern actionPattern(String regex) { @@ -45,7 +45,7 @@ public class ActionParser { } public static Action parseAction(String input) { - for (Entry entry : commandTypesMap.entrySet()) { + for (Entry entry : actionsByPrefix.entrySet()) { Matcher matcher = entry.getKey().matcher(input); if (matcher.find()) { // Remove the action prefix and trim the spaces @@ -58,7 +58,7 @@ public class ActionParser { } - private static interface IconCommandFactory { + private interface IconCommandFactory { Action create(String actionString); From 56742061bb20a9fcb001fad13b403a04a56aacff Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 21 Jun 2020 16:51:24 +0200 Subject: [PATCH 080/213] Automatically update config files with legacy values --- .../chestcommands/ChestCommands.java | 61 +++++- .../chestcommands/config/ConfigUtil.java | 91 -------- .../filoghost/chestcommands/config/Lang.java | 5 +- .../chestcommands/config/Settings.java | 4 +- .../config/yaml/PluginConfig.java | 5 + .../config/yaml/SpecialConfig.java | 17 +- .../chestcommands/legacy/ConfigConverter.java | 23 ++ .../legacy/LegacyMenuConverter.java | 202 ++++++++++++++++++ .../legacy/LegacySettingsConverter.java | 49 +++++ .../chestcommands/parser/IconParser.java | 48 ++--- .../chestcommands/parser/MenuParser.java | 14 +- 11 files changed, 371 insertions(+), 148 deletions(-) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/ConfigConverter.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacyMenuConverter.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacySettingsConverter.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 7d51d94..be77628 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -16,8 +16,18 @@ package me.filoghost.chestcommands; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; + +import me.filoghost.chestcommands.legacy.ConfigConverter; +import me.filoghost.chestcommands.legacy.LegacyMenuConverter; +import me.filoghost.chestcommands.legacy.LegacySettingsConverter; import org.bstats.bukkit.MetricsLite; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -72,8 +82,8 @@ public class ChestCommands extends JavaPlugin { instance = this; menuManager = new MenuManager(); - settings = new Settings(new PluginConfig(this, "config.yml")); - lang = new Lang(new PluginConfig(this, "lang.yml")); + settings = new Settings(); + lang = new Lang(); if (!Utils.isClassLoaded("org.bukkit.inventory.ItemFlag")) { // ItemFlag was added in 1.8 if (Bukkit.getVersion().contains("(MC: 1.8)")) { @@ -144,8 +154,17 @@ public class ChestCommands extends JavaPlugin { ErrorCollector errors = new ErrorCollector(); menuManager.clear(); + String legacyCommandSeparator = null; + try { - settings.load(); + PluginConfig settingsYaml = new PluginConfig(this, "config.yml"); + settingsYaml.load(); + + LegacySettingsConverter legacySettingsConverter = new LegacySettingsConverter(); + legacyCommandSeparator = legacySettingsConverter.getLegacyCommandSeparator(settingsYaml); + convertIfLegacy(settingsYaml, legacySettingsConverter); + + settings.load(settingsYaml); } catch (IOException e) { e.printStackTrace(); getLogger().warning("I/O error while using the configuration. Default values will be used."); @@ -158,7 +177,9 @@ public class ChestCommands extends JavaPlugin { } try { - lang.load(); + PluginConfig langYaml = new PluginConfig(this, "lang.yml"); + langYaml.load(); + lang.load(langYaml); } catch (IOException e) { e.printStackTrace(); getLogger().warning("I/O error while using the language file. Default values will be used."); @@ -180,6 +201,7 @@ public class ChestCommands extends JavaPlugin { getLogger().warning("Unhandled error while reading the placeholders! Please inform the developer."); } + // Load the menus File menusFolder = new File(getDataFolder(), "menu"); @@ -189,10 +211,16 @@ public class ChestCommands extends JavaPlugin { FileUtils.saveResourceSafe(this, "menu" + File.separator + "example.yml"); } + if (legacyCommandSeparator == null) { + legacyCommandSeparator = ";"; + } + LegacyMenuConverter legacyMenuConverter = new LegacyMenuConverter(legacyCommandSeparator); + List menusList = loadMenus(menusFolder); for (PluginConfig menuConfig : menusList) { try { menuConfig.load(); + convertIfLegacy(menuConfig, legacyMenuConverter); } catch (IOException e) { e.printStackTrace(); errors.addError("I/O error while loading the menu \"" + menuConfig.getFileName() + "\". Is the file in use?"); @@ -228,6 +256,31 @@ public class ChestCommands extends JavaPlugin { return errors; } + private void convertIfLegacy(PluginConfig config, ConfigConverter legacyConverter) { + boolean modified = legacyConverter.convert(config); + if (modified) { + Path configPath = config.getFile().toPath(); + try { + String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy.MM.dd_HH.mm")); + String backupName = config.getFileName() + "-" + date + ".backup"; + Files.copy(configPath, configPath.resolveSibling(backupName), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + getLogger().log(Level.SEVERE, "Couldn't create backup of " + config.getFileName(), e); + return; + } + + ChestCommands.getInstance().getLogger().info( + "Automatically updated configuration file " + config.getFileName() + " with newer configuration nodes. " + + "A backup of the old file has been saved (" + config.getFileName() + ".backup)."); + + try { + config.save(); + } catch (IOException e) { + getLogger().log(Level.SEVERE, "Couldn't save modified file: ", e); + } + } + } + /** * Loads all the configuration files recursively into a list. diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java deleted file mode 100644 index 436714e..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.config; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.regex.Pattern; - -import org.bukkit.configuration.ConfigurationSection; - -import me.filoghost.chestcommands.util.Strings; - -public class ConfigUtil { - - public static String getAnyString(ConfigurationSection config, String... paths) { - for (String path : paths) { - String value = config.getString(path); - if (value != null) { - return value; - } - } - return null; - } - - public static Integer getAnyInt(ConfigurationSection config, String... paths) { - for (String path : paths) { - if (config.isSet(path)) { - return config.getInt(path); - } - } - return null; - } - - public static List getStringListOrInlineList(ConfigurationSection config, String separator, String... paths) { - for (String path : paths) { - if (config.isSet(path)) { - if (config.isList(path)) { - return config.getStringList(path); - } else { - return getSeparatedValues(config.getString(path), separator); - } - } - } - return null; - } - - public static List getStringListOrSingle(ConfigurationSection config, String... paths) { - for (String path : paths) { - if (config.isSet(path)) { - if (config.isList(path)) { - return config.getStringList(path); - } else { - return Collections.singletonList(config.getString(path)); - } - } - } - return null; - } - - private static List getSeparatedValues(String input, String separator) { - if (separator == null || separator.length() == 0) { - separator = ";"; - } - - String[] splitValues = Strings.trimmedSplit(input, Pattern.quote(separator)); - List values = new ArrayList<>(); - - for (String value : splitValues) { - if (!value.isEmpty()) { - values.add(value); - } - } - - return values; - } - - -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java index 863ea51..9f7f7b6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java @@ -21,7 +21,7 @@ public class Lang extends SpecialConfig { public String no_open_permission = "&cYou don't have permission &e{permission} &cto use this menu."; public String default_no_icon_permission = "&cYou don't have permission for this icon."; - public String no_required_item = "&cYou must have &e{amount}x {material} &c(durability: {datavalue}) for this."; + public String no_required_item = "&cYou must have &e{amount}x {material} &c(durability: {durability}) for this."; public String no_money = "&cYou need {money}$ for this."; public String no_exp = "&cYou need {levels} XP levels for this."; public String menu_not_found = "&cMenu not found! Please inform the staff."; @@ -29,7 +29,4 @@ public class Lang extends SpecialConfig { public String open_menu_others = "&aOpening the menu \"{menu}\" to {player}."; public String any = "any"; // Used in no_required_item when durability is not restrictive - public Lang(PluginConfig config) { - super(config); - } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java index 0026e1d..14e2851 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java @@ -21,12 +21,10 @@ public class Settings extends SpecialConfig { public String default_color__name = "&f"; public String default_color__lore = "&7"; - public String multiple_commands_separator = ";"; public boolean update_notifications = true; public int anti_click_spam_delay = 200; - public Settings(PluginConfig config) { - super(config); + public Settings() { setHeader("ChestCommands configuration file.\nTutorial: http://dev.bukkit.org/bukkit-plugins/chest-commands\n"); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/PluginConfig.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/PluginConfig.java index a7a4f76..47e491c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/PluginConfig.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/PluginConfig.java @@ -67,7 +67,12 @@ public class PluginConfig extends YamlConfiguration { return plugin; } + public File getFile() { + return file; + } + public String getFileName() { return file.getName(); } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/SpecialConfig.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/SpecialConfig.java index 80498a1..bedafaf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/SpecialConfig.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/SpecialConfig.java @@ -14,13 +14,15 @@ */ package me.filoghost.chestcommands.config.yaml; -import org.bukkit.configuration.InvalidConfigurationException; - +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.legacy.ConfigConverter; import me.filoghost.chestcommands.util.FormatUtils; +import org.bukkit.configuration.InvalidConfigurationException; import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.nio.file.Files; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -31,19 +33,14 @@ import java.util.Map.Entry; */ public class SpecialConfig { - private transient PluginConfig config; private transient String header; private transient Map defaultValuesMap; - public SpecialConfig(PluginConfig config) { - this.config = config; - } - public void setHeader(String header) { this.header = header; } - public void load() throws IOException, InvalidConfigurationException, Exception { + public void load(PluginConfig config) throws IOException, IllegalAccessException { // Check if the configuration was initialized if (defaultValuesMap == null) { @@ -70,11 +67,9 @@ public class SpecialConfig { } } - // First of all, try to load the yaml file - config.load(); + boolean needsSave = false; // Save default values not set - boolean needsSave = false; for (Entry entry : defaultValuesMap.entrySet()) { if (!config.isSet(entry.getKey())) { needsSave = true; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/ConfigConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/ConfigConverter.java new file mode 100644 index 0000000..758fa7c --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/ConfigConverter.java @@ -0,0 +1,23 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.legacy; + +import me.filoghost.chestcommands.config.yaml.PluginConfig; + +public interface ConfigConverter { + + boolean convert(PluginConfig config); + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacyMenuConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacyMenuConverter.java new file mode 100644 index 0000000..ca17205 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacyMenuConverter.java @@ -0,0 +1,202 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.legacy; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import me.filoghost.chestcommands.config.yaml.PluginConfig; +import me.filoghost.chestcommands.util.Strings; +import org.bukkit.configuration.ConfigurationSection; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Pattern; + +public class LegacyMenuConverter implements ConfigConverter { + + private static final Map menuSettingsReplacements = ImmutableMap.builder() + .put("command", "commands") + .put("open-action", "open-actions") + .put("open-with-item.id", "open-with-item.material") + .build(); + + private static final Map menuSettingsInlineLists = ImmutableMap.builder() + .put("commands", ";") + .put("open-actions", "") + .build(); + + private static final Map iconAttributesReplacements = ImmutableMap.builder() + .put("ID", "MATERIAL") + .put("DATA-VALUE", "DURABILITY") + .put("NBT", "NBT-DATA") + .put("ENCHANTMENT", "ENCHANTMENTS") + .put("COMMAND", "ACTIONS") + .put("COMMANDS", "ACTIONS") + .put("REQUIRED-ITEM", "REQUIRED-ITEMS") + .build(); + + private static final Map iconAttributesInlineLists = ImmutableMap.builder() + .put("ACTIONS", "") + .put("ENCHANTMENTS", ";") + .build(); + + private static final Set iconAttributesSingleStringLists = ImmutableSet.of( + "REQUIRED-ITEMS" + ); + + + private final String legacyCommandSeparator; + + public LegacyMenuConverter(String legacyCommandSeparator) { + this.legacyCommandSeparator = legacyCommandSeparator; + } + + @Override + public boolean convert(PluginConfig menuConfig) { + boolean modified = false; + + for (String key : menuConfig.getKeys(true)) { + if (!menuConfig.isConfigurationSection(key)) { + continue; + } + + ConfigurationSection section = menuConfig.getConfigurationSection(key); + if (key.equals("menu-settings")) { + modified |= renameNodes(section, menuSettingsReplacements); + modified |= expandInlineLists(section, menuSettingsInlineLists); + } else { + modified |= renameNodes(section, iconAttributesReplacements); + modified |= expandInlineLists(section, iconAttributesInlineLists); + modified |= expandSingletonLists(section, iconAttributesSingleStringLists); + + modified |= convertInlineItemstack(section); + } + } + + return modified; + } + + private boolean convertInlineItemstack(ConfigurationSection section) { + boolean modified = false; + String material = section.getString("MATERIAL"); + if (material == null) { + return modified; + } + + if (material.contains(",")) { + String[] parts = Strings.trimmedSplit(material, ",", 2); + if (!section.isSet("AMOUNT")) { + try { + section.set("AMOUNT", Integer.parseInt(parts[1])); + } catch (NumberFormatException e) { + section.set("AMOUNT", parts[1]); + } + } + material = parts[0]; + modified = true; + } + + if (material.contains(":")) { + String[] parts = Strings.trimmedSplit(material, ":", 2); + if (!section.isSet("DURABILITY")) { + try { + section.set("DURABILITY", Integer.parseInt(parts[1])); + } catch (NumberFormatException e) { + section.set("DURABILITY", parts[1]); + } + } + material = parts[0]; + modified = true; + } + + if (modified) { + section.set("MATERIAL", material); + } + + return modified; + } + + private boolean renameNodes(ConfigurationSection config, Map replacements) { + boolean modified = false; + + for (Map.Entry entry : replacements.entrySet()) { + String oldNode = entry.getKey(); + String newNode = entry.getValue(); + if (config.isSet(oldNode) && !config.isSet(newNode)) { + config.set(newNode, config.get(oldNode)); + config.set(oldNode, null); + modified = true; + } + } + + return modified; + } + + private boolean expandInlineLists(ConfigurationSection config, Map nodesAndSeparators) { + boolean modified = false; + + for (Map.Entry entry : nodesAndSeparators.entrySet()) { + String inlineListNode = entry.getKey(); + String separator = entry.getValue(); + if (config.isSet(inlineListNode)) { + if (config.isString(inlineListNode)) { + config.set(inlineListNode, getSeparatedValues(config.getString(inlineListNode), separator)); + modified = true; + } + } + } + + return modified; + } + + private boolean expandSingletonLists(ConfigurationSection config, Set nodes) { + boolean modified = false; + + for (String singleStringListNode : nodes) { + if (config.isSet(singleStringListNode)) { + config.set(singleStringListNode, Collections.singletonList(config.get(singleStringListNode))); + modified = true; + } + } + + return modified; + } + + private List getSeparatedValues(String input, String separator) { + if (separator == null || separator.length() == 0) { + separator = this.legacyCommandSeparator; + } + + String[] splitValues = Strings.trimmedSplit(input, Pattern.quote(separator)); + List values = new ArrayList<>(); + + for (String value : splitValues) { + if (!value.isEmpty()) { + values.add(value); + } + } + + // Return a list with an empty value to avoid displaying the empty list value "[]" in the YML file + if (values.isEmpty()) { + values.add(""); + } + + return values; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacySettingsConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacySettingsConverter.java new file mode 100644 index 0000000..5af824e --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacySettingsConverter.java @@ -0,0 +1,49 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.legacy; + +import com.google.common.collect.ImmutableSet; +import me.filoghost.chestcommands.config.yaml.PluginConfig; + +import java.util.Set; + +public class LegacySettingsConverter implements ConfigConverter { + + private static final Set removedConfigNodes = ImmutableSet.of( + "use-only-commands-without-args", + "use-console-colors", + "multiple-commands-separator" + ); + + public String getLegacyCommandSeparator(PluginConfig settingsConfig) { + return settingsConfig.getString("multiple-commands-separator"); + + } + + @Override + public boolean convert(PluginConfig settingsConfig) { + boolean modified = false; + + for (String removedConfigNode : removedConfigNodes) { + if (settingsConfig.isSet(removedConfigNode)) { + settingsConfig.set(removedConfigNode, null); + modified = true; + } + } + + return modified; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index 6cbb1f6..5a41bc6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -19,14 +19,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import me.filoghost.chestcommands.util.MaterialsHelper; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.enchantments.Enchantment; -import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.config.AsciiPlaceholders; -import me.filoghost.chestcommands.config.ConfigUtil; import me.filoghost.chestcommands.menu.icon.AdvancedIcon; import me.filoghost.chestcommands.menu.icon.RequiredItem; import me.filoghost.chestcommands.parser.EnchantmentParser.EnchantmentDetails; @@ -40,21 +39,21 @@ public class IconParser { private static class Nodes { - public static final String[] MATERIAL = {"MATERIAL", "ID"}; + public static final String MATERIAL = "MATERIAL"; public static final String AMOUNT = "AMOUNT"; - public static final String[] DURABILITY = {"DURABILITY", "DATA-VALUE"}; - public static final String[] NBT_DATA = {"NBT-DATA", "NBT"}; + public static final String DURABILITY = "DURABILITY"; + public static final String NBT_DATA = "NBT-DATA"; public static final String NAME = "NAME"; public static final String LORE = "LORE"; - public static final String[] ENCHANTMENTS = {"ENCHANTMENTS", "ENCHANTMENT"}; + public static final String ENCHANTMENTS = "ENCHANTMENTS"; public static final String COLOR = "COLOR"; public static final String SKULL_OWNER = "SKULL-OWNER"; public static final String BANNER_COLOR = "BANNER-COLOR"; public static final String BANNER_PATTERNS = "BANNER-PATTERNS"; - public static final String[] ACTIONS = {"ACTIONS", "COMMAND"}; + public static final String ACTIONS = "ACTIONS"; public static final String PRICE = "PRICE"; public static final String EXP_LEVELS = "LEVELS"; - public static final String[] REQUIRED_ITEMS = {"REQUIRED-ITEMS", "REQUIRED-ITEM"}; + public static final String REQUIRED_ITEMS = "REQUIRED-ITEMS"; public static final String PERMISSION = "PERMISSION"; public static final String PERMISSION_MESSAGE = "PERMISSION-MESSAGE"; public static final String VIEW_PERMISSION = "VIEW-PERMISSION"; @@ -95,28 +94,23 @@ public class IconParser { AdvancedIcon icon = new AdvancedIcon(Material.BEDROCK); - String material = ConfigUtil.getAnyString(section, Nodes.MATERIAL); - if (material != null) { - try { - ItemStackParser itemReader = new ItemStackParser(material, true); - icon.setMaterial(itemReader.getMaterial()); - icon.setDurability(itemReader.getDurability()); - icon.setAmount(itemReader.getAmount()); - } catch (ParseException e) { - errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid MATERIAL: " + e.getMessage()); + String serializedMaterial = section.getString(Nodes.MATERIAL); + if (serializedMaterial != null) { + Material material = MaterialsHelper.matchMaterial(serializedMaterial); + if (material != null) { + icon.setMaterial(material); + } else { + errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid MATERIAL: " + serializedMaterial); } } if (section.isSet(Nodes.AMOUNT)) { icon.setAmount(section.getInt(Nodes.AMOUNT)); } - - Integer durability = ConfigUtil.getAnyInt(section, Nodes.DURABILITY); - if (durability != null) { - icon.setDurability(durability.shortValue()); - } - String nbtData = ConfigUtil.getAnyString(section, Nodes.NBT_DATA); + icon.setDurability((short) section.getInt(Nodes.DURABILITY)); + + String nbtData = section.getString(Nodes.NBT_DATA); if (nbtData != null) { try { // Check that NBT has valid syntax before applying it to the icon @@ -130,7 +124,7 @@ public class IconParser { icon.setName(AsciiPlaceholders.placeholdersToSymbols(FormatUtils.colorizeName(section.getString(Nodes.NAME)))); icon.setLore(AsciiPlaceholders.placeholdersToSymbols(FormatUtils.colorizeLore(section.getStringList(Nodes.LORE)))); - List serializedEnchantments = ConfigUtil.getStringListOrInlineList(section, ";", Nodes.ENCHANTMENTS); + List serializedEnchantments = section.getStringList(Nodes.ENCHANTMENTS); if (serializedEnchantments != null && !serializedEnchantments.isEmpty()) { Map enchantments = new HashMap<>(); @@ -159,7 +153,7 @@ public class IconParser { icon.setSkullOwner(section.getString(Nodes.SKULL_OWNER)); - String bannerColor = ConfigUtil.getAnyString(section, Nodes.BANNER_COLOR); + String bannerColor = section.getString(Nodes.BANNER_COLOR); if (bannerColor != null) { try { icon.setBannerColor(ItemMetaParser.parseDyeColor(bannerColor)); @@ -183,7 +177,7 @@ public class IconParser { boolean closeOnClick = !section.getBoolean(Nodes.KEEP_OPEN); icon.setCloseOnClick(closeOnClick); - List serializedActions = ConfigUtil.getStringListOrInlineList(section, ChestCommands.getSettings().multiple_commands_separator, Nodes.ACTIONS); + List serializedActions = section.getStringList(Nodes.ACTIONS); if (serializedActions != null && !serializedActions.isEmpty()) { List actions = new ArrayList<>(); @@ -213,7 +207,7 @@ public class IconParser { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has negative LEVELS: " + levels); } - List serializedRequiredItems = ConfigUtil.getStringListOrSingle(section, Nodes.REQUIRED_ITEMS); + List serializedRequiredItems = section.getStringList(Nodes.REQUIRED_ITEMS); if (serializedRequiredItems != null && !serializedRequiredItems.isEmpty()) { List requiredItems = new ArrayList<>(); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java index d920f34..a1e48cf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java @@ -20,9 +20,7 @@ import java.util.List; import org.bukkit.ChatColor; import org.bukkit.configuration.ConfigurationSection; -import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.action.Action; -import me.filoghost.chestcommands.config.ConfigUtil; import me.filoghost.chestcommands.config.yaml.PluginConfig; import me.filoghost.chestcommands.menu.AdvancedIconMenu; import me.filoghost.chestcommands.menu.icon.AdvancedIcon; @@ -39,11 +37,11 @@ public class MenuParser { public static final String MENU_NAME = "menu-settings.name"; public static final String MENU_ROWS = "menu-settings.rows"; - public static final String[] MENU_COMMANDS = {"menu-settings.command", "menu-settings.commands"}; + public static final String MENU_COMMANDS = "menu-settings.commands"; - public static final String[] OPEN_ACTIONS = {"menu-settings.open-actions", "menu-settings.open-action"}; + public static final String OPEN_ACTIONS = "menu-settings.open-actions"; - public static final String[] OPEN_ITEM_MATERIAL = {"menu-settings.open-with-item.id", "menu-settings.open-with-item.material"}; + public static final String OPEN_ITEM_MATERIAL = "menu-settings.open-with-item.material"; public static final String OPEN_ITEM_LEFT_CLICK = "menu-settings.open-with-item.left-click"; public static final String OPEN_ITEM_RIGHT_CLICK = "menu-settings.open-with-item.right-click"; @@ -121,12 +119,12 @@ public class MenuParser { MenuSettings menuSettings = new MenuSettings(title, rows); - List triggeringCommands = ConfigUtil.getStringListOrInlineList(config, ";", Nodes.MENU_COMMANDS); + List triggeringCommands = config.getStringList(Nodes.MENU_COMMANDS); if (triggeringCommands != null) { menuSettings.setCommands(triggeringCommands); } - List serializedOpenActions = ConfigUtil.getStringListOrInlineList(config, ChestCommands.getSettings().multiple_commands_separator, Nodes.OPEN_ACTIONS); + List serializedOpenActions = config.getStringList(Nodes.OPEN_ACTIONS); if (serializedOpenActions != null && !serializedOpenActions.isEmpty()) { List openActions = new ArrayList<>(); @@ -142,7 +140,7 @@ public class MenuParser { } } - String openItemMaterial = ConfigUtil.getAnyString(config, Nodes.OPEN_ITEM_MATERIAL); + String openItemMaterial = config.getString(Nodes.OPEN_ITEM_MATERIAL); if (openItemMaterial != null) { boolean leftClick = config.getBoolean(Nodes.OPEN_ITEM_LEFT_CLICK); boolean rightClick = config.getBoolean(Nodes.OPEN_ITEM_RIGHT_CLICK); From f1d2ad353ef100d79f8f85e117d7f438df2cace3 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 21 Jun 2020 16:53:36 +0200 Subject: [PATCH 081/213] Update settings header --- .../main/java/me/filoghost/chestcommands/config/Settings.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java index 14e2851..dc6d1b1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java @@ -25,7 +25,9 @@ public class Settings extends SpecialConfig { public int anti_click_spam_delay = 200; public Settings() { - setHeader("ChestCommands configuration file.\nTutorial: http://dev.bukkit.org/bukkit-plugins/chest-commands\n"); + setHeader( + "ChestCommands main configuration file.\n" + + "Documentation: https://filoghost.me/docs/chest-commands\n"); } } From 20d9b94ea5cb2d36a47d2aa634bfb49039ec3c98 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 21 Jun 2020 16:57:13 +0200 Subject: [PATCH 082/213] Rename variables --- .../chestcommands/menu/icon/AdvancedIcon.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java index ae3e41d..89a9e32 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/icon/AdvancedIcon.java @@ -32,9 +32,9 @@ import me.filoghost.chestcommands.util.Utils; public class AdvancedIcon extends ConfigurableIconImpl { - private PermissionChecker viewPermissionChecker; + private PermissionChecker viewPermission; - private PermissionChecker requiredPermission; + private PermissionChecker clickPermission; private RequiredMoney requiredMoney; private RequiredExpLevel requiredExpLevel; private RequiredItems requiredItems; @@ -45,23 +45,23 @@ public class AdvancedIcon extends ConfigurableIconImpl { } public boolean canViewIcon(Player player) { - return viewPermissionChecker == null || viewPermissionChecker.hasPermission(player); + return viewPermission == null || viewPermission.hasPermission(player); } public boolean hasViewPermission() { - return viewPermissionChecker != null && !viewPermissionChecker.isEmpty(); + return viewPermission != null && !viewPermission.isEmpty(); } public void setClickPermission(String permission) { - this.requiredPermission = new PermissionChecker(permission); + this.clickPermission = new PermissionChecker(permission); } public void setNoClickPermissionMessage(String clickNoPermissionMessage) { - requiredPermission.setNoPermissionMessage(clickNoPermissionMessage); + clickPermission.setNoPermissionMessage(clickNoPermissionMessage); } public void setViewPermission(String viewPermission) { - this.viewPermissionChecker = new PermissionChecker(viewPermission); + this.viewPermission = new PermissionChecker(viewPermission); } public void setRequiredMoney(double requiredMoney) { @@ -131,13 +131,13 @@ public class AdvancedIcon extends ConfigurableIconImpl { @Override public boolean onClick(Inventory inventory, Player player) { // Check all the requirements - boolean hasAllRequirements = Requirement.checkAll(player, requiredPermission, requiredMoney, requiredExpLevel, requiredItems); + boolean hasAllRequirements = Requirement.checkAll(player, clickPermission, requiredMoney, requiredExpLevel, requiredItems); if (!hasAllRequirements) { return closeOnClick; } // If all requirements are satisfied, take their cost - boolean takenAllCosts = Requirement.takeCostAll(player, requiredPermission, requiredMoney, requiredExpLevel, requiredItems); + boolean takenAllCosts = Requirement.takeCostAll(player, clickPermission, requiredMoney, requiredExpLevel, requiredItems); if (!takenAllCosts) { return closeOnClick; } From 9b07383a8e144d11d155c4c9e04b62215de6a5b3 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 22 Jun 2020 19:54:27 +0200 Subject: [PATCH 083/213] Improve automatic config updates --- .../chestcommands/ChestCommands.java | 100 ++++++--------- .../chestcommands/legacy/ConfigConverter.java | 21 +++- .../legacy/ConversionException.java | 23 ++++ .../chestcommands/legacy/LegacyConverter.java | 118 ++++++++++++++++++ .../legacy/LegacyMenuConverter.java | 75 ++++------- .../legacy/LegacySettingsConverter.java | 21 ++-- .../legacy/UpgradesDoneRegistry.java | 86 +++++++++++++ 7 files changed, 320 insertions(+), 124 deletions(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/ConversionException.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacyConverter.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index be77628..836b912 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -14,27 +14,6 @@ */ package me.filoghost.chestcommands; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - -import me.filoghost.chestcommands.legacy.ConfigConverter; -import me.filoghost.chestcommands.legacy.LegacyMenuConverter; -import me.filoghost.chestcommands.legacy.LegacySettingsConverter; -import org.bstats.bukkit.MetricsLite; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - import me.filoghost.chestcommands.command.CommandHandler; import me.filoghost.chestcommands.command.framework.CommandFramework; import me.filoghost.chestcommands.config.AsciiPlaceholders; @@ -45,6 +24,8 @@ import me.filoghost.chestcommands.hook.BarAPIHook; import me.filoghost.chestcommands.hook.BungeeCordHook; import me.filoghost.chestcommands.hook.PlaceholderAPIHook; import me.filoghost.chestcommands.hook.VaultEconomyHook; +import me.filoghost.chestcommands.legacy.ConversionException; +import me.filoghost.chestcommands.legacy.LegacyConverter; import me.filoghost.chestcommands.listener.CommandListener; import me.filoghost.chestcommands.listener.InventoryListener; import me.filoghost.chestcommands.listener.JoinListener; @@ -54,10 +35,22 @@ import me.filoghost.chestcommands.menu.MenuManager; import me.filoghost.chestcommands.menu.settings.MenuSettings; import me.filoghost.chestcommands.parser.MenuParser; import me.filoghost.chestcommands.task.RefreshMenusTask; -import me.filoghost.chestcommands.util.FileUtils; import me.filoghost.chestcommands.util.ErrorCollector; +import me.filoghost.chestcommands.util.FileUtils; import me.filoghost.chestcommands.util.Utils; import me.filoghost.updatechecker.UpdateChecker; +import org.bstats.bukkit.MetricsLite; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; public class ChestCommands extends JavaPlugin { @@ -153,17 +146,18 @@ public class ChestCommands extends JavaPlugin { public ErrorCollector load() { ErrorCollector errors = new ErrorCollector(); menuManager.clear(); - - String legacyCommandSeparator = null; + boolean isFreshInstall = !getDataFolder().isDirectory(); + getDataFolder().mkdirs(); try { - PluginConfig settingsYaml = new PluginConfig(this, "config.yml"); + new LegacyConverter(this).run(isFreshInstall); + } catch (ConversionException e) { + getLogger().log(Level.SEVERE, "Couldn't run automatic configuration upgrades. The plugin may not work correctly.", e); + } + + try { + PluginConfig settingsYaml = getSettingsConfig(); settingsYaml.load(); - - LegacySettingsConverter legacySettingsConverter = new LegacySettingsConverter(); - legacyCommandSeparator = legacySettingsConverter.getLegacyCommandSeparator(settingsYaml); - convertIfLegacy(settingsYaml, legacySettingsConverter); - settings.load(settingsYaml); } catch (IOException e) { e.printStackTrace(); @@ -177,7 +171,7 @@ public class ChestCommands extends JavaPlugin { } try { - PluginConfig langYaml = new PluginConfig(this, "lang.yml"); + PluginConfig langYaml = getLangConfig(); langYaml.load(); lang.load(langYaml); } catch (IOException e) { @@ -203,7 +197,7 @@ public class ChestCommands extends JavaPlugin { // Load the menus - File menusFolder = new File(getDataFolder(), "menu"); + File menusFolder = getMenusFolder(); if (!menusFolder.isDirectory()) { // Create the directory with the default menu @@ -211,16 +205,10 @@ public class ChestCommands extends JavaPlugin { FileUtils.saveResourceSafe(this, "menu" + File.separator + "example.yml"); } - if (legacyCommandSeparator == null) { - legacyCommandSeparator = ";"; - } - LegacyMenuConverter legacyMenuConverter = new LegacyMenuConverter(legacyCommandSeparator); - List menusList = loadMenus(menusFolder); for (PluginConfig menuConfig : menusList) { try { menuConfig.load(); - convertIfLegacy(menuConfig, legacyMenuConverter); } catch (IOException e) { e.printStackTrace(); errors.addError("I/O error while loading the menu \"" + menuConfig.getFileName() + "\". Is the file in use?"); @@ -256,36 +244,22 @@ public class ChestCommands extends JavaPlugin { return errors; } - private void convertIfLegacy(PluginConfig config, ConfigConverter legacyConverter) { - boolean modified = legacyConverter.convert(config); - if (modified) { - Path configPath = config.getFile().toPath(); - try { - String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy.MM.dd_HH.mm")); - String backupName = config.getFileName() + "-" + date + ".backup"; - Files.copy(configPath, configPath.resolveSibling(backupName), StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - getLogger().log(Level.SEVERE, "Couldn't create backup of " + config.getFileName(), e); - return; - } - - ChestCommands.getInstance().getLogger().info( - "Automatically updated configuration file " + config.getFileName() + " with newer configuration nodes. " + - "A backup of the old file has been saved (" + config.getFileName() + ".backup)."); - - try { - config.save(); - } catch (IOException e) { - getLogger().log(Level.SEVERE, "Couldn't save modified file: ", e); - } - } + public PluginConfig getLangConfig() { + return new PluginConfig(this, "lang.yml"); } + public PluginConfig getSettingsConfig() { + return new PluginConfig(this, "config.yml"); + } + + public File getMenusFolder() { + return new File(getDataFolder(), "menu"); + } /** * Loads all the configuration files recursively into a list. */ - private List loadMenus(File file) { + public List loadMenus(File file) { List list = new ArrayList<>(); if (file.isDirectory()) { for (File subFile : file.listFiles()) { @@ -312,7 +286,7 @@ public class ChestCommands extends JavaPlugin { public static ChestCommands getInstance() { return instance; } - + public MenuManager getMenuManager() { return menuManager; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/ConfigConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/ConfigConverter.java index 758fa7c..645c5ee 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/ConfigConverter.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/ConfigConverter.java @@ -14,10 +14,25 @@ */ package me.filoghost.chestcommands.legacy; -import me.filoghost.chestcommands.config.yaml.PluginConfig; +import me.filoghost.chestcommands.util.Preconditions; -public interface ConfigConverter { +public abstract class ConfigConverter { - boolean convert(PluginConfig config); + private boolean hasRun; + private boolean modified; + + + protected void setModified() { + this.modified = true; + } + + public boolean convert() { + Preconditions.checkState(!hasRun, "Conversion already run"); + hasRun = true; + convert0(); + return modified; + } + + protected abstract void convert0(); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/ConversionException.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/ConversionException.java new file mode 100644 index 0000000..0502773 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/ConversionException.java @@ -0,0 +1,23 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.legacy; + +public class ConversionException extends Exception { + + public ConversionException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacyConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacyConverter.java new file mode 100644 index 0000000..5d869b1 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacyConverter.java @@ -0,0 +1,118 @@ +package me.filoghost.chestcommands.legacy; + +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.config.yaml.PluginConfig; +import me.filoghost.chestcommands.legacy.UpgradesDoneRegistry.Upgrade; +import org.bukkit.configuration.InvalidConfigurationException; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.logging.Level; + +public class LegacyConverter { + + private final ChestCommands plugin; + + public LegacyConverter(ChestCommands plugin) { + this.plugin = plugin; + } + + public void run(boolean isFreshInstall) throws ConversionException { + Path upgradesDoneFile = plugin.getDataFolder().toPath().resolve(".upgrades-done"); + UpgradesDoneRegistry upgradesDone; + + try { + upgradesDone = new UpgradesDoneRegistry(upgradesDoneFile); + } catch (IOException e) { + throw new ConversionException("Couldn't read upgrades metadata file \"" + upgradesDoneFile.getFileName() + "\"", e); + } + + if (isFreshInstall) { + // Mark all upgrades as already done, assuming default configuration files are up to date + upgradesDone.setAllDone(); + + } else { + PluginConfig settingsConfig = plugin.getSettingsConfig(); + loadConfig(settingsConfig); + LegacySettingsConverter legacySettingsConverter = new LegacySettingsConverter(settingsConfig); + + String legacyCommandSeparator = legacySettingsConverter.getLegacyCommandSeparator().orElse(";"); + + upgradesDone.runIfNecessary( + Upgrade.V4_MENUS, + () -> convertMenus(legacyCommandSeparator)); + + upgradesDone.runIfNecessary( + Upgrade.V4_CONFIG, + () -> convertIfLegacy(settingsConfig, legacySettingsConverter)); + } + + try { + upgradesDone.save(); + } catch (IOException e) { + throw new ConversionException("Couldn't save upgrades metadata file \"" + upgradesDoneFile.getFileName() + "\"", e); + } + } + + private void loadConfig(PluginConfig config) throws ConversionException { + try { + config.load(); + } catch (IOException e) { + throw new ConversionException("Couldn't read configuration file \"" + config.getFileName() + "\"", e); + } catch (InvalidConfigurationException e) { + throw new ConversionException("Couldn't parse YAML syntax for file \"" + config.getFileName() + "\"", e); + } + } + + private void convertMenus(String legacyCommandSeparator) throws ConversionException { + File menusFolder = plugin.getMenusFolder(); + + List menuConfigs = plugin.loadMenus(menusFolder); + for (PluginConfig menuConfig : menuConfigs) { + loadConfig(menuConfig); + convertMenu(menuConfig, legacyCommandSeparator); + } + } + + private void convertMenu(PluginConfig menuConfig, String legacyCommandSeparator) { + LegacyMenuConverter legacyMenuConverter = new LegacyMenuConverter(menuConfig, legacyCommandSeparator); + convertIfLegacy(menuConfig, legacyMenuConverter); + } + + private void convertIfLegacy(PluginConfig config, ConfigConverter legacyConverter) { + boolean modified = legacyConverter.convert(); + if (modified) { + try { + createBackupFile(config.getFile()); + } catch (IOException e) { + plugin.getLogger().log(Level.SEVERE, "Couldn't create backup of " + config.getFileName(), e); + return; + } + + plugin.getLogger().info( + "Automatically updated configuration file " + config.getFileName() + " with newer configuration nodes. " + + "A backup of the old file has been saved."); + + try { + config.save(); + } catch (IOException e) { + plugin.getLogger().log(Level.SEVERE, "Couldn't save modified file: ", e); + } + } + } + + private void createBackupFile(File file) throws IOException { + String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy.MM.dd_HH.mm")); + String backupName = file.getName() + "-" + date + ".backup"; + Files.copy(file.toPath(), file.toPath().resolveSibling(backupName), StandardCopyOption.REPLACE_EXISTING); + } + + + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacyMenuConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacyMenuConverter.java index ca17205..f9d9ec3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacyMenuConverter.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacyMenuConverter.java @@ -27,7 +27,7 @@ import java.util.Map; import java.util.Set; import java.util.regex.Pattern; -public class LegacyMenuConverter implements ConfigConverter { +public class LegacyMenuConverter extends ConfigConverter { private static final Map menuSettingsReplacements = ImmutableMap.builder() .put("command", "commands") @@ -60,16 +60,16 @@ public class LegacyMenuConverter implements ConfigConverter { ); + private final PluginConfig menuConfig; private final String legacyCommandSeparator; - public LegacyMenuConverter(String legacyCommandSeparator) { + public LegacyMenuConverter(PluginConfig menuConfig, String legacyCommandSeparator) { + this.menuConfig = menuConfig; this.legacyCommandSeparator = legacyCommandSeparator; } @Override - public boolean convert(PluginConfig menuConfig) { - boolean modified = false; - + protected void convert0() { for (String key : menuConfig.getKeys(true)) { if (!menuConfig.isConfigurationSection(key)) { continue; @@ -77,25 +77,22 @@ public class LegacyMenuConverter implements ConfigConverter { ConfigurationSection section = menuConfig.getConfigurationSection(key); if (key.equals("menu-settings")) { - modified |= renameNodes(section, menuSettingsReplacements); - modified |= expandInlineLists(section, menuSettingsInlineLists); + renameNodes(section, menuSettingsReplacements); + expandInlineLists(section, menuSettingsInlineLists); } else { - modified |= renameNodes(section, iconAttributesReplacements); - modified |= expandInlineLists(section, iconAttributesInlineLists); - modified |= expandSingletonLists(section, iconAttributesSingleStringLists); + renameNodes(section, iconAttributesReplacements); + expandInlineLists(section, iconAttributesInlineLists); + expandSingletonLists(section, iconAttributesSingleStringLists); - modified |= convertInlineItemstack(section); + convertInlineItemstack(section); } } - - return modified; } - private boolean convertInlineItemstack(ConfigurationSection section) { - boolean modified = false; + private void convertInlineItemstack(ConfigurationSection section) { String material = section.getString("MATERIAL"); if (material == null) { - return modified; + return; } if (material.contains(",")) { @@ -108,7 +105,8 @@ public class LegacyMenuConverter implements ConfigConverter { } } material = parts[0]; - modified = true; + section.set("MATERIAL", material); + setModified(); } if (material.contains(":")) { @@ -121,60 +119,39 @@ public class LegacyMenuConverter implements ConfigConverter { } } material = parts[0]; - modified = true; - } - - if (modified) { section.set("MATERIAL", material); + setModified(); } - - return modified; } - private boolean renameNodes(ConfigurationSection config, Map replacements) { - boolean modified = false; - - for (Map.Entry entry : replacements.entrySet()) { - String oldNode = entry.getKey(); - String newNode = entry.getValue(); + private void renameNodes(ConfigurationSection config, Map replacements) { + replacements.forEach((oldNode, newNode) -> { if (config.isSet(oldNode) && !config.isSet(newNode)) { config.set(newNode, config.get(oldNode)); config.set(oldNode, null); - modified = true; + setModified(); } - } - - return modified; + }); } - private boolean expandInlineLists(ConfigurationSection config, Map nodesAndSeparators) { - boolean modified = false; - - for (Map.Entry entry : nodesAndSeparators.entrySet()) { - String inlineListNode = entry.getKey(); - String separator = entry.getValue(); + private void expandInlineLists(ConfigurationSection config, Map nodesAndSeparators) { + nodesAndSeparators.forEach((inlineListNode, separator) -> { if (config.isSet(inlineListNode)) { if (config.isString(inlineListNode)) { config.set(inlineListNode, getSeparatedValues(config.getString(inlineListNode), separator)); - modified = true; + setModified(); } } - } - - return modified; + }); } - private boolean expandSingletonLists(ConfigurationSection config, Set nodes) { - boolean modified = false; - + private void expandSingletonLists(ConfigurationSection config, Set nodes) { for (String singleStringListNode : nodes) { if (config.isSet(singleStringListNode)) { config.set(singleStringListNode, Collections.singletonList(config.get(singleStringListNode))); - modified = true; + setModified(); } } - - return modified; } private List getSeparatedValues(String input, String separator) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacySettingsConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacySettingsConverter.java index 5af824e..a56b5dd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacySettingsConverter.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/LegacySettingsConverter.java @@ -17,9 +17,10 @@ package me.filoghost.chestcommands.legacy; import com.google.common.collect.ImmutableSet; import me.filoghost.chestcommands.config.yaml.PluginConfig; +import java.util.Optional; import java.util.Set; -public class LegacySettingsConverter implements ConfigConverter { +public class LegacySettingsConverter extends ConfigConverter { private static final Set removedConfigNodes = ImmutableSet.of( "use-only-commands-without-args", @@ -27,23 +28,25 @@ public class LegacySettingsConverter implements ConfigConverter { "multiple-commands-separator" ); - public String getLegacyCommandSeparator(PluginConfig settingsConfig) { - return settingsConfig.getString("multiple-commands-separator"); + private final PluginConfig settingsConfig; + + public LegacySettingsConverter(PluginConfig settingsConfig) { + this.settingsConfig = settingsConfig; + } + + public Optional getLegacyCommandSeparator() { + return Optional.ofNullable(settingsConfig.getString("multiple-commands-separator")); } @Override - public boolean convert(PluginConfig settingsConfig) { - boolean modified = false; - + protected void convert0() { for (String removedConfigNode : removedConfigNodes) { if (settingsConfig.isSet(removedConfigNode)) { settingsConfig.set(removedConfigNode, null); - modified = true; + setModified(); } } - - return modified; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java new file mode 100644 index 0000000..3056186 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java @@ -0,0 +1,86 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.legacy; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashSet; +import java.util.Set; + +public class UpgradesDoneRegistry { + + private final Path saveFile; + private final Set upgradesDone; + private boolean needSave; + + public UpgradesDoneRegistry(Path saveFile) throws IOException { + this.saveFile = saveFile; + this.upgradesDone = new HashSet<>(); + + if (Files.isRegularFile(saveFile)) { + Files.lines(saveFile, StandardCharsets.UTF_8).forEach(upgradesDone::add); + } + } + + public void runIfNecessary(Upgrade upgrade, UpgradeTask upgradeTask) throws ConversionException { + if (!upgradesDone.contains(upgrade.propertyName)) { + upgradeTask.run(); + setDone(upgrade); + } + } + + public void setAllDone() { + for (Upgrade upgrade : Upgrade.values()) { + setDone(upgrade); + } + } + + private void setDone(Upgrade upgrade) { + if (upgradesDone.add(upgrade.propertyName)) { + needSave = true; + } + } + + + public void save() throws IOException { + if (needSave) { + Files.write(saveFile, upgradesDone, StandardCharsets.UTF_8); + needSave = false; + } + } + + + public interface UpgradeTask { + + void run() throws ConversionException; + + } + + + public enum Upgrade { + + V4_MENUS("v4.0-menus"), + V4_CONFIG("v4.0-config"); + + private final String propertyName; + + Upgrade(String propertyName) { + this.propertyName = propertyName; + } + } + +} From 4535e4a11fadcc68c73826008b7b127adabfdf90 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 22 Jun 2020 20:03:35 +0200 Subject: [PATCH 084/213] Cleanup --- .../chestcommands/ChestCommands.java | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 836b912..4d4b9f4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -128,9 +128,7 @@ public class ChestCommands extends JavaPlugin { ErrorCollector errorCollector = load(); if (errorCollector.hasWarningsOrErrors()) { - Bukkit.getScheduler().runTaskLater(this, () -> { - errorCollector.logToConsole(); - }, 10L); + Bukkit.getScheduler().runTaskLater(this, errorCollector::logToConsole, 10L); } Bukkit.getScheduler().runTaskTimer(this, new RefreshMenusTask(), 2L, 2L); @@ -234,11 +232,6 @@ public class ChestCommands extends JavaPlugin { menuManager.registerTriggerItem(menuSettings.getOpenTrigger(), iconMenu); } } - - // Register the BungeeCord plugin channel - if (!Bukkit.getMessenger().isOutgoingChannelRegistered(this, "BungeeCord")) { - Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); - } ChestCommands.lastLoadErrors = errors; return errors; @@ -313,21 +306,24 @@ public class ChestCommands extends JavaPlugin { private static void criticalShutdown(String... errorMessage) { String separator = "****************************************************************************"; - StringBuffer output = new StringBuffer("\n "); - output.append("\n" + separator); + + List output = new ArrayList<>(); + + output.add(" "); + output.add(separator); for (String line : errorMessage) { - output.append("\n " + line); + output.add(" " + line); } - output.append("\n "); - output.append("\n This plugin has been disabled."); - output.append("\n" + separator); - output.append("\n "); + output.add(" "); + output.add(" This plugin has been disabled."); + output.add(separator); + output.add(" "); - System.out.println(output); + System.out.println("\n" + output); try { Thread.sleep(5000); - } catch (InterruptedException ex) {} + } catch (InterruptedException ignored) {} instance.setEnabled(false); } From 0dab4c277db12d44405e2fe41746a25858568b27 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 22 Jun 2020 20:06:30 +0200 Subject: [PATCH 085/213] Use 4.0.0 as base version --- API/pom.xml | 2 +- Plugin/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/API/pom.xml b/API/pom.xml index 2863e7f..6e16b40 100644 --- a/API/pom.xml +++ b/API/pom.xml @@ -6,7 +6,7 @@ me.filoghost.chestcommands chestcommands-parent - 4.0-SNAPSHOT + 4.0.0-SNAPSHOT chestcommands-api diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 02c9c6c..45d60c6 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -6,7 +6,7 @@ me.filoghost.chestcommands chestcommands-parent - 4.0-SNAPSHOT + 4.0.0-SNAPSHOT chestcommands-plugin diff --git a/pom.xml b/pom.xml index 6f417fe..4659108 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.filoghost.chestcommands chestcommands-parent ChestCommands Parent - 4.0-SNAPSHOT + 4.0.0-SNAPSHOT pom https://dev.bukkit.org/bukkit-plugins/chest-commands From 1aaba0eefb2c1c3e7e034e293acf5ded86a4d886 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 22 Jun 2020 21:03:21 +0200 Subject: [PATCH 086/213] General cleanup --- .github/ISSUE_TEMPLATE/1-bug.md | 2 +- .github/ISSUE_TEMPLATE/2-feature.md | 2 +- .github/ISSUE_TEMPLATE/3-help.md | 2 +- .github/ISSUE_TEMPLATE/4-documentation.md | 2 +- .../chestcommands/action/PlaySoundAction.java | 2 ++ .../chestcommands/command/CommandHandler.java | 2 +- .../chestcommands/config/AsciiPlaceholders.java | 1 + .../java/me/filoghost/chestcommands/config/Lang.java | 1 - .../me/filoghost/chestcommands/config/Settings.java | 1 - .../chestcommands/config/yaml/SpecialConfig.java | 4 ---- .../chestcommands/menu/icon/PermissionChecker.java | 2 +- .../chestcommands/menu/settings/ClickType.java | 4 ++-- .../filoghost/chestcommands/parser/ItemMetaParser.java | 2 +- .../chestcommands/parser/ItemStackParser.java | 2 +- .../chestcommands/util/CaseInsensitiveMap.java | 2 +- .../java/me/filoghost/chestcommands/util/Strings.java | 10 +++++----- .../filoghost/chestcommands/util/nbt/NBTCompound.java | 4 ++-- .../me/filoghost/chestcommands/util/nbt/NBTList.java | 2 +- .../chestcommands/util/nbt/parser/MojangsonParser.java | 4 ++-- .../chestcommands/variable/RelativeStringList.java | 2 +- 20 files changed, 25 insertions(+), 28 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/1-bug.md b/.github/ISSUE_TEMPLATE/1-bug.md index adcf1f1..d2adf25 100644 --- a/.github/ISSUE_TEMPLATE/1-bug.md +++ b/.github/ISSUE_TEMPLATE/1-bug.md @@ -5,7 +5,7 @@ labels: Bug --- - * - * 0 1 2 3 4 5 6 7 8 - * ^ +--------------------------------------------+ - * | 0 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | - * |----+----+----+----+----+----+----+----+----| - * Row 1 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | - * |----+----+----+----+----+----+----+----+----| - * | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | - * v +--------------------------------------------+ - * - */ -public class Grid { - - private final int rows, columns; - private final T[] elements; - - - @SuppressWarnings("unchecked") - public Grid(int rows, int columns) { - this.rows = rows; - this.columns = columns; - elements = (T[]) new Object[rows * columns]; - } - - public void setElement(int x, int y, T element) { - elements[getOrdinalIndex(x, y)] = element; - } - - public T getElement(int x, int y) { - return getElementAtIndex(getOrdinalIndex(x, y)); - } - - public T getElementAtIndex(int ordinalIndex) { - Preconditions.checkIndex(ordinalIndex, getSize(), "ordinalIndex"); - return elements[ordinalIndex]; - } - - private int getOrdinalIndex(int x, int y) { - Preconditions.checkIndex(x, getColumns(), "x"); - Preconditions.checkIndex(y, getRows(), "y"); - - int ordinalIndex = y * getColumns() + x; - Preconditions.checkIndex(ordinalIndex, getSize(), "ordinalIndex"); - return ordinalIndex; - } - - public int getRows() { - return rows; - } - - public int getColumns() { - return columns; - } - - public int getSize() { - return elements.length; - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.util.collection; + +import me.filoghost.chestcommands.util.Preconditions; + +/* + * Example: + * There 3 rows and 9 columns. The number inside the cells is the index. + * + * <--- Column ---> + * + * 0 1 2 3 4 5 6 7 8 + * ^ +--------------------------------------------+ + * | 0 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | + * |----+----+----+----+----+----+----+----+----| + * Row 1 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | + * |----+----+----+----+----+----+----+----+----| + * | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | + * v +--------------------------------------------+ + * + */ +public abstract class Grid { + + private final int rows, columns, size; + + public Grid(int rows, int columns) { + this.rows = rows; + this.columns = columns; + this.size = rows * columns; + } + + public final void set(int row, int column, T element) { + setByIndex(toOrdinalIndex(row, column), element); + } + + public final T get(int row, int column) { + return getByIndex(toOrdinalIndex(row, column)); + } + + public final T getByIndex(int ordinalIndex) { + Preconditions.checkIndex(ordinalIndex, getSize(), "ordinalIndex"); + return getByIndex0(ordinalIndex); + } + + protected abstract T getByIndex0(int ordinalIndex); + + public final void setByIndex(int ordinalIndex, T element) { + Preconditions.checkIndex(ordinalIndex, getSize(), "ordinalIndex"); + setByIndex0(ordinalIndex, element); + } + + + protected abstract void setByIndex0(int ordinalIndex, T element); + + private int toOrdinalIndex(int row, int column) { + Preconditions.checkIndex(row, getRows(), "row"); + Preconditions.checkIndex(column, getColumns(), "column"); + + int ordinalIndex = row * getColumns() + column; + Preconditions.checkIndex(ordinalIndex, getSize(), "ordinalIndex"); + return ordinalIndex; + } + + public int getRows() { + return rows; + } + + public int getColumns() { + return columns; + } + + public int getSize() { + return size; + } + +} From 863ef85c50a8954b9ed9d19fac5d543af45ff760 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 4 Jul 2020 21:15:55 +0200 Subject: [PATCH 119/213] Fix default configurations not being created properly --- .../chestcommands/config/files/Lang.java | 18 +++++++++--------- .../chestcommands/config/files/Settings.java | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/files/Lang.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/files/Lang.java index 6443a61..53dc987 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/files/Lang.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/files/Lang.java @@ -18,14 +18,14 @@ import me.filoghost.chestcommands.config.SpecialConfig; public class Lang extends SpecialConfig { - public final String no_open_permission = "&cYou don't have permission &e{permission} &cto use this menu."; - public final String default_no_icon_permission = "&cYou don't have permission for this icon."; - public final String no_required_item = "&cYou must have &e{amount}x {material} &c(durability: {durability}) for this."; - public final String no_money = "&cYou need {money}$ for this."; - public final String no_exp = "&cYou need {levels} XP levels for this."; - public final String menu_not_found = "&cMenu not found! Please inform the staff."; - public final String open_menu = "&aOpening the menu \"{menu}\"."; - public final String open_menu_others = "&aOpening the menu \"{menu}\" to {player}."; - public final String any = "any"; // Used in no_required_item when durability is not restrictive + public String no_open_permission = "&cYou don't have permission &e{permission} &cto use this menu."; + public String default_no_icon_permission = "&cYou don't have permission for this icon."; + public String no_required_item = "&cYou must have &e{amount}x {material} &c(durability: {durability}) for this."; + public String no_money = "&cYou need {money}$ for this."; + public String no_exp = "&cYou need {levels} XP levels for this."; + public String menu_not_found = "&cMenu not found! Please inform the staff."; + public String open_menu = "&aOpening the menu \"{menu}\"."; + public String open_menu_others = "&aOpening the menu \"{menu}\" to {player}."; + public String any = "any"; // Used in no_required_item when durability is not restrictive } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/files/Settings.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/files/Settings.java index d38191b..a8bd20c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/files/Settings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/files/Settings.java @@ -18,10 +18,10 @@ import me.filoghost.chestcommands.config.SpecialConfig; public class Settings extends SpecialConfig { - public final String default_color__name = "&f"; - public final String default_color__lore = "&7"; - public final boolean update_notifications = true; - public final int anti_click_spam_delay = 200; + public String default_color__name = "&f"; + public String default_color__lore = "&7"; + public boolean update_notifications = true; + public int anti_click_spam_delay = 200; public Settings() { setHeader( From fc97595d8006176a851f3b3ab57128dbfe1569e8 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 5 Jul 2020 12:08:00 +0200 Subject: [PATCH 120/213] Move and rename methods and classes --- .../chestcommands/ChestCommands.java | 7 ++--- .../{api/impl => }/DefaultBackendAPI.java | 5 +++- .../chestcommands/config/ConfigManager.java | 10 +++---- .../impl => icon}/APIConfigurableIcon.java | 2 +- .../{api/impl => icon}/APIStaticIcon.java | 2 +- .../icon/requirement/RequiredItem.java | 4 +-- .../inventory/DefaultItemInventory.java | 2 +- .../inventory/InventoryGrid.java | 2 +- ...ryHolder.java => ItemInventoryHolder.java} | 14 +++++----- .../legacy/UpgradesExecutor.java | 4 +-- .../listener/InventoryListener.java | 8 +++--- .../{api/impl => menu}/APIIconMenu.java | 2 +- .../chestcommands/menu/BaseIconMenu.java | 6 ++-- .../chestcommands/menu/MenuManager.java | 28 +++++++++---------- .../parsing/ItemStackParser.java | 4 +-- .../chestcommands/task/RefreshMenusTask.java | 2 +- 16 files changed, 51 insertions(+), 51 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/{api/impl => }/DefaultBackendAPI.java (90%) rename Plugin/src/main/java/me/filoghost/chestcommands/{api/impl => icon}/APIConfigurableIcon.java (92%) rename Plugin/src/main/java/me/filoghost/chestcommands/{api/impl => icon}/APIStaticIcon.java (94%) rename Plugin/src/main/java/me/filoghost/chestcommands/inventory/{MenuInventoryHolder.java => ItemInventoryHolder.java} (78%) rename Plugin/src/main/java/me/filoghost/chestcommands/{api/impl => menu}/APIIconMenu.java (95%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index b3730d7..c3778bd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -14,7 +14,6 @@ */ package me.filoghost.chestcommands; -import me.filoghost.chestcommands.api.impl.DefaultBackendAPI; import me.filoghost.chestcommands.api.internal.BackendAPI; import me.filoghost.chestcommands.command.CommandHandler; import me.filoghost.chestcommands.command.framework.CommandFramework; @@ -172,8 +171,8 @@ public class ChestCommands extends JavaPlugin { placeholders = configManager.tryLoadCustomPlaceholders(errors); // Create the menu folder with the example menu - if (!Files.isDirectory(configManager.getMenusPath())) { - ConfigLoader exampleMenuLoader = new ConfigLoader(configManager.getMenusPath().resolve("example.yml")); + if (!Files.isDirectory(configManager.getMenusFolder())) { + ConfigLoader exampleMenuLoader = new ConfigLoader(configManager.getMenusFolder().resolve("example.yml")); configManager.tryCreateDefault(exampleMenuLoader); } @@ -188,7 +187,7 @@ public class ChestCommands extends JavaPlugin { public static void closeAllMenus() { for (Player player : Bukkit.getOnlinePlayers()) { - if (MenuManager.getOpenMenuInventory(player) != null) { + if (MenuManager.getOpenItemInventory(player) != null) { player.closeInventory(); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/DefaultBackendAPI.java b/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java similarity index 90% rename from Plugin/src/main/java/me/filoghost/chestcommands/api/impl/DefaultBackendAPI.java rename to Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java index 2e05841..cfb5c62 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/DefaultBackendAPI.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java @@ -12,13 +12,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.api.impl; +package me.filoghost.chestcommands; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.api.ConfigurableIcon; import me.filoghost.chestcommands.api.IconMenu; import me.filoghost.chestcommands.api.StaticIcon; import me.filoghost.chestcommands.api.internal.BackendAPI; +import me.filoghost.chestcommands.icon.APIConfigurableIcon; +import me.filoghost.chestcommands.icon.APIStaticIcon; +import me.filoghost.chestcommands.menu.APIIconMenu; import me.filoghost.chestcommands.menu.InternalIconMenu; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java index 6a73acb..5b70d7b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java @@ -95,15 +95,15 @@ public class ConfigManager { } } - public Path getMenusPath() { + public Path getMenusFolder() { return baseDataPath.resolve("menu"); } /** * Returns a list of YML menu files. */ - public List getMenusPathList() throws IOException { - try (Stream paths = Files.walk(getMenusPath(), FileVisitOption.FOLLOW_LINKS)) { + public List getMenuPaths() throws IOException { + try (Stream paths = Files.walk(getMenusFolder(), FileVisitOption.FOLLOW_LINKS)) { return paths.filter(Files::isRegularFile) .filter(this::isYmlPath) .collect(Collectors.toList()); @@ -148,9 +148,9 @@ public class ConfigManager { List menuPaths; try { - menuPaths = getMenusPathList(); + menuPaths = getMenuPaths(); } catch (IOException e) { - Log.severe("Couldn't fetch files inside the folder \"" + getMenusPath().getFileName() + "\"", e); + Log.severe("Couldn't fetch files inside the folder \"" + getMenusFolder().getFileName() + "\"", e); return Collections.emptyList(); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/APIConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIConfigurableIcon.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/api/impl/APIConfigurableIcon.java rename to Plugin/src/main/java/me/filoghost/chestcommands/icon/APIConfigurableIcon.java index 746f464..d9a38d1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/APIConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIConfigurableIcon.java @@ -1,4 +1,4 @@ -package me.filoghost.chestcommands.api.impl; +package me.filoghost.chestcommands.icon; import me.filoghost.chestcommands.api.ClickHandler; import me.filoghost.chestcommands.api.ConfigurableIcon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/APIStaticIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java similarity index 94% rename from Plugin/src/main/java/me/filoghost/chestcommands/api/impl/APIStaticIcon.java rename to Plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java index 690e6b3..a8996ca 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/APIStaticIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java @@ -1,4 +1,4 @@ -package me.filoghost.chestcommands.api.impl; +package me.filoghost.chestcommands.icon; import me.filoghost.chestcommands.api.ClickHandler; import me.filoghost.chestcommands.api.StaticIcon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItem.java index cc05a25..7db9dbb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItem.java @@ -101,11 +101,11 @@ public class RequiredItem { return item != null && item.getType() == material && isMatchingDurability(item.getDurability()); } - private boolean isMatchingDurability(short data) { + private boolean isMatchingDurability(short durability) { if (!isDurabilityRestrictive) { return true; } - return data == this.durability; + return this.durability == durability; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultItemInventory.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultItemInventory.java index 5019441..e90bfc9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultItemInventory.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultItemInventory.java @@ -20,7 +20,7 @@ public class DefaultItemInventory implements ItemInventory { public DefaultItemInventory(BaseIconMenu menu, Player viewer) { this.menu = menu; this.viewer = viewer; - this.bukkitInventory = new InventoryGrid(new MenuInventoryHolder(this), menu.getRowCount(), menu.getTitle()); + this.bukkitInventory = new InventoryGrid(new ItemInventoryHolder(this), menu.getRowCount(), menu.getTitle()); refresh(); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java index 6d47622..48d1b11 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java @@ -9,7 +9,7 @@ public class InventoryGrid extends Grid { private final Inventory inventory; - public InventoryGrid(MenuInventoryHolder inventoryHolder, int rows, String title) { + public InventoryGrid(ItemInventoryHolder inventoryHolder, int rows, String title) { super(rows, 9); this.inventory = Bukkit.createInventory(inventoryHolder, getSize(), title); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/ItemInventoryHolder.java similarity index 78% rename from Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java rename to Plugin/src/main/java/me/filoghost/chestcommands/inventory/ItemInventoryHolder.java index b9580d4..e6d8805 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/ItemInventoryHolder.java @@ -19,13 +19,13 @@ import org.bukkit.Bukkit; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -public class MenuInventoryHolder implements InventoryHolder { +public class ItemInventoryHolder implements InventoryHolder { - private final DefaultItemInventory menuInventory; + private final DefaultItemInventory itemInventory; - public MenuInventoryHolder(DefaultItemInventory menuInventory) { - Preconditions.notNull(menuInventory, "menuInventory"); - this.menuInventory = menuInventory; + public ItemInventoryHolder(DefaultItemInventory itemInventory) { + Preconditions.notNull(itemInventory, "itemInventory"); + this.itemInventory = itemInventory; } @Override @@ -39,7 +39,7 @@ public class MenuInventoryHolder implements InventoryHolder { return Bukkit.createInventory(null, 9); } - public DefaultItemInventory getMenuInventory() { - return menuInventory; + public DefaultItemInventory getItemInventory() { + return itemInventory; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java index f2e6ee8..f49d0fa 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java @@ -66,11 +66,11 @@ public class UpgradesExecutor { try { List menuUpgrades = CollectionUtils.transform( - configManager.getMenusPathList(), + configManager.getMenuPaths(), menuPath -> new MenuUpgrade(new ConfigLoader(menuPath), legacyCommandSeparator)); runIfNecessary(UpgradeID.V4_MENUS, menuUpgrades); } catch (IOException e) { - failedUpgrades.add(configManager.getMenusPath()); + failedUpgrades.add(configManager.getMenusFolder()); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index 08b0ff0..bb9bfa2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -52,7 +52,7 @@ public class InventoryListener implements Listener { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) public void onEarlyInventoryClick(InventoryClickEvent event) { - if (MenuManager.isMenuInventory(event.getInventory())) { + if (MenuManager.isItemInventory(event.getInventory())) { // Cancel the event as early as possible event.setCancelled(true); } @@ -61,8 +61,8 @@ public class InventoryListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) public void onLateInventoryClick(InventoryClickEvent event) { Inventory inventory = event.getInventory(); - DefaultItemInventory menuInventory = MenuManager.getOpenMenuInventory(inventory); - if (menuInventory == null) { + DefaultItemInventory itemInventory = MenuManager.getOpenItemInventory(inventory); + if (itemInventory == null) { return; } @@ -71,7 +71,7 @@ public class InventoryListener implements Listener { int slot = event.getRawSlot(); Player clicker = (Player) event.getWhoClicked(); - SlotClickHandler slotClickHandler = menuInventory.getSlotClickHandler(slot, clicker); + SlotClickHandler slotClickHandler = itemInventory.getSlotClickHandler(slot, clicker); if (slotClickHandler == null) { return; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/APIIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java similarity index 95% rename from Plugin/src/main/java/me/filoghost/chestcommands/api/impl/APIIconMenu.java rename to Plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java index 2a680f2..5033766 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/APIIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.api.impl; +package me.filoghost.chestcommands.menu; import me.filoghost.chestcommands.menu.BaseIconMenu; import org.bukkit.plugin.Plugin; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java index 13a59dd..7d0ce59 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java @@ -68,9 +68,9 @@ public abstract class BaseIconMenu implements IconMenu { public ItemInventory open(Player player) { Preconditions.notNull(player, "player"); - DefaultItemInventory menuInventory = new DefaultItemInventory(this, player); - menuInventory.open(player); - return menuInventory; + DefaultItemInventory itemInventory = new DefaultItemInventory(this, player); + itemInventory.open(player); + return itemInventory; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java index f949de7..ebf265b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java @@ -15,7 +15,7 @@ package me.filoghost.chestcommands.menu; import me.filoghost.chestcommands.inventory.DefaultItemInventory; -import me.filoghost.chestcommands.inventory.MenuInventoryHolder; +import me.filoghost.chestcommands.inventory.ItemInventoryHolder; import me.filoghost.chestcommands.parsing.menu.LoadedMenu; import me.filoghost.chestcommands.parsing.menu.OpenTrigger; import me.filoghost.chestcommands.util.collection.CaseInsensitiveMap; @@ -95,37 +95,37 @@ public class MenuManager { return Collections.unmodifiableCollection(menusByFile.keySet()); } - public static boolean isMenuInventory(Inventory inventory) { - return getMenuInventoryHolder(inventory) != null; + public static boolean isItemInventory(Inventory inventory) { + return getItemInventoryHolder(inventory) != null; } - public static DefaultItemInventory getOpenMenuInventory(Player player) { + public static DefaultItemInventory getOpenItemInventory(Player player) { InventoryView view = player.getOpenInventory(); if (view == null) { return null; } - DefaultItemInventory menuInventory = getOpenMenuInventory(view.getTopInventory()); - if (menuInventory == null) { - menuInventory = getOpenMenuInventory(view.getBottomInventory()); + DefaultItemInventory itemInventory = getOpenItemInventory(view.getTopInventory()); + if (itemInventory == null) { + itemInventory = getOpenItemInventory(view.getBottomInventory()); } - return menuInventory; + return itemInventory; } - public static DefaultItemInventory getOpenMenuInventory(Inventory inventory) { - MenuInventoryHolder inventoryHolder = getMenuInventoryHolder(inventory); + public static DefaultItemInventory getOpenItemInventory(Inventory inventory) { + ItemInventoryHolder inventoryHolder = getItemInventoryHolder(inventory); if (inventoryHolder != null) { - return inventoryHolder.getMenuInventory(); + return inventoryHolder.getItemInventory(); } else { return null; } } - private static MenuInventoryHolder getMenuInventoryHolder(Inventory inventory) { - if (inventory.getHolder() instanceof MenuInventoryHolder) { - return (MenuInventoryHolder) inventory.getHolder(); + private static ItemInventoryHolder getItemInventoryHolder(Inventory inventory) { + if (inventory.getHolder() instanceof ItemInventoryHolder) { + return (ItemInventoryHolder) inventory.getHolder(); } else { return null; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java index 667eb84..5b78f29 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java @@ -31,9 +31,7 @@ public class ItemStackParser { private boolean hasExplicitDurability = false; /** - * Reads item in the format "id:data, amount" - * id can be either the id of the material or its name. - * for example wool:5, 3 is a valid input. + * Reads item in the format "material:durability, amount". */ public ItemStackParser(String input, boolean parseAmount) throws ParseException { Preconditions.notNull(input, "input"); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java index ee7345d..bd7611c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java @@ -27,7 +27,7 @@ public class RefreshMenusTask implements Runnable { @Override public void run() { for (Player player : Bukkit.getOnlinePlayers()) { - DefaultItemInventory itemInventory = MenuManager.getOpenMenuInventory(player); + DefaultItemInventory itemInventory = MenuManager.getOpenItemInventory(player); if (itemInventory == null || !(itemInventory.getMenu() instanceof InternalIconMenu)) { continue; From 7241a39a914eb58210855d7a0cdb426fcddf8cd4 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 5 Jul 2020 12:28:54 +0200 Subject: [PATCH 121/213] Separate Utils module --- API/pom.xml | 6 + Plugin/pom.xml | 6 + .../icon/BaseConfigurableIcon.java | 1 - .../icon/attributes/LoreAttribute.java | 18 +- .../icon/attributes/NameAttribute.java | 17 +- .../filoghost/chestcommands/util/Colors.java | 42 --- Utils/pom.xml | 31 +++ .../filoghost/chestcommands/util/Colors.java | 14 + .../me/filoghost/chestcommands/util/Log.java | 0 .../chestcommands/util/MaterialsHelper.java | 250 +++++++++--------- .../chestcommands/util/Preconditions.java | 136 +++++----- .../filoghost/chestcommands/util/Strings.java | 182 ++++++------- .../filoghost/chestcommands/util/Utils.java | 0 .../util/collection/ArrayGrid.java | 0 .../util/collection/CaseInsensitiveMap.java | 0 .../util/collection/CollectionUtils.java | 0 .../util/collection/ErrorCollector.java | 0 .../chestcommands/util/collection/Grid.java | 0 .../util/collection/Registry.java | 0 .../chestcommands/util/nbt/NBTByte.java | 0 .../chestcommands/util/nbt/NBTByteArray.java | 0 .../chestcommands/util/nbt/NBTCompound.java | 0 .../chestcommands/util/nbt/NBTDouble.java | 0 .../chestcommands/util/nbt/NBTFloat.java | 0 .../chestcommands/util/nbt/NBTInt.java | 0 .../chestcommands/util/nbt/NBTIntArray.java | 0 .../chestcommands/util/nbt/NBTList.java | 0 .../chestcommands/util/nbt/NBTLong.java | 0 .../chestcommands/util/nbt/NBTLongArray.java | 0 .../chestcommands/util/nbt/NBTShort.java | 0 .../chestcommands/util/nbt/NBTString.java | 0 .../chestcommands/util/nbt/NBTTag.java | 0 .../chestcommands/util/nbt/NBTType.java | 0 .../nbt/parser/MojangsonParseException.java | 0 .../util/nbt/parser/MojangsonParser.java | 0 pom.xml | 3 +- 36 files changed, 374 insertions(+), 332 deletions(-) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/util/Colors.java create mode 100644 Utils/pom.xml create mode 100644 Utils/src/main/java/me/filoghost/chestcommands/util/Colors.java rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/Log.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java (97%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/Preconditions.java (96%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/Strings.java (96%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/Utils.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/collection/ArrayGrid.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/collection/CaseInsensitiveMap.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/collection/ErrorCollector.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/collection/Grid.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/collection/Registry.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java (100%) rename {Plugin => Utils}/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java (100%) diff --git a/API/pom.xml b/API/pom.xml index 6e16b40..d5f0e0f 100644 --- a/API/pom.xml +++ b/API/pom.xml @@ -26,6 +26,12 @@ ${bukkit.version} provided + + + ${project.groupId} + chestcommands-utils + ${project.version} + \ No newline at end of file diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 45d60c6..0ccb4ec 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -85,6 +85,12 @@ chestcommands-api ${project.version} + + + ${project.groupId} + chestcommands-utils + ${project.version} + diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java index 2ac5868..565d6b5 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java @@ -15,7 +15,6 @@ package me.filoghost.chestcommands.icon; import me.filoghost.chestcommands.api.Icon; -import me.filoghost.chestcommands.parsing.icon.IconSettingsNode; import me.filoghost.chestcommands.util.Log; import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.collection.CollectionUtils; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LoreAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LoreAttribute.java index e7b51e8..7bc2834 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LoreAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LoreAttribute.java @@ -19,6 +19,8 @@ import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; import me.filoghost.chestcommands.util.Colors; +import me.filoghost.chestcommands.util.collection.CollectionUtils; +import org.bukkit.ChatColor; import java.util.List; @@ -27,9 +29,21 @@ public class LoreAttribute implements ApplicableIconAttribute { private final List lore; public LoreAttribute(List lore, AttributeErrorCollector attributeErrorCollector) { - this.lore = ChestCommands.getCustomPlaceholders().replaceAll(Colors.colorLore(lore)); + this.lore = ChestCommands.getCustomPlaceholders().replaceAll(colorLore(lore)); } - + + private List colorLore(List input) { + return CollectionUtils.transform(input, line -> { + if (line.isEmpty()) { + return line; + } else if (line.charAt(0) != ChatColor.COLOR_CHAR) { + return ChestCommands.getSettings().default_color__lore + Colors.addColors(line); + } else { + return Colors.addColors(line); + } + }); + } + @Override public void apply(InternalConfigurableIcon icon) { icon.setLore(lore); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NameAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NameAttribute.java index aac6ab5..5b5f3ac 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NameAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NameAttribute.java @@ -19,15 +19,28 @@ import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; import me.filoghost.chestcommands.util.Colors; +import org.bukkit.ChatColor; public class NameAttribute implements ApplicableIconAttribute { private final String name; public NameAttribute(String name, AttributeErrorCollector attributeErrorCollector) { - this.name = ChestCommands.getCustomPlaceholders().replaceAll(Colors.colorName(name)); + this.name = ChestCommands.getCustomPlaceholders().replaceAll(colorName(name)); } - + + private String colorName(String input) { + if (input == null || input.isEmpty()) { + return input; + } + + if (input.charAt(0) != ChatColor.COLOR_CHAR) { + return ChestCommands.getSettings().default_color__name + Colors.addColors(input); + } else { + return Colors.addColors(input); + } + } + @Override public void apply(InternalConfigurableIcon icon) { icon.setName(name); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Colors.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Colors.java deleted file mode 100644 index 4ffb274..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Colors.java +++ /dev/null @@ -1,42 +0,0 @@ -package me.filoghost.chestcommands.util; - -import me.filoghost.chestcommands.util.collection.CollectionUtils; -import org.bukkit.ChatColor; - -import me.filoghost.chestcommands.ChestCommands; - -import java.util.List; - -public final class Colors { - - public static String addColors(String input) { - if (input == null || input.isEmpty()) { - return input; - } - return ChatColor.translateAlternateColorCodes('&', input); - } - - public static String colorName(String input) { - if (input == null || input.isEmpty()) { - return input; - } - - if (input.charAt(0) != ChatColor.COLOR_CHAR) { - return ChestCommands.getSettings().default_color__name + addColors(input); - } else { - return addColors(input); - } - } - - public static List colorLore(List input) { - return CollectionUtils.transform(input, line -> { - if (line.isEmpty()) { - return line; - } else if (line.charAt(0) != ChatColor.COLOR_CHAR) { - return ChestCommands.getSettings().default_color__lore + addColors(line); - } else { - return addColors(line); - } - }); - } -} diff --git a/Utils/pom.xml b/Utils/pom.xml new file mode 100644 index 0000000..ba37d4f --- /dev/null +++ b/Utils/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + + me.filoghost.chestcommands + chestcommands-parent + 4.0.0-SNAPSHOT + + + chestcommands-utils + ChestCommands Utils + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + + + + org.bukkit + bukkit + ${bukkit.version} + provided + + + + \ No newline at end of file diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Colors.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Colors.java new file mode 100644 index 0000000..227fb9a --- /dev/null +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/Colors.java @@ -0,0 +1,14 @@ +package me.filoghost.chestcommands.util; + +import org.bukkit.ChatColor; + +public final class Colors { + + public static String addColors(String input) { + if (input == null || input.isEmpty()) { + return input; + } + return ChatColor.translateAlternateColorCodes('&', input); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Log.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Log.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/Log.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/Log.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java b/Utils/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java similarity index 97% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java index 7f9461c..da2c039 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java @@ -1,125 +1,125 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.util; - -import me.filoghost.chestcommands.util.collection.Registry; -import org.bukkit.Material; -import java.util.Collection; -import java.util.HashSet; -import java.util.Optional; - -public final class MaterialsHelper { - - // Material names have been changed in 1.13, when dolphins were added - private static final boolean USE_NEW_MATERIAL_NAMES = Utils.isClassLoaded("org.bukkit.entity.Dolphin"); - - // Default material names are ugly - private static final Registry MATERIALS_REGISTRY = initMaterialsRegistry(); - - // Materials that are considered air (with 1.13+ compatibility) - private static final Collection AIR_MATERIALS = getExistingMaterials("AIR", "CAVE_AIR", "VOID_AIR"); - - private MaterialsHelper() {} - - @SuppressWarnings("deprecation") - private static Registry initMaterialsRegistry() { - Registry materialsRegistry = Registry.fromEnumValues(Material.class); - - if (!USE_NEW_MATERIAL_NAMES) { - // Add numerical IDs in versions before 1.13 - for (Material material : Material.values()) { - materialsRegistry.put(String.valueOf(material.getId()), material); - } - } - - // Add some default useful aliases (when present) - materialsRegistry.putIfEnumExists("iron bar", "IRON_FENCE"); - materialsRegistry.putIfEnumExists("iron bars", "IRON_FENCE"); - materialsRegistry.putIfEnumExists("glass pane", "THIN_GLASS"); - materialsRegistry.putIfEnumExists("nether wart", "NETHER_STALK"); - materialsRegistry.putIfEnumExists("nether warts", "NETHER_STALK"); - materialsRegistry.putIfEnumExists("slab", "STEP"); - materialsRegistry.putIfEnumExists("double slab", "DOUBLE_STEP"); - materialsRegistry.putIfEnumExists("stone brick", "SMOOTH_BRICK"); - materialsRegistry.putIfEnumExists("stone bricks", "SMOOTH_BRICK"); - materialsRegistry.putIfEnumExists("stone stair", "SMOOTH_STAIRS"); - materialsRegistry.putIfEnumExists("stone stairs", "SMOOTH_STAIRS"); - materialsRegistry.putIfEnumExists("potato", "POTATO_ITEM"); - materialsRegistry.putIfEnumExists("carrot", "CARROT_ITEM"); - materialsRegistry.putIfEnumExists("brewing stand", "BREWING_STAND_ITEM"); - materialsRegistry.putIfEnumExists("cauldron", "CAULDRON_ITEM"); - materialsRegistry.putIfEnumExists("carrot on stick", "CARROT_STICK"); - materialsRegistry.putIfEnumExists("carrot on a stick", "CARROT_STICK"); - materialsRegistry.putIfEnumExists("cobblestone wall", "COBBLE_WALL"); - materialsRegistry.putIfEnumExists("acacia wood stairs", "ACACIA_STAIRS"); - materialsRegistry.putIfEnumExists("dark oak wood stairs", "DARK_OAK_STAIRS"); - materialsRegistry.putIfEnumExists("wood slab", "WOOD_STEP"); - materialsRegistry.putIfEnumExists("double wood slab", "WOOD_DOUBLE_STEP"); - materialsRegistry.putIfEnumExists("repeater", "DIODE"); - materialsRegistry.putIfEnumExists("piston", "PISTON_BASE"); - materialsRegistry.putIfEnumExists("sticky piston", "PISTON_STICKY_BASE"); - materialsRegistry.putIfEnumExists("flower pot", "FLOWER_POT_ITEM"); - materialsRegistry.putIfEnumExists("wood showel", "WOOD_SPADE"); - materialsRegistry.putIfEnumExists("stone showel", "STONE_SPADE"); - materialsRegistry.putIfEnumExists("gold showel", "GOLD_SPADE"); - materialsRegistry.putIfEnumExists("iron showel", "IRON_SPADE"); - materialsRegistry.putIfEnumExists("diamond showel", "DIAMOND_SPADE"); - materialsRegistry.putIfEnumExists("steak", "COOKED_BEEF"); - materialsRegistry.putIfEnumExists("cooked porkchop", "GRILLED_PORK"); - materialsRegistry.putIfEnumExists("raw porkchop", "PORK"); - materialsRegistry.putIfEnumExists("hardened clay", "HARD_CLAY"); - materialsRegistry.putIfEnumExists("huge brown mushroom", "HUGE_MUSHROOM_1"); - materialsRegistry.putIfEnumExists("huge red mushroom", "HUGE_MUSHROOM_2"); - materialsRegistry.putIfEnumExists("mycelium", "MYCEL"); - materialsRegistry.putIfEnumExists("poppy", "RED_ROSE"); - materialsRegistry.putIfEnumExists("comparator", "REDSTONE_COMPARATOR"); - materialsRegistry.putIfEnumExists("skull", "SKULL_ITEM"); - materialsRegistry.putIfEnumExists("head", "SKULL_ITEM"); - materialsRegistry.putIfEnumExists("redstone torch", "REDSTONE_TORCH_ON"); - materialsRegistry.putIfEnumExists("redstone lamp", "REDSTONE_LAMP_OFF"); - materialsRegistry.putIfEnumExists("glistering melon", "SPECKLED_MELON"); - materialsRegistry.putIfEnumExists("acacia leaves", "LEAVES_2"); - materialsRegistry.putIfEnumExists("acacia log", "LOG_2"); - materialsRegistry.putIfEnumExists("gunpowder", "SULPHUR"); - materialsRegistry.putIfEnumExists("lilypad", "WATER_LILY"); - materialsRegistry.putIfEnumExists("command block", "COMMAND"); - materialsRegistry.putIfEnumExists("dye", "INK_SACK"); - - return materialsRegistry; - } - - public static Optional matchMaterial(String materialName) { - return MATERIALS_REGISTRY.find(materialName); - } - - private static Collection getExistingMaterials(String... materialEnumNames) { - Collection existingMaterials = new HashSet<>(); - - for (String materialEnumName : materialEnumNames) { - try { - existingMaterials.add(Material.valueOf(materialEnumName)); - } catch (IllegalArgumentException e) { - // Ignore, not existing - } - } - - return existingMaterials; - } - - public static boolean isAir(Material material) { - return AIR_MATERIALS.contains(material); - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.util; + +import me.filoghost.chestcommands.util.collection.Registry; +import org.bukkit.Material; +import java.util.Collection; +import java.util.HashSet; +import java.util.Optional; + +public final class MaterialsHelper { + + // Material names have been changed in 1.13, when dolphins were added + private static final boolean USE_NEW_MATERIAL_NAMES = Utils.isClassLoaded("org.bukkit.entity.Dolphin"); + + // Default material names are ugly + private static final Registry MATERIALS_REGISTRY = initMaterialsRegistry(); + + // Materials that are considered air (with 1.13+ compatibility) + private static final Collection AIR_MATERIALS = getExistingMaterials("AIR", "CAVE_AIR", "VOID_AIR"); + + private MaterialsHelper() {} + + @SuppressWarnings("deprecation") + private static Registry initMaterialsRegistry() { + Registry materialsRegistry = Registry.fromEnumValues(Material.class); + + if (!USE_NEW_MATERIAL_NAMES) { + // Add numerical IDs in versions before 1.13 + for (Material material : Material.values()) { + materialsRegistry.put(String.valueOf(material.getId()), material); + } + } + + // Add some default useful aliases (when present) + materialsRegistry.putIfEnumExists("iron bar", "IRON_FENCE"); + materialsRegistry.putIfEnumExists("iron bars", "IRON_FENCE"); + materialsRegistry.putIfEnumExists("glass pane", "THIN_GLASS"); + materialsRegistry.putIfEnumExists("nether wart", "NETHER_STALK"); + materialsRegistry.putIfEnumExists("nether warts", "NETHER_STALK"); + materialsRegistry.putIfEnumExists("slab", "STEP"); + materialsRegistry.putIfEnumExists("double slab", "DOUBLE_STEP"); + materialsRegistry.putIfEnumExists("stone brick", "SMOOTH_BRICK"); + materialsRegistry.putIfEnumExists("stone bricks", "SMOOTH_BRICK"); + materialsRegistry.putIfEnumExists("stone stair", "SMOOTH_STAIRS"); + materialsRegistry.putIfEnumExists("stone stairs", "SMOOTH_STAIRS"); + materialsRegistry.putIfEnumExists("potato", "POTATO_ITEM"); + materialsRegistry.putIfEnumExists("carrot", "CARROT_ITEM"); + materialsRegistry.putIfEnumExists("brewing stand", "BREWING_STAND_ITEM"); + materialsRegistry.putIfEnumExists("cauldron", "CAULDRON_ITEM"); + materialsRegistry.putIfEnumExists("carrot on stick", "CARROT_STICK"); + materialsRegistry.putIfEnumExists("carrot on a stick", "CARROT_STICK"); + materialsRegistry.putIfEnumExists("cobblestone wall", "COBBLE_WALL"); + materialsRegistry.putIfEnumExists("acacia wood stairs", "ACACIA_STAIRS"); + materialsRegistry.putIfEnumExists("dark oak wood stairs", "DARK_OAK_STAIRS"); + materialsRegistry.putIfEnumExists("wood slab", "WOOD_STEP"); + materialsRegistry.putIfEnumExists("double wood slab", "WOOD_DOUBLE_STEP"); + materialsRegistry.putIfEnumExists("repeater", "DIODE"); + materialsRegistry.putIfEnumExists("piston", "PISTON_BASE"); + materialsRegistry.putIfEnumExists("sticky piston", "PISTON_STICKY_BASE"); + materialsRegistry.putIfEnumExists("flower pot", "FLOWER_POT_ITEM"); + materialsRegistry.putIfEnumExists("wood showel", "WOOD_SPADE"); + materialsRegistry.putIfEnumExists("stone showel", "STONE_SPADE"); + materialsRegistry.putIfEnumExists("gold showel", "GOLD_SPADE"); + materialsRegistry.putIfEnumExists("iron showel", "IRON_SPADE"); + materialsRegistry.putIfEnumExists("diamond showel", "DIAMOND_SPADE"); + materialsRegistry.putIfEnumExists("steak", "COOKED_BEEF"); + materialsRegistry.putIfEnumExists("cooked porkchop", "GRILLED_PORK"); + materialsRegistry.putIfEnumExists("raw porkchop", "PORK"); + materialsRegistry.putIfEnumExists("hardened clay", "HARD_CLAY"); + materialsRegistry.putIfEnumExists("huge brown mushroom", "HUGE_MUSHROOM_1"); + materialsRegistry.putIfEnumExists("huge red mushroom", "HUGE_MUSHROOM_2"); + materialsRegistry.putIfEnumExists("mycelium", "MYCEL"); + materialsRegistry.putIfEnumExists("poppy", "RED_ROSE"); + materialsRegistry.putIfEnumExists("comparator", "REDSTONE_COMPARATOR"); + materialsRegistry.putIfEnumExists("skull", "SKULL_ITEM"); + materialsRegistry.putIfEnumExists("head", "SKULL_ITEM"); + materialsRegistry.putIfEnumExists("redstone torch", "REDSTONE_TORCH_ON"); + materialsRegistry.putIfEnumExists("redstone lamp", "REDSTONE_LAMP_OFF"); + materialsRegistry.putIfEnumExists("glistering melon", "SPECKLED_MELON"); + materialsRegistry.putIfEnumExists("acacia leaves", "LEAVES_2"); + materialsRegistry.putIfEnumExists("acacia log", "LOG_2"); + materialsRegistry.putIfEnumExists("gunpowder", "SULPHUR"); + materialsRegistry.putIfEnumExists("lilypad", "WATER_LILY"); + materialsRegistry.putIfEnumExists("command block", "COMMAND"); + materialsRegistry.putIfEnumExists("dye", "INK_SACK"); + + return materialsRegistry; + } + + public static Optional matchMaterial(String materialName) { + return MATERIALS_REGISTRY.find(materialName); + } + + private static Collection getExistingMaterials(String... materialEnumNames) { + Collection existingMaterials = new HashSet<>(); + + for (String materialEnumName : materialEnumNames) { + try { + existingMaterials.add(Material.valueOf(materialEnumName)); + } catch (IllegalArgumentException e) { + // Ignore, not existing + } + } + + return existingMaterials; + } + + public static boolean isAir(Material material) { + return AIR_MATERIALS.contains(material); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Preconditions.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java similarity index 96% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/Preconditions.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java index ce7db9b..473c164 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Preconditions.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java @@ -1,68 +1,68 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.util; - -import java.util.Collection; - -import org.bukkit.Material; - -public final class Preconditions { - - private Preconditions() {} - - public static void notNull(Object object, String objectName) { - if (object == null) { - throw new NullPointerException(objectName + " cannot be null"); - } - } - - public static void notEmpty(Collection collection, String objectName) { - notNull(collection, objectName); - if (collection.isEmpty()) { - throw new IllegalArgumentException(objectName + " cannot be empty"); - } - } - - public static void checkArgument(boolean expression, String errorMessage) { - if (!expression) { - throw new IllegalArgumentException(errorMessage); - } - } - - public static void checkState(boolean expression, String errorMessage) { - if (!expression) { - throw new IllegalStateException(errorMessage); - } - } - - public static void checkIndex(int index, int size, String objectName) { - checkArgument(size >= 0, "size cannot be negative"); - - if (index < 0) { - throw new IndexOutOfBoundsException(objectName + " (" + index + ") cannot be negative"); - } - if (index >= size) { - throw new IndexOutOfBoundsException(objectName + " (" + index + ") must be less than size (" + size + ")"); - } - } - - public static void checkArgumentNotAir(Material material, String objectName) { - notNull(material, objectName); - if (MaterialsHelper.isAir(material)) { - throw new IllegalArgumentException(objectName + " cannot be " + material); - } - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.util; + +import java.util.Collection; + +import org.bukkit.Material; + +public final class Preconditions { + + private Preconditions() {} + + public static void notNull(Object object, String objectName) { + if (object == null) { + throw new NullPointerException(objectName + " cannot be null"); + } + } + + public static void notEmpty(Collection collection, String objectName) { + notNull(collection, objectName); + if (collection.isEmpty()) { + throw new IllegalArgumentException(objectName + " cannot be empty"); + } + } + + public static void checkArgument(boolean expression, String errorMessage) { + if (!expression) { + throw new IllegalArgumentException(errorMessage); + } + } + + public static void checkState(boolean expression, String errorMessage) { + if (!expression) { + throw new IllegalStateException(errorMessage); + } + } + + public static void checkIndex(int index, int size, String objectName) { + checkArgument(size >= 0, "size cannot be negative"); + + if (index < 0) { + throw new IndexOutOfBoundsException(objectName + " (" + index + ") cannot be negative"); + } + if (index >= size) { + throw new IndexOutOfBoundsException(objectName + " (" + index + ") must be less than size (" + size + ")"); + } + } + + public static void checkArgumentNotAir(Material material, String objectName) { + notNull(material, objectName); + if (MaterialsHelper.isAir(material)) { + throw new IllegalArgumentException(objectName + " cannot be " + material); + } + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Strings.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java similarity index 96% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/Strings.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java index 17860d7..075cfca 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Strings.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java @@ -1,91 +1,91 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.util; - -public final class Strings { - - private Strings() {} - - - public static String[] trimmedSplit(String input, String pattern) { - return trimmedSplit(input, pattern, 0); - } - - - public static String[] trimmedSplit(String input, String pattern, int limit) { - String[] output = input.split(pattern, limit); - for (int i = 0; i < output.length; i++) { - output[i] = output[i].trim(); - } - return output; - } - - - public static String stripChars(String input, char... removed) { - if (input == null || input.isEmpty() || removed.length == 0) { - return input; - } - - char[] chars = input.toCharArray(); - - int pos = 0; - for (int i = 0; i < chars.length; i++) { - if (!arrayContains(removed, chars[i])) { - chars[(pos++)] = chars[i]; - } - } - - return new String(chars, 0, pos); - } - - private static boolean arrayContains(char[] arr, char match) { - for (char c : arr) { - if (c == match) { - return true; - } - } - - return false; - } - - public static String capitalizeFully(String input) { - if (input == null) return null; - - String s = input.toLowerCase(); - - int strLen = s.length(); - StringBuilder output = new StringBuilder(strLen); - boolean capitalizeNext = true; - for (int i = 0; i < strLen; i++) { - char ch = s.charAt(i); - - if (Character.isWhitespace(ch)) { - output.append(ch); - capitalizeNext = true; - } else if (capitalizeNext) { - output.append(Character.toTitleCase(ch)); - capitalizeNext = false; - } else { - output.append(ch); - } - } - return output.toString(); - } - - public static boolean isNullOrEmpty(String s) { - return s == null || s.isEmpty(); - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.util; + +public final class Strings { + + private Strings() {} + + + public static String[] trimmedSplit(String input, String pattern) { + return trimmedSplit(input, pattern, 0); + } + + + public static String[] trimmedSplit(String input, String pattern, int limit) { + String[] output = input.split(pattern, limit); + for (int i = 0; i < output.length; i++) { + output[i] = output[i].trim(); + } + return output; + } + + + public static String stripChars(String input, char... removed) { + if (input == null || input.isEmpty() || removed.length == 0) { + return input; + } + + char[] chars = input.toCharArray(); + + int pos = 0; + for (int i = 0; i < chars.length; i++) { + if (!arrayContains(removed, chars[i])) { + chars[(pos++)] = chars[i]; + } + } + + return new String(chars, 0, pos); + } + + private static boolean arrayContains(char[] arr, char match) { + for (char c : arr) { + if (c == match) { + return true; + } + } + + return false; + } + + public static String capitalizeFully(String input) { + if (input == null) return null; + + String s = input.toLowerCase(); + + int strLen = s.length(); + StringBuilder output = new StringBuilder(strLen); + boolean capitalizeNext = true; + for (int i = 0; i < strLen; i++) { + char ch = s.charAt(i); + + if (Character.isWhitespace(ch)) { + output.append(ch); + capitalizeNext = true; + } else if (capitalizeNext) { + output.append(Character.toTitleCase(ch)); + capitalizeNext = false; + } else { + output.append(ch); + } + } + return output.toString(); + } + + public static boolean isNullOrEmpty(String s) { + return s == null || s.isEmpty(); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/collection/ArrayGrid.java b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/ArrayGrid.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/collection/ArrayGrid.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/collection/ArrayGrid.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/collection/CaseInsensitiveMap.java b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CaseInsensitiveMap.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/collection/CaseInsensitiveMap.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/collection/CaseInsensitiveMap.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/collection/ErrorCollector.java b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/ErrorCollector.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/collection/ErrorCollector.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/collection/ErrorCollector.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/collection/Grid.java b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/Grid.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/collection/Grid.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/collection/Grid.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/collection/Registry.java b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/Registry.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/collection/Registry.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/collection/Registry.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java diff --git a/pom.xml b/pom.xml index 4659108..81bca38 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,8 @@ API Plugin - + Utils + From 4040e603078b9504f817cdb6a4d7409a50255762 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 5 Jul 2020 12:30:37 +0200 Subject: [PATCH 122/213] Use Preconditions in API --- .../filoghost/chestcommands/api/internal/BackendAPI.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java index 7637438..c977c74 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java @@ -17,6 +17,7 @@ package me.filoghost.chestcommands.api.internal; import me.filoghost.chestcommands.api.ConfigurableIcon; import me.filoghost.chestcommands.api.IconMenu; import me.filoghost.chestcommands.api.StaticIcon; +import me.filoghost.chestcommands.util.Preconditions; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -27,13 +28,14 @@ public abstract class BackendAPI { private static BackendAPI implementation; public static void setImplementation(BackendAPI implementation) { + Preconditions.notNull(implementation, "implementation"); + Preconditions.checkState(implementation == null, "implementation already set"); + BackendAPI.implementation = implementation; } public static BackendAPI getImplementation() { - if (implementation == null) { - throw new IllegalStateException("no implementation set"); - } + Preconditions.checkState(implementation != null, "no implementation set"); return implementation; } From 035b445418f2d8f3b2ca6751d94196bae65e9be6 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 5 Jul 2020 12:33:46 +0200 Subject: [PATCH 123/213] Use ticks as unit for menu refreshing --- .../java/me/filoghost/chestcommands/ChestCommands.java | 2 +- .../chestcommands/parsing/menu/MenuParser.java | 10 +++++----- .../chestcommands/parsing/menu/MenuSettings.java | 10 +++++----- .../filoghost/chestcommands/task/RefreshMenusTask.java | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index c3778bd..5e1bc40 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -139,7 +139,7 @@ public class ChestCommands extends JavaPlugin { Bukkit.getScheduler().runTaskLater(this, errorCollector::logToConsole, 10L); } - Bukkit.getScheduler().runTaskTimer(this, new RefreshMenusTask(), 2L, 2L); + Bukkit.getScheduler().runTaskTimer(this, new RefreshMenusTask(), 1L, 1L); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index f60d46a..c868437 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -51,7 +51,7 @@ public class MenuParser { } } - iconMenu.setRefreshTicks(menuSettings.getRefreshTenths()); + iconMenu.setRefreshTicks(menuSettings.getRefreshTicks()); iconMenu.setOpenActions(menuSettings.getOpenActions()); return new LoadedMenu(iconMenu, menuConfig.getFileName(), menuSettings.getCommands(), menuSettings.getOpenTrigger()); @@ -163,11 +163,11 @@ public class MenuParser { } if (settingsSection.isSet(MenuSettingsNode.AUTO_REFRESH)) { - int tenthsToRefresh = (int) (settingsSection.getDouble(MenuSettingsNode.AUTO_REFRESH) * 10.0); - if (tenthsToRefresh < 1) { - tenthsToRefresh = 1; + int refreshTicks = (int) (settingsSection.getDouble(MenuSettingsNode.AUTO_REFRESH) * 20.0); + if (refreshTicks < 1) { + refreshTicks = 1; } - menuSettings.setRefreshTenths(tenthsToRefresh); + menuSettings.setRefreshTicks(refreshTicks); } return menuSettings; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java index dafa125..9809c04 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java @@ -27,7 +27,7 @@ public class MenuSettings { // Optional settings private List commands; private List openActions; - private int refreshTenths; + private int refreshTicks; private OpenTrigger openTrigger; @@ -60,12 +60,12 @@ public class MenuSettings { this.openActions = openAction; } - public int getRefreshTenths() { - return refreshTenths; + public int getRefreshTicks() { + return refreshTicks; } - public void setRefreshTenths(int refreshTenths) { - this.refreshTenths = refreshTenths; + public void setRefreshTicks(int refreshTicks) { + this.refreshTicks = refreshTicks; } public OpenTrigger getOpenTrigger() { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java index bd7611c..d0ebebb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java @@ -22,7 +22,7 @@ import org.bukkit.entity.Player; public class RefreshMenusTask implements Runnable { - private long elapsedTenths; + private long currentTick; @Override public void run() { @@ -35,12 +35,12 @@ public class RefreshMenusTask implements Runnable { int refreshTicks = ((InternalIconMenu) itemInventory.getMenu()).getRefreshTicks(); - if (refreshTicks > 0 && elapsedTenths % refreshTicks == 0) { + if (refreshTicks > 0 && currentTick % refreshTicks == 0) { itemInventory.refresh(); } } - elapsedTenths++; + currentTick++; } } From 25e7dbbaf7301fe2e103c51bb7cb0ed31cfd68d0 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 5 Jul 2020 12:39:52 +0200 Subject: [PATCH 124/213] Internally rename "variables" to "placeholders" --- .../chestcommands/action/BroadcastAction.java | 2 +- .../action/ChangeServerAction.java | 2 +- .../action/ConsoleCommandAction.java | 2 +- .../chestcommands/action/DragonBarAction.java | 2 +- .../chestcommands/action/OpCommandAction.java | 2 +- .../chestcommands/action/OpenMenuAction.java | 2 +- .../action/PlayerCommandAction.java | 2 +- .../action/SendMessageAction.java | 2 +- .../hook/PlaceholderAPIHook.java | 4 +- .../icon/BaseConfigurableIcon.java | 13 +- .../CachedGetters.java | 72 ++++----- .../Placeholder.java} | 143 +++++++++--------- .../placeholder/PlaceholderManager.java | 39 +++++ .../RelativeString.java | 14 +- .../RelativeStringList.java | 14 +- .../variable/VariableManager.java | 39 ----- Plugin/src/main/resources/menu/example.yml | 2 +- 17 files changed, 180 insertions(+), 176 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/{variable => placeholder}/CachedGetters.java (93%) rename Plugin/src/main/java/me/filoghost/chestcommands/{variable/Variable.java => placeholder/Placeholder.java} (90%) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java rename Plugin/src/main/java/me/filoghost/chestcommands/{variable => placeholder}/RelativeString.java (59%) rename Plugin/src/main/java/me/filoghost/chestcommands/{variable => placeholder}/RelativeStringList.java (73%) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/variable/VariableManager.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java index 8d80646..4ad9bba 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java @@ -18,7 +18,7 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import me.filoghost.chestcommands.util.Colors; -import me.filoghost.chestcommands.variable.RelativeString; +import me.filoghost.chestcommands.placeholder.RelativeString; public class BroadcastAction extends Action { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java index faf7b0f..efe9d3f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java @@ -17,7 +17,7 @@ package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; import me.filoghost.chestcommands.hook.BungeeCordHook; -import me.filoghost.chestcommands.variable.RelativeString; +import me.filoghost.chestcommands.placeholder.RelativeString; public class ChangeServerAction extends Action { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java index 5535a31..21a7ffa 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java @@ -17,7 +17,7 @@ package me.filoghost.chestcommands.action; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.variable.RelativeString; +import me.filoghost.chestcommands.placeholder.RelativeString; public class ConsoleCommandAction extends Action { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java index b48d6b3..953e083 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java @@ -22,7 +22,7 @@ import me.filoghost.chestcommands.hook.BarAPIHook; import me.filoghost.chestcommands.parsing.NumberParser; import me.filoghost.chestcommands.util.Colors; import me.filoghost.chestcommands.util.Strings; -import me.filoghost.chestcommands.variable.RelativeString; +import me.filoghost.chestcommands.placeholder.RelativeString; public class DragonBarAction extends Action { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java index d67e175..8f60de1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java @@ -16,7 +16,7 @@ package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.variable.RelativeString; +import me.filoghost.chestcommands.placeholder.RelativeString; public class OpCommandAction extends Action { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java index e08f04a..8cb94af 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java @@ -16,7 +16,7 @@ package me.filoghost.chestcommands.action; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.menu.InternalIconMenu; -import me.filoghost.chestcommands.variable.RelativeString; +import me.filoghost.chestcommands.placeholder.RelativeString; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java index ad7b45b..6aa3fc5 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java @@ -16,7 +16,7 @@ package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.variable.RelativeString; +import me.filoghost.chestcommands.placeholder.RelativeString; public class PlayerCommandAction extends Action { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java index c579e6f..53d6a2b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java @@ -17,7 +17,7 @@ package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; import me.filoghost.chestcommands.util.Colors; -import me.filoghost.chestcommands.variable.RelativeString; +import me.filoghost.chestcommands.placeholder.RelativeString; public class SendMessageAction extends Action { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java index 0a0ead6..1859861 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java @@ -26,10 +26,10 @@ public enum PlaceholderAPIHook implements PluginHook { return PlaceholderAPI.containsPlaceholders(message); } - public static String setPlaceholders(String message, Player executor) { + public static String setPlaceholders(String message, Player viewer) { INSTANCE.checkEnabledState(); - return PlaceholderAPI.setPlaceholders(executor, message); + return PlaceholderAPI.setPlaceholders(viewer, message); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java index 565d6b5..979927b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java @@ -18,8 +18,8 @@ import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.util.Log; import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.collection.CollectionUtils; -import me.filoghost.chestcommands.variable.RelativeString; -import me.filoghost.chestcommands.variable.RelativeStringList; +import me.filoghost.chestcommands.placeholder.RelativeString; +import me.filoghost.chestcommands.placeholder.RelativeStringList; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Color; @@ -57,7 +57,7 @@ public abstract class BaseConfigurableIcon implements Icon { private List bannerPatterns; private boolean placeholdersEnabled; - protected ItemStack cachedRendering; // Cache the rendered item when there are no variables and values haven't changed + protected ItemStack cachedRendering; // Cache the rendered item when possible and if state hasn't changed public BaseConfigurableIcon(Material material) { Preconditions.checkArgumentNotAir(material, "material"); @@ -70,9 +70,9 @@ public abstract class BaseConfigurableIcon implements Icon { return false; } - return (name == null || !name.hasVariables()) - && (lore == null || !lore.hasVariables()) - && (skullOwner == null || !skullOwner.hasVariables()); + return (name == null || !name.hasPlaceholders()) + && (lore == null || !lore.hasPlaceholders()) + && (skullOwner == null || !skullOwner.hasPlaceholders()); } public void setMaterial(Material material) { @@ -324,7 +324,6 @@ public abstract class BaseConfigurableIcon implements Icon { if (shouldCacheRendering()) { - // If there are no variables, cache the item cachedRendering = itemStack; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/variable/CachedGetters.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/CachedGetters.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/variable/CachedGetters.java rename to Plugin/src/main/java/me/filoghost/chestcommands/placeholder/CachedGetters.java index 73d1de0..f905120 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/variable/CachedGetters.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/CachedGetters.java @@ -1,36 +1,36 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.variable; - -import org.bukkit.Bukkit; - -public class CachedGetters { - - private static long lastOnlinePlayersRefresh; - private static int onlinePlayers; - - - public static int getOnlinePlayers() { - long now = System.currentTimeMillis(); - if (lastOnlinePlayersRefresh == 0 || now - lastOnlinePlayersRefresh > 1000) { - // getOnlinePlayers() could be expensive if called frequently - lastOnlinePlayersRefresh = now; - onlinePlayers = Bukkit.getOnlinePlayers().size(); - } - - return onlinePlayers; - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.placeholder; + +import org.bukkit.Bukkit; + +public class CachedGetters { + + private static long lastOnlinePlayersRefresh; + private static int onlinePlayers; + + + public static int getOnlinePlayers() { + long now = System.currentTimeMillis(); + if (lastOnlinePlayersRefresh == 0 || now - lastOnlinePlayersRefresh > 1000) { + // getOnlinePlayers() could be expensive if called frequently + lastOnlinePlayersRefresh = now; + onlinePlayers = Bukkit.getOnlinePlayers().size(); + } + + return onlinePlayers; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/variable/Variable.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/Placeholder.java similarity index 90% rename from Plugin/src/main/java/me/filoghost/chestcommands/variable/Variable.java rename to Plugin/src/main/java/me/filoghost/chestcommands/placeholder/Placeholder.java index a2e09a4..3482a61 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/variable/Variable.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/Placeholder.java @@ -1,69 +1,74 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.variable; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import me.filoghost.chestcommands.hook.VaultEconomyHook; - -public enum Variable { - - PLAYER("{player}") { - public String getReplacement(Player executor) { - return executor.getName(); - } - }, - - ONLINE("{online}") { - public String getReplacement(Player executor) { - return String.valueOf(CachedGetters.getOnlinePlayers()); - } - }, - - MAX_PLAYERS("{max_players}") { - public String getReplacement(Player executor) { - return String.valueOf(Bukkit.getMaxPlayers()); - } - }, - - MONEY("{money}") { - public String getReplacement(Player executor) { - if (VaultEconomyHook.INSTANCE.isEnabled()) { - return VaultEconomyHook.formatMoney(VaultEconomyHook.getMoney(executor)); - } else { - return "[ECONOMY PLUGIN NOT FOUND]"; - } - } - }, - - WORLD("{world}") { - public String getReplacement(Player executor) { - return executor.getWorld().getName(); - } - }; - - private final String text; - - private Variable(String text) { - this.text = text; - } - - public String getText() { - return text; - } - - public abstract String getReplacement(Player executor); -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.placeholder; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import me.filoghost.chestcommands.hook.VaultEconomyHook; + +public enum Placeholder { + + PLAYER("{player}") { + @Override + public String getReplacement(Player executor) { + return executor.getName(); + } + }, + + ONLINE("{online}") { + @Override + public String getReplacement(Player executor) { + return String.valueOf(CachedGetters.getOnlinePlayers()); + } + }, + + MAX_PLAYERS("{max_players}") { + @Override + public String getReplacement(Player executor) { + return String.valueOf(Bukkit.getMaxPlayers()); + } + }, + + MONEY("{money}") { + @Override + public String getReplacement(Player executor) { + if (VaultEconomyHook.INSTANCE.isEnabled()) { + return VaultEconomyHook.formatMoney(VaultEconomyHook.getMoney(executor)); + } else { + return "[ECONOMY PLUGIN NOT FOUND]"; + } + } + }, + + WORLD("{world}") { + @Override + public String getReplacement(Player executor) { + return executor.getWorld().getName(); + } + }; + + private final String text; + + Placeholder(String text) { + this.text = text; + } + + public String getText() { + return text; + } + + public abstract String getReplacement(Player executor); +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java new file mode 100644 index 0000000..4eda536 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java @@ -0,0 +1,39 @@ +package me.filoghost.chestcommands.placeholder; + +import org.bukkit.entity.Player; + +import me.filoghost.chestcommands.hook.PlaceholderAPIHook; + +public class PlaceholderManager { + + public static boolean hasPlaceholders(String message) { + if(message == null) { + return false; + } + for (Placeholder placeholder : Placeholder.values()) { + if (message.contains(placeholder.getText())) { + return true; + } + } + if (PlaceholderAPIHook.INSTANCE.isEnabled() && PlaceholderAPIHook.hasPlaceholders(message)) { + return true; + } + return false; + } + + public static String replacePlaceholders(String message, Player viewer) { + if (message == null) { + return null; + } + for (Placeholder placeholder : Placeholder.values()) { + if (message.contains(placeholder.getText())) { + message = message.replace(placeholder.getText(), placeholder.getReplacement(viewer)); + } + } + if (PlaceholderAPIHook.INSTANCE.isEnabled()) { + message = PlaceholderAPIHook.setPlaceholders(message, viewer); + } + return message; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/variable/RelativeString.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeString.java similarity index 59% rename from Plugin/src/main/java/me/filoghost/chestcommands/variable/RelativeString.java rename to Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeString.java index ba0f59c..a4e754e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/variable/RelativeString.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeString.java @@ -1,11 +1,11 @@ -package me.filoghost.chestcommands.variable; +package me.filoghost.chestcommands.placeholder; import org.bukkit.entity.Player; public class RelativeString { private final String string; - private final boolean hasVariables; + private final boolean hasPlaceholders; public static RelativeString of(String string) { if (string != null) { @@ -17,7 +17,7 @@ public class RelativeString { private RelativeString(String string) { this.string = string; - this.hasVariables = VariableManager.hasVariables(string); + this.hasPlaceholders = PlaceholderManager.hasPlaceholders(string); } public String getRawValue() { @@ -25,15 +25,15 @@ public class RelativeString { } public String getValue(Player player) { - if (hasVariables) { - return VariableManager.setVariables(string, player); + if (hasPlaceholders) { + return PlaceholderManager.replacePlaceholders(string, player); } else { return string; } } - public boolean hasVariables() { - return hasVariables; + public boolean hasPlaceholders() { + return hasPlaceholders; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/variable/RelativeStringList.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeStringList.java similarity index 73% rename from Plugin/src/main/java/me/filoghost/chestcommands/variable/RelativeStringList.java rename to Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeStringList.java index cd1ae39..14ff906 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/variable/RelativeStringList.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeStringList.java @@ -1,4 +1,4 @@ -package me.filoghost.chestcommands.variable; +package me.filoghost.chestcommands.placeholder; import java.util.List; @@ -12,17 +12,17 @@ public class RelativeStringList { private final ImmutableList originalList; private final List relativeList; - private final boolean hasVariables; + private final boolean hasPlaceholders; public RelativeStringList(List list) { if (list != null) { this.originalList = ImmutableList.copyOf(list); this.relativeList = CollectionUtils.transform(list, RelativeString::of); - this.hasVariables = this.relativeList.stream().anyMatch(RelativeString::hasVariables); + this.hasPlaceholders = this.relativeList.stream().anyMatch(RelativeString::hasPlaceholders); } else { this.originalList = null; this.relativeList = null; - this.hasVariables = false; + this.hasPlaceholders = false; } } @@ -31,15 +31,15 @@ public class RelativeStringList { } public List getValue(Player player) { - if (hasVariables) { + if (hasPlaceholders) { return CollectionUtils.transform(relativeList, element -> element.getValue(player)); } else { return originalList; } } - public boolean hasVariables() { - return hasVariables; + public boolean hasPlaceholders() { + return hasPlaceholders; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/variable/VariableManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/variable/VariableManager.java deleted file mode 100644 index 07f75e2..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/variable/VariableManager.java +++ /dev/null @@ -1,39 +0,0 @@ -package me.filoghost.chestcommands.variable; - -import org.bukkit.entity.Player; - -import me.filoghost.chestcommands.hook.PlaceholderAPIHook; - -public class VariableManager { - - public static boolean hasVariables(String message) { - if(message == null) { - return false; - } - for (Variable variable : Variable.values()) { - if (message.contains(variable.getText())) { - return true; - } - } - if (PlaceholderAPIHook.INSTANCE.isEnabled() && PlaceholderAPIHook.hasPlaceholders(message)) { - return true; - } - return false; - } - - public static String setVariables(String message, Player executor) { - if (message == null) { - return null; - } - for (Variable variable : Variable.values()) { - if (message.contains(variable.getText())) { - message = message.replace(variable.getText(), variable.getReplacement(executor)); - } - } - if (PlaceholderAPIHook.INSTANCE.isEnabled()) { - message = PlaceholderAPIHook.setPlaceholders(message, executor); - } - return message; - } - -} diff --git a/Plugin/src/main/resources/menu/example.yml b/Plugin/src/main/resources/menu/example.yml index e12fe95..c075935 100644 --- a/Plugin/src/main/resources/menu/example.yml +++ b/Plugin/src/main/resources/menu/example.yml @@ -21,7 +21,7 @@ menu-settings: # OPTIONAL # How frequently the menu will be refreshed, in seconds. - # Useful if you have variables in icon descriptions. + # Useful if you have placeholders in icon descriptions. auto-refresh: 5 # OPTIONAL From dfc060fdcdd7584014e495ead3534636718f51b4 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 6 Jul 2020 18:08:19 +0200 Subject: [PATCH 125/213] Fix startup error --- .../me/filoghost/chestcommands/api/internal/BackendAPI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java index c977c74..21e3000 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java @@ -29,7 +29,7 @@ public abstract class BackendAPI { public static void setImplementation(BackendAPI implementation) { Preconditions.notNull(implementation, "implementation"); - Preconditions.checkState(implementation == null, "implementation already set"); + Preconditions.checkState(BackendAPI.implementation == null, "implementation already set"); BackendAPI.implementation = implementation; } From 58bdf388bfd0dab86497876e7364aa2315585474 Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 9 Jul 2020 23:35:40 +0200 Subject: [PATCH 126/213] Large configuration refactoring --- .../chestcommands/ChestCommands.java | 18 +- .../chestcommands/config/ConfigLoader.java | 126 -------------- .../chestcommands/config/ConfigManager.java | 117 ++++++------- .../config/ConfigValueException.java | 9 - .../{files => }/CustomPlaceholders.java | 10 +- .../config/{files => }/Lang.java | 8 +- .../config/{files => }/Settings.java | 12 +- .../chestcommands/config/SpecialConfig.java | 128 -------------- .../config/framework/BaseConfigManager.java | 51 ++++++ .../config/{ => framework}/Config.java | 20 ++- .../config/framework/ConfigLoader.java | 143 ++++++++++++++++ .../config/{ => framework}/ConfigSection.java | 15 +- .../framework/exception/ConfigException.java | 13 ++ .../exception/ConfigLoadException.java | 9 + .../exception/ConfigSaveException.java | 9 + .../exception/ConfigSyntaxException.java | 11 ++ .../exception/ConfigValueException.java | 9 + .../config/framework/mapped/ConfigMapper.java | 157 ++++++++++++++++++ .../framework/mapped/IncludeStatic.java | 26 +++ .../config/framework/mapped/MappedConfig.java | 33 ++++ .../framework/mapped/MappedConfigLoader.java | 78 +++++++++ .../config/framework/mapped/MappedField.java | 88 ++++++++++ .../mapped/converter/BooleanConverter.java | 38 +++++ .../framework/mapped/converter/Converter.java | 29 ++++ .../mapped/converter/DoubleConverter.java | 38 +++++ .../mapped/converter/IntegerConverter.java | 38 +++++ .../mapped/converter/ListConverter.java | 51 ++++++ .../mapped/converter/StringConverter.java | 38 +++++ .../framework/mapped/modifier/ChatColors.java | 26 +++ .../mapped/modifier/ChatColorsModifier.java | 36 ++++ .../mapped/modifier/ValueModifier.java | 38 +++++ .../chestcommands/legacy/Upgrade.java | 27 ++- .../legacy/UpgradesExecutor.java | 38 +++-- .../legacy/upgrades/MenuUpgrade.java | 22 +-- .../legacy/upgrades/PlaceholdersUpgrade.java | 26 +-- .../legacy/upgrades/SettingsUpgrade.java | 23 +-- .../chestcommands/parsing/ErrorFormat.java | 13 +- .../parsing/icon/IconSettings.java | 4 +- .../parsing/menu/MenuParser.java | 20 +-- .../chestcommands/util/Preconditions.java | 4 +- 40 files changed, 1135 insertions(+), 464 deletions(-) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigLoader.java delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigValueException.java rename Plugin/src/main/java/me/filoghost/chestcommands/config/{files => }/CustomPlaceholders.java (83%) rename Plugin/src/main/java/me/filoghost/chestcommands/config/{files => }/Lang.java (85%) rename Plugin/src/main/java/me/filoghost/chestcommands/config/{files => }/Settings.java (70%) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/SpecialConfig.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/BaseConfigManager.java rename Plugin/src/main/java/me/filoghost/chestcommands/config/{ => framework}/Config.java (73%) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java rename Plugin/src/main/java/me/filoghost/chestcommands/config/{ => framework}/ConfigSection.java (91%) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigException.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigLoadException.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSaveException.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSyntaxException.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigValueException.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/ConfigMapper.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/IncludeStatic.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfig.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedField.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/BooleanConverter.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/Converter.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/DoubleConverter.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/IntegerConverter.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/ListConverter.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/StringConverter.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColors.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColorsModifier.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ValueModifier.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 5e1bc40..4fc019f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -17,12 +17,11 @@ package me.filoghost.chestcommands; import me.filoghost.chestcommands.api.internal.BackendAPI; import me.filoghost.chestcommands.command.CommandHandler; import me.filoghost.chestcommands.command.framework.CommandFramework; -import me.filoghost.chestcommands.config.ConfigLoader; +import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.config.ConfigManager; -import me.filoghost.chestcommands.config.files.CustomPlaceholders; -import me.filoghost.chestcommands.config.files.Lang; -import me.filoghost.chestcommands.parsing.menu.LoadedMenu; -import me.filoghost.chestcommands.config.files.Settings; +import me.filoghost.chestcommands.config.CustomPlaceholders; +import me.filoghost.chestcommands.config.Lang; +import me.filoghost.chestcommands.config.Settings; import me.filoghost.chestcommands.hook.BarAPIHook; import me.filoghost.chestcommands.hook.BungeeCordHook; import me.filoghost.chestcommands.hook.PlaceholderAPIHook; @@ -34,10 +33,11 @@ import me.filoghost.chestcommands.listener.InventoryListener; import me.filoghost.chestcommands.listener.JoinListener; import me.filoghost.chestcommands.listener.SignListener; import me.filoghost.chestcommands.menu.MenuManager; +import me.filoghost.chestcommands.parsing.menu.LoadedMenu; import me.filoghost.chestcommands.task.RefreshMenusTask; +import me.filoghost.chestcommands.util.Log; import me.filoghost.chestcommands.util.Utils; import me.filoghost.chestcommands.util.collection.ErrorCollector; -import me.filoghost.chestcommands.util.Log; import me.filoghost.updatechecker.UpdateChecker; import org.bstats.bukkit.MetricsLite; import org.bukkit.Bukkit; @@ -152,9 +152,9 @@ public class ChestCommands extends JavaPlugin { public ErrorCollector load() { ErrorCollector errors = new ErrorCollector(); menuManager.clear(); - boolean isFreshInstall = !Files.isDirectory(configManager.getBaseDataPath()); + boolean isFreshInstall = !Files.isDirectory(configManager.getRootDataFolder()); try { - Files.createDirectories(configManager.getBaseDataPath()); + Files.createDirectories(configManager.getRootDataFolder()); } catch (IOException e) { errors.addError("Plugin failed to load, couldn't create data folder."); return errors; @@ -172,7 +172,7 @@ public class ChestCommands extends JavaPlugin { // Create the menu folder with the example menu if (!Files.isDirectory(configManager.getMenusFolder())) { - ConfigLoader exampleMenuLoader = new ConfigLoader(configManager.getMenusFolder().resolve("example.yml")); + ConfigLoader exampleMenuLoader = configManager.getConfigLoader(configManager.getMenusFolder().resolve("example.yml")); configManager.tryCreateDefault(exampleMenuLoader); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigLoader.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigLoader.java deleted file mode 100644 index 7c8cd2b..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigLoader.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.config; - -import me.filoghost.chestcommands.util.Preconditions; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - -public class ConfigLoader { - - private final Path path; - - public ConfigLoader(Path path) { - this.path = path; - } - - public Path getPath() { - return path; - } - - public void createDefault(Path baseDataPath) throws IOException { - if (!path.startsWith(baseDataPath)) { - throw new IOException("Config file " + path + " must be inside " + baseDataPath); - } - - if (Files.exists(path)) { - return; - } - - if (path.getParent() != null) { - Files.createDirectories(path.getParent()); - } - - Path absoluteDataPath = baseDataPath.toAbsolutePath(); - Path absoluteConfigPath = path.toAbsolutePath(); - - if (absoluteConfigPath.startsWith(absoluteDataPath)) { - Path relativeConfigPath = absoluteDataPath.relativize(absoluteConfigPath); - String internalJarPath = toInternalJarPath(relativeConfigPath); - - try (InputStream defaultFile = getResource(internalJarPath)) { - if (defaultFile != null) { - Files.copy(defaultFile, path); - return; - } - } - } - - Files.createFile(path); - } - - private String toInternalJarPath(Path path) { - return StreamSupport.stream(path.spliterator(), false) - .map(Path::toString) - .collect(Collectors.joining("/", "/", "")); - } - - - private InputStream getResource(String internalJarPath) throws IOException { - Preconditions.notNull(internalJarPath, "internalJarPath"); - - URL resourceURL = getClass().getResource(internalJarPath); - if (resourceURL == null) { - return null; - } - - URLConnection connection = resourceURL.openConnection(); - connection.setUseCaches(false); - return connection.getInputStream(); - } - - - public Config load() throws IOException, InvalidConfigurationException { - YamlConfiguration yaml = new YamlConfiguration(); - - try (BufferedReader reader = Files.newBufferedReader(path)) { - yaml.load(reader); - } - - return new Config(yaml, path); - } - - public Config loadEmpty() { - return new Config(new YamlConfiguration(), path); - } - - public void save(Config config) throws IOException { - if (path.getParent() != null) { - Files.createDirectories(path.getParent()); - } - - String data = config.saveToString(); - - try (BufferedWriter writer = Files.newBufferedWriter(path)) { - writer.write(data); - } - } - - public String getFileName() { - return path.getFileName().toString(); - } - -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java index 5b70d7b..fe0339e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java @@ -14,14 +14,17 @@ */ package me.filoghost.chestcommands.config; -import me.filoghost.chestcommands.config.files.CustomPlaceholders; -import me.filoghost.chestcommands.config.files.Lang; +import me.filoghost.chestcommands.config.framework.BaseConfigManager; +import me.filoghost.chestcommands.config.framework.Config; +import me.filoghost.chestcommands.config.framework.ConfigLoader; +import me.filoghost.chestcommands.config.framework.exception.ConfigException; +import me.filoghost.chestcommands.config.framework.exception.ConfigSyntaxException; +import me.filoghost.chestcommands.config.framework.mapped.MappedConfigLoader; import me.filoghost.chestcommands.parsing.menu.LoadedMenu; -import me.filoghost.chestcommands.config.files.Settings; import me.filoghost.chestcommands.parsing.menu.MenuParser; -import me.filoghost.chestcommands.util.collection.ErrorCollector; import me.filoghost.chestcommands.util.Log; -import org.bukkit.configuration.InvalidConfigurationException; +import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.chestcommands.util.collection.ErrorCollector; import java.io.IOException; import java.nio.file.FileVisitOption; @@ -33,55 +36,46 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -public class ConfigManager { +public class ConfigManager extends BaseConfigManager { - private final Path baseDataPath; - private final ConfigLoader settingsConfigLoader; + private final MappedConfigLoader settingsConfigLoader; private final ConfigLoader placeholdersConfigLoader; - private final ConfigLoader langConfigLoader; + private final MappedConfigLoader langConfigLoader; - public ConfigManager(Path baseDataPath) { - this.baseDataPath = baseDataPath; - settingsConfigLoader = new ConfigLoader(baseDataPath.resolve("config.yml")); - placeholdersConfigLoader = new ConfigLoader(baseDataPath.resolve("custom-placeholders.yml")); - langConfigLoader = new ConfigLoader(baseDataPath.resolve("lang.yml")); + public ConfigManager(Path rootDataFolder) { + super(rootDataFolder); + + settingsConfigLoader = getMappedConfigLoader("config.yml", Settings::new); + placeholdersConfigLoader = getConfigLoader("custom-placeholders.yml"); + langConfigLoader = getMappedConfigLoader("lang.yml", Lang::new); } public Settings tryLoadSettings() { - Settings settings = new Settings(); - try { - settingsConfigLoader.createDefault(baseDataPath); - settings.load(settingsConfigLoader); - } catch (Throwable t) { - logConfigLoadException(settingsConfigLoader, t); + return settingsConfigLoader.init(); + } catch (ConfigException e) { + logConfigInitException(settingsConfigLoader.getFileName(), e); + return new Settings(); } - - return settings; } public Lang tryLoadLang() { - Lang lang = new Lang(); - try { - langConfigLoader.createDefault(baseDataPath); - lang.load(langConfigLoader); - } catch (Throwable t) { - logConfigLoadException(langConfigLoader, t); + return langConfigLoader.init(); + } catch (ConfigException e) { + logConfigInitException(langConfigLoader.getFileName(), e); + return new Lang(); } - - return lang; } public CustomPlaceholders tryLoadCustomPlaceholders(ErrorCollector errorCollector) { CustomPlaceholders placeholders = new CustomPlaceholders(); try { - placeholdersConfigLoader.createDefault(baseDataPath); - Config placeholdersConfig = placeholdersConfigLoader.load(); + Config placeholdersConfig = placeholdersConfigLoader.init(); placeholders.load(placeholdersConfig, errorCollector); - } catch (Throwable t) { - logConfigLoadException(placeholdersConfigLoader, t); + } catch (ConfigException t) { + logConfigInitException(placeholdersConfigLoader.getFileName(), t); } return placeholders; @@ -89,20 +83,22 @@ public class ConfigManager { public void tryCreateDefault(ConfigLoader configLoader) { try { - configLoader.createDefault(baseDataPath); - } catch (Throwable t) { - logConfigLoadException(configLoader, t); + configLoader.createDefault(); + } catch (ConfigException e) { + logConfigInitException(configLoader.getFileName(), e); } } public Path getMenusFolder() { - return baseDataPath.resolve("menu"); + return rootDataFolder.resolve("menu"); } /** * Returns a list of YML menu files. */ public List getMenuPaths() throws IOException { + Preconditions.checkState(Files.isDirectory(getMenusFolder()), "menus folder doesn't exist"); + try (Stream paths = Files.walk(getMenusFolder(), FileVisitOption.FOLLOW_LINKS)) { return paths.filter(Files::isRegularFile) .filter(this::isYmlPath) @@ -110,39 +106,15 @@ public class ConfigManager { } } - - private boolean isYmlPath(Path path) { - return path.getFileName().toString().toLowerCase().endsWith(".yml"); - } - - private void logConfigLoadException(ConfigLoader configLoader, Throwable t) { - t.printStackTrace(); - - if (t instanceof IOException) { - Log.warning("Error while reading the file \"" + configLoader.getFileName() + "\". Default values will be used."); - } else if (t instanceof InvalidConfigurationException) { - Log.warning("Invalid YAML syntax in the file \"" + configLoader.getFileName() + "\", please look at the error above. Default values will be used."); + private void logConfigInitException(String fileName, ConfigException e) { + if (e instanceof ConfigSyntaxException) { + Log.warning("Invalid YAML syntax in config file \"" + fileName + "\": " + e.getMessage()); } else { - Log.warning("Unhandled error while parsing the file \"" + configLoader.getFileName() + "\". Please inform the developer."); + e.printStackTrace(); + Log.warning("Error while reading config file \"" + fileName + "\": " + e.getMessage()); } } - public Path getBaseDataPath() { - return baseDataPath; - } - - public ConfigLoader getSettingsConfigLoader() { - return settingsConfigLoader; - } - - public ConfigLoader getPlaceholdersConfigLoader() { - return placeholdersConfigLoader; - } - - public ConfigLoader getLangConfigLoader() { - return langConfigLoader; - } - public List tryLoadMenus(ErrorCollector errorCollector) { List loadedMenus = new ArrayList<>(); List menuPaths; @@ -155,16 +127,21 @@ public class ConfigManager { } for (Path menuFile : menuPaths) { - ConfigLoader menuConfigLoader = new ConfigLoader(menuFile); + ConfigLoader menuConfigLoader = new ConfigLoader(rootDataFolder, menuFile); try { Config menuConfig = menuConfigLoader.load(); loadedMenus.add(MenuParser.loadMenu(menuConfig, errorCollector)); - } catch (Throwable t) { - logConfigLoadException(menuConfigLoader, t); + } catch (ConfigException e) { + logConfigInitException(menuConfigLoader.getFileName(), e); } } return loadedMenus; } + + private boolean isYmlPath(Path path) { + return path.getFileName().toString().toLowerCase().endsWith(".yml"); + } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigValueException.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigValueException.java deleted file mode 100644 index 61aa8b1..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigValueException.java +++ /dev/null @@ -1,9 +0,0 @@ -package me.filoghost.chestcommands.config; - -public class ConfigValueException extends Exception { - - public ConfigValueException(String message) { - super(message); - } - -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/files/CustomPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java similarity index 83% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/files/CustomPlaceholders.java rename to Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java index 5164727..b8b4beb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/files/CustomPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java @@ -12,12 +12,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.files; +package me.filoghost.chestcommands.config; -import me.filoghost.chestcommands.config.Config; -import me.filoghost.chestcommands.util.collection.ErrorCollector; +import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.util.Colors; import me.filoghost.chestcommands.util.collection.CollectionUtils; +import me.filoghost.chestcommands.util.collection.ErrorCollector; import java.util.HashMap; import java.util.List; @@ -36,12 +36,12 @@ public class CustomPlaceholders { String replacement = Colors.addColors(config.getString(key)); if (placeholder.length() == 0) { - errorCollector.addError("Error in " + config.getFileName() + ": placeholder cannot be empty (skipped)."); + errorCollector.addError("Error in " + config.getSourceFileName() + ": placeholder cannot be empty (skipped)."); continue; } if (placeholder.length() > 100) { - errorCollector.addError("Error in " + config.getFileName() + ": placeholder cannot be longer than 100 character (" + placeholder + ")."); + errorCollector.addError("Error in " + config.getSourceFileName() + ": placeholder cannot be longer than 100 character (" + placeholder + ")."); continue; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/files/Lang.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java similarity index 85% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/files/Lang.java rename to Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java index 53dc987..7108241 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/files/Lang.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java @@ -12,11 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.files; +package me.filoghost.chestcommands.config; -import me.filoghost.chestcommands.config.SpecialConfig; +import me.filoghost.chestcommands.config.framework.mapped.MappedConfig; +import me.filoghost.chestcommands.config.framework.mapped.modifier.ChatColors; -public class Lang extends SpecialConfig { +@ChatColors +public class Lang extends MappedConfig { public String no_open_permission = "&cYou don't have permission &e{permission} &cto use this menu."; public String default_no_icon_permission = "&cYou don't have permission for this icon."; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/files/Settings.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java similarity index 70% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/files/Settings.java rename to Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java index a8bd20c..d308eb4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/files/Settings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java @@ -12,11 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.files; +package me.filoghost.chestcommands.config; -import me.filoghost.chestcommands.config.SpecialConfig; +import me.filoghost.chestcommands.config.framework.mapped.MappedConfig; +import me.filoghost.chestcommands.config.framework.mapped.modifier.ChatColors; -public class Settings extends SpecialConfig { +@ChatColors +public class Settings extends MappedConfig { public String default_color__name = "&f"; public String default_color__lore = "&7"; @@ -25,8 +27,8 @@ public class Settings extends SpecialConfig { public Settings() { setHeader( - "ChestCommands main configuration file.\n" + - "Documentation: https://filoghost.me/docs/chest-commands\n"); + "ChestCommands main configuration file.", + "Documentation: https://filoghost.me/docs/chest-commands"); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/SpecialConfig.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/SpecialConfig.java deleted file mode 100644 index d6a285f..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/SpecialConfig.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.config; - -import me.filoghost.chestcommands.util.Colors; -import me.filoghost.chestcommands.util.Log; -import org.bukkit.configuration.InvalidConfigurationException; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -/** - * A special configuration wrapper that reads the values using reflection. - * It will also save default values if not set. - */ -public abstract class SpecialConfig { - - private transient String header; - private transient Map defaultValuesMap; - - public void setHeader(String header) { - this.header = header; - } - - public void load(ConfigLoader loader) throws IOException, IllegalAccessException, InvalidConfigurationException { - Config config = loader.load(); - - // Check if the configuration was initialized - if (defaultValuesMap == null) { - defaultValuesMap = new HashMap<>(); - - // Put the values in the default values map - for (Field field : getClass().getDeclaredFields()) { - if (skipField(field)) continue; - - field.setAccessible(true); - String configKey = getConfigNode(field); - - try { - Object defaultValue = field.get(this); - if (defaultValue != null) { - defaultValuesMap.put(configKey, defaultValue); - } else { - Log.warning("The field " + field.getName() + " was not provided with a default value, please inform the developer."); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } - - boolean needsSave = false; - - // Save default values not set - for (Entry entry : defaultValuesMap.entrySet()) { - if (!config.isSet(entry.getKey())) { - needsSave = true; - config.set(entry.getKey(), entry.getValue()); - } - } - - if (needsSave) { - config.setHeader(header); - loader.save(config); - } - - // Now read change the fields - for (Field field : getClass().getDeclaredFields()) { - if (skipField(field)) { - continue; - } - - field.setAccessible(true); - String configNode = getConfigNode(field); - - if (config.isSet(configNode)) { - Class type = field.getType(); - - if (type == boolean.class || type == Boolean.class) { - field.set(this, config.getBoolean(configNode)); - - } else if (type == int.class || type == Integer.class) { - field.set(this, config.getInt(configNode)); - - } else if (type == double.class || type == Double.class) { - field.set(this, config.getDouble(configNode)); - - } else if (type == String.class) { - field.set(this, Colors.addColors(config.getString(configNode))); // Always add colors - - } else { - Log.warning("Unknown field type: " + field.getType().getName() + " (" + field.getName() + "). Please inform the developer."); - } - - } else { - field.set(this, defaultValuesMap.get(configNode)); - } - } - } - - - private boolean skipField(Field field) { - int modifiers = field.getModifiers(); - return Modifier.isTransient(modifiers) || Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers); - } - - private String getConfigNode(Field field) { - return field.getName().replace("__", ".").replace("_", "-"); - } - -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/BaseConfigManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/BaseConfigManager.java new file mode 100644 index 0000000..00efc64 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/BaseConfigManager.java @@ -0,0 +1,51 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework; + +import me.filoghost.chestcommands.config.framework.mapped.MappedConfig; +import me.filoghost.chestcommands.config.framework.mapped.MappedConfigLoader; + +import java.nio.file.Path; +import java.util.function.Supplier; + +public class BaseConfigManager { + + protected final Path rootDataFolder; + + public BaseConfigManager(Path rootDataFolder) { + this.rootDataFolder = rootDataFolder; + } + + public Path getRootDataFolder() { + return rootDataFolder; + } + + public ConfigLoader getConfigLoader(String fileName) { + return getConfigLoader(rootDataFolder.resolve(fileName)); + } + + public ConfigLoader getConfigLoader(Path configPath) { + return new ConfigLoader(rootDataFolder, configPath); + } + + public MappedConfigLoader getMappedConfigLoader(String fileName, Supplier mappedObjectConstructor) { + return getMappedConfigLoader(rootDataFolder.resolve(fileName), mappedObjectConstructor); + } + + public MappedConfigLoader getMappedConfigLoader(Path configPath, Supplier mappedObjectConstructor) { + return new MappedConfigLoader<>(rootDataFolder, configPath, mappedObjectConstructor); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/Config.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java similarity index 73% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/Config.java rename to Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java index b8d43f7..8460851 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/Config.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config; +package me.filoghost.chestcommands.config.framework; import org.bukkit.configuration.file.YamlConfiguration; @@ -21,16 +21,20 @@ import java.nio.file.Path; public class Config extends ConfigSection { private final YamlConfiguration yaml; - private final Path filePath; + private final Path sourceFilePath; - public Config(YamlConfiguration yaml, Path filePath) { - super(yaml); - this.yaml = yaml; - this.filePath = filePath; + public Config(Path sourceFilePath) { + this(new YamlConfiguration(), sourceFilePath); } - public String getFileName() { - return filePath.getFileName().toString(); + public Config(YamlConfiguration yaml, Path sourceFilePath) { + super(yaml); + this.yaml = yaml; + this.sourceFilePath = sourceFilePath; + } + + public String getSourceFileName() { + return sourceFilePath.getFileName().toString(); } public String saveToString() { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java new file mode 100644 index 0000000..66006a2 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java @@ -0,0 +1,143 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework; + +import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; +import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; +import me.filoghost.chestcommands.config.framework.exception.ConfigSyntaxException; +import me.filoghost.chestcommands.util.Preconditions; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +public class ConfigLoader { + + private final Path rootDataFolder; + private final Path configPath; + + public ConfigLoader(Path rootDataFolder, Path configPath) { + Preconditions.checkArgument(configPath.startsWith(rootDataFolder), "config file " + configPath + " cannot be outside " + rootDataFolder); + + this.rootDataFolder = rootDataFolder; + this.configPath = configPath; + } + + public Config init() throws ConfigSaveException, ConfigLoadException { + createDefault(); + return load(); + } + + public void createDefault() throws ConfigSaveException { + if (fileExists()) { + return; + } + + createParentDirectory(); + + Path relativeConfigPath = rootDataFolder.relativize(configPath); + String internalJarPath = toInternalJarPath(relativeConfigPath); + + try (InputStream defaultFile = getInternalResource(internalJarPath)) { + if (defaultFile != null) { + Files.copy(defaultFile, configPath); + } else { + Files.createFile(configPath); + } + } catch (IOException e) { + throw new ConfigSaveException("couldn't create default config file " + configPath, e); + } + } + + private String toInternalJarPath(Path path) { + return StreamSupport.stream(path.spliterator(), false) + .map(Path::toString) + .collect(Collectors.joining("/", "/", "")); + } + + + private InputStream getInternalResource(String internalJarPath) throws IOException { + Preconditions.notNull(internalJarPath, "internalJarPath"); + + URL resourceURL = getClass().getResource(internalJarPath); + if (resourceURL == null) { + return null; + } + + URLConnection connection = resourceURL.openConnection(); + connection.setUseCaches(false); + return connection.getInputStream(); + } + + public boolean fileExists() { + return (Files.isRegularFile(configPath)); + } + + public Config load() throws ConfigLoadException { + Preconditions.checkState(fileExists(), configPath.getFileName() + " doesn't exist or is not a regular file"); + + YamlConfiguration yaml = new YamlConfiguration(); + + try (BufferedReader reader = Files.newBufferedReader(configPath)) { + yaml.load(reader); + } catch (IOException e) { + throw new ConfigLoadException("couldn't read config file " + configPath, e); + } catch (InvalidConfigurationException e) { + throw new ConfigSyntaxException(e.getMessage(), e); + } + + return new Config(yaml, configPath); + } + + public void save(Config config) throws ConfigSaveException { + createParentDirectory(); + + String data = config.saveToString(); + + try (BufferedWriter writer = Files.newBufferedWriter(configPath)) { + writer.write(data); + } catch (IOException e) { + throw new ConfigSaveException("couldn't write config data to " + configPath, e); + } + } + + private void createParentDirectory() throws ConfigSaveException { + if (configPath.getParent() != null) { + try { + Files.createDirectories(configPath.getParent()); + } catch (IOException e) { + throw new ConfigSaveException("couldn't create directory " + configPath.getParent(), e); + } + } + } + + public Path getConfigPath() { + return configPath; + } + + public String getFileName() { + return configPath.getFileName().toString(); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigSection.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java similarity index 91% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigSection.java rename to Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java index 1e6fe77..70e5ab0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigSection.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java @@ -1,5 +1,6 @@ -package me.filoghost.chestcommands.config; +package me.filoghost.chestcommands.config.framework; +import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; import org.bukkit.configuration.ConfigurationSection; import java.util.ArrayList; @@ -75,10 +76,6 @@ public class ConfigSection { return yamlSection.getKeys(deep); } - public boolean contains(String path) { - return yamlSection.contains(path); - } - public boolean isSet(String path) { return yamlSection.isSet(path); } @@ -91,10 +88,6 @@ public class ConfigSection { return yamlSection.getString(path); } - public String getString(String path, String def) { - return yamlSection.getString(path, def); - } - public int getInt(String path) { return yamlSection.getInt(path); } @@ -107,10 +100,6 @@ public class ConfigSection { return yamlSection.getDouble(path); } - public long getLong(String path) { - return yamlSection.getLong(path); - } - public List getStringList(String path) { return yamlSection.getStringList(path); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigException.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigException.java new file mode 100644 index 0000000..5dd6b05 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigException.java @@ -0,0 +1,13 @@ +package me.filoghost.chestcommands.config.framework.exception; + +public class ConfigException extends Exception { + + public ConfigException(String message) { + super(message); + } + + public ConfigException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigLoadException.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigLoadException.java new file mode 100644 index 0000000..c145072 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigLoadException.java @@ -0,0 +1,9 @@ +package me.filoghost.chestcommands.config.framework.exception; + +public class ConfigLoadException extends ConfigException { + + public ConfigLoadException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSaveException.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSaveException.java new file mode 100644 index 0000000..de64ce1 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSaveException.java @@ -0,0 +1,9 @@ +package me.filoghost.chestcommands.config.framework.exception; + +public class ConfigSaveException extends ConfigException { + + public ConfigSaveException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSyntaxException.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSyntaxException.java new file mode 100644 index 0000000..5f868c0 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSyntaxException.java @@ -0,0 +1,11 @@ +package me.filoghost.chestcommands.config.framework.exception; + +import org.bukkit.configuration.InvalidConfigurationException; + +public class ConfigSyntaxException extends ConfigLoadException { + + public ConfigSyntaxException(String message, InvalidConfigurationException cause) { + super(message, cause); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigValueException.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigValueException.java new file mode 100644 index 0000000..2a484b6 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigValueException.java @@ -0,0 +1,9 @@ +package me.filoghost.chestcommands.config.framework.exception; + +public class ConfigValueException extends ConfigException { + + public ConfigValueException(String message) { + super(message); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/ConfigMapper.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/ConfigMapper.java new file mode 100644 index 0000000..686f35a --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/ConfigMapper.java @@ -0,0 +1,157 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework.mapped; + +import com.google.common.collect.ImmutableList; +import me.filoghost.chestcommands.config.framework.ConfigSection; +import me.filoghost.chestcommands.config.framework.mapped.converter.BooleanConverter; +import me.filoghost.chestcommands.config.framework.mapped.converter.Converter; +import me.filoghost.chestcommands.config.framework.mapped.converter.DoubleConverter; +import me.filoghost.chestcommands.config.framework.mapped.converter.IntegerConverter; +import me.filoghost.chestcommands.config.framework.mapped.converter.ListConverter; +import me.filoghost.chestcommands.config.framework.mapped.converter.StringConverter; +import me.filoghost.chestcommands.config.framework.mapped.modifier.ChatColorsModifier; +import me.filoghost.chestcommands.config.framework.mapped.modifier.ValueModifier; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.lang.reflect.Type; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +public class ConfigMapper { + + private static final List CONVERTERS = ImmutableList.of( + new DoubleConverter(), + new IntegerConverter(), + new BooleanConverter(), + new StringConverter(), + new ListConverter() + ); + + private static final List> VALUE_MODIFIERS = ImmutableList.of( + new ChatColorsModifier() + ); + + private final MappedConfig mappedObject; + private final ConfigSection config; + private final List mappedFields; + + public ConfigMapper(MappedConfig mappedObject, ConfigSection config) throws ReflectiveOperationException { + this.mappedObject = mappedObject; + this.config = config; + this.mappedFields = getMappableFields(mappedObject.getClass()); + } + + private List getMappableFields(Class type) throws ReflectiveOperationException { + Field[] declaredFields; + + try { + declaredFields = type.getDeclaredFields(); + } catch (Throwable t) { + throw new ReflectiveOperationException(t); + } + + return Arrays.stream(declaredFields) + .filter(this::isMappable) + .map(MappedField::new) + .collect(Collectors.toList()); + } + + public Map getFieldValues() throws ReflectiveOperationException { + Map mappedFieldValues = new HashMap<>(); + + for (MappedField mappedField : mappedFields) { + Object defaultValue = mappedField.getFromObject(mappedObject); + + if (defaultValue == null) { + throw new IllegalArgumentException("mapped field \"" + mappedField.getFieldName() + "\" cannot be null by default"); + } + + mappedFieldValues.put(mappedField, defaultValue); + } + + return mappedFieldValues; + } + + public boolean addMissingConfigValues(Map defaultValues) { + boolean modified = false; + + // Add missing values from defaults + for (Entry entry : defaultValues.entrySet()) { + MappedField mappedField = entry.getKey(); + Object defaultValue = entry.getValue(); + + if (!config.isSet(mappedField.getConfigPath())) { + modified = true; + Converter converter = findConverter(mappedField.getFieldType()); + converter.setConfigValue(config, mappedField.getConfigPath(), defaultValue); + } + } + + return modified; + } + + public void injectObjectFields() throws ReflectiveOperationException { + for (MappedField mappedField : mappedFields) { + injectObjectField(mappedField); + } + } + + private void injectObjectField(MappedField mappedField) throws ReflectiveOperationException { + Type[] genericTypes = mappedField.getGenericTypes(); + Converter converter = findConverter(mappedField.getFieldType()); + + Object fieldValue = converter.getFieldValue(config, mappedField.getConfigPath(), genericTypes); + + for (Annotation annotation : mappedField.getAnnotations()) { + fieldValue = applyValueModifiers(fieldValue, annotation); + } + + mappedField.setToObject(mappedObject, fieldValue); + } + + private Object applyValueModifiers(Object fieldValue, Annotation annotation) { + for (ValueModifier modifier : VALUE_MODIFIERS) { + if (modifier.isApplicable(annotation, fieldValue)) { + fieldValue = modifier.transform(annotation, fieldValue); + } + } + return fieldValue; + } + + private Converter findConverter(Class type) { + return CONVERTERS.stream() + .filter(converter -> converter.matches(type)) + .findFirst() + .orElseThrow(() -> new IllegalStateException("cannot find converter for type " + type)); + } + + private boolean isMappable(Field field) { + int modifiers = field.getModifiers(); + boolean includeStatic = field.isAnnotationPresent(IncludeStatic.class) + || field.getDeclaringClass().isAnnotationPresent(IncludeStatic.class); + + return (!Modifier.isStatic(modifiers) || includeStatic) + || !Modifier.isTransient(modifiers) + || !Modifier.isFinal(modifiers); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/IncludeStatic.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/IncludeStatic.java new file mode 100644 index 0000000..c90b557 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/IncludeStatic.java @@ -0,0 +1,26 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework.mapped; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD, ElementType.TYPE}) +public @interface IncludeStatic { + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfig.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfig.java new file mode 100644 index 0000000..e97b425 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfig.java @@ -0,0 +1,33 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework.mapped; + +import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; + +public class MappedConfig { + + private String header; + + protected void setHeader(String... header) { + this.header = String.join("\n", header) + "\n"; + } + + public String getHeader() { + return header; + } + + public void postLoad() throws ConfigLoadException {} + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java new file mode 100644 index 0000000..fd3208f --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java @@ -0,0 +1,78 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework.mapped; + +import me.filoghost.chestcommands.config.framework.Config; +import me.filoghost.chestcommands.config.framework.ConfigLoader; +import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; +import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; + +import java.nio.file.Path; +import java.util.Map; +import java.util.function.Supplier; + +public class MappedConfigLoader { + + private final ConfigLoader configLoader; + private final Supplier mappedObjectConstructor; + private Map defaultValues; + + public MappedConfigLoader(Path rootDataFolder, Path configPath, Supplier mappedObjectConstructor) { + this.configLoader = new ConfigLoader(rootDataFolder, configPath); + this.mappedObjectConstructor = mappedObjectConstructor; + } + + public T init() throws ConfigLoadException, ConfigSaveException { + Config config = configLoader.init(); + T mappedObject = mappedObjectConstructor.get(); + + ConfigMapper mapper; + try { + mapper = new ConfigMapper(mappedObject, config); + } catch (ReflectiveOperationException e) { + throw new ConfigLoadException("couldn't initialize config mapper for class " + mappedObject.getClass(), e); + } + + // Extract default values from fields + if (defaultValues == null) { + try { + defaultValues = mapper.getFieldValues(); + } catch (ReflectiveOperationException e) { + throw new ConfigLoadException("couldn't read field values in class " + mappedObject.getClass(), e); + } + } + + // Add missing values and save if necessary + boolean modified = mapper.addMissingConfigValues(defaultValues); + if (modified) { + config.setHeader(mappedObject.getHeader()); + configLoader.save(config); + } + + // Update the mapped object with the contents from the config + try { + mapper.injectObjectFields(); + } catch (ReflectiveOperationException e) { + throw new ConfigLoadException("couldn't inject fields values in class " + mappedObject.getClass(), e); + } + mappedObject.postLoad(); + return mappedObject; + } + + public String getFileName() { + return configLoader.getFileName(); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedField.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedField.java new file mode 100644 index 0000000..d9370dc --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedField.java @@ -0,0 +1,88 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework.mapped; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class MappedField { + + private final Field field; + private final String configPath; + + public MappedField(Field field) { + this.field = field; + + this.configPath = field.getName() + .replace("__", ".") + .replace("_", "-"); + } + + public Object getFromObject(MappedConfig mappedObject) throws ReflectiveOperationException { + try { + field.setAccessible(true); + return field.get(mappedObject); + } catch (Throwable t) { + throw new ReflectiveOperationException(t); + } + } + + public void setToObject(MappedConfig mappedObject, Object fieldValue) throws ReflectiveOperationException { + try { + field.setAccessible(true); + field.set(mappedObject, fieldValue); + } catch (Throwable t) { + throw new ReflectiveOperationException(t); + } + } + + public Type[] getGenericTypes() throws ReflectiveOperationException { + try { + Type genericType = field.getGenericType(); + if (genericType instanceof ParameterizedType) { + return ((ParameterizedType) genericType).getActualTypeArguments(); + } else { + return null; + } + } catch (Throwable t) { + throw new ReflectiveOperationException(t); + } + } + + public List getAnnotations() { + return Stream.concat( + Arrays.stream(field.getDeclaredAnnotations()), + Arrays.stream(field.getDeclaringClass().getDeclaredAnnotations())) + .collect(Collectors.toList()); + } + + public String getFieldName() { + return field.getName(); + } + + public Class getFieldType() { + return field.getType(); + } + + public String getConfigPath() { + return configPath; + } +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/BooleanConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/BooleanConverter.java new file mode 100644 index 0000000..2960496 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/BooleanConverter.java @@ -0,0 +1,38 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework.mapped.converter; + +import me.filoghost.chestcommands.config.framework.ConfigSection; + +import java.lang.reflect.Type; + +public class BooleanConverter implements Converter { + + @Override + public void setConfigValue(ConfigSection config, String path, Object value) { + config.set(path, value); + } + + @Override + public Boolean getFieldValue(ConfigSection config, String path, Type[] parameterizedTypes) { + return config.getBoolean(path); + } + + @Override + public boolean matches(Class type) { + return type == Boolean.class || type == boolean.class; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/Converter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/Converter.java new file mode 100644 index 0000000..df0e921 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/Converter.java @@ -0,0 +1,29 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework.mapped.converter; + +import me.filoghost.chestcommands.config.framework.ConfigSection; + +import java.lang.reflect.Type; + +public interface Converter { + + void setConfigValue(ConfigSection config, String path, Object value); + + Object getFieldValue(ConfigSection config, String path, Type[] genericTypes); + + boolean matches(Class type); + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/DoubleConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/DoubleConverter.java new file mode 100644 index 0000000..e6c9ffc --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/DoubleConverter.java @@ -0,0 +1,38 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework.mapped.converter; + +import me.filoghost.chestcommands.config.framework.ConfigSection; + +import java.lang.reflect.Type; + +public class DoubleConverter implements Converter { + + @Override + public void setConfigValue(ConfigSection config, String path, Object value) { + config.set(path, value); + } + + @Override + public Double getFieldValue(ConfigSection config, String path, Type[] parameterizedTypes) { + return config.getDouble(path); + } + + @Override + public boolean matches(Class type) { + return type == Double.class || type == double.class; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/IntegerConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/IntegerConverter.java new file mode 100644 index 0000000..47ac621 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/IntegerConverter.java @@ -0,0 +1,38 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework.mapped.converter; + +import me.filoghost.chestcommands.config.framework.ConfigSection; + +import java.lang.reflect.Type; + +public class IntegerConverter implements Converter { + + @Override + public void setConfigValue(ConfigSection config, String path, Object value) { + config.set(path, value); + } + + @Override + public Integer getFieldValue(ConfigSection config, String path, Type[] parameterizedTypes) { + return config.getInt(path); + } + + @Override + public boolean matches(Class type) { + return type == Integer.class || type == int.class; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/ListConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/ListConverter.java new file mode 100644 index 0000000..99ca844 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/ListConverter.java @@ -0,0 +1,51 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework.mapped.converter; + +import me.filoghost.chestcommands.config.framework.ConfigSection; +import me.filoghost.chestcommands.util.Preconditions; + +import java.lang.reflect.Type; +import java.util.List; + +public class ListConverter implements Converter { + + @Override + public void setConfigValue(ConfigSection config, String path, Object value) { + config.set(path, value); + } + + @Override + public List getFieldValue(ConfigSection config, String path, Type[] genericTypes) { + Preconditions.notNull(genericTypes, "genericTypes"); + Preconditions.checkArgument(genericTypes.length == 1, "genericTypes length must be 1"); + + Type listType = genericTypes[0]; + + if (listType == Integer.class) { + return config.getIntegerList(path); + } else if (listType == String.class) { + return config.getStringList(path); + } else { + throw new IllegalArgumentException("unsupported list type: " + listType); + } + } + + @Override + public boolean matches(Class type) { + return type == List.class; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/StringConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/StringConverter.java new file mode 100644 index 0000000..422dcbd --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/StringConverter.java @@ -0,0 +1,38 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework.mapped.converter; + +import me.filoghost.chestcommands.config.framework.ConfigSection; + +import java.lang.reflect.Type; + +public class StringConverter implements Converter { + + @Override + public void setConfigValue(ConfigSection config, String path, Object value) { + config.set(path, value); + } + + @Override + public String getFieldValue(ConfigSection config, String path, Type[] parameterizedTypes) { + return config.getString(path); + } + + @Override + public boolean matches(Class type) { + return type == String.class; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColors.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColors.java new file mode 100644 index 0000000..7a8034e --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColors.java @@ -0,0 +1,26 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework.mapped.modifier; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD, ElementType.TYPE}) +public @interface ChatColors { + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColorsModifier.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColorsModifier.java new file mode 100644 index 0000000..18f65cd --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColorsModifier.java @@ -0,0 +1,36 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework.mapped.modifier; + +import me.filoghost.chestcommands.util.Colors; + +public class ChatColorsModifier implements ValueModifier { + + @Override + public String transformChecked(ChatColors annotation, String value) { + return Colors.addColors(value); + } + + @Override + public Class getAnnotationType() { + return ChatColors.class; + } + + @Override + public Class getValueType() { + return String.class; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ValueModifier.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ValueModifier.java new file mode 100644 index 0000000..1925f7a --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ValueModifier.java @@ -0,0 +1,38 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework.mapped.modifier; + +import me.filoghost.chestcommands.util.Preconditions; + +import java.lang.annotation.Annotation; + +public interface ValueModifier { + + V transformChecked(A annotation, V value); + + Class getAnnotationType(); + + Class getValueType(); + + default boolean isApplicable(Annotation annotation, Object value) { + return getAnnotationType().isInstance(annotation) && getValueType().isInstance(value); + } + + default Object transform(Annotation annotation, Object fieldValue) { + Preconditions.checkArgument(isApplicable(annotation, fieldValue), "modifier doesn't match given types"); + + return transformChecked(getAnnotationType().cast(annotation), getValueType().cast(fieldValue)); + } +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java index dad391f..ee45a69 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java @@ -14,10 +14,9 @@ */ package me.filoghost.chestcommands.legacy; -import me.filoghost.chestcommands.config.Config; -import me.filoghost.chestcommands.config.ConfigLoader; +import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; +import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; import me.filoghost.chestcommands.util.Preconditions; -import org.bukkit.configuration.InvalidConfigurationException; import java.io.IOException; import java.nio.file.Files; @@ -40,7 +39,11 @@ public abstract class Upgrade { Preconditions.checkState(!hasRun, "Upgrade can only be run once"); hasRun = true; - computeChanges(); + try { + computeChanges(); + } catch (ConfigLoadException e) { + throw new UpgradeException("couldn't load file to upgrade \"" + getOriginalFile().getFileName() + "\"", e); + } if (modified) { try { @@ -51,7 +54,7 @@ public abstract class Upgrade { try { saveChanges(); - } catch (IOException e) { + } catch (ConfigSaveException e) { throw new UpgradeException("couldn't save upgraded file \"" + getUpgradedFile().getFileName() + "\"", e); } } @@ -59,16 +62,6 @@ public abstract class Upgrade { return modified; } - protected Config loadConfig(ConfigLoader configLoader) throws UpgradeException { - try { - return configLoader.load(); - } catch (IOException e) { - throw new UpgradeException("couldn't read configuration file \"" + configLoader.getFileName() + "\"", e); - } catch (InvalidConfigurationException e) { - throw new UpgradeException("couldn't parse YAML syntax of file \"" + configLoader.getFileName() + "\"", e); - } - } - private void createBackupFile(Path path) throws IOException { String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy.MM.dd-HH.mm")); String backupName = path.getFileName() + "_" + date + ".backup"; @@ -80,8 +73,8 @@ public abstract class Upgrade { public abstract Path getUpgradedFile(); - protected abstract void computeChanges() throws UpgradeException; + protected abstract void computeChanges() throws ConfigLoadException; - protected abstract void saveChanges() throws IOException; + protected abstract void saveChanges() throws ConfigSaveException; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java index f49d0fa..f2a54bd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java @@ -15,7 +15,7 @@ package me.filoghost.chestcommands.legacy; import me.filoghost.chestcommands.config.ConfigManager; -import me.filoghost.chestcommands.config.ConfigLoader; +import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.legacy.UpgradesDoneRegistry.UpgradeID; import me.filoghost.chestcommands.legacy.upgrades.MenuUpgrade; import me.filoghost.chestcommands.legacy.upgrades.PlaceholdersUpgrade; @@ -42,7 +42,7 @@ public class UpgradesExecutor { public void run(boolean isFreshInstall) throws UpgradeExecutorException { this.failedUpgrades = new ArrayList<>(); - Path upgradesDoneFile = configManager.getBaseDataPath().resolve(".upgrades-done"); + Path upgradesDoneFile = configManager.getRootDataFolder().resolve(".upgrades-done"); try { upgradesDoneRegistry = new UpgradesDoneRegistry(upgradesDoneFile); @@ -56,18 +56,23 @@ public class UpgradesExecutor { upgradesDoneRegistry.setAllDone(); } else { - String legacyCommandSeparator = readLegacyCommandSeparator(); + String legacyCommandSeparator; + if (!upgradesDoneRegistry.isDone(UpgradeID.V4_MENUS)) { + legacyCommandSeparator = readLegacyCommandSeparator(); + } else { + legacyCommandSeparator = null; + } - SettingsUpgrade settingsUpgrade = new SettingsUpgrade(configManager.getSettingsConfigLoader()); + SettingsUpgrade settingsUpgrade = new SettingsUpgrade(configManager); runIfNecessary(UpgradeID.V4_CONFIG, settingsUpgrade); - PlaceholdersUpgrade placeholdersUpgrade = new PlaceholdersUpgrade(configManager.getPlaceholdersConfigLoader(), configManager.getBaseDataPath()); + PlaceholdersUpgrade placeholdersUpgrade = new PlaceholdersUpgrade(configManager); runIfNecessary(UpgradeID.V4_PLACEHOLDERS, placeholdersUpgrade); try { List menuUpgrades = CollectionUtils.transform( configManager.getMenuPaths(), - menuPath -> new MenuUpgrade(new ConfigLoader(menuPath), legacyCommandSeparator)); + menuPath -> new MenuUpgrade(configManager.getConfigLoader(menuPath), legacyCommandSeparator)); runIfNecessary(UpgradeID.V4_MENUS, menuUpgrades); } catch (IOException e) { failedUpgrades.add(configManager.getMenusFolder()); @@ -91,18 +96,18 @@ public class UpgradesExecutor { } private String readLegacyCommandSeparator() { - String legacyCommandSeparator; - ConfigLoader settingsConfigLoader = configManager.getSettingsConfigLoader(); + ConfigLoader settingsConfigLoader = configManager.getConfigLoader("config.yml"); - try { - legacyCommandSeparator = settingsConfigLoader.load().getString("multiple-commands-separator", ";"); - } catch (Exception e) { - legacyCommandSeparator = ";"; - Log.severe("Failed to load " + settingsConfigLoader.getFileName() - + ", assuming default command separator \"" + legacyCommandSeparator + "\"."); + if (!settingsConfigLoader.fileExists()) { + return null; } - return legacyCommandSeparator; + try { + return settingsConfigLoader.load().getString("multiple-commands-separator"); + } catch (Throwable t) { + Log.severe("Failed to load " + settingsConfigLoader.getFileName() + ", assuming default command separator \";\"."); + return null; + } } @@ -143,8 +148,7 @@ public class UpgradesExecutor { private void logUpgradeException(Upgrade upgrade, UpgradeException upgradeException) { Log.severe( - "Error while trying to automatically upgrade " - + upgrade.getOriginalFile() + ": " + upgradeException.getMessage(), + "Error while trying to automatically upgrade " + upgrade.getOriginalFile() + ": " + upgradeException.getMessage(), upgradeException.getCause()); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/MenuUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/MenuUpgrade.java index 14e3f97..e37f38d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/MenuUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/MenuUpgrade.java @@ -14,16 +14,16 @@ */ package me.filoghost.chestcommands.legacy.upgrades; -import me.filoghost.chestcommands.config.Config; -import me.filoghost.chestcommands.config.ConfigLoader; -import me.filoghost.chestcommands.config.ConfigSection; +import me.filoghost.chestcommands.config.framework.Config; +import me.filoghost.chestcommands.config.framework.ConfigLoader; +import me.filoghost.chestcommands.config.framework.ConfigSection; +import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; +import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; import me.filoghost.chestcommands.legacy.Upgrade; -import me.filoghost.chestcommands.legacy.UpgradeException; -import me.filoghost.chestcommands.parsing.menu.MenuSettingsNode; import me.filoghost.chestcommands.parsing.icon.IconSettingsNode; +import me.filoghost.chestcommands.parsing.menu.MenuSettingsNode; import me.filoghost.chestcommands.util.Strings; -import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; @@ -43,17 +43,17 @@ public class MenuUpgrade extends Upgrade { @Override public Path getOriginalFile() { - return menuConfigLoader.getPath(); + return menuConfigLoader.getConfigPath(); } @Override public Path getUpgradedFile() { - return menuConfigLoader.getPath(); + return menuConfigLoader.getConfigPath(); } @Override - protected void computeChanges() throws UpgradeException { - Config menuConfig = loadConfig(menuConfigLoader); + protected void computeChanges() throws ConfigLoadException { + Config menuConfig = menuConfigLoader.load(); menuConfig.setHeader(null); for (String key : menuConfig.getKeys(true)) { @@ -74,7 +74,7 @@ public class MenuUpgrade extends Upgrade { } @Override - protected void saveChanges() throws IOException { + protected void saveChanges() throws ConfigSaveException { menuConfigLoader.save(updatedConfig); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/PlaceholdersUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/PlaceholdersUpgrade.java index 1d5abbc..9f0142e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/PlaceholdersUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/PlaceholdersUpgrade.java @@ -14,10 +14,12 @@ */ package me.filoghost.chestcommands.legacy.upgrades; -import me.filoghost.chestcommands.config.Config; -import me.filoghost.chestcommands.config.ConfigLoader; +import me.filoghost.chestcommands.config.ConfigManager; +import me.filoghost.chestcommands.config.framework.Config; +import me.filoghost.chestcommands.config.framework.ConfigLoader; +import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; +import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; import me.filoghost.chestcommands.legacy.Upgrade; -import me.filoghost.chestcommands.legacy.UpgradeException; import me.filoghost.chestcommands.util.Strings; import org.apache.commons.lang.StringEscapeUtils; @@ -28,13 +30,13 @@ import java.util.List; public class PlaceholdersUpgrade extends Upgrade { - private final ConfigLoader newPlaceholdersConfigLoader; private final Path oldPlaceholdersFile; + private final ConfigLoader newPlaceholdersConfigLoader; private Config updatedConfig; - public PlaceholdersUpgrade(ConfigLoader placeholdersConfigLoader, Path dataPath) { - this.newPlaceholdersConfigLoader = placeholdersConfigLoader; - this.oldPlaceholdersFile = dataPath.resolve("placeholders.yml"); + public PlaceholdersUpgrade(ConfigManager configManager) { + this.oldPlaceholdersFile = configManager.getRootDataFolder().resolve("placeholders.yml"); + this.newPlaceholdersConfigLoader = configManager.getConfigLoader("custom-placeholders.yml"); } @Override @@ -44,22 +46,22 @@ public class PlaceholdersUpgrade extends Upgrade { @Override public Path getUpgradedFile() { - return newPlaceholdersConfigLoader.getPath(); + return newPlaceholdersConfigLoader.getConfigPath(); } @Override - protected void computeChanges() throws UpgradeException { + protected void computeChanges() throws ConfigLoadException { if (!Files.isRegularFile(oldPlaceholdersFile)) { return; } // Do NOT load the new placeholder configuration from disk, as it should only contain placeholders imported from the old file - Config newPlaceholdersConfig = newPlaceholdersConfigLoader.loadEmpty(); + Config newPlaceholdersConfig = new Config(newPlaceholdersConfigLoader.getConfigPath()); List lines; try { lines = Files.readAllLines(oldPlaceholdersFile); } catch (IOException e) { - throw new UpgradeException("couldn't read file \"" + oldPlaceholdersFile.getFileName() + "\"", e); + throw new ConfigLoadException("couldn't read file \"" + oldPlaceholdersFile.getFileName() + "\"", e); } for (String line : lines) { @@ -85,7 +87,7 @@ public class PlaceholdersUpgrade extends Upgrade { } @Override - protected void saveChanges() throws IOException { + protected void saveChanges() throws ConfigSaveException { try { Files.deleteIfExists(oldPlaceholdersFile); } catch (IOException ignored) {} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/SettingsUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/SettingsUpgrade.java index b70596a..c3dc2bf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/SettingsUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/SettingsUpgrade.java @@ -14,12 +14,13 @@ */ package me.filoghost.chestcommands.legacy.upgrades; -import me.filoghost.chestcommands.config.Config; -import me.filoghost.chestcommands.config.ConfigLoader; +import me.filoghost.chestcommands.config.ConfigManager; +import me.filoghost.chestcommands.config.framework.Config; +import me.filoghost.chestcommands.config.framework.ConfigLoader; +import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; +import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; import me.filoghost.chestcommands.legacy.Upgrade; -import me.filoghost.chestcommands.legacy.UpgradeException; -import java.io.IOException; import java.nio.file.Path; public class SettingsUpgrade extends Upgrade { @@ -27,23 +28,23 @@ public class SettingsUpgrade extends Upgrade { private final ConfigLoader settingsConfigLoader; private Config updatedConfig; - public SettingsUpgrade(ConfigLoader settingsConfigLoader) { - this.settingsConfigLoader = settingsConfigLoader; + public SettingsUpgrade(ConfigManager configManager) { + this.settingsConfigLoader = configManager.getConfigLoader("config.yml"); } @Override public Path getOriginalFile() { - return settingsConfigLoader.getPath(); + return settingsConfigLoader.getConfigPath(); } @Override public Path getUpgradedFile() { - return settingsConfigLoader.getPath(); + return settingsConfigLoader.getConfigPath(); } @Override - protected void computeChanges() throws UpgradeException { - Config settingsConfig = loadConfig(settingsConfigLoader); + protected void computeChanges() throws ConfigLoadException { + Config settingsConfig = settingsConfigLoader.load(); removeNode(settingsConfig, "use-only-commands-without-args"); removeNode(settingsConfig, "use-console-colors"); @@ -61,7 +62,7 @@ public class SettingsUpgrade extends Upgrade { @Override - protected void saveChanges() throws IOException { + protected void saveChanges() throws ConfigSaveException { settingsConfigLoader.save(updatedConfig); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ErrorFormat.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ErrorFormat.java index ccdfac8..7e3c86c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ErrorFormat.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ErrorFormat.java @@ -1,19 +1,20 @@ package me.filoghost.chestcommands.parsing; +import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.parsing.icon.IconSettings; public class ErrorFormat { - public static String invalidMenuSetting(String menuName, String invalidSetting, String errorMessage) { - return menuError(menuName, "has an invalid menu setting \"" + invalidSetting + "\": " + errorMessage); + public static String invalidMenuSetting(Config menuConfig, String invalidSetting, String errorMessage) { + return menuError(menuConfig, "has an invalid menu setting \"" + invalidSetting + "\": " + errorMessage); } - public static String missingMenuSetting(String menuName, String missingSetting) { - return menuError(menuName, "is missing the menu setting \"" + missingSetting + "\""); + public static String missingMenuSetting(Config menuConfig, String missingSetting) { + return menuError(menuConfig, "is missing the menu setting \"" + missingSetting + "\""); } - private static String menuError(String menuName, String errorMessage) { - return "The menu \"" + menuName + "\" " + errorMessage + "."; + private static String menuError(Config menuConfig, String errorMessage) { + return "The menu \"" + menuConfig.getSourceFileName() + "\" " + errorMessage + "."; } public static String invalidAttribute(IconSettings iconSettings, String attributeName, String errorMessage) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java index de7ef59..2d41e82 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java @@ -14,8 +14,8 @@ */ package me.filoghost.chestcommands.parsing.icon; -import me.filoghost.chestcommands.config.ConfigSection; -import me.filoghost.chestcommands.config.ConfigValueException; +import me.filoghost.chestcommands.config.framework.ConfigSection; +import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.chestcommands.parsing.icon.attributes.ActionsAttribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index c868437..7a25b4b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -15,11 +15,11 @@ package me.filoghost.chestcommands.parsing.menu; import me.filoghost.chestcommands.action.Action; -import me.filoghost.chestcommands.config.Config; -import me.filoghost.chestcommands.config.ConfigSection; -import me.filoghost.chestcommands.config.ConfigValueException; -import me.filoghost.chestcommands.menu.InternalIconMenu; +import me.filoghost.chestcommands.config.framework.Config; +import me.filoghost.chestcommands.config.framework.ConfigSection; +import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; +import me.filoghost.chestcommands.menu.InternalIconMenu; import me.filoghost.chestcommands.parsing.ActionParser; import me.filoghost.chestcommands.parsing.ErrorFormat; import me.filoghost.chestcommands.parsing.ItemStackParser; @@ -41,7 +41,7 @@ public class MenuParser { MenuSettings menuSettings = loadMenuSettings(menuConfig, errorCollector); List iconSettingsList = loadIconSettingsList(menuConfig, errorCollector); - InternalIconMenu iconMenu = new InternalIconMenu(menuSettings.getTitle(), menuSettings.getRows(), menuConfig.getFileName()); + InternalIconMenu iconMenu = new InternalIconMenu(menuSettings.getTitle(), menuSettings.getRows(), menuConfig.getSourceFileName()); for (IconSettings iconSettings : iconSettingsList) { try { @@ -54,7 +54,7 @@ public class MenuParser { iconMenu.setRefreshTicks(menuSettings.getRefreshTicks()); iconMenu.setOpenActions(menuSettings.getOpenActions()); - return new LoadedMenu(iconMenu, menuConfig.getFileName(), menuSettings.getCommands(), menuSettings.getOpenTrigger()); + return new LoadedMenu(iconMenu, menuConfig.getSourceFileName(), menuSettings.getCommands(), menuSettings.getOpenTrigger()); } @@ -105,7 +105,7 @@ public class MenuParser { } } catch (ConfigValueException e) { title = ChatColor.DARK_RED + "No name set"; - errorCollector.addError(ErrorFormat.missingMenuSetting(config.getFileName(), MenuSettingsNode.NAME)); + errorCollector.addError(ErrorFormat.missingMenuSetting(config, MenuSettingsNode.NAME)); } int rows; @@ -116,7 +116,7 @@ public class MenuParser { } } catch (ConfigValueException e) { rows = 6; // Defaults to 6 rows - errorCollector.addError(ErrorFormat.missingMenuSetting(config.getFileName(), MenuSettingsNode.ROWS)); + errorCollector.addError(ErrorFormat.missingMenuSetting(config, MenuSettingsNode.ROWS)); } MenuSettings menuSettings = new MenuSettings(title, rows); @@ -157,7 +157,7 @@ public class MenuParser { menuSettings.setOpenTrigger(openTrigger); } catch (ParseException e) { - errorCollector.addError(ErrorFormat.invalidMenuSetting(config.getFileName(), MenuSettingsNode.OPEN_ITEM_MATERIAL, e.getMessage())); + errorCollector.addError(ErrorFormat.invalidMenuSetting(config, MenuSettingsNode.OPEN_ITEM_MATERIAL, e.getMessage())); } } } @@ -183,7 +183,7 @@ public class MenuParser { } ConfigSection iconSection = config.getConfigSection(iconSectionName); - IconSettings iconSettings = new IconSettings(config.getFileName(), iconSectionName); + IconSettings iconSettings = new IconSettings(config.getSourceFileName(), iconSectionName); iconSettings.loadFrom(iconSection, errorCollector); iconSettingsList.add(iconSettings); } diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java index 473c164..ead530c 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java @@ -14,10 +14,10 @@ */ package me.filoghost.chestcommands.util; -import java.util.Collection; - import org.bukkit.Material; +import java.util.Collection; + public final class Preconditions { private Preconditions() {} From 73ae9b45c0610c9f6d5a2e723c20f8c68c3db395 Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 10 Jul 2020 17:59:40 +0200 Subject: [PATCH 127/213] Add methods to ItemInventory --- .../filoghost/chestcommands/api/ItemInventory.java | 6 ++++++ .../inventory/DefaultItemInventory.java | 14 ++++++++++---- .../chestcommands/task/RefreshMenusTask.java | 4 ++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ItemInventory.java b/API/src/main/java/me/filoghost/chestcommands/api/ItemInventory.java index b00aa3d..7140f4b 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ItemInventory.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ItemInventory.java @@ -1,7 +1,13 @@ package me.filoghost.chestcommands.api; +import org.bukkit.entity.Player; + public interface ItemInventory { void refresh(); + Player getViewer(); + + IconMenu getIconMenu(); + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultItemInventory.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultItemInventory.java index e90bfc9..a4003bf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultItemInventory.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultItemInventory.java @@ -24,10 +24,6 @@ public class DefaultItemInventory implements ItemInventory { refresh(); } - public BaseIconMenu getMenu() { - return menu; - } - @Override public void refresh() { for (int i = 0; i < menu.getIcons().getSize(); i++) { @@ -61,6 +57,16 @@ public class DefaultItemInventory implements ItemInventory { return () -> icon.onClick(this, clicker); } + @Override + public BaseIconMenu getIconMenu() { + return menu; + } + + @Override + public Player getViewer() { + return viewer; + } + @FunctionalInterface public interface SlotClickHandler { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java index d0ebebb..8c2b042 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java @@ -29,11 +29,11 @@ public class RefreshMenusTask implements Runnable { for (Player player : Bukkit.getOnlinePlayers()) { DefaultItemInventory itemInventory = MenuManager.getOpenItemInventory(player); - if (itemInventory == null || !(itemInventory.getMenu() instanceof InternalIconMenu)) { + if (itemInventory == null || !(itemInventory.getIconMenu() instanceof InternalIconMenu)) { continue; } - int refreshTicks = ((InternalIconMenu) itemInventory.getMenu()).getRefreshTicks(); + int refreshTicks = ((InternalIconMenu) itemInventory.getIconMenu()).getRefreshTicks(); if (refreshTicks > 0 && currentTick % refreshTicks == 0) { itemInventory.refresh(); From 7ff586e3b372be0a95fed9351b9b13d937b56f49 Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 10 Jul 2020 19:01:47 +0200 Subject: [PATCH 128/213] Add method to refresh all open inventories of a menu --- .../java/me/filoghost/chestcommands/api/IconMenu.java | 2 ++ .../me/filoghost/chestcommands/menu/BaseIconMenu.java | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java index cb13596..06f18c7 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java @@ -42,4 +42,6 @@ public interface IconMenu { */ ItemInventory open(Player player); + void refreshOpenInventories(); + } \ No newline at end of file diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java index 7d0ce59..4b24ad7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java @@ -21,6 +21,7 @@ import me.filoghost.chestcommands.inventory.DefaultItemInventory; import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.collection.ArrayGrid; import me.filoghost.chestcommands.util.collection.Grid; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; public abstract class BaseIconMenu implements IconMenu { @@ -73,4 +74,13 @@ public abstract class BaseIconMenu implements IconMenu { return itemInventory; } + @Override + public void refreshOpenInventories() { + for (Player player : Bukkit.getOnlinePlayers()) { + DefaultItemInventory itemInventory = MenuManager.getOpenItemInventory(player); + if (itemInventory.getIconMenu() == this) { + itemInventory.refresh(); + } + } + } } From dd3e5aa89b61a00fada6abcffcb088084e9ebb9d Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 10 Jul 2020 20:15:56 +0200 Subject: [PATCH 129/213] Add ItemInventory to ClickHandler --- .../main/java/me/filoghost/chestcommands/api/ClickHandler.java | 2 +- .../main/java/me/filoghost/chestcommands/api/ClickableIcon.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java b/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java index 4aa8cb2..2a25802 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java @@ -23,6 +23,6 @@ public interface ClickHandler { * @param player the player that clicked on the inventory * @return true if the inventory should be closed, false otherwise */ - ClickResult onClick(Player player); + ClickResult onClick(ItemInventory itemInventory, Player player); } diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java b/API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java index a5f601b..5e4b37c 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java @@ -11,7 +11,7 @@ public interface ClickableIcon extends Icon { @Override default ClickResult onClick(ItemInventory itemInventory, Player clicker) { if (getClickHandler() != null) { - return getClickHandler().onClick(clicker); + return getClickHandler().onClick(itemInventory, clicker); } else { return ClickResult.KEEP_OPEN; } From d934242503f17f61e38ce749789826147a721e29 Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 10 Jul 2020 20:19:57 +0200 Subject: [PATCH 130/213] Add missing header --- .../config/framework/ConfigSection.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java index 70e5ab0..cbf55a1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.config.framework; import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; From 58fee17358eb8cda0268b9dbbfd6547a09d3c98a Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 10 Jul 2020 20:29:24 +0200 Subject: [PATCH 131/213] Only get top level sections for menu upgrades --- .../me/filoghost/chestcommands/legacy/upgrades/MenuUpgrade.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/MenuUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/MenuUpgrade.java index e37f38d..72f78ac 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/MenuUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/MenuUpgrade.java @@ -56,7 +56,7 @@ public class MenuUpgrade extends Upgrade { Config menuConfig = menuConfigLoader.load(); menuConfig.setHeader(null); - for (String key : menuConfig.getKeys(true)) { + for (String key : menuConfig.getKeys(false)) { if (!menuConfig.isConfigSection(key)) { continue; } From b60bba9aab7630bf07f53161e55150b7b38ccdda Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 10 Jul 2020 20:33:23 +0200 Subject: [PATCH 132/213] Remove utilities private constructors --- .../java/me/filoghost/chestcommands/util/MaterialsHelper.java | 3 +-- .../java/me/filoghost/chestcommands/util/Preconditions.java | 1 - .../src/main/java/me/filoghost/chestcommands/util/Strings.java | 2 -- .../chestcommands/util/collection/CollectionUtils.java | 1 - 4 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java b/Utils/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java index da2c039..2c32616 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java @@ -31,8 +31,7 @@ public final class MaterialsHelper { // Materials that are considered air (with 1.13+ compatibility) private static final Collection AIR_MATERIALS = getExistingMaterials("AIR", "CAVE_AIR", "VOID_AIR"); - private MaterialsHelper() {} - + @SuppressWarnings("deprecation") private static Registry initMaterialsRegistry() { Registry materialsRegistry = Registry.fromEnumValues(Material.class); diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java index ead530c..0032a1d 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java @@ -20,7 +20,6 @@ import java.util.Collection; public final class Preconditions { - private Preconditions() {} public static void notNull(Object object, String objectName) { if (object == null) { diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java index 075cfca..42c1ae7 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java @@ -16,8 +16,6 @@ package me.filoghost.chestcommands.util; public final class Strings { - private Strings() {} - public static String[] trimmedSplit(String input, String pattern) { return trimmedSplit(input, pattern, 0); diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java index f41a490..d6b01a1 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java @@ -23,7 +23,6 @@ import java.util.function.Function; public final class CollectionUtils { - private CollectionUtils() {} public static boolean isNullOrEmpty(Collection collection) { return collection == null || collection.isEmpty(); From 05cba09a49df354a4441b1932265a4e19cd3b595 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 11 Jul 2020 18:47:52 +0200 Subject: [PATCH 133/213] Add lang.yml upgrade --- .../legacy/RegexFileReplacer.java | 49 +++++++++++ .../legacy/UpgradesDoneRegistry.java | 3 +- .../legacy/UpgradesExecutor.java | 4 + .../legacy/upgrades/LangUpgrade.java | 29 +++++++ .../legacy/upgrades/RegexUpgrade.java | 87 +++++++++++++++++++ 5 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/RegexFileReplacer.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/LangUpgrade.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/RegexUpgrade.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/RegexFileReplacer.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/RegexFileReplacer.java new file mode 100644 index 0000000..42a7695 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/RegexFileReplacer.java @@ -0,0 +1,49 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.legacy; + +import java.util.List; +import java.util.function.Function; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +public class RegexFileReplacer { + + private final Pattern regex; + private final Function replaceCallback; + + public RegexFileReplacer(Pattern regex, Function replaceCallback) { + this.regex = regex; + this.replaceCallback = replaceCallback; + } + + public List replace(List lines) { + return lines.stream().map(this::replace).collect(Collectors.toList()); + } + + private String replace(String line) { + Matcher matcher = regex.matcher(line); + StringBuffer output = new StringBuffer(); + + while (matcher.find()) { + matcher.appendReplacement(output, replaceCallback.apply(matcher)); + } + matcher.appendTail(output); + + return output.toString(); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java index 5639b25..04b7614 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java @@ -75,7 +75,8 @@ public class UpgradesDoneRegistry { V4_MENUS("v4.0-menus"), V4_CONFIG("v4.0-config"), - V4_PLACEHOLDERS("v4.0-placeholders"); + V4_PLACEHOLDERS("v4.0-placeholders"), + V4_LANG("v4.0-lang"); private final String stringID; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java index f2a54bd..7566d34 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java @@ -17,6 +17,7 @@ package me.filoghost.chestcommands.legacy; import me.filoghost.chestcommands.config.ConfigManager; import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.legacy.UpgradesDoneRegistry.UpgradeID; +import me.filoghost.chestcommands.legacy.upgrades.LangUpgrade; import me.filoghost.chestcommands.legacy.upgrades.MenuUpgrade; import me.filoghost.chestcommands.legacy.upgrades.PlaceholdersUpgrade; import me.filoghost.chestcommands.legacy.upgrades.SettingsUpgrade; @@ -69,6 +70,9 @@ public class UpgradesExecutor { PlaceholdersUpgrade placeholdersUpgrade = new PlaceholdersUpgrade(configManager); runIfNecessary(UpgradeID.V4_PLACEHOLDERS, placeholdersUpgrade); + LangUpgrade langUpgrade = new LangUpgrade(configManager); + runIfNecessary(UpgradeID.V4_LANG, langUpgrade); + try { List menuUpgrades = CollectionUtils.transform( configManager.getMenuPaths(), diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/LangUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/LangUpgrade.java new file mode 100644 index 0000000..ce601e3 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/LangUpgrade.java @@ -0,0 +1,29 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.legacy.upgrades; + +import me.filoghost.chestcommands.config.ConfigManager; + +import java.util.regex.Pattern; + +public class LangUpgrade extends RegexUpgrade { + + public LangUpgrade(ConfigManager configManager) { + super(configManager.getRootDataFolder().resolve("lang.yml")); + + addRegexReplacer(Pattern.compile(Pattern.quote("{datavalue}")), matcher -> "{durability}"); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/RegexUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/RegexUpgrade.java new file mode 100644 index 0000000..30b7c3c --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/RegexUpgrade.java @@ -0,0 +1,87 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.legacy.upgrades; + +import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; +import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; +import me.filoghost.chestcommands.legacy.RegexFileReplacer; +import me.filoghost.chestcommands.legacy.Upgrade; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class RegexUpgrade extends Upgrade { + + private final Path file; + private List newContents; + private List replacers; + + public RegexUpgrade(Path file) { + this.file = file; + this.replacers = new ArrayList<>(); + } + + protected void addRegexReplacer(Pattern regex, Function replaceCallback) { + replacers.add(new RegexFileReplacer(regex, replaceCallback)); + } + + @Override + public Path getOriginalFile() { + return file; + } + + @Override + public Path getUpgradedFile() { + return file; + } + + @Override + protected void computeChanges() throws ConfigLoadException { + if (!Files.isRegularFile(file)) { + return; + } + + List lines; + try { + lines = Files.readAllLines(file); + } catch (IOException e) { + throw new ConfigLoadException("couldn't read file \"" + file.getFileName() + "\"", e); + } + + for (RegexFileReplacer replacer : replacers) { + newContents = replacer.replace(lines); + } + + if (!newContents.equals(lines)) { + setModified(); + } + } + + @Override + protected void saveChanges() throws ConfigSaveException { + try { + Files.write(file, newContents); + } catch (IOException e) { + throw new ConfigSaveException("couldn't save file \"" + file.getFileName() + "\"", e); + } + } + +} From 556ef481a225ca98909822a63465ce6bb7ec68b8 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 12 Jul 2020 10:40:51 +0200 Subject: [PATCH 134/213] Improve menu upgrades --- ...exFileReplacer.java => RegexReplacer.java} | 14 ++---- .../legacy/UpgradesDoneRegistry.java | 3 +- .../legacy/UpgradesExecutor.java | 50 +++++++++++-------- .../{upgrades => upgrade}/LangUpgrade.java | 2 +- .../MenuNodeExpandUpgrade.java} | 30 ++--------- .../legacy/upgrade/MenuNodeRenameUpgrade.java | 47 +++++++++++++++++ .../PlaceholdersYamlUpgrade.java} | 7 ++- .../{upgrades => upgrade}/RegexUpgrade.java | 18 ++++--- .../SettingsUpgrade.java | 3 +- .../legacy/{ => upgrade}/Upgrade.java | 2 +- .../{ => upgrade}/UpgradeException.java | 2 +- 11 files changed, 105 insertions(+), 73 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/{RegexFileReplacer.java => RegexReplacer.java} (77%) rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/{upgrades => upgrade}/LangUpgrade.java (95%) rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/{upgrades/MenuUpgrade.java => upgrade/MenuNodeExpandUpgrade.java} (80%) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgrade.java rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/{upgrades/PlaceholdersUpgrade.java => upgrade/PlaceholdersYamlUpgrade.java} (94%) rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/{upgrades => upgrade}/RegexUpgrade.java (81%) rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/{upgrades => upgrade}/SettingsUpgrade.java (95%) rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/{ => upgrade}/Upgrade.java (98%) rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/{ => upgrade}/UpgradeException.java (94%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/RegexFileReplacer.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/RegexReplacer.java similarity index 77% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/RegexFileReplacer.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/RegexReplacer.java index 42a7695..ef94b64 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/RegexFileReplacer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/RegexReplacer.java @@ -14,27 +14,22 @@ */ package me.filoghost.chestcommands.legacy; -import java.util.List; import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; -public class RegexFileReplacer { +public class RegexReplacer implements Function { private final Pattern regex; private final Function replaceCallback; - public RegexFileReplacer(Pattern regex, Function replaceCallback) { + public RegexReplacer(Pattern regex, Function replaceCallback) { this.regex = regex; this.replaceCallback = replaceCallback; } - public List replace(List lines) { - return lines.stream().map(this::replace).collect(Collectors.toList()); - } - - private String replace(String line) { + @Override + public String apply(String line) { Matcher matcher = regex.matcher(line); StringBuffer output = new StringBuffer(); @@ -45,5 +40,4 @@ public class RegexFileReplacer { return output.toString(); } - } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java index 04b7614..f9a822b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java @@ -73,7 +73,8 @@ public class UpgradesDoneRegistry { public enum UpgradeID { - V4_MENUS("v4.0-menus"), + V4_MENU_REPLACE("v4.0-menus-rename"), + V4_MENUS_REFORMAT("v4.0-menus-reformat"), V4_CONFIG("v4.0-config"), V4_PLACEHOLDERS("v4.0-placeholders"), V4_LANG("v4.0-lang"); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java index 7566d34..3fdfdc2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java @@ -17,10 +17,13 @@ package me.filoghost.chestcommands.legacy; import me.filoghost.chestcommands.config.ConfigManager; import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.legacy.UpgradesDoneRegistry.UpgradeID; -import me.filoghost.chestcommands.legacy.upgrades.LangUpgrade; -import me.filoghost.chestcommands.legacy.upgrades.MenuUpgrade; -import me.filoghost.chestcommands.legacy.upgrades.PlaceholdersUpgrade; -import me.filoghost.chestcommands.legacy.upgrades.SettingsUpgrade; +import me.filoghost.chestcommands.legacy.upgrade.LangUpgrade; +import me.filoghost.chestcommands.legacy.upgrade.MenuNodeExpandUpgrade; +import me.filoghost.chestcommands.legacy.upgrade.MenuNodeRenameUpgrade; +import me.filoghost.chestcommands.legacy.upgrade.PlaceholdersYamlUpgrade; +import me.filoghost.chestcommands.legacy.upgrade.SettingsUpgrade; +import me.filoghost.chestcommands.legacy.upgrade.Upgrade; +import me.filoghost.chestcommands.legacy.upgrade.UpgradeException; import me.filoghost.chestcommands.util.Log; import me.filoghost.chestcommands.util.collection.CollectionUtils; @@ -29,6 +32,7 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.function.Supplier; import java.util.stream.Collectors; public class UpgradesExecutor { @@ -58,27 +62,31 @@ public class UpgradesExecutor { } else { String legacyCommandSeparator; - if (!upgradesDoneRegistry.isDone(UpgradeID.V4_MENUS)) { + if (!upgradesDoneRegistry.isDone(UpgradeID.V4_MENUS_REFORMAT)) { legacyCommandSeparator = readLegacyCommandSeparator(); } else { legacyCommandSeparator = null; } - SettingsUpgrade settingsUpgrade = new SettingsUpgrade(configManager); - runIfNecessary(UpgradeID.V4_CONFIG, settingsUpgrade); - - PlaceholdersUpgrade placeholdersUpgrade = new PlaceholdersUpgrade(configManager); - runIfNecessary(UpgradeID.V4_PLACEHOLDERS, placeholdersUpgrade); - - LangUpgrade langUpgrade = new LangUpgrade(configManager); - runIfNecessary(UpgradeID.V4_LANG, langUpgrade); + runIfNecessary(UpgradeID.V4_CONFIG, () -> new SettingsUpgrade(configManager)); + runIfNecessary(UpgradeID.V4_PLACEHOLDERS, () -> new PlaceholdersYamlUpgrade(configManager)); + runIfNecessary(UpgradeID.V4_LANG, () -> new LangUpgrade(configManager)); try { - List menuUpgrades = CollectionUtils.transform( - configManager.getMenuPaths(), - menuPath -> new MenuUpgrade(configManager.getConfigLoader(menuPath), legacyCommandSeparator)); - runIfNecessary(UpgradeID.V4_MENUS, menuUpgrades); + List menuFiles = configManager.getMenuPaths(); + + runIfNecessaryMultiple(UpgradeID.V4_MENU_REPLACE, () -> { + return CollectionUtils.transform(menuFiles, + MenuNodeRenameUpgrade::new); + }); + + runIfNecessaryMultiple(UpgradeID.V4_MENUS_REFORMAT, () -> { + return CollectionUtils.transform(menuFiles, + file -> new MenuNodeExpandUpgrade(configManager, file, legacyCommandSeparator)); + }); + } catch (IOException e) { + Log.severe("Couldn't obtain a list of menu files. Some automatic upgrades were skipped.", e); failedUpgrades.add(configManager.getMenusFolder()); } } @@ -115,19 +123,19 @@ public class UpgradesExecutor { } - private void runIfNecessary(UpgradeID upgradeID, Upgrade upgradeTask) { - runIfNecessary(upgradeID, Collections.singletonList(upgradeTask)); + private void runIfNecessary(UpgradeID upgradeID, Supplier upgradeTask) { + runIfNecessaryMultiple(upgradeID, () -> Collections.singletonList(upgradeTask.get())); } - private void runIfNecessary(UpgradeID upgradeID, List upgradeTasks) { + private void runIfNecessaryMultiple(UpgradeID upgradeID, Supplier> upgradeTasks) { if (upgradesDoneRegistry.isDone(upgradeID)) { return; } boolean failedAnyUpgrade = false; - for (Upgrade upgradeTask : upgradeTasks) { + for (Upgrade upgradeTask : upgradeTasks.get()) { try { boolean modified = upgradeTask.backupAndUpgradeIfNecessary(); if (modified) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/LangUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/LangUpgrade.java similarity index 95% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/LangUpgrade.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/LangUpgrade.java index ce601e3..d73809d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/LangUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/LangUpgrade.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.legacy.upgrades; +package me.filoghost.chestcommands.legacy.upgrade; import me.filoghost.chestcommands.config.ConfigManager; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/MenuUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgrade.java similarity index 80% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/MenuUpgrade.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgrade.java index 72f78ac..1870948 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/MenuUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgrade.java @@ -12,14 +12,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.legacy.upgrades; +package me.filoghost.chestcommands.legacy.upgrade; +import me.filoghost.chestcommands.config.ConfigManager; import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.config.framework.ConfigSection; import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; -import me.filoghost.chestcommands.legacy.Upgrade; import me.filoghost.chestcommands.parsing.icon.IconSettingsNode; import me.filoghost.chestcommands.parsing.menu.MenuSettingsNode; import me.filoghost.chestcommands.util.Strings; @@ -30,14 +30,14 @@ import java.util.Collections; import java.util.List; import java.util.regex.Pattern; -public class MenuUpgrade extends Upgrade { +public class MenuNodeExpandUpgrade extends Upgrade { private final ConfigLoader menuConfigLoader; private final String legacyCommandSeparator; private Config updatedConfig; - public MenuUpgrade(ConfigLoader menuConfigLoader, String legacyCommandSeparator) { - this.menuConfigLoader = menuConfigLoader; + public MenuNodeExpandUpgrade(ConfigManager configManager, Path menuFile, String legacyCommandSeparator) { + this.menuConfigLoader = configManager.getConfigLoader(menuFile); this.legacyCommandSeparator = legacyCommandSeparator; } @@ -80,23 +80,11 @@ public class MenuUpgrade extends Upgrade { private void upgradeMenuSettings(ConfigSection section) { - renameNode(section, "command", MenuSettingsNode.COMMANDS); - renameNode(section, "open-action", MenuSettingsNode.OPEN_ACTIONS); - renameNode(section, "open-with-item.id", MenuSettingsNode.OPEN_ITEM_MATERIAL); - expandInlineList(section, MenuSettingsNode.COMMANDS, ";"); expandInlineList(section, MenuSettingsNode.OPEN_ACTIONS, legacyCommandSeparator); } private void upgradeIcon(ConfigSection section) { - renameNode(section, "ID", IconSettingsNode.MATERIAL); - renameNode(section, "DATA-VALUE", IconSettingsNode.DURABILITY); - renameNode(section, "NBT", IconSettingsNode.NBT_DATA); - renameNode(section, "ENCHANTMENT", IconSettingsNode.ENCHANTMENTS); - renameNode(section, "COMMAND", IconSettingsNode.ACTIONS); - renameNode(section, "COMMANDS", IconSettingsNode.ACTIONS); - renameNode(section, "REQUIRED-ITEM", IconSettingsNode.REQUIRED_ITEMS); - expandInlineList(section, IconSettingsNode.ACTIONS, legacyCommandSeparator); expandInlineList(section, IconSettingsNode.ENCHANTMENTS, ";"); @@ -140,14 +128,6 @@ public class MenuUpgrade extends Upgrade { } } - private void renameNode(ConfigSection config, String oldNode, String newNode) { - if (config.isSet(oldNode) && !config.isSet(newNode)) { - config.set(newNode, config.get(oldNode)); - config.set(oldNode, null); - setModified(); - } - } - private void expandInlineList(ConfigSection config, String node, String separator) { if (config.isSet(node)) { if (config.isString(node)) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgrade.java new file mode 100644 index 0000000..cb237a9 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgrade.java @@ -0,0 +1,47 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.legacy.upgrade; + +import me.filoghost.chestcommands.parsing.icon.IconSettingsNode; +import me.filoghost.chestcommands.parsing.menu.MenuSettingsNode; + +import java.nio.file.Path; +import java.util.regex.Pattern; + +public class MenuNodeRenameUpgrade extends RegexUpgrade { + + public MenuNodeRenameUpgrade(Path menuFile) { + super(menuFile); + + addSubNodeReplacer("command", MenuSettingsNode.COMMANDS); + addSubNodeReplacer("open-action", MenuSettingsNode.OPEN_ACTIONS); + addSubNodeReplacer("open-with-item.id", MenuSettingsNode.OPEN_ITEM_MATERIAL); + + addSubNodeReplacer("ID", IconSettingsNode.MATERIAL); + addSubNodeReplacer("DATA-VALUE", IconSettingsNode.DURABILITY); + addSubNodeReplacer("NBT", IconSettingsNode.NBT_DATA); + addSubNodeReplacer("ENCHANTMENT", IconSettingsNode.ENCHANTMENTS); + addSubNodeReplacer("COMMAND", IconSettingsNode.ACTIONS); + addSubNodeReplacer("COMMANDS", IconSettingsNode.ACTIONS); + addSubNodeReplacer("REQUIRED-ITEM", IconSettingsNode.REQUIRED_ITEMS); + } + + private void addSubNodeReplacer(String oldAttribute, String newAttribute) { + addRegexReplacer( + Pattern.compile("(^\\s+)" + Pattern.quote(oldAttribute) + "(:)"), + matcher -> matcher.group(1) + newAttribute + matcher.group(2)); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/PlaceholdersUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgrade.java similarity index 94% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/PlaceholdersUpgrade.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgrade.java index 9f0142e..1e48f6c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/PlaceholdersUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgrade.java @@ -12,14 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.legacy.upgrades; +package me.filoghost.chestcommands.legacy.upgrade; import me.filoghost.chestcommands.config.ConfigManager; import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; -import me.filoghost.chestcommands.legacy.Upgrade; import me.filoghost.chestcommands.util.Strings; import org.apache.commons.lang.StringEscapeUtils; @@ -28,13 +27,13 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.List; -public class PlaceholdersUpgrade extends Upgrade { +public class PlaceholdersYamlUpgrade extends Upgrade { private final Path oldPlaceholdersFile; private final ConfigLoader newPlaceholdersConfigLoader; private Config updatedConfig; - public PlaceholdersUpgrade(ConfigManager configManager) { + public PlaceholdersYamlUpgrade(ConfigManager configManager) { this.oldPlaceholdersFile = configManager.getRootDataFolder().resolve("placeholders.yml"); this.newPlaceholdersConfigLoader = configManager.getConfigLoader("custom-placeholders.yml"); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/RegexUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgrade.java similarity index 81% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/RegexUpgrade.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgrade.java index 30b7c3c..d512276 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/RegexUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgrade.java @@ -12,12 +12,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.legacy.upgrades; +package me.filoghost.chestcommands.legacy.upgrade; import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; -import me.filoghost.chestcommands.legacy.RegexFileReplacer; -import me.filoghost.chestcommands.legacy.Upgrade; +import me.filoghost.chestcommands.legacy.RegexReplacer; import java.io.IOException; import java.nio.file.Files; @@ -27,12 +26,14 @@ import java.util.List; import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class RegexUpgrade extends Upgrade { private final Path file; + private final List replacers; private List newContents; - private List replacers; public RegexUpgrade(Path file) { this.file = file; @@ -40,7 +41,7 @@ public class RegexUpgrade extends Upgrade { } protected void addRegexReplacer(Pattern regex, Function replaceCallback) { - replacers.add(new RegexFileReplacer(regex, replaceCallback)); + replacers.add(new RegexReplacer(regex, replaceCallback)); } @Override @@ -66,10 +67,13 @@ public class RegexUpgrade extends Upgrade { throw new ConfigLoadException("couldn't read file \"" + file.getFileName() + "\"", e); } - for (RegexFileReplacer replacer : replacers) { - newContents = replacer.replace(lines); + Stream linesStream = lines.stream(); + for (RegexReplacer replacer : replacers) { + linesStream = linesStream.map(replacer); } + newContents = linesStream.collect(Collectors.toList()); + if (!newContents.equals(lines)) { setModified(); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/SettingsUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgrade.java similarity index 95% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/SettingsUpgrade.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgrade.java index c3dc2bf..2f296dd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrades/SettingsUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgrade.java @@ -12,14 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.legacy.upgrades; +package me.filoghost.chestcommands.legacy.upgrade; import me.filoghost.chestcommands.config.ConfigManager; import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; -import me.filoghost.chestcommands.legacy.Upgrade; import java.nio.file.Path; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java similarity index 98% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java index ee45a69..d11f81c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.legacy; +package me.filoghost.chestcommands.legacy.upgrade; import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeException.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeException.java similarity index 94% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeException.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeException.java index 19314fe..e17e6a6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeException.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.legacy; +package me.filoghost.chestcommands.legacy.upgrade; public class UpgradeException extends Exception { From 1379ce344a97a7c844276091312a98ec0a6f1a8e Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 12 Jul 2020 10:54:12 +0200 Subject: [PATCH 135/213] Fix NullPointerException --- .../main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java index 4b24ad7..798905e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java @@ -78,7 +78,7 @@ public abstract class BaseIconMenu implements IconMenu { public void refreshOpenInventories() { for (Player player : Bukkit.getOnlinePlayers()) { DefaultItemInventory itemInventory = MenuManager.getOpenItemInventory(player); - if (itemInventory.getIconMenu() == this) { + if (itemInventory != null && itemInventory.getIconMenu() == this) { itemInventory.refresh(); } } From cfac51bcf48e800872f878769f222aae61bcc9a8 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 12 Jul 2020 16:36:42 +0200 Subject: [PATCH 136/213] Placeholders refactoring --- .../chestcommands/ChestCommands.java | 6 +- .../placeholder/CachedGetters.java | 36 ------- .../placeholder/DefaultPlaceholders.java | 60 ++++++++++++ .../placeholder/Placeholder.java | 55 +---------- .../placeholder/PlaceholderManager.java | 49 +++++++--- ...RefreshMenusTask.java => TickingTask.java} | 98 ++++++++++--------- 6 files changed, 154 insertions(+), 150 deletions(-) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/placeholder/CachedGetters.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholders.java rename Plugin/src/main/java/me/filoghost/chestcommands/task/{RefreshMenusTask.java => TickingTask.java} (87%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 4fc019f..938d1ad 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -17,11 +17,11 @@ package me.filoghost.chestcommands; import me.filoghost.chestcommands.api.internal.BackendAPI; import me.filoghost.chestcommands.command.CommandHandler; import me.filoghost.chestcommands.command.framework.CommandFramework; -import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.config.ConfigManager; import me.filoghost.chestcommands.config.CustomPlaceholders; import me.filoghost.chestcommands.config.Lang; import me.filoghost.chestcommands.config.Settings; +import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.hook.BarAPIHook; import me.filoghost.chestcommands.hook.BungeeCordHook; import me.filoghost.chestcommands.hook.PlaceholderAPIHook; @@ -34,7 +34,7 @@ import me.filoghost.chestcommands.listener.JoinListener; import me.filoghost.chestcommands.listener.SignListener; import me.filoghost.chestcommands.menu.MenuManager; import me.filoghost.chestcommands.parsing.menu.LoadedMenu; -import me.filoghost.chestcommands.task.RefreshMenusTask; +import me.filoghost.chestcommands.task.TickingTask; import me.filoghost.chestcommands.util.Log; import me.filoghost.chestcommands.util.Utils; import me.filoghost.chestcommands.util.collection.ErrorCollector; @@ -139,7 +139,7 @@ public class ChestCommands extends JavaPlugin { Bukkit.getScheduler().runTaskLater(this, errorCollector::logToConsole, 10L); } - Bukkit.getScheduler().runTaskTimer(this, new RefreshMenusTask(), 1L, 1L); + Bukkit.getScheduler().runTaskTimer(this, new TickingTask(), 1L, 1L); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/CachedGetters.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/CachedGetters.java deleted file mode 100644 index f905120..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/CachedGetters.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.placeholder; - -import org.bukkit.Bukkit; - -public class CachedGetters { - - private static long lastOnlinePlayersRefresh; - private static int onlinePlayers; - - - public static int getOnlinePlayers() { - long now = System.currentTimeMillis(); - if (lastOnlinePlayersRefresh == 0 || now - lastOnlinePlayersRefresh > 1000) { - // getOnlinePlayers() could be expensive if called frequently - lastOnlinePlayersRefresh = now; - onlinePlayers = Bukkit.getOnlinePlayers().size(); - } - - return onlinePlayers; - } - -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholders.java new file mode 100644 index 0000000..1764901 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholders.java @@ -0,0 +1,60 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.placeholder; + +import me.filoghost.chestcommands.hook.VaultEconomyHook; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.function.Function; + +public enum DefaultPlaceholders implements Placeholder { + + PLAYER("{player}", player -> player.getName()), + + ONLINE("{online}", player -> String.valueOf(Bukkit.getOnlinePlayers().size())), + + MAX_PLAYERS("{max_players}", player -> String.valueOf(Bukkit.getMaxPlayers())), + + WORLD("{world}", player -> player.getWorld().getName()), + + MONEY("{money}", player -> { + if (VaultEconomyHook.INSTANCE.isEnabled()) { + return VaultEconomyHook.formatMoney(VaultEconomyHook.getMoney(player)); + } else { + return "[ECONOMY PLUGIN NOT FOUND]"; + } + }); + + + private final String text; + private final Function getReplacementFunction; + + DefaultPlaceholders(String text, Function getReplacementFunction) { + this.text = text; + this.getReplacementFunction = getReplacementFunction; + } + + @Override + public String getPlaceholderText() { + return text; + } + + @Override + public String getReplacementText(Player player) { + return getReplacementFunction.apply(player); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/Placeholder.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/Placeholder.java index 3482a61..e670eb1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/Placeholder.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/Placeholder.java @@ -14,61 +14,12 @@ */ package me.filoghost.chestcommands.placeholder; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.hook.VaultEconomyHook; +public interface Placeholder { -public enum Placeholder { + String getPlaceholderText(); - PLAYER("{player}") { - @Override - public String getReplacement(Player executor) { - return executor.getName(); - } - }, + String getReplacementText(Player player); - ONLINE("{online}") { - @Override - public String getReplacement(Player executor) { - return String.valueOf(CachedGetters.getOnlinePlayers()); - } - }, - - MAX_PLAYERS("{max_players}") { - @Override - public String getReplacement(Player executor) { - return String.valueOf(Bukkit.getMaxPlayers()); - } - }, - - MONEY("{money}") { - @Override - public String getReplacement(Player executor) { - if (VaultEconomyHook.INSTANCE.isEnabled()) { - return VaultEconomyHook.formatMoney(VaultEconomyHook.getMoney(executor)); - } else { - return "[ECONOMY PLUGIN NOT FOUND]"; - } - } - }, - - WORLD("{world}") { - @Override - public String getReplacement(Player executor) { - return executor.getWorld().getName(); - } - }; - - private final String text; - - Placeholder(String text) { - this.text = text; - } - - public String getText() { - return text; - } - - public abstract String getReplacement(Player executor); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java index 4eda536..8df60f1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java @@ -1,39 +1,62 @@ package me.filoghost.chestcommands.placeholder; +import me.filoghost.chestcommands.hook.PlaceholderAPIHook; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.hook.PlaceholderAPIHook; +import java.util.HashMap; +import java.util.Map; +import java.util.WeakHashMap; public class PlaceholderManager { - public static boolean hasPlaceholders(String message) { - if(message == null) { + private static final Map> cachedReplacements = new WeakHashMap<>(); + + public static boolean hasPlaceholders(String text) { + if(text == null) { return false; } - for (Placeholder placeholder : Placeholder.values()) { - if (message.contains(placeholder.getText())) { + + for (Placeholder placeholder : DefaultPlaceholders.values()) { + if (text.contains(placeholder.getPlaceholderText())) { return true; } } - if (PlaceholderAPIHook.INSTANCE.isEnabled() && PlaceholderAPIHook.hasPlaceholders(message)) { + + if (PlaceholderAPIHook.INSTANCE.isEnabled() && PlaceholderAPIHook.hasPlaceholders(text)) { return true; } + return false; } - public static String replacePlaceholders(String message, Player viewer) { - if (message == null) { + public static String replacePlaceholders(String text, Player player) { + if (text == null) { return null; } - for (Placeholder placeholder : Placeholder.values()) { - if (message.contains(placeholder.getText())) { - message = message.replace(placeholder.getText(), placeholder.getReplacement(viewer)); + + for (Placeholder placeholder : DefaultPlaceholders.values()) { + if (text.contains(placeholder.getPlaceholderText())) { + String replacement = getCachedReplacement(placeholder, player); + text = text.replace(placeholder.getPlaceholderText(), replacement); } } + if (PlaceholderAPIHook.INSTANCE.isEnabled()) { - message = PlaceholderAPIHook.setPlaceholders(message, viewer); + text = PlaceholderAPIHook.setPlaceholders(text, player); } - return message; + + return text; } + private static String getCachedReplacement(Placeholder placeholder, Player player) { + return cachedReplacements + .computeIfAbsent(player, key -> new HashMap<>()) + .computeIfAbsent(placeholder, key -> placeholder.getReplacementText(player)); + } + + public static void onTick() { + cachedReplacements.forEach((player, placeholderMap) -> placeholderMap.clear()); + } + + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java similarity index 87% rename from Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java rename to Plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java index 8c2b042..6525214 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java @@ -1,46 +1,52 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.task; - -import me.filoghost.chestcommands.inventory.DefaultItemInventory; -import me.filoghost.chestcommands.menu.InternalIconMenu; -import me.filoghost.chestcommands.menu.MenuManager; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -public class RefreshMenusTask implements Runnable { - - private long currentTick; - - @Override - public void run() { - for (Player player : Bukkit.getOnlinePlayers()) { - DefaultItemInventory itemInventory = MenuManager.getOpenItemInventory(player); - - if (itemInventory == null || !(itemInventory.getIconMenu() instanceof InternalIconMenu)) { - continue; - } - - int refreshTicks = ((InternalIconMenu) itemInventory.getIconMenu()).getRefreshTicks(); - - if (refreshTicks > 0 && currentTick % refreshTicks == 0) { - itemInventory.refresh(); - } - } - - currentTick++; - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.task; + +import me.filoghost.chestcommands.inventory.DefaultItemInventory; +import me.filoghost.chestcommands.menu.InternalIconMenu; +import me.filoghost.chestcommands.menu.MenuManager; +import me.filoghost.chestcommands.placeholder.PlaceholderManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class TickingTask implements Runnable { + + private long currentTick; + + @Override + public void run() { + updateInventories(); + PlaceholderManager.onTick(); + + currentTick++; + } + + private void updateInventories() { + for (Player player : Bukkit.getOnlinePlayers()) { + DefaultItemInventory itemInventory = MenuManager.getOpenItemInventory(player); + + if (itemInventory == null || !(itemInventory.getIconMenu() instanceof InternalIconMenu)) { + continue; + } + + int refreshTicks = ((InternalIconMenu) itemInventory.getIconMenu()).getRefreshTicks(); + + if (refreshTicks > 0 && currentTick % refreshTicks == 0) { + itemInventory.refresh(); + } + } + } + +} From adfdd5b72db38cee91eb344aac12584d0e418974 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 19 Jul 2020 11:56:35 +0200 Subject: [PATCH 137/213] Error logging refactoring --- .../chestcommands/ChestCommands.java | 34 +-- .../filoghost/chestcommands/Permissions.java | 11 +- .../chestcommands/action/DragonBarAction.java | 2 +- .../chestcommands/action/GiveMoneyAction.java | 2 +- .../chestcommands/command/CommandHandler.java | 20 +- .../chestcommands/config/ConfigManager.java | 32 ++- .../config/CustomPlaceholders.java | 7 +- .../config/framework/Config.java | 4 +- .../config/framework/ConfigLoader.java | 47 ++-- .../config/framework/ConfigSection.java | 11 +- .../exception/ConfigSyntaxException.java | 7 + .../framework/mapped/MappedConfigLoader.java | 11 +- .../icon/BaseConfigurableIcon.java | 6 +- .../legacy/UpgradesDoneRegistry.java | 2 +- .../legacy/UpgradesExecutor.java | 54 ++--- .../legacy/upgrade/MenuNodeExpandUpgrade.java | 4 +- .../upgrade/PlaceholdersYamlUpgrade.java | 7 +- .../legacy/upgrade/RegexUpgrade.java | 5 +- .../legacy/upgrade/SettingsUpgrade.java | 7 +- .../chestcommands/legacy/upgrade/Upgrade.java | 7 +- .../chestcommands/listener/JoinListener.java | 9 +- .../chestcommands/logging/ErrorMessages.java | 216 ++++++++++++++++++ .../chestcommands/logging/ErrorPrintInfo.java | 35 +++ .../logging/MessagePartJoiner.java | 76 ++++++ .../logging/PrintableErrorCollector.java | 91 ++++++++ .../chestcommands/menu/InternalIconMenu.java | 13 +- .../chestcommands/menu/MenuManager.java | 20 +- .../parsing/EnchantmentParser.java | 11 +- .../chestcommands/parsing/ErrorFormat.java | 39 ---- .../chestcommands/parsing/ItemMetaParser.java | 37 ++- .../parsing/ItemStackParser.java | 21 +- .../chestcommands/parsing/NumberParser.java | 42 ++-- .../chestcommands/parsing/ParseException.java | 5 + .../parsing/icon/AttributeErrorCollector.java | 13 +- .../parsing/icon/IconSettings.java | 21 +- .../icon/attributes/AmountAttribute.java | 3 +- .../icon/attributes/ExpLevelsAttribute.java | 3 +- .../icon/attributes/MaterialAttribute.java | 3 +- .../icon/attributes/PriceAttribute.java | 3 +- .../parsing/menu/LoadedMenu.java | 11 +- .../parsing/menu/MenuParser.java | 55 ++--- .../filoghost/chestcommands/util/Strings.java | 13 +- .../util/collection/ErrorCollector.java | 77 ------- .../util/logging/ErrorCollector.java | 48 ++++ .../chestcommands/util/logging/ErrorInfo.java | 33 +++ .../chestcommands/util/{ => logging}/Log.java | 2 +- .../chestcommands/util/nbt/NBTType.java | 2 +- .../nbt/parser/MojangsonParseException.java | 6 +- 48 files changed, 797 insertions(+), 391 deletions(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorPrintInfo.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/parsing/ErrorFormat.java delete mode 100644 Utils/src/main/java/me/filoghost/chestcommands/util/collection/ErrorCollector.java create mode 100644 Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorCollector.java create mode 100644 Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorInfo.java rename Utils/src/main/java/me/filoghost/chestcommands/util/{ => logging}/Log.java (96%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 938d1ad..114f542 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -32,12 +32,14 @@ import me.filoghost.chestcommands.listener.CommandListener; import me.filoghost.chestcommands.listener.InventoryListener; import me.filoghost.chestcommands.listener.JoinListener; import me.filoghost.chestcommands.listener.SignListener; +import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.PrintableErrorCollector; import me.filoghost.chestcommands.menu.MenuManager; import me.filoghost.chestcommands.parsing.menu.LoadedMenu; import me.filoghost.chestcommands.task.TickingTask; -import me.filoghost.chestcommands.util.Log; import me.filoghost.chestcommands.util.Utils; -import me.filoghost.chestcommands.util.collection.ErrorCollector; +import me.filoghost.chestcommands.util.logging.ErrorCollector; +import me.filoghost.chestcommands.util.logging.Log; import me.filoghost.updatechecker.UpdateChecker; import org.bstats.bukkit.MetricsLite; import org.bukkit.Bukkit; @@ -135,7 +137,7 @@ public class ChestCommands extends JavaPlugin { ErrorCollector errorCollector = load(); - if (errorCollector.hasWarningsOrErrors()) { + if (errorCollector.hasErrors()) { Bukkit.getScheduler().runTaskLater(this, errorCollector::logToConsole, 10L); } @@ -150,39 +152,39 @@ public class ChestCommands extends JavaPlugin { public ErrorCollector load() { - ErrorCollector errors = new ErrorCollector(); + ErrorCollector errorCollector = new PrintableErrorCollector(); menuManager.clear(); boolean isFreshInstall = !Files.isDirectory(configManager.getRootDataFolder()); try { Files.createDirectories(configManager.getRootDataFolder()); } catch (IOException e) { - errors.addError("Plugin failed to load, couldn't create data folder."); - return errors; + errorCollector.add(ErrorMessages.Config.createDataFolderIOException, e); + return errorCollector; } try { - new UpgradesExecutor(configManager).run(isFreshInstall); + new UpgradesExecutor(configManager).run(isFreshInstall, errorCollector); } catch (UpgradeExecutorException e) { - Log.severe("Encountered errors while running run automatic configuration upgrades. Some configuration files or menus may require manual updates.", e); + errorCollector.add(ErrorMessages.Upgrade.genericExecutorError, e); } - settings = configManager.tryLoadSettings(); - lang = configManager.tryLoadLang(); - placeholders = configManager.tryLoadCustomPlaceholders(errors); + settings = configManager.tryLoadSettings(errorCollector); + lang = configManager.tryLoadLang(errorCollector); + placeholders = configManager.tryLoadCustomPlaceholders(errorCollector); // Create the menu folder with the example menu if (!Files.isDirectory(configManager.getMenusFolder())) { ConfigLoader exampleMenuLoader = configManager.getConfigLoader(configManager.getMenusFolder().resolve("example.yml")); - configManager.tryCreateDefault(exampleMenuLoader); + configManager.tryCreateDefault(errorCollector, exampleMenuLoader); } - List loadedMenus = configManager.tryLoadMenus(errors); + List loadedMenus = configManager.tryLoadMenus(errorCollector); for (LoadedMenu loadedMenu : loadedMenus) { - menuManager.registerMenu(loadedMenu, errors); + menuManager.registerMenu(loadedMenu, errorCollector); } - ChestCommands.lastLoadErrors = errors; - return errors; + ChestCommands.lastLoadErrors = errorCollector; + return errorCollector; } public static void closeAllMenus() { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java b/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java index aeed75b..2ea4587 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java @@ -18,11 +18,12 @@ public class Permissions { public static final String - UPDATE_NOTIFICATIONS = "chestcommands.update", - SEE_ERRORS = "chestcommands.errors", - SIGN_CREATE = "chestcommands.sign", + BASE_PREFIX = "chestcommands.", + COMMAND_PREFIX = BASE_PREFIX + "command.", + OPEN_MENU_PREFIX = BASE_PREFIX + "open.", - COMMAND_BASE = "chestcommands.command.", - OPEN_MENU_BASE = "chestcommands.open."; + UPDATE_NOTIFICATIONS = BASE_PREFIX + "update", + SEE_ERRORS = BASE_PREFIX + "errors", + SIGN_CREATE = BASE_PREFIX + "sign"; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java index 953e083..d06efc8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java @@ -39,7 +39,7 @@ public class DragonBarAction extends Action { seconds = NumberParser.getStrictlyPositiveInteger(split[0]); message = split[1]; } catch (ParseException ex) { - disable(ChatColor.RED + "Invalid dragon bar time: " + split[0]); + disable(ChatColor.RED + "Invalid dragon bar time \"" + split[0] + "\": " + ex.getMessage()); return; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java index 1fe2d37..1076207 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java @@ -29,7 +29,7 @@ public class GiveMoneyAction extends Action { try { moneyToGive = NumberParser.getStrictlyPositiveDouble(action); } catch (ParseException e) { - disable(ChatColor.RED + "Invalid money amount: " + action); + disable(ChatColor.RED + "Invalid money amount \"" + action + "\": " + e.getMessage()); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index 8a57615..0d00136 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -20,7 +20,7 @@ import me.filoghost.chestcommands.command.framework.CommandFramework; import me.filoghost.chestcommands.command.framework.CommandValidate; import me.filoghost.chestcommands.menu.InternalIconMenu; import me.filoghost.chestcommands.menu.MenuManager; -import me.filoghost.chestcommands.util.collection.ErrorCollector; +import me.filoghost.chestcommands.util.logging.ErrorCollector; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -50,7 +50,7 @@ public class CommandHandler extends CommandFramework { if (args[0].equalsIgnoreCase("help")) { - CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "help"), "You don't have permission."); + CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "help"), "You don't have permission."); sender.sendMessage(ChestCommands.CHAT_PREFIX + " Commands:"); sender.sendMessage(ChatColor.WHITE + "/" + label + " reload" + ChatColor.GRAY + " - Reloads the plugin."); sender.sendMessage(ChatColor.WHITE + "/" + label + " list" + ChatColor.GRAY + " - Lists the loaded menus."); @@ -60,17 +60,17 @@ public class CommandHandler extends CommandFramework { if (args[0].equalsIgnoreCase("reload")) { - CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "reload"), "You don't have permission."); + CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "reload"), "You don't have permission."); ChestCommands.closeAllMenus(); - ErrorCollector errors = ChestCommands.getInstance().load(); + ErrorCollector errorCollector = ChestCommands.getInstance().load(); - if (!errors.hasWarningsOrErrors()) { + if (!errorCollector.hasErrors()) { sender.sendMessage(ChestCommands.CHAT_PREFIX + "Plugin reloaded."); } else { - errors.logToConsole(); - sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Plugin reloaded with " + errors.getWarningsCount() + " warning(s) and " + errors.getErrorsCount() + " error(s)."); + errorCollector.logToConsole(); + sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Plugin reloaded with " + errorCollector.getErrorsCount() + " error(s)."); if (!(sender instanceof ConsoleCommandSender)) { sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Please check the console."); } @@ -80,14 +80,14 @@ public class CommandHandler extends CommandFramework { if (args[0].equalsIgnoreCase("open")) { - CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "open"), "You don't have permission."); + CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "open"), "You don't have permission."); CommandValidate.minLength(args, 2, "Usage: /" + label + " open

[player]"); Player target; if (sender instanceof Player) { if (args.length > 2) { - CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "open.others"), "You don't have permission to open menus for others."); + CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "open.others"), "You don't have permission to open menus for others."); target = Bukkit.getPlayerExact(args[2]); } else { target = (Player) sender; @@ -124,7 +124,7 @@ public class CommandHandler extends CommandFramework { if (args[0].equalsIgnoreCase("list")) { - CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "list"), "You don't have permission."); + CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "list"), "You don't have permission."); sender.sendMessage(ChestCommands.CHAT_PREFIX + " Loaded menus:"); for (String file : menuManager.getMenuFileNames()) { sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.WHITE + file); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java index fe0339e..0c0fb45 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java @@ -18,13 +18,12 @@ import me.filoghost.chestcommands.config.framework.BaseConfigManager; import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.config.framework.exception.ConfigException; -import me.filoghost.chestcommands.config.framework.exception.ConfigSyntaxException; import me.filoghost.chestcommands.config.framework.mapped.MappedConfigLoader; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.menu.LoadedMenu; import me.filoghost.chestcommands.parsing.menu.MenuParser; -import me.filoghost.chestcommands.util.Log; import me.filoghost.chestcommands.util.Preconditions; -import me.filoghost.chestcommands.util.collection.ErrorCollector; +import me.filoghost.chestcommands.util.logging.ErrorCollector; import java.io.IOException; import java.nio.file.FileVisitOption; @@ -50,20 +49,20 @@ public class ConfigManager extends BaseConfigManager { langConfigLoader = getMappedConfigLoader("lang.yml", Lang::new); } - public Settings tryLoadSettings() { + public Settings tryLoadSettings(ErrorCollector errorCollector) { try { return settingsConfigLoader.init(); } catch (ConfigException e) { - logConfigInitException(settingsConfigLoader.getFileName(), e); + logConfigInitException(errorCollector, settingsConfigLoader.getFile(), e); return new Settings(); } } - public Lang tryLoadLang() { + public Lang tryLoadLang(ErrorCollector errorCollector) { try { return langConfigLoader.init(); } catch (ConfigException e) { - logConfigInitException(langConfigLoader.getFileName(), e); + logConfigInitException(errorCollector, langConfigLoader.getFile(), e); return new Lang(); } } @@ -75,17 +74,17 @@ public class ConfigManager extends BaseConfigManager { Config placeholdersConfig = placeholdersConfigLoader.init(); placeholders.load(placeholdersConfig, errorCollector); } catch (ConfigException t) { - logConfigInitException(placeholdersConfigLoader.getFileName(), t); + logConfigInitException(errorCollector, placeholdersConfigLoader.getFile(), t); } return placeholders; } - public void tryCreateDefault(ConfigLoader configLoader) { + public void tryCreateDefault(ErrorCollector errorCollector, ConfigLoader configLoader) { try { configLoader.createDefault(); } catch (ConfigException e) { - logConfigInitException(configLoader.getFileName(), e); + logConfigInitException(errorCollector, configLoader.getFile(), e); } } @@ -106,13 +105,8 @@ public class ConfigManager extends BaseConfigManager { } } - private void logConfigInitException(String fileName, ConfigException e) { - if (e instanceof ConfigSyntaxException) { - Log.warning("Invalid YAML syntax in config file \"" + fileName + "\": " + e.getMessage()); - } else { - e.printStackTrace(); - Log.warning("Error while reading config file \"" + fileName + "\": " + e.getMessage()); - } + private void logConfigInitException(ErrorCollector errorCollector, Path file, ConfigException e) { + errorCollector.add(ErrorMessages.Config.initException(file), e); } public List tryLoadMenus(ErrorCollector errorCollector) { @@ -122,7 +116,7 @@ public class ConfigManager extends BaseConfigManager { try { menuPaths = getMenuPaths(); } catch (IOException e) { - Log.severe("Couldn't fetch files inside the folder \"" + getMenusFolder().getFileName() + "\"", e); + errorCollector.add(ErrorMessages.Config.menuListIOException(getMenusFolder()), e); return Collections.emptyList(); } @@ -133,7 +127,7 @@ public class ConfigManager extends BaseConfigManager { Config menuConfig = menuConfigLoader.load(); loadedMenus.add(MenuParser.loadMenu(menuConfig, errorCollector)); } catch (ConfigException e) { - logConfigInitException(menuConfigLoader.getFileName(), e); + logConfigInitException(errorCollector, menuConfigLoader.getFile(), e); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java index b8b4beb..e3ab568 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java @@ -15,9 +15,10 @@ package me.filoghost.chestcommands.config; import me.filoghost.chestcommands.config.framework.Config; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.util.Colors; import me.filoghost.chestcommands.util.collection.CollectionUtils; -import me.filoghost.chestcommands.util.collection.ErrorCollector; +import me.filoghost.chestcommands.util.logging.ErrorCollector; import java.util.HashMap; import java.util.List; @@ -36,12 +37,12 @@ public class CustomPlaceholders { String replacement = Colors.addColors(config.getString(key)); if (placeholder.length() == 0) { - errorCollector.addError("Error in " + config.getSourceFileName() + ": placeholder cannot be empty (skipped)."); + errorCollector.add(ErrorMessages.Config.emptyPlaceholder(config.getSourceFile())); continue; } if (placeholder.length() > 100) { - errorCollector.addError("Error in " + config.getSourceFileName() + ": placeholder cannot be longer than 100 character (" + placeholder + ")."); + errorCollector.add(ErrorMessages.Config.tooLongPlaceholder(config.getSourceFile(), placeholder)); continue; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java index 8460851..852e053 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java @@ -33,8 +33,8 @@ public class Config extends ConfigSection { this.sourceFilePath = sourceFilePath; } - public String getSourceFileName() { - return sourceFilePath.getFileName().toString(); + public Path getSourceFile() { + return sourceFilePath; } public String saveToString() { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java index 66006a2..e2bb954 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java @@ -17,6 +17,7 @@ package me.filoghost.chestcommands.config.framework; import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; import me.filoghost.chestcommands.config.framework.exception.ConfigSyntaxException; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.util.Preconditions; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; @@ -35,13 +36,13 @@ import java.util.stream.StreamSupport; public class ConfigLoader { private final Path rootDataFolder; - private final Path configPath; + private final Path filePath; - public ConfigLoader(Path rootDataFolder, Path configPath) { - Preconditions.checkArgument(configPath.startsWith(rootDataFolder), "config file " + configPath + " cannot be outside " + rootDataFolder); + public ConfigLoader(Path rootDataFolder, Path filePath) { + Preconditions.checkArgument(filePath.startsWith(rootDataFolder), "file \"" + filePath + "\" must be inside \"" + rootDataFolder + "\""); this.rootDataFolder = rootDataFolder; - this.configPath = configPath; + this.filePath = filePath; } public Config init() throws ConfigSaveException, ConfigLoadException { @@ -56,17 +57,17 @@ public class ConfigLoader { createParentDirectory(); - Path relativeConfigPath = rootDataFolder.relativize(configPath); + Path relativeConfigPath = rootDataFolder.relativize(filePath); String internalJarPath = toInternalJarPath(relativeConfigPath); try (InputStream defaultFile = getInternalResource(internalJarPath)) { if (defaultFile != null) { - Files.copy(defaultFile, configPath); + Files.copy(defaultFile, filePath); } else { - Files.createFile(configPath); + Files.createFile(filePath); } } catch (IOException e) { - throw new ConfigSaveException("couldn't create default config file " + configPath, e); + throw new ConfigSaveException(ErrorMessages.Config.createDefaultIOException, e); } } @@ -91,23 +92,23 @@ public class ConfigLoader { } public boolean fileExists() { - return (Files.isRegularFile(configPath)); + return Files.isRegularFile(filePath); } public Config load() throws ConfigLoadException { - Preconditions.checkState(fileExists(), configPath.getFileName() + " doesn't exist or is not a regular file"); + Preconditions.checkState(fileExists(), "\"" + filePath + "\" doesn't exist or is not a regular file"); YamlConfiguration yaml = new YamlConfiguration(); - try (BufferedReader reader = Files.newBufferedReader(configPath)) { + try (BufferedReader reader = Files.newBufferedReader(filePath)) { yaml.load(reader); } catch (IOException e) { - throw new ConfigLoadException("couldn't read config file " + configPath, e); + throw new ConfigLoadException(ErrorMessages.Config.readIOException, e); } catch (InvalidConfigurationException e) { - throw new ConfigSyntaxException(e.getMessage(), e); + throw new ConfigSyntaxException(ErrorMessages.Config.invalidYamlSyntax, e); } - return new Config(yaml, configPath); + return new Config(yaml, filePath); } public void save(Config config) throws ConfigSaveException { @@ -115,29 +116,25 @@ public class ConfigLoader { String data = config.saveToString(); - try (BufferedWriter writer = Files.newBufferedWriter(configPath)) { + try (BufferedWriter writer = Files.newBufferedWriter(filePath)) { writer.write(data); } catch (IOException e) { - throw new ConfigSaveException("couldn't write config data to " + configPath, e); + throw new ConfigSaveException(ErrorMessages.Config.writeDataIOException, e); } } private void createParentDirectory() throws ConfigSaveException { - if (configPath.getParent() != null) { + if (filePath.getParent() != null) { try { - Files.createDirectories(configPath.getParent()); + Files.createDirectories(filePath.getParent()); } catch (IOException e) { - throw new ConfigSaveException("couldn't create directory " + configPath.getParent(), e); + throw new ConfigSaveException(ErrorMessages.Config.createParentFolderIOException(filePath.getParent()), e); } } } - public Path getConfigPath() { - return configPath; - } - - public String getFileName() { - return configPath.getFileName().toString(); + public Path getFile() { + return filePath; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java index cbf55a1..c8a0b18 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java @@ -15,6 +15,7 @@ package me.filoghost.chestcommands.config.framework; import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; +import me.filoghost.chestcommands.logging.ErrorMessages; import org.bukkit.configuration.ConfigurationSection; import java.util.ArrayList; @@ -39,22 +40,22 @@ public class ConfigSection { } public int getRequiredInt(String path) throws ConfigValueException { - Number value = cast(getRequired(path), Number.class, "value is not a number"); + Number value = cast(getRequired(path), Number.class, ErrorMessages.Config.valueNotNumber); return value.intValue(); } public double getRequiredDouble(String path) throws ConfigValueException { - Number value = cast(getRequired(path), Number.class, "value is not a number"); + Number value = cast(getRequired(path), Number.class, ErrorMessages.Config.valueNotNumber); return value.doubleValue(); } public boolean getRequiredBoolean(String path) throws ConfigValueException { - Boolean value = cast(getRequired(path), Boolean.class, "value is not a boolean"); + Boolean value = cast(getRequired(path), Boolean.class, ErrorMessages.Config.valueNotBoolean); return value; } public List getRequiredStringList(String path) throws ConfigValueException { - List value = cast(getRequired(path), List.class, "value is not a list"); + List value = cast(getRequired(path), List.class, ErrorMessages.Config.valueNotList); List result = new ArrayList<>(); for (Object object : value) { @@ -69,7 +70,7 @@ public class ConfigSection { private Object getRequired(String path) throws ConfigValueException { Object value = yamlSection.get(path, null); if (value == null) { - throw new ConfigValueException("value is not set"); + throw new ConfigValueException(ErrorMessages.Config.valueNotSet); } return value; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSyntaxException.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSyntaxException.java index 5f868c0..5d90347 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSyntaxException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSyntaxException.java @@ -4,8 +4,15 @@ import org.bukkit.configuration.InvalidConfigurationException; public class ConfigSyntaxException extends ConfigLoadException { + private final String parsingErrorDetails; + public ConfigSyntaxException(String message, InvalidConfigurationException cause) { super(message, cause); + this.parsingErrorDetails = cause.getMessage(); + } + + public String getParsingErrorDetails() { + return parsingErrorDetails; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java index fd3208f..93f51fd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java @@ -18,6 +18,7 @@ import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; +import me.filoghost.chestcommands.logging.ErrorMessages; import java.nio.file.Path; import java.util.Map; @@ -42,7 +43,7 @@ public class MappedConfigLoader { try { mapper = new ConfigMapper(mappedObject, config); } catch (ReflectiveOperationException e) { - throw new ConfigLoadException("couldn't initialize config mapper for class " + mappedObject.getClass(), e); + throw new ConfigLoadException(ErrorMessages.Config.mapperInitError(mappedObject), e); } // Extract default values from fields @@ -50,7 +51,7 @@ public class MappedConfigLoader { try { defaultValues = mapper.getFieldValues(); } catch (ReflectiveOperationException e) { - throw new ConfigLoadException("couldn't read field values in class " + mappedObject.getClass(), e); + throw new ConfigLoadException(ErrorMessages.Config.fieldReadError(mappedObject), e); } } @@ -65,14 +66,14 @@ public class MappedConfigLoader { try { mapper.injectObjectFields(); } catch (ReflectiveOperationException e) { - throw new ConfigLoadException("couldn't inject fields values in class " + mappedObject.getClass(), e); + throw new ConfigLoadException(ErrorMessages.Config.fieldInjectError(mappedObject), e); } mappedObject.postLoad(); return mappedObject; } - public String getFileName() { - return configLoader.getFileName(); + public Path getFile() { + return configLoader.getFile(); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java index 979927b..a2eaa73 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java @@ -15,11 +15,11 @@ package me.filoghost.chestcommands.icon; import me.filoghost.chestcommands.api.Icon; -import me.filoghost.chestcommands.util.Log; -import me.filoghost.chestcommands.util.Preconditions; -import me.filoghost.chestcommands.util.collection.CollectionUtils; import me.filoghost.chestcommands.placeholder.RelativeString; import me.filoghost.chestcommands.placeholder.RelativeStringList; +import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.chestcommands.util.collection.CollectionUtils; +import me.filoghost.chestcommands.util.logging.Log; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Color; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java index f9a822b..d1f9120 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java @@ -29,7 +29,7 @@ public class UpgradesDoneRegistry { private final Set upgradesDone; private boolean needSave; - public UpgradesDoneRegistry(Path saveFile) throws IOException { + public UpgradesDoneRegistry(Path saveFile) throws IOException { this.saveFile = saveFile; this.upgradesDone = new HashSet<>(); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java index 3fdfdc2..8167dd3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java @@ -24,36 +24,38 @@ import me.filoghost.chestcommands.legacy.upgrade.PlaceholdersYamlUpgrade; import me.filoghost.chestcommands.legacy.upgrade.SettingsUpgrade; import me.filoghost.chestcommands.legacy.upgrade.Upgrade; import me.filoghost.chestcommands.legacy.upgrade.UpgradeException; -import me.filoghost.chestcommands.util.Log; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.util.collection.CollectionUtils; +import me.filoghost.chestcommands.util.logging.ErrorCollector; +import me.filoghost.chestcommands.util.logging.Log; import java.io.IOException; import java.nio.file.Path; -import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.function.Supplier; -import java.util.stream.Collectors; public class UpgradesExecutor { private final ConfigManager configManager; - private List failedUpgrades; + private Set failedUpgrades; private UpgradesDoneRegistry upgradesDoneRegistry; public UpgradesExecutor(ConfigManager configManager) { this.configManager = configManager; } - public void run(boolean isFreshInstall) throws UpgradeExecutorException { - this.failedUpgrades = new ArrayList<>(); + public void run(boolean isFreshInstall, ErrorCollector errorCollector) throws UpgradeExecutorException { + this.failedUpgrades = new HashSet<>(); Path upgradesDoneFile = configManager.getRootDataFolder().resolve(".upgrades-done"); try { upgradesDoneRegistry = new UpgradesDoneRegistry(upgradesDoneFile); } catch (IOException e) { // Upgrades can't proceed if metadata file is not read correctly - throw new UpgradeExecutorException("Couldn't read upgrades metadata file \"" + upgradesDoneFile.getFileName() + "\"", e); + throw new UpgradeExecutorException(ErrorMessages.Upgrade.metadataReadError(upgradesDoneFile), e); } if (isFreshInstall) { @@ -68,9 +70,9 @@ public class UpgradesExecutor { legacyCommandSeparator = null; } - runIfNecessary(UpgradeID.V4_CONFIG, () -> new SettingsUpgrade(configManager)); - runIfNecessary(UpgradeID.V4_PLACEHOLDERS, () -> new PlaceholdersYamlUpgrade(configManager)); - runIfNecessary(UpgradeID.V4_LANG, () -> new LangUpgrade(configManager)); + runIfNecessary(UpgradeID.V4_CONFIG, () -> new SettingsUpgrade(configManager), errorCollector); + runIfNecessary(UpgradeID.V4_PLACEHOLDERS, () -> new PlaceholdersYamlUpgrade(configManager), errorCollector); + runIfNecessary(UpgradeID.V4_LANG, () -> new LangUpgrade(configManager), errorCollector); try { List menuFiles = configManager.getMenuPaths(); @@ -78,15 +80,15 @@ public class UpgradesExecutor { runIfNecessaryMultiple(UpgradeID.V4_MENU_REPLACE, () -> { return CollectionUtils.transform(menuFiles, MenuNodeRenameUpgrade::new); - }); + }, errorCollector); runIfNecessaryMultiple(UpgradeID.V4_MENUS_REFORMAT, () -> { return CollectionUtils.transform(menuFiles, file -> new MenuNodeExpandUpgrade(configManager, file, legacyCommandSeparator)); - }); + }, errorCollector); } catch (IOException e) { - Log.severe("Couldn't obtain a list of menu files. Some automatic upgrades were skipped.", e); + errorCollector.add(ErrorMessages.Upgrade.menuListIOException, e); failedUpgrades.add(configManager.getMenusFolder()); } } @@ -95,15 +97,12 @@ public class UpgradesExecutor { upgradesDoneRegistry.save(); } catch (IOException e) { // Upgrades can't proceed if metadata file is not read correctly - throw new UpgradeExecutorException("Couldn't save upgrades metadata file \"" + upgradesDoneFile.getFileName() + "\"", e); + throw new UpgradeExecutorException(ErrorMessages.Upgrade.metadataSaveError(upgradesDoneFile), e); } // Success only if no upgrade failed if (!failedUpgrades.isEmpty()) { - String failedConversionFiles = failedUpgrades.stream() - .map(Path::toString) - .collect(Collectors.joining(", ")); - throw new UpgradeExecutorException("Failed to automatically upgrade the following files: " + failedConversionFiles); + throw new UpgradeExecutorException(ErrorMessages.Upgrade.failedUpgradesList(failedUpgrades)); } } @@ -117,18 +116,18 @@ public class UpgradesExecutor { try { return settingsConfigLoader.load().getString("multiple-commands-separator"); } catch (Throwable t) { - Log.severe("Failed to load " + settingsConfigLoader.getFileName() + ", assuming default command separator \";\"."); + Log.warning("Failed to load \"" + settingsConfigLoader.getFile() + "\", assuming default command separator \";\"."); return null; } } - private void runIfNecessary(UpgradeID upgradeID, Supplier upgradeTask) { - runIfNecessaryMultiple(upgradeID, () -> Collections.singletonList(upgradeTask.get())); + private void runIfNecessary(UpgradeID upgradeID, Supplier upgradeTask, ErrorCollector errorCollector) { + runIfNecessaryMultiple(upgradeID, () -> Collections.singletonList(upgradeTask.get()), errorCollector); } - private void runIfNecessaryMultiple(UpgradeID upgradeID, Supplier> upgradeTasks) { + private void runIfNecessaryMultiple(UpgradeID upgradeID, Supplier> upgradeTasks, ErrorCollector errorCollector) { if (upgradesDoneRegistry.isDone(upgradeID)) { return; } @@ -141,13 +140,13 @@ public class UpgradesExecutor { if (modified) { Log.info( "Automatically upgraded configuration file \"" - + upgradeTask.getUpgradedFile().getFileName() + "\" with newer configuration nodes. " + + upgradeTask.getUpgradedFile() + "\" with newer configuration nodes. " + "A backup of the old file has been saved."); } } catch (UpgradeException e) { failedAnyUpgrade = true; failedUpgrades.add(upgradeTask.getOriginalFile()); - logUpgradeException(upgradeTask, e); + errorCollector.add(ErrorMessages.Upgrade.failedSingleUpgrade(upgradeTask.getOriginalFile()), e); } } @@ -157,11 +156,4 @@ public class UpgradesExecutor { } } - - private void logUpgradeException(Upgrade upgrade, UpgradeException upgradeException) { - Log.severe( - "Error while trying to automatically upgrade " + upgrade.getOriginalFile() + ": " + upgradeException.getMessage(), - upgradeException.getCause()); - } - } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgrade.java index 1870948..77f5b71 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgrade.java @@ -43,12 +43,12 @@ public class MenuNodeExpandUpgrade extends Upgrade { @Override public Path getOriginalFile() { - return menuConfigLoader.getConfigPath(); + return menuConfigLoader.getFile(); } @Override public Path getUpgradedFile() { - return menuConfigLoader.getConfigPath(); + return menuConfigLoader.getFile(); } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgrade.java index 1e48f6c..94b5b56 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgrade.java @@ -19,6 +19,7 @@ import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.util.Strings; import org.apache.commons.lang.StringEscapeUtils; @@ -45,7 +46,7 @@ public class PlaceholdersYamlUpgrade extends Upgrade { @Override public Path getUpgradedFile() { - return newPlaceholdersConfigLoader.getConfigPath(); + return newPlaceholdersConfigLoader.getFile(); } @Override @@ -55,12 +56,12 @@ public class PlaceholdersYamlUpgrade extends Upgrade { } // Do NOT load the new placeholder configuration from disk, as it should only contain placeholders imported from the old file - Config newPlaceholdersConfig = new Config(newPlaceholdersConfigLoader.getConfigPath()); + Config newPlaceholdersConfig = new Config(newPlaceholdersConfigLoader.getFile()); List lines; try { lines = Files.readAllLines(oldPlaceholdersFile); } catch (IOException e) { - throw new ConfigLoadException("couldn't read file \"" + oldPlaceholdersFile.getFileName() + "\"", e); + throw new ConfigLoadException(ErrorMessages.Config.readIOException, e); } for (String line : lines) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgrade.java index d512276..f323f94 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgrade.java @@ -17,6 +17,7 @@ package me.filoghost.chestcommands.legacy.upgrade; import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; import me.filoghost.chestcommands.legacy.RegexReplacer; +import me.filoghost.chestcommands.logging.ErrorMessages; import java.io.IOException; import java.nio.file.Files; @@ -64,7 +65,7 @@ public class RegexUpgrade extends Upgrade { try { lines = Files.readAllLines(file); } catch (IOException e) { - throw new ConfigLoadException("couldn't read file \"" + file.getFileName() + "\"", e); + throw new ConfigLoadException(ErrorMessages.Config.readIOException, e); } Stream linesStream = lines.stream(); @@ -84,7 +85,7 @@ public class RegexUpgrade extends Upgrade { try { Files.write(file, newContents); } catch (IOException e) { - throw new ConfigSaveException("couldn't save file \"" + file.getFileName() + "\"", e); + throw new ConfigSaveException(ErrorMessages.Config.writeDataIOException, e); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgrade.java index 2f296dd..ca4d425 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgrade.java @@ -33,16 +33,19 @@ public class SettingsUpgrade extends Upgrade { @Override public Path getOriginalFile() { - return settingsConfigLoader.getConfigPath(); + return settingsConfigLoader.getFile(); } @Override public Path getUpgradedFile() { - return settingsConfigLoader.getConfigPath(); + return settingsConfigLoader.getFile(); } @Override protected void computeChanges() throws ConfigLoadException { + if (!settingsConfigLoader.fileExists()) { + return; + } Config settingsConfig = settingsConfigLoader.load(); removeNode(settingsConfig, "use-only-commands-without-args"); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java index d11f81c..7281735 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java @@ -16,6 +16,7 @@ package me.filoghost.chestcommands.legacy.upgrade; import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.util.Preconditions; import java.io.IOException; @@ -42,20 +43,20 @@ public abstract class Upgrade { try { computeChanges(); } catch (ConfigLoadException e) { - throw new UpgradeException("couldn't load file to upgrade \"" + getOriginalFile().getFileName() + "\"", e); + throw new UpgradeException(ErrorMessages.Upgrade.loadError(getOriginalFile()), e); } if (modified) { try { createBackupFile(getOriginalFile()); } catch (IOException e) { - throw new UpgradeException("couldn't create backup of file \"" + getOriginalFile().getFileName() + "\"", e); + throw new UpgradeException(ErrorMessages.Upgrade.backupError(getOriginalFile()), e); } try { saveChanges(); } catch (ConfigSaveException e) { - throw new UpgradeException("couldn't save upgraded file \"" + getUpgradedFile().getFileName() + "\"", e); + throw new UpgradeException(ErrorMessages.Upgrade.saveError(getUpgradedFile()), e); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java index d39cf31..7de0fc9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java @@ -14,21 +14,20 @@ */ package me.filoghost.chestcommands.listener; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.Permissions; import org.bukkit.ChatColor; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.Permissions; - public class JoinListener implements Listener { @EventHandler public void onJoin(PlayerJoinEvent event) { - if (ChestCommands.getLastLoadErrors().hasWarningsOrErrors() && event.getPlayer().hasPermission(Permissions.SEE_ERRORS)) { - event.getPlayer().sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "The plugin found " + ChestCommands.getLastLoadErrors().getWarningsCount() + " warning(s) and " + ChestCommands.getLastLoadErrors().getErrorsCount() + " error(s) last time it was loaded. You can see them by doing \"/cc reload\" in the console."); + if (ChestCommands.getLastLoadErrors().hasErrors() && event.getPlayer().hasPermission(Permissions.SEE_ERRORS)) { + event.getPlayer().sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "The plugin found " + ChestCommands.getLastLoadErrors().getErrorsCount() + " error(s) last time it was loaded. You can see them by doing \"/cc reload\" in the console."); } if (ChestCommands.hasNewVersion() && ChestCommands.getSettings().update_notifications && event.getPlayer().hasPermission(Permissions.UPDATE_NOTIFICATIONS)) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java new file mode 100644 index 0000000..67e931a --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java @@ -0,0 +1,216 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.logging; + +import me.filoghost.chestcommands.config.framework.mapped.MappedConfig; +import me.filoghost.chestcommands.parsing.icon.IconSettings; + +import java.nio.file.Path; +import java.util.Set; +import java.util.stream.Collectors; + +public class ErrorMessages { + + public static class Config { + + public static String readIOException = "I/O exception while reading file"; + public static String createDefaultIOException = "I/O exception while creating default file"; + public static String writeDataIOException = "I/O exception while writing data to file"; + public static String createDataFolderIOException = "Plugin failed to load, couldn't create data folder"; + public static String invalidYamlSyntax = "invalid YAML syntax"; + + public static String valueNotSet = "value is not set"; + public static String valueNotList = "value is not a list"; + public static String valueNotBoolean = "value is not a boolean"; + public static String valueNotNumber = "value is not a number"; + + public static String menuListIOException(Path menuFolder) { + return "couldn't fetch menu files inside the folder \"" + menuFolder + "\""; + } + + public static String initException(Path file) { + return "error while initializing config file \"" + formatPath(file) + "\""; + } + + public static String emptyPlaceholder(Path configFile) { + return "error in \"" + configFile + "\": placeholder cannot be empty (skipped)."; + } + + public static String tooLongPlaceholder(Path configFile, String placeholder) { + return "error in \"" + configFile + "\": placeholder cannot be longer than 100 character (" + placeholder + ")."; + } + + public static String createParentFolderIOException(Path folder) { + return "I/O exception while creating parent directory \"" + formatPath(folder) + "\""; + } + + public static String mapperInitError(MappedConfig mappedConfig) { + return "couldn't initialize config mapper for class \"" + mappedConfig.getClass() + "\""; + } + + public static String fieldReadError(MappedConfig mappedConfig) { + return "couldn't read field values from class \"" + mappedConfig.getClass() + "\""; + } + + public static String fieldInjectError(MappedConfig mappedConfig) { + return "couldn't inject fields values in class \"" + mappedConfig.getClass() + "\""; + } + } + + + public static class Upgrade { + + public static String genericExecutorError = "encountered errors while running run automatic configuration upgrades, " + + "some configuration files or menus may require manual updates."; + public static String menuListIOException = "couldn't obtain a list of menu files, some automatic upgrades were skipped"; + + public static String metadataReadError(Path metadataFile) { + return "couldn't read upgrades metadata file \"" + formatPath(metadataFile) + "\""; + } + + public static String metadataSaveError(Path metadataFile) { + return "couldn't save upgrades metadata file \"" + formatPath(metadataFile) + "\""; + } + + public static String failedSingleUpgrade(Path file) { + return "error while trying to automatically upgrade \"" + formatPath(file) + "\""; + } + + public static String failedUpgradesList(Set failedUpgrades) { + String failedConversionFiles = failedUpgrades.stream() + .map(path -> "\"" + path + "\"") + .collect(Collectors.joining(", ")); + return "failed to automatically upgrade the following files: " + failedConversionFiles; + } + + public static String loadError(Path file) { + return "couldn't load file to upgrade \"" + formatPath(file) + "\""; + } + + public static String backupError(Path file) { + return "couldn't create backup of file \"" + formatPath(file) + "\""; + } + + public static String saveError(Path file) { + return "couldn't save upgraded file \"" + formatPath(file) + "\""; + } + } + + + public static class Parsing { + + public static String invalidDouble = "value is not a valid decimal"; + public static String invalidShort = "value is not a valid short integer"; + public static String invalidInteger = "value not a valid integer"; + + public static String strictlyPositive = "value must be greater than zero"; + public static String zeroOrPositive = "value must be zero or greater"; + + public static String invalidColorFormat = "value must match the format \"red, green, blue\""; + public static String invalidPatternFormat = "value must match the format \"pattern:color\""; + + public static String unknownAttribute = "unknown attribute"; + + public static String unknownMaterial(String materialString) { + return "unknown material \"" + materialString + "\""; + } + + public static String unknownPatternType(String patternTypeString) { + return "unknown pattern type \"" + patternTypeString + "\""; + } + + public static String unknownDyeColor(String dyeColorString) { + return "unknown dye color \"" + dyeColorString + "\""; + } + + public static String unknownEnchantmentType(String typeString) { + return "unknown enchantment type \"" + typeString + "\""; + } + + public static String invalidEnchantmentLevel(String levelString) { + return "invalid enchantment level \"" + levelString + "\","; + } + + public static String invalidDurability(String durabilityString) { + return "invalid durability \"" + durabilityString + "\""; + } + + public static String invalidAmount(String amountString) { + return "invalid amount \"" + amountString + "\""; + } + + public static String invalidColorNumber(String numberString, String colorName) { + return "invalid " + colorName + " color \"" + numberString + "\""; + } + + public static String invalidColorRange(String valueString, String colorName) { + return "invalid " + colorName + " color \"" + valueString + "\", value must be between 0 and 255"; + } + + } + + public static class Menu { + + public static String invalidSetting(Path menuFile, String invalidSetting) { + return menuError(menuFile, "has an invalid menu setting \"" + invalidSetting + "\""); + } + + public static String missingSetting(Path menuFile, String missingSetting) { + return menuError(menuFile, "is missing the menu setting \"" + missingSetting + "\""); + } + + private static String menuError(Path menuFile, String errorMessage) { + return "the menu \"" + formatPath(menuFile) + "\" " + errorMessage; + } + + public static String invalidAttribute(IconSettings iconSettings, String attributeName) { + return iconError(iconSettings, "has an invalid attribute \"" + attributeName + "\""); + } + + public static String missingAttribute(IconSettings iconSettings, String attributeName) { + return iconError(iconSettings, "is missing the attribute \"" + attributeName + "\""); + } + + public static String invalidAttributeListElement(IconSettings iconSettings, String attributeName, String listElement) { + return iconError(iconSettings, + "contains an invalid list element (\"" + listElement + "\") " + + "in the attribute \"" + attributeName + "\""); + } + + public static String iconOverridesAnother(IconSettings iconSettings) { + return iconError(iconSettings, "is overriding another icon with the same position"); + } + + private static String iconError(IconSettings iconSettings, String errorMessage) { + return "the icon \"" + iconSettings.getIconName() + "\" in the menu \"" + + formatPath(iconSettings.getMenuFile()) + "\" " + errorMessage; + } + + public static String duplicateMenuName(Path menuFile1, Path menuFile2) { + return "two menus (\"" + menuFile1 + "\" and \"" + menuFile2 + "\") " + + "have the same file name. Only of them will work when referenced by name"; + } + + public static String duplicateMenuCommand(Path menuFile1, Path menuFile2, String command) { + return "two menus (\"" + menuFile1 + "\" and \"" + menuFile2 + "\") " + + "have the same command \"" + command + "\". Only one will be opened when the command is executed"; + } + } + + private static String formatPath(Path path) { + return path.subpath(2, path.getNameCount()).toString(); // Remove "/plugins/ChestCommands" prefix + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorPrintInfo.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorPrintInfo.java new file mode 100644 index 0000000..03d553c --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorPrintInfo.java @@ -0,0 +1,35 @@ +package me.filoghost.chestcommands.logging; + +import java.util.List; + +class ErrorPrintInfo { + + private final int index; + private final List message; + private final String details; + private final Throwable cause; + + public ErrorPrintInfo(int index, List message, String details, Throwable cause) { + this.index = index; + this.message = message; + this.details = details; + this.cause = cause; + } + + public int getIndex() { + return index; + } + + public List getMessage() { + return message; + } + + public String getDetails() { + return details; + } + + public Throwable getCause() { + return cause; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java new file mode 100644 index 0000000..4c40613 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java @@ -0,0 +1,76 @@ +package me.filoghost.chestcommands.logging; + +import me.filoghost.chestcommands.util.Strings; + +import java.util.List; + +class MessagePartJoiner { + + private final StringBuilder output; + + private String previousMessagePart; + private boolean appendedFirstSentenceSeparator; + + public static String join(List messageParts) { + int estimateLength = getEstimateLength(messageParts); + MessagePartJoiner errorMessageBuilder = new MessagePartJoiner(estimateLength); + for (String messagePart : messageParts) { + errorMessageBuilder.append(messagePart); + } + return errorMessageBuilder.build(); + } + + private static int getEstimateLength(List messageParts) { + int estimateLength = 0; + + // Length of message parts + for (String messagePart : messageParts) { + estimateLength += messagePart.length(); + } + + // Length of separators in between + estimateLength += (messageParts.size() - 1) * 2; + + return estimateLength; + } + + private MessagePartJoiner(int estimateLength) { + output = new StringBuilder(estimateLength); + } + + private void append(String messagePart) { + appendSeparator(); + appendMessagePart(messagePart); + + previousMessagePart = messagePart; + } + + private void appendMessagePart(String messagePart) { + if (previousMessagePart == null || previousMessagePart.endsWith(".")) { + output.append(Strings.capitalizeFirst(messagePart)); + } else { + output.append(messagePart); + } + } + + private void appendSeparator() { + if (previousMessagePart != null) { + if (previousMessagePart.endsWith(".")) { + output.append(" "); + this.appendedFirstSentenceSeparator = false; + + } else if (!appendedFirstSentenceSeparator) { + output.append(": "); + this.appendedFirstSentenceSeparator = true; + + } else { + output.append(", "); + } + } + } + + private String build() { + return output.toString(); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java new file mode 100644 index 0000000..dc49ec6 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java @@ -0,0 +1,91 @@ +package me.filoghost.chestcommands.logging; + +import me.filoghost.chestcommands.config.framework.exception.ConfigException; +import me.filoghost.chestcommands.config.framework.exception.ConfigSyntaxException; +import me.filoghost.chestcommands.legacy.UpgradeExecutorException; +import me.filoghost.chestcommands.legacy.upgrade.UpgradeException; +import me.filoghost.chestcommands.parsing.ParseException; +import me.filoghost.chestcommands.util.logging.ErrorCollector; +import me.filoghost.chestcommands.util.logging.ErrorInfo; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.List; + +public class PrintableErrorCollector extends ErrorCollector { + + + @Override + public void logToConsole() { + StringBuilder output = new StringBuilder(); + output.append(" \n \n"); + + if (errors.size() > 0) { + output.append(ChatColor.RED).append("[ChestCommands] Encountered ").append(errors.size()).append(" error(s) on load:\n"); + output.append(" \n"); + + int index = 1; + for (ErrorInfo error : errors) { + ErrorPrintInfo printFormat = getErrorPrintInfo(index, error); + printError(output, printFormat); + index++; + } + } + + Bukkit.getConsoleSender().sendMessage(output.toString()); + } + + private ErrorPrintInfo getErrorPrintInfo(int index, ErrorInfo error) { + List message = error.getMessage(); + String details = null; + Throwable cause = error.getCause(); + + // Recursively inspect the cause until an unknown or null exception is found + while (true) { + if (cause instanceof ConfigSyntaxException) { + message.add(cause.getMessage()); + details = ((ConfigSyntaxException) cause).getParsingErrorDetails(); + cause = null; // Do not print stacktrace for syntax exceptions + + } else if (cause instanceof ConfigException + || cause instanceof ParseException + || cause instanceof UpgradeException + || cause instanceof UpgradeExecutorException) { + message.add(cause.getMessage()); + cause = cause.getCause(); // Print the cause (or nothing if null), not our "known" exception + + } else { + return new ErrorPrintInfo(index, message, details, cause); + } + } + } + + private void printError(StringBuilder output, ErrorPrintInfo error) { + output.append(ChatColor.YELLOW).append(error.getIndex()).append(") "); + output.append(ChatColor.WHITE).append(MessagePartJoiner.join(error.getMessage())); + + if (error.getDetails() != null) { + output.append(". Details:\n"); + output.append(ChatColor.YELLOW).append(error.getDetails()).append("\n"); + } else { + output.append(".\n"); + } + if (error.getCause() != null) { + output.append(ChatColor.DARK_GRAY); + output.append("--------[ Exception details ]--------\n"); + output.append(getStackTraceString(error.getCause())); + output.append("-------------------------------------\n"); + } + output.append(" \n"); + output.append(ChatColor.RESET); + } + + private String getStackTraceString(Throwable throwable) { + StringWriter stringWriter = new StringWriter(); + throwable.printStackTrace(new PrintWriter(stringWriter)); + return stringWriter.toString(); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java index 5422064..34b0b50 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java @@ -22,24 +22,25 @@ import me.filoghost.chestcommands.util.collection.CollectionUtils; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.nio.file.Path; import java.util.List; public class InternalIconMenu extends BaseIconMenu { - private final String fileName; + private final Path sourceFile; private final String openPermission; private List openActions; private int refreshTicks; - public InternalIconMenu(String title, int rows, String fileName) { + public InternalIconMenu(String title, int rows, Path sourceFile) { super(title, rows); - this.fileName = fileName; - this.openPermission = Permissions.OPEN_MENU_BASE + fileName; + this.sourceFile = sourceFile; + this.openPermission = Permissions.OPEN_MENU_PREFIX + sourceFile.getFileName(); } - public String getFileName() { - return fileName; + public Path getSourceFile() { + return sourceFile; } public void setOpenActions(List openAction) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java index ebf265b..3774cbb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java @@ -16,10 +16,11 @@ package me.filoghost.chestcommands.menu; import me.filoghost.chestcommands.inventory.DefaultItemInventory; import me.filoghost.chestcommands.inventory.ItemInventoryHolder; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.menu.LoadedMenu; import me.filoghost.chestcommands.parsing.menu.OpenTrigger; import me.filoghost.chestcommands.util.collection.CaseInsensitiveMap; -import me.filoghost.chestcommands.util.collection.ErrorCollector; +import me.filoghost.chestcommands.util.logging.ErrorCollector; import org.bukkit.entity.Player; import org.bukkit.event.block.Action; import org.bukkit.inventory.Inventory; @@ -56,19 +57,18 @@ public class MenuManager { public void registerMenu(LoadedMenu loadedMenu, ErrorCollector errorCollector) { InternalIconMenu menu = loadedMenu.getMenu(); - if (menusByFile.containsKey(loadedMenu.getFileName())) { - errorCollector.addError("Two menus have the same file name \"" + loadedMenu.getFileName() + "\". " - + "One of them will not work."); + String fileName = loadedMenu.getSourceFile().getFileName().toString(); + InternalIconMenu sameNameMenu = menusByFile.get(fileName); + if (sameNameMenu != null) { + errorCollector.add(ErrorMessages.Menu.duplicateMenuName(sameNameMenu.getSourceFile(), loadedMenu.getSourceFile())); } - - menusByFile.put(loadedMenu.getFileName(), menu); + menusByFile.put(fileName, menu); for (String triggerCommand : loadedMenu.getTriggerCommands()) { if (!triggerCommand.isEmpty()) { - if (menusByCommand.containsKey(triggerCommand)) { - errorCollector.addError("The menus \"" + menusByCommand.get(triggerCommand).getFileName() + "\" " - + "and \"" + loadedMenu.getFileName() + "\" have the same command \"" + triggerCommand + "\". " - + "Only one will be opened."); + InternalIconMenu sameCommandMenu = menusByCommand.get(triggerCommand); + if (sameCommandMenu != null) { + errorCollector.add(ErrorMessages.Menu.duplicateMenuCommand(sameCommandMenu.getSourceFile(), loadedMenu.getSourceFile(), triggerCommand)); } menusByCommand.put(triggerCommand, menu); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java index 652a2ce..782f55e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java @@ -14,8 +14,9 @@ */ package me.filoghost.chestcommands.parsing; -import me.filoghost.chestcommands.util.collection.Registry; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.util.Strings; +import me.filoghost.chestcommands.util.collection.Registry; import org.bukkit.enchantments.Enchantment; import java.util.Optional; @@ -61,9 +62,9 @@ public class EnchantmentParser { String[] levelSplit = Strings.trimmedSplit(input, ",", 2); try { - level = Integer.parseInt(levelSplit[1].trim()); - } catch (NumberFormatException ex) { - throw new ParseException("invalid enchantment level \"" + levelSplit[1] + "\""); + level = NumberParser.getStrictlyPositiveInteger(levelSplit[1]); + } catch (ParseException e) { + throw new ParseException(ErrorMessages.Parsing.invalidEnchantmentLevel(levelSplit[1]), e); } input = levelSplit[0]; } @@ -73,7 +74,7 @@ public class EnchantmentParser { if (enchantment.isPresent()) { return new EnchantmentDetails(enchantment.get(), level); } else { - throw new ParseException("invalid enchantment type \"" + input + "\""); + throw new ParseException(ErrorMessages.Parsing.unknownEnchantmentType(input)); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ErrorFormat.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ErrorFormat.java deleted file mode 100644 index 7e3c86c..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ErrorFormat.java +++ /dev/null @@ -1,39 +0,0 @@ -package me.filoghost.chestcommands.parsing; - -import me.filoghost.chestcommands.config.framework.Config; -import me.filoghost.chestcommands.parsing.icon.IconSettings; - -public class ErrorFormat { - - public static String invalidMenuSetting(Config menuConfig, String invalidSetting, String errorMessage) { - return menuError(menuConfig, "has an invalid menu setting \"" + invalidSetting + "\": " + errorMessage); - } - - public static String missingMenuSetting(Config menuConfig, String missingSetting) { - return menuError(menuConfig, "is missing the menu setting \"" + missingSetting + "\""); - } - - private static String menuError(Config menuConfig, String errorMessage) { - return "The menu \"" + menuConfig.getSourceFileName() + "\" " + errorMessage + "."; - } - - public static String invalidAttribute(IconSettings iconSettings, String attributeName, String errorMessage) { - return iconError(iconSettings, "has an invalid attribute \"" + attributeName + "\": " + errorMessage); - } - - public static String missingAttribute(IconSettings iconSettings, String attributeName) { - return iconError(iconSettings, "is missing the attribute \"" + attributeName + "\""); - } - - public static String invalidListElement(IconSettings iconSettings, String attributeName, String listElement, String errorMessage) { - return iconError(iconSettings, - "contains an invalid list element (\"" + listElement + "\") " - + "in the attribute \"" + attributeName + "\": " + errorMessage); - } - - public static String iconError(IconSettings iconSettings, String errorMessage) { - return "The icon \"" + iconSettings.getIconName() + "\" " - + "in the menu \"" + iconSettings.getMenuName() + "\" " - + errorMessage + "."; - } -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java index 1470dfe..9194582 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java @@ -14,8 +14,9 @@ */ package me.filoghost.chestcommands.parsing; -import me.filoghost.chestcommands.util.collection.Registry; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.util.Strings; +import me.filoghost.chestcommands.util.collection.Registry; import org.bukkit.Color; import org.bukkit.DyeColor; import org.bukkit.block.banner.Pattern; @@ -33,33 +34,45 @@ public final class ItemMetaParser { String[] split = Strings.trimmedSplit(input, ","); if (split.length != 3) { - throw new ParseException("it must be in the format \"red, green, blue\""); + throw new ParseException(ErrorMessages.Parsing.invalidColorFormat); } - int red = NumberParser.getInteger(split[0], "red is not a number"); - int green = NumberParser.getInteger(split[1], "green is not a number"); - int blue = NumberParser.getInteger(split[2], "blue is not a number"); - - if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) { - throw new ParseException("it should only contain numbers between 0 and 255"); - } + int red = parseColor(split[0], "red"); + int green = parseColor(split[1], "green"); + int blue = parseColor(split[2], "blue"); return Color.fromRGB(red, green, blue); } + private static int parseColor(String valueString, String colorName) throws ParseException { + int value; + + try { + value = NumberParser.getInteger(valueString); + } catch (ParseException e) { + throw new ParseException(ErrorMessages.Parsing.invalidColorNumber(valueString, colorName), e); + } + + if (value < 0 || value > 255) { + throw new ParseException(ErrorMessages.Parsing.invalidColorRange(valueString, colorName)); + } + + return value; + } + public static DyeColor parseDyeColor(String input) throws ParseException { return DYE_COLORS_REGISTRY.find(input) - .orElseThrow(() -> new ParseException("it must be a valid color")); + .orElseThrow(() -> new ParseException(ErrorMessages.Parsing.unknownDyeColor(input))); } public static Pattern parseBannerPattern(String input) throws ParseException { String[] split = Strings.trimmedSplit(input, ":"); if (split.length != 2) { - throw new ParseException("it must be in the format \"pattern:color\""); + throw new ParseException(ErrorMessages.Parsing.invalidPatternFormat); } PatternType patternType = PATTERN_TYPES_REGISTRY.find(split[0]) - .orElseThrow(() -> new ParseException("it must be a valid pattern type")); + .orElseThrow(() -> new ParseException(ErrorMessages.Parsing.unknownPatternType(split[0]))); DyeColor patternColor = parseDyeColor(split[1]); return new Pattern(patternColor, patternType); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java index 5b78f29..537f04e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java @@ -14,12 +14,12 @@ */ package me.filoghost.chestcommands.parsing; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.util.MaterialsHelper; import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.Strings; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; import java.util.Optional; @@ -41,7 +41,11 @@ public class ItemStackParser { String[] splitAmount = Strings.trimmedSplit(input, ",", 2); if (splitAmount.length > 1) { - this.amount = NumberParser.getStrictlyPositiveInteger(splitAmount[1], "invalid amount \"" + splitAmount[1] + "\""); + try { + this.amount = NumberParser.getStrictlyPositiveInteger(splitAmount[1]); + } catch (ParseException e) { + throw new ParseException(ErrorMessages.Parsing.invalidAmount(splitAmount[1]), e); + } // Only keep the first part as input input = splitAmount[0]; @@ -53,10 +57,13 @@ public class ItemStackParser { String[] splitByColons = Strings.trimmedSplit(input, ":", 2); if (splitByColons.length > 1) { - short durability = NumberParser.getPositiveShort(splitByColons[1], "invalid durability \"" + splitByColons[1] + "\""); + try { + this.durability = NumberParser.getPositiveShort(splitByColons[1]); + } catch (ParseException e) { + throw new ParseException(ErrorMessages.Parsing.invalidDurability(splitByColons[1]), e); + } this.hasExplicitDurability = true; - this.durability = durability; // Only keep the first part as input input = splitByColons[0]; @@ -65,7 +72,7 @@ public class ItemStackParser { Optional material = MaterialsHelper.matchMaterial(input); if (!material.isPresent() || MaterialsHelper.isAir(material.get())) { - throw new ParseException("invalid material \"" + input + "\""); + throw new ParseException(ErrorMessages.Parsing.unknownMaterial(input)); } this.material = material.get(); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java index 76e139f..b951fdd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java @@ -14,55 +14,49 @@ */ package me.filoghost.chestcommands.parsing; -public class NumberParser { - - public static double getStrictlyPositiveDouble(String input) throws ParseException { - return getStrictlyPositiveDouble(input, "number must be a valid decimal and greater than 0"); - } +import me.filoghost.chestcommands.logging.ErrorMessages; - public static double getStrictlyPositiveDouble(String input, String errorMessage) throws ParseException { - double value = getDouble(input, errorMessage); - check(value > 0.0, errorMessage); +public class NumberParser { + + public static double getStrictlyPositiveDouble(String input) throws ParseException { + double value = getDouble(input); + check(value > 0.0, ErrorMessages.Parsing.strictlyPositive); return value; } - private static double getDouble(String input, String errorMessage) throws ParseException { + private static double getDouble(String input) throws ParseException { try { return Double.parseDouble(input); } catch (NumberFormatException ex) { - throw new ParseException(errorMessage); + throw new ParseException(ErrorMessages.Parsing.invalidDouble); } } - public static short getPositiveShort(String input, String errorMessage) throws ParseException { - short value = getShort(input, errorMessage); - check(value >= 0, errorMessage); + public static short getPositiveShort(String input) throws ParseException { + short value = getShort(input); + check(value >= 0, ErrorMessages.Parsing.zeroOrPositive); return value; } - public static short getShort(String input, String errorMessage) throws ParseException { + private static short getShort(String input) throws ParseException { try { return Short.parseShort(input); } catch (NumberFormatException ex) { - throw new ParseException(errorMessage); + throw new ParseException(ErrorMessages.Parsing.invalidShort); } } - - public static int getStrictlyPositiveInteger(String input) throws ParseException { - return getStrictlyPositiveInteger(input, "number must be a valid integer and greater than 0"); - } - public static int getStrictlyPositiveInteger(String input, String errorMessage) throws ParseException { - int value = getInteger(input, errorMessage); - check(value > 0, errorMessage); + public static int getStrictlyPositiveInteger(String input) throws ParseException { + int value = getInteger(input); + check(value > 0, ErrorMessages.Parsing.strictlyPositive); return value; } - public static int getInteger(String input, String errorMessage) throws ParseException { + public static int getInteger(String input) throws ParseException { try { return Integer.parseInt(input); } catch (NumberFormatException ex) { - throw new ParseException(errorMessage); + throw new ParseException(ErrorMessages.Parsing.invalidInteger); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ParseException.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ParseException.java index 6ca8851..eb4a58f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ParseException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ParseException.java @@ -21,4 +21,9 @@ public class ParseException extends Exception { public ParseException(String message) { super(message); } + + public ParseException(String message, ParseException cause) { + super(message, cause); + } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeErrorCollector.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeErrorCollector.java index 8e7e19f..78930f4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeErrorCollector.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeErrorCollector.java @@ -1,7 +1,8 @@ package me.filoghost.chestcommands.parsing.icon; -import me.filoghost.chestcommands.parsing.ErrorFormat; -import me.filoghost.chestcommands.util.collection.ErrorCollector; +import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.parsing.ParseException; +import me.filoghost.chestcommands.util.logging.ErrorCollector; public class AttributeErrorCollector { @@ -15,12 +16,8 @@ public class AttributeErrorCollector { this.attributeName = attributeName; } - public void addAttributeError(Exception e) { - errorCollector.addError(ErrorFormat.invalidAttribute(iconSettings, attributeName, e.getMessage())); - } - - public void addListElementError(String listElement, Exception e) { - errorCollector.addError(ErrorFormat.invalidListElement(iconSettings, attributeName, listElement, e.getMessage())); + public void addListElementError(String listElement, ParseException e) { + errorCollector.add(ErrorMessages.Menu.invalidAttributeListElement(iconSettings, attributeName, listElement), e); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java index 2d41e82..efae7a6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java @@ -17,6 +17,7 @@ package me.filoghost.chestcommands.parsing.icon; import me.filoghost.chestcommands.config.framework.ConfigSection; import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.chestcommands.parsing.icon.attributes.ActionsAttribute; import me.filoghost.chestcommands.parsing.icon.attributes.AmountAttribute; @@ -39,8 +40,9 @@ import me.filoghost.chestcommands.parsing.icon.attributes.RequiredItemsAttribute import me.filoghost.chestcommands.parsing.icon.attributes.SkullOwnerAttribute; import me.filoghost.chestcommands.parsing.icon.attributes.ViewPermissionAttribute; import me.filoghost.chestcommands.util.Preconditions; -import me.filoghost.chestcommands.util.collection.ErrorCollector; +import me.filoghost.chestcommands.util.logging.ErrorCollector; +import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -48,7 +50,7 @@ import java.util.Map; public class IconSettings { - private final String menuName; + private final Path menuFile; private final String iconName; private PositionAttribute positionX; @@ -82,8 +84,8 @@ public class IconSettings { addApplicableIconNodeHandler(IconSettingsNode.REQUIRED_ITEMS, ValueExtractor.STRING_LIST, RequiredItemsAttribute::new); } - public String getMenuName() { - return menuName; + public Path getMenuFile() { + return menuFile; } public String getIconName() { @@ -152,26 +154,25 @@ public class IconSettings { iconNodeHandlers.put(node, iconNodeHandler); } - public IconSettings(String menuName, String iconName) { - this.menuName = menuName; + public IconSettings(Path menuFile, String iconName) { + this.menuFile = menuFile; this.iconName = iconName; this.applicableAttributes = new ArrayList<>(); } public void loadFrom(ConfigSection config, ErrorCollector errorCollector) { for (String attributeKey : config.getKeys(false)) { - AttributeErrorCollector attributeErrorCollector = new AttributeErrorCollector(errorCollector, this, attributeKey); - try { IconNodeHandler nodeHandler = iconNodeHandlers.get(attributeKey); if (nodeHandler == null) { - throw new ParseException("unknown attribute"); + throw new ParseException(ErrorMessages.Parsing.unknownAttribute); } + AttributeErrorCollector attributeErrorCollector = new AttributeErrorCollector(errorCollector, this, attributeKey); nodeHandler.handle(this, config, attributeKey, attributeErrorCollector); } catch (ParseException | ConfigValueException e) { - attributeErrorCollector.addAttributeError(e); + errorCollector.add(ErrorMessages.Menu.invalidAttribute(this, attributeKey), e); } } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/AmountAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/AmountAttribute.java index 1c62ad4..90b2e6c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/AmountAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/AmountAttribute.java @@ -15,6 +15,7 @@ package me.filoghost.chestcommands.parsing.icon.attributes; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; @@ -25,7 +26,7 @@ public class AmountAttribute implements ApplicableIconAttribute { public AmountAttribute(int amount, AttributeErrorCollector attributeErrorCollector) throws ParseException { if (amount < 0) { - throw new ParseException("negative value"); + throw new ParseException(ErrorMessages.Parsing.zeroOrPositive); } this.amount = amount; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ExpLevelsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ExpLevelsAttribute.java index 8dbd661..56bff62 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ExpLevelsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ExpLevelsAttribute.java @@ -15,6 +15,7 @@ package me.filoghost.chestcommands.parsing.icon.attributes; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; @@ -25,7 +26,7 @@ public class ExpLevelsAttribute implements ApplicableIconAttribute { public ExpLevelsAttribute(int expLevels, AttributeErrorCollector attributeErrorCollector) throws ParseException { if (expLevels < 0) { - throw new ParseException("negative value"); + throw new ParseException(ErrorMessages.Parsing.zeroOrPositive); } this.expLevels = expLevels; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/MaterialAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/MaterialAttribute.java index 65519f8..a5f63ec 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/MaterialAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/MaterialAttribute.java @@ -15,6 +15,7 @@ package me.filoghost.chestcommands.parsing.icon.attributes; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; @@ -31,7 +32,7 @@ public class MaterialAttribute implements ApplicableIconAttribute { Optional material = MaterialsHelper.matchMaterial(serializedMaterial); if (!material.isPresent() || MaterialsHelper.isAir(material.get())) { - throw new ParseException("invalid material \"" + serializedMaterial + "\""); + throw new ParseException(ErrorMessages.Parsing.unknownMaterial(serializedMaterial)); } this.material = material.get(); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PriceAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PriceAttribute.java index 5582653..9a29795 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PriceAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PriceAttribute.java @@ -15,6 +15,7 @@ package me.filoghost.chestcommands.parsing.icon.attributes; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; @@ -25,7 +26,7 @@ public class PriceAttribute implements ApplicableIconAttribute { public PriceAttribute(double price, AttributeErrorCollector attributeErrorCollector) throws ParseException { if (price < 0) { - throw new ParseException("negative value"); + throw new ParseException(ErrorMessages.Parsing.zeroOrPositive); } this.price = price; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java index 8ea39c5..e892cb9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java @@ -2,18 +2,19 @@ package me.filoghost.chestcommands.parsing.menu; import me.filoghost.chestcommands.menu.InternalIconMenu; +import java.nio.file.Path; import java.util.List; public class LoadedMenu { private final InternalIconMenu menu; - private final String fileName; + private final Path sourceFile; private final List triggerCommands; private final OpenTrigger openTrigger; - public LoadedMenu(InternalIconMenu menu, String fileName, List triggerCommands, OpenTrigger openTrigger) { + public LoadedMenu(InternalIconMenu menu, Path menuFile, List triggerCommands, OpenTrigger openTrigger) { this.menu = menu; - this.fileName = fileName; + this.sourceFile = menuFile; this.triggerCommands = triggerCommands; this.openTrigger = openTrigger; } @@ -22,8 +23,8 @@ public class LoadedMenu { return menu; } - public String getFileName() { - return fileName; + public Path getSourceFile() { + return sourceFile; } public List getTriggerCommands() { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index 7a25b4b..9f67b56 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -19,15 +19,15 @@ import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.config.framework.ConfigSection; import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.menu.InternalIconMenu; import me.filoghost.chestcommands.parsing.ActionParser; -import me.filoghost.chestcommands.parsing.ErrorFormat; import me.filoghost.chestcommands.parsing.ItemStackParser; import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.chestcommands.parsing.icon.IconSettings; import me.filoghost.chestcommands.parsing.icon.IconSettingsNode; import me.filoghost.chestcommands.util.Colors; -import me.filoghost.chestcommands.util.collection.ErrorCollector; +import me.filoghost.chestcommands.util.logging.ErrorCollector; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -41,51 +41,50 @@ public class MenuParser { MenuSettings menuSettings = loadMenuSettings(menuConfig, errorCollector); List iconSettingsList = loadIconSettingsList(menuConfig, errorCollector); - InternalIconMenu iconMenu = new InternalIconMenu(menuSettings.getTitle(), menuSettings.getRows(), menuConfig.getSourceFileName()); + InternalIconMenu iconMenu = new InternalIconMenu(menuSettings.getTitle(), menuSettings.getRows(), menuConfig.getSourceFile()); for (IconSettings iconSettings : iconSettingsList) { - try { - addIconToMenu(iconMenu, iconSettings, errorCollector); - } catch (IconAddException e) { - errorCollector.addError(e.getMessage()); - } + tryAddIconToMenu(iconMenu, iconSettings, errorCollector); } iconMenu.setRefreshTicks(menuSettings.getRefreshTicks()); iconMenu.setOpenActions(menuSettings.getOpenActions()); - return new LoadedMenu(iconMenu, menuConfig.getSourceFileName(), menuSettings.getCommands(), menuSettings.getOpenTrigger()); + return new LoadedMenu(iconMenu, menuConfig.getSourceFile(), menuSettings.getCommands(), menuSettings.getOpenTrigger()); } - private static void addIconToMenu(InternalIconMenu iconMenu, IconSettings iconSettings, ErrorCollector errorCollector) throws IconAddException { + private static void tryAddIconToMenu(InternalIconMenu iconMenu, IconSettings iconSettings, ErrorCollector errorCollector) { if (iconSettings.getPositionX() == null) { - throw new IconAddException(ErrorFormat.missingAttribute(iconSettings, IconSettingsNode.POSITION_X)); + errorCollector.add(ErrorMessages.Menu.missingAttribute(iconSettings, IconSettingsNode.POSITION_X)); + return; } if (iconSettings.getPositionY() == null) { - throw new IconAddException(ErrorFormat.missingAttribute(iconSettings, IconSettingsNode.POSITION_Y)); + errorCollector.add(ErrorMessages.Menu.missingAttribute(iconSettings, IconSettingsNode.POSITION_Y)); + return; } int row = iconSettings.getPositionY().getPosition() - 1; int column = iconSettings.getPositionX().getPosition() - 1; if (row < 0 || row >= iconMenu.getRowCount()) { - throw new IconAddException(ErrorFormat.invalidAttribute(iconSettings, IconSettingsNode.POSITION_Y, - "it must be between 1 and " + iconMenu.getRowCount())); + errorCollector.add(ErrorMessages.Menu.invalidAttribute(iconSettings, IconSettingsNode.POSITION_Y)) + .appendMessage("it must be between 1 and " + iconMenu.getRowCount()); + return; } if (column < 0 || column >= iconMenu.getColumnCount()) { - throw new IconAddException(ErrorFormat.invalidAttribute(iconSettings, IconSettingsNode.POSITION_X, - "it must be between 1 and " + iconMenu.getColumnCount())); + errorCollector.add(ErrorMessages.Menu.invalidAttribute(iconSettings, IconSettingsNode.POSITION_X)) + .appendMessage(("it must be between 1 and " + iconMenu.getColumnCount())); + return; } if (iconMenu.getIcon(row, column) != null) { - throw new IconAddException(ErrorFormat.iconError(iconSettings, - "is overriding another icon with the same position")); + errorCollector.add(ErrorMessages.Menu.iconOverridesAnother(iconSettings)); } if (iconSettings.getMaterialAttribute() == null) { - errorCollector.addError(ErrorFormat.missingAttribute(iconSettings, IconSettingsNode.MATERIAL)); + errorCollector.add(ErrorMessages.Menu.missingAttribute(iconSettings, IconSettingsNode.MATERIAL)); } InternalConfigurableIcon icon = new InternalConfigurableIcon(Material.BEDROCK); @@ -105,7 +104,7 @@ public class MenuParser { } } catch (ConfigValueException e) { title = ChatColor.DARK_RED + "No name set"; - errorCollector.addError(ErrorFormat.missingMenuSetting(config, MenuSettingsNode.NAME)); + errorCollector.add(ErrorMessages.Menu.missingSetting(config.getSourceFile(), MenuSettingsNode.NAME)); } int rows; @@ -116,7 +115,7 @@ public class MenuParser { } } catch (ConfigValueException e) { rows = 6; // Defaults to 6 rows - errorCollector.addError(ErrorFormat.missingMenuSetting(config, MenuSettingsNode.ROWS)); + errorCollector.add(ErrorMessages.Menu.missingSetting(config.getSourceFile(), MenuSettingsNode.ROWS)); } MenuSettings menuSettings = new MenuSettings(title, rows); @@ -157,7 +156,8 @@ public class MenuParser { menuSettings.setOpenTrigger(openTrigger); } catch (ParseException e) { - errorCollector.addError(ErrorFormat.invalidMenuSetting(config, MenuSettingsNode.OPEN_ITEM_MATERIAL, e.getMessage())); + errorCollector.add( + ErrorMessages.Menu.invalidSetting(config.getSourceFile(), MenuSettingsNode.OPEN_ITEM_MATERIAL), e); } } } @@ -183,7 +183,7 @@ public class MenuParser { } ConfigSection iconSection = config.getConfigSection(iconSectionName); - IconSettings iconSettings = new IconSettings(config.getSourceFileName(), iconSectionName); + IconSettings iconSettings = new IconSettings(config.getSourceFile(), iconSectionName); iconSettings.loadFrom(iconSection, errorCollector); iconSettingsList.add(iconSettings); } @@ -191,13 +191,4 @@ public class MenuParser { return iconSettingsList; } - - private static class IconAddException extends Exception { - - public IconAddException(String message) { - super(message); - } - - } - } diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java index 42c1ae7..83e1cd3 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java @@ -59,7 +59,9 @@ public final class Strings { } public static String capitalizeFully(String input) { - if (input == null) return null; + if (input == null) { + return null; + } String s = input.toLowerCase(); @@ -82,8 +84,15 @@ public final class Strings { return output.toString(); } + public static String capitalizeFirst(String input) { + if (isNullOrEmpty(input)) { + return input; + } + + return Character.toTitleCase(input.charAt(0)) + input.substring(1); + } + public static boolean isNullOrEmpty(String s) { return s == null || s.isEmpty(); } - } diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/ErrorCollector.java b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/ErrorCollector.java deleted file mode 100644 index f281079..0000000 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/ErrorCollector.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.util.collection; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; - -/** - * This is a class to collect all the errors found while loading the plugin. - */ -public class ErrorCollector { - - private final List errors = new ArrayList<>(); - private final List warnings = new ArrayList<>(); - - public void addError(String error) { - errors.add(error); - } - - public void addWarning(String warning) { - warnings.add(warning); - } - - public int getErrorsCount() { - return errors.size(); - } - - public int getWarningsCount() { - return warnings.size(); - } - - public boolean hasWarningsOrErrors() { - return errors.size() > 0 || warnings.size() > 0; - } - - public void logToConsole() { - StringBuilder msg = new StringBuilder(200); - msg.append(" \n \n"); - - if (errors.size() > 0) { - msg.append(ChatColor.RED + "[ChestCommands] Encountered " + errors.size() + " error(s) on load:\n"); - appendNumberedList(msg, errors); - } - - if (warnings.size() > 0) { - msg.append(ChatColor.YELLOW + "[ChestCommands] Encountered " + warnings.size() + " warnings(s) on load:\n"); - appendNumberedList(msg, warnings); - } - - Bukkit.getConsoleSender().sendMessage(msg.toString()); - } - - private void appendNumberedList(StringBuilder output, List lines) { - int count = 1; - for (String line : lines) { - output.append(ChatColor.WHITE).append(count).append(") ").append(line); - output.append("\n"); - count++; - } - } - -} diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorCollector.java b/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorCollector.java new file mode 100644 index 0000000..d963c0e --- /dev/null +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorCollector.java @@ -0,0 +1,48 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.util.logging; + +import java.util.ArrayList; +import java.util.List; + +/** + * This is a class to collect all the errors found while loading the plugin. + */ +public abstract class ErrorCollector { + + protected final List errors = new ArrayList<>(); + + public ErrorInfo add(String message) { + return add(message, null); + } + + public ErrorInfo add(String message, Throwable throwable) { + ErrorInfo errorInfo = new ErrorInfo(message); + errorInfo.setCause(throwable); + errors.add(errorInfo); + return errorInfo; + } + + public int getErrorsCount() { + return errors.size(); + } + + public boolean hasErrors() { + return errors.size() > 0; + } + + public abstract void logToConsole(); + +} \ No newline at end of file diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorInfo.java b/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorInfo.java new file mode 100644 index 0000000..0858d0e --- /dev/null +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorInfo.java @@ -0,0 +1,33 @@ +package me.filoghost.chestcommands.util.logging; + +import java.util.ArrayList; +import java.util.List; + +public class ErrorInfo { + + private final List message; + private Throwable cause; + + protected ErrorInfo(String messagePart) { + this.message = new ArrayList<>(); + this.message.add(messagePart); + } + + public ErrorInfo appendMessage(String messagePart) { + message.add(messagePart); + return this; + } + + public List getMessage() { + return message; + } + + public Throwable getCause() { + return cause; + } + + public void setCause(Throwable cause) { + this.cause = cause; + } + +} diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Log.java b/Utils/src/main/java/me/filoghost/chestcommands/util/logging/Log.java similarity index 96% rename from Utils/src/main/java/me/filoghost/chestcommands/util/Log.java rename to Utils/src/main/java/me/filoghost/chestcommands/util/logging/Log.java index 46612d8..05507ff 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Log.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/logging/Log.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.util; +package me.filoghost.chestcommands.util.logging; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java index d52296b..03c1be3 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java @@ -167,7 +167,7 @@ public enum NBTType { /** * Returns whether this tag type is primitive, meaning that it is not a {@link NBTByteArray}, {@link NBTIntArray}, - * {@link NBTList}, {@link NBTCompound} or {@link NBTEnd}. + * {@link NBTList}, {@link NBTCompound}. * * @return whether this type is numeric */ diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java index 14f4ef0..02f1619 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java @@ -1,7 +1,5 @@ package me.filoghost.chestcommands.util.nbt.parser; -import org.bukkit.ChatColor; - import java.io.IOException; public class MojangsonParseException extends IOException { @@ -18,8 +16,8 @@ public class MojangsonParseException extends IOException { if (i > 35) { builder.append("..."); } - builder.append(content.substring(Math.max(0, i - 35), i)); - builder.append(ChatColor.GOLD + "<--[HERE]"); + builder.append(content, Math.max(0, i - 35), i); + builder.append("<--[HERE]"); return builder.toString(); } From f7bb6a1c632a11629bb67e9ab5c5821a31d34e1c Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 19 Jul 2020 12:42:15 +0200 Subject: [PATCH 138/213] Cleanup --- .../chestcommands/hook/PluginHook.java | 2 +- .../chestcommands/hook/VaultEconomyHook.java | 22 +++-------- .../chestcommands/logging/ErrorMessages.java | 38 +++++++++---------- 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java index 4e92bbc..812ccc0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java @@ -23,7 +23,7 @@ public interface PluginHook { boolean isEnabled(); - public default void checkEnabledState() { + default void checkEnabledState() { Preconditions.checkState(isEnabled(), "Plugin hook " + getClass().getSimpleName() + " is not enabled"); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java index d673387..acfd36c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java @@ -14,13 +14,12 @@ */ package me.filoghost.chestcommands.hook; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.RegisteredServiceProvider; - import me.filoghost.chestcommands.util.Preconditions; import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.EconomyResponse; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.RegisteredServiceProvider; public enum VaultEconomyHook implements PluginHook { @@ -59,12 +58,7 @@ public enum VaultEconomyHook implements PluginHook { checkPositiveAmount(minimum); double balance = INSTANCE.economy.getBalance(player, player.getWorld().getName()); - - if (balance < minimum) { - return false; - } else { - return true; - } + return balance >= minimum; } /** @@ -75,9 +69,7 @@ public enum VaultEconomyHook implements PluginHook { checkPositiveAmount(amount); EconomyResponse response = INSTANCE.economy.withdrawPlayer(player, player.getWorld().getName(), amount); - boolean result = response.transactionSuccess(); - - return result; + return response.transactionSuccess(); } public static boolean giveMoney(Player player, double amount) { @@ -85,9 +77,7 @@ public enum VaultEconomyHook implements PluginHook { checkPositiveAmount(amount); EconomyResponse response = INSTANCE.economy.depositPlayer(player, player.getWorld().getName(), amount); - boolean result = response.transactionSuccess(); - - return result; + return response.transactionSuccess(); } private static void checkPositiveAmount(double amount) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java index 67e931a..1d750a0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java @@ -25,16 +25,16 @@ public class ErrorMessages { public static class Config { - public static String readIOException = "I/O exception while reading file"; - public static String createDefaultIOException = "I/O exception while creating default file"; - public static String writeDataIOException = "I/O exception while writing data to file"; - public static String createDataFolderIOException = "Plugin failed to load, couldn't create data folder"; - public static String invalidYamlSyntax = "invalid YAML syntax"; + public static final String readIOException = "I/O exception while reading file"; + public static final String createDefaultIOException = "I/O exception while creating default file"; + public static final String writeDataIOException = "I/O exception while writing data to file"; + public static final String createDataFolderIOException = "Plugin failed to load, couldn't create data folder"; + public static final String invalidYamlSyntax = "invalid YAML syntax"; - public static String valueNotSet = "value is not set"; - public static String valueNotList = "value is not a list"; - public static String valueNotBoolean = "value is not a boolean"; - public static String valueNotNumber = "value is not a number"; + public static final String valueNotSet = "value is not set"; + public static final String valueNotList = "value is not a list"; + public static final String valueNotBoolean = "value is not a boolean"; + public static final String valueNotNumber = "value is not a number"; public static String menuListIOException(Path menuFolder) { return "couldn't fetch menu files inside the folder \"" + menuFolder + "\""; @@ -72,9 +72,9 @@ public class ErrorMessages { public static class Upgrade { - public static String genericExecutorError = "encountered errors while running run automatic configuration upgrades, " + public static final String genericExecutorError = "encountered errors while running run automatic configuration upgrades, " + "some configuration files or menus may require manual updates."; - public static String menuListIOException = "couldn't obtain a list of menu files, some automatic upgrades were skipped"; + public static final String menuListIOException = "couldn't obtain a list of menu files, some automatic upgrades were skipped"; public static String metadataReadError(Path metadataFile) { return "couldn't read upgrades metadata file \"" + formatPath(metadataFile) + "\""; @@ -111,17 +111,17 @@ public class ErrorMessages { public static class Parsing { - public static String invalidDouble = "value is not a valid decimal"; - public static String invalidShort = "value is not a valid short integer"; - public static String invalidInteger = "value not a valid integer"; + public static final String invalidDouble = "value is not a valid decimal"; + public static final String invalidShort = "value is not a valid short integer"; + public static final String invalidInteger = "value not a valid integer"; - public static String strictlyPositive = "value must be greater than zero"; - public static String zeroOrPositive = "value must be zero or greater"; + public static final String strictlyPositive = "value must be greater than zero"; + public static final String zeroOrPositive = "value must be zero or greater"; - public static String invalidColorFormat = "value must match the format \"red, green, blue\""; - public static String invalidPatternFormat = "value must match the format \"pattern:color\""; + public static final String invalidColorFormat = "value must match the format \"red, green, blue\""; + public static final String invalidPatternFormat = "value must match the format \"pattern:color\""; - public static String unknownAttribute = "unknown attribute"; + public static final String unknownAttribute = "unknown attribute"; public static String unknownMaterial(String materialString) { return "unknown material \"" + materialString + "\""; From 01a04d19ff43bf2c9e1e45908419654ba031749a Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 19 Jul 2020 16:27:24 +0200 Subject: [PATCH 139/213] Log errors at loading time, display a recap at startup end --- .../chestcommands/ChestCommands.java | 7 +++++- .../chestcommands/command/CommandHandler.java | 22 +++++++++++++++++-- .../logging/PrintableErrorCollector.java | 1 - 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 114f542..5ae2d6b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -138,7 +138,12 @@ public class ChestCommands extends JavaPlugin { ErrorCollector errorCollector = load(); if (errorCollector.hasErrors()) { - Bukkit.getScheduler().runTaskLater(this, errorCollector::logToConsole, 10L); + errorCollector.logToConsole(); + Bukkit.getScheduler().runTaskLater(this, () -> { + Bukkit.getConsoleSender().sendMessage( + ChatColor.RED + "[ChestCommands] Encountered " + errorCollector.getErrorsCount() + " on load. " + + "Check previous console logs or run \"/chestcommands errors\" to see them again."); + }, 10L); } Bukkit.getScheduler().runTaskTimer(this, new TickingTask(), 1L, 1L); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index 0d00136..8367ade 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -51,14 +51,32 @@ public class CommandHandler extends CommandFramework { if (args[0].equalsIgnoreCase("help")) { CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "help"), "You don't have permission."); - sender.sendMessage(ChestCommands.CHAT_PREFIX + " Commands:"); + sender.sendMessage(ChestCommands.CHAT_PREFIX + "Commands:"); sender.sendMessage(ChatColor.WHITE + "/" + label + " reload" + ChatColor.GRAY + " - Reloads the plugin."); + sender.sendMessage(ChatColor.WHITE + "/" + label + " errors" + ChatColor.GRAY + " - Displays the last load errors on the console."); sender.sendMessage(ChatColor.WHITE + "/" + label + " list" + ChatColor.GRAY + " - Lists the loaded menus."); sender.sendMessage(ChatColor.WHITE + "/" + label + " open [player]" + ChatColor.GRAY + " - Opens a menu for a player."); return; } + if (args[0].equalsIgnoreCase("errors")) { + CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "errors"), "You don't have permission."); + ErrorCollector errorCollector = ChestCommands.getLastLoadErrors(); + + if (errorCollector.hasErrors()) { + errorCollector.logToConsole(); + sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Last time the plugin loaded, " + errorCollector.getErrorsCount() + " error(s) were found."); + if (!(sender instanceof ConsoleCommandSender)) { + sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Errors were printed on the console."); + } + } else { + sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.GREEN + "Last plugin load was successful, no errors logged."); + } + return; + } + + if (args[0].equalsIgnoreCase("reload")) { CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "reload"), "You don't have permission."); @@ -125,7 +143,7 @@ public class CommandHandler extends CommandFramework { if (args[0].equalsIgnoreCase("list")) { CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "list"), "You don't have permission."); - sender.sendMessage(ChestCommands.CHAT_PREFIX + " Loaded menus:"); + sender.sendMessage(ChestCommands.CHAT_PREFIX + "Loaded menus:"); for (String file : menuManager.getMenuFileNames()) { sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.WHITE + file); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java index dc49ec6..60b6e74 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java @@ -20,7 +20,6 @@ public class PrintableErrorCollector extends ErrorCollector { @Override public void logToConsole() { StringBuilder output = new StringBuilder(); - output.append(" \n \n"); if (errors.size() > 0) { output.append(ChatColor.RED).append("[ChestCommands] Encountered ").append(errors.size()).append(" error(s) on load:\n"); From 98e768a1f9c07db7b8cdd7f8a07053dee7112fd6 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 19 Jul 2020 16:35:24 +0200 Subject: [PATCH 140/213] Small refactoring --- .../chestcommands/ChestCommands.java | 2 +- .../chestcommands/command/CommandHandler.java | 19 ++++++++++++------- .../chestcommands/listener/SignListener.java | 16 +++------------- .../logging/PrintableErrorCollector.java | 3 ++- .../filoghost/chestcommands/util/Utils.java | 11 +++++++++++ 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 5ae2d6b..e24644c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -141,7 +141,7 @@ public class ChestCommands extends JavaPlugin { errorCollector.logToConsole(); Bukkit.getScheduler().runTaskLater(this, () -> { Bukkit.getConsoleSender().sendMessage( - ChatColor.RED + "[ChestCommands] Encountered " + errorCollector.getErrorsCount() + " on load. " + ChestCommands.CHAT_PREFIX + ChatColor.RED + "Encountered " + errorCollector.getErrorsCount() + " error(s) on load. " + "Check previous console logs or run \"/chestcommands errors\" to see them again."); }, 10L); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index 8367ade..fa03e93 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -20,6 +20,7 @@ import me.filoghost.chestcommands.command.framework.CommandFramework; import me.filoghost.chestcommands.command.framework.CommandValidate; import me.filoghost.chestcommands.menu.InternalIconMenu; import me.filoghost.chestcommands.menu.MenuManager; +import me.filoghost.chestcommands.util.Utils; import me.filoghost.chestcommands.util.logging.ErrorCollector; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -50,7 +51,7 @@ public class CommandHandler extends CommandFramework { if (args[0].equalsIgnoreCase("help")) { - CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "help"), "You don't have permission."); + checkCommandPermission(sender, "help"); sender.sendMessage(ChestCommands.CHAT_PREFIX + "Commands:"); sender.sendMessage(ChatColor.WHITE + "/" + label + " reload" + ChatColor.GRAY + " - Reloads the plugin."); sender.sendMessage(ChatColor.WHITE + "/" + label + " errors" + ChatColor.GRAY + " - Displays the last load errors on the console."); @@ -61,7 +62,7 @@ public class CommandHandler extends CommandFramework { if (args[0].equalsIgnoreCase("errors")) { - CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "errors"), "You don't have permission."); + checkCommandPermission(sender, "errors"); ErrorCollector errorCollector = ChestCommands.getLastLoadErrors(); if (errorCollector.hasErrors()) { @@ -78,7 +79,7 @@ public class CommandHandler extends CommandFramework { if (args[0].equalsIgnoreCase("reload")) { - CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "reload"), "You don't have permission."); + checkCommandPermission(sender, "reload"); ChestCommands.closeAllMenus(); @@ -98,14 +99,14 @@ public class CommandHandler extends CommandFramework { if (args[0].equalsIgnoreCase("open")) { - CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "open"), "You don't have permission."); + checkCommandPermission(sender, "open"); CommandValidate.minLength(args, 2, "Usage: /" + label + " open [player]"); Player target; if (sender instanceof Player) { if (args.length > 2) { - CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "open.others"), "You don't have permission to open menus for others."); + checkCommandPermission(sender, "open.others"); target = Bukkit.getPlayerExact(args[2]); } else { target = (Player) sender; @@ -117,7 +118,7 @@ public class CommandHandler extends CommandFramework { CommandValidate.notNull(target, "That player is not online."); - String menuName = args[1].toLowerCase().endsWith(".yml") ? args[1] : args[1] + ".yml"; + String menuName = Utils.addYamlExtension(args[1]); InternalIconMenu menu = menuManager.getMenuByFileName(menuName); CommandValidate.notNull(menu, "The menu \"" + menuName + "\" was not found."); @@ -142,7 +143,7 @@ public class CommandHandler extends CommandFramework { if (args[0].equalsIgnoreCase("list")) { - CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "list"), "You don't have permission."); + checkCommandPermission(sender, "list"); sender.sendMessage(ChestCommands.CHAT_PREFIX + "Loaded menus:"); for (String file : menuManager.getMenuFileNames()) { sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.WHITE + file); @@ -154,4 +155,8 @@ public class CommandHandler extends CommandFramework { sender.sendMessage(ChatColor.RED + "Unknown sub-command \"" + args[0] + "\"."); } + private void checkCommandPermission(CommandSender sender, String commandPermission) { + CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + commandPermission), "You don't have permission."); + } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java index c2eb47b..2b5d327 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java @@ -18,6 +18,7 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.menu.InternalIconMenu; import me.filoghost.chestcommands.menu.MenuManager; +import me.filoghost.chestcommands.util.Utils; import org.bukkit.ChatColor; import org.bukkit.block.BlockState; import org.bukkit.block.Sign; @@ -63,7 +64,7 @@ public class SignListener implements Listener { return; } - String menuFileName = addYamlExtension(sign.getLine(FILENAME_LINE).trim()); + String menuFileName = Utils.addYamlExtension(sign.getLine(FILENAME_LINE).trim()); InternalIconMenu menu = menuManager.getMenuByFileName(menuFileName); if (menu == null) { @@ -85,7 +86,7 @@ public class SignListener implements Listener { return; } - menuFileName = addYamlExtension(menuFileName); + menuFileName = Utils.addYamlExtension(menuFileName); InternalIconMenu iconMenu = menuManager.getMenuByFileName(menuFileName); if (iconMenu == null) { @@ -120,16 +121,5 @@ public class SignListener implements Listener { private boolean canCreateMenuSign(Player player) { return player.hasPermission(Permissions.SIGN_CREATE); } - - private String addYamlExtension(String fileName) { - if (fileName == null) { - return null; - } - if (fileName.toLowerCase().endsWith(".yml")) { - return fileName; - } else { - return fileName + ".yml"; - } - } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java index 60b6e74..c38ee62 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java @@ -1,5 +1,6 @@ package me.filoghost.chestcommands.logging; +import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.config.framework.exception.ConfigException; import me.filoghost.chestcommands.config.framework.exception.ConfigSyntaxException; import me.filoghost.chestcommands.legacy.UpgradeExecutorException; @@ -22,7 +23,7 @@ public class PrintableErrorCollector extends ErrorCollector { StringBuilder output = new StringBuilder(); if (errors.size() > 0) { - output.append(ChatColor.RED).append("[ChestCommands] Encountered ").append(errors.size()).append(" error(s) on load:\n"); + output.append(ChestCommands.CHAT_PREFIX).append(ChatColor.RED).append("Encountered ").append(errors.size()).append(" error(s) on load:\n"); output.append(" \n"); int index = 1; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java index f81468b..11effab 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java @@ -15,4 +15,15 @@ public class Utils { return Strings.capitalizeFully(enumValue.name().replace("_", " ")); } + public static String addYamlExtension(String fileName) { + if (fileName == null) { + return null; + } + if (fileName.toLowerCase().endsWith(".yml")) { + return fileName; + } else { + return fileName + ".yml"; + } + } + } From 207a2c59fcb5ca4a451ad39aef7017a9d9f5b830 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 19 Jul 2020 21:01:37 +0200 Subject: [PATCH 141/213] Improve fatal error logging in onEnable --- .../chestcommands/BaseJavaPlugin.java | 63 +++++++++++++++++++ .../chestcommands/ChestCommands.java | 52 +++++---------- 2 files changed, 77 insertions(+), 38 deletions(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java b/Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java new file mode 100644 index 0000000..7ef3b28 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java @@ -0,0 +1,63 @@ +package me.filoghost.chestcommands; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.ArrayList; +import java.util.List; + +public abstract class BaseJavaPlugin extends JavaPlugin { + + @Override + public final void onEnable() { + try { + onCheckedEnable(); + } catch (PluginEnableException e) { + criticalShutdown(e.getMessage()); + } + } + + protected abstract void onCheckedEnable() throws PluginEnableException; + + + private void criticalShutdown(String errorMessage) { + String separator = "**********"; + + List output = new ArrayList<>(); + + output.add(ChatColor.DARK_RED + "[" + getDescription().getName() + "]" + ChatColor.RED + " Fatal error while enabling plugin:"); + output.add(" "); + output.add(separator); + output.add(" "); + output.add(errorMessage); + output.add(" "); + output.add("The plugin has been disabled."); + output.add(" "); + output.add(separator); + output.add(" "); + + Bukkit.getConsoleSender().sendMessage(String.join("\n", output)); + + try { + Thread.sleep(5000); + } catch (InterruptedException ignored) {} + + Bukkit.getScheduler().runTaskLater(this, () -> { + Bukkit.getConsoleSender().sendMessage( + ChatColor.DARK_RED + "[" + getDescription().getName() + "]" + + ChatColor.RED + " Fatal error while enabling plugin. Check previous console logs to find the cause."); + }, 10); + + setEnabled(false); + } + + + public static class PluginEnableException extends Exception { + + public PluginEnableException(String message) { + super(message); + } + + } +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index e24644c..6b64cf2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -45,14 +45,12 @@ import org.bstats.bukkit.MetricsLite; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; import java.io.IOException; import java.nio.file.Files; -import java.util.ArrayList; import java.util.List; -public class ChestCommands extends JavaPlugin { +public class ChestCommands extends BaseJavaPlugin { public static final String CHAT_PREFIX = ChatColor.DARK_GREEN + "[" + ChatColor.GREEN + "ChestCommands" + ChatColor.DARK_GREEN + "] " + ChatColor.GREEN; @@ -70,7 +68,15 @@ public class ChestCommands extends JavaPlugin { private static String newVersion; @Override - public void onEnable() { + protected void onCheckedEnable() throws PluginEnableException { + if (!Utils.isClassLoaded("org.bukkit.inventory.ItemFlag")) { // ItemFlag was added in 1.8 + if (Bukkit.getVersion().contains("(MC: 1.8)")) { + throw new PluginEnableException("ChestCommands requires a more recent version of Bukkit 1.8 to run."); + } else { + throw new PluginEnableException("ChestCommands requires at least Bukkit 1.8 to run."); + } + } + if (instance != null || System.getProperty("ChestCommandsLoaded") != null) { Log.warning("Please do not use /reload or plugin reloaders. Use the command \"/cc reload\" instead."); return; @@ -87,22 +93,15 @@ public class ChestCommands extends JavaPlugin { settings = new Settings(); lang = new Lang(); placeholders = new CustomPlaceholders(); - - if (!Utils.isClassLoaded("org.bukkit.inventory.ItemFlag")) { // ItemFlag was added in 1.8 - if (Bukkit.getVersion().contains("(MC: 1.8)")) { - criticalShutdown("ChestCommands requires a more recent version of Bukkit 1.8 to run."); - } else { - criticalShutdown("ChestCommands requires at least Bukkit 1.8 to run."); - } - return; - } - + VaultEconomyHook.INSTANCE.setup(); BarAPIHook.INSTANCE.setup(); PlaceholderAPIHook.INSTANCE.setup(); BungeeCordHook.INSTANCE.setup(); - if (!VaultEconomyHook.INSTANCE.isEnabled()) { + if (VaultEconomyHook.INSTANCE.isEnabled()) { + Log.info("Hooked Vault"); + } else { Log.warning("Couldn't find Vault and a compatible economy plugin! Money-related features will not work."); } @@ -233,27 +232,4 @@ public class ChestCommands extends JavaPlugin { return lastLoadErrors; } - private static void criticalShutdown(String... errorMessage) { - String separator = "****************************************************************************"; - - List output = new ArrayList<>(); - - output.add(" "); - output.add(separator); - for (String line : errorMessage) { - output.add(" " + line); - } - output.add(" "); - output.add(" This plugin has been disabled."); - output.add(separator); - output.add(" "); - - System.out.println("\n" + output); - - try { - Thread.sleep(5000); - } catch (InterruptedException ignored) {} - instance.setEnabled(false); - } - } From 527e95261aafc8dd26f07d947e383785174e62ec Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 20 Jul 2020 18:07:20 +0200 Subject: [PATCH 142/213] Improve fatal error logging --- .../chestcommands/BaseJavaPlugin.java | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java b/Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java index 7ef3b28..3b63753 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java @@ -22,36 +22,31 @@ public abstract class BaseJavaPlugin extends JavaPlugin { private void criticalShutdown(String errorMessage) { - String separator = "**********"; - - List output = new ArrayList<>(); - - output.add(ChatColor.DARK_RED + "[" + getDescription().getName() + "]" + ChatColor.RED + " Fatal error while enabling plugin:"); - output.add(" "); - output.add(separator); - output.add(" "); - output.add(errorMessage); - output.add(" "); - output.add("The plugin has been disabled."); - output.add(" "); - output.add(separator); - output.add(" "); - - Bukkit.getConsoleSender().sendMessage(String.join("\n", output)); - - try { - Thread.sleep(5000); - } catch (InterruptedException ignored) {} + Bukkit.getConsoleSender().sendMessage(getFatalErrorPrefix() + " " + errorMessage); Bukkit.getScheduler().runTaskLater(this, () -> { - Bukkit.getConsoleSender().sendMessage( - ChatColor.DARK_RED + "[" + getDescription().getName() + "]" - + ChatColor.RED + " Fatal error while enabling plugin. Check previous console logs to find the cause."); + Bukkit.getConsoleSender().sendMessage(getPostStartupMessage(errorMessage)); }, 10); setEnabled(false); } + protected String getPostStartupMessage(String errorMessage) { + List output = new ArrayList<>(); + + output.add(getFatalErrorPrefix()); + output.add(" "); + output.add(errorMessage); + output.add("The plugin has been disabled."); + output.add(" "); + + return String.join("\n", output); + } + + private String getFatalErrorPrefix() { + return ChatColor.DARK_RED + "[" + getDescription().getName() + "] " + ChatColor.RED + "Fatal error while enabling plugin:"; + } + public static class PluginEnableException extends Exception { From 8e0356427ded190f2b2b9d0b4e8bc8aef9bbde7d Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 20 Jul 2020 19:35:45 +0200 Subject: [PATCH 143/213] Multiple renames --- .../chestcommands/api/ClickHandler.java | 2 +- .../chestcommands/api/ClickableIcon.java | 4 +- .../me/filoghost/chestcommands/api/Icon.java | 2 +- .../filoghost/chestcommands/api/IconMenu.java | 2 +- ...{ItemInventory.java => MenuInventory.java} | 2 +- .../chestcommands/ChestCommands.java | 2 +- .../icon/InternalConfigurableIcon.java | 6 +- ...ventory.java => DefaultMenuInventory.java} | 8 +-- .../inventory/InventoryGrid.java | 2 +- ...ryHolder.java => MenuInventoryHolder.java} | 14 ++-- .../listener/CommandListener.java | 4 +- .../listener/InventoryListener.java | 12 ++-- .../chestcommands/menu/BaseIconMenu.java | 18 ++--- .../chestcommands/menu/InternalIconMenu.java | 4 +- .../chestcommands/menu/MenuManager.java | 66 +++++++++---------- .../parsing/menu/LoadedMenu.java | 18 ++--- .../{OpenTrigger.java => MenuOpenItem.java} | 7 +- .../parsing/menu/MenuParser.java | 12 ++-- .../parsing/menu/MenuSettings.java | 10 +-- .../chestcommands/task/TickingTask.java | 10 +-- 20 files changed, 101 insertions(+), 104 deletions(-) rename API/src/main/java/me/filoghost/chestcommands/api/{ItemInventory.java => MenuInventory.java} (81%) rename Plugin/src/main/java/me/filoghost/chestcommands/inventory/{DefaultItemInventory.java => DefaultMenuInventory.java} (87%) rename Plugin/src/main/java/me/filoghost/chestcommands/inventory/{ItemInventoryHolder.java => MenuInventoryHolder.java} (78%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/{OpenTrigger.java => MenuOpenItem.java} (94%) diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java b/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java index 2a25802..a3e853f 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java @@ -23,6 +23,6 @@ public interface ClickHandler { * @param player the player that clicked on the inventory * @return true if the inventory should be closed, false otherwise */ - ClickResult onClick(ItemInventory itemInventory, Player player); + ClickResult onClick(MenuInventory menuInventory, Player player); } diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java b/API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java index 5e4b37c..d2d2ed2 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java @@ -9,9 +9,9 @@ public interface ClickableIcon extends Icon { ClickHandler getClickHandler(); @Override - default ClickResult onClick(ItemInventory itemInventory, Player clicker) { + default ClickResult onClick(MenuInventory menuInventory, Player clicker) { if (getClickHandler() != null) { - return getClickHandler().onClick(itemInventory, clicker); + return getClickHandler().onClick(menuInventory, clicker); } else { return ClickResult.KEEP_OPEN; } diff --git a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java index 4593abc..595277d 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java @@ -21,6 +21,6 @@ public interface Icon { ItemStack render(Player viewer); - ClickResult onClick(ItemInventory itemInventory, Player clicker); + ClickResult onClick(MenuInventory menuInventory, Player clicker); } \ No newline at end of file diff --git a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java index 06f18c7..fbee194 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java @@ -40,7 +40,7 @@ public interface IconMenu { * * @param player the player to which the menu will be displayed */ - ItemInventory open(Player player); + MenuInventory open(Player player); void refreshOpenInventories(); diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ItemInventory.java b/API/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java similarity index 81% rename from API/src/main/java/me/filoghost/chestcommands/api/ItemInventory.java rename to API/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java index 7140f4b..13ea8c4 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ItemInventory.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java @@ -2,7 +2,7 @@ package me.filoghost.chestcommands.api; import org.bukkit.entity.Player; -public interface ItemInventory { +public interface MenuInventory { void refresh(); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 6b64cf2..b21a239 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -193,7 +193,7 @@ public class ChestCommands extends BaseJavaPlugin { public static void closeAllMenus() { for (Player player : Bukkit.getOnlinePlayers()) { - if (MenuManager.getOpenItemInventory(player) != null) { + if (MenuManager.getOpenMenuInventory(player) != null) { player.closeInventory(); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java index 5d4c47b..67b801e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java @@ -17,7 +17,7 @@ package me.filoghost.chestcommands.icon; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.OpenMenuAction; import me.filoghost.chestcommands.api.ClickResult; -import me.filoghost.chestcommands.api.ItemInventory; +import me.filoghost.chestcommands.api.MenuInventory; import me.filoghost.chestcommands.icon.requirement.PermissionChecker; import me.filoghost.chestcommands.icon.requirement.RequiredExpLevel; import me.filoghost.chestcommands.icon.requirement.RequiredItem; @@ -121,7 +121,7 @@ public class InternalConfigurableIcon extends BaseConfigurableIcon implements Re } @Override - public ClickResult onClick(ItemInventory itemInventory, Player player) { + public ClickResult onClick(MenuInventory menuInventory, Player player) { // Check all the requirements boolean hasAllRequirements = Requirement.hasAll(player, clickPermission, requiredMoney, requiredExpLevel, requiredItems); if (!hasAllRequirements) { @@ -147,7 +147,7 @@ public class InternalConfigurableIcon extends BaseConfigurableIcon implements Re } // Update the menu after taking requirement costs and executing all actions - itemInventory.refresh(); + menuInventory.refresh(); // Force menu to stay open if actions open another menu if (hasOpenMenuAction) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultItemInventory.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java similarity index 87% rename from Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultItemInventory.java rename to Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java index a4003bf..e66ae47 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultItemInventory.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java @@ -2,7 +2,7 @@ package me.filoghost.chestcommands.inventory; import me.filoghost.chestcommands.api.ClickResult; import me.filoghost.chestcommands.api.Icon; -import me.filoghost.chestcommands.api.ItemInventory; +import me.filoghost.chestcommands.api.MenuInventory; import me.filoghost.chestcommands.icon.RefreshableIcon; import me.filoghost.chestcommands.menu.BaseIconMenu; import org.bukkit.entity.Player; @@ -11,16 +11,16 @@ import org.bukkit.inventory.ItemStack; /** * Represents a particular view of a menu. */ -public class DefaultItemInventory implements ItemInventory { +public class DefaultMenuInventory implements MenuInventory { private final BaseIconMenu menu; private final InventoryGrid bukkitInventory; private final Player viewer; - public DefaultItemInventory(BaseIconMenu menu, Player viewer) { + public DefaultMenuInventory(BaseIconMenu menu, Player viewer) { this.menu = menu; this.viewer = viewer; - this.bukkitInventory = new InventoryGrid(new ItemInventoryHolder(this), menu.getRowCount(), menu.getTitle()); + this.bukkitInventory = new InventoryGrid(new MenuInventoryHolder(this), menu.getRowCount(), menu.getTitle()); refresh(); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java index 48d1b11..6d47622 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java @@ -9,7 +9,7 @@ public class InventoryGrid extends Grid { private final Inventory inventory; - public InventoryGrid(ItemInventoryHolder inventoryHolder, int rows, String title) { + public InventoryGrid(MenuInventoryHolder inventoryHolder, int rows, String title) { super(rows, 9); this.inventory = Bukkit.createInventory(inventoryHolder, getSize(), title); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/ItemInventoryHolder.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java similarity index 78% rename from Plugin/src/main/java/me/filoghost/chestcommands/inventory/ItemInventoryHolder.java rename to Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java index e6d8805..1df539c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/ItemInventoryHolder.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java @@ -19,13 +19,13 @@ import org.bukkit.Bukkit; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -public class ItemInventoryHolder implements InventoryHolder { +public class MenuInventoryHolder implements InventoryHolder { - private final DefaultItemInventory itemInventory; + private final DefaultMenuInventory menuInventory; - public ItemInventoryHolder(DefaultItemInventory itemInventory) { - Preconditions.notNull(itemInventory, "itemInventory"); - this.itemInventory = itemInventory; + public MenuInventoryHolder(DefaultMenuInventory menuInventory) { + Preconditions.notNull(menuInventory, "menuInventory"); + this.menuInventory = menuInventory; } @Override @@ -39,7 +39,7 @@ public class ItemInventoryHolder implements InventoryHolder { return Bukkit.createInventory(null, 9); } - public DefaultItemInventory getItemInventory() { - return itemInventory; + public DefaultMenuInventory getMenuInventory() { + return menuInventory; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java index 53dcb15..0d1c427 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java @@ -32,13 +32,11 @@ public class CommandListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onCommand(PlayerCommandPreprocessEvent event) { String command = getCommandName(event.getMessage()); - if (command == null) { return; } - InternalIconMenu menu = menuManager.getMenuByCommand(command); - + InternalIconMenu menu = menuManager.getMenuByOpenCommand(command); if (menu == null) { return; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index bb9bfa2..0b9539f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -16,9 +16,9 @@ package me.filoghost.chestcommands.listener; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.api.ClickResult; -import me.filoghost.chestcommands.inventory.DefaultItemInventory.SlotClickHandler; +import me.filoghost.chestcommands.inventory.DefaultMenuInventory; +import me.filoghost.chestcommands.inventory.DefaultMenuInventory.SlotClickHandler; import me.filoghost.chestcommands.menu.MenuManager; -import me.filoghost.chestcommands.inventory.DefaultItemInventory; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -52,7 +52,7 @@ public class InventoryListener implements Listener { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) public void onEarlyInventoryClick(InventoryClickEvent event) { - if (MenuManager.isItemInventory(event.getInventory())) { + if (MenuManager.isMenuInventory(event.getInventory())) { // Cancel the event as early as possible event.setCancelled(true); } @@ -61,8 +61,8 @@ public class InventoryListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) public void onLateInventoryClick(InventoryClickEvent event) { Inventory inventory = event.getInventory(); - DefaultItemInventory itemInventory = MenuManager.getOpenItemInventory(inventory); - if (itemInventory == null) { + DefaultMenuInventory menuInventory = MenuManager.getOpenMenuInventory(inventory); + if (menuInventory == null) { return; } @@ -71,7 +71,7 @@ public class InventoryListener implements Listener { int slot = event.getRawSlot(); Player clicker = (Player) event.getWhoClicked(); - SlotClickHandler slotClickHandler = itemInventory.getSlotClickHandler(slot, clicker); + SlotClickHandler slotClickHandler = menuInventory.getSlotClickHandler(slot, clicker); if (slotClickHandler == null) { return; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java index 798905e..b67a60c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java @@ -16,8 +16,8 @@ package me.filoghost.chestcommands.menu; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.api.IconMenu; -import me.filoghost.chestcommands.api.ItemInventory; -import me.filoghost.chestcommands.inventory.DefaultItemInventory; +import me.filoghost.chestcommands.api.MenuInventory; +import me.filoghost.chestcommands.inventory.DefaultMenuInventory; import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.collection.ArrayGrid; import me.filoghost.chestcommands.util.collection.Grid; @@ -66,20 +66,20 @@ public abstract class BaseIconMenu implements IconMenu { } @Override - public ItemInventory open(Player player) { + public MenuInventory open(Player player) { Preconditions.notNull(player, "player"); - DefaultItemInventory itemInventory = new DefaultItemInventory(this, player); - itemInventory.open(player); - return itemInventory; + DefaultMenuInventory menuInventory = new DefaultMenuInventory(this, player); + menuInventory.open(player); + return menuInventory; } @Override public void refreshOpenInventories() { for (Player player : Bukkit.getOnlinePlayers()) { - DefaultItemInventory itemInventory = MenuManager.getOpenItemInventory(player); - if (itemInventory != null && itemInventory.getIconMenu() == this) { - itemInventory.refresh(); + DefaultMenuInventory menuInventory = MenuManager.getOpenMenuInventory(player); + if (menuInventory != null && menuInventory.getIconMenu() == this) { + menuInventory.refresh(); } } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java index 34b0b50..44c7616 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java @@ -17,7 +17,7 @@ package me.filoghost.chestcommands.menu; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.action.Action; -import me.filoghost.chestcommands.api.ItemInventory; +import me.filoghost.chestcommands.api.MenuInventory; import me.filoghost.chestcommands.util.collection.CollectionUtils; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -60,7 +60,7 @@ public class InternalIconMenu extends BaseIconMenu { } @Override - public ItemInventory open(Player player) { + public MenuInventory open(Player player) { if (openActions != null) { for (Action openAction : openActions) { openAction.execute(player); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java index 3774cbb..2a9f610 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java @@ -14,11 +14,11 @@ */ package me.filoghost.chestcommands.menu; -import me.filoghost.chestcommands.inventory.DefaultItemInventory; -import me.filoghost.chestcommands.inventory.ItemInventoryHolder; +import me.filoghost.chestcommands.inventory.DefaultMenuInventory; +import me.filoghost.chestcommands.inventory.MenuInventoryHolder; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.menu.LoadedMenu; -import me.filoghost.chestcommands.parsing.menu.OpenTrigger; +import me.filoghost.chestcommands.parsing.menu.MenuOpenItem; import me.filoghost.chestcommands.util.collection.CaseInsensitiveMap; import me.filoghost.chestcommands.util.logging.ErrorCollector; import org.bukkit.entity.Player; @@ -35,19 +35,19 @@ import java.util.Map; public class MenuManager { private static Map menusByFile; - private static Map menusByCommand; - private static Map menusByOpenTrigger; + private static Map menusByOpenCommand; + private static Map menusByOpenItem; public MenuManager() { menusByFile = new CaseInsensitiveMap<>(); - menusByCommand = new CaseInsensitiveMap<>(); - menusByOpenTrigger = new HashMap<>(); + menusByOpenCommand = new CaseInsensitiveMap<>(); + menusByOpenItem = new HashMap<>(); } public void clear() { menusByFile.clear(); - menusByCommand.clear(); - menusByOpenTrigger.clear(); + menusByOpenCommand.clear(); + menusByOpenItem.clear(); } public InternalIconMenu getMenuByFileName(String fileName) { @@ -64,68 +64,68 @@ public class MenuManager { } menusByFile.put(fileName, menu); - for (String triggerCommand : loadedMenu.getTriggerCommands()) { - if (!triggerCommand.isEmpty()) { - InternalIconMenu sameCommandMenu = menusByCommand.get(triggerCommand); + for (String openCommand : loadedMenu.getOpenCommands()) { + if (!openCommand.isEmpty()) { + InternalIconMenu sameCommandMenu = menusByOpenCommand.get(openCommand); if (sameCommandMenu != null) { - errorCollector.add(ErrorMessages.Menu.duplicateMenuCommand(sameCommandMenu.getSourceFile(), loadedMenu.getSourceFile(), triggerCommand)); + errorCollector.add(ErrorMessages.Menu.duplicateMenuCommand(sameCommandMenu.getSourceFile(), loadedMenu.getSourceFile(), openCommand)); } - menusByCommand.put(triggerCommand, menu); + menusByOpenCommand.put(openCommand, menu); } } - if (loadedMenu.getOpenTrigger() != null) { - menusByOpenTrigger.put(loadedMenu.getOpenTrigger(), menu); + if (loadedMenu.getOpenItem() != null) { + menusByOpenItem.put(loadedMenu.getOpenItem(), menu); } } public void openMenuByItem(Player player, ItemStack itemInHand, Action clickAction) { - menusByOpenTrigger.forEach((openTrigger, menu) -> { - if (openTrigger.matches(itemInHand, clickAction)) { + menusByOpenItem.forEach((openItem, menu) -> { + if (openItem.matches(itemInHand, clickAction)) { menu.openCheckingPermission(player); } }); } - public InternalIconMenu getMenuByCommand(String command) { - return menusByCommand.get(command); + public InternalIconMenu getMenuByOpenCommand(String openCommand) { + return menusByOpenCommand.get(openCommand); } public Collection getMenuFileNames() { return Collections.unmodifiableCollection(menusByFile.keySet()); } - public static boolean isItemInventory(Inventory inventory) { - return getItemInventoryHolder(inventory) != null; + public static boolean isMenuInventory(Inventory inventory) { + return getMenuInventoryHolder(inventory) != null; } - public static DefaultItemInventory getOpenItemInventory(Player player) { + public static DefaultMenuInventory getOpenMenuInventory(Player player) { InventoryView view = player.getOpenInventory(); if (view == null) { return null; } - DefaultItemInventory itemInventory = getOpenItemInventory(view.getTopInventory()); - if (itemInventory == null) { - itemInventory = getOpenItemInventory(view.getBottomInventory()); + DefaultMenuInventory menuInventory = getOpenMenuInventory(view.getTopInventory()); + if (menuInventory == null) { + menuInventory = getOpenMenuInventory(view.getBottomInventory()); } - return itemInventory; + return menuInventory; } - public static DefaultItemInventory getOpenItemInventory(Inventory inventory) { - ItemInventoryHolder inventoryHolder = getItemInventoryHolder(inventory); + public static DefaultMenuInventory getOpenMenuInventory(Inventory inventory) { + MenuInventoryHolder inventoryHolder = getMenuInventoryHolder(inventory); if (inventoryHolder != null) { - return inventoryHolder.getItemInventory(); + return inventoryHolder.getMenuInventory(); } else { return null; } } - private static ItemInventoryHolder getItemInventoryHolder(Inventory inventory) { - if (inventory.getHolder() instanceof ItemInventoryHolder) { - return (ItemInventoryHolder) inventory.getHolder(); + private static MenuInventoryHolder getMenuInventoryHolder(Inventory inventory) { + if (inventory.getHolder() instanceof MenuInventoryHolder) { + return (MenuInventoryHolder) inventory.getHolder(); } else { return null; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java index e892cb9..22f3c1b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java @@ -9,14 +9,14 @@ public class LoadedMenu { private final InternalIconMenu menu; private final Path sourceFile; - private final List triggerCommands; - private final OpenTrigger openTrigger; + private final List openCommands; + private final MenuOpenItem openItem; - public LoadedMenu(InternalIconMenu menu, Path menuFile, List triggerCommands, OpenTrigger openTrigger) { + public LoadedMenu(InternalIconMenu menu, Path menuFile, List openCommands, MenuOpenItem openItem) { this.menu = menu; this.sourceFile = menuFile; - this.triggerCommands = triggerCommands; - this.openTrigger = openTrigger; + this.openCommands = openCommands; + this.openItem = openItem; } public InternalIconMenu getMenu() { @@ -27,12 +27,12 @@ public class LoadedMenu { return sourceFile; } - public List getTriggerCommands() { - return triggerCommands; + public List getOpenCommands() { + return openCommands; } - public OpenTrigger getOpenTrigger() { - return openTrigger; + public MenuOpenItem getOpenItem() { + return openItem; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/OpenTrigger.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java similarity index 94% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/OpenTrigger.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java index ddb5283..6ec41d9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/OpenTrigger.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java @@ -14,20 +14,19 @@ */ package me.filoghost.chestcommands.parsing.menu; +import me.filoghost.chestcommands.util.Preconditions; import org.bukkit.Material; import org.bukkit.event.block.Action; import org.bukkit.inventory.ItemStack; -import me.filoghost.chestcommands.util.Preconditions; - -public class OpenTrigger { +public class MenuOpenItem { private final Material material; private final ClickType clickType; private short durability; private boolean isRestrictiveDurability; - public OpenTrigger(Material material, ClickType clickType) { + public MenuOpenItem(Material material, ClickType clickType) { Preconditions.checkArgumentNotAir(material, "material"); Preconditions.notNull(clickType, "clickType"); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index 9f67b56..a6e7369 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -50,7 +50,7 @@ public class MenuParser { iconMenu.setRefreshTicks(menuSettings.getRefreshTicks()); iconMenu.setOpenActions(menuSettings.getOpenActions()); - return new LoadedMenu(iconMenu, menuConfig.getSourceFile(), menuSettings.getCommands(), menuSettings.getOpenTrigger()); + return new LoadedMenu(iconMenu, menuConfig.getSourceFile(), menuSettings.getCommands(), menuSettings.getOpenItem()); } @@ -120,8 +120,8 @@ public class MenuParser { MenuSettings menuSettings = new MenuSettings(title, rows); - List triggeringCommands = settingsSection.getStringList(MenuSettingsNode.COMMANDS); - menuSettings.setCommands(triggeringCommands); + List openCommands = settingsSection.getStringList(MenuSettingsNode.COMMANDS); + menuSettings.setCommands(openCommands); List serializedOpenActions = settingsSection.getStringList(MenuSettingsNode.OPEN_ACTIONS); @@ -147,13 +147,13 @@ public class MenuParser { ItemStackParser itemReader = new ItemStackParser(openItemMaterial, false); ClickType clickType = ClickType.fromOptions(leftClick, rightClick); - OpenTrigger openTrigger = new OpenTrigger(itemReader.getMaterial(), clickType); + MenuOpenItem openItem = new MenuOpenItem(itemReader.getMaterial(), clickType); if (itemReader.hasExplicitDurability()) { - openTrigger.setRestrictiveDurability(itemReader.getDurability()); + openItem.setRestrictiveDurability(itemReader.getDurability()); } - menuSettings.setOpenTrigger(openTrigger); + menuSettings.setOpenItem(openItem); } catch (ParseException e) { errorCollector.add( diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java index 9809c04..4447084 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java @@ -29,7 +29,7 @@ public class MenuSettings { private List openActions; private int refreshTicks; - private OpenTrigger openTrigger; + private MenuOpenItem openItem; public MenuSettings(String title, int rows) { this.title = title; @@ -68,12 +68,12 @@ public class MenuSettings { this.refreshTicks = refreshTicks; } - public OpenTrigger getOpenTrigger() { - return openTrigger; + public MenuOpenItem getOpenItem() { + return openItem; } - public void setOpenTrigger(OpenTrigger openTrigger) { - this.openTrigger = openTrigger; + public void setOpenItem(MenuOpenItem openItem) { + this.openItem = openItem; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java index 6525214..91af57b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java @@ -14,7 +14,7 @@ */ package me.filoghost.chestcommands.task; -import me.filoghost.chestcommands.inventory.DefaultItemInventory; +import me.filoghost.chestcommands.inventory.DefaultMenuInventory; import me.filoghost.chestcommands.menu.InternalIconMenu; import me.filoghost.chestcommands.menu.MenuManager; import me.filoghost.chestcommands.placeholder.PlaceholderManager; @@ -35,16 +35,16 @@ public class TickingTask implements Runnable { private void updateInventories() { for (Player player : Bukkit.getOnlinePlayers()) { - DefaultItemInventory itemInventory = MenuManager.getOpenItemInventory(player); + DefaultMenuInventory menuInventory = MenuManager.getOpenMenuInventory(player); - if (itemInventory == null || !(itemInventory.getIconMenu() instanceof InternalIconMenu)) { + if (menuInventory == null || !(menuInventory.getIconMenu() instanceof InternalIconMenu)) { continue; } - int refreshTicks = ((InternalIconMenu) itemInventory.getIconMenu()).getRefreshTicks(); + int refreshTicks = ((InternalIconMenu) menuInventory.getIconMenu()).getRefreshTicks(); if (refreshTicks > 0 && currentTick % refreshTicks == 0) { - itemInventory.refresh(); + menuInventory.refresh(); } } } From 354a62b2c5e0510abcafc66aaa1cde9a86954726 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 20 Jul 2020 20:32:50 +0200 Subject: [PATCH 144/213] Unify copyright notices --- .../chestcommands/api/ChestCommandsAPI.java | 23 ++++++------ .../chestcommands/api/ClickHandler.java | 20 +++++----- .../chestcommands/api/ClickResult.java | 24 ++++++------ .../chestcommands/api/ClickableIcon.java | 14 +++++++ .../chestcommands/api/ConfigurableIcon.java | 24 ++++++------ .../me/filoghost/chestcommands/api/Icon.java | 24 ++++++------ .../filoghost/chestcommands/api/IconMenu.java | 24 ++++++------ .../chestcommands/api/MenuInventory.java | 14 +++++++ .../chestcommands/api/StaticIcon.java | 24 ++++++------ .../api/internal/BackendAPI.java | 24 ++++++------ .../chestcommands/BaseJavaPlugin.java | 14 +++++++ .../chestcommands/ChestCommands.java | 20 +++++----- .../chestcommands/DefaultBackendAPI.java | 25 ++++++------- .../filoghost/chestcommands/Permissions.java | 20 +++++----- .../chestcommands/action/Action.java | 20 +++++----- .../chestcommands/action/BroadcastAction.java | 25 ++++++------- .../action/ChangeServerAction.java | 23 ++++++------ .../action/ConsoleCommandAction.java | 23 ++++++------ .../chestcommands/action/DragonBarAction.java | 29 +++++++-------- .../chestcommands/action/GiveItemAction.java | 25 ++++++------- .../chestcommands/action/GiveMoneyAction.java | 27 +++++++------- .../chestcommands/action/OpCommandAction.java | 23 ++++++------ .../chestcommands/action/OpenMenuAction.java | 20 +++++----- .../chestcommands/action/PlaySoundAction.java | 25 ++++++------- .../action/PlayerCommandAction.java | 23 ++++++------ .../action/SendMessageAction.java | 25 ++++++------- .../chestcommands/command/CommandHandler.java | 20 +++++----- .../command/framework/CommandException.java | 20 +++++----- .../command/framework/CommandFramework.java | 20 +++++----- .../command/framework/CommandValidate.java | 20 +++++----- .../chestcommands/config/ConfigManager.java | 20 +++++----- .../config/CustomPlaceholders.java | 20 +++++----- .../filoghost/chestcommands/config/Lang.java | 20 +++++----- .../chestcommands/config/Settings.java | 20 +++++----- .../config/framework/BaseConfigManager.java | 20 +++++----- .../config/framework/Config.java | 20 +++++----- .../config/framework/ConfigLoader.java | 20 +++++----- .../config/framework/ConfigSection.java | 20 +++++----- .../framework/exception/ConfigException.java | 14 +++++++ .../exception/ConfigLoadException.java | 14 +++++++ .../exception/ConfigSaveException.java | 14 +++++++ .../exception/ConfigSyntaxException.java | 14 +++++++ .../exception/ConfigValueException.java | 14 +++++++ .../config/framework/mapped/ConfigMapper.java | 20 +++++----- .../framework/mapped/IncludeStatic.java | 20 +++++----- .../config/framework/mapped/MappedConfig.java | 20 +++++----- .../framework/mapped/MappedConfigLoader.java | 20 +++++----- .../config/framework/mapped/MappedField.java | 20 +++++----- .../mapped/converter/BooleanConverter.java | 20 +++++----- .../framework/mapped/converter/Converter.java | 20 +++++----- .../mapped/converter/DoubleConverter.java | 20 +++++----- .../mapped/converter/IntegerConverter.java | 20 +++++----- .../mapped/converter/ListConverter.java | 20 +++++----- .../mapped/converter/StringConverter.java | 20 +++++----- .../framework/mapped/modifier/ChatColors.java | 20 +++++----- .../mapped/modifier/ChatColorsModifier.java | 20 +++++----- .../mapped/modifier/ValueModifier.java | 20 +++++----- .../chestcommands/hook/BarAPIHook.java | 20 +++++----- .../chestcommands/hook/BungeeCordHook.java | 29 +++++++-------- .../hook/PlaceholderAPIHook.java | 14 +++++++ .../chestcommands/hook/PluginHook.java | 24 ++++++------ .../chestcommands/hook/VaultEconomyHook.java | 20 +++++----- .../icon/APIConfigurableIcon.java | 15 +++++++- .../chestcommands/icon/APIStaticIcon.java | 14 +++++++ .../icon/BaseConfigurableIcon.java | 20 +++++----- .../icon/InternalConfigurableIcon.java | 20 +++++----- .../chestcommands/icon/RefreshableIcon.java | 14 +++++++ .../icon/requirement/PermissionChecker.java | 27 +++++++------- .../icon/requirement/RequiredExpLevel.java | 28 +++++++------- .../icon/requirement/RequiredItem.java | 23 ++++++------ .../icon/requirement/RequiredItems.java | 34 ++++++++--------- .../icon/requirement/RequiredMoney.java | 30 +++++++-------- .../icon/requirement/Requirement.java | 24 ++++++------ .../inventory/DefaultMenuInventory.java | 14 +++++++ .../inventory/InventoryGrid.java | 14 +++++++ .../inventory/MenuInventoryHolder.java | 20 +++++----- .../chestcommands/legacy/RegexReplacer.java | 20 +++++----- .../legacy/UpgradeExecutorException.java | 20 +++++----- .../legacy/UpgradesDoneRegistry.java | 20 +++++----- .../legacy/UpgradesExecutor.java | 20 +++++----- .../legacy/upgrade/LangUpgrade.java | 20 +++++----- .../legacy/upgrade/MenuNodeExpandUpgrade.java | 20 +++++----- .../legacy/upgrade/MenuNodeRenameUpgrade.java | 20 +++++----- .../upgrade/PlaceholdersYamlUpgrade.java | 20 +++++----- .../legacy/upgrade/RegexUpgrade.java | 20 +++++----- .../legacy/upgrade/SettingsUpgrade.java | 20 +++++----- .../chestcommands/legacy/upgrade/Upgrade.java | 20 +++++----- .../legacy/upgrade/UpgradeException.java | 20 +++++----- .../listener/CommandListener.java | 20 +++++----- .../listener/InventoryListener.java | 20 +++++----- .../chestcommands/listener/JoinListener.java | 20 +++++----- .../chestcommands/listener/SignListener.java | 20 +++++----- .../chestcommands/logging/ErrorMessages.java | 20 +++++----- .../chestcommands/logging/ErrorPrintInfo.java | 14 +++++++ .../logging/MessagePartJoiner.java | 14 +++++++ .../logging/PrintableErrorCollector.java | 14 +++++++ .../chestcommands/menu/APIIconMenu.java | 21 +++++------ .../chestcommands/menu/BaseIconMenu.java | 20 +++++----- .../chestcommands/menu/InternalIconMenu.java | 20 +++++----- .../chestcommands/menu/MenuManager.java | 24 ++++++------ .../chestcommands/parsing/ActionParser.java | 37 ++++++++++++------- .../parsing/EnchantmentParser.java | 20 +++++----- .../chestcommands/parsing/ItemMetaParser.java | 20 +++++----- .../parsing/ItemStackParser.java | 20 +++++----- .../chestcommands/parsing/NumberParser.java | 24 ++++++------ .../chestcommands/parsing/ParseException.java | 20 +++++----- .../parsing/icon/ApplicableIconAttribute.java | 24 ++++++------ .../parsing/icon/AttributeErrorCollector.java | 14 +++++++ .../parsing/icon/IconAttribute.java | 24 ++++++------ .../parsing/icon/IconSettings.java | 24 ++++++------ .../parsing/icon/IconSettingsNode.java | 20 +++++----- .../icon/attributes/ActionsAttribute.java | 24 ++++++------ .../icon/attributes/AmountAttribute.java | 24 ++++++------ .../icon/attributes/BannerColorAttribute.java | 24 ++++++------ .../attributes/BannerPatternsAttribute.java | 24 ++++++------ .../attributes/ClickPermissionAttribute.java | 24 ++++++------ .../ClickPermissionMessageAttribute.java | 24 ++++++------ .../icon/attributes/DurabilityAttribute.java | 24 ++++++------ .../attributes/EnchantmentsAttribute.java | 24 ++++++------ .../icon/attributes/ExpLevelsAttribute.java | 24 ++++++------ .../icon/attributes/KeepOpenAttribute.java | 24 ++++++------ .../attributes/LeatherColorAttribute.java | 24 ++++++------ .../icon/attributes/LoreAttribute.java | 24 ++++++------ .../icon/attributes/MaterialAttribute.java | 24 ++++++------ .../icon/attributes/NBTDataAttribute.java | 24 ++++++------ .../icon/attributes/NameAttribute.java | 24 ++++++------ .../icon/attributes/PositionAttribute.java | 24 ++++++------ .../icon/attributes/PriceAttribute.java | 24 ++++++------ .../attributes/RequiredItemsAttribute.java | 24 ++++++------ .../icon/attributes/SkullOwnerAttribute.java | 24 ++++++------ .../attributes/ViewPermissionAttribute.java | 24 ++++++------ .../chestcommands/parsing/menu/ClickType.java | 20 +++++----- .../parsing/menu/LoadedMenu.java | 14 +++++++ .../parsing/menu/MenuOpenItem.java | 20 +++++----- .../parsing/menu/MenuParser.java | 20 +++++----- .../parsing/menu/MenuSettings.java | 20 +++++----- .../parsing/menu/MenuSettingsNode.java | 14 +++++++ .../placeholder/DefaultPlaceholders.java | 20 +++++----- .../placeholder/Placeholder.java | 20 +++++----- .../placeholder/PlaceholderManager.java | 14 +++++++ .../placeholder/RelativeString.java | 14 +++++++ .../placeholder/RelativeStringList.java | 22 ++++++++--- .../chestcommands/task/TickingTask.java | 20 +++++----- .../filoghost/chestcommands/util/Colors.java | 14 +++++++ .../chestcommands/util/MaterialsHelper.java | 21 ++++++----- .../chestcommands/util/Preconditions.java | 20 +++++----- .../filoghost/chestcommands/util/Strings.java | 20 +++++----- .../filoghost/chestcommands/util/Utils.java | 14 +++++++ .../util/collection/ArrayGrid.java | 14 +++++++ .../util/collection/CaseInsensitiveMap.java | 20 +++++----- .../util/collection/CollectionUtils.java | 20 +++++----- .../chestcommands/util/collection/Grid.java | 24 ++++++------ .../util/collection/Registry.java | 24 ++++++------ .../util/logging/ErrorCollector.java | 20 +++++----- .../chestcommands/util/logging/ErrorInfo.java | 14 +++++++ .../chestcommands/util/logging/Log.java | 24 ++++++------ 156 files changed, 1801 insertions(+), 1436 deletions(-) diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java index 6cdd64a..9f8296d 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java @@ -1,22 +1,21 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.api; -import org.bukkit.entity.Player; - import me.filoghost.chestcommands.api.internal.BackendAPI; +import org.bukkit.entity.Player; public class ChestCommandsAPI { diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java b/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java index a3e853f..225eac6 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.api; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java b/API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java index c608f11..2404d45 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.api; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java b/API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java index d2d2ed2..f6ff824 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.api; import org.bukkit.entity.Player; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java b/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java index 9de8112..8028841 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.api; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java index 595277d..f1d7de6 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.api; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java index fbee194..1a02bdf 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.api; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java b/API/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java index 13ea8c4..9c80889 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.api; import org.bukkit.entity.Player; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java b/API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java index 14dedb5..144fd99 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.api; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java index 21e3000..8a5c278 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.api.internal; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java b/Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java index 3b63753..d0fcb37 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands; import org.bukkit.Bukkit; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index b21a239..810230a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java b/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java index cfb5c62..619c7be 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java @@ -1,20 +1,19 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands; -import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.api.ConfigurableIcon; import me.filoghost.chestcommands.api.IconMenu; import me.filoghost.chestcommands.api.StaticIcon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java b/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java index 2ea4587..9a929da 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java index dad3420..0e3230a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java index 4ad9bba..aa92d26 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java @@ -1,25 +1,24 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.action; +import me.filoghost.chestcommands.placeholder.RelativeString; +import me.filoghost.chestcommands.util.Colors; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.util.Colors; -import me.filoghost.chestcommands.placeholder.RelativeString; - public class BroadcastAction extends Action { private final RelativeString message; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java index efe9d3f..8a234c0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java @@ -1,23 +1,22 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.action; -import org.bukkit.entity.Player; - import me.filoghost.chestcommands.hook.BungeeCordHook; import me.filoghost.chestcommands.placeholder.RelativeString; +import org.bukkit.entity.Player; public class ChangeServerAction extends Action { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java index 21a7ffa..ff88a3e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java @@ -1,24 +1,23 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.action; +import me.filoghost.chestcommands.placeholder.RelativeString; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.placeholder.RelativeString; - public class ConsoleCommandAction extends Action { private final RelativeString command; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java index d06efc8..e7caa16 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java @@ -1,28 +1,27 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.action; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.chestcommands.hook.BarAPIHook; import me.filoghost.chestcommands.parsing.NumberParser; +import me.filoghost.chestcommands.parsing.ParseException; +import me.filoghost.chestcommands.placeholder.RelativeString; import me.filoghost.chestcommands.util.Colors; import me.filoghost.chestcommands.util.Strings; -import me.filoghost.chestcommands.placeholder.RelativeString; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; public class DragonBarAction extends Action { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java index f56dd11..85956fd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java @@ -1,26 +1,25 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.action; +import me.filoghost.chestcommands.parsing.ItemStackParser; +import me.filoghost.chestcommands.parsing.ParseException; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.parsing.ItemStackParser; - public class GiveItemAction extends Action { private ItemStack itemToGive; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java index 1076207..eda53d8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java @@ -1,25 +1,24 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.action; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.chestcommands.hook.VaultEconomyHook; import me.filoghost.chestcommands.parsing.NumberParser; +import me.filoghost.chestcommands.parsing.ParseException; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; public class GiveMoneyAction extends Action { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java index 8f60de1..819a803 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java @@ -1,22 +1,21 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.action; -import org.bukkit.entity.Player; - import me.filoghost.chestcommands.placeholder.RelativeString; +import org.bukkit.entity.Player; public class OpCommandAction extends Action { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java index 8cb94af..150d5c7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java index 35d25b9..6db31ab 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java @@ -1,26 +1,25 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.action; +import me.filoghost.chestcommands.util.Strings; +import me.filoghost.chestcommands.util.collection.Registry; import org.bukkit.ChatColor; import org.bukkit.Sound; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.util.collection.Registry; -import me.filoghost.chestcommands.util.Strings; - import java.util.Optional; public class PlaySoundAction extends Action { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java index 6aa3fc5..e5cdfae 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java @@ -1,22 +1,21 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.action; -import org.bukkit.entity.Player; - import me.filoghost.chestcommands.placeholder.RelativeString; +import org.bukkit.entity.Player; public class PlayerCommandAction extends Action { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java index 53d6a2b..fcb77aa 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java @@ -1,23 +1,22 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.action; -import org.bukkit.entity.Player; - -import me.filoghost.chestcommands.util.Colors; import me.filoghost.chestcommands.placeholder.RelativeString; +import me.filoghost.chestcommands.util.Colors; +import org.bukkit.entity.Player; public class SendMessageAction extends Action { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index fa03e93..0a7833a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.command; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandException.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandException.java index ca6db68..2b87790 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandException.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.command.framework; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandFramework.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandFramework.java index 66c5ecd..6359596 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandFramework.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandFramework.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.command.framework; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandValidate.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandValidate.java index 81c6c09..ae0fbdf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandValidate.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandValidate.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.command.framework; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java index 0c0fb45..b74d24d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java index e3ab568..a85e581 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java index 7108241..3cdf819 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java index d308eb4..b293123 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/BaseConfigManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/BaseConfigManager.java index 00efc64..3bc81a8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/BaseConfigManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/BaseConfigManager.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java index 852e053..f7c7e94 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java index e2bb954..d447800 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java index c8a0b18..843eb02 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigException.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigException.java index 5dd6b05..2b31296 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigException.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.config.framework.exception; public class ConfigException extends Exception { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigLoadException.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigLoadException.java index c145072..b99446f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigLoadException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigLoadException.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.config.framework.exception; public class ConfigLoadException extends ConfigException { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSaveException.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSaveException.java index de64ce1..3feeb5c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSaveException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSaveException.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.config.framework.exception; public class ConfigSaveException extends ConfigException { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSyntaxException.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSyntaxException.java index 5d90347..bebdd9e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSyntaxException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSyntaxException.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.config.framework.exception; import org.bukkit.configuration.InvalidConfigurationException; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigValueException.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigValueException.java index 2a484b6..b37ed87 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigValueException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigValueException.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.config.framework.exception; public class ConfigValueException extends ConfigException { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/ConfigMapper.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/ConfigMapper.java index 686f35a..fa81edb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/ConfigMapper.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/ConfigMapper.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework.mapped; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/IncludeStatic.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/IncludeStatic.java index c90b557..60a8901 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/IncludeStatic.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/IncludeStatic.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework.mapped; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfig.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfig.java index e97b425..19258bd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfig.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfig.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework.mapped; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java index 93f51fd..f2718af 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework.mapped; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedField.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedField.java index d9370dc..ef8c1bb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedField.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedField.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework.mapped; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/BooleanConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/BooleanConverter.java index 2960496..49ff6f1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/BooleanConverter.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/BooleanConverter.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework.mapped.converter; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/Converter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/Converter.java index df0e921..a6e7185 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/Converter.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/Converter.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework.mapped.converter; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/DoubleConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/DoubleConverter.java index e6c9ffc..3fa7da3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/DoubleConverter.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/DoubleConverter.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework.mapped.converter; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/IntegerConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/IntegerConverter.java index 47ac621..b8f0003 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/IntegerConverter.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/IntegerConverter.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework.mapped.converter; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/ListConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/ListConverter.java index 99ca844..76d9620 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/ListConverter.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/ListConverter.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework.mapped.converter; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/StringConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/StringConverter.java index 422dcbd..a8689a4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/StringConverter.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/StringConverter.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework.mapped.converter; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColors.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColors.java index 7a8034e..db9c274 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColors.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColors.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework.mapped.modifier; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColorsModifier.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColorsModifier.java index 18f65cd..49b2c44 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColorsModifier.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColorsModifier.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework.mapped.modifier; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ValueModifier.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ValueModifier.java index 1925f7a..2a9b2f4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ValueModifier.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ValueModifier.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.config.framework.mapped.modifier; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java index dc64e39..69237b8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.hook; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java index 4087d58..241011b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java @@ -1,28 +1,27 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.hook; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; - +import me.filoghost.chestcommands.ChestCommands; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; -import me.filoghost.chestcommands.ChestCommands; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; public enum BungeeCordHook implements PluginHook { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java index 1859861..e4d612a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.hook; import me.clip.placeholderapi.PlaceholderAPI; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java index 812ccc0..a196910 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.hook; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java index acfd36c..1bb6931 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.hook; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIConfigurableIcon.java index d9a38d1..2304fbb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIConfigurableIcon.java @@ -1,8 +1,21 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.icon; import me.filoghost.chestcommands.api.ClickHandler; import me.filoghost.chestcommands.api.ConfigurableIcon; -import me.filoghost.chestcommands.icon.BaseConfigurableIcon; import org.bukkit.Material; public class APIConfigurableIcon extends BaseConfigurableIcon implements ConfigurableIcon { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java index a8996ca..6e16ea2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.icon; import me.filoghost.chestcommands.api.ClickHandler; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java index a2eaa73..bd62fc8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.icon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java index 67b801e..5dd0d1e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.icon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/RefreshableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/RefreshableIcon.java index 8ec512d..279be2a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/RefreshableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/RefreshableIcon.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.icon; import org.bukkit.entity.Player; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/PermissionChecker.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/PermissionChecker.java index 2ac5ecf..6e7a5ee 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/PermissionChecker.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/PermissionChecker.java @@ -1,23 +1,22 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.icon.requirement; -import org.bukkit.entity.Player; - import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.util.Strings; +import org.bukkit.entity.Player; public class PermissionChecker implements Requirement { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java index c043e65..4064ae3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java @@ -1,24 +1,22 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.icon.requirement; -import org.bukkit.entity.Player; - import com.google.common.base.Preconditions; - import me.filoghost.chestcommands.ChestCommands; +import org.bukkit.entity.Player; public class RequiredExpLevel implements Requirement { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItem.java index 7db9dbb..a776249 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItem.java @@ -1,25 +1,24 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.icon.requirement; +import me.filoghost.chestcommands.util.Preconditions; import org.bukkit.Material; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -import me.filoghost.chestcommands.util.Preconditions; - public class RequiredItem { private final Material material; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItems.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItems.java index 36f55c5..9ff22f3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItems.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItems.java @@ -1,28 +1,26 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.icon.requirement; -import java.util.List; - +import com.google.common.collect.ImmutableList; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.Utils; import org.bukkit.entity.Player; -import com.google.common.collect.ImmutableList; - -import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.util.Preconditions; +import java.util.List; public class RequiredItems implements Requirement { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java index 5c6c92a..b21962a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java @@ -1,26 +1,24 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.icon.requirement; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - import com.google.common.base.Preconditions; - import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.hook.VaultEconomyHook; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; public class RequiredMoney implements Requirement { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/Requirement.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/Requirement.java index 3e824db..b8e52e4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/Requirement.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/Requirement.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.icon.requirement; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java index e66ae47..eef5d15 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.inventory; import me.filoghost.chestcommands.api.ClickResult; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java index 6d47622..baeb8cf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.inventory; import me.filoghost.chestcommands.util.collection.Grid; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java index 1df539c..ccde737 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.inventory; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/RegexReplacer.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/RegexReplacer.java index ef94b64..df57b8d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/RegexReplacer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/RegexReplacer.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.legacy; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeExecutorException.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeExecutorException.java index 0285916..76a2ba5 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeExecutorException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeExecutorException.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.legacy; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java index d1f9120..3005969 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.legacy; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java index 8167dd3..6d5a90f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.legacy; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/LangUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/LangUpgrade.java index d73809d..22c67f7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/LangUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/LangUpgrade.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.legacy.upgrade; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgrade.java index 77f5b71..c2d5cec 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgrade.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.legacy.upgrade; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgrade.java index cb237a9..2a3cbdf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgrade.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.legacy.upgrade; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgrade.java index 94b5b56..4112d49 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgrade.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.legacy.upgrade; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgrade.java index f323f94..503d35b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgrade.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.legacy.upgrade; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgrade.java index ca4d425..dccbaf5 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgrade.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.legacy.upgrade; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java index 7281735..c9daefa 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.legacy.upgrade; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeException.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeException.java index e17e6a6..3f1a77d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeException.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.legacy.upgrade; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java index 0d1c427..fcb4890 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.listener; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index 0b9539f..d0d0abb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.listener; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java index 7de0fc9..50c9a6b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.listener; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java index 2b5d327..ab04229 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.listener; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java index 1d750a0..8ea48a9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.logging; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorPrintInfo.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorPrintInfo.java index 03d553c..c0cf0e6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorPrintInfo.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorPrintInfo.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.logging; import java.util.List; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java index 4c40613..f46acbf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.logging; import me.filoghost.chestcommands.util.Strings; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java index c38ee62..443c5bf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.logging; import me.filoghost.chestcommands.ChestCommands; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java index 5033766..881f612 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java @@ -1,20 +1,19 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.menu; -import me.filoghost.chestcommands.menu.BaseIconMenu; import org.bukkit.plugin.Plugin; public class APIIconMenu extends BaseIconMenu { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java index b67a60c..bb7c0b2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.menu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java index 44c7616..1f8e2fe 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.menu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java index 2a9f610..7f3f704 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.menu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java index 0f21285..19f538d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java @@ -1,28 +1,39 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.action.Action; +import me.filoghost.chestcommands.action.BroadcastAction; +import me.filoghost.chestcommands.action.ChangeServerAction; +import me.filoghost.chestcommands.action.ConsoleCommandAction; +import me.filoghost.chestcommands.action.DragonBarAction; +import me.filoghost.chestcommands.action.GiveItemAction; +import me.filoghost.chestcommands.action.GiveMoneyAction; +import me.filoghost.chestcommands.action.OpCommandAction; +import me.filoghost.chestcommands.action.OpenMenuAction; +import me.filoghost.chestcommands.action.PlaySoundAction; +import me.filoghost.chestcommands.action.PlayerCommandAction; +import me.filoghost.chestcommands.action.SendMessageAction; + import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; -import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.action.*; - public class ActionParser { private static final Map actionsByPrefix = new HashMap<>(); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java index 782f55e..f1b45bd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java index 9194582..5c5dfc3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java index 537f04e..ae6a154 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java index b951fdd..a7fa188 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ParseException.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ParseException.java index eb4a58f..348476e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ParseException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ParseException.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/ApplicableIconAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/ApplicableIconAttribute.java index 92ae596..bffcfb0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/ApplicableIconAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/ApplicableIconAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeErrorCollector.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeErrorCollector.java index 78930f4..3225ed1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeErrorCollector.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeErrorCollector.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.parsing.icon; import me.filoghost.chestcommands.logging.ErrorMessages; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconAttribute.java index f5a8216..5029ad5 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java index efae7a6..8d6ee4b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettingsNode.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettingsNode.java index ca82f5a..24e95ee 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettingsNode.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettingsNode.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ActionsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ActionsAttribute.java index c6b0e2d..bd3d22b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ActionsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ActionsAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/AmountAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/AmountAttribute.java index 90b2e6c..434fe26 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/AmountAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/AmountAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/BannerColorAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/BannerColorAttribute.java index a0add38..805f71f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/BannerColorAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/BannerColorAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/BannerPatternsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/BannerPatternsAttribute.java index 366f163..e838192 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/BannerPatternsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/BannerPatternsAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ClickPermissionAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ClickPermissionAttribute.java index ae8425f..bf31e7a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ClickPermissionAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ClickPermissionAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ClickPermissionMessageAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ClickPermissionMessageAttribute.java index b8da273..1448f02 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ClickPermissionMessageAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ClickPermissionMessageAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/DurabilityAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/DurabilityAttribute.java index 6d89976..debe3bf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/DurabilityAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/DurabilityAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/EnchantmentsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/EnchantmentsAttribute.java index 97698cf..339244f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/EnchantmentsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/EnchantmentsAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ExpLevelsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ExpLevelsAttribute.java index 56bff62..4c994a6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ExpLevelsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ExpLevelsAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/KeepOpenAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/KeepOpenAttribute.java index 84c48f2..9ac99a7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/KeepOpenAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/KeepOpenAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LeatherColorAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LeatherColorAttribute.java index a6ee0b0..5a9cc1b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LeatherColorAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LeatherColorAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LoreAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LoreAttribute.java index 7bc2834..90b464d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LoreAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LoreAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/MaterialAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/MaterialAttribute.java index a5f63ec..8fffbde 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/MaterialAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/MaterialAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NBTDataAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NBTDataAttribute.java index ea44b3c..df721df 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NBTDataAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NBTDataAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NameAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NameAttribute.java index 5b5f3ac..34b8153 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NameAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NameAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PositionAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PositionAttribute.java index 6868ab6..fc63f8a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PositionAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PositionAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PriceAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PriceAttribute.java index 9a29795..9142675 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PriceAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PriceAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/RequiredItemsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/RequiredItemsAttribute.java index 9386fad..7698c12 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/RequiredItemsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/RequiredItemsAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/SkullOwnerAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/SkullOwnerAttribute.java index 9b4430e..008aeef 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/SkullOwnerAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/SkullOwnerAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ViewPermissionAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ViewPermissionAttribute.java index 14f3a6b..d936b44 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ViewPermissionAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ViewPermissionAttribute.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.icon.attributes; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/ClickType.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/ClickType.java index e7f107a..1a265eb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/ClickType.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/ClickType.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.menu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java index 22f3c1b..f6581e0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.parsing.menu; import me.filoghost.chestcommands.menu.InternalIconMenu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java index 6ec41d9..53dd390 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.menu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index a6e7369..21ae0d5 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.menu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java index 4447084..9f78736 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.parsing.menu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettingsNode.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettingsNode.java index effff85..5bbc866 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettingsNode.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettingsNode.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.parsing.menu; public class MenuSettingsNode { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholders.java index 1764901..36ea7b8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholders.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.placeholder; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/Placeholder.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/Placeholder.java index e670eb1..0378335 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/Placeholder.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/Placeholder.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.placeholder; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java index 8df60f1..ac5ec24 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.placeholder; import me.filoghost.chestcommands.hook.PlaceholderAPIHook; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeString.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeString.java index a4e754e..7d4cfe4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeString.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeString.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.placeholder; import org.bukkit.entity.Player; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeStringList.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeStringList.java index 14ff906..e710ea7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeStringList.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeStringList.java @@ -1,12 +1,24 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.placeholder; -import java.util.List; - +import com.google.common.collect.ImmutableList; +import me.filoghost.chestcommands.util.collection.CollectionUtils; import org.bukkit.entity.Player; -import com.google.common.collect.ImmutableList; - -import me.filoghost.chestcommands.util.collection.CollectionUtils; +import java.util.List; public class RelativeStringList { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java index 91af57b..78db376 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.task; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Colors.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Colors.java index 227fb9a..4c7193b 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Colors.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/Colors.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.util; import org.bukkit.ChatColor; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java b/Utils/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java index 2c32616..52b6ba0 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java @@ -1,21 +1,22 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.util; import me.filoghost.chestcommands.util.collection.Registry; import org.bukkit.Material; + import java.util.Collection; import java.util.HashSet; import java.util.Optional; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java index 0032a1d..d4c56ef 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.util; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java index 83e1cd3..ad3591a 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.util; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java index 11effab..d98e6e6 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.util; public class Utils { diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/ArrayGrid.java b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/ArrayGrid.java index 6f6270f..cccee7c 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/ArrayGrid.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/ArrayGrid.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.util.collection; public class ArrayGrid extends Grid { diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CaseInsensitiveMap.java b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CaseInsensitiveMap.java index 27d4d8b..f8832cb 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CaseInsensitiveMap.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CaseInsensitiveMap.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.util.collection; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java index d6b01a1..87682db 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.util.collection; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/Grid.java b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/Grid.java index 6d1ae4a..947c57d 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/Grid.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/Grid.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.util.collection; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/Registry.java b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/Registry.java index 6c06a52..ce12310 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/Registry.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/Registry.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.util.collection; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorCollector.java b/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorCollector.java index d963c0e..9e246e2 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorCollector.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorCollector.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.util.logging; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorInfo.java b/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorInfo.java index 0858d0e..463ed27 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorInfo.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorInfo.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.util.logging; import java.util.ArrayList; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/logging/Log.java b/Utils/src/main/java/me/filoghost/chestcommands/util/logging/Log.java index 05507ff..894b351 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/logging/Log.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/logging/Log.java @@ -1,16 +1,16 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package me.filoghost.chestcommands.util.logging; From d13f3ec68fa4508596fc4d8474ce1cd63bc066ec Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 20 Jul 2020 21:46:15 +0200 Subject: [PATCH 145/213] Fix automatic menu upgrade --- .../legacy/upgrade/MenuNodeRenameUpgrade.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgrade.java index 2a3cbdf..f1bb9cf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgrade.java @@ -15,7 +15,6 @@ package me.filoghost.chestcommands.legacy.upgrade; import me.filoghost.chestcommands.parsing.icon.IconSettingsNode; -import me.filoghost.chestcommands.parsing.menu.MenuSettingsNode; import java.nio.file.Path; import java.util.regex.Pattern; @@ -25,9 +24,9 @@ public class MenuNodeRenameUpgrade extends RegexUpgrade { public MenuNodeRenameUpgrade(Path menuFile) { super(menuFile); - addSubNodeReplacer("command", MenuSettingsNode.COMMANDS); - addSubNodeReplacer("open-action", MenuSettingsNode.OPEN_ACTIONS); - addSubNodeReplacer("open-with-item.id", MenuSettingsNode.OPEN_ITEM_MATERIAL); + addSubNodeReplacer("command", "commands"); + addSubNodeReplacer("open-action", "open-actions"); + addSubNodeReplacer("id", "material"); addSubNodeReplacer("ID", IconSettingsNode.MATERIAL); addSubNodeReplacer("DATA-VALUE", IconSettingsNode.DURABILITY); @@ -38,10 +37,10 @@ public class MenuNodeRenameUpgrade extends RegexUpgrade { addSubNodeReplacer("REQUIRED-ITEM", IconSettingsNode.REQUIRED_ITEMS); } - private void addSubNodeReplacer(String oldAttribute, String newAttribute) { + private void addSubNodeReplacer(String oldNode, String newNode) { addRegexReplacer( - Pattern.compile("(^\\s+)" + Pattern.quote(oldAttribute) + "(:)"), - matcher -> matcher.group(1) + newAttribute + matcher.group(2)); + Pattern.compile("(^\\s+)" + Pattern.quote(oldNode) + "(:)"), + matcher -> matcher.group(1) + newNode + matcher.group(2)); } } From 1e0c4caeccc2ab104ffb0ccc0f20237a07721fa2 Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 23 Jul 2020 16:57:51 +0200 Subject: [PATCH 146/213] Improve automatic configuration upgrades --- .../chestcommands/ChestCommands.java | 8 +- .../chestcommands/legacy/Backup.java | 36 +++++ .../chestcommands/legacy/Upgrade.java | 111 ++++++++++++++++ .../legacy/UpgradesDoneRegistry.java | 26 +--- .../legacy/UpgradesExecutor.java | 123 ++++++------------ ...{LangUpgrade.java => LangUpgradeTask.java} | 4 +- ...de.java => MenuNodeExpandUpgradeTask.java} | 16 +-- ...de.java => MenuNodeRenameUpgradeTask.java} | 4 +- ....java => PlaceholdersYamlUpgradeTask.java} | 10 +- ...egexUpgrade.java => RegexUpgradeTask.java} | 10 +- ...sUpgrade.java => SettingsUpgradeTask.java} | 10 +- .../{Upgrade.java => UpgradeTask.java} | 42 +++--- ...ception.java => UpgradeTaskException.java} | 4 +- .../chestcommands/logging/ErrorMessages.java | 17 +-- .../logging/PrintableErrorCollector.java | 4 +- 15 files changed, 250 insertions(+), 175 deletions(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/{LangUpgrade.java => LangUpgradeTask.java} (89%) rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/{MenuNodeExpandUpgrade.java => MenuNodeExpandUpgradeTask.java} (92%) rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/{MenuNodeRenameUpgrade.java => MenuNodeRenameUpgradeTask.java} (93%) rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/{PlaceholdersYamlUpgrade.java => PlaceholdersYamlUpgradeTask.java} (92%) rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/{RegexUpgrade.java => RegexUpgradeTask.java} (91%) rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/{SettingsUpgrade.java => SettingsUpgradeTask.java} (88%) rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/{Upgrade.java => UpgradeTask.java} (58%) rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/{UpgradeException.java => UpgradeTaskException.java} (86%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 810230a..8bb2209 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -166,10 +166,16 @@ public class ChestCommands extends BaseJavaPlugin { return errorCollector; } + UpgradesExecutor upgradeExecutor = new UpgradesExecutor(configManager); + try { - new UpgradesExecutor(configManager).run(isFreshInstall, errorCollector); + boolean allUpgradesSuccessful = upgradeExecutor.run(isFreshInstall, errorCollector); + if (!allUpgradesSuccessful) { + errorCollector.add(ErrorMessages.Upgrade.failedSomeUpgrades); + } } catch (UpgradeExecutorException e) { errorCollector.add(ErrorMessages.Upgrade.genericExecutorError, e); + errorCollector.add(ErrorMessages.Upgrade.failedSomeUpgrades); } settings = configManager.tryLoadSettings(errorCollector); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java new file mode 100644 index 0000000..ac953a2 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java @@ -0,0 +1,36 @@ +package me.filoghost.chestcommands.legacy; + +import me.filoghost.chestcommands.util.Preconditions; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +public class Backup { + + private final Path dataFolder; + private final Path backupFolder; + + public Backup(Path dataFolder, String backupName) { + this.dataFolder = dataFolder; + this.backupFolder = dataFolder.resolve("backups").resolve(backupName); + } + + public static Backup newTimestampedBackup(Path dataFolder) { + String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy.MM.dd-HH.mm")); + String backupName = "backup_" + date; + return new Backup(dataFolder, backupName); + } + + public void backupFile(Path fileToBackup) throws IOException { + Preconditions.checkArgument(fileToBackup.startsWith(dataFolder), "file is not inside data folder"); + Path destination = backupFolder.resolve(dataFolder.relativize(fileToBackup)); + Files.createDirectories(destination.getParent()); + if (!Files.isRegularFile(destination)) { + Files.copy(fileToBackup, destination); + } + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java new file mode 100644 index 0000000..b6ce2d4 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java @@ -0,0 +1,111 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.legacy; + +import me.filoghost.chestcommands.config.ConfigManager; +import me.filoghost.chestcommands.config.framework.ConfigLoader; +import me.filoghost.chestcommands.legacy.upgrade.LangUpgradeTask; +import me.filoghost.chestcommands.legacy.upgrade.MenuNodeExpandUpgradeTask; +import me.filoghost.chestcommands.legacy.upgrade.MenuNodeRenameUpgradeTask; +import me.filoghost.chestcommands.legacy.upgrade.PlaceholdersYamlUpgradeTask; +import me.filoghost.chestcommands.legacy.upgrade.SettingsUpgradeTask; +import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask; +import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException; +import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.util.collection.CollectionUtils; +import me.filoghost.chestcommands.util.logging.Log; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.Collections; +import java.util.List; + +public enum Upgrade { + + V4_MENUS_RENAME("v4.0-menus-rename", (configManager) -> { + List menuFiles = getMenuFiles(configManager); + + return CollectionUtils.transform(menuFiles, + MenuNodeRenameUpgradeTask::new); + }), + + V4_MENUS_REFORMAT("v4.0-menus-reformat", (configManager) -> { + String legacyCommandSeparator = readLegacyCommandSeparator(configManager); + List menuFiles = getMenuFiles(configManager); + + return CollectionUtils.transform(menuFiles, + file -> new MenuNodeExpandUpgradeTask(configManager, file, legacyCommandSeparator)); + }), + + V4_CONFIG("v4.0-config", (configManager) -> { + return Collections.singletonList(new SettingsUpgradeTask(configManager)); + }), + + V4_PLACEHOLDERS("v4.0-placeholders", (configManager) -> { + return Collections.singletonList(new PlaceholdersYamlUpgradeTask(configManager)); + }), + + V4_LANG("v4.0-lang", (configManager) -> { + return Collections.singletonList(new LangUpgradeTask(configManager)); + }); + + + private final String id; + private final UpgradeTasksSupplier upgradeTasksSupplier; + + Upgrade(String id, UpgradeTasksSupplier upgradeTasksSupplier) { + this.id = id; + this.upgradeTasksSupplier = upgradeTasksSupplier; + } + + public String getID() { + return id; + } + + public List createUpgradeTasks(ConfigManager configManager) throws UpgradeTaskException { + return upgradeTasksSupplier.getTasks(configManager); + } + + private static List getMenuFiles(ConfigManager configManager) throws UpgradeTaskException { + try { + return configManager.getMenuPaths(); + } catch (IOException e) { + throw new UpgradeTaskException(ErrorMessages.Upgrade.menuListIOException, e); + } + } + + private static String readLegacyCommandSeparator(ConfigManager configManager) { + ConfigLoader settingsConfigLoader = configManager.getConfigLoader("config.yml"); + + if (!settingsConfigLoader.fileExists()) { + return null; + } + + try { + return settingsConfigLoader.load().getString("multiple-commands-separator"); + } catch (Throwable t) { + Log.warning("Failed to load \"" + settingsConfigLoader.getFile() + "\", assuming default command separator \";\"."); + return null; + } + } + + @FunctionalInterface + interface UpgradeTasksSupplier { + + List getTasks(ConfigManager configManager) throws UpgradeTaskException; + + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java index 3005969..7e76bde 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java @@ -42,19 +42,19 @@ public class UpgradesDoneRegistry { } public void setAllDone() { - for (UpgradeID upgrade : UpgradeID.values()) { + for (Upgrade upgrade : Upgrade.values()) { setDone(upgrade); } } - public void setDone(UpgradeID upgrade) { - if (upgradesDone.add(upgrade.stringID)) { + public void setDone(Upgrade upgrade) { + if (upgradesDone.add(upgrade.getID())) { needSave = true; } } - public boolean isDone(UpgradeID upgrade) { - return upgradesDone.contains(upgrade.stringID); + public boolean isDone(Upgrade upgrade) { + return upgradesDone.contains(upgrade.getID()); } public void save() throws IOException { @@ -70,20 +70,4 @@ public class UpgradesDoneRegistry { } } - - public enum UpgradeID { - - V4_MENU_REPLACE("v4.0-menus-rename"), - V4_MENUS_REFORMAT("v4.0-menus-reformat"), - V4_CONFIG("v4.0-config"), - V4_PLACEHOLDERS("v4.0-placeholders"), - V4_LANG("v4.0-lang"); - - private final String stringID; - - UpgradeID(String stringID) { - this.stringID = stringID; - } - } - } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java index 6d5a90f..b2f4207 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java @@ -15,40 +15,28 @@ package me.filoghost.chestcommands.legacy; import me.filoghost.chestcommands.config.ConfigManager; -import me.filoghost.chestcommands.config.framework.ConfigLoader; -import me.filoghost.chestcommands.legacy.UpgradesDoneRegistry.UpgradeID; -import me.filoghost.chestcommands.legacy.upgrade.LangUpgrade; -import me.filoghost.chestcommands.legacy.upgrade.MenuNodeExpandUpgrade; -import me.filoghost.chestcommands.legacy.upgrade.MenuNodeRenameUpgrade; -import me.filoghost.chestcommands.legacy.upgrade.PlaceholdersYamlUpgrade; -import me.filoghost.chestcommands.legacy.upgrade.SettingsUpgrade; -import me.filoghost.chestcommands.legacy.upgrade.Upgrade; -import me.filoghost.chestcommands.legacy.upgrade.UpgradeException; +import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask; +import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException; import me.filoghost.chestcommands.logging.ErrorMessages; -import me.filoghost.chestcommands.util.collection.CollectionUtils; import me.filoghost.chestcommands.util.logging.ErrorCollector; import me.filoghost.chestcommands.util.logging.Log; import java.io.IOException; import java.nio.file.Path; -import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; -import java.util.function.Supplier; public class UpgradesExecutor { private final ConfigManager configManager; - private Set failedUpgrades; + private boolean allUpgradesSuccessful; private UpgradesDoneRegistry upgradesDoneRegistry; public UpgradesExecutor(ConfigManager configManager) { this.configManager = configManager; } - public void run(boolean isFreshInstall, ErrorCollector errorCollector) throws UpgradeExecutorException { - this.failedUpgrades = new HashSet<>(); + public boolean run(boolean isFreshInstall, ErrorCollector errorCollector) throws UpgradeExecutorException { + this.allUpgradesSuccessful = true; Path upgradesDoneFile = configManager.getRootDataFolder().resolve(".upgrades-done"); try { @@ -61,99 +49,64 @@ public class UpgradesExecutor { if (isFreshInstall) { // Mark all currently existing upgrades as already done, assuming default configuration files are up to date upgradesDoneRegistry.setAllDone(); - } else { - String legacyCommandSeparator; - if (!upgradesDoneRegistry.isDone(UpgradeID.V4_MENUS_REFORMAT)) { - legacyCommandSeparator = readLegacyCommandSeparator(); - } else { - legacyCommandSeparator = null; - } - - runIfNecessary(UpgradeID.V4_CONFIG, () -> new SettingsUpgrade(configManager), errorCollector); - runIfNecessary(UpgradeID.V4_PLACEHOLDERS, () -> new PlaceholdersYamlUpgrade(configManager), errorCollector); - runIfNecessary(UpgradeID.V4_LANG, () -> new LangUpgrade(configManager), errorCollector); - - try { - List menuFiles = configManager.getMenuPaths(); - - runIfNecessaryMultiple(UpgradeID.V4_MENU_REPLACE, () -> { - return CollectionUtils.transform(menuFiles, - MenuNodeRenameUpgrade::new); - }, errorCollector); - - runIfNecessaryMultiple(UpgradeID.V4_MENUS_REFORMAT, () -> { - return CollectionUtils.transform(menuFiles, - file -> new MenuNodeExpandUpgrade(configManager, file, legacyCommandSeparator)); - }, errorCollector); - - } catch (IOException e) { - errorCollector.add(ErrorMessages.Upgrade.menuListIOException, e); - failedUpgrades.add(configManager.getMenusFolder()); - } + // Run missing upgrades + Backup backup = Backup.newTimestampedBackup(configManager.getRootDataFolder()); + runMissingUpgrades(backup, errorCollector); } try { upgradesDoneRegistry.save(); } catch (IOException e) { - // Upgrades can't proceed if metadata file is not read correctly + // Upgrades can't proceed if metadata file is not saved correctly throw new UpgradeExecutorException(ErrorMessages.Upgrade.metadataSaveError(upgradesDoneFile), e); } - // Success only if no upgrade failed - if (!failedUpgrades.isEmpty()) { - throw new UpgradeExecutorException(ErrorMessages.Upgrade.failedUpgradesList(failedUpgrades)); + return allUpgradesSuccessful; + } + + + private void runMissingUpgrades(Backup backup, ErrorCollector errorCollector) { + for (Upgrade upgrade : Upgrade.values()) { + if (!upgradesDoneRegistry.isDone(upgrade)) { + boolean allTasksSuccessful = tryRunUpgradeTasks(upgrade, backup, errorCollector); + + // Consider an upgrade "done" if all its tasks were completed successfully + if (allTasksSuccessful) { + upgradesDoneRegistry.setDone(upgrade); + } else { + allUpgradesSuccessful = false; + } + } } } - private String readLegacyCommandSeparator() { - ConfigLoader settingsConfigLoader = configManager.getConfigLoader("config.yml"); - if (!settingsConfigLoader.fileExists()) { - return null; - } + private boolean tryRunUpgradeTasks(Upgrade upgrade, Backup backup, ErrorCollector errorCollector) { + boolean allTasksSuccessful = true; + List upgradeTasks; try { - return settingsConfigLoader.load().getString("multiple-commands-separator"); - } catch (Throwable t) { - Log.warning("Failed to load \"" + settingsConfigLoader.getFile() + "\", assuming default command separator \";\"."); - return null; - } - } - - - private void runIfNecessary(UpgradeID upgradeID, Supplier upgradeTask, ErrorCollector errorCollector) { - runIfNecessaryMultiple(upgradeID, () -> Collections.singletonList(upgradeTask.get()), errorCollector); - } - - - private void runIfNecessaryMultiple(UpgradeID upgradeID, Supplier> upgradeTasks, ErrorCollector errorCollector) { - if (upgradesDoneRegistry.isDone(upgradeID)) { - return; + upgradeTasks = upgrade.createUpgradeTasks(configManager); + } catch (UpgradeTaskException e) { + errorCollector.add(ErrorMessages.Upgrade.failedToPrepareUpgradeTasks, e); + return false; } - boolean failedAnyUpgrade = false; - - for (Upgrade upgradeTask : upgradeTasks.get()) { + for (UpgradeTask upgradeTask : upgradeTasks) { try { - boolean modified = upgradeTask.backupAndUpgradeIfNecessary(); + boolean modified = upgradeTask.runAndBackupIfNecessary(backup); if (modified) { - Log.info( - "Automatically upgraded configuration file \"" - + upgradeTask.getUpgradedFile() + "\" with newer configuration nodes. " + Log.info("Automatically upgraded configuration file \"" + upgradeTask.getUpgradedFile() + "\". " + "A backup of the old file has been saved."); } - } catch (UpgradeException e) { - failedAnyUpgrade = true; - failedUpgrades.add(upgradeTask.getOriginalFile()); + } catch (UpgradeTaskException e) { + allTasksSuccessful = false; errorCollector.add(ErrorMessages.Upgrade.failedSingleUpgrade(upgradeTask.getOriginalFile()), e); } } - // Upgrade ID is considered complete only if all relative upgrades tasks are successful - if (!failedAnyUpgrade) { - upgradesDoneRegistry.setDone(upgradeID); - } + return allTasksSuccessful; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/LangUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/LangUpgradeTask.java similarity index 89% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/LangUpgrade.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/LangUpgradeTask.java index 22c67f7..9df8f7a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/LangUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/LangUpgradeTask.java @@ -18,9 +18,9 @@ import me.filoghost.chestcommands.config.ConfigManager; import java.util.regex.Pattern; -public class LangUpgrade extends RegexUpgrade { +public class LangUpgradeTask extends RegexUpgradeTask { - public LangUpgrade(ConfigManager configManager) { + public LangUpgradeTask(ConfigManager configManager) { super(configManager.getRootDataFolder().resolve("lang.yml")); addRegexReplacer(Pattern.compile(Pattern.quote("{datavalue}")), matcher -> "{durability}"); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgrade.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java index c2d5cec..e311f76 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java @@ -30,13 +30,13 @@ import java.util.Collections; import java.util.List; import java.util.regex.Pattern; -public class MenuNodeExpandUpgrade extends Upgrade { +public class MenuNodeExpandUpgradeTask extends UpgradeTask { private final ConfigLoader menuConfigLoader; private final String legacyCommandSeparator; private Config updatedConfig; - public MenuNodeExpandUpgrade(ConfigManager configManager, Path menuFile, String legacyCommandSeparator) { + public MenuNodeExpandUpgradeTask(ConfigManager configManager, Path menuFile, String legacyCommandSeparator) { this.menuConfigLoader = configManager.getConfigLoader(menuFile); this.legacyCommandSeparator = legacyCommandSeparator; } @@ -52,7 +52,7 @@ public class MenuNodeExpandUpgrade extends Upgrade { } @Override - protected void computeChanges() throws ConfigLoadException { + public void computeChanges() throws ConfigLoadException { Config menuConfig = menuConfigLoader.load(); menuConfig.setHeader(null); @@ -74,7 +74,7 @@ public class MenuNodeExpandUpgrade extends Upgrade { } @Override - protected void saveChanges() throws ConfigSaveException { + public void saveChanges() throws ConfigSaveException { menuConfigLoader.save(updatedConfig); } @@ -110,7 +110,7 @@ public class MenuNodeExpandUpgrade extends Upgrade { } material = parts[0]; section.set(IconSettingsNode.MATERIAL, material); - setModified(); + setSaveRequired(); } if (material.contains(":")) { @@ -124,7 +124,7 @@ public class MenuNodeExpandUpgrade extends Upgrade { } material = parts[0]; section.set(IconSettingsNode.MATERIAL, material); - setModified(); + setSaveRequired(); } } @@ -132,7 +132,7 @@ public class MenuNodeExpandUpgrade extends Upgrade { if (config.isSet(node)) { if (config.isString(node)) { config.set(node, getSeparatedValues(config.getString(node), separator)); - setModified(); + setSaveRequired(); } } } @@ -140,7 +140,7 @@ public class MenuNodeExpandUpgrade extends Upgrade { private void expandSingletonList(ConfigSection config, String node) { if (config.isSet(node)) { config.set(node, Collections.singletonList(config.get(node))); - setModified(); + setSaveRequired(); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgradeTask.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgrade.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgradeTask.java index f1bb9cf..5cb85b6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgradeTask.java @@ -19,9 +19,9 @@ import me.filoghost.chestcommands.parsing.icon.IconSettingsNode; import java.nio.file.Path; import java.util.regex.Pattern; -public class MenuNodeRenameUpgrade extends RegexUpgrade { +public class MenuNodeRenameUpgradeTask extends RegexUpgradeTask { - public MenuNodeRenameUpgrade(Path menuFile) { + public MenuNodeRenameUpgradeTask(Path menuFile) { super(menuFile); addSubNodeReplacer("command", "commands"); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgradeTask.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgrade.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgradeTask.java index 4112d49..06dc4a0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgradeTask.java @@ -28,13 +28,13 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.List; -public class PlaceholdersYamlUpgrade extends Upgrade { +public class PlaceholdersYamlUpgradeTask extends UpgradeTask { private final Path oldPlaceholdersFile; private final ConfigLoader newPlaceholdersConfigLoader; private Config updatedConfig; - public PlaceholdersYamlUpgrade(ConfigManager configManager) { + public PlaceholdersYamlUpgradeTask(ConfigManager configManager) { this.oldPlaceholdersFile = configManager.getRootDataFolder().resolve("placeholders.yml"); this.newPlaceholdersConfigLoader = configManager.getConfigLoader("custom-placeholders.yml"); } @@ -50,7 +50,7 @@ public class PlaceholdersYamlUpgrade extends Upgrade { } @Override - protected void computeChanges() throws ConfigLoadException { + public void computeChanges() throws ConfigLoadException { if (!Files.isRegularFile(oldPlaceholdersFile)) { return; } @@ -80,14 +80,14 @@ public class PlaceholdersYamlUpgrade extends Upgrade { String replacement = StringEscapeUtils.unescapeJava(unquote(parts[1])); newPlaceholdersConfig.set(placeholder, replacement); - setModified(); + setSaveRequired(); } this.updatedConfig = newPlaceholdersConfig; } @Override - protected void saveChanges() throws ConfigSaveException { + public void saveChanges() throws ConfigSaveException { try { Files.deleteIfExists(oldPlaceholdersFile); } catch (IOException ignored) {} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java similarity index 91% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgrade.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java index 503d35b..2f4d8f9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java @@ -30,13 +30,13 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; -public class RegexUpgrade extends Upgrade { +public class RegexUpgradeTask extends UpgradeTask { private final Path file; private final List replacers; private List newContents; - public RegexUpgrade(Path file) { + public RegexUpgradeTask(Path file) { this.file = file; this.replacers = new ArrayList<>(); } @@ -56,7 +56,7 @@ public class RegexUpgrade extends Upgrade { } @Override - protected void computeChanges() throws ConfigLoadException { + public void computeChanges() throws ConfigLoadException { if (!Files.isRegularFile(file)) { return; } @@ -76,12 +76,12 @@ public class RegexUpgrade extends Upgrade { newContents = linesStream.collect(Collectors.toList()); if (!newContents.equals(lines)) { - setModified(); + setSaveRequired(); } } @Override - protected void saveChanges() throws ConfigSaveException { + public void saveChanges() throws ConfigSaveException { try { Files.write(file, newContents); } catch (IOException e) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgradeTask.java similarity index 88% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgrade.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgradeTask.java index dccbaf5..f26663d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgradeTask.java @@ -22,12 +22,12 @@ import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException import java.nio.file.Path; -public class SettingsUpgrade extends Upgrade { +public class SettingsUpgradeTask extends UpgradeTask { private final ConfigLoader settingsConfigLoader; private Config updatedConfig; - public SettingsUpgrade(ConfigManager configManager) { + public SettingsUpgradeTask(ConfigManager configManager) { this.settingsConfigLoader = configManager.getConfigLoader("config.yml"); } @@ -42,7 +42,7 @@ public class SettingsUpgrade extends Upgrade { } @Override - protected void computeChanges() throws ConfigLoadException { + public void computeChanges() throws ConfigLoadException { if (!settingsConfigLoader.fileExists()) { return; } @@ -58,13 +58,13 @@ public class SettingsUpgrade extends Upgrade { private void removeNode(Config config, String node) { if (config.isSet(node)) { config.set(node, null); - setModified(); + setSaveRequired(); } } @Override - protected void saveChanges() throws ConfigSaveException { + public void saveChanges() throws ConfigSaveException { settingsConfigLoader.save(updatedConfig); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java similarity index 58% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java index c9daefa..a6d9cbc 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java @@ -16,58 +16,50 @@ package me.filoghost.chestcommands.legacy.upgrade; import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; +import me.filoghost.chestcommands.legacy.Backup; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.util.Preconditions; import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -public abstract class Upgrade { +public abstract class UpgradeTask { - private boolean modified; + private boolean saveRequired; private boolean hasRun; - protected void setModified() { - this.modified = true; + protected void setSaveRequired() { + this.saveRequired = true; } - - public boolean backupAndUpgradeIfNecessary() throws UpgradeException { - Preconditions.checkState(!hasRun, "Upgrade can only be run once"); + public boolean runAndBackupIfNecessary(Backup backup) throws UpgradeTaskException { + Preconditions.checkState(!hasRun, "Upgrade task has already run"); hasRun = true; try { computeChanges(); } catch (ConfigLoadException e) { - throw new UpgradeException(ErrorMessages.Upgrade.loadError(getOriginalFile()), e); + throw new UpgradeTaskException(ErrorMessages.Upgrade.loadError(getOriginalFile()), e); } - if (modified) { + if (saveRequired) { try { - createBackupFile(getOriginalFile()); + backup.backupFile(getOriginalFile()); } catch (IOException e) { - throw new UpgradeException(ErrorMessages.Upgrade.backupError(getOriginalFile()), e); + throw new UpgradeTaskException(ErrorMessages.Upgrade.backupError(getOriginalFile()), e); } try { saveChanges(); } catch (ConfigSaveException e) { - throw new UpgradeException(ErrorMessages.Upgrade.saveError(getUpgradedFile()), e); + throw new UpgradeTaskException(ErrorMessages.Upgrade.saveError(getUpgradedFile()), e); } + + return true; + + } else { + return false; } - - return modified; - } - - private void createBackupFile(Path path) throws IOException { - String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy.MM.dd-HH.mm")); - String backupName = path.getFileName() + "_" + date + ".backup"; - - Files.copy(path, path.resolveSibling(backupName), StandardCopyOption.REPLACE_EXISTING); } public abstract Path getOriginalFile(); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeException.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTaskException.java similarity index 86% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeException.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTaskException.java index 3f1a77d..18db42a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTaskException.java @@ -14,9 +14,9 @@ */ package me.filoghost.chestcommands.legacy.upgrade; -public class UpgradeException extends Exception { +public class UpgradeTaskException extends Exception { - public UpgradeException(String message, Throwable cause) { + public UpgradeTaskException(String message, Throwable cause) { super(message, cause); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java index 8ea48a9..c5c17ba 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java @@ -18,8 +18,6 @@ import me.filoghost.chestcommands.config.framework.mapped.MappedConfig; import me.filoghost.chestcommands.parsing.icon.IconSettings; import java.nio.file.Path; -import java.util.Set; -import java.util.stream.Collectors; public class ErrorMessages { @@ -72,9 +70,10 @@ public class ErrorMessages { public static class Upgrade { - public static final String genericExecutorError = "encountered errors while running run automatic configuration upgrades, " - + "some configuration files or menus may require manual updates."; - public static final String menuListIOException = "couldn't obtain a list of menu files, some automatic upgrades were skipped"; + public static final String genericExecutorError = "error while running automatic configuration upgrades"; + public static final String menuListIOException = "couldn't obtain a list of menu files"; + public static final String failedSomeUpgrades = "note: one or more automatic upgrades may have not been applied, configuration files or menus may require manual changes"; + public static final String failedToPrepareUpgradeTasks = "error while trying to prepare an automatic configuration upgrade"; public static String metadataReadError(Path metadataFile) { return "couldn't read upgrades metadata file \"" + formatPath(metadataFile) + "\""; @@ -88,13 +87,6 @@ public class ErrorMessages { return "error while trying to automatically upgrade \"" + formatPath(file) + "\""; } - public static String failedUpgradesList(Set failedUpgrades) { - String failedConversionFiles = failedUpgrades.stream() - .map(path -> "\"" + path + "\"") - .collect(Collectors.joining(", ")); - return "failed to automatically upgrade the following files: " + failedConversionFiles; - } - public static String loadError(Path file) { return "couldn't load file to upgrade \"" + formatPath(file) + "\""; } @@ -106,6 +98,7 @@ public class ErrorMessages { public static String saveError(Path file) { return "couldn't save upgraded file \"" + formatPath(file) + "\""; } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java index 443c5bf..f640d1c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java @@ -18,7 +18,7 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.config.framework.exception.ConfigException; import me.filoghost.chestcommands.config.framework.exception.ConfigSyntaxException; import me.filoghost.chestcommands.legacy.UpgradeExecutorException; -import me.filoghost.chestcommands.legacy.upgrade.UpgradeException; +import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException; import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.chestcommands.util.logging.ErrorCollector; import me.filoghost.chestcommands.util.logging.ErrorInfo; @@ -65,7 +65,7 @@ public class PrintableErrorCollector extends ErrorCollector { } else if (cause instanceof ConfigException || cause instanceof ParseException - || cause instanceof UpgradeException + || cause instanceof UpgradeTaskException || cause instanceof UpgradeExecutorException) { message.add(cause.getMessage()); cause = cause.getCause(); // Print the cause (or nothing if null), not our "known" exception From e9f710a1d350351c589fe113546fe693fcd6daf8 Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 23 Jul 2020 17:03:51 +0200 Subject: [PATCH 147/213] Fix menu upgrade --- .../chestcommands/config/framework/ConfigSection.java | 5 +++++ .../legacy/upgrade/MenuNodeExpandUpgradeTask.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java index 843eb02..ecdb9fd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java @@ -139,10 +139,15 @@ public class ConfigSection { return yamlSection.isConfigurationSection(path); } + public boolean isList(String path) { + return yamlSection.isList(path); + } + private boolean isPrimitiveWrapper(Object input) { return input instanceof Integer || input instanceof Boolean || input instanceof Character || input instanceof Byte || input instanceof Short || input instanceof Double || input instanceof Long || input instanceof Float; } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java index e311f76..9ef01f9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java @@ -138,7 +138,7 @@ public class MenuNodeExpandUpgradeTask extends UpgradeTask { } private void expandSingletonList(ConfigSection config, String node) { - if (config.isSet(node)) { + if (config.isSet(node) && !config.isList(node)) { config.set(node, Collections.singletonList(config.get(node))); setSaveRequired(); } From 6a00d49e06b5fc61efd410e586fec0077cb5ecc2 Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 24 Jul 2020 18:06:09 +0200 Subject: [PATCH 148/213] Change backups folder name and add "readme.txt" --- .../me/filoghost/chestcommands/legacy/Backup.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java index ac953a2..cf11e23 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java @@ -7,15 +7,19 @@ import java.nio.file.Files; import java.nio.file.Path; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.Arrays; public class Backup { private final Path dataFolder; private final Path backupFolder; + private final Path infoFile; public Backup(Path dataFolder, String backupName) { this.dataFolder = dataFolder; - this.backupFolder = dataFolder.resolve("backups").resolve(backupName); + Path backupsFolder = dataFolder.resolve("old_files"); + this.backupFolder = backupsFolder.resolve(backupName); + this.infoFile = backupsFolder.resolve("readme.txt"); } public static Backup newTimestampedBackup(Path dataFolder) { @@ -31,6 +35,13 @@ public class Backup { if (!Files.isRegularFile(destination)) { Files.copy(fileToBackup, destination); } + if (!Files.isRegularFile(infoFile)) { + Files.write(infoFile, Arrays.asList( + "Files in this folders are copies of original configuration files that have been automatically upgraded.", + "", + "Note: some configuration upgrades remove comments and other formatting (such as empty lines)." + )); + } } } From cf8e5da6bfa521f69359ca0f7dff7f6d56780d69 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 25 Jul 2020 10:23:59 +0200 Subject: [PATCH 149/213] Refactoring --- .../chestcommands/ChestCommands.java | 10 ++- .../chestcommands/action/BroadcastAction.java | 4 +- .../chestcommands/action/GiveMoneyAction.java | 6 +- .../action/SendMessageAction.java | 4 +- .../chestcommands/config/ConfigManager.java | 19 ++--- .../config/CustomPlaceholders.java | 11 ++- .../chestcommands/hook/PluginHook.java | 1 - .../icon/InternalConfigurableIcon.java | 15 ++-- .../icon/requirement/RequiredExpLevel.java | 4 -- .../icon/requirement/RequiredItems.java | 4 -- .../icon/requirement/RequiredMoney.java | 4 -- ...onChecker.java => RequiredPermission.java} | 4 +- .../icon/requirement/Requirement.java | 2 +- .../chestcommands/legacy/Upgrade.java | 2 +- .../upgrade/MenuNodeExpandUpgradeTask.java | 4 +- .../chestcommands/listener/JoinListener.java | 14 ++-- .../chestcommands/logging/ErrorMessages.java | 11 ++- .../chestcommands/parsing/ActionParser.java | 10 +-- .../ActionsAttribute.java | 6 +- .../AmountAttribute.java | 6 +- .../ApplicableIconAttribute.java | 2 +- .../attribute/AttributeErrorHandler.java | 23 ++++++ .../BannerColorAttribute.java | 6 +- .../BannerPatternsAttribute.java | 8 +-- .../ClickPermissionAttribute.java | 6 +- .../ClickPermissionMessageAttribute.java | 6 +- .../DurabilityAttribute.java | 6 +- .../EnchantmentsAttribute.java | 8 +-- .../ExpLevelsAttribute.java | 6 +- .../{icon => attribute}/IconAttribute.java | 2 +- .../KeepOpenAttribute.java | 6 +- .../LeatherColorAttribute.java | 6 +- .../LoreAttribute.java | 8 +-- .../MaterialAttribute.java | 6 +- .../NBTDataAttribute.java | 6 +- .../NameAttribute.java | 8 +-- .../PositionAttribute.java | 7 +- .../PriceAttribute.java | 6 +- .../RequiredItemsAttribute.java | 8 +-- .../SkullOwnerAttribute.java | 6 +- .../ViewPermissionAttribute.java | 6 +- .../parsing/icon/AttributeErrorCollector.java | 37 ---------- .../parsing/icon/IconSettings.java | 72 ++++++++++--------- .../placeholder/DefaultPlaceholders.java | 14 ++-- 44 files changed, 178 insertions(+), 232 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/{PermissionChecker.java => RequiredPermission.java} (95%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/ActionsAttribute.java (84%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/AmountAttribute.java (78%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon => attribute}/ApplicableIconAttribute.java (93%) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/AttributeErrorHandler.java rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/BannerColorAttribute.java (81%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/BannerPatternsAttribute.java (82%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/ClickPermissionAttribute.java (81%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/ClickPermissionMessageAttribute.java (80%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/DurabilityAttribute.java (76%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/EnchantmentsAttribute.java (83%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/ExpLevelsAttribute.java (78%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon => attribute}/IconAttribute.java (92%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/KeepOpenAttribute.java (78%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/LeatherColorAttribute.java (81%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/LoreAttribute.java (79%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/MaterialAttribute.java (84%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/NBTDataAttribute.java (80%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/NameAttribute.java (78%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/PositionAttribute.java (74%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/PriceAttribute.java (78%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/RequiredItemsAttribute.java (84%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/SkullOwnerAttribute.java (76%) rename Plugin/src/main/java/me/filoghost/chestcommands/parsing/{icon/attributes => attribute}/ViewPermissionAttribute.java (81%) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeErrorCollector.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 8bb2209..53fa5e6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -48,6 +48,7 @@ import org.bukkit.entity.Player; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.util.List; public class ChestCommands extends BaseJavaPlugin { @@ -55,8 +56,8 @@ public class ChestCommands extends BaseJavaPlugin { public static final String CHAT_PREFIX = ChatColor.DARK_GREEN + "[" + ChatColor.GREEN + "ChestCommands" + ChatColor.DARK_GREEN + "] " + ChatColor.GREEN; - private static ChestCommands instance; + private static Path dataFolderPath; private ConfigManager configManager; private MenuManager menuManager; @@ -85,10 +86,11 @@ public class ChestCommands extends BaseJavaPlugin { System.setProperty("ChestCommandsLoaded", "true"); instance = this; + dataFolderPath = getDataFolder().toPath(); Log.setLogger(getLogger()); BackendAPI.setImplementation(new DefaultBackendAPI()); - configManager = new ConfigManager(getDataFolder().toPath()); + configManager = new ConfigManager(getDataFolderPath()); menuManager = new MenuManager(); settings = new Settings(); lang = new Lang(); @@ -148,13 +150,15 @@ public class ChestCommands extends BaseJavaPlugin { Bukkit.getScheduler().runTaskTimer(this, new TickingTask(), 1L, 1L); } + public static Path getDataFolderPath() { + return dataFolderPath; + } @Override public void onDisable() { closeAllMenus(); } - public ErrorCollector load() { ErrorCollector errorCollector = new PrintableErrorCollector(); menuManager.clear(); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java index aa92d26..7ba21b2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java @@ -23,8 +23,8 @@ public class BroadcastAction extends Action { private final RelativeString message; - public BroadcastAction(String action) { - message = RelativeString.of(Colors.addColors(action)); + public BroadcastAction(String serializedAction) { + message = RelativeString.of(Colors.addColors(serializedAction)); } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java index eda53d8..de15f04 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java @@ -24,11 +24,11 @@ public class GiveMoneyAction extends Action { private double moneyToGive; - public GiveMoneyAction(String action) { + public GiveMoneyAction(String serializedAction) { try { - moneyToGive = NumberParser.getStrictlyPositiveDouble(action); + moneyToGive = NumberParser.getStrictlyPositiveDouble(serializedAction); } catch (ParseException e) { - disable(ChatColor.RED + "Invalid money amount \"" + action + "\": " + e.getMessage()); + disable(ChatColor.RED + "Invalid money amount \"" + serializedAction + "\": " + e.getMessage()); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java index fcb77aa..787983d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java @@ -22,8 +22,8 @@ public class SendMessageAction extends Action { private final RelativeString message; - public SendMessageAction(String action) { - message = RelativeString.of(Colors.addColors(action)); + public SendMessageAction(String serializedAction) { + message = RelativeString.of(Colors.addColors(serializedAction)); } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java index b74d24d..8e90537 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java @@ -92,16 +92,11 @@ public class ConfigManager extends BaseConfigManager { return rootDataFolder.resolve("menu"); } - /** - * Returns a list of YML menu files. - */ - public List getMenuPaths() throws IOException { + public List getMenuFiles() throws IOException { Preconditions.checkState(Files.isDirectory(getMenusFolder()), "menus folder doesn't exist"); try (Stream paths = Files.walk(getMenusFolder(), FileVisitOption.FOLLOW_LINKS)) { - return paths.filter(Files::isRegularFile) - .filter(this::isYmlPath) - .collect(Collectors.toList()); + return paths.filter(this::isYamlFile).collect(Collectors.toList()); } } @@ -111,16 +106,16 @@ public class ConfigManager extends BaseConfigManager { public List tryLoadMenus(ErrorCollector errorCollector) { List loadedMenus = new ArrayList<>(); - List menuPaths; + List menuFiles; try { - menuPaths = getMenuPaths(); + menuFiles = getMenuFiles(); } catch (IOException e) { errorCollector.add(ErrorMessages.Config.menuListIOException(getMenusFolder()), e); return Collections.emptyList(); } - for (Path menuFile : menuPaths) { + for (Path menuFile : menuFiles) { ConfigLoader menuConfigLoader = new ConfigLoader(rootDataFolder, menuFile); try { @@ -134,8 +129,8 @@ public class ConfigManager extends BaseConfigManager { return loadedMenus; } - private boolean isYmlPath(Path path) { - return path.getFileName().toString().toLowerCase().endsWith(".yml"); + private boolean isYamlFile(Path path) { + return Files.isRegularFile(path) && path.getFileName().toString().toLowerCase().endsWith(".yml"); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java index a85e581..553b441 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java @@ -32,9 +32,8 @@ public class CustomPlaceholders { public void load(Config config, ErrorCollector errorCollector) { placeholders.clear(); - for (String key : config.getKeys(false)) { - String placeholder = key; - String replacement = Colors.addColors(config.getString(key)); + for (String placeholder : config.getKeys(false)) { + String replacement = Colors.addColors(config.getString(placeholder)); if (placeholder.length() == 0) { errorCollector.add(ErrorMessages.Config.emptyPlaceholder(config.getSourceFile())); @@ -50,14 +49,14 @@ public class CustomPlaceholders { } } - public List replaceAll(List input) { + public List replacePlaceholders(List input) { if (input == null) { return null; } - return CollectionUtils.transform(input, this::replaceAll); + return CollectionUtils.transform(input, this::replacePlaceholders); } - public String replaceAll(String input) { + public String replacePlaceholders(String input) { if (input == null) { return null; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java index a196910..9436ac5 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java @@ -26,6 +26,5 @@ public interface PluginHook { default void checkEnabledState() { Preconditions.checkState(isEnabled(), "Plugin hook " + getClass().getSimpleName() + " is not enabled"); } - } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java index 5dd0d1e..fd33442 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java @@ -18,11 +18,11 @@ import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.OpenMenuAction; import me.filoghost.chestcommands.api.ClickResult; import me.filoghost.chestcommands.api.MenuInventory; -import me.filoghost.chestcommands.icon.requirement.PermissionChecker; import me.filoghost.chestcommands.icon.requirement.RequiredExpLevel; import me.filoghost.chestcommands.icon.requirement.RequiredItem; import me.filoghost.chestcommands.icon.requirement.RequiredItems; import me.filoghost.chestcommands.icon.requirement.RequiredMoney; +import me.filoghost.chestcommands.icon.requirement.RequiredPermission; import me.filoghost.chestcommands.icon.requirement.Requirement; import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.collection.CollectionUtils; @@ -35,9 +35,9 @@ import java.util.List; public class InternalConfigurableIcon extends BaseConfigurableIcon implements RefreshableIcon { - private PermissionChecker viewPermission; + private RequiredPermission viewPermission; - private PermissionChecker clickPermission; + private RequiredPermission clickPermission; private RequiredMoney requiredMoney; private RequiredExpLevel requiredExpLevel; private RequiredItems requiredItems; @@ -60,7 +60,7 @@ public class InternalConfigurableIcon extends BaseConfigurableIcon implements Re } public void setClickPermission(String permission) { - this.clickPermission = new PermissionChecker(permission); + this.clickPermission = new RequiredPermission(permission); } public void setNoClickPermissionMessage(String clickNoPermissionMessage) { @@ -68,7 +68,7 @@ public class InternalConfigurableIcon extends BaseConfigurableIcon implements Re } public void setViewPermission(String viewPermission) { - this.viewPermission = new PermissionChecker(viewPermission); + this.viewPermission = new RequiredPermission(viewPermission); } public void setRequiredMoney(double requiredMoney) { @@ -123,13 +123,14 @@ public class InternalConfigurableIcon extends BaseConfigurableIcon implements Re @Override public ClickResult onClick(MenuInventory menuInventory, Player player) { // Check all the requirements - boolean hasAllRequirements = Requirement.hasAll(player, clickPermission, requiredMoney, requiredExpLevel, requiredItems); + Requirement[] requirements = {clickPermission, requiredMoney, requiredExpLevel, requiredItems}; + boolean hasAllRequirements = Requirement.hasAllCosts(player, requirements); if (!hasAllRequirements) { return clickResult; } // If all requirements are satisfied, take their cost - boolean takenAllCosts = Requirement.takeAllCosts(player, clickPermission, requiredMoney, requiredExpLevel, requiredItems); + boolean takenAllCosts = Requirement.takeAllCosts(player, requirements); if (!takenAllCosts) { return clickResult; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java index 4064ae3..3d4c959 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java @@ -26,10 +26,6 @@ public class RequiredExpLevel implements Requirement { Preconditions.checkArgument(levels > 0, "levels must be positive"); this.levels = levels; } - - public int getLevels() { - return levels; - } @Override public boolean hasCost(Player player) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItems.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItems.java index 9ff22f3..e8a7d84 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItems.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItems.java @@ -30,10 +30,6 @@ public class RequiredItems implements Requirement { Preconditions.notEmpty(items, "items"); this.items = ImmutableList.copyOf(items); } - - public List geItems() { - return items; - } @Override public boolean hasCost(Player player) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java index b21962a..ae23779 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java @@ -28,10 +28,6 @@ public class RequiredMoney implements Requirement { Preconditions.checkArgument(moneyAmount > 0.0, "money amount must be positive"); this.moneyAmount = moneyAmount; } - - public double getAmount() { - return moneyAmount; - } @Override public boolean hasCost(Player player) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/PermissionChecker.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java similarity index 95% rename from Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/PermissionChecker.java rename to Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java index 6e7a5ee..7b3ead5 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/PermissionChecker.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java @@ -18,13 +18,13 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.util.Strings; import org.bukkit.entity.Player; -public class PermissionChecker implements Requirement { +public class RequiredPermission implements Requirement { private final String permission; private final boolean negated; private String noPermissionMessage; - public PermissionChecker(String permission) { + public RequiredPermission(String permission) { if (permission != null) { permission = permission.trim(); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/Requirement.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/Requirement.java index b8e52e4..17d67ac 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/Requirement.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/Requirement.java @@ -22,7 +22,7 @@ public interface Requirement { boolean takeCost(Player player); - static boolean hasAll(Player player, Requirement... requirements) { + static boolean hasAllCosts(Player player, Requirement... requirements) { for (Requirement requirement : requirements) { if (requirement != null && !requirement.hasCost(player)) { return false; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java index b6ce2d4..0a9a5ef 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java @@ -80,7 +80,7 @@ public enum Upgrade { private static List getMenuFiles(ConfigManager configManager) throws UpgradeTaskException { try { - return configManager.getMenuPaths(); + return configManager.getMenuFiles(); } catch (IOException e) { throw new UpgradeTaskException(ErrorMessages.Upgrade.menuListIOException, e); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java index 9ef01f9..fc840ae 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java @@ -131,7 +131,7 @@ public class MenuNodeExpandUpgradeTask extends UpgradeTask { private void expandInlineList(ConfigSection config, String node, String separator) { if (config.isSet(node)) { if (config.isString(node)) { - config.set(node, getSeparatedValues(config.getString(node), separator)); + config.set(node, splitListElements(config.getString(node), separator)); setSaveRequired(); } } @@ -144,7 +144,7 @@ public class MenuNodeExpandUpgradeTask extends UpgradeTask { } } - private List getSeparatedValues(String input, String separator) { + private List splitListElements(String input, String separator) { if (separator == null || separator.length() == 0) { separator = ";"; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java index 50c9a6b..a789dd7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java @@ -17,6 +17,7 @@ package me.filoghost.chestcommands.listener; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; import org.bukkit.ChatColor; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; @@ -25,14 +26,17 @@ public class JoinListener implements Listener { @EventHandler public void onJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); - if (ChestCommands.getLastLoadErrors().hasErrors() && event.getPlayer().hasPermission(Permissions.SEE_ERRORS)) { - event.getPlayer().sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "The plugin found " + ChestCommands.getLastLoadErrors().getErrorsCount() + " error(s) last time it was loaded. You can see them by doing \"/cc reload\" in the console."); + if (ChestCommands.getLastLoadErrors().hasErrors() && player.hasPermission(Permissions.SEE_ERRORS)) { + player.sendMessage( + ChestCommands.CHAT_PREFIX + ChatColor.RED + "The plugin found " + ChestCommands.getLastLoadErrors().getErrorsCount() + + " error(s) last time it was loaded. You can see them by doing \"/cc reload\" in the console."); } - if (ChestCommands.hasNewVersion() && ChestCommands.getSettings().update_notifications && event.getPlayer().hasPermission(Permissions.UPDATE_NOTIFICATIONS)) { - event.getPlayer().sendMessage(ChestCommands.CHAT_PREFIX + "Found an update: " + ChestCommands.getNewVersion() + ". Download:"); - event.getPlayer().sendMessage(ChatColor.DARK_GREEN + ">> " + ChatColor.GREEN + "http://dev.bukkit.org/bukkit-plugins/chest-commands"); + if (ChestCommands.hasNewVersion() && ChestCommands.getSettings().update_notifications && player.hasPermission(Permissions.UPDATE_NOTIFICATIONS)) { + player.sendMessage(ChestCommands.CHAT_PREFIX + "Found an update: " + ChestCommands.getNewVersion() + ". Download:"); + player.sendMessage(ChatColor.DARK_GREEN + ">> " + ChatColor.GREEN + "http://dev.bukkit.org/bukkit-plugins/chest-commands"); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java index c5c17ba..9c849ed 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java @@ -14,6 +14,7 @@ */ package me.filoghost.chestcommands.logging; +import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.config.framework.mapped.MappedConfig; import me.filoghost.chestcommands.parsing.icon.IconSettings; @@ -26,7 +27,7 @@ public class ErrorMessages { public static final String readIOException = "I/O exception while reading file"; public static final String createDefaultIOException = "I/O exception while creating default file"; public static final String writeDataIOException = "I/O exception while writing data to file"; - public static final String createDataFolderIOException = "Plugin failed to load, couldn't create data folder"; + public static final String createDataFolderIOException = "plugin failed to load, couldn't create data folder"; public static final String invalidYamlSyntax = "invalid YAML syntax"; public static final String valueNotSet = "value is not set"; @@ -202,8 +203,14 @@ public class ErrorMessages { } } + private static String formatPath(Path path) { - return path.subpath(2, path.getNameCount()).toString(); // Remove "/plugins/ChestCommands" prefix + if (path.startsWith(ChestCommands.getDataFolderPath())) { + // Remove "/plugins/ChestCommands" prefix + return path.subpath(ChestCommands.getDataFolderPath().getNameCount(), path.getNameCount()).toString(); + } else { + return path.toString(); + } } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java index 19f538d..6fdb67c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java @@ -36,7 +36,7 @@ import java.util.regex.Pattern; public class ActionParser { - private static final Map actionsByPrefix = new HashMap<>(); + private static final Map actionsByPrefix = new HashMap<>(); static { actionsByPrefix.put(actionPattern("console:"), ConsoleCommandAction::new); @@ -56,20 +56,20 @@ public class ActionParser { } public static Action parseAction(String input) { - for (Entry entry : actionsByPrefix.entrySet()) { + for (Entry entry : actionsByPrefix.entrySet()) { Matcher matcher = entry.getKey().matcher(input); if (matcher.find()) { // Remove the action prefix and trim the spaces String serializedAction = matcher.replaceFirst("").trim(); - return entry.getValue().create(ChestCommands.getCustomPlaceholders().replaceAll(serializedAction)); + return entry.getValue().create(ChestCommands.getCustomPlaceholders().replacePlaceholders(serializedAction)); } } - return new PlayerCommandAction(ChestCommands.getCustomPlaceholders().replaceAll(input)); // Default action, no match found + return new PlayerCommandAction(ChestCommands.getCustomPlaceholders().replacePlaceholders(input)); // Default action, no match found } - private interface IconCommandFactory { + private interface ActionFactory { Action create(String actionString); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ActionsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ActionsAttribute.java similarity index 84% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ActionsAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ActionsAttribute.java index bd3d22b..68d70da 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ActionsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ActionsAttribute.java @@ -12,13 +12,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.parsing.ActionParser; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; import java.util.ArrayList; import java.util.List; @@ -27,7 +25,7 @@ public class ActionsAttribute implements ApplicableIconAttribute { private final List actions; - public ActionsAttribute(List serializedActions, AttributeErrorCollector attributeErrorCollector) { + public ActionsAttribute(List serializedActions, AttributeErrorHandler errorHandler) { actions = new ArrayList<>(); for (String serializedAction : serializedActions) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/AmountAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/AmountAttribute.java similarity index 78% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/AmountAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/AmountAttribute.java index 434fe26..679e8ce 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/AmountAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/AmountAttribute.java @@ -12,19 +12,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; public class AmountAttribute implements ApplicableIconAttribute { private final int amount; - public AmountAttribute(int amount, AttributeErrorCollector attributeErrorCollector) throws ParseException { + public AmountAttribute(int amount, AttributeErrorHandler errorHandler) throws ParseException { if (amount < 0) { throw new ParseException(ErrorMessages.Parsing.zeroOrPositive); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/ApplicableIconAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ApplicableIconAttribute.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/ApplicableIconAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ApplicableIconAttribute.java index bffcfb0..805d98b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/ApplicableIconAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ApplicableIconAttribute.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/AttributeErrorHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/AttributeErrorHandler.java new file mode 100644 index 0000000..acc9759 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/AttributeErrorHandler.java @@ -0,0 +1,23 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.parsing.attribute; + +import me.filoghost.chestcommands.parsing.ParseException; + +public interface AttributeErrorHandler { + + void onListElementError(String listElement, ParseException e); + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/BannerColorAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/BannerColorAttribute.java similarity index 81% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/BannerColorAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/BannerColorAttribute.java index 805f71f..6c0249d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/BannerColorAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/BannerColorAttribute.java @@ -12,20 +12,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.parsing.ItemMetaParser; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; import org.bukkit.DyeColor; public class BannerColorAttribute implements ApplicableIconAttribute { private final DyeColor dyeColor; - public BannerColorAttribute(String serializedDyeColor, AttributeErrorCollector attributeErrorCollector) throws ParseException { + public BannerColorAttribute(String serializedDyeColor, AttributeErrorHandler errorHandler) throws ParseException { this.dyeColor = ItemMetaParser.parseDyeColor(serializedDyeColor); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/BannerPatternsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/BannerPatternsAttribute.java similarity index 82% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/BannerPatternsAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/BannerPatternsAttribute.java index e838192..36d96a5 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/BannerPatternsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/BannerPatternsAttribute.java @@ -12,13 +12,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.parsing.ItemMetaParser; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; import org.bukkit.block.banner.Pattern; import java.util.ArrayList; @@ -28,7 +26,7 @@ public class BannerPatternsAttribute implements ApplicableIconAttribute { private final List patterns; - public BannerPatternsAttribute(List serializedPatterns, AttributeErrorCollector attributeErrorCollector) { + public BannerPatternsAttribute(List serializedPatterns, AttributeErrorHandler errorHandler) { patterns = new ArrayList<>(); for (String serializedPattern : serializedPatterns) { @@ -40,7 +38,7 @@ public class BannerPatternsAttribute implements ApplicableIconAttribute { Pattern pattern = ItemMetaParser.parseBannerPattern(serializedPattern); patterns.add(pattern); } catch (ParseException e) { - attributeErrorCollector.addListElementError(serializedPattern, e); + errorHandler.onListElementError(serializedPattern, e); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ClickPermissionAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ClickPermissionAttribute.java similarity index 81% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ClickPermissionAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ClickPermissionAttribute.java index bf31e7a..cba87b2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ClickPermissionAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ClickPermissionAttribute.java @@ -12,17 +12,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; public class ClickPermissionAttribute implements ApplicableIconAttribute { private final String clickPermission; - public ClickPermissionAttribute(String clickPermission, AttributeErrorCollector attributeErrorCollector) { + public ClickPermissionAttribute(String clickPermission, AttributeErrorHandler errorHandler) { this.clickPermission = clickPermission; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ClickPermissionMessageAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ClickPermissionMessageAttribute.java similarity index 80% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ClickPermissionMessageAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ClickPermissionMessageAttribute.java index 1448f02..270eeea 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ClickPermissionMessageAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ClickPermissionMessageAttribute.java @@ -12,17 +12,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; public class ClickPermissionMessageAttribute implements ApplicableIconAttribute { private final String clickPermissionMessage; - public ClickPermissionMessageAttribute(String clickPermissionMessage, AttributeErrorCollector attributeErrorCollector) { + public ClickPermissionMessageAttribute(String clickPermissionMessage, AttributeErrorHandler errorHandler) { this.clickPermissionMessage = clickPermissionMessage; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/DurabilityAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/DurabilityAttribute.java similarity index 76% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/DurabilityAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/DurabilityAttribute.java index debe3bf..750254d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/DurabilityAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/DurabilityAttribute.java @@ -12,17 +12,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; public class DurabilityAttribute implements ApplicableIconAttribute { private final short durability; - public DurabilityAttribute(short durability, AttributeErrorCollector attributeErrorCollector) { + public DurabilityAttribute(short durability, AttributeErrorHandler errorHandler) { this.durability = durability; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/EnchantmentsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/EnchantmentsAttribute.java similarity index 83% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/EnchantmentsAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/EnchantmentsAttribute.java index 339244f..657c54b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/EnchantmentsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/EnchantmentsAttribute.java @@ -12,13 +12,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.parsing.EnchantmentParser; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; import org.bukkit.enchantments.Enchantment; import java.util.HashMap; @@ -29,7 +27,7 @@ public class EnchantmentsAttribute implements ApplicableIconAttribute { private final Map enchantments; - public EnchantmentsAttribute(List serializedEnchantments, AttributeErrorCollector attributeErrorCollector) { + public EnchantmentsAttribute(List serializedEnchantments, AttributeErrorHandler errorHandler) { enchantments = new HashMap<>(); for (String serializedEnchantment : serializedEnchantments) { @@ -41,7 +39,7 @@ public class EnchantmentsAttribute implements ApplicableIconAttribute { EnchantmentParser.EnchantmentDetails enchantment = EnchantmentParser.parseEnchantment(serializedEnchantment); enchantments.put(enchantment.getEnchantment(), enchantment.getLevel()); } catch (ParseException e) { - attributeErrorCollector.addListElementError(serializedEnchantment, e); + errorHandler.onListElementError(serializedEnchantment, e); } } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ExpLevelsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ExpLevelsAttribute.java similarity index 78% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ExpLevelsAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ExpLevelsAttribute.java index 4c994a6..b362f53 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ExpLevelsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ExpLevelsAttribute.java @@ -12,19 +12,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; public class ExpLevelsAttribute implements ApplicableIconAttribute { private final int expLevels; - public ExpLevelsAttribute(int expLevels, AttributeErrorCollector attributeErrorCollector) throws ParseException { + public ExpLevelsAttribute(int expLevels, AttributeErrorHandler errorHandler) throws ParseException { if (expLevels < 0) { throw new ParseException(ErrorMessages.Parsing.zeroOrPositive); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/IconAttribute.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/IconAttribute.java index 5029ad5..35998c8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/IconAttribute.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon; +package me.filoghost.chestcommands.parsing.attribute; public interface IconAttribute { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/KeepOpenAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/KeepOpenAttribute.java similarity index 78% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/KeepOpenAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/KeepOpenAttribute.java index 9ac99a7..4695850 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/KeepOpenAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/KeepOpenAttribute.java @@ -12,18 +12,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.api.ClickResult; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; public class KeepOpenAttribute implements ApplicableIconAttribute { private final ClickResult clickResult; - public KeepOpenAttribute(boolean keepOpen, AttributeErrorCollector attributeErrorCollector) { + public KeepOpenAttribute(boolean keepOpen, AttributeErrorHandler errorHandler) { if (keepOpen) { this.clickResult = ClickResult.KEEP_OPEN; } else { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LeatherColorAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/LeatherColorAttribute.java similarity index 81% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LeatherColorAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/LeatherColorAttribute.java index 5a9cc1b..799fa86 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LeatherColorAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/LeatherColorAttribute.java @@ -12,20 +12,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.parsing.ItemMetaParser; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; import org.bukkit.Color; public class LeatherColorAttribute implements ApplicableIconAttribute { private final Color color; - public LeatherColorAttribute(String serializedColor, AttributeErrorCollector attributeErrorCollector) throws ParseException { + public LeatherColorAttribute(String serializedColor, AttributeErrorHandler errorHandler) throws ParseException { this.color = ItemMetaParser.parseRGBColor(serializedColor); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LoreAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/LoreAttribute.java similarity index 79% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LoreAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/LoreAttribute.java index 90b464d..7d17dfa 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/LoreAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/LoreAttribute.java @@ -12,12 +12,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; import me.filoghost.chestcommands.util.Colors; import me.filoghost.chestcommands.util.collection.CollectionUtils; import org.bukkit.ChatColor; @@ -28,8 +26,8 @@ public class LoreAttribute implements ApplicableIconAttribute { private final List lore; - public LoreAttribute(List lore, AttributeErrorCollector attributeErrorCollector) { - this.lore = ChestCommands.getCustomPlaceholders().replaceAll(colorLore(lore)); + public LoreAttribute(List lore, AttributeErrorHandler errorHandler) { + this.lore = ChestCommands.getCustomPlaceholders().replacePlaceholders(colorLore(lore)); } private List colorLore(List input) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/MaterialAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/MaterialAttribute.java similarity index 84% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/MaterialAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/MaterialAttribute.java index 8fffbde..448f18e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/MaterialAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/MaterialAttribute.java @@ -12,13 +12,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; import me.filoghost.chestcommands.util.MaterialsHelper; import org.bukkit.Material; @@ -28,7 +26,7 @@ public class MaterialAttribute implements ApplicableIconAttribute { private final Material material; - public MaterialAttribute(String serializedMaterial, AttributeErrorCollector attributeErrorCollector) throws ParseException { + public MaterialAttribute(String serializedMaterial, AttributeErrorHandler errorHandler) throws ParseException { Optional material = MaterialsHelper.matchMaterial(serializedMaterial); if (!material.isPresent() || MaterialsHelper.isAir(material.get())) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NBTDataAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/NBTDataAttribute.java similarity index 80% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NBTDataAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/NBTDataAttribute.java index df721df..b063ecb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NBTDataAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/NBTDataAttribute.java @@ -12,12 +12,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; import me.filoghost.chestcommands.util.nbt.parser.MojangsonParseException; import me.filoghost.chestcommands.util.nbt.parser.MojangsonParser; @@ -25,7 +23,7 @@ public class NBTDataAttribute implements ApplicableIconAttribute { private final String nbtData; - public NBTDataAttribute(String nbtData, AttributeErrorCollector attributeErrorCollector) throws ParseException { + public NBTDataAttribute(String nbtData, AttributeErrorHandler errorHandler) throws ParseException { try { // Check that NBT syntax is valid before applying it to the icon MojangsonParser.parse(nbtData); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NameAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/NameAttribute.java similarity index 78% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NameAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/NameAttribute.java index 34b8153..a63f340 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/NameAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/NameAttribute.java @@ -12,12 +12,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; import me.filoghost.chestcommands.util.Colors; import org.bukkit.ChatColor; @@ -25,8 +23,8 @@ public class NameAttribute implements ApplicableIconAttribute { private final String name; - public NameAttribute(String name, AttributeErrorCollector attributeErrorCollector) { - this.name = ChestCommands.getCustomPlaceholders().replaceAll(colorName(name)); + public NameAttribute(String name, AttributeErrorHandler errorHandler) { + this.name = ChestCommands.getCustomPlaceholders().replacePlaceholders(colorName(name)); } private String colorName(String input) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PositionAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/PositionAttribute.java similarity index 74% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PositionAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/PositionAttribute.java index fc63f8a..848ea3e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PositionAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/PositionAttribute.java @@ -12,16 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; - -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; -import me.filoghost.chestcommands.parsing.icon.IconAttribute; +package me.filoghost.chestcommands.parsing.attribute; public class PositionAttribute implements IconAttribute { private final int position; - public PositionAttribute(int position, AttributeErrorCollector attributeErrorCollector) { + public PositionAttribute(int position, AttributeErrorHandler errorHandler) { this.position = position; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PriceAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/PriceAttribute.java similarity index 78% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PriceAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/PriceAttribute.java index 9142675..4a99f67 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/PriceAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/PriceAttribute.java @@ -12,19 +12,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; public class PriceAttribute implements ApplicableIconAttribute { private final double price; - public PriceAttribute(double price, AttributeErrorCollector attributeErrorCollector) throws ParseException { + public PriceAttribute(double price, AttributeErrorHandler errorHandler) throws ParseException { if (price < 0) { throw new ParseException(ErrorMessages.Parsing.zeroOrPositive); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/RequiredItemsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/RequiredItemsAttribute.java similarity index 84% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/RequiredItemsAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/RequiredItemsAttribute.java index 7698c12..12da173 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/RequiredItemsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/RequiredItemsAttribute.java @@ -12,14 +12,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.icon.requirement.RequiredItem; import me.filoghost.chestcommands.parsing.ItemStackParser; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; import java.util.ArrayList; import java.util.List; @@ -28,7 +26,7 @@ public class RequiredItemsAttribute implements ApplicableIconAttribute { private final List requiredItems; - public RequiredItemsAttribute(List serializedRequiredItems, AttributeErrorCollector attributeErrorCollector) { + public RequiredItemsAttribute(List serializedRequiredItems, AttributeErrorHandler errorHandler) { requiredItems = new ArrayList<>(); for (String serializedItem : serializedRequiredItems) { @@ -40,7 +38,7 @@ public class RequiredItemsAttribute implements ApplicableIconAttribute { } requiredItems.add(requiredItem); } catch (ParseException e) { - attributeErrorCollector.addListElementError(serializedItem, e); + errorHandler.onListElementError(serializedItem, e); } } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/SkullOwnerAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/SkullOwnerAttribute.java similarity index 76% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/SkullOwnerAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/SkullOwnerAttribute.java index 008aeef..dd7b810 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/SkullOwnerAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/SkullOwnerAttribute.java @@ -12,17 +12,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; public class SkullOwnerAttribute implements ApplicableIconAttribute { private final String skullOwner; - public SkullOwnerAttribute(String skullOwner, AttributeErrorCollector attributeErrorCollector) { + public SkullOwnerAttribute(String skullOwner, AttributeErrorHandler errorHandler) { this.skullOwner = skullOwner; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ViewPermissionAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ViewPermissionAttribute.java similarity index 81% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ViewPermissionAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ViewPermissionAttribute.java index d936b44..094c863 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/attributes/ViewPermissionAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ViewPermissionAttribute.java @@ -12,17 +12,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.icon.attributes; +package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -import me.filoghost.chestcommands.parsing.icon.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.icon.AttributeErrorCollector; public class ViewPermissionAttribute implements ApplicableIconAttribute { private final String viewPermission; - public ViewPermissionAttribute(String viewPermission, AttributeErrorCollector attributeErrorCollector) { + public ViewPermissionAttribute(String viewPermission, AttributeErrorHandler errorHandler) { this.viewPermission = viewPermission; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeErrorCollector.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeErrorCollector.java deleted file mode 100644 index 3225ed1..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeErrorCollector.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.parsing.icon; - -import me.filoghost.chestcommands.logging.ErrorMessages; -import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.util.logging.ErrorCollector; - -public class AttributeErrorCollector { - - private final ErrorCollector errorCollector; - private final IconSettings iconSettings; - private final String attributeName; - - public AttributeErrorCollector(ErrorCollector errorCollector, IconSettings iconSettings, String attributeName) { - this.errorCollector = errorCollector; - this.iconSettings = iconSettings; - this.attributeName = attributeName; - } - - public void addListElementError(String listElement, ParseException e) { - errorCollector.add(ErrorMessages.Menu.invalidAttributeListElement(iconSettings, attributeName, listElement), e); - } - -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java index 8d6ee4b..ecd2683 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java @@ -19,26 +19,29 @@ import me.filoghost.chestcommands.config.framework.exception.ConfigValueExceptio import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.parsing.icon.attributes.ActionsAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.AmountAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.BannerColorAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.BannerPatternsAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.ClickPermissionAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.ClickPermissionMessageAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.DurabilityAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.EnchantmentsAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.ExpLevelsAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.KeepOpenAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.LeatherColorAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.LoreAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.MaterialAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.NBTDataAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.NameAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.PositionAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.PriceAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.RequiredItemsAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.SkullOwnerAttribute; -import me.filoghost.chestcommands.parsing.icon.attributes.ViewPermissionAttribute; +import me.filoghost.chestcommands.parsing.attribute.ActionsAttribute; +import me.filoghost.chestcommands.parsing.attribute.AmountAttribute; +import me.filoghost.chestcommands.parsing.attribute.ApplicableIconAttribute; +import me.filoghost.chestcommands.parsing.attribute.AttributeErrorHandler; +import me.filoghost.chestcommands.parsing.attribute.BannerColorAttribute; +import me.filoghost.chestcommands.parsing.attribute.BannerPatternsAttribute; +import me.filoghost.chestcommands.parsing.attribute.ClickPermissionAttribute; +import me.filoghost.chestcommands.parsing.attribute.ClickPermissionMessageAttribute; +import me.filoghost.chestcommands.parsing.attribute.DurabilityAttribute; +import me.filoghost.chestcommands.parsing.attribute.EnchantmentsAttribute; +import me.filoghost.chestcommands.parsing.attribute.ExpLevelsAttribute; +import me.filoghost.chestcommands.parsing.attribute.IconAttribute; +import me.filoghost.chestcommands.parsing.attribute.KeepOpenAttribute; +import me.filoghost.chestcommands.parsing.attribute.LeatherColorAttribute; +import me.filoghost.chestcommands.parsing.attribute.LoreAttribute; +import me.filoghost.chestcommands.parsing.attribute.MaterialAttribute; +import me.filoghost.chestcommands.parsing.attribute.NBTDataAttribute; +import me.filoghost.chestcommands.parsing.attribute.NameAttribute; +import me.filoghost.chestcommands.parsing.attribute.PositionAttribute; +import me.filoghost.chestcommands.parsing.attribute.PriceAttribute; +import me.filoghost.chestcommands.parsing.attribute.RequiredItemsAttribute; +import me.filoghost.chestcommands.parsing.attribute.SkullOwnerAttribute; +import me.filoghost.chestcommands.parsing.attribute.ViewPermissionAttribute; import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.logging.ErrorCollector; @@ -58,7 +61,7 @@ public class IconSettings { private MaterialAttribute materialAttribute; private final List applicableAttributes; - public static final Map iconNodeHandlers = new HashMap<>(); + public static final Map iconNodeHandlers = new HashMap<>(); static { addIconNodeHandler(IconSettingsNode.POSITION_X, ValueExtractor.INT, PositionAttribute::new, IconSettings::setPositionX); addIconNodeHandler(IconSettingsNode.POSITION_Y, ValueExtractor.INT, PositionAttribute::new, IconSettings::setPositionY); @@ -141,7 +144,7 @@ public class IconSettings { String node, ValueExtractor valueExtractor, AttributeFactory attributeFactory, - AttributeCallback callback) { + AttributeApplier callback) { addIconNodeHandler(node, (iconSettings, config, configNode, parseContext) -> { V value = valueExtractor.getValue(config, configNode); A iconAttribute = attributeFactory.create(value, parseContext); @@ -149,7 +152,7 @@ public class IconSettings { }); } - private static void addIconNodeHandler(String node, IconNodeHandler iconNodeHandler) { + private static void addIconNodeHandler(String node, AttributeParser iconNodeHandler) { Preconditions.checkState(!iconNodeHandlers.containsKey(node), "Handler already exists for attribute " + node); iconNodeHandlers.put(node, iconNodeHandler); } @@ -161,22 +164,24 @@ public class IconSettings { } public void loadFrom(ConfigSection config, ErrorCollector errorCollector) { - for (String attributeKey : config.getKeys(false)) { + for (String attributeName : config.getKeys(false)) { try { - IconNodeHandler nodeHandler = iconNodeHandlers.get(attributeKey); - if (nodeHandler == null) { + AttributeParser attributeParser = iconNodeHandlers.get(attributeName); + if (attributeParser == null) { throw new ParseException(ErrorMessages.Parsing.unknownAttribute); } - AttributeErrorCollector attributeErrorCollector = new AttributeErrorCollector(errorCollector, this, attributeKey); - nodeHandler.handle(this, config, attributeKey, attributeErrorCollector); + attributeParser.parse(this, config, attributeName, (String listElement, ParseException e) -> { + errorCollector.add(ErrorMessages.Menu.invalidAttributeListElement(this, attributeName, listElement), e); + }); } catch (ParseException | ConfigValueException e) { - errorCollector.add(ErrorMessages.Menu.invalidAttribute(this, attributeKey), e); + errorCollector.add(ErrorMessages.Menu.invalidAttribute(this, attributeName), e); } } } + private interface ValueExtractor { V getValue(ConfigSection config, String key) throws ConfigValueException; @@ -192,21 +197,20 @@ public class IconSettings { private interface AttributeFactory { - A create(V value, AttributeErrorCollector attributeErrorCollector) throws ParseException; + A create(V value, AttributeErrorHandler errorHandler) throws ParseException; } - private interface AttributeCallback { + private interface AttributeApplier { void apply(IconSettings iconSettings, A attribute); } - private interface IconNodeHandler { + private interface AttributeParser { - void handle(IconSettings iconSettings, ConfigSection config, String node, AttributeErrorCollector attributeErrorCollector) throws ParseException, ConfigValueException; + void parse(IconSettings iconSettings, ConfigSection config, String node, AttributeErrorHandler errorHandler) throws ParseException, ConfigValueException; } - } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholders.java index 36ea7b8..c44e537 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholders.java @@ -39,22 +39,22 @@ public enum DefaultPlaceholders implements Placeholder { }); - private final String text; - private final Function getReplacementFunction; + private final String placeholderText; + private final Function placeholderReplacer; - DefaultPlaceholders(String text, Function getReplacementFunction) { - this.text = text; - this.getReplacementFunction = getReplacementFunction; + DefaultPlaceholders(String placeholderText, Function placeholderReplacer) { + this.placeholderText = placeholderText; + this.placeholderReplacer = placeholderReplacer; } @Override public String getPlaceholderText() { - return text; + return placeholderText; } @Override public String getReplacementText(Player player) { - return getReplacementFunction.apply(player); + return placeholderReplacer.apply(player); } } From a86e3a6951167a44b9fcd006af02f3e3468e8e32 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 25 Jul 2020 10:48:51 +0200 Subject: [PATCH 150/213] Make methods in ChestCommands class static --- .../chestcommands/ChestCommands.java | 35 ++++++++++--------- .../chestcommands/DefaultBackendAPI.java | 4 +-- .../chestcommands/action/OpenMenuAction.java | 4 +-- .../chestcommands/command/CommandHandler.java | 4 +-- .../chestcommands/hook/BungeeCordHook.java | 6 ++-- .../listener/InventoryListener.java | 2 +- .../chestcommands/listener/SignListener.java | 10 +++--- 7 files changed, 34 insertions(+), 31 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 53fa5e6..8aa8f83 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -45,6 +45,7 @@ import org.bstats.bukkit.MetricsLite; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; import java.io.IOException; import java.nio.file.Files; @@ -56,11 +57,11 @@ public class ChestCommands extends BaseJavaPlugin { public static final String CHAT_PREFIX = ChatColor.DARK_GREEN + "[" + ChatColor.GREEN + "ChestCommands" + ChatColor.DARK_GREEN + "] " + ChatColor.GREEN; - private static ChestCommands instance; + private static Plugin pluginInstance; private static Path dataFolderPath; - private ConfigManager configManager; - private MenuManager menuManager; + private static ConfigManager configManager; + private static MenuManager menuManager; private static Settings settings; private static Lang lang; private static CustomPlaceholders placeholders; @@ -78,29 +79,29 @@ public class ChestCommands extends BaseJavaPlugin { } } - if (instance != null || System.getProperty("ChestCommandsLoaded") != null) { + if (pluginInstance != null || System.getProperty("ChestCommandsLoaded") != null) { Log.warning("Please do not use /reload or plugin reloaders. Use the command \"/cc reload\" instead."); return; } System.setProperty("ChestCommandsLoaded", "true"); - instance = this; + pluginInstance = this; dataFolderPath = getDataFolder().toPath(); Log.setLogger(getLogger()); - BackendAPI.setImplementation(new DefaultBackendAPI()); - configManager = new ConfigManager(getDataFolderPath()); menuManager = new MenuManager(); settings = new Settings(); lang = new Lang(); placeholders = new CustomPlaceholders(); + BackendAPI.setImplementation(new DefaultBackendAPI()); + VaultEconomyHook.INSTANCE.setup(); BarAPIHook.INSTANCE.setup(); PlaceholderAPIHook.INSTANCE.setup(); BungeeCordHook.INSTANCE.setup(); - + if (VaultEconomyHook.INSTANCE.isEnabled()) { Log.info("Hooked Vault"); } else { @@ -137,7 +138,7 @@ public class ChestCommands extends BaseJavaPlugin { CommandFramework.register(this, new CommandHandler(menuManager, "chestcommands")); ErrorCollector errorCollector = load(); - + if (errorCollector.hasErrors()) { errorCollector.logToConsole(); Bukkit.getScheduler().runTaskLater(this, () -> { @@ -150,16 +151,12 @@ public class ChestCommands extends BaseJavaPlugin { Bukkit.getScheduler().runTaskTimer(this, new TickingTask(), 1L, 1L); } - public static Path getDataFolderPath() { - return dataFolderPath; - } - @Override public void onDisable() { closeAllMenus(); } - public ErrorCollector load() { + public static ErrorCollector load() { ErrorCollector errorCollector = new PrintableErrorCollector(); menuManager.clear(); boolean isFreshInstall = !Files.isDirectory(configManager.getRootDataFolder()); @@ -210,11 +207,15 @@ public class ChestCommands extends BaseJavaPlugin { } - public static ChestCommands getInstance() { - return instance; + public static Plugin getPluginInstance() { + return pluginInstance; } - public MenuManager getMenuManager() { + public static Path getDataFolderPath() { + return dataFolderPath; + } + + public static MenuManager getMenuManager() { return menuManager; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java b/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java index 619c7be..e57b92f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java @@ -31,12 +31,12 @@ public class DefaultBackendAPI extends BackendAPI { @Override public boolean isPluginMenu(String yamlFile) { - return ChestCommands.getInstance().getMenuManager().getMenuByFileName(yamlFile) != null; + return ChestCommands.getMenuManager().getMenuByFileName(yamlFile) != null; } @Override public boolean openPluginMenu(Player player, String yamlFile) { - InternalIconMenu menu = ChestCommands.getInstance().getMenuManager().getMenuByFileName(yamlFile); + InternalIconMenu menu = ChestCommands.getMenuManager().getMenuByFileName(yamlFile); if (menu != null) { menu.open(player); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java index 150d5c7..40df9c9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java @@ -31,14 +31,14 @@ public class OpenMenuAction extends Action { @Override protected void execute0(final Player player) { - final InternalIconMenu menu = ChestCommands.getInstance().getMenuManager().getMenuByFileName(targetMenu.getValue(player)); + final InternalIconMenu menu = ChestCommands.getMenuManager().getMenuByFileName(targetMenu.getValue(player)); if (menu != null) { /* * Delay the task, since this action is executed in ClickInventoryEvent * and opening another inventory in the same moment is not a good idea. */ - Bukkit.getScheduler().runTask(ChestCommands.getInstance(), () -> { + Bukkit.getScheduler().runTask(ChestCommands.getPluginInstance(), () -> { menu.openCheckingPermission(player); }); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index 0a7833a..1a6e8a2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -43,7 +43,7 @@ public class CommandHandler extends CommandFramework { if (args.length == 0) { // This info is accessible to anyone. Please don't remove it, remember that Chest Commands is developed for free sender.sendMessage(ChestCommands.CHAT_PREFIX); - sender.sendMessage(ChatColor.GREEN + "Version: " + ChatColor.GRAY + ChestCommands.getInstance().getDescription().getVersion()); + sender.sendMessage(ChatColor.GREEN + "Version: " + ChatColor.GRAY + ChestCommands.getPluginInstance().getDescription().getVersion()); sender.sendMessage(ChatColor.GREEN + "Developer: " + ChatColor.GRAY + "filoghost"); sender.sendMessage(ChatColor.GREEN + "Commands: " + ChatColor.GRAY + "/" + label + " help"); return; @@ -83,7 +83,7 @@ public class CommandHandler extends CommandFramework { ChestCommands.closeAllMenus(); - ErrorCollector errorCollector = ChestCommands.getInstance().load(); + ErrorCollector errorCollector = ChestCommands.load(); if (!errorCollector.hasErrors()) { sender.sendMessage(ChestCommands.CHAT_PREFIX + "Plugin reloaded."); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java index 241011b..79223de 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java @@ -29,8 +29,8 @@ public enum BungeeCordHook implements PluginHook { @Override public void setup() { - if (!Bukkit.getMessenger().isOutgoingChannelRegistered(ChestCommands.getInstance(), "BungeeCord")) { - Bukkit.getMessenger().registerOutgoingPluginChannel(ChestCommands.getInstance(), "BungeeCord"); + if (!Bukkit.getMessenger().isOutgoingChannelRegistered(ChestCommands.getPluginInstance(), "BungeeCord")) { + Bukkit.getMessenger().registerOutgoingPluginChannel(ChestCommands.getPluginInstance(), "BungeeCord"); } } @@ -57,7 +57,7 @@ public enum BungeeCordHook implements PluginHook { throw new AssertionError(); } - player.sendPluginMessage(ChestCommands.getInstance(), "BungeeCord", byteArrayOutputStream.toByteArray()); + player.sendPluginMessage(ChestCommands.getPluginInstance(), "BungeeCord", byteArrayOutputStream.toByteArray()); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index d0d0abb..bfd1fc8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -89,7 +89,7 @@ public class InventoryListener implements Listener { } // Only handle the click AFTER the event has finished - Bukkit.getScheduler().runTask(ChestCommands.getInstance(), () -> { + Bukkit.getScheduler().runTask(ChestCommands.getPluginInstance(), () -> { ClickResult result = slotClickHandler.onClick(); if (result == ClickResult.CLOSE) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java index ab04229..bc871f1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java @@ -77,12 +77,14 @@ public class SignListener implements Listener { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onCreateMenuSign(SignChangeEvent event) { - if (isCreatingMenuSign(event.getLine(HEADER_LINE)) && canCreateMenuSign(event.getPlayer())) { + Player player = event.getPlayer(); + + if (isCreatingMenuSign(event.getLine(HEADER_LINE)) && canCreateMenuSign(player)) { String menuFileName = event.getLine(FILENAME_LINE).trim(); if (menuFileName.isEmpty()) { event.setCancelled(true); - event.getPlayer().sendMessage(ChatColor.RED + "You must write a menu name in the second line."); + player.sendMessage(ChatColor.RED + "You must write a menu name in the second line."); return; } @@ -91,12 +93,12 @@ public class SignListener implements Listener { InternalIconMenu iconMenu = menuManager.getMenuByFileName(menuFileName); if (iconMenu == null) { event.setCancelled(true); - event.getPlayer().sendMessage(ChatColor.RED + "Menu \"" + menuFileName + "\" was not found."); + player.sendMessage(ChatColor.RED + "Menu \"" + menuFileName + "\" was not found."); return; } event.setLine(HEADER_LINE, VALID_SIGN_COLOR + event.getLine(HEADER_LINE)); - event.getPlayer().sendMessage(ChatColor.GREEN + "Successfully created a sign for the menu " + menuFileName + "."); + player.sendMessage(ChatColor.GREEN + "Successfully created a sign for the menu " + menuFileName + "."); } } From 7572240fb344b0bf32aa070dac7676753be51571 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 25 Jul 2020 17:02:16 +0200 Subject: [PATCH 151/213] Improve custom placeholders handling --- .../chestcommands/action/BroadcastAction.java | 6 +- .../action/ChangeServerAction.java | 6 +- .../action/ConsoleCommandAction.java | 6 +- .../chestcommands/action/DragonBarAction.java | 6 +- .../chestcommands/action/OpCommandAction.java | 6 +- .../chestcommands/action/OpenMenuAction.java | 6 +- .../action/PlayerCommandAction.java | 6 +- .../action/SendMessageAction.java | 6 +- .../config/CustomPlaceholders.java | 30 ++++++--- .../icon/BaseConfigurableIcon.java | 32 ++++----- .../chestcommands/parsing/ActionParser.java | 5 +- .../parsing/attribute/LoreAttribute.java | 2 +- .../parsing/attribute/NameAttribute.java | 2 +- .../placeholder/PlaceholderManager.java | 13 +++- .../placeholder/PlaceholderString.java | 56 ++++++++++++++++ .../placeholder/PlaceholderStringList.java | 65 +++++++++++++++++++ .../placeholder/RelativeString.java | 53 --------------- .../placeholder/RelativeStringList.java | 57 ---------------- .../util/collection/CollectionUtils.java | 28 +++++++- 19 files changed, 225 insertions(+), 166 deletions(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderString.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeString.java delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeStringList.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java index 7ba21b2..0a94c06 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java @@ -14,17 +14,17 @@ */ package me.filoghost.chestcommands.action; -import me.filoghost.chestcommands.placeholder.RelativeString; +import me.filoghost.chestcommands.placeholder.PlaceholderString; import me.filoghost.chestcommands.util.Colors; import org.bukkit.Bukkit; import org.bukkit.entity.Player; public class BroadcastAction extends Action { - private final RelativeString message; + private final PlaceholderString message; public BroadcastAction(String serializedAction) { - message = RelativeString.of(Colors.addColors(serializedAction)); + message = PlaceholderString.of(Colors.addColors(serializedAction)); } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java index 8a234c0..9c48b0b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java @@ -15,15 +15,15 @@ package me.filoghost.chestcommands.action; import me.filoghost.chestcommands.hook.BungeeCordHook; -import me.filoghost.chestcommands.placeholder.RelativeString; +import me.filoghost.chestcommands.placeholder.PlaceholderString; import org.bukkit.entity.Player; public class ChangeServerAction extends Action { - private final RelativeString targetServer; + private final PlaceholderString targetServer; public ChangeServerAction(String serializedAction) { - targetServer = RelativeString.of(serializedAction); + targetServer = PlaceholderString.of(serializedAction); } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java index ff88a3e..b920f64 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java @@ -14,16 +14,16 @@ */ package me.filoghost.chestcommands.action; -import me.filoghost.chestcommands.placeholder.RelativeString; +import me.filoghost.chestcommands.placeholder.PlaceholderString; import org.bukkit.Bukkit; import org.bukkit.entity.Player; public class ConsoleCommandAction extends Action { - private final RelativeString command; + private final PlaceholderString command; public ConsoleCommandAction(String serializedAction) { - command = RelativeString.of(serializedAction); + command = PlaceholderString.of(serializedAction); } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java index e7caa16..008cdb7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java @@ -17,7 +17,7 @@ package me.filoghost.chestcommands.action; import me.filoghost.chestcommands.hook.BarAPIHook; import me.filoghost.chestcommands.parsing.NumberParser; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.placeholder.RelativeString; +import me.filoghost.chestcommands.placeholder.PlaceholderString; import me.filoghost.chestcommands.util.Colors; import me.filoghost.chestcommands.util.Strings; import org.bukkit.ChatColor; @@ -25,7 +25,7 @@ import org.bukkit.entity.Player; public class DragonBarAction extends Action { - private RelativeString message; + private PlaceholderString message; private int seconds; public DragonBarAction(String serialiazedAction) { @@ -43,7 +43,7 @@ public class DragonBarAction extends Action { } } - this.message = RelativeString.of(Colors.addColors(message)); + this.message = PlaceholderString.of(Colors.addColors(message)); } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java index 819a803..58db352 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java @@ -14,15 +14,15 @@ */ package me.filoghost.chestcommands.action; -import me.filoghost.chestcommands.placeholder.RelativeString; +import me.filoghost.chestcommands.placeholder.PlaceholderString; import org.bukkit.entity.Player; public class OpCommandAction extends Action { - private final RelativeString command; + private final PlaceholderString command; public OpCommandAction(String serializedAction) { - command = RelativeString.of(serializedAction); + command = PlaceholderString.of(serializedAction); } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java index 40df9c9..f6b3a6c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java @@ -16,17 +16,17 @@ package me.filoghost.chestcommands.action; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.menu.InternalIconMenu; -import me.filoghost.chestcommands.placeholder.RelativeString; +import me.filoghost.chestcommands.placeholder.PlaceholderString; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; public class OpenMenuAction extends Action { - private final RelativeString targetMenu; + private final PlaceholderString targetMenu; public OpenMenuAction(String serializedAction) { - targetMenu = RelativeString.of(serializedAction); + targetMenu = PlaceholderString.of(serializedAction); } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java index e5cdfae..5aff43f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java @@ -14,15 +14,15 @@ */ package me.filoghost.chestcommands.action; -import me.filoghost.chestcommands.placeholder.RelativeString; +import me.filoghost.chestcommands.placeholder.PlaceholderString; import org.bukkit.entity.Player; public class PlayerCommandAction extends Action { - private final RelativeString command; + private final PlaceholderString command; public PlayerCommandAction(String serializedAction) { - command = RelativeString.of(serializedAction); + command = PlaceholderString.of(serializedAction); } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java index 787983d..16aa216 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java @@ -14,16 +14,16 @@ */ package me.filoghost.chestcommands.action; -import me.filoghost.chestcommands.placeholder.RelativeString; +import me.filoghost.chestcommands.placeholder.PlaceholderString; import me.filoghost.chestcommands.util.Colors; import org.bukkit.entity.Player; public class SendMessageAction extends Action { - private final RelativeString message; + private final PlaceholderString message; public SendMessageAction(String serializedAction) { - message = RelativeString.of(Colors.addColors(serializedAction)); + message = PlaceholderString.of(Colors.addColors(serializedAction)); } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java index 553b441..bea7ade 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java @@ -17,7 +17,6 @@ package me.filoghost.chestcommands.config; import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.util.Colors; -import me.filoghost.chestcommands.util.collection.CollectionUtils; import me.filoghost.chestcommands.util.logging.ErrorCollector; import java.util.HashMap; @@ -49,13 +48,6 @@ public class CustomPlaceholders { } } - public List replacePlaceholders(List input) { - if (input == null) { - return null; - } - return CollectionUtils.transform(input, this::replacePlaceholders); - } - public String replacePlaceholders(String input) { if (input == null) { return null; @@ -66,4 +58,26 @@ public class CustomPlaceholders { return input; } + public boolean containsPlaceholders(String input) { + if (input == null) { + return false; + } + for (String placeholder : placeholders.keySet()) { + if (input.contains(placeholder)) { + return true; + } + } + return false; + } + + public boolean containsPlaceholders(List list) { + for (String element : list) { + if (containsPlaceholders(element)) { + return true; + } + } + + return false; + } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java index bd62fc8..3f36ad4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java @@ -15,8 +15,8 @@ package me.filoghost.chestcommands.icon; import me.filoghost.chestcommands.api.Icon; -import me.filoghost.chestcommands.placeholder.RelativeString; -import me.filoghost.chestcommands.placeholder.RelativeStringList; +import me.filoghost.chestcommands.placeholder.PlaceholderString; +import me.filoghost.chestcommands.placeholder.PlaceholderStringList; import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.collection.CollectionUtils; import me.filoghost.chestcommands.util.logging.Log; @@ -48,11 +48,11 @@ public abstract class BaseConfigurableIcon implements Icon { private short durability; private String nbtData; - private RelativeString name; - private RelativeStringList lore; + private PlaceholderString name; + private PlaceholderStringList lore; private Map enchantments; private Color leatherColor; - private RelativeString skullOwner; + private PlaceholderString skullOwner; private DyeColor bannerColor; private List bannerPatterns; private boolean placeholdersEnabled; @@ -70,9 +70,9 @@ public abstract class BaseConfigurableIcon implements Icon { return false; } - return (name == null || !name.hasPlaceholders()) - && (lore == null || !lore.hasPlaceholders()) - && (skullOwner == null || !skullOwner.hasPlaceholders()); + return (name == null || !name.hasDynamicPlaceholders()) + && (lore == null || !lore.hasDynamicPlaceholders()) + && (skullOwner == null || !skullOwner.hasDynamicPlaceholders()); } public void setMaterial(Material material) { @@ -115,7 +115,7 @@ public abstract class BaseConfigurableIcon implements Icon { } public void setName(String name) { - this.name = RelativeString.of(name); + this.name = PlaceholderString.of(name); cachedRendering = null; } @@ -125,7 +125,7 @@ public abstract class BaseConfigurableIcon implements Icon { public String getName() { if (name != null) { - return name.getRawValue(); + return name.getOriginalValue(); } else { return null; } @@ -139,7 +139,7 @@ public abstract class BaseConfigurableIcon implements Icon { public void setLore(List lore) { if (!CollectionUtils.isNullOrEmpty(lore)) { - this.lore = new RelativeStringList(lore); + this.lore = new PlaceholderStringList(CollectionUtils.replaceNulls(lore, "")); } else { this.lore = null; } @@ -152,7 +152,7 @@ public abstract class BaseConfigurableIcon implements Icon { public List getLore() { if (lore != null) { - return new ArrayList<>(lore.getRawValue()); + return new ArrayList<>(lore.getOriginalValue()); } else { return null; } @@ -198,14 +198,14 @@ public abstract class BaseConfigurableIcon implements Icon { public String getSkullOwner() { if (skullOwner != null) { - return skullOwner.getRawValue(); + return skullOwner.getOriginalValue(); } else { return null; } } public void setSkullOwner(String skullOwner) { - this.skullOwner = RelativeString.of(skullOwner); + this.skullOwner = PlaceholderString.of(skullOwner); cachedRendering = null; } @@ -237,7 +237,7 @@ public abstract class BaseConfigurableIcon implements Icon { return null; } if (!placeholdersEnabled) { - return name.getRawValue(); + return name.getOriginalValue(); } String name = this.name.getValue(viewer); @@ -255,7 +255,7 @@ public abstract class BaseConfigurableIcon implements Icon { return null; } if (!placeholdersEnabled) { - return lore.getRawValue(); + return lore.getOriginalValue(); } return lore.getValue(viewer); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java index 6fdb67c..9ab6ccc 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java @@ -14,7 +14,6 @@ */ package me.filoghost.chestcommands.parsing; -import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.BroadcastAction; import me.filoghost.chestcommands.action.ChangeServerAction; @@ -61,11 +60,11 @@ public class ActionParser { if (matcher.find()) { // Remove the action prefix and trim the spaces String serializedAction = matcher.replaceFirst("").trim(); - return entry.getValue().create(ChestCommands.getCustomPlaceholders().replacePlaceholders(serializedAction)); + return entry.getValue().create(serializedAction); } } - return new PlayerCommandAction(ChestCommands.getCustomPlaceholders().replacePlaceholders(input)); // Default action, no match found + return new PlayerCommandAction(input); // Default action, no match found } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/LoreAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/LoreAttribute.java index 7d17dfa..f68cadd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/LoreAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/LoreAttribute.java @@ -27,7 +27,7 @@ public class LoreAttribute implements ApplicableIconAttribute { private final List lore; public LoreAttribute(List lore, AttributeErrorHandler errorHandler) { - this.lore = ChestCommands.getCustomPlaceholders().replacePlaceholders(colorLore(lore)); + this.lore = colorLore(lore); } private List colorLore(List input) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/NameAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/NameAttribute.java index a63f340..8a566e8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/NameAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/NameAttribute.java @@ -24,7 +24,7 @@ public class NameAttribute implements ApplicableIconAttribute { private final String name; public NameAttribute(String name, AttributeErrorHandler errorHandler) { - this.name = ChestCommands.getCustomPlaceholders().replacePlaceholders(colorName(name)); + this.name = colorName(name); } private String colorName(String input) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java index ac5ec24..7aba7eb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java @@ -18,6 +18,7 @@ import me.filoghost.chestcommands.hook.PlaceholderAPIHook; import org.bukkit.entity.Player; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.WeakHashMap; @@ -26,7 +27,7 @@ public class PlaceholderManager { private static final Map> cachedReplacements = new WeakHashMap<>(); public static boolean hasPlaceholders(String text) { - if(text == null) { + if (text == null) { return false; } @@ -43,6 +44,15 @@ public class PlaceholderManager { return false; } + public static boolean hasPlaceholders(List list) { + for (String element : list) { + if (hasPlaceholders(element)) { + return true; + } + } + return false; + } + public static String replacePlaceholders(String text, Player player) { if (text == null) { return null; @@ -72,5 +82,4 @@ public class PlaceholderManager { cachedReplacements.forEach((player, placeholderMap) -> placeholderMap.clear()); } - } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderString.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderString.java new file mode 100644 index 0000000..77c8090 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderString.java @@ -0,0 +1,56 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.placeholder; + +import me.filoghost.chestcommands.ChestCommands; +import org.bukkit.entity.Player; + +public class PlaceholderString { + + private final String originalString; + private final String stringWithStaticPlaceholders; + private final boolean hasDynamicPlaceholders; + + public static PlaceholderString of(String string) { + if (string != null) { + return new PlaceholderString(string); + } else { + return null; + } + } + + private PlaceholderString(String originalString) { + this.originalString = originalString; + this.stringWithStaticPlaceholders = ChestCommands.getCustomPlaceholders().replacePlaceholders(originalString); + this.hasDynamicPlaceholders = PlaceholderManager.hasPlaceholders(stringWithStaticPlaceholders); + } + + public String getValue(Player player) { + if (hasDynamicPlaceholders) { + return PlaceholderManager.replacePlaceholders(stringWithStaticPlaceholders, player); + } else { + return stringWithStaticPlaceholders; + } + } + + public String getOriginalValue() { + return originalString; + } + + public boolean hasDynamicPlaceholders() { + return hasDynamicPlaceholders; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java new file mode 100644 index 0000000..6169902 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java @@ -0,0 +1,65 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.placeholder; + +import com.google.common.collect.ImmutableList; +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.chestcommands.util.collection.CollectionUtils; +import org.bukkit.entity.Player; + +public class PlaceholderStringList { + + private final ImmutableList originalList; + private final ImmutableList listWithStaticPlaceholders; + private final ImmutableList placeholderStringList; + private final boolean hasDynamicPlaceholders; + + public PlaceholderStringList(ImmutableList list) { + Preconditions.notNull(list, "list"); + this.originalList = list; + + // Replace static placeholders only once, if present + if (ChestCommands.getCustomPlaceholders().containsPlaceholders(originalList)) { + this.listWithStaticPlaceholders = CollectionUtils.transformImmutable(originalList, ChestCommands.getCustomPlaceholders()::replacePlaceholders); + } else { + this.listWithStaticPlaceholders = originalList; + } + + this.hasDynamicPlaceholders = PlaceholderManager.hasPlaceholders(listWithStaticPlaceholders); + if (hasDynamicPlaceholders) { + this.placeholderStringList = CollectionUtils.transformImmutable(listWithStaticPlaceholders, PlaceholderString::of); + } else { + this.placeholderStringList = null; + } + } + + public ImmutableList getOriginalValue() { + return originalList; + } + + public ImmutableList getValue(Player player) { + if (hasDynamicPlaceholders) { + return CollectionUtils.transformImmutable(placeholderStringList, element -> element.getValue(player)); + } else { + return listWithStaticPlaceholders; + } + } + + public boolean hasDynamicPlaceholders() { + return hasDynamicPlaceholders; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeString.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeString.java deleted file mode 100644 index 7d4cfe4..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeString.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.placeholder; - -import org.bukkit.entity.Player; - -public class RelativeString { - - private final String string; - private final boolean hasPlaceholders; - - public static RelativeString of(String string) { - if (string != null) { - return new RelativeString(string); - } else { - return null; - } - } - - private RelativeString(String string) { - this.string = string; - this.hasPlaceholders = PlaceholderManager.hasPlaceholders(string); - } - - public String getRawValue() { - return string; - } - - public String getValue(Player player) { - if (hasPlaceholders) { - return PlaceholderManager.replacePlaceholders(string, player); - } else { - return string; - } - } - - public boolean hasPlaceholders() { - return hasPlaceholders; - } - -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeStringList.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeStringList.java deleted file mode 100644 index e710ea7..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/RelativeStringList.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.placeholder; - -import com.google.common.collect.ImmutableList; -import me.filoghost.chestcommands.util.collection.CollectionUtils; -import org.bukkit.entity.Player; - -import java.util.List; - -public class RelativeStringList { - - private final ImmutableList originalList; - private final List relativeList; - private final boolean hasPlaceholders; - - public RelativeStringList(List list) { - if (list != null) { - this.originalList = ImmutableList.copyOf(list); - this.relativeList = CollectionUtils.transform(list, RelativeString::of); - this.hasPlaceholders = this.relativeList.stream().anyMatch(RelativeString::hasPlaceholders); - } else { - this.originalList = null; - this.relativeList = null; - this.hasPlaceholders = false; - } - } - - public ImmutableList getRawValue() { - return originalList; - } - - public List getValue(Player player) { - if (hasPlaceholders) { - return CollectionUtils.transform(relativeList, element -> element.getValue(player)); - } else { - return originalList; - } - } - - public boolean hasPlaceholders() { - return hasPlaceholders; - } - -} diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java index 87682db..e23abe6 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java @@ -14,6 +14,8 @@ */ package me.filoghost.chestcommands.util.collection; +import com.google.common.collect.ImmutableList; + import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -23,7 +25,6 @@ import java.util.function.Function; public final class CollectionUtils { - public static boolean isNullOrEmpty(Collection collection) { return collection == null || collection.isEmpty(); } @@ -55,4 +56,29 @@ public final class CollectionUtils { return result; } + public static ImmutableList transformImmutable(List list, Function transformFunction) { + if (list == null) { + return null; + } + ImmutableList.Builder builder = ImmutableList.builder(); + for (A element : list) { + builder.add(transformFunction.apply(element)); + } + return builder.build(); + } + + public static ImmutableList replaceNulls(List list, E replacement) { + ImmutableList.Builder builder = ImmutableList.builder(); + + for (E element : list) { + if (element != null) { + builder.add(element); + } else { + builder.add(replacement); + } + } + + return builder.build(); + } + } From b922b6255674dc846518fdab8686de2d8c5b64aa Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 27 Jul 2020 19:34:12 +0200 Subject: [PATCH 152/213] Refactor placeholders --- .../chestcommands/api/ChestCommandsAPI.java | 6 + .../api/PlaceholderReplacer.java | 8 +- .../api/internal/BackendAPI.java | 3 + .../chestcommands/ChestCommands.java | 6 +- .../chestcommands/DefaultBackendAPI.java | 7 ++ .../config/CustomPlaceholders.java | 41 +------ ...ceholders.java => DefaultPlaceholder.java} | 36 +++--- .../placeholder/PlaceholderCache.java | 43 +++++++ .../placeholder/PlaceholderManager.java | 113 ++++++++++++------ .../placeholder/PlaceholderRegistry.java | 62 ++++++++++ .../placeholder/PlaceholderString.java | 7 +- .../placeholder/PlaceholderStringList.java | 7 +- .../placeholder/StaticPlaceholder.java | 35 ++++++ .../placeholder/scanner/PlaceholderMatch.java | 90 ++++++++++++++ .../scanner/PlaceholderScanner.java | 97 +++++++++++++++ .../util/collection/CollectionUtils.java | 4 + 16 files changed, 458 insertions(+), 107 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/placeholder/Placeholder.java => API/src/main/java/me/filoghost/chestcommands/api/PlaceholderReplacer.java (81%) rename Plugin/src/main/java/me/filoghost/chestcommands/placeholder/{DefaultPlaceholders.java => DefaultPlaceholder.java} (52%) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderCache.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderRegistry.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/placeholder/StaticPlaceholder.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java index 9f8296d..562ecb4 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java @@ -16,6 +16,7 @@ package me.filoghost.chestcommands.api; import me.filoghost.chestcommands.api.internal.BackendAPI; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; public class ChestCommandsAPI { @@ -33,6 +34,11 @@ public class ChestCommandsAPI { public static int getAPIVersion() { return 1; } + + + public static void registerPlaceholder(Plugin plugin, String identifier, PlaceholderReplacer placeholderReplacer) { + BackendAPI.getImplementation().registerPlaceholder(plugin, identifier, placeholderReplacer); + } /** diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/Placeholder.java b/API/src/main/java/me/filoghost/chestcommands/api/PlaceholderReplacer.java similarity index 81% rename from Plugin/src/main/java/me/filoghost/chestcommands/placeholder/Placeholder.java rename to API/src/main/java/me/filoghost/chestcommands/api/PlaceholderReplacer.java index 0378335..9805161 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/Placeholder.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/PlaceholderReplacer.java @@ -12,14 +12,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.placeholder; +package me.filoghost.chestcommands.api; import org.bukkit.entity.Player; -public interface Placeholder { +public interface PlaceholderReplacer { - String getPlaceholderText(); - - String getReplacementText(Player player); + String getReplacement(Player player, String argument); } diff --git a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java index 8a5c278..16cb8b1 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java @@ -16,6 +16,7 @@ package me.filoghost.chestcommands.api.internal; import me.filoghost.chestcommands.api.ConfigurableIcon; import me.filoghost.chestcommands.api.IconMenu; +import me.filoghost.chestcommands.api.PlaceholderReplacer; import me.filoghost.chestcommands.api.StaticIcon; import me.filoghost.chestcommands.util.Preconditions; import org.bukkit.Material; @@ -50,4 +51,6 @@ public abstract class BackendAPI { public abstract StaticIcon createStaticIcon(ItemStack itemStack); + public abstract void registerPlaceholder(Plugin plugin, String identifier, PlaceholderReplacer placeholderReplacer); + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 8aa8f83..92bf0db 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -36,6 +36,7 @@ import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.logging.PrintableErrorCollector; import me.filoghost.chestcommands.menu.MenuManager; import me.filoghost.chestcommands.parsing.menu.LoadedMenu; +import me.filoghost.chestcommands.placeholder.PlaceholderManager; import me.filoghost.chestcommands.task.TickingTask; import me.filoghost.chestcommands.util.Utils; import me.filoghost.chestcommands.util.logging.ErrorCollector; @@ -182,6 +183,7 @@ public class ChestCommands extends BaseJavaPlugin { settings = configManager.tryLoadSettings(errorCollector); lang = configManager.tryLoadLang(errorCollector); placeholders = configManager.tryLoadCustomPlaceholders(errorCollector); + PlaceholderManager.setStaticPlaceholders(placeholders.getPlaceholders()); // Create the menu folder with the example menu if (!Files.isDirectory(configManager.getMenusFolder())) { @@ -227,10 +229,6 @@ public class ChestCommands extends BaseJavaPlugin { return lang; } - public static CustomPlaceholders getCustomPlaceholders() { - return placeholders; - } - public static boolean hasNewVersion() { return newVersion != null; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java b/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java index e57b92f..ee12362 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java @@ -16,12 +16,14 @@ package me.filoghost.chestcommands; import me.filoghost.chestcommands.api.ConfigurableIcon; import me.filoghost.chestcommands.api.IconMenu; +import me.filoghost.chestcommands.api.PlaceholderReplacer; import me.filoghost.chestcommands.api.StaticIcon; import me.filoghost.chestcommands.api.internal.BackendAPI; import me.filoghost.chestcommands.icon.APIConfigurableIcon; import me.filoghost.chestcommands.icon.APIStaticIcon; import me.filoghost.chestcommands.menu.APIIconMenu; import me.filoghost.chestcommands.menu.InternalIconMenu; +import me.filoghost.chestcommands.placeholder.PlaceholderManager; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -61,4 +63,9 @@ public class DefaultBackendAPI extends BackendAPI { return new APIStaticIcon(itemStack); } + @Override + public void registerPlaceholder(Plugin plugin, String identifier, PlaceholderReplacer placeholderReplacer) { + PlaceholderManager.registerPluginPlaceholder(plugin, identifier, placeholderReplacer); + } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java index bea7ade..cb3a73a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java @@ -16,17 +16,16 @@ package me.filoghost.chestcommands.config; import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.placeholder.StaticPlaceholder; import me.filoghost.chestcommands.util.Colors; import me.filoghost.chestcommands.util.logging.ErrorCollector; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; public class CustomPlaceholders { - private final Map placeholders = new HashMap<>(); + private final List placeholders = new ArrayList<>(); public void load(Config config, ErrorCollector errorCollector) { placeholders.clear(); @@ -44,40 +43,12 @@ public class CustomPlaceholders { continue; } - placeholders.put(placeholder, replacement); + placeholders.add(new StaticPlaceholder(placeholder, replacement)); } } - public String replacePlaceholders(String input) { - if (input == null) { - return null; - } - for (Entry entry : placeholders.entrySet()) { - input = input.replace(entry.getKey(), entry.getValue()); - } - return input; - } - - public boolean containsPlaceholders(String input) { - if (input == null) { - return false; - } - for (String placeholder : placeholders.keySet()) { - if (input.contains(placeholder)) { - return true; - } - } - return false; - } - - public boolean containsPlaceholders(List list) { - for (String element : list) { - if (containsPlaceholders(element)) { - return true; - } - } - - return false; + public List getPlaceholders() { + return placeholders; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholder.java similarity index 52% rename from Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholders.java rename to Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholder.java index c44e537..9b224a6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholder.java @@ -14,23 +14,21 @@ */ package me.filoghost.chestcommands.placeholder; +import me.filoghost.chestcommands.api.PlaceholderReplacer; import me.filoghost.chestcommands.hook.VaultEconomyHook; import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import java.util.function.Function; +public enum DefaultPlaceholder { -public enum DefaultPlaceholders implements Placeholder { + PLAYER("player", (player, argument) -> player.getName()), - PLAYER("{player}", player -> player.getName()), + ONLINE("online", (player, argument) -> String.valueOf(Bukkit.getOnlinePlayers().size())), - ONLINE("{online}", player -> String.valueOf(Bukkit.getOnlinePlayers().size())), + MAX_PLAYERS("max_players", (player, argument) -> String.valueOf(Bukkit.getMaxPlayers())), - MAX_PLAYERS("{max_players}", player -> String.valueOf(Bukkit.getMaxPlayers())), + WORLD("world", (player, argument) -> player.getWorld().getName()), - WORLD("{world}", player -> player.getWorld().getName()), - - MONEY("{money}", player -> { + MONEY("money", (player, argument) -> { if (VaultEconomyHook.INSTANCE.isEnabled()) { return VaultEconomyHook.formatMoney(VaultEconomyHook.getMoney(player)); } else { @@ -39,22 +37,20 @@ public enum DefaultPlaceholders implements Placeholder { }); - private final String placeholderText; - private final Function placeholderReplacer; + private final String identifier; + private final PlaceholderReplacer replacer; - DefaultPlaceholders(String placeholderText, Function placeholderReplacer) { - this.placeholderText = placeholderText; - this.placeholderReplacer = placeholderReplacer; + DefaultPlaceholder(String identifier, PlaceholderReplacer replacer) { + this.identifier = identifier; + this.replacer = replacer; } - @Override - public String getPlaceholderText() { - return placeholderText; + public String getIdentifier() { + return identifier; } - @Override - public String getReplacementText(Player player) { - return placeholderReplacer.apply(player); + public PlaceholderReplacer getReplacer() { + return replacer; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderCache.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderCache.java new file mode 100644 index 0000000..093fc14 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderCache.java @@ -0,0 +1,43 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.placeholder; + +import me.filoghost.chestcommands.placeholder.scanner.PlaceholderMatch; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; +import java.util.WeakHashMap; +import java.util.function.Supplier; + +public class PlaceholderCache { + + private final Map> cachedReplacements; + + public PlaceholderCache() { + cachedReplacements = new WeakHashMap<>(); + } + + public String computeIfAbsent(PlaceholderMatch placeholderMatch, Player player, Supplier replacementGetter) { + return cachedReplacements + .computeIfAbsent(player, key -> new HashMap<>()) + .computeIfAbsent(placeholderMatch, key -> replacementGetter.get()); + } + + public void onTick() { + cachedReplacements.forEach((player, placeholderMap) -> placeholderMap.clear()); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java index 7aba7eb..1f408d2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java @@ -14,28 +14,42 @@ */ package me.filoghost.chestcommands.placeholder; +import me.filoghost.chestcommands.api.PlaceholderReplacer; import me.filoghost.chestcommands.hook.PlaceholderAPIHook; +import me.filoghost.chestcommands.placeholder.scanner.PlaceholderMatch; +import me.filoghost.chestcommands.placeholder.scanner.PlaceholderScanner; +import me.filoghost.chestcommands.util.Preconditions; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.WeakHashMap; public class PlaceholderManager { - private static final Map> cachedReplacements = new WeakHashMap<>(); - - public static boolean hasPlaceholders(String text) { - if (text == null) { - return false; + private static final List staticPlaceholders = new ArrayList<>(); + private static final PlaceholderRegistry relativePlaceholderRegistry = new PlaceholderRegistry(); + static { + for (DefaultPlaceholder placeholder : DefaultPlaceholder.values()) { + relativePlaceholderRegistry.registerInternalPlaceholder(placeholder.getIdentifier(), placeholder.getReplacer()); } + } - for (Placeholder placeholder : DefaultPlaceholders.values()) { - if (text.contains(placeholder.getPlaceholderText())) { + private static final PlaceholderCache placeholderCache = new PlaceholderCache(); + + public static boolean hasRelativePlaceholders(List list) { + for (String element : list) { + if (hasRelativePlaceholders(element)) { return true; } } + return false; + } + + public static boolean hasRelativePlaceholders(String text) { + if (new PlaceholderScanner(text).anyMatch(PlaceholderManager::isValidPlaceholder)) { + return true; + } if (PlaceholderAPIHook.INSTANCE.isEnabled() && PlaceholderAPIHook.hasPlaceholders(text)) { return true; @@ -44,26 +58,8 @@ public class PlaceholderManager { return false; } - public static boolean hasPlaceholders(List list) { - for (String element : list) { - if (hasPlaceholders(element)) { - return true; - } - } - return false; - } - - public static String replacePlaceholders(String text, Player player) { - if (text == null) { - return null; - } - - for (Placeholder placeholder : DefaultPlaceholders.values()) { - if (text.contains(placeholder.getPlaceholderText())) { - String replacement = getCachedReplacement(placeholder, player); - text = text.replace(placeholder.getPlaceholderText(), replacement); - } - } + public static String replaceRelativePlaceholders(String text, Player player) { + text = new PlaceholderScanner(text).replace(match -> getReplacement(match, player)); if (PlaceholderAPIHook.INSTANCE.isEnabled()) { text = PlaceholderAPIHook.setPlaceholders(text, player); @@ -72,14 +68,61 @@ public class PlaceholderManager { return text; } - private static String getCachedReplacement(Placeholder placeholder, Player player) { - return cachedReplacements - .computeIfAbsent(player, key -> new HashMap<>()) - .computeIfAbsent(placeholder, key -> placeholder.getReplacementText(player)); + private static boolean isValidPlaceholder(PlaceholderMatch placeholderMatch) { + return relativePlaceholderRegistry.getPlaceholderReplacer(placeholderMatch) != null; + } + + private static String getReplacement(PlaceholderMatch placeholderMatch, Player player) { + PlaceholderReplacer placeholderReplacer = relativePlaceholderRegistry.getPlaceholderReplacer(placeholderMatch); + + if (placeholderReplacer == null) { + return null; // Placeholder not found + } + + return placeholderCache.computeIfAbsent(placeholderMatch, player, () -> { + return placeholderReplacer.getReplacement(player, placeholderMatch.getArgument()); + }); + } + + public static void setStaticPlaceholders(List staticPlaceholders) { + PlaceholderManager.staticPlaceholders.clear(); + PlaceholderManager.staticPlaceholders.addAll(staticPlaceholders); + } + + public static boolean hasStaticPlaceholders(List list) { + for (String element : list) { + if (hasStaticPlaceholders(element)) { + return true; + } + } + return false; + } + + public static boolean hasStaticPlaceholders(String text) { + for (StaticPlaceholder staticPlaceholder : staticPlaceholders) { + if (text.contains(staticPlaceholder.getIdentifier())) { + return true; + } + } + return false; + } + + public static String replaceStaticPlaceholders(String text) { + for (StaticPlaceholder staticPlaceholder : staticPlaceholders) { + text = text.replace(staticPlaceholder.getIdentifier(), staticPlaceholder.getReplacement()); + } + return text; + } + + public static void registerPluginPlaceholder(Plugin plugin, String identifier, PlaceholderReplacer placeholderReplacer) { + Preconditions.checkArgument(1 <= identifier.length() && identifier.length() <= 30, "identifier length must be between 1 and 30"); + Preconditions.checkArgument(identifier.matches("[a-zA-Z0-9_]+"), "identifier must contain only letters, numbers and underscores"); + + relativePlaceholderRegistry.registerExternalPlaceholder(plugin, identifier, placeholderReplacer); } public static void onTick() { - cachedReplacements.forEach((player, placeholderMap) -> placeholderMap.clear()); + placeholderCache.onTick(); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderRegistry.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderRegistry.java new file mode 100644 index 0000000..9129154 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderRegistry.java @@ -0,0 +1,62 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.placeholder; + +import me.filoghost.chestcommands.api.PlaceholderReplacer; +import me.filoghost.chestcommands.placeholder.scanner.PlaceholderMatch; +import org.bukkit.plugin.Plugin; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +public class PlaceholderRegistry { + + private final Map internalPlaceholders = new HashMap<>(); + private final Map> externalPlaceholders = new HashMap<>(); + + public void registerInternalPlaceholder(String identifier, PlaceholderReplacer replacer) { + internalPlaceholders.put(identifier, replacer); + } + + public void registerExternalPlaceholder(Plugin plugin, String identifier, PlaceholderReplacer placeholderReplacer) { + externalPlaceholders + .computeIfAbsent(identifier, key -> new LinkedHashMap<>()) + .put(plugin.getName(), placeholderReplacer); + } + + public PlaceholderReplacer getPlaceholderReplacer(PlaceholderMatch placeholderMatch) { + if (placeholderMatch.getPluginNamespace() == null) { + PlaceholderReplacer internalReplacer = internalPlaceholders.get(placeholderMatch.getIdentifier()); + if (internalReplacer != null) { + return internalReplacer; + } + } + + Map externalReplacers = externalPlaceholders.get(placeholderMatch.getIdentifier()); + + // Find exact replacer if plugin name is specified + if (placeholderMatch.getPluginNamespace() != null) { + return externalReplacers.get(placeholderMatch.getPluginNamespace()); + } + + if (externalReplacers != null && !externalReplacers.isEmpty()) { + return externalReplacers.values().iterator().next(); + } + + return null; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderString.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderString.java index 77c8090..6a1860a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderString.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderString.java @@ -14,7 +14,6 @@ */ package me.filoghost.chestcommands.placeholder; -import me.filoghost.chestcommands.ChestCommands; import org.bukkit.entity.Player; public class PlaceholderString { @@ -33,13 +32,13 @@ public class PlaceholderString { private PlaceholderString(String originalString) { this.originalString = originalString; - this.stringWithStaticPlaceholders = ChestCommands.getCustomPlaceholders().replacePlaceholders(originalString); - this.hasDynamicPlaceholders = PlaceholderManager.hasPlaceholders(stringWithStaticPlaceholders); + this.stringWithStaticPlaceholders = PlaceholderManager.replaceStaticPlaceholders(originalString); + this.hasDynamicPlaceholders = PlaceholderManager.hasRelativePlaceholders(stringWithStaticPlaceholders); } public String getValue(Player player) { if (hasDynamicPlaceholders) { - return PlaceholderManager.replacePlaceholders(stringWithStaticPlaceholders, player); + return PlaceholderManager.replaceRelativePlaceholders(stringWithStaticPlaceholders, player); } else { return stringWithStaticPlaceholders; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java index 6169902..d3b2908 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java @@ -15,7 +15,6 @@ package me.filoghost.chestcommands.placeholder; import com.google.common.collect.ImmutableList; -import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.collection.CollectionUtils; import org.bukkit.entity.Player; @@ -32,13 +31,13 @@ public class PlaceholderStringList { this.originalList = list; // Replace static placeholders only once, if present - if (ChestCommands.getCustomPlaceholders().containsPlaceholders(originalList)) { - this.listWithStaticPlaceholders = CollectionUtils.transformImmutable(originalList, ChestCommands.getCustomPlaceholders()::replacePlaceholders); + if (PlaceholderManager.hasStaticPlaceholders(originalList)) { + this.listWithStaticPlaceholders = CollectionUtils.transformImmutable(originalList, PlaceholderManager::replaceStaticPlaceholders); } else { this.listWithStaticPlaceholders = originalList; } - this.hasDynamicPlaceholders = PlaceholderManager.hasPlaceholders(listWithStaticPlaceholders); + this.hasDynamicPlaceholders = PlaceholderManager.hasRelativePlaceholders(listWithStaticPlaceholders); if (hasDynamicPlaceholders) { this.placeholderStringList = CollectionUtils.transformImmutable(listWithStaticPlaceholders, PlaceholderString::of); } else { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/StaticPlaceholder.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/StaticPlaceholder.java new file mode 100644 index 0000000..dcfe556 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/StaticPlaceholder.java @@ -0,0 +1,35 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.placeholder; + +public class StaticPlaceholder { + + private final String identifier; + private final String replacement; + + public StaticPlaceholder(String identifier, String replacement) { + this.identifier = identifier; + this.replacement = replacement; + } + + public String getIdentifier() { + return identifier; + } + + public String getReplacement() { + return replacement; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java new file mode 100644 index 0000000..372a685 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java @@ -0,0 +1,90 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.placeholder.scanner; + +import me.filoghost.chestcommands.util.Strings; + +import java.util.Objects; + +public class PlaceholderMatch { + + private final String pluginNamespace; + private final String identifier; + private final String argument; + + private PlaceholderMatch(String pluginNamespace, String identifier, String argument) { + this.pluginNamespace = pluginNamespace; + this.identifier = identifier; + this.argument = argument; + } + + public String getPluginNamespace() { + return pluginNamespace; + } + + public String getIdentifier() { + return identifier; + } + + public String getArgument() { + return argument; + } + + /** + * Expected format: {pluginName/placeholder: argument} + */ + public static PlaceholderMatch parse(String placeholderContent) { + String explicitPluginName = null; + String identifier; + String argument = null; + + if (placeholderContent.contains(":")) { + String[] parts = Strings.trimmedSplit(placeholderContent, ":", 2); + identifier = parts[0]; + argument = parts[1]; + } else { + identifier = placeholderContent; + } + + if (identifier.contains("/")) { + String[] parts = Strings.trimmedSplit(identifier, "\\/", 2); + identifier = parts[0]; + explicitPluginName = parts[1]; + } + + return new PlaceholderMatch(explicitPluginName, identifier, argument); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || this.getClass() != obj.getClass()) { + return false; + } + + PlaceholderMatch other = (PlaceholderMatch) obj; + return Objects.equals(this.pluginNamespace, other.pluginNamespace) && + Objects.equals(this.identifier, other.identifier) && + Objects.equals(this.argument, other.argument); + } + + @Override + public int hashCode() { + return Objects.hash(pluginNamespace, identifier, argument); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java new file mode 100644 index 0000000..bed6b69 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java @@ -0,0 +1,97 @@ +package me.filoghost.chestcommands.placeholder.scanner; + +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; + +public class PlaceholderScanner { + + private final String input; + private final int inputLength; + + private int lastAppendIndex; + private int placeholderStartIndex; + private int index; + private boolean stopExecution; + + public PlaceholderScanner(String input) { + this.input = input; + this.inputLength = input.length(); + } + + public boolean anyMatch(Predicate predicate) { + AtomicBoolean matchFound = new AtomicBoolean(false); + + scan(identifier -> { + if (predicate.test(identifier)) { + matchFound.set(true); + stopExecution = true; + } + }); + + return matchFound.get(); + } + + public String replace(Function replaceFunction) { + StringBuilder output = new StringBuilder(); + + scan(identifier -> { + String replacement = replaceFunction.apply(identifier); + + if (replacement != null) { + // Append preceding text and replacement + output.append(input, lastAppendIndex, placeholderStartIndex); + output.append(replacement); + lastAppendIndex = index + 1; // Start next append after the closing tag + } + + // Else, if no replacement is found, ignore the placeholder replacement and proceed normally + }); + + // Append trailing text + if (lastAppendIndex < inputLength) { + output.append(input, lastAppendIndex, inputLength); + } + + return output.toString(); + } + + private void scan(Consumer matchCallback) { + index = 0; + placeholderStartIndex = 0; + lastAppendIndex = 0; + + boolean insidePlaceholder = false; + + while (index < inputLength) { + char currentChar = input.charAt(index); + + if (insidePlaceholder) { + if (currentChar == '}') { + // If the placeholder is "{player}" then the identifier is "player" + String placeholderContent = input.substring(placeholderStartIndex + 1, index); // Skip the opening tag + matchCallback.accept(PlaceholderMatch.parse(placeholderContent)); + if (!stopExecution) { + return; + } + + insidePlaceholder = false; + placeholderStartIndex = 0; + + } else if (currentChar == '{') { + // Nested placeholder, ignore wrapping placeholder and update placeholder start index + placeholderStartIndex = index; + } + } else { + if (currentChar == '{') { + insidePlaceholder = true; + placeholderStartIndex = index; + } + } + + index++; + } + } + +} diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java index e23abe6..f0ad021 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java @@ -29,6 +29,10 @@ public final class CollectionUtils { return collection == null || collection.isEmpty(); } + public static boolean isNullOrEmpty(Map map) { + return map == null || map.isEmpty(); + } + public static List nullableCopy(List list) { if (isNullOrEmpty(list)) { return null; From a1c7f9d24dc3ef08988f73b1fb99bcfb924265e1 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 27 Jul 2020 21:37:01 +0200 Subject: [PATCH 153/213] Simplify class --- .../chestcommands/parsing/ActionParser.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java index 9ab6ccc..1cc942b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java @@ -36,22 +36,23 @@ import java.util.regex.Pattern; public class ActionParser { private static final Map actionsByPrefix = new HashMap<>(); - static { - actionsByPrefix.put(actionPattern("console:"), ConsoleCommandAction::new); - actionsByPrefix.put(actionPattern("op:"), OpCommandAction::new); - actionsByPrefix.put(actionPattern("(open|menu):"), OpenMenuAction::new); - actionsByPrefix.put(actionPattern("server:?"), ChangeServerAction::new); // The colon is optional - actionsByPrefix.put(actionPattern("tell:"), SendMessageAction::new); - actionsByPrefix.put(actionPattern("broadcast:"), BroadcastAction::new); - actionsByPrefix.put(actionPattern("give:"), GiveItemAction::new); - actionsByPrefix.put(actionPattern("give-?money:"), GiveMoneyAction::new); - actionsByPrefix.put(actionPattern("sound:"), PlaySoundAction::new); - actionsByPrefix.put(actionPattern("dragon-?bar:"), DragonBarAction::new); + addActionParserMapping("console:", ConsoleCommandAction::new); + addActionParserMapping("op:", OpCommandAction::new); + addActionParserMapping("(open|menu):", OpenMenuAction::new); + addActionParserMapping("server:?", ChangeServerAction::new); // The colon is optional + addActionParserMapping("tell:", SendMessageAction::new); + addActionParserMapping("broadcast:", BroadcastAction::new); + addActionParserMapping("give:", GiveItemAction::new); + addActionParserMapping("give-?money:", GiveMoneyAction::new); + addActionParserMapping("sound:", PlaySoundAction::new); + addActionParserMapping("dragon-?bar:", DragonBarAction::new); } - private static Pattern actionPattern(String regex) { - return Pattern.compile("^" + regex, Pattern.CASE_INSENSITIVE); // Case insensitive and only at the beginning + private static void addActionParserMapping(String regex, ActionFactory actionFactory) { + actionsByPrefix.put( + Pattern.compile("^" + regex, Pattern.CASE_INSENSITIVE), // Case insensitive and only at the beginning + actionFactory); } public static Action parseAction(String input) { @@ -67,7 +68,7 @@ public class ActionParser { return new PlayerCommandAction(input); // Default action, no match found } - + @FunctionalInterface private interface ActionFactory { Action create(String actionString); From 92310bc4ab0c0f7e9afd025bd73b9f4edb3a7117 Mon Sep 17 00:00:00 2001 From: filoghost Date: Tue, 28 Jul 2020 12:04:03 +0200 Subject: [PATCH 154/213] Refactor ItemSettings --- .../upgrade/MenuNodeExpandUpgradeTask.java | 26 +-- .../upgrade/MenuNodeRenameUpgradeTask.java | 16 +- .../chestcommands/logging/ErrorMessages.java | 9 +- .../parsing/icon/AttributeType.java | 139 ++++++++++++ .../parsing/icon/IconSettings.java | 211 ++++-------------- .../parsing/icon/IconSettingsNode.java | 41 ---- .../parsing/menu/MenuParser.java | 32 +-- 7 files changed, 225 insertions(+), 249 deletions(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettingsNode.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java index fc840ae..6655b00 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java @@ -20,7 +20,7 @@ import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.config.framework.ConfigSection; import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; -import me.filoghost.chestcommands.parsing.icon.IconSettingsNode; +import me.filoghost.chestcommands.parsing.icon.AttributeType; import me.filoghost.chestcommands.parsing.menu.MenuSettingsNode; import me.filoghost.chestcommands.util.Strings; @@ -85,45 +85,45 @@ public class MenuNodeExpandUpgradeTask extends UpgradeTask { } private void upgradeIcon(ConfigSection section) { - expandInlineList(section, IconSettingsNode.ACTIONS, legacyCommandSeparator); - expandInlineList(section, IconSettingsNode.ENCHANTMENTS, ";"); + expandInlineList(section, AttributeType.ACTIONS.getAttributeName(), legacyCommandSeparator); + expandInlineList(section, AttributeType.ENCHANTMENTS.getAttributeName(), ";"); - expandSingletonList(section, IconSettingsNode.REQUIRED_ITEMS); + expandSingletonList(section, AttributeType.REQUIRED_ITEMS.getAttributeName()); expandInlineItemstack(section); } private void expandInlineItemstack(ConfigSection section) { - String material = section.getString(IconSettingsNode.MATERIAL); + String material = section.getString(AttributeType.MATERIAL.getAttributeName()); if (material == null) { return; } if (material.contains(",")) { String[] parts = Strings.trimmedSplit(material, ",", 2); - if (!section.isSet(IconSettingsNode.AMOUNT)) { + if (!section.isSet(AttributeType.AMOUNT.getAttributeName())) { try { - section.set(IconSettingsNode.AMOUNT, Integer.parseInt(parts[1])); + section.set(AttributeType.AMOUNT.getAttributeName(), Integer.parseInt(parts[1])); } catch (NumberFormatException e) { - section.set(IconSettingsNode.AMOUNT, parts[1]); + section.set(AttributeType.AMOUNT.getAttributeName(), parts[1]); } } material = parts[0]; - section.set(IconSettingsNode.MATERIAL, material); + section.set(AttributeType.MATERIAL.getAttributeName(), material); setSaveRequired(); } if (material.contains(":")) { String[] parts = Strings.trimmedSplit(material, ":", 2); - if (!section.isSet(IconSettingsNode.DURABILITY)) { + if (!section.isSet(AttributeType.DURABILITY.getAttributeName())) { try { - section.set(IconSettingsNode.DURABILITY, Integer.parseInt(parts[1])); + section.set(AttributeType.DURABILITY.getAttributeName(), Integer.parseInt(parts[1])); } catch (NumberFormatException e) { - section.set(IconSettingsNode.DURABILITY, parts[1]); + section.set(AttributeType.DURABILITY.getAttributeName(), parts[1]); } } material = parts[0]; - section.set(IconSettingsNode.MATERIAL, material); + section.set(AttributeType.MATERIAL.getAttributeName(), material); setSaveRequired(); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgradeTask.java index 5cb85b6..5e49f2c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgradeTask.java @@ -14,7 +14,7 @@ */ package me.filoghost.chestcommands.legacy.upgrade; -import me.filoghost.chestcommands.parsing.icon.IconSettingsNode; +import me.filoghost.chestcommands.parsing.icon.AttributeType; import java.nio.file.Path; import java.util.regex.Pattern; @@ -28,13 +28,13 @@ public class MenuNodeRenameUpgradeTask extends RegexUpgradeTask { addSubNodeReplacer("open-action", "open-actions"); addSubNodeReplacer("id", "material"); - addSubNodeReplacer("ID", IconSettingsNode.MATERIAL); - addSubNodeReplacer("DATA-VALUE", IconSettingsNode.DURABILITY); - addSubNodeReplacer("NBT", IconSettingsNode.NBT_DATA); - addSubNodeReplacer("ENCHANTMENT", IconSettingsNode.ENCHANTMENTS); - addSubNodeReplacer("COMMAND", IconSettingsNode.ACTIONS); - addSubNodeReplacer("COMMANDS", IconSettingsNode.ACTIONS); - addSubNodeReplacer("REQUIRED-ITEM", IconSettingsNode.REQUIRED_ITEMS); + addSubNodeReplacer("ID", AttributeType.MATERIAL.getAttributeName()); + addSubNodeReplacer("DATA-VALUE", AttributeType.DURABILITY.getAttributeName()); + addSubNodeReplacer("NBT", AttributeType.NBT_DATA.getAttributeName()); + addSubNodeReplacer("ENCHANTMENT", AttributeType.ENCHANTMENTS.getAttributeName()); + addSubNodeReplacer("COMMAND", AttributeType.ACTIONS.getAttributeName()); + addSubNodeReplacer("COMMANDS", AttributeType.ACTIONS.getAttributeName()); + addSubNodeReplacer("REQUIRED-ITEM", AttributeType.REQUIRED_ITEMS.getAttributeName()); } private void addSubNodeReplacer(String oldNode, String newNode) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java index 9c849ed..5cd0703 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java @@ -16,6 +16,7 @@ package me.filoghost.chestcommands.logging; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.config.framework.mapped.MappedConfig; +import me.filoghost.chestcommands.parsing.icon.AttributeType; import me.filoghost.chestcommands.parsing.icon.IconSettings; import java.nio.file.Path; @@ -169,12 +170,16 @@ public class ErrorMessages { return "the menu \"" + formatPath(menuFile) + "\" " + errorMessage; } + public static String invalidAttribute(IconSettings iconSettings, AttributeType attributeType) { + return invalidAttribute(iconSettings, attributeType.getAttributeName()); + } + public static String invalidAttribute(IconSettings iconSettings, String attributeName) { return iconError(iconSettings, "has an invalid attribute \"" + attributeName + "\""); } - public static String missingAttribute(IconSettings iconSettings, String attributeName) { - return iconError(iconSettings, "is missing the attribute \"" + attributeName + "\""); + public static String missingAttribute(IconSettings iconSettings, AttributeType attributeType) { + return iconError(iconSettings, "is missing the attribute \"" + attributeType.getAttributeName() + "\""); } public static String invalidAttributeListElement(IconSettings iconSettings, String attributeName, String listElement) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java new file mode 100644 index 0000000..af0438c --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java @@ -0,0 +1,139 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.parsing.icon; + +import me.filoghost.chestcommands.config.framework.ConfigPath; +import me.filoghost.chestcommands.config.framework.ConfigSection; +import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; +import me.filoghost.chestcommands.parsing.ParseException; +import me.filoghost.chestcommands.parsing.attribute.ActionsAttribute; +import me.filoghost.chestcommands.parsing.attribute.AmountAttribute; +import me.filoghost.chestcommands.parsing.attribute.AttributeErrorHandler; +import me.filoghost.chestcommands.parsing.attribute.BannerColorAttribute; +import me.filoghost.chestcommands.parsing.attribute.BannerPatternsAttribute; +import me.filoghost.chestcommands.parsing.attribute.ClickPermissionAttribute; +import me.filoghost.chestcommands.parsing.attribute.ClickPermissionMessageAttribute; +import me.filoghost.chestcommands.parsing.attribute.DurabilityAttribute; +import me.filoghost.chestcommands.parsing.attribute.EnchantmentsAttribute; +import me.filoghost.chestcommands.parsing.attribute.ExpLevelsAttribute; +import me.filoghost.chestcommands.parsing.attribute.IconAttribute; +import me.filoghost.chestcommands.parsing.attribute.KeepOpenAttribute; +import me.filoghost.chestcommands.parsing.attribute.LeatherColorAttribute; +import me.filoghost.chestcommands.parsing.attribute.LoreAttribute; +import me.filoghost.chestcommands.parsing.attribute.MaterialAttribute; +import me.filoghost.chestcommands.parsing.attribute.NBTDataAttribute; +import me.filoghost.chestcommands.parsing.attribute.NameAttribute; +import me.filoghost.chestcommands.parsing.attribute.PositionAttribute; +import me.filoghost.chestcommands.parsing.attribute.PriceAttribute; +import me.filoghost.chestcommands.parsing.attribute.RequiredItemsAttribute; +import me.filoghost.chestcommands.parsing.attribute.SkullOwnerAttribute; +import me.filoghost.chestcommands.parsing.attribute.ViewPermissionAttribute; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public enum AttributeType implements ConfigPath { + + POSITION_X("POSITION-X", ValueExtractor.INT, PositionAttribute::new), + POSITION_Y("POSITION-Y", ValueExtractor.INT, PositionAttribute::new), + MATERIAL("MATERIAL", ValueExtractor.STRING, MaterialAttribute::new), + DURABILITY("DURABILITY", ValueExtractor.SHORT, DurabilityAttribute::new), + AMOUNT("AMOUNT", ValueExtractor.INT, AmountAttribute::new), + NAME("NAME", ValueExtractor.STRING, NameAttribute::new), + LORE("LORE", ValueExtractor.STRING_LIST, LoreAttribute::new), + NBT_DATA("NBT-DATA", ValueExtractor.STRING, NBTDataAttribute::new), + LEATHER_COLOR("COLOR", ValueExtractor.STRING, LeatherColorAttribute::new), + SKULL_OWNER("SKULL-OWNER", ValueExtractor.STRING, SkullOwnerAttribute::new), + BANNER_COLOR("BANNER-COLOR", ValueExtractor.STRING, BannerColorAttribute::new), + BANNER_PATTERNS("BANNER-PATTERNS", ValueExtractor.STRING_LIST, BannerPatternsAttribute::new), + PRICE("PRICE", ValueExtractor.DOUBLE, PriceAttribute::new), + EXP_LEVELS("LEVELS", ValueExtractor.INT, ExpLevelsAttribute::new), + CLICK_PERMISSION("PERMISSION", ValueExtractor.STRING, ClickPermissionAttribute::new), + CLICK_PERMISSION_MESSAGE("PERMISSION-MESSAGE", ValueExtractor.STRING, ClickPermissionMessageAttribute::new), + VIEW_PERMISSION("VIEW-PERMISSION", ValueExtractor.STRING, ViewPermissionAttribute::new), + KEEP_OPEN("KEEP-OPEN", ValueExtractor.BOOLEAN, KeepOpenAttribute::new), + ACTIONS("ACTIONS", ValueExtractor.STRING_LIST, ActionsAttribute::new), + ENCHANTMENTS("ENCHANTMENTS", ValueExtractor.STRING_LIST, EnchantmentsAttribute::new), + REQUIRED_ITEMS("REQUIRED-ITEMS", ValueExtractor.STRING_LIST, RequiredItemsAttribute::new); + + private static final Map parsersByAttributeName; + static { + parsersByAttributeName = new HashMap<>(); + for (AttributeType attributeParser : values()) { + parsersByAttributeName.put(attributeParser.getAttributeName(), attributeParser); + } + } + + private final String attributeName; + private final AttributeParser attributeParser; + + AttributeType(String attributeName, ValueExtractor valueExtractor, AttributeFactory attributeFactory) { + this.attributeName = attributeName; + this.attributeParser = (ConfigSection config, String node, AttributeErrorHandler errorHandler) -> { + V configValue = valueExtractor.getValue(config, node); + return attributeFactory.create(configValue, errorHandler); + }; + } + + public String getAttributeName() { + return attributeName; + } + + public AttributeParser getParser() { + return attributeParser; + } + + @Override + public String getConfigPath() { + return attributeName; + } + + public static AttributeType fromAttributeName(String attributeName) { + return parsersByAttributeName.get(attributeName); + } + + + @FunctionalInterface + private interface ValueExtractor { + + V getValue(ConfigSection config, String key) throws ConfigValueException; + + ValueExtractor INT = ConfigSection::getRequiredInt; + ValueExtractor DOUBLE = ConfigSection::getRequiredDouble; + ValueExtractor SHORT = ConfigSection::getRequiredShort; + ValueExtractor BOOLEAN = ConfigSection::getRequiredBoolean; + ValueExtractor STRING = ConfigSection::getRequiredString; + ValueExtractor> STRING_LIST = ConfigSection::getRequiredStringList; + + } + + + @FunctionalInterface + private interface AttributeFactory { + + A create(V value, AttributeErrorHandler errorHandler) throws ParseException; + + } + + + @FunctionalInterface + public interface AttributeParser { + + IconAttribute parse(ConfigSection config, String node, AttributeErrorHandler errorHandler) throws ParseException, ConfigValueException; + + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java index ecd2683..5479df7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java @@ -19,72 +19,63 @@ import me.filoghost.chestcommands.config.framework.exception.ConfigValueExceptio import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.parsing.attribute.ActionsAttribute; -import me.filoghost.chestcommands.parsing.attribute.AmountAttribute; import me.filoghost.chestcommands.parsing.attribute.ApplicableIconAttribute; import me.filoghost.chestcommands.parsing.attribute.AttributeErrorHandler; -import me.filoghost.chestcommands.parsing.attribute.BannerColorAttribute; -import me.filoghost.chestcommands.parsing.attribute.BannerPatternsAttribute; -import me.filoghost.chestcommands.parsing.attribute.ClickPermissionAttribute; -import me.filoghost.chestcommands.parsing.attribute.ClickPermissionMessageAttribute; -import me.filoghost.chestcommands.parsing.attribute.DurabilityAttribute; -import me.filoghost.chestcommands.parsing.attribute.EnchantmentsAttribute; -import me.filoghost.chestcommands.parsing.attribute.ExpLevelsAttribute; import me.filoghost.chestcommands.parsing.attribute.IconAttribute; -import me.filoghost.chestcommands.parsing.attribute.KeepOpenAttribute; -import me.filoghost.chestcommands.parsing.attribute.LeatherColorAttribute; -import me.filoghost.chestcommands.parsing.attribute.LoreAttribute; -import me.filoghost.chestcommands.parsing.attribute.MaterialAttribute; -import me.filoghost.chestcommands.parsing.attribute.NBTDataAttribute; -import me.filoghost.chestcommands.parsing.attribute.NameAttribute; -import me.filoghost.chestcommands.parsing.attribute.PositionAttribute; -import me.filoghost.chestcommands.parsing.attribute.PriceAttribute; -import me.filoghost.chestcommands.parsing.attribute.RequiredItemsAttribute; -import me.filoghost.chestcommands.parsing.attribute.SkullOwnerAttribute; -import me.filoghost.chestcommands.parsing.attribute.ViewPermissionAttribute; -import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.logging.ErrorCollector; +import org.bukkit.Material; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; +import java.util.EnumMap; import java.util.Map; public class IconSettings { private final Path menuFile; private final String iconName; + private final Map attributes; - private PositionAttribute positionX; - private PositionAttribute positionY; - private MaterialAttribute materialAttribute; - private final List applicableAttributes; + public IconSettings(Path menuFile, String iconName) { + this.menuFile = menuFile; + this.iconName = iconName; + this.attributes = new EnumMap<>(AttributeType.class); + } - public static final Map iconNodeHandlers = new HashMap<>(); - static { - addIconNodeHandler(IconSettingsNode.POSITION_X, ValueExtractor.INT, PositionAttribute::new, IconSettings::setPositionX); - addIconNodeHandler(IconSettingsNode.POSITION_Y, ValueExtractor.INT, PositionAttribute::new, IconSettings::setPositionY); - addIconNodeHandler(IconSettingsNode.MATERIAL, ValueExtractor.STRING, MaterialAttribute::new, IconSettings::setMaterialAttribute); + public InternalConfigurableIcon createIcon() { + InternalConfigurableIcon icon = new InternalConfigurableIcon(Material.BEDROCK); - addApplicableIconNodeHandler(IconSettingsNode.DURABILITY, ValueExtractor.SHORT, DurabilityAttribute::new); - addApplicableIconNodeHandler(IconSettingsNode.AMOUNT, ValueExtractor.INT, AmountAttribute::new); - addApplicableIconNodeHandler(IconSettingsNode.NAME, ValueExtractor.STRING, NameAttribute::new); - addApplicableIconNodeHandler(IconSettingsNode.LORE, ValueExtractor.STRING_LIST, LoreAttribute::new); - addApplicableIconNodeHandler(IconSettingsNode.NBT_DATA, ValueExtractor.STRING, NBTDataAttribute::new); - addApplicableIconNodeHandler(IconSettingsNode.LEATHER_COLOR, ValueExtractor.STRING, LeatherColorAttribute::new); - addApplicableIconNodeHandler(IconSettingsNode.SKULL_OWNER, ValueExtractor.STRING, SkullOwnerAttribute::new); - addApplicableIconNodeHandler(IconSettingsNode.BANNER_COLOR, ValueExtractor.STRING, BannerColorAttribute::new); - addApplicableIconNodeHandler(IconSettingsNode.BANNER_PATTERNS, ValueExtractor.STRING_LIST, BannerPatternsAttribute::new); - addApplicableIconNodeHandler(IconSettingsNode.PRICE, ValueExtractor.DOUBLE, PriceAttribute::new); - addApplicableIconNodeHandler(IconSettingsNode.EXP_LEVELS, ValueExtractor.INT, ExpLevelsAttribute::new); - addApplicableIconNodeHandler(IconSettingsNode.CLICK_PERMISSION, ValueExtractor.STRING, ClickPermissionAttribute::new); - addApplicableIconNodeHandler(IconSettingsNode.CLICK_PERMISSION_MESSAGE, ValueExtractor.STRING, ClickPermissionMessageAttribute::new); - addApplicableIconNodeHandler(IconSettingsNode.VIEW_PERMISSION, ValueExtractor.STRING, ViewPermissionAttribute::new); - addApplicableIconNodeHandler(IconSettingsNode.KEEP_OPEN, ValueExtractor.BOOLEAN, KeepOpenAttribute::new); - addApplicableIconNodeHandler(IconSettingsNode.ACTIONS, ValueExtractor.STRING_LIST, ActionsAttribute::new); - addApplicableIconNodeHandler(IconSettingsNode.ENCHANTMENTS, ValueExtractor.STRING_LIST, EnchantmentsAttribute::new); - addApplicableIconNodeHandler(IconSettingsNode.REQUIRED_ITEMS, ValueExtractor.STRING_LIST, RequiredItemsAttribute::new); + for (IconAttribute attribute : attributes.values()) { + if (attribute instanceof ApplicableIconAttribute) { + ((ApplicableIconAttribute) attribute).apply(icon); + } + } + + return icon; + } + + public IconAttribute getAttributeValue(AttributeType attributeType) { + return attributes.get(attributeType); + } + + public void loadFrom(ConfigSection config, ErrorCollector errorCollector) { + for (String attributeName : config.getKeys(false)) { + try { + AttributeType attributeType = AttributeType.fromAttributeName(attributeName); + if (attributeType == null) { + throw new ParseException(ErrorMessages.Parsing.unknownAttribute); + } + + AttributeErrorHandler errorHandler = (String listElement, ParseException e) -> { + errorCollector.add(ErrorMessages.Menu.invalidAttributeListElement(this, attributeName, listElement), e); + }; + + IconAttribute iconAttribute = attributeType.getParser().parse(config, attributeName, errorHandler); + attributes.put(attributeType, iconAttribute); + + } catch (ParseException | ConfigValueException e) { + errorCollector.add(ErrorMessages.Menu.invalidAttribute(this, attributeName), e); + } + } } public Path getMenuFile() { @@ -95,122 +86,4 @@ public class IconSettings { return iconName; } - public PositionAttribute getPositionX() { - return positionX; - } - - private void setPositionX(PositionAttribute positionAttribute) { - this.positionX = positionAttribute; - } - - public PositionAttribute getPositionY() { - return positionY; - } - - private void setPositionY(PositionAttribute positionAttribute) { - this.positionY = positionAttribute; - } - - public MaterialAttribute getMaterialAttribute() { - return materialAttribute; - } - - private void setMaterialAttribute(MaterialAttribute materialAttribute) { - this.materialAttribute = materialAttribute; - } - - public void addApplicableAttribute(ApplicableIconAttribute iconAttribute) { - applicableAttributes.add(iconAttribute); - } - - public void applyAttributesTo(InternalConfigurableIcon icon) { - if (materialAttribute != null) { - materialAttribute.apply(icon); - } - for (ApplicableIconAttribute attribute : applicableAttributes) { - attribute.apply(icon); - } - } - - public static void addApplicableIconNodeHandler( - String node, - ValueExtractor valueExtractor, - AttributeFactory attributeFactory) { - addIconNodeHandler(node, valueExtractor, attributeFactory, IconSettings::addApplicableAttribute); - } - - - public static void addIconNodeHandler( - String node, - ValueExtractor valueExtractor, - AttributeFactory attributeFactory, - AttributeApplier callback) { - addIconNodeHandler(node, (iconSettings, config, configNode, parseContext) -> { - V value = valueExtractor.getValue(config, configNode); - A iconAttribute = attributeFactory.create(value, parseContext); - callback.apply(iconSettings, iconAttribute); - }); - } - - private static void addIconNodeHandler(String node, AttributeParser iconNodeHandler) { - Preconditions.checkState(!iconNodeHandlers.containsKey(node), "Handler already exists for attribute " + node); - iconNodeHandlers.put(node, iconNodeHandler); - } - - public IconSettings(Path menuFile, String iconName) { - this.menuFile = menuFile; - this.iconName = iconName; - this.applicableAttributes = new ArrayList<>(); - } - - public void loadFrom(ConfigSection config, ErrorCollector errorCollector) { - for (String attributeName : config.getKeys(false)) { - try { - AttributeParser attributeParser = iconNodeHandlers.get(attributeName); - if (attributeParser == null) { - throw new ParseException(ErrorMessages.Parsing.unknownAttribute); - } - - attributeParser.parse(this, config, attributeName, (String listElement, ParseException e) -> { - errorCollector.add(ErrorMessages.Menu.invalidAttributeListElement(this, attributeName, listElement), e); - }); - - } catch (ParseException | ConfigValueException e) { - errorCollector.add(ErrorMessages.Menu.invalidAttribute(this, attributeName), e); - } - } - } - - - private interface ValueExtractor { - - V getValue(ConfigSection config, String key) throws ConfigValueException; - - ValueExtractor INT = ConfigSection::getRequiredInt; - ValueExtractor DOUBLE = ConfigSection::getRequiredDouble; - ValueExtractor SHORT = ConfigSection::getRequiredShort; - ValueExtractor BOOLEAN = ConfigSection::getRequiredBoolean; - ValueExtractor STRING = ConfigSection::getRequiredString; - ValueExtractor> STRING_LIST = ConfigSection::getRequiredStringList; - - } - - private interface AttributeFactory { - - A create(V value, AttributeErrorHandler errorHandler) throws ParseException; - - } - - private interface AttributeApplier { - - void apply(IconSettings iconSettings, A attribute); - - } - - private interface AttributeParser { - - void parse(IconSettings iconSettings, ConfigSection config, String node, AttributeErrorHandler errorHandler) throws ParseException, ConfigValueException; - - } - } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettingsNode.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettingsNode.java deleted file mode 100644 index 24e95ee..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettingsNode.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.parsing.icon; - -public class IconSettingsNode { - - public static final String - POSITION_X = "POSITION-X", - POSITION_Y = "POSITION-Y", - MATERIAL = "MATERIAL", - AMOUNT = "AMOUNT", - DURABILITY = "DURABILITY", - NBT_DATA = "NBT-DATA", - NAME = "NAME", - LORE = "LORE", - ENCHANTMENTS = "ENCHANTMENTS", - LEATHER_COLOR = "COLOR", - SKULL_OWNER = "SKULL-OWNER", - BANNER_COLOR = "BANNER-COLOR", - BANNER_PATTERNS = "BANNER-PATTERNS", - ACTIONS = "ACTIONS", - PRICE = "PRICE", - EXP_LEVELS = "LEVELS", - REQUIRED_ITEMS = "REQUIRED-ITEMS", - CLICK_PERMISSION = "PERMISSION", - CLICK_PERMISSION_MESSAGE = "PERMISSION-MESSAGE", - VIEW_PERMISSION = "VIEW-PERMISSION", - KEEP_OPEN = "KEEP-OPEN"; -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index 21ae0d5..a47d784 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -18,18 +18,17 @@ import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.config.framework.ConfigSection; import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; -import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.menu.InternalIconMenu; import me.filoghost.chestcommands.parsing.ActionParser; import me.filoghost.chestcommands.parsing.ItemStackParser; import me.filoghost.chestcommands.parsing.ParseException; +import me.filoghost.chestcommands.parsing.attribute.PositionAttribute; +import me.filoghost.chestcommands.parsing.icon.AttributeType; import me.filoghost.chestcommands.parsing.icon.IconSettings; -import me.filoghost.chestcommands.parsing.icon.IconSettingsNode; import me.filoghost.chestcommands.util.Colors; import me.filoghost.chestcommands.util.logging.ErrorCollector; import org.bukkit.ChatColor; -import org.bukkit.Material; import java.util.ArrayList; import java.util.List; @@ -55,26 +54,29 @@ public class MenuParser { private static void tryAddIconToMenu(InternalIconMenu iconMenu, IconSettings iconSettings, ErrorCollector errorCollector) { - if (iconSettings.getPositionX() == null) { - errorCollector.add(ErrorMessages.Menu.missingAttribute(iconSettings, IconSettingsNode.POSITION_X)); + PositionAttribute positionX = (PositionAttribute) iconSettings.getAttributeValue(AttributeType.POSITION_X); + PositionAttribute positionY = (PositionAttribute) iconSettings.getAttributeValue(AttributeType.POSITION_Y); + + if (positionX == null) { + errorCollector.add(ErrorMessages.Menu.missingAttribute(iconSettings, AttributeType.POSITION_X)); return; } - if (iconSettings.getPositionY() == null) { - errorCollector.add(ErrorMessages.Menu.missingAttribute(iconSettings, IconSettingsNode.POSITION_Y)); + if (positionY == null) { + errorCollector.add(ErrorMessages.Menu.missingAttribute(iconSettings, AttributeType.POSITION_Y)); return; } - int row = iconSettings.getPositionY().getPosition() - 1; - int column = iconSettings.getPositionX().getPosition() - 1; + int row = positionY.getPosition() - 1; + int column = positionX.getPosition() - 1; if (row < 0 || row >= iconMenu.getRowCount()) { - errorCollector.add(ErrorMessages.Menu.invalidAttribute(iconSettings, IconSettingsNode.POSITION_Y)) + errorCollector.add(ErrorMessages.Menu.invalidAttribute(iconSettings, AttributeType.POSITION_Y)) .appendMessage("it must be between 1 and " + iconMenu.getRowCount()); return; } if (column < 0 || column >= iconMenu.getColumnCount()) { - errorCollector.add(ErrorMessages.Menu.invalidAttribute(iconSettings, IconSettingsNode.POSITION_X)) + errorCollector.add(ErrorMessages.Menu.invalidAttribute(iconSettings, AttributeType.POSITION_X)) .appendMessage(("it must be between 1 and " + iconMenu.getColumnCount())); return; } @@ -83,13 +85,11 @@ public class MenuParser { errorCollector.add(ErrorMessages.Menu.iconOverridesAnother(iconSettings)); } - if (iconSettings.getMaterialAttribute() == null) { - errorCollector.add(ErrorMessages.Menu.missingAttribute(iconSettings, IconSettingsNode.MATERIAL)); + if (iconSettings.getAttributeValue(AttributeType.MATERIAL) == null) { + errorCollector.add(ErrorMessages.Menu.missingAttribute(iconSettings, AttributeType.MATERIAL)); } - InternalConfigurableIcon icon = new InternalConfigurableIcon(Material.BEDROCK); - iconSettings.applyAttributesTo(icon); - iconMenu.setIcon(row, column, icon); + iconMenu.setIcon(row, column, iconSettings.createIcon()); } From 2ea3266a1951c92b122cba0756b4ae8d03703722 Mon Sep 17 00:00:00 2001 From: filoghost Date: Tue, 28 Jul 2020 12:45:29 +0200 Subject: [PATCH 155/213] Refactor ActionParser --- .../chestcommands/parsing/ActionParser.java | 74 ++++++++++--------- .../parsing/attribute/ActionsAttribute.java | 2 +- .../parsing/icon/AttributeType.java | 8 +- .../parsing/menu/MenuParser.java | 2 +- 4 files changed, 41 insertions(+), 45 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java index 1cc942b..c9fcab3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java @@ -27,52 +27,54 @@ import me.filoghost.chestcommands.action.PlaySoundAction; import me.filoghost.chestcommands.action.PlayerCommandAction; import me.filoghost.chestcommands.action.SendMessageAction; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; public class ActionParser { - private static final Map actionsByPrefix = new HashMap<>(); - static { - addActionParserMapping("console:", ConsoleCommandAction::new); - addActionParserMapping("op:", OpCommandAction::new); - addActionParserMapping("(open|menu):", OpenMenuAction::new); - addActionParserMapping("server:?", ChangeServerAction::new); // The colon is optional - addActionParserMapping("tell:", SendMessageAction::new); - addActionParserMapping("broadcast:", BroadcastAction::new); - addActionParserMapping("give:", GiveItemAction::new); - addActionParserMapping("give-?money:", GiveMoneyAction::new); - addActionParserMapping("sound:", PlaySoundAction::new); - addActionParserMapping("dragon-?bar:", DragonBarAction::new); - } - - private static void addActionParserMapping(String regex, ActionFactory actionFactory) { - actionsByPrefix.put( - Pattern.compile("^" + regex, Pattern.CASE_INSENSITIVE), // Case insensitive and only at the beginning - actionFactory); - } - - public static Action parseAction(String input) { - for (Entry entry : actionsByPrefix.entrySet()) { - Matcher matcher = entry.getKey().matcher(input); + public static Action parse(String serializedAction) { + for (ActionType actionType : ActionType.values()) { + Matcher matcher = actionType.prefixPattern.matcher(serializedAction); if (matcher.find()) { // Remove the action prefix and trim the spaces - String serializedAction = matcher.replaceFirst("").trim(); - return entry.getValue().create(serializedAction); + serializedAction = matcher.replaceFirst("").trim(); + return actionType.actionFactory.create(serializedAction); } } - return new PlayerCommandAction(input); // Default action, no match found - } - - @FunctionalInterface - private interface ActionFactory { - - Action create(String actionString); - + return new PlayerCommandAction(serializedAction); // Default action, no match found } + + private enum ActionType { + + CONSOLE_COMMAND("console:", ConsoleCommandAction::new), + OP_COMMAND("op:", OpCommandAction::new), + OPEN("(open|menu):", OpenMenuAction::new), + SERVER("server:?", ChangeServerAction::new), // The colon is optional + TELL("tell:", SendMessageAction::new), + BROADCAST("broadcast:", BroadcastAction::new), + GIVE_ITEM("give:", GiveItemAction::new), + GIVE_MONEY("give-?money:", GiveMoneyAction::new), + SOUND("sound:", PlaySoundAction::new), + BOSS_BAR("dragon-?bar:", DragonBarAction::new); + + + private final Pattern prefixPattern; + private final ActionFactory actionFactory; + + + ActionType(String prefixPattern, ActionFactory actionFactory) { + this.prefixPattern = Pattern.compile("^" + prefixPattern, Pattern.CASE_INSENSITIVE); // Case insensitive and only at the beginning + this.actionFactory = actionFactory; + } + + @FunctionalInterface + private interface ActionFactory { + + Action create(String serializedAction); + + } + + } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ActionsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ActionsAttribute.java index 68d70da..3f84cc0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ActionsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ActionsAttribute.java @@ -33,7 +33,7 @@ public class ActionsAttribute implements ApplicableIconAttribute { continue; // Skip } - actions.add(ActionParser.parseAction(serializedAction)); + actions.add(ActionParser.parse(serializedAction)); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java index af0438c..4eb3fcd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java @@ -14,7 +14,6 @@ */ package me.filoghost.chestcommands.parsing.icon; -import me.filoghost.chestcommands.config.framework.ConfigPath; import me.filoghost.chestcommands.config.framework.ConfigSection; import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; import me.filoghost.chestcommands.parsing.ParseException; @@ -45,7 +44,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -public enum AttributeType implements ConfigPath { +public enum AttributeType { POSITION_X("POSITION-X", ValueExtractor.INT, PositionAttribute::new), POSITION_Y("POSITION-Y", ValueExtractor.INT, PositionAttribute::new), @@ -96,11 +95,6 @@ public enum AttributeType implements ConfigPath { return attributeParser; } - @Override - public String getConfigPath() { - return attributeName; - } - public static AttributeType fromAttributeName(String attributeName) { return parsersByAttributeName.get(attributeName); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index a47d784..ca0cf7e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -130,7 +130,7 @@ public class MenuParser { for (String serializedAction : serializedOpenActions) { if (serializedAction != null && !serializedAction.isEmpty()) { - openActions.add(ActionParser.parseAction(serializedAction)); + openActions.add(ActionParser.parse(serializedAction)); } } From edc682d87e6c381485a5e6c922e3a544bca9a38a Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 3 Aug 2020 21:14:07 +0200 Subject: [PATCH 156/213] Refactor configuration --- .../config/CustomPlaceholders.java | 2 +- .../config/framework/Config.java | 14 +- .../config/framework/ConfigLoader.java | 32 +-- .../config/framework/ConfigPath.java | 21 ++ .../config/framework/ConfigSection.java | 195 +++++++++++------- .../config/framework/ConfigValue.java | 65 ++++++ .../config/framework/ConfigValueType.java | 148 +++++++++++++ .../exception/ConfigLoadException.java | 4 + .../exception/ConfigValueException.java | 2 +- .../exception/ConverterCastException.java | 23 +++ .../InvalidConfigValueException.java | 23 +++ .../MissingConfigValueException.java | 23 +++ .../config/framework/mapped/ConfigMapper.java | 76 ++++--- .../framework/mapped/MappedConfigLoader.java | 5 +- .../config/framework/mapped/MappedField.java | 40 ++-- .../mapped/converter/BooleanConverter.java | 11 +- .../framework/mapped/converter/Converter.java | 26 ++- .../mapped/converter/DoubleConverter.java | 11 +- .../mapped/converter/IntegerConverter.java | 11 +- .../mapped/converter/ListConverter.java | 19 +- .../mapped/converter/StringConverter.java | 11 +- .../upgrade/MenuNodeExpandUpgradeTask.java | 36 ++-- .../upgrade/PlaceholdersYamlUpgradeTask.java | 2 +- .../legacy/upgrade/SettingsUpgradeTask.java | 4 +- .../chestcommands/logging/ErrorMessages.java | 13 ++ .../parsing/icon/AttributeType.java | 70 +++---- .../parsing/icon/IconSettings.java | 6 +- .../parsing/menu/MenuParser.java | 17 +- 28 files changed, 648 insertions(+), 262 deletions(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigPath.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigValue.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigValueType.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConverterCastException.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/InvalidConfigValueException.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/MissingConfigValueException.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java index cb3a73a..53a4b3f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java @@ -30,7 +30,7 @@ public class CustomPlaceholders { public void load(Config config, ErrorCollector errorCollector) { placeholders.clear(); - for (String placeholder : config.getKeys(false)) { + for (String placeholder : config.getKeys()) { String replacement = Colors.addColors(config.getString(placeholder)); if (placeholder.length() == 0) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java index f7c7e94..7a03da6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java @@ -14,6 +14,7 @@ */ package me.filoghost.chestcommands.config.framework; +import me.filoghost.chestcommands.util.Preconditions; import org.bukkit.configuration.file.YamlConfiguration; import java.nio.file.Path; @@ -21,20 +22,21 @@ import java.nio.file.Path; public class Config extends ConfigSection { private final YamlConfiguration yaml; - private final Path sourceFilePath; + private final Path sourceFile; - public Config(Path sourceFilePath) { - this(new YamlConfiguration(), sourceFilePath); + public Config(Path sourceFile) { + this(new YamlConfiguration(), sourceFile); } - public Config(YamlConfiguration yaml, Path sourceFilePath) { + public Config(YamlConfiguration yaml, Path sourceFile) { super(yaml); + Preconditions.notNull(sourceFile, "sourceFile"); this.yaml = yaml; - this.sourceFilePath = sourceFilePath; + this.sourceFile = sourceFile; } public Path getSourceFile() { - return sourceFilePath; + return sourceFile; } public String saveToString() { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java index d447800..151d1c4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java @@ -36,13 +36,13 @@ import java.util.stream.StreamSupport; public class ConfigLoader { private final Path rootDataFolder; - private final Path filePath; + private final Path file; - public ConfigLoader(Path rootDataFolder, Path filePath) { - Preconditions.checkArgument(filePath.startsWith(rootDataFolder), "file \"" + filePath + "\" must be inside \"" + rootDataFolder + "\""); + public ConfigLoader(Path rootDataFolder, Path file) { + Preconditions.checkArgument(file.startsWith(rootDataFolder), "file \"" + file + "\" must be inside \"" + rootDataFolder + "\""); this.rootDataFolder = rootDataFolder; - this.filePath = filePath; + this.file = file; } public Config init() throws ConfigSaveException, ConfigLoadException { @@ -57,14 +57,14 @@ public class ConfigLoader { createParentDirectory(); - Path relativeConfigPath = rootDataFolder.relativize(filePath); + Path relativeConfigPath = rootDataFolder.relativize(file); String internalJarPath = toInternalJarPath(relativeConfigPath); try (InputStream defaultFile = getInternalResource(internalJarPath)) { if (defaultFile != null) { - Files.copy(defaultFile, filePath); + Files.copy(defaultFile, file); } else { - Files.createFile(filePath); + Files.createFile(file); } } catch (IOException e) { throw new ConfigSaveException(ErrorMessages.Config.createDefaultIOException, e); @@ -92,15 +92,15 @@ public class ConfigLoader { } public boolean fileExists() { - return Files.isRegularFile(filePath); + return Files.isRegularFile(file); } public Config load() throws ConfigLoadException { - Preconditions.checkState(fileExists(), "\"" + filePath + "\" doesn't exist or is not a regular file"); + Preconditions.checkState(fileExists(), "\"" + file + "\" doesn't exist or is not a regular file"); YamlConfiguration yaml = new YamlConfiguration(); - try (BufferedReader reader = Files.newBufferedReader(filePath)) { + try (BufferedReader reader = Files.newBufferedReader(file)) { yaml.load(reader); } catch (IOException e) { throw new ConfigLoadException(ErrorMessages.Config.readIOException, e); @@ -108,7 +108,7 @@ public class ConfigLoader { throw new ConfigSyntaxException(ErrorMessages.Config.invalidYamlSyntax, e); } - return new Config(yaml, filePath); + return new Config(yaml, file); } public void save(Config config) throws ConfigSaveException { @@ -116,7 +116,7 @@ public class ConfigLoader { String data = config.saveToString(); - try (BufferedWriter writer = Files.newBufferedWriter(filePath)) { + try (BufferedWriter writer = Files.newBufferedWriter(file)) { writer.write(data); } catch (IOException e) { throw new ConfigSaveException(ErrorMessages.Config.writeDataIOException, e); @@ -124,17 +124,17 @@ public class ConfigLoader { } private void createParentDirectory() throws ConfigSaveException { - if (filePath.getParent() != null) { + if (file.getParent() != null) { try { - Files.createDirectories(filePath.getParent()); + Files.createDirectories(file.getParent()); } catch (IOException e) { - throw new ConfigSaveException(ErrorMessages.Config.createParentFolderIOException(filePath.getParent()), e); + throw new ConfigSaveException(ErrorMessages.Config.createParentFolderIOException(file.getParent()), e); } } } public Path getFile() { - return filePath; + return file; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigPath.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigPath.java new file mode 100644 index 0000000..4ae8d9e --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigPath.java @@ -0,0 +1,21 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework; + +public interface ConfigPath { + + String getConfigPath(); + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java index ecdb9fd..42dedec 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java @@ -14,11 +14,11 @@ */ package me.filoghost.chestcommands.config.framework; -import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.config.framework.exception.InvalidConfigValueException; +import me.filoghost.chestcommands.config.framework.exception.MissingConfigValueException; +import me.filoghost.chestcommands.util.Preconditions; import org.bukkit.configuration.ConfigurationSection; -import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -27,127 +27,170 @@ public class ConfigSection { private final ConfigurationSection yamlSection; public ConfigSection(ConfigurationSection yamlSection) { + Preconditions.notNull(yamlSection, "yamlSection"); this.yamlSection = yamlSection; } - public String getRequiredString(String path) throws ConfigValueException { - Object value = getRequired(path); - return value.toString(); + public ConfigValue get(String path) { + return ConfigValue.fromRawConfigValue(getRawValue(path)); } - public short getRequiredShort(String path) throws ConfigValueException { - return (short) getRequiredInt(path); + public T get(String path, ConfigValueType configValueType) { + return getOrDefault(path, configValueType, null); } - public int getRequiredInt(String path) throws ConfigValueException { - Number value = cast(getRequired(path), Number.class, ErrorMessages.Config.valueNotNumber); - return value.intValue(); + public T getRequired(String path, ConfigValueType configValueType) throws MissingConfigValueException, InvalidConfigValueException { + return configValueType.fromConfigValueRequired(getRawValue(path)); } - public double getRequiredDouble(String path) throws ConfigValueException { - Number value = cast(getRequired(path), Number.class, ErrorMessages.Config.valueNotNumber); - return value.doubleValue(); + public T getOrDefault(String path, ConfigValueType configValueType, T defaultValue) { + return configValueType.fromConfigValueOrDefault(getRawValue(path), defaultValue); } - public boolean getRequiredBoolean(String path) throws ConfigValueException { - Boolean value = cast(getRequired(path), Boolean.class, ErrorMessages.Config.valueNotBoolean); - return value; + public void set(String path, ConfigValue configValue) { + setRawValue(path, configValue.getRawConfigValue()); } - public List getRequiredStringList(String path) throws ConfigValueException { - List value = cast(getRequired(path), List.class, ErrorMessages.Config.valueNotList); - List result = new ArrayList<>(); - - for (Object object : value) { - if (object instanceof String || isPrimitiveWrapper(object)) { - result.add(object.toString()); - } - } - - return result; + public void set(String path, ConfigValueType configValueType, T value) { + setRawValue(path, configValueType.toConfigValue(value)); } - private Object getRequired(String path) throws ConfigValueException { - Object value = yamlSection.get(path, null); - if (value == null) { - throw new ConfigValueException(ErrorMessages.Config.valueNotSet); - } - return value; + public boolean contains(String path) { + return getRawValue(path) != null; } - private T cast(Object obj, Class castType, String errorMessage) throws ConfigValueException { - if (obj != null && !castType.isInstance(obj)) { - throw new ConfigValueException(errorMessage); - } - - return castType.cast(obj); + public void remove(String path) { + setRawValue(path, null); } - /* - * Delegate methods below - */ - - public Set getKeys(boolean deep) { - return yamlSection.getKeys(deep); + public ConfigSection createSection(String path) { + return new ConfigSection(yamlSection.createSection(path)); } - public boolean isSet(String path) { - return yamlSection.isSet(path); + public Set getKeys() { + return yamlSection.getKeys(false); } - public void set(String path, Object value) { + private Object getRawValue(String path) { + return yamlSection.get(path, null); + } + + private void setRawValue(String path, Object value) { yamlSection.set(path, value); } - public String getString(String path) { - return yamlSection.getString(path); + protected ConfigurationSection getInternalYamlSection() { + return yamlSection; } - public int getInt(String path) { - return yamlSection.getInt(path); + /* + * Convenience getRequired{TYPE} alias methods + */ + + public String getRequiredString(String path) throws MissingConfigValueException, InvalidConfigValueException { + return getRequired(path, ConfigValueType.STRING); + } + + public boolean getRequiredBoolean(String path) throws MissingConfigValueException, InvalidConfigValueException { + return getRequired(path, ConfigValueType.BOOLEAN); + } + + public int getRequiredInt(String path) throws MissingConfigValueException, InvalidConfigValueException { + return getRequired(path, ConfigValueType.INTEGER); + } + + public double getRequiredDouble(String path) throws MissingConfigValueException, InvalidConfigValueException { + return getRequired(path, ConfigValueType.DOUBLE); + } + + public List getRequiredStringList(String path) throws MissingConfigValueException, InvalidConfigValueException { + return getRequired(path, ConfigValueType.STRING_LIST); + } + + public ConfigSection getRequiredConfigSection(String path) throws MissingConfigValueException, InvalidConfigValueException { + return getRequired(path, ConfigValueType.CONFIG_SECTION); + } + + /* + * Convenience get{TYPE} (without defaults) alias methods + */ + public String getString(String path) { + return getOrDefault(path, ConfigValueType.STRING, null); } public boolean getBoolean(String path) { - return yamlSection.getBoolean(path); + return getOrDefault(path, ConfigValueType.BOOLEAN, false); + } + + public int getInt(String path) { + return getOrDefault(path, ConfigValueType.INTEGER, 0); } public double getDouble(String path) { - return yamlSection.getDouble(path); + return getOrDefault(path, ConfigValueType.DOUBLE, 0.0); } public List getStringList(String path) { - return yamlSection.getStringList(path); - } - - public List getIntegerList(String path) { - return yamlSection.getIntegerList(path); - } - - public Object get(String path) { - return yamlSection.get(path); + return getOrDefault(path, ConfigValueType.STRING_LIST, null); } public ConfigSection getConfigSection(String path) { - return new ConfigSection(yamlSection.getConfigurationSection(path)); + return getOrDefault(path, ConfigValueType.CONFIG_SECTION, null); } - public boolean isString(String path) { - return yamlSection.isString(path); + /* + * Convenience get{TYPE} (with defaults) alias methods + */ + public String getString(String path, String defaultValue) { + return getOrDefault(path, ConfigValueType.STRING, defaultValue); } - public boolean isConfigSection(String path) { - return yamlSection.isConfigurationSection(path); + public boolean getBoolean(String path, boolean defaultValue) { + return getOrDefault(path, ConfigValueType.BOOLEAN, defaultValue); } - public boolean isList(String path) { - return yamlSection.isList(path); + public int getInt(String path, int defaultValue) { + return getOrDefault(path, ConfigValueType.INTEGER, defaultValue); } - private boolean isPrimitiveWrapper(Object input) { - return input instanceof Integer || input instanceof Boolean || - input instanceof Character || input instanceof Byte || - input instanceof Short || input instanceof Double || - input instanceof Long || input instanceof Float; + public double getDouble(String path, double defaultValue) { + return getOrDefault(path, ConfigValueType.DOUBLE, defaultValue); + } + + public List getStringList(String path, List defaultValue) { + return getOrDefault(path, ConfigValueType.STRING_LIST, defaultValue); + } + + public ConfigSection getConfigSection(String path, ConfigSection defaultValue) { + return getOrDefault(path, ConfigValueType.CONFIG_SECTION, defaultValue); + } + + + /* + * Convenience set{TYPE} alias methods + */ + public void setString(String path, String value) { + set(path, ConfigValueType.STRING, value); + } + + public void setBoolean(String path, boolean value) { + set(path, ConfigValueType.BOOLEAN, value); + } + + public void setInt(String path, int value) { + set(path, ConfigValueType.INTEGER, value); + } + + public void setDouble(String path, double value) { + set(path, ConfigValueType.DOUBLE, value); + } + + public void setStringList(String path, List value) { + set(path, ConfigValueType.STRING_LIST, value); + } + + public void setConfigSection(String path, ConfigSection value) { + set(path, ConfigValueType.CONFIG_SECTION, value); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigValue.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigValue.java new file mode 100644 index 0000000..7ccd581 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigValue.java @@ -0,0 +1,65 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework; + +import me.filoghost.chestcommands.config.framework.exception.InvalidConfigValueException; +import me.filoghost.chestcommands.config.framework.exception.MissingConfigValueException; +import me.filoghost.chestcommands.util.Preconditions; + +public class ConfigValue { + + private static final ConfigValue EMPTY = new ConfigValue(null); + + private final Object rawConfigValue; + + public static ConfigValue of(ConfigValueType valueType, T value) { + Preconditions.notNull(valueType, "valueType"); + Preconditions.notNull(value, "value"); + return new ConfigValue(valueType.toConfigValue(value)); + } + + protected static ConfigValue fromRawConfigValue(Object rawConfigValue) { + if (rawConfigValue != null) { + return new ConfigValue(rawConfigValue); + } else { + return EMPTY; + } + } + + private ConfigValue(Object rawConfigValue) { + this.rawConfigValue = rawConfigValue; + } + + protected Object getRawConfigValue() { + return rawConfigValue; + } + + public T as(ConfigValueType valueType) { + return valueType.fromConfigValueOrDefault(rawConfigValue, null); + } + + public T asRequired(ConfigValueType valueType) throws MissingConfigValueException, InvalidConfigValueException { + return valueType.fromConfigValueRequired(rawConfigValue); + } + + public T asOrDefault(ConfigValueType valueType, T defaultValue) { + return valueType.fromConfigValueOrDefault(rawConfigValue, defaultValue); + } + + public boolean isValidAs(ConfigValueType configValueType) { + return configValueType.isValidConfigValue(rawConfigValue); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigValueType.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigValueType.java new file mode 100644 index 0000000..26c89a3 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigValueType.java @@ -0,0 +1,148 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework; + +import me.filoghost.chestcommands.config.framework.exception.InvalidConfigValueException; +import me.filoghost.chestcommands.config.framework.exception.MissingConfigValueException; +import me.filoghost.chestcommands.logging.ErrorMessages; +import org.bukkit.configuration.ConfigurationSection; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; +import java.util.function.Predicate; + +public class ConfigValueType { + + public static final ConfigValueType STRING = new ConfigValueType<>( + (Object value) -> value instanceof String || value instanceof Number || value instanceof Boolean || value instanceof Character, + (Object value) -> value.toString(), + (String value) -> value, + ErrorMessages.Config.valueNotString + ); + + public static final ConfigValueType BOOLEAN = new ConfigValueType<>( + (Object value) -> value instanceof Boolean, + (Object value) -> (Boolean) value, + (Boolean value) -> value, + ErrorMessages.Config.valueNotBoolean + ); + + public static final ConfigValueType LONG = newNumberType(Number::longValue); + public static final ConfigValueType INTEGER = newNumberType(Number::intValue); + public static final ConfigValueType SHORT = newNumberType(Number::shortValue); + public static final ConfigValueType BYTE = newNumberType(Number::byteValue); + public static final ConfigValueType DOUBLE = newNumberType(Number::doubleValue); + public static final ConfigValueType FLOAT = newNumberType(Number::floatValue); + + public static final ConfigValueType> STRING_LIST = newListType(STRING); + public static final ConfigValueType> INTEGER_LIST = newListType(INTEGER); + + public static final ConfigValueType> LIST = new ConfigValueType<>( + (Object value) -> value instanceof List, + (Object value) -> (List) value, + (List value) -> value, + ErrorMessages.Config.valueNotList + ); + + public static final ConfigValueType CONFIG_SECTION = new ConfigValueType<>( + (Object value) -> value instanceof ConfigurationSection, + (Object value) -> new ConfigSection((ConfigurationSection) value), + (ConfigSection value) -> value.getInternalYamlSection(), + ErrorMessages.Config.valueNotSection + ); + + private final Predicate isValidConfigValueFunction; + private final Function fromConfigValueFunction; + private final Function toConfigValueFunction; + private final String notConvertibleErrorMessage; + + public ConfigValueType( + Predicate isConvertibleFunction, + Function fromConfigValueFunction, + Function toConfigValueFunction, + String notConvertibleErrorMessage) { + this.isValidConfigValueFunction = isConvertibleFunction; + this.fromConfigValueFunction = fromConfigValueFunction; + this.toConfigValueFunction = toConfigValueFunction; + this.notConvertibleErrorMessage = notConvertibleErrorMessage; + } + + protected boolean isValidConfigValue(Object rawConfigValue) { + return rawConfigValue != null && isValidConfigValueFunction.test(rawConfigValue); + } + + protected T fromConfigValueRequired(Object rawConfigValue) throws MissingConfigValueException, InvalidConfigValueException { + if (rawConfigValue == null) { + throw new MissingConfigValueException(ErrorMessages.Config.valueNotSet); + } + + if (isValidConfigValueFunction.test(rawConfigValue)) { + return fromConfigValueFunction.apply(rawConfigValue); + } else { + throw new InvalidConfigValueException(notConvertibleErrorMessage); + } + } + + protected T fromConfigValueOrDefault(Object rawConfigValue, T defaultValue) { + if (rawConfigValue == null) { + return defaultValue; + } + + if (isValidConfigValueFunction.test(rawConfigValue)) { + return fromConfigValueFunction.apply(rawConfigValue); + } else { + return defaultValue; + } + } + + protected Object toConfigValue(T value) { + if (value != null) { + return toConfigValueFunction.apply(value); + } else { + return null; + } + } + + + private static ConfigValueType newNumberType(Function toTypeFunction) { + return new ConfigValueType<>( + (Object value) -> value instanceof Number, + (Object value) -> toTypeFunction.apply((Number) value), + (T value) -> value, + ErrorMessages.Config.valueNotNumber + ); + } + + private static ConfigValueType> newListType(ConfigValueType elementType) { + return new ConfigValueType<>( + (Object value) -> value instanceof List, + (Object value) -> { + List result = new ArrayList<>(); + + for (Object element : ((List) value)) { + if (elementType.isValidConfigValueFunction.test(element)) { + result.add(elementType.fromConfigValueFunction.apply(element)); + } + } + + return result; + }, + (List value) -> value, + ErrorMessages.Config.valueNotList + ); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigLoadException.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigLoadException.java index b99446f..92b9185 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigLoadException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigLoadException.java @@ -20,4 +20,8 @@ public class ConfigLoadException extends ConfigException { super(message, cause); } + public ConfigLoadException(String message) { + super(message); + } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigValueException.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigValueException.java index b37ed87..6b37c16 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigValueException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigValueException.java @@ -14,7 +14,7 @@ */ package me.filoghost.chestcommands.config.framework.exception; -public class ConfigValueException extends ConfigException { +public abstract class ConfigValueException extends ConfigException { public ConfigValueException(String message) { super(message); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConverterCastException.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConverterCastException.java new file mode 100644 index 0000000..6ce637d --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConverterCastException.java @@ -0,0 +1,23 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework.exception; + +public class ConverterCastException extends ConfigException { + + public ConverterCastException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/InvalidConfigValueException.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/InvalidConfigValueException.java new file mode 100644 index 0000000..24840fe --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/InvalidConfigValueException.java @@ -0,0 +1,23 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework.exception; + +public class InvalidConfigValueException extends ConfigValueException { + + public InvalidConfigValueException(String message) { + super(message); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/MissingConfigValueException.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/MissingConfigValueException.java new file mode 100644 index 0000000..1020a43 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/MissingConfigValueException.java @@ -0,0 +1,23 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework.exception; + +public class MissingConfigValueException extends ConfigValueException { + + public MissingConfigValueException(String message) { + super(message); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/ConfigMapper.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/ConfigMapper.java index fa81edb..d10fe88 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/ConfigMapper.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/ConfigMapper.java @@ -16,6 +16,10 @@ package me.filoghost.chestcommands.config.framework.mapped; import com.google.common.collect.ImmutableList; import me.filoghost.chestcommands.config.framework.ConfigSection; +import me.filoghost.chestcommands.config.framework.ConfigValue; +import me.filoghost.chestcommands.config.framework.ConfigValueType; +import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; +import me.filoghost.chestcommands.config.framework.exception.ConverterCastException; import me.filoghost.chestcommands.config.framework.mapped.converter.BooleanConverter; import me.filoghost.chestcommands.config.framework.mapped.converter.Converter; import me.filoghost.chestcommands.config.framework.mapped.converter.DoubleConverter; @@ -24,17 +28,17 @@ import me.filoghost.chestcommands.config.framework.mapped.converter.ListConverte import me.filoghost.chestcommands.config.framework.mapped.converter.StringConverter; import me.filoghost.chestcommands.config.framework.mapped.modifier.ChatColorsModifier; import me.filoghost.chestcommands.config.framework.mapped.modifier.ValueModifier; +import me.filoghost.chestcommands.logging.ErrorMessages; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.lang.reflect.Type; -import java.util.Arrays; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.stream.Collectors; public class ConfigMapper { @@ -62,17 +66,31 @@ public class ConfigMapper { private List getMappableFields(Class type) throws ReflectiveOperationException { Field[] declaredFields; + List mappedFields = new ArrayList<>(); try { declaredFields = type.getDeclaredFields(); + for (Field field : declaredFields) { + if (isMappable(field)) { + mappedFields.add(new MappedField(field)); + } + } + } catch (Throwable t) { throw new ReflectiveOperationException(t); } - return Arrays.stream(declaredFields) - .filter(this::isMappable) - .map(MappedField::new) - .collect(Collectors.toList()); + return mappedFields; + } + + private boolean isMappable(Field field) { + int modifiers = field.getModifiers(); + boolean includeStatic = field.isAnnotationPresent(IncludeStatic.class) + || field.getDeclaringClass().isAnnotationPresent(IncludeStatic.class); + + return (!Modifier.isStatic(modifiers) || includeStatic) + || !Modifier.isTransient(modifiers) + || !Modifier.isFinal(modifiers); } public Map getFieldValues() throws ReflectiveOperationException { @@ -82,7 +100,7 @@ public class ConfigMapper { Object defaultValue = mappedField.getFromObject(mappedObject); if (defaultValue == null) { - throw new IllegalArgumentException("mapped field \"" + mappedField.getFieldName() + "\" cannot be null by default"); + throw new ReflectiveOperationException(ErrorMessages.Config.mapperFieldCannotBeNull(mappedField)); } mappedFieldValues.put(mappedField, defaultValue); @@ -91,18 +109,35 @@ public class ConfigMapper { return mappedFieldValues; } - public boolean addMissingConfigValues(Map defaultValues) { - boolean modified = false; + public Map toConfigValues(Map fieldValues) throws ConfigLoadException { + Map configValues = new HashMap<>(); - // Add missing values from defaults - for (Entry entry : defaultValues.entrySet()) { + for (Entry entry : fieldValues.entrySet()) { MappedField mappedField = entry.getKey(); Object defaultValue = entry.getValue(); - if (!config.isSet(mappedField.getConfigPath())) { + Converter converter = findConverter(mappedField.getFieldType()); + + try { + configValues.put(mappedField.getConfigPath(), converter.toConfigValue(mappedField, defaultValue)); + } catch (ConverterCastException e) { + throw new ConfigLoadException("error while converting field \"" + mappedField.getFieldName() + "\"", e); + } + } + + return configValues; + } + + public boolean addMissingConfigValues(Map defaultValues) { + boolean modified = false; + + for (Entry entry : defaultValues.entrySet()) { + String path = entry.getKey(); + ConfigValue defaultValue = entry.getValue(); + + if (!config.contains(path)) { modified = true; - Converter converter = findConverter(mappedField.getFieldType()); - converter.setConfigValue(config, mappedField.getConfigPath(), defaultValue); + config.set(path, defaultValue); } } @@ -119,7 +154,8 @@ public class ConfigMapper { Type[] genericTypes = mappedField.getGenericTypes(); Converter converter = findConverter(mappedField.getFieldType()); - Object fieldValue = converter.getFieldValue(config, mappedField.getConfigPath(), genericTypes); + ConfigValueType configValueType = converter.getConfigValueType(genericTypes); + Object fieldValue = config.get(mappedField.getConfigPath(), configValueType); for (Annotation annotation : mappedField.getAnnotations()) { fieldValue = applyValueModifiers(fieldValue, annotation); @@ -144,14 +180,4 @@ public class ConfigMapper { .orElseThrow(() -> new IllegalStateException("cannot find converter for type " + type)); } - private boolean isMappable(Field field) { - int modifiers = field.getModifiers(); - boolean includeStatic = field.isAnnotationPresent(IncludeStatic.class) - || field.getDeclaringClass().isAnnotationPresent(IncludeStatic.class); - - return (!Modifier.isStatic(modifiers) || includeStatic) - || !Modifier.isTransient(modifiers) - || !Modifier.isFinal(modifiers); - } - } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java index f2718af..c40bf83 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java @@ -16,6 +16,7 @@ package me.filoghost.chestcommands.config.framework.mapped; import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.config.framework.ConfigLoader; +import me.filoghost.chestcommands.config.framework.ConfigValue; import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; import me.filoghost.chestcommands.logging.ErrorMessages; @@ -28,7 +29,7 @@ public class MappedConfigLoader { private final ConfigLoader configLoader; private final Supplier mappedObjectConstructor; - private Map defaultValues; + private Map defaultValues; public MappedConfigLoader(Path rootDataFolder, Path configPath, Supplier mappedObjectConstructor) { this.configLoader = new ConfigLoader(rootDataFolder, configPath); @@ -49,7 +50,7 @@ public class MappedConfigLoader { // Extract default values from fields if (defaultValues == null) { try { - defaultValues = mapper.getFieldValues(); + defaultValues = mapper.toConfigValues(mapper.getFieldValues()); } catch (ReflectiveOperationException e) { throw new ConfigLoadException(ErrorMessages.Config.fieldReadError(mappedObject), e); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedField.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedField.java index ef8c1bb..d7ec37c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedField.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedField.java @@ -27,13 +27,32 @@ public class MappedField { private final Field field; private final String configPath; + private final Type[] genericTypes; + private final List annotations; - public MappedField(Field field) { + + public MappedField(Field field) throws ReflectiveOperationException { this.field = field; this.configPath = field.getName() .replace("__", ".") .replace("_", "-"); + + try { + Type genericType = field.getGenericType(); + if (genericType instanceof ParameterizedType) { + this.genericTypes = ((ParameterizedType) genericType).getActualTypeArguments(); + } else { + this.genericTypes = null; + } + + annotations = Stream.concat( + Arrays.stream(field.getDeclaredAnnotations()), + Arrays.stream(field.getDeclaringClass().getDeclaredAnnotations())) + .collect(Collectors.toList()); + } catch (Throwable t) { + throw new ReflectiveOperationException(t); + } } public Object getFromObject(MappedConfig mappedObject) throws ReflectiveOperationException { @@ -54,24 +73,12 @@ public class MappedField { } } - public Type[] getGenericTypes() throws ReflectiveOperationException { - try { - Type genericType = field.getGenericType(); - if (genericType instanceof ParameterizedType) { - return ((ParameterizedType) genericType).getActualTypeArguments(); - } else { - return null; - } - } catch (Throwable t) { - throw new ReflectiveOperationException(t); - } + public Type[] getGenericTypes() { + return genericTypes; } public List getAnnotations() { - return Stream.concat( - Arrays.stream(field.getDeclaredAnnotations()), - Arrays.stream(field.getDeclaringClass().getDeclaredAnnotations())) - .collect(Collectors.toList()); + return annotations; } public String getFieldName() { @@ -85,4 +92,5 @@ public class MappedField { public String getConfigPath() { return configPath; } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/BooleanConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/BooleanConverter.java index 49ff6f1..afaae7f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/BooleanConverter.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/BooleanConverter.java @@ -14,20 +14,15 @@ */ package me.filoghost.chestcommands.config.framework.mapped.converter; -import me.filoghost.chestcommands.config.framework.ConfigSection; +import me.filoghost.chestcommands.config.framework.ConfigValueType; import java.lang.reflect.Type; public class BooleanConverter implements Converter { @Override - public void setConfigValue(ConfigSection config, String path, Object value) { - config.set(path, value); - } - - @Override - public Boolean getFieldValue(ConfigSection config, String path, Type[] parameterizedTypes) { - return config.getBoolean(path); + public ConfigValueType getConfigValueType(Type[] fieldGenericTypes) { + return ConfigValueType.BOOLEAN; } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/Converter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/Converter.java index a6e7185..c7fa213 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/Converter.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/Converter.java @@ -14,16 +14,34 @@ */ package me.filoghost.chestcommands.config.framework.mapped.converter; -import me.filoghost.chestcommands.config.framework.ConfigSection; +import me.filoghost.chestcommands.config.framework.ConfigValue; +import me.filoghost.chestcommands.config.framework.ConfigValueType; +import me.filoghost.chestcommands.config.framework.exception.ConverterCastException; +import me.filoghost.chestcommands.config.framework.mapped.MappedField; +import me.filoghost.chestcommands.logging.ErrorMessages; import java.lang.reflect.Type; public interface Converter { - void setConfigValue(ConfigSection config, String path, Object value); - - Object getFieldValue(ConfigSection config, String path, Type[] genericTypes); + ConfigValueType getConfigValueType(Type[] fieldGenericTypes); boolean matches(Class type); + default ConfigValue toConfigValue(MappedField mappedField, Object value) throws ConverterCastException { + ConfigValueType configValueType = getConfigValueType(mappedField.getGenericTypes()); + + // Assume that ConfigValueType is compatible with the value + return toTypedConfigValue(configValueType, value); + } + + @SuppressWarnings("unchecked") + default ConfigValue toTypedConfigValue(ConfigValueType configValueType, Object value) throws ConverterCastException { + try { + return ConfigValue.of(configValueType, (T) value); + } catch (ClassCastException e) { + throw new ConverterCastException(ErrorMessages.Config.converterFailed(value, this), e); + } + } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/DoubleConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/DoubleConverter.java index 3fa7da3..43ca7ed 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/DoubleConverter.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/DoubleConverter.java @@ -14,20 +14,15 @@ */ package me.filoghost.chestcommands.config.framework.mapped.converter; -import me.filoghost.chestcommands.config.framework.ConfigSection; +import me.filoghost.chestcommands.config.framework.ConfigValueType; import java.lang.reflect.Type; public class DoubleConverter implements Converter { @Override - public void setConfigValue(ConfigSection config, String path, Object value) { - config.set(path, value); - } - - @Override - public Double getFieldValue(ConfigSection config, String path, Type[] parameterizedTypes) { - return config.getDouble(path); + public ConfigValueType getConfigValueType(Type[] fieldGenericTypes) { + return ConfigValueType.DOUBLE; } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/IntegerConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/IntegerConverter.java index b8f0003..5c40369 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/IntegerConverter.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/IntegerConverter.java @@ -14,20 +14,15 @@ */ package me.filoghost.chestcommands.config.framework.mapped.converter; -import me.filoghost.chestcommands.config.framework.ConfigSection; +import me.filoghost.chestcommands.config.framework.ConfigValueType; import java.lang.reflect.Type; public class IntegerConverter implements Converter { @Override - public void setConfigValue(ConfigSection config, String path, Object value) { - config.set(path, value); - } - - @Override - public Integer getFieldValue(ConfigSection config, String path, Type[] parameterizedTypes) { - return config.getInt(path); + public ConfigValueType getConfigValueType(Type[] fieldGenericTypes) { + return ConfigValueType.INTEGER; } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/ListConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/ListConverter.java index 76d9620..3fe2d33 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/ListConverter.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/ListConverter.java @@ -14,7 +14,7 @@ */ package me.filoghost.chestcommands.config.framework.mapped.converter; -import me.filoghost.chestcommands.config.framework.ConfigSection; +import me.filoghost.chestcommands.config.framework.ConfigValueType; import me.filoghost.chestcommands.util.Preconditions; import java.lang.reflect.Type; @@ -23,21 +23,16 @@ import java.util.List; public class ListConverter implements Converter { @Override - public void setConfigValue(ConfigSection config, String path, Object value) { - config.set(path, value); - } + public ConfigValueType getConfigValueType(Type[] fieldGenericTypes) { + Preconditions.notNull(fieldGenericTypes, "fieldGenericTypes"); + Preconditions.checkArgument(fieldGenericTypes.length == 1, "fieldGenericTypes length must be 1"); - @Override - public List getFieldValue(ConfigSection config, String path, Type[] genericTypes) { - Preconditions.notNull(genericTypes, "genericTypes"); - Preconditions.checkArgument(genericTypes.length == 1, "genericTypes length must be 1"); - - Type listType = genericTypes[0]; + Type listType = fieldGenericTypes[0]; if (listType == Integer.class) { - return config.getIntegerList(path); + return ConfigValueType.INTEGER_LIST; } else if (listType == String.class) { - return config.getStringList(path); + return ConfigValueType.STRING_LIST; } else { throw new IllegalArgumentException("unsupported list type: " + listType); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/StringConverter.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/StringConverter.java index a8689a4..acd14ec 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/StringConverter.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/StringConverter.java @@ -14,20 +14,15 @@ */ package me.filoghost.chestcommands.config.framework.mapped.converter; -import me.filoghost.chestcommands.config.framework.ConfigSection; +import me.filoghost.chestcommands.config.framework.ConfigValueType; import java.lang.reflect.Type; public class StringConverter implements Converter { @Override - public void setConfigValue(ConfigSection config, String path, Object value) { - config.set(path, value); - } - - @Override - public String getFieldValue(ConfigSection config, String path, Type[] parameterizedTypes) { - return config.getString(path); + public ConfigValueType getConfigValueType(Type[] fieldGenericTypes) { + return ConfigValueType.STRING; } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java index 6655b00..f3ce3f7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java @@ -18,6 +18,7 @@ import me.filoghost.chestcommands.config.ConfigManager; import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.config.framework.ConfigSection; +import me.filoghost.chestcommands.config.framework.ConfigValueType; import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; import me.filoghost.chestcommands.parsing.icon.AttributeType; @@ -56,13 +57,12 @@ public class MenuNodeExpandUpgradeTask extends UpgradeTask { Config menuConfig = menuConfigLoader.load(); menuConfig.setHeader(null); - for (String key : menuConfig.getKeys(false)) { - if (!menuConfig.isConfigSection(key)) { + for (String key : menuConfig.getKeys()) { + ConfigSection section = menuConfig.getConfigSection(key); + if (section == null) { continue; } - ConfigSection section = menuConfig.getConfigSection(key); - if (key.equals(MenuSettingsNode.ROOT_SECTION)) { upgradeMenuSettings(section); } else { @@ -101,45 +101,43 @@ public class MenuNodeExpandUpgradeTask extends UpgradeTask { if (material.contains(",")) { String[] parts = Strings.trimmedSplit(material, ",", 2); - if (!section.isSet(AttributeType.AMOUNT.getAttributeName())) { + if (!section.contains(AttributeType.AMOUNT.getAttributeName())) { try { - section.set(AttributeType.AMOUNT.getAttributeName(), Integer.parseInt(parts[1])); + section.setInt(AttributeType.AMOUNT.getAttributeName(), Integer.parseInt(parts[1])); } catch (NumberFormatException e) { - section.set(AttributeType.AMOUNT.getAttributeName(), parts[1]); + section.setString(AttributeType.AMOUNT.getAttributeName(), parts[1]); } } material = parts[0]; - section.set(AttributeType.MATERIAL.getAttributeName(), material); + section.setString(AttributeType.MATERIAL.getAttributeName(), material); setSaveRequired(); } if (material.contains(":")) { String[] parts = Strings.trimmedSplit(material, ":", 2); - if (!section.isSet(AttributeType.DURABILITY.getAttributeName())) { + if (!section.contains(AttributeType.DURABILITY.getAttributeName())) { try { - section.set(AttributeType.DURABILITY.getAttributeName(), Integer.parseInt(parts[1])); + section.setInt(AttributeType.DURABILITY.getAttributeName(), Integer.parseInt(parts[1])); } catch (NumberFormatException e) { - section.set(AttributeType.DURABILITY.getAttributeName(), parts[1]); + section.setString(AttributeType.DURABILITY.getAttributeName(), parts[1]); } } material = parts[0]; - section.set(AttributeType.MATERIAL.getAttributeName(), material); + section.setString(AttributeType.MATERIAL.getAttributeName(), material); setSaveRequired(); } } private void expandInlineList(ConfigSection config, String node, String separator) { - if (config.isSet(node)) { - if (config.isString(node)) { - config.set(node, splitListElements(config.getString(node), separator)); - setSaveRequired(); - } + if (config.get(node).isValidAs(ConfigValueType.STRING)) { + config.setStringList(node, splitListElements(config.getString(node), separator)); + setSaveRequired(); } } private void expandSingletonList(ConfigSection config, String node) { - if (config.isSet(node) && !config.isList(node)) { - config.set(node, Collections.singletonList(config.get(node))); + if (config.get(node).isValidAs(ConfigValueType.STRING)) { + config.setStringList(node, Collections.singletonList(config.getString(node))); setSaveRequired(); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgradeTask.java index 06dc4a0..13e0e27 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgradeTask.java @@ -79,7 +79,7 @@ public class PlaceholdersYamlUpgradeTask extends UpgradeTask { String placeholder = unquote(parts[0]); String replacement = StringEscapeUtils.unescapeJava(unquote(parts[1])); - newPlaceholdersConfig.set(placeholder, replacement); + newPlaceholdersConfig.setString(placeholder, replacement); setSaveRequired(); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgradeTask.java index f26663d..e89739b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgradeTask.java @@ -56,8 +56,8 @@ public class SettingsUpgradeTask extends UpgradeTask { } private void removeNode(Config config, String node) { - if (config.isSet(node)) { - config.set(node, null); + if (config.contains(node)) { + config.remove(node); setSaveRequired(); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java index 5cd0703..9e57f59 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java @@ -16,6 +16,8 @@ package me.filoghost.chestcommands.logging; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.config.framework.mapped.MappedConfig; +import me.filoghost.chestcommands.config.framework.mapped.MappedField; +import me.filoghost.chestcommands.config.framework.mapped.converter.Converter; import me.filoghost.chestcommands.parsing.icon.AttributeType; import me.filoghost.chestcommands.parsing.icon.IconSettings; @@ -35,6 +37,8 @@ public class ErrorMessages { public static final String valueNotList = "value is not a list"; public static final String valueNotBoolean = "value is not a boolean"; public static final String valueNotNumber = "value is not a number"; + public static final String valueNotString = "value is not a string"; + public static final String valueNotSection = "value is not a configuration section"; public static String menuListIOException(Path menuFolder) { return "couldn't fetch menu files inside the folder \"" + menuFolder + "\""; @@ -67,6 +71,15 @@ public class ErrorMessages { public static String fieldInjectError(MappedConfig mappedConfig) { return "couldn't inject fields values in class \"" + mappedConfig.getClass() + "\""; } + + public static String mapperFieldCannotBeNull(MappedField mappedField) { + return "mapped field \"" + mappedField.getFieldName() + "\" cannot be null by default"; + } + + public static String converterFailed(Object value, Converter converter) { + return "value of type \"" + value.getClass() + "\" couldn't be converted by \"" + converter.getClass() + "\""; + } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java index 4eb3fcd..ce2c980 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java @@ -14,7 +14,8 @@ */ package me.filoghost.chestcommands.parsing.icon; -import me.filoghost.chestcommands.config.framework.ConfigSection; +import me.filoghost.chestcommands.config.framework.ConfigValue; +import me.filoghost.chestcommands.config.framework.ConfigValueType; import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.chestcommands.parsing.attribute.ActionsAttribute; @@ -41,32 +42,31 @@ import me.filoghost.chestcommands.parsing.attribute.SkullOwnerAttribute; import me.filoghost.chestcommands.parsing.attribute.ViewPermissionAttribute; import java.util.HashMap; -import java.util.List; import java.util.Map; public enum AttributeType { - POSITION_X("POSITION-X", ValueExtractor.INT, PositionAttribute::new), - POSITION_Y("POSITION-Y", ValueExtractor.INT, PositionAttribute::new), - MATERIAL("MATERIAL", ValueExtractor.STRING, MaterialAttribute::new), - DURABILITY("DURABILITY", ValueExtractor.SHORT, DurabilityAttribute::new), - AMOUNT("AMOUNT", ValueExtractor.INT, AmountAttribute::new), - NAME("NAME", ValueExtractor.STRING, NameAttribute::new), - LORE("LORE", ValueExtractor.STRING_LIST, LoreAttribute::new), - NBT_DATA("NBT-DATA", ValueExtractor.STRING, NBTDataAttribute::new), - LEATHER_COLOR("COLOR", ValueExtractor.STRING, LeatherColorAttribute::new), - SKULL_OWNER("SKULL-OWNER", ValueExtractor.STRING, SkullOwnerAttribute::new), - BANNER_COLOR("BANNER-COLOR", ValueExtractor.STRING, BannerColorAttribute::new), - BANNER_PATTERNS("BANNER-PATTERNS", ValueExtractor.STRING_LIST, BannerPatternsAttribute::new), - PRICE("PRICE", ValueExtractor.DOUBLE, PriceAttribute::new), - EXP_LEVELS("LEVELS", ValueExtractor.INT, ExpLevelsAttribute::new), - CLICK_PERMISSION("PERMISSION", ValueExtractor.STRING, ClickPermissionAttribute::new), - CLICK_PERMISSION_MESSAGE("PERMISSION-MESSAGE", ValueExtractor.STRING, ClickPermissionMessageAttribute::new), - VIEW_PERMISSION("VIEW-PERMISSION", ValueExtractor.STRING, ViewPermissionAttribute::new), - KEEP_OPEN("KEEP-OPEN", ValueExtractor.BOOLEAN, KeepOpenAttribute::new), - ACTIONS("ACTIONS", ValueExtractor.STRING_LIST, ActionsAttribute::new), - ENCHANTMENTS("ENCHANTMENTS", ValueExtractor.STRING_LIST, EnchantmentsAttribute::new), - REQUIRED_ITEMS("REQUIRED-ITEMS", ValueExtractor.STRING_LIST, RequiredItemsAttribute::new); + POSITION_X("POSITION-X", ConfigValueType.INTEGER, PositionAttribute::new), + POSITION_Y("POSITION-Y", ConfigValueType.INTEGER, PositionAttribute::new), + MATERIAL("MATERIAL", ConfigValueType.STRING, MaterialAttribute::new), + DURABILITY("DURABILITY", ConfigValueType.SHORT, DurabilityAttribute::new), + AMOUNT("AMOUNT", ConfigValueType.INTEGER, AmountAttribute::new), + NAME("NAME", ConfigValueType.STRING, NameAttribute::new), + LORE("LORE", ConfigValueType.STRING_LIST, LoreAttribute::new), + NBT_DATA("NBT-DATA", ConfigValueType.STRING, NBTDataAttribute::new), + LEATHER_COLOR("COLOR", ConfigValueType.STRING, LeatherColorAttribute::new), + SKULL_OWNER("SKULL-OWNER", ConfigValueType.STRING, SkullOwnerAttribute::new), + BANNER_COLOR("BANNER-COLOR", ConfigValueType.STRING, BannerColorAttribute::new), + BANNER_PATTERNS("BANNER-PATTERNS", ConfigValueType.STRING_LIST, BannerPatternsAttribute::new), + PRICE("PRICE", ConfigValueType.DOUBLE, PriceAttribute::new), + EXP_LEVELS("LEVELS", ConfigValueType.INTEGER, ExpLevelsAttribute::new), + CLICK_PERMISSION("PERMISSION", ConfigValueType.STRING, ClickPermissionAttribute::new), + CLICK_PERMISSION_MESSAGE("PERMISSION-MESSAGE", ConfigValueType.STRING, ClickPermissionMessageAttribute::new), + VIEW_PERMISSION("VIEW-PERMISSION", ConfigValueType.STRING, ViewPermissionAttribute::new), + KEEP_OPEN("KEEP-OPEN", ConfigValueType.BOOLEAN, KeepOpenAttribute::new), + ACTIONS("ACTIONS", ConfigValueType.STRING_LIST, ActionsAttribute::new), + ENCHANTMENTS("ENCHANTMENTS", ConfigValueType.STRING_LIST, EnchantmentsAttribute::new), + REQUIRED_ITEMS("REQUIRED-ITEMS", ConfigValueType.STRING_LIST, RequiredItemsAttribute::new); private static final Map parsersByAttributeName; static { @@ -79,11 +79,10 @@ public enum AttributeType { private final String attributeName; private final AttributeParser attributeParser; - AttributeType(String attributeName, ValueExtractor valueExtractor, AttributeFactory attributeFactory) { + AttributeType(String attributeName, ConfigValueType configValueType, AttributeFactory attributeFactory) { this.attributeName = attributeName; - this.attributeParser = (ConfigSection config, String node, AttributeErrorHandler errorHandler) -> { - V configValue = valueExtractor.getValue(config, node); - return attributeFactory.create(configValue, errorHandler); + this.attributeParser = (ConfigValue configValue, AttributeErrorHandler errorHandler) -> { + return attributeFactory.create(configValue.asRequired(configValueType), errorHandler); }; } @@ -100,21 +99,6 @@ public enum AttributeType { } - @FunctionalInterface - private interface ValueExtractor { - - V getValue(ConfigSection config, String key) throws ConfigValueException; - - ValueExtractor INT = ConfigSection::getRequiredInt; - ValueExtractor DOUBLE = ConfigSection::getRequiredDouble; - ValueExtractor SHORT = ConfigSection::getRequiredShort; - ValueExtractor BOOLEAN = ConfigSection::getRequiredBoolean; - ValueExtractor STRING = ConfigSection::getRequiredString; - ValueExtractor> STRING_LIST = ConfigSection::getRequiredStringList; - - } - - @FunctionalInterface private interface AttributeFactory { @@ -126,7 +110,7 @@ public enum AttributeType { @FunctionalInterface public interface AttributeParser { - IconAttribute parse(ConfigSection config, String node, AttributeErrorHandler errorHandler) throws ParseException, ConfigValueException; + IconAttribute parse(ConfigValue configValue, AttributeErrorHandler errorHandler) throws ParseException, ConfigValueException; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java index 5479df7..41461cd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java @@ -15,6 +15,7 @@ package me.filoghost.chestcommands.parsing.icon; import me.filoghost.chestcommands.config.framework.ConfigSection; +import me.filoghost.chestcommands.config.framework.ConfigValue; import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.logging.ErrorMessages; @@ -58,7 +59,7 @@ public class IconSettings { } public void loadFrom(ConfigSection config, ErrorCollector errorCollector) { - for (String attributeName : config.getKeys(false)) { + for (String attributeName : config.getKeys()) { try { AttributeType attributeType = AttributeType.fromAttributeName(attributeName); if (attributeType == null) { @@ -69,7 +70,8 @@ public class IconSettings { errorCollector.add(ErrorMessages.Menu.invalidAttributeListElement(this, attributeName, listElement), e); }; - IconAttribute iconAttribute = attributeType.getParser().parse(config, attributeName, errorHandler); + ConfigValue configValue = config.get(attributeName); + IconAttribute iconAttribute = attributeType.getParser().parse(configValue, errorHandler); attributes.put(attributeType, iconAttribute); } catch (ParseException | ConfigValueException e) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index ca0cf7e..245ae09 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -18,6 +18,7 @@ import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.config.framework.ConfigSection; import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; +import me.filoghost.chestcommands.config.framework.exception.MissingConfigValueException; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.menu.InternalIconMenu; import me.filoghost.chestcommands.parsing.ActionParser; @@ -104,7 +105,7 @@ public class MenuParser { } } catch (ConfigValueException e) { title = ChatColor.DARK_RED + "No name set"; - errorCollector.add(ErrorMessages.Menu.missingSetting(config.getSourceFile(), MenuSettingsNode.NAME)); + addMenuSettingError(errorCollector, config, MenuSettingsNode.NAME, e); } int rows; @@ -115,7 +116,7 @@ public class MenuParser { } } catch (ConfigValueException e) { rows = 6; // Defaults to 6 rows - errorCollector.add(ErrorMessages.Menu.missingSetting(config.getSourceFile(), MenuSettingsNode.ROWS)); + addMenuSettingError(errorCollector, config, MenuSettingsNode.ROWS, e); } MenuSettings menuSettings = new MenuSettings(title, rows); @@ -162,7 +163,7 @@ public class MenuParser { } } - if (settingsSection.isSet(MenuSettingsNode.AUTO_REFRESH)) { + if (settingsSection.contains(MenuSettingsNode.AUTO_REFRESH)) { int refreshTicks = (int) (settingsSection.getDouble(MenuSettingsNode.AUTO_REFRESH) * 20.0); if (refreshTicks < 1) { refreshTicks = 1; @@ -173,11 +174,19 @@ public class MenuParser { return menuSettings; } + private static void addMenuSettingError(ErrorCollector errorCollector, Config config, String missingSetting, ConfigValueException e) { + if (e instanceof MissingConfigValueException) { + errorCollector.add(ErrorMessages.Menu.missingSetting(config.getSourceFile(), missingSetting)); + } else { + errorCollector.add(ErrorMessages.Menu.invalidSetting(config.getSourceFile(), missingSetting), e); + } + } + private static List loadIconSettingsList(Config config, ErrorCollector errorCollector) { List iconSettingsList = new ArrayList<>(); - for (String iconSectionName : config.getKeys(false)) { + for (String iconSectionName : config.getKeys()) { if (iconSectionName.equals(MenuSettingsNode.ROOT_SECTION)) { continue; } From 70bced767212179f225053b8c224fccd3405707f Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 3 Aug 2020 21:14:54 +0200 Subject: [PATCH 157/213] Add missing copyright headers --- .../me/filoghost/chestcommands/legacy/Backup.java | 14 ++++++++++++++ .../placeholder/scanner/PlaceholderScanner.java | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java index cf11e23..171a8f2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.legacy; import me.filoghost.chestcommands.util.Preconditions; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java index bed6b69..1f1cb0f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package me.filoghost.chestcommands.placeholder.scanner; import java.util.concurrent.atomic.AtomicBoolean; From f92a0eb07b21a2ff07793ec5915414556e371a69 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 3 Aug 2020 21:27:23 +0200 Subject: [PATCH 158/213] Use https for repository --- Plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 0ccb4ec..66ffb30 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -35,7 +35,7 @@ placeholderapi-repo - http://repo.extendedclip.com/content/repositories/placeholderapi/ + https://repo.extendedclip.com/content/repositories/placeholderapi/ From a14099b88a0e0e6b74422e0565ae791c6d32300c Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 3 Aug 2020 23:09:16 +0200 Subject: [PATCH 159/213] Use section for custom placeholders --- .../chestcommands/config/CustomPlaceholders.java | 10 ++++++++-- .../legacy/upgrade/PlaceholdersYamlUpgradeTask.java | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java index 53a4b3f..78f5d03 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java @@ -15,6 +15,7 @@ package me.filoghost.chestcommands.config; import me.filoghost.chestcommands.config.framework.Config; +import me.filoghost.chestcommands.config.framework.ConfigSection; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.placeholder.StaticPlaceholder; import me.filoghost.chestcommands.util.Colors; @@ -30,8 +31,13 @@ public class CustomPlaceholders { public void load(Config config, ErrorCollector errorCollector) { placeholders.clear(); - for (String placeholder : config.getKeys()) { - String replacement = Colors.addColors(config.getString(placeholder)); + ConfigSection placeholdersSection = config.getConfigSection("placeholders"); + if (placeholdersSection == null) { + return; + } + + for (String placeholder : placeholdersSection.getKeys()) { + String replacement = Colors.addColors(placeholdersSection.getString(placeholder)); if (placeholder.length() == 0) { errorCollector.add(ErrorMessages.Config.emptyPlaceholder(config.getSourceFile())); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgradeTask.java index 13e0e27..1ff4ce9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgradeTask.java @@ -79,7 +79,7 @@ public class PlaceholdersYamlUpgradeTask extends UpgradeTask { String placeholder = unquote(parts[0]); String replacement = StringEscapeUtils.unescapeJava(unquote(parts[1])); - newPlaceholdersConfig.setString(placeholder, replacement); + newPlaceholdersConfig.setString("placeholders." + placeholder, replacement); setSaveRequired(); } From e1256acd856e266743c5336ce49fab2f0f794923 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 3 Aug 2020 23:43:10 +0200 Subject: [PATCH 160/213] Fix NPE --- .../me/filoghost/chestcommands/config/CustomPlaceholders.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java index 78f5d03..d72fea9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java @@ -38,6 +38,9 @@ public class CustomPlaceholders { for (String placeholder : placeholdersSection.getKeys()) { String replacement = Colors.addColors(placeholdersSection.getString(placeholder)); + if (replacement == null) { + return; + } if (placeholder.length() == 0) { errorCollector.add(ErrorMessages.Config.emptyPlaceholder(config.getSourceFile())); From 03a0ab30afb15f70174adc4b68e44a603fbab154 Mon Sep 17 00:00:00 2001 From: filoghost Date: Wed, 5 Aug 2020 21:44:03 +0200 Subject: [PATCH 161/213] Refactor legacy upgrades --- .../chestcommands/legacy/Backup.java | 2 +- .../chestcommands/legacy/Upgrade.java | 111 ------------------ .../legacy/UpgradeExecutorException.java | 4 - .../chestcommands/legacy/UpgradeList.java | 102 ++++++++++++++++ .../legacy/UpgradesDoneRegistry.java | 4 +- .../legacy/UpgradesExecutor.java | 3 +- .../upgrade/MenuNodeRenameUpgradeTask.java | 46 -------- .../legacy/{ => upgrade}/RegexReplacer.java | 6 +- .../legacy/upgrade/RegexUpgradeTask.java | 45 ++++--- .../chestcommands/legacy/upgrade/Upgrade.java | 53 +++++++++ .../legacy/upgrade/UpgradeTask.java | 2 +- ...sUpgradeTask.java => YamlUpgradeTask.java} | 45 ++++--- .../v4_0_LangUpgradeTask.java} | 14 ++- .../v4_0_MenuNodeExpandUpgradeTask.java} | 35 +----- .../v4_0/v4_0_MenuNodeRenameUpgradeTask.java | 42 +++++++ .../v4_0_PlaceholdersFileUpgradeTask.java} | 7 +- .../legacy/v4_0/v4_0_SettingsUpgradeTask.java | 34 ++++++ 17 files changed, 308 insertions(+), 247 deletions(-) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgradeTask.java rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/{ => upgrade}/RegexReplacer.java (90%) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/{SettingsUpgradeTask.java => YamlUpgradeTask.java} (55%) rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/{upgrade/LangUpgradeTask.java => v4_0/v4_0_LangUpgradeTask.java} (69%) rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/{upgrade/MenuNodeExpandUpgradeTask.java => v4_0/v4_0_MenuNodeExpandUpgradeTask.java} (81%) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeRenameUpgradeTask.java rename Plugin/src/main/java/me/filoghost/chestcommands/legacy/{upgrade/PlaceholdersYamlUpgradeTask.java => v4_0/v4_0_PlaceholdersFileUpgradeTask.java} (93%) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java index 171a8f2..ccb3818 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java @@ -42,7 +42,7 @@ public class Backup { return new Backup(dataFolder, backupName); } - public void backupFile(Path fileToBackup) throws IOException { + public void addFile(Path fileToBackup) throws IOException { Preconditions.checkArgument(fileToBackup.startsWith(dataFolder), "file is not inside data folder"); Path destination = backupFolder.resolve(dataFolder.relativize(fileToBackup)); Files.createDirectories(destination.getParent()); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java deleted file mode 100644 index 0a9a5ef..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Upgrade.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.legacy; - -import me.filoghost.chestcommands.config.ConfigManager; -import me.filoghost.chestcommands.config.framework.ConfigLoader; -import me.filoghost.chestcommands.legacy.upgrade.LangUpgradeTask; -import me.filoghost.chestcommands.legacy.upgrade.MenuNodeExpandUpgradeTask; -import me.filoghost.chestcommands.legacy.upgrade.MenuNodeRenameUpgradeTask; -import me.filoghost.chestcommands.legacy.upgrade.PlaceholdersYamlUpgradeTask; -import me.filoghost.chestcommands.legacy.upgrade.SettingsUpgradeTask; -import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask; -import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException; -import me.filoghost.chestcommands.logging.ErrorMessages; -import me.filoghost.chestcommands.util.collection.CollectionUtils; -import me.filoghost.chestcommands.util.logging.Log; - -import java.io.IOException; -import java.nio.file.Path; -import java.util.Collections; -import java.util.List; - -public enum Upgrade { - - V4_MENUS_RENAME("v4.0-menus-rename", (configManager) -> { - List menuFiles = getMenuFiles(configManager); - - return CollectionUtils.transform(menuFiles, - MenuNodeRenameUpgradeTask::new); - }), - - V4_MENUS_REFORMAT("v4.0-menus-reformat", (configManager) -> { - String legacyCommandSeparator = readLegacyCommandSeparator(configManager); - List menuFiles = getMenuFiles(configManager); - - return CollectionUtils.transform(menuFiles, - file -> new MenuNodeExpandUpgradeTask(configManager, file, legacyCommandSeparator)); - }), - - V4_CONFIG("v4.0-config", (configManager) -> { - return Collections.singletonList(new SettingsUpgradeTask(configManager)); - }), - - V4_PLACEHOLDERS("v4.0-placeholders", (configManager) -> { - return Collections.singletonList(new PlaceholdersYamlUpgradeTask(configManager)); - }), - - V4_LANG("v4.0-lang", (configManager) -> { - return Collections.singletonList(new LangUpgradeTask(configManager)); - }); - - - private final String id; - private final UpgradeTasksSupplier upgradeTasksSupplier; - - Upgrade(String id, UpgradeTasksSupplier upgradeTasksSupplier) { - this.id = id; - this.upgradeTasksSupplier = upgradeTasksSupplier; - } - - public String getID() { - return id; - } - - public List createUpgradeTasks(ConfigManager configManager) throws UpgradeTaskException { - return upgradeTasksSupplier.getTasks(configManager); - } - - private static List getMenuFiles(ConfigManager configManager) throws UpgradeTaskException { - try { - return configManager.getMenuFiles(); - } catch (IOException e) { - throw new UpgradeTaskException(ErrorMessages.Upgrade.menuListIOException, e); - } - } - - private static String readLegacyCommandSeparator(ConfigManager configManager) { - ConfigLoader settingsConfigLoader = configManager.getConfigLoader("config.yml"); - - if (!settingsConfigLoader.fileExists()) { - return null; - } - - try { - return settingsConfigLoader.load().getString("multiple-commands-separator"); - } catch (Throwable t) { - Log.warning("Failed to load \"" + settingsConfigLoader.getFile() + "\", assuming default command separator \";\"."); - return null; - } - } - - @FunctionalInterface - interface UpgradeTasksSupplier { - - List getTasks(ConfigManager configManager) throws UpgradeTaskException; - - } - -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeExecutorException.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeExecutorException.java index 76a2ba5..376fb20 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeExecutorException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeExecutorException.java @@ -16,10 +16,6 @@ package me.filoghost.chestcommands.legacy; public class UpgradeExecutorException extends Exception { - public UpgradeExecutorException(String message) { - super(message); - } - public UpgradeExecutorException(String message, Throwable cause) { super(message, cause); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java new file mode 100644 index 0000000..2a76de8 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java @@ -0,0 +1,102 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.legacy; + +import com.google.common.collect.ImmutableList; +import me.filoghost.chestcommands.config.ConfigManager; +import me.filoghost.chestcommands.config.framework.ConfigLoader; +import me.filoghost.chestcommands.legacy.upgrade.Upgrade; +import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask; +import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException; +import me.filoghost.chestcommands.legacy.v4_0.v4_0_LangUpgradeTask; +import me.filoghost.chestcommands.legacy.v4_0.v4_0_MenuNodeExpandUpgradeTask; +import me.filoghost.chestcommands.legacy.v4_0.v4_0_MenuNodeRenameUpgradeTask; +import me.filoghost.chestcommands.legacy.v4_0.v4_0_PlaceholdersFileUpgradeTask; +import me.filoghost.chestcommands.legacy.v4_0.v4_0_SettingsUpgradeTask; +import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.util.collection.CollectionUtils; +import me.filoghost.chestcommands.util.logging.Log; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.Collections; +import java.util.List; +import java.util.function.Function; + +public class UpgradeList { + + /* + * Note: order of declaration determines order of execution + */ + private static final ImmutableList orderedUpgrades = ImmutableList.of( + multiTaskUpgrade("v4.0-menus-rename", (configManager) -> { + return createMenuBulkUpgrade(configManager, v4_0_MenuNodeRenameUpgradeTask::new); + }), + + // Reformat after nodes have already been renamed + multiTaskUpgrade("v4.0-menus-reformat", (configManager) -> { + String legacyCommandSeparator = readLegacyCommandSeparator(configManager); + return createMenuBulkUpgrade(configManager, + file -> new v4_0_MenuNodeExpandUpgradeTask(configManager, file, legacyCommandSeparator)); + }), + + // Upgrade config after reading the command separator for menus + singleTaskUpgrade("v4.0-config", v4_0_SettingsUpgradeTask::new), + singleTaskUpgrade("v4.0-placeholders", v4_0_PlaceholdersFileUpgradeTask::new), + singleTaskUpgrade("v4.0-lang", v4_0_LangUpgradeTask::new) + ); + + private static Upgrade singleTaskUpgrade(String id, Upgrade.SingleTaskSupplier upgradeTaskSupplier) { + return new Upgrade(id, configManager -> { + return Collections.singletonList(upgradeTaskSupplier.getTask(configManager)); + }); + } + + private static Upgrade multiTaskUpgrade(String id, Upgrade.MultiTaskSupplier upgradeTasksSupplier) { + return new Upgrade(id, upgradeTasksSupplier); + } + + private static List createMenuBulkUpgrade(ConfigManager configManager, Function menuTaskSupplier) throws UpgradeTaskException { + List menuFiles = getMenuFiles(configManager); + return CollectionUtils.transform(menuFiles, menuTaskSupplier); + } + + private static List getMenuFiles(ConfigManager configManager) throws UpgradeTaskException { + try { + return configManager.getMenuFiles(); + } catch (IOException e) { + throw new UpgradeTaskException(ErrorMessages.Upgrade.menuListIOException, e); + } + } + + private static String readLegacyCommandSeparator(ConfigManager configManager) { + ConfigLoader settingsConfigLoader = configManager.getConfigLoader("config.yml"); + + if (!settingsConfigLoader.fileExists()) { + return null; + } + + try { + return settingsConfigLoader.load().getString("multiple-commands-separator"); + } catch (Throwable t) { + Log.warning("Failed to load \"" + settingsConfigLoader.getFile() + "\", assuming default command separator \";\"."); + return null; + } + } + + public static ImmutableList getOrderedUpgrades() { + return orderedUpgrades; + } +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java index 7e76bde..37e495f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java @@ -14,6 +14,8 @@ */ package me.filoghost.chestcommands.legacy; +import me.filoghost.chestcommands.legacy.upgrade.Upgrade; + import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -42,7 +44,7 @@ public class UpgradesDoneRegistry { } public void setAllDone() { - for (Upgrade upgrade : Upgrade.values()) { + for (Upgrade upgrade : UpgradeList.getOrderedUpgrades()) { setDone(upgrade); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java index b2f4207..4fbadfb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java @@ -15,6 +15,7 @@ package me.filoghost.chestcommands.legacy; import me.filoghost.chestcommands.config.ConfigManager; +import me.filoghost.chestcommands.legacy.upgrade.Upgrade; import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask; import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException; import me.filoghost.chestcommands.logging.ErrorMessages; @@ -67,7 +68,7 @@ public class UpgradesExecutor { private void runMissingUpgrades(Backup backup, ErrorCollector errorCollector) { - for (Upgrade upgrade : Upgrade.values()) { + for (Upgrade upgrade : UpgradeList.getOrderedUpgrades()) { if (!upgradesDoneRegistry.isDone(upgrade)) { boolean allTasksSuccessful = tryRunUpgradeTasks(upgrade, backup, errorCollector); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgradeTask.java deleted file mode 100644 index 5e49f2c..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeRenameUpgradeTask.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.legacy.upgrade; - -import me.filoghost.chestcommands.parsing.icon.AttributeType; - -import java.nio.file.Path; -import java.util.regex.Pattern; - -public class MenuNodeRenameUpgradeTask extends RegexUpgradeTask { - - public MenuNodeRenameUpgradeTask(Path menuFile) { - super(menuFile); - - addSubNodeReplacer("command", "commands"); - addSubNodeReplacer("open-action", "open-actions"); - addSubNodeReplacer("id", "material"); - - addSubNodeReplacer("ID", AttributeType.MATERIAL.getAttributeName()); - addSubNodeReplacer("DATA-VALUE", AttributeType.DURABILITY.getAttributeName()); - addSubNodeReplacer("NBT", AttributeType.NBT_DATA.getAttributeName()); - addSubNodeReplacer("ENCHANTMENT", AttributeType.ENCHANTMENTS.getAttributeName()); - addSubNodeReplacer("COMMAND", AttributeType.ACTIONS.getAttributeName()); - addSubNodeReplacer("COMMANDS", AttributeType.ACTIONS.getAttributeName()); - addSubNodeReplacer("REQUIRED-ITEM", AttributeType.REQUIRED_ITEMS.getAttributeName()); - } - - private void addSubNodeReplacer(String oldNode, String newNode) { - addRegexReplacer( - Pattern.compile("(^\\s+)" + Pattern.quote(oldNode) + "(:)"), - matcher -> matcher.group(1) + newNode + matcher.group(2)); - } - -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/RegexReplacer.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexReplacer.java similarity index 90% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/RegexReplacer.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexReplacer.java index df57b8d..c084b1e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/RegexReplacer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexReplacer.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.legacy; +package me.filoghost.chestcommands.legacy.upgrade; import java.util.function.Function; import java.util.regex.Matcher; @@ -29,8 +29,8 @@ public class RegexReplacer implements Function { } @Override - public String apply(String line) { - Matcher matcher = regex.matcher(line); + public String apply(String string) { + Matcher matcher = regex.matcher(string); StringBuffer output = new StringBuffer(); while (matcher.find()) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java index 2f4d8f9..8d090b2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java @@ -16,13 +16,11 @@ package me.filoghost.chestcommands.legacy.upgrade; import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; -import me.filoghost.chestcommands.legacy.RegexReplacer; import me.filoghost.chestcommands.logging.ErrorMessages; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; import java.util.List; import java.util.function.Function; import java.util.regex.Matcher; @@ -30,33 +28,28 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; -public class RegexUpgradeTask extends UpgradeTask { +public abstract class RegexUpgradeTask extends UpgradeTask { private final Path file; - private final List replacers; private List newContents; + private Stream linesStream; public RegexUpgradeTask(Path file) { this.file = file; - this.replacers = new ArrayList<>(); - } - - protected void addRegexReplacer(Pattern regex, Function replaceCallback) { - replacers.add(new RegexReplacer(regex, replaceCallback)); } @Override - public Path getOriginalFile() { + public final Path getOriginalFile() { return file; } @Override - public Path getUpgradedFile() { + public final Path getUpgradedFile() { return file; } @Override - public void computeChanges() throws ConfigLoadException { + public final void computeChanges() throws ConfigLoadException { if (!Files.isRegularFile(file)) { return; } @@ -68,10 +61,8 @@ public class RegexUpgradeTask extends UpgradeTask { throw new ConfigLoadException(ErrorMessages.Config.readIOException, e); } - Stream linesStream = lines.stream(); - for (RegexReplacer replacer : replacers) { - linesStream = linesStream.map(replacer); - } + this.linesStream = lines.stream(); + computeRegexChanges(); newContents = linesStream.collect(Collectors.toList()); @@ -81,7 +72,7 @@ public class RegexUpgradeTask extends UpgradeTask { } @Override - public void saveChanges() throws ConfigSaveException { + public final void saveChanges() throws ConfigSaveException { try { Files.write(file, newContents); } catch (IOException e) { @@ -89,4 +80,24 @@ public class RegexUpgradeTask extends UpgradeTask { } } + protected abstract void computeRegexChanges(); + + protected void replaceString(String target, String replacement) { + replaceRegex( + Pattern.compile(Pattern.quote(target)), + matcher -> replacement + ); + } + + protected void replaceSubNode(String oldNode, String newNode) { + replaceRegex( + Pattern.compile("(^\\s+)" + Pattern.quote(oldNode) + "(:)"), + matcher -> matcher.group(1) + newNode + matcher.group(2) + ); + } + + protected void replaceRegex(Pattern regex, Function replaceCallback) { + linesStream = linesStream.map(new RegexReplacer(regex, replaceCallback)); + } + } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java new file mode 100644 index 0000000..091dc4e --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java @@ -0,0 +1,53 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.legacy.upgrade; + +import me.filoghost.chestcommands.config.ConfigManager; + +import java.util.List; + +public class Upgrade { + + private final String id; + private final MultiTaskSupplier upgradeTasksSupplier; + + public Upgrade(String id, MultiTaskSupplier taskSupplier) { + this.id = id; + this.upgradeTasksSupplier = taskSupplier; + } + + public String getID() { + return id; + } + + public List createUpgradeTasks(ConfigManager configManager) throws UpgradeTaskException { + return upgradeTasksSupplier.getTasks(configManager); + } + + @FunctionalInterface + public interface SingleTaskSupplier { + + UpgradeTask getTask(ConfigManager configManager) throws UpgradeTaskException; + + } + + @FunctionalInterface + public interface MultiTaskSupplier { + + List getTasks(ConfigManager configManager) throws UpgradeTaskException; + + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java index a6d9cbc..788c76c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java @@ -44,7 +44,7 @@ public abstract class UpgradeTask { if (saveRequired) { try { - backup.backupFile(getOriginalFile()); + backup.addFile(getOriginalFile()); } catch (IOException e) { throw new UpgradeTaskException(ErrorMessages.Upgrade.backupError(getOriginalFile()), e); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java similarity index 55% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgradeTask.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java index e89739b..e4c3a27 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/SettingsUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java @@ -14,7 +14,6 @@ */ package me.filoghost.chestcommands.legacy.upgrade; -import me.filoghost.chestcommands.config.ConfigManager; import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; @@ -22,49 +21,47 @@ import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException import java.nio.file.Path; -public class SettingsUpgradeTask extends UpgradeTask { +public abstract class YamlUpgradeTask extends UpgradeTask { - private final ConfigLoader settingsConfigLoader; + private final ConfigLoader configLoader; private Config updatedConfig; - public SettingsUpgradeTask(ConfigManager configManager) { - this.settingsConfigLoader = configManager.getConfigLoader("config.yml"); + public YamlUpgradeTask(ConfigLoader configLoader) { + this.configLoader = configLoader; } @Override - public Path getOriginalFile() { - return settingsConfigLoader.getFile(); + public final Path getOriginalFile() { + return configLoader.getFile(); } @Override - public Path getUpgradedFile() { - return settingsConfigLoader.getFile(); + public final Path getUpgradedFile() { + return configLoader.getFile(); } @Override - public void computeChanges() throws ConfigLoadException { - if (!settingsConfigLoader.fileExists()) { + public final void computeChanges() throws ConfigLoadException { + if (!configLoader.fileExists()) { return; } - Config settingsConfig = settingsConfigLoader.load(); - - removeNode(settingsConfig, "use-only-commands-without-args"); - removeNode(settingsConfig, "use-console-colors"); - removeNode(settingsConfig, "multiple-commands-separator"); - - this.updatedConfig = settingsConfig; + Config config = configLoader.load(); + computeYamlChanges(config); + this.updatedConfig = config; } - private void removeNode(Config config, String node) { + @Override + public final void saveChanges() throws ConfigSaveException { + configLoader.save(updatedConfig); + } + + protected abstract void computeYamlChanges(Config config); + + protected void removeNode(Config config, String node) { if (config.contains(node)) { config.remove(node); setSaveRequired(); } } - - @Override - public void saveChanges() throws ConfigSaveException { - settingsConfigLoader.save(updatedConfig); - } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/LangUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_LangUpgradeTask.java similarity index 69% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/LangUpgradeTask.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_LangUpgradeTask.java index 9df8f7a..a9a5f8d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/LangUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_LangUpgradeTask.java @@ -12,18 +12,20 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.legacy.upgrade; +package me.filoghost.chestcommands.legacy.v4_0; import me.filoghost.chestcommands.config.ConfigManager; +import me.filoghost.chestcommands.legacy.upgrade.RegexUpgradeTask; -import java.util.regex.Pattern; +public class v4_0_LangUpgradeTask extends RegexUpgradeTask { -public class LangUpgradeTask extends RegexUpgradeTask { - - public LangUpgradeTask(ConfigManager configManager) { + public v4_0_LangUpgradeTask(ConfigManager configManager) { super(configManager.getRootDataFolder().resolve("lang.yml")); + } - addRegexReplacer(Pattern.compile(Pattern.quote("{datavalue}")), matcher -> "{durability}"); + @Override + protected void computeRegexChanges() { + replaceString("{datavalue}", "{durability}"); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java similarity index 81% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java index f3ce3f7..2e83844 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/MenuNodeExpandUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java @@ -12,15 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.legacy.upgrade; +package me.filoghost.chestcommands.legacy.v4_0; import me.filoghost.chestcommands.config.ConfigManager; import me.filoghost.chestcommands.config.framework.Config; -import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.config.framework.ConfigSection; import me.filoghost.chestcommands.config.framework.ConfigValueType; -import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; -import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; +import me.filoghost.chestcommands.legacy.upgrade.YamlUpgradeTask; import me.filoghost.chestcommands.parsing.icon.AttributeType; import me.filoghost.chestcommands.parsing.menu.MenuSettingsNode; import me.filoghost.chestcommands.util.Strings; @@ -31,30 +29,17 @@ import java.util.Collections; import java.util.List; import java.util.regex.Pattern; -public class MenuNodeExpandUpgradeTask extends UpgradeTask { +public class v4_0_MenuNodeExpandUpgradeTask extends YamlUpgradeTask { - private final ConfigLoader menuConfigLoader; private final String legacyCommandSeparator; - private Config updatedConfig; - public MenuNodeExpandUpgradeTask(ConfigManager configManager, Path menuFile, String legacyCommandSeparator) { - this.menuConfigLoader = configManager.getConfigLoader(menuFile); + public v4_0_MenuNodeExpandUpgradeTask(ConfigManager configManager, Path menuFile, String legacyCommandSeparator) { + super(configManager.getConfigLoader(menuFile)); this.legacyCommandSeparator = legacyCommandSeparator; } @Override - public Path getOriginalFile() { - return menuConfigLoader.getFile(); - } - - @Override - public Path getUpgradedFile() { - return menuConfigLoader.getFile(); - } - - @Override - public void computeChanges() throws ConfigLoadException { - Config menuConfig = menuConfigLoader.load(); + public void computeYamlChanges(Config menuConfig) { menuConfig.setHeader(null); for (String key : menuConfig.getKeys()) { @@ -69,16 +54,8 @@ public class MenuNodeExpandUpgradeTask extends UpgradeTask { upgradeIcon(section); } } - - this.updatedConfig = menuConfig; } - @Override - public void saveChanges() throws ConfigSaveException { - menuConfigLoader.save(updatedConfig); - } - - private void upgradeMenuSettings(ConfigSection section) { expandInlineList(section, MenuSettingsNode.COMMANDS, ";"); expandInlineList(section, MenuSettingsNode.OPEN_ACTIONS, legacyCommandSeparator); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeRenameUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeRenameUpgradeTask.java new file mode 100644 index 0000000..135cc3b --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeRenameUpgradeTask.java @@ -0,0 +1,42 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.legacy.v4_0; + +import me.filoghost.chestcommands.legacy.upgrade.RegexUpgradeTask; +import me.filoghost.chestcommands.parsing.icon.AttributeType; + +import java.nio.file.Path; + +public class v4_0_MenuNodeRenameUpgradeTask extends RegexUpgradeTask { + + public v4_0_MenuNodeRenameUpgradeTask(Path menuFile) { + super(menuFile); + } + @Override + protected void computeRegexChanges() { + replaceSubNode("command", "commands"); + replaceSubNode("open-action", "open-actions"); + replaceSubNode("id", "material"); + + replaceSubNode("ID", AttributeType.MATERIAL.getAttributeName()); + replaceSubNode("DATA-VALUE", AttributeType.DURABILITY.getAttributeName()); + replaceSubNode("NBT", AttributeType.NBT_DATA.getAttributeName()); + replaceSubNode("ENCHANTMENT", AttributeType.ENCHANTMENTS.getAttributeName()); + replaceSubNode("COMMAND", AttributeType.ACTIONS.getAttributeName()); + replaceSubNode("COMMANDS", AttributeType.ACTIONS.getAttributeName()); + replaceSubNode("REQUIRED-ITEM", AttributeType.REQUIRED_ITEMS.getAttributeName()); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgradeTask.java rename to Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java index 1ff4ce9..0e69718 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/PlaceholdersYamlUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java @@ -12,13 +12,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.legacy.upgrade; +package me.filoghost.chestcommands.legacy.v4_0; import me.filoghost.chestcommands.config.ConfigManager; import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; +import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.util.Strings; import org.apache.commons.lang.StringEscapeUtils; @@ -28,13 +29,13 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.List; -public class PlaceholdersYamlUpgradeTask extends UpgradeTask { +public class v4_0_PlaceholdersFileUpgradeTask extends UpgradeTask { private final Path oldPlaceholdersFile; private final ConfigLoader newPlaceholdersConfigLoader; private Config updatedConfig; - public PlaceholdersYamlUpgradeTask(ConfigManager configManager) { + public v4_0_PlaceholdersFileUpgradeTask(ConfigManager configManager) { this.oldPlaceholdersFile = configManager.getRootDataFolder().resolve("placeholders.yml"); this.newPlaceholdersConfigLoader = configManager.getConfigLoader("custom-placeholders.yml"); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java new file mode 100644 index 0000000..d4439a2 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java @@ -0,0 +1,34 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.legacy.v4_0; + +import me.filoghost.chestcommands.config.ConfigManager; +import me.filoghost.chestcommands.config.framework.Config; +import me.filoghost.chestcommands.legacy.upgrade.YamlUpgradeTask; + +public class v4_0_SettingsUpgradeTask extends YamlUpgradeTask { + + public v4_0_SettingsUpgradeTask(ConfigManager configManager) { + super(configManager.getConfigLoader("config.yml")); + } + + @Override + public void computeYamlChanges(Config settingsConfig) { + removeNode(settingsConfig, "use-only-commands-without-args"); + removeNode(settingsConfig, "use-console-colors"); + removeNode(settingsConfig, "multiple-commands-separator"); + } + +} From dd04a1efbb6384e2a1a468bc19f63c9a8c00d89c Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 6 Aug 2020 00:05:23 +0200 Subject: [PATCH 162/213] Add empty ConfigSection --- .../config/framework/ConfigSection.java | 1 + .../config/framework/EmptyConfigSection.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/config/framework/EmptyConfigSection.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java index 42dedec..c2a177f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java @@ -76,6 +76,7 @@ public class ConfigSection { } private void setRawValue(String path, Object value) { + Preconditions.checkArgument(!(value instanceof ConfigurationSection), "cannot set ConfigurationSection as value"); yamlSection.set(path, value); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/EmptyConfigSection.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/EmptyConfigSection.java new file mode 100644 index 0000000..88a1df8 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/EmptyConfigSection.java @@ -0,0 +1,25 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.config.framework; + +import org.bukkit.configuration.MemoryConfiguration; + +public class EmptyConfigSection extends ConfigSection { + + public EmptyConfigSection() { + super(new MemoryConfiguration()); + } + +} From aee7dda5b1dde3ef84d064f41539430ca7e4dec3 Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 6 Aug 2020 00:07:32 +0200 Subject: [PATCH 163/213] Handle missing values --- .../chestcommands/logging/ErrorMessages.java | 4 ++++ .../filoghost/chestcommands/menu/MenuManager.java | 14 ++++++++------ .../chestcommands/parsing/menu/MenuParser.java | 5 +++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java index 9e57f59..852e35b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java @@ -179,6 +179,10 @@ public class ErrorMessages { return menuError(menuFile, "is missing the menu setting \"" + missingSetting + "\""); } + public static String missingSettingsSection(Path menuFile) { + return menuError(menuFile, "is missing the menu setting section"); + } + private static String menuError(Path menuFile, String errorMessage) { return "the menu \"" + formatPath(menuFile) + "\" " + errorMessage; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java index 7f3f704..ada8d4f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java @@ -64,13 +64,15 @@ public class MenuManager { } menusByFile.put(fileName, menu); - for (String openCommand : loadedMenu.getOpenCommands()) { - if (!openCommand.isEmpty()) { - InternalIconMenu sameCommandMenu = menusByOpenCommand.get(openCommand); - if (sameCommandMenu != null) { - errorCollector.add(ErrorMessages.Menu.duplicateMenuCommand(sameCommandMenu.getSourceFile(), loadedMenu.getSourceFile(), openCommand)); + if (loadedMenu.getOpenCommands() != null) { + for (String openCommand : loadedMenu.getOpenCommands()) { + if (!openCommand.isEmpty()) { + InternalIconMenu sameCommandMenu = menusByOpenCommand.get(openCommand); + if (sameCommandMenu != null) { + errorCollector.add(ErrorMessages.Menu.duplicateMenuCommand(sameCommandMenu.getSourceFile(), loadedMenu.getSourceFile(), openCommand)); + } + menusByOpenCommand.put(openCommand, menu); } - menusByOpenCommand.put(openCommand, menu); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index 245ae09..0423f14 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -17,6 +17,7 @@ package me.filoghost.chestcommands.parsing.menu; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.config.framework.ConfigSection; +import me.filoghost.chestcommands.config.framework.EmptyConfigSection; import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; import me.filoghost.chestcommands.config.framework.exception.MissingConfigValueException; import me.filoghost.chestcommands.logging.ErrorMessages; @@ -96,6 +97,10 @@ public class MenuParser { private static MenuSettings loadMenuSettings(Config config, ErrorCollector errorCollector) { ConfigSection settingsSection = config.getConfigSection(MenuSettingsNode.ROOT_SECTION); + if (settingsSection == null) { + errorCollector.add(ErrorMessages.Menu.missingSettingsSection(config.getSourceFile())); + settingsSection = new EmptyConfigSection(); + } String title; try { From 2d654caca6c9d6add72d42d2651fc685331934fd Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 6 Aug 2020 00:13:40 +0200 Subject: [PATCH 164/213] Fix duplicate error messages --- .../chestcommands/logging/PrintableErrorCollector.java | 3 ++- .../me/filoghost/chestcommands/util/logging/ErrorInfo.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java index f640d1c..26e0b22 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java @@ -27,6 +27,7 @@ import org.bukkit.ChatColor; import java.io.PrintWriter; import java.io.StringWriter; +import java.util.ArrayList; import java.util.List; public class PrintableErrorCollector extends ErrorCollector { @@ -52,7 +53,7 @@ public class PrintableErrorCollector extends ErrorCollector { } private ErrorPrintInfo getErrorPrintInfo(int index, ErrorInfo error) { - List message = error.getMessage(); + List message = new ArrayList<>(error.getMessage()); String details = null; Throwable cause = error.getCause(); diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorInfo.java b/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorInfo.java index 463ed27..23a471d 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorInfo.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorInfo.java @@ -15,6 +15,7 @@ package me.filoghost.chestcommands.util.logging; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class ErrorInfo { @@ -33,7 +34,7 @@ public class ErrorInfo { } public List getMessage() { - return message; + return Collections.unmodifiableList(message); } public Throwable getCause() { From d9da788b6c0aae586a66dbcd3d502c562293b196 Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 6 Aug 2020 12:08:51 +0200 Subject: [PATCH 165/213] Rename method --- .../java/me/filoghost/chestcommands/legacy/UpgradeList.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java index 2a76de8..b1df271 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java @@ -42,13 +42,13 @@ public class UpgradeList { */ private static final ImmutableList orderedUpgrades = ImmutableList.of( multiTaskUpgrade("v4.0-menus-rename", (configManager) -> { - return createMenuBulkUpgrade(configManager, v4_0_MenuNodeRenameUpgradeTask::new); + return createMenuTasks(configManager, v4_0_MenuNodeRenameUpgradeTask::new); }), // Reformat after nodes have already been renamed multiTaskUpgrade("v4.0-menus-reformat", (configManager) -> { String legacyCommandSeparator = readLegacyCommandSeparator(configManager); - return createMenuBulkUpgrade(configManager, + return createMenuTasks(configManager, file -> new v4_0_MenuNodeExpandUpgradeTask(configManager, file, legacyCommandSeparator)); }), @@ -68,7 +68,7 @@ public class UpgradeList { return new Upgrade(id, upgradeTasksSupplier); } - private static List createMenuBulkUpgrade(ConfigManager configManager, Function menuTaskSupplier) throws UpgradeTaskException { + private static List createMenuTasks(ConfigManager configManager, Function menuTaskSupplier) throws UpgradeTaskException { List menuFiles = getMenuFiles(configManager); return CollectionUtils.transform(menuFiles, menuTaskSupplier); } From 134e996c6cb1f275f25b061bae18d3c69eb51cc0 Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 6 Aug 2020 12:24:23 +0200 Subject: [PATCH 166/213] Simplify collection usage --- .../chestcommands/api/ConfigurableIcon.java | 4 -- .../icon/BaseConfigurableIcon.java | 32 ++++-------- .../icon/InternalConfigurableIcon.java | 7 +-- .../icon/requirement/RequiredItems.java | 2 - .../icon/requirement/RequiredPermission.java | 2 +- .../chestcommands/menu/InternalIconMenu.java | 5 +- .../parsing/menu/LoadedMenu.java | 8 +-- .../parsing/menu/MenuParser.java | 2 +- .../parsing/menu/MenuSettings.java | 14 +++--- .../placeholder/PlaceholderStringList.java | 6 ++- .../chestcommands/util/Preconditions.java | 9 ---- .../filoghost/chestcommands/util/Strings.java | 4 +- .../util/collection/CollectionUtils.java | 49 +++++++------------ 13 files changed, 57 insertions(+), 87 deletions(-) diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java b/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java index 8028841..85be8a4 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java @@ -47,8 +47,6 @@ public interface ConfigurableIcon extends ClickableIcon { String getNBTData(); void setName(String name); - - boolean hasName(); String getName(); @@ -56,8 +54,6 @@ public interface ConfigurableIcon extends ClickableIcon { void setLore(List lore); - boolean hasLore(); - List getLore(); void setEnchantments(Map enchantments); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java index 3f36ad4..4ede5b1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java @@ -119,10 +119,6 @@ public abstract class BaseConfigurableIcon implements Icon { cachedRendering = null; } - public boolean hasName() { - return name != null; - } - public String getName() { if (name != null) { return name.getOriginalValue(); @@ -138,7 +134,7 @@ public abstract class BaseConfigurableIcon implements Icon { } public void setLore(List lore) { - if (!CollectionUtils.isNullOrEmpty(lore)) { + if (lore != null) { this.lore = new PlaceholderStringList(CollectionUtils.replaceNulls(lore, "")); } else { this.lore = null; @@ -146,10 +142,6 @@ public abstract class BaseConfigurableIcon implements Icon { cachedRendering = null; } - public boolean hasLore() { - return lore != null; - } - public List getLore() { if (lore != null) { return new ArrayList<>(lore.getOriginalValue()); @@ -159,12 +151,12 @@ public abstract class BaseConfigurableIcon implements Icon { } public void setEnchantments(Map enchantments) { - this.enchantments = CollectionUtils.nullableCopy(enchantments); + this.enchantments = CollectionUtils.copy(enchantments); cachedRendering = null; } public Map getEnchantments() { - return CollectionUtils.nullableCopy(enchantments); + return CollectionUtils.copy(enchantments); } public void addEnchantment(Enchantment enchantment) { @@ -219,11 +211,11 @@ public abstract class BaseConfigurableIcon implements Icon { } public List getBannerPatterns() { - return CollectionUtils.nullableCopy(bannerPatterns); + return CollectionUtils.copy(bannerPatterns); } public void setBannerPatterns(List bannerPatterns) { - this.bannerPatterns = CollectionUtils.nullableCopy(bannerPatterns); + this.bannerPatterns = CollectionUtils.copy(bannerPatterns); cachedRendering = null; } @@ -233,7 +225,7 @@ public abstract class BaseConfigurableIcon implements Icon { } public String renderName(Player viewer) { - if (!hasName()) { + if (name == null) { return null; } if (!placeholdersEnabled) { @@ -251,7 +243,7 @@ public abstract class BaseConfigurableIcon implements Icon { } public List renderLore(Player viewer) { - if (!hasLore()) { + if (lore == null) { return null; } if (!placeholdersEnabled) { @@ -285,12 +277,8 @@ public abstract class BaseConfigurableIcon implements Icon { // Then apply data from config nodes, overwriting NBT data if there are conflicting values ItemMeta itemMeta = itemStack.getItemMeta(); - if (hasName()) { - itemMeta.setDisplayName(renderName(viewer)); - } - if (hasLore()) { - itemMeta.setLore(renderLore(viewer)); - } + itemMeta.setDisplayName(renderName(viewer)); + itemMeta.setLore(renderLore(viewer)); if (leatherColor != null && itemMeta instanceof LeatherArmorMeta) { ((LeatherArmorMeta) itemMeta).setColor(leatherColor); @@ -312,7 +300,7 @@ public abstract class BaseConfigurableIcon implements Icon { } // Hide all text details (damage, enchantments, potions, etc,) - if (CollectionUtils.isNullOrEmpty(itemMeta.getItemFlags())) { + if (itemMeta.getItemFlags().isEmpty()) { itemMeta.addItemFlags(ItemFlag.values()); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java index fd33442..0a1fdbb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java @@ -14,6 +14,7 @@ */ package me.filoghost.chestcommands.icon; +import com.google.common.collect.ImmutableList; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.OpenMenuAction; import me.filoghost.chestcommands.api.ClickResult; @@ -41,7 +42,7 @@ public class InternalConfigurableIcon extends BaseConfigurableIcon implements Re private RequiredMoney requiredMoney; private RequiredExpLevel requiredExpLevel; private RequiredItems requiredItems; - private List clickActions; + private ImmutableList clickActions; private ClickResult clickResult; @@ -88,7 +89,7 @@ public class InternalConfigurableIcon extends BaseConfigurableIcon implements Re } public void setRequiredItems(List requiredItems) { - if (!CollectionUtils.isNullOrEmpty(requiredItems)) { + if (requiredItems != null) { this.requiredItems = new RequiredItems(requiredItems); } else { this.requiredItems = null; @@ -96,7 +97,7 @@ public class InternalConfigurableIcon extends BaseConfigurableIcon implements Re } public void setClickActions(List clickActions) { - this.clickActions = CollectionUtils.nullableCopy(clickActions); + this.clickActions = CollectionUtils.immutableCopy(clickActions); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItems.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItems.java index e8a7d84..583f210 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItems.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItems.java @@ -16,7 +16,6 @@ package me.filoghost.chestcommands.icon.requirement; import com.google.common.collect.ImmutableList; import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.Utils; import org.bukkit.entity.Player; @@ -27,7 +26,6 @@ public class RequiredItems implements Requirement { private final List items; public RequiredItems(List items) { - Preconditions.notEmpty(items, "items"); this.items = ImmutableList.copyOf(items); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java index 7b3ead5..da20afc 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java @@ -29,7 +29,7 @@ public class RequiredPermission implements Requirement { permission = permission.trim(); } - if (Strings.isNullOrEmpty(permission)) { + if (Strings.isEmpty(permission)) { this.permission = null; negated = false; } else { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java index 1f8e2fe..718dc19 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java @@ -14,6 +14,7 @@ */ package me.filoghost.chestcommands.menu; +import com.google.common.collect.ImmutableList; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.action.Action; @@ -30,7 +31,7 @@ public class InternalIconMenu extends BaseIconMenu { private final Path sourceFile; private final String openPermission; - private List openActions; + private ImmutableList openActions; private int refreshTicks; public InternalIconMenu(String title, int rows, Path sourceFile) { @@ -44,7 +45,7 @@ public class InternalIconMenu extends BaseIconMenu { } public void setOpenActions(List openAction) { - this.openActions = CollectionUtils.nullableCopy(openAction); + this.openActions = CollectionUtils.immutableCopy(openAction); } public String getOpenPermission() { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java index f6581e0..32dba22 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java @@ -14,7 +14,9 @@ */ package me.filoghost.chestcommands.parsing.menu; +import com.google.common.collect.ImmutableList; import me.filoghost.chestcommands.menu.InternalIconMenu; +import me.filoghost.chestcommands.util.collection.CollectionUtils; import java.nio.file.Path; import java.util.List; @@ -23,13 +25,13 @@ public class LoadedMenu { private final InternalIconMenu menu; private final Path sourceFile; - private final List openCommands; + private final ImmutableList openCommands; private final MenuOpenItem openItem; public LoadedMenu(InternalIconMenu menu, Path menuFile, List openCommands, MenuOpenItem openItem) { this.menu = menu; this.sourceFile = menuFile; - this.openCommands = openCommands; + this.openCommands = CollectionUtils.immutableCopy(openCommands); this.openItem = openItem; } @@ -41,7 +43,7 @@ public class LoadedMenu { return sourceFile; } - public List getOpenCommands() { + public ImmutableList getOpenCommands() { return openCommands; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index 0423f14..5945e5c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -131,7 +131,7 @@ public class MenuParser { List serializedOpenActions = settingsSection.getStringList(MenuSettingsNode.OPEN_ACTIONS); - if (serializedOpenActions != null && !serializedOpenActions.isEmpty()) { + if (serializedOpenActions != null) { List openActions = new ArrayList<>(); for (String serializedAction : serializedOpenActions) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java index 9f78736..02441db 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java @@ -14,7 +14,9 @@ */ package me.filoghost.chestcommands.parsing.menu; +import com.google.common.collect.ImmutableList; import me.filoghost.chestcommands.action.Action; +import me.filoghost.chestcommands.util.collection.CollectionUtils; import java.util.List; @@ -25,8 +27,8 @@ public class MenuSettings { private final int rows; // Optional settings - private List commands; - private List openActions; + private ImmutableList commands; + private ImmutableList openActions; private int refreshTicks; private MenuOpenItem openItem; @@ -45,19 +47,19 @@ public class MenuSettings { } public void setCommands(List commands) { - this.commands = commands; + this.commands = CollectionUtils.immutableCopy(commands); } - public List getCommands() { + public ImmutableList getCommands() { return commands; } - public List getOpenActions() { + public ImmutableList getOpenActions() { return openActions; } public void setOpenActions(List openAction) { - this.openActions = openAction; + this.openActions = CollectionUtils.immutableCopy(openAction); } public int getRefreshTicks() { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java index d3b2908..9bc23f7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java @@ -19,6 +19,8 @@ import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.collection.CollectionUtils; import org.bukkit.entity.Player; +import java.util.List; + public class PlaceholderStringList { private final ImmutableList originalList; @@ -26,9 +28,9 @@ public class PlaceholderStringList { private final ImmutableList placeholderStringList; private final boolean hasDynamicPlaceholders; - public PlaceholderStringList(ImmutableList list) { + public PlaceholderStringList(List list) { Preconditions.notNull(list, "list"); - this.originalList = list; + this.originalList = ImmutableList.copyOf(list); // Replace static placeholders only once, if present if (PlaceholderManager.hasStaticPlaceholders(originalList)) { diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java index d4c56ef..93ff0fd 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java @@ -16,8 +16,6 @@ package me.filoghost.chestcommands.util; import org.bukkit.Material; -import java.util.Collection; - public final class Preconditions { @@ -27,13 +25,6 @@ public final class Preconditions { } } - public static void notEmpty(Collection collection, String objectName) { - notNull(collection, objectName); - if (collection.isEmpty()) { - throw new IllegalArgumentException(objectName + " cannot be empty"); - } - } - public static void checkArgument(boolean expression, String errorMessage) { if (!expression) { throw new IllegalArgumentException(errorMessage); diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java index ad3591a..97cba05 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java @@ -85,14 +85,14 @@ public final class Strings { } public static String capitalizeFirst(String input) { - if (isNullOrEmpty(input)) { + if (isEmpty(input)) { return input; } return Character.toTitleCase(input.charAt(0)) + input.substring(1); } - public static boolean isNullOrEmpty(String s) { + public static boolean isEmpty(String s) { return s == null || s.isEmpty(); } } diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java index f0ad021..810f7d3 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java @@ -17,7 +17,6 @@ package me.filoghost.chestcommands.util.collection; import com.google.common.collect.ImmutableList; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -25,27 +24,27 @@ import java.util.function.Function; public final class CollectionUtils { - public static boolean isNullOrEmpty(Collection collection) { - return collection == null || collection.isEmpty(); - } - - public static boolean isNullOrEmpty(Map map) { - return map == null || map.isEmpty(); - } - - public static List nullableCopy(List list) { - if (isNullOrEmpty(list)) { - return null; - } else { + public static List copy(List list) { + if (list != null) { return new ArrayList<>(list); + } else { + return null; } } - - public static Map nullableCopy(Map map) { - if (map == null || map.isEmpty()) { - return null; - } else { + + public static Map copy(Map map) { + if (map != null) { return new HashMap<>(map); + } else { + return null; + } + } + + public static ImmutableList immutableCopy(List list) { + if (list != null) { + return ImmutableList.copyOf(list); + } else { + return null; } } @@ -71,18 +70,8 @@ public final class CollectionUtils { return builder.build(); } - public static ImmutableList replaceNulls(List list, E replacement) { - ImmutableList.Builder builder = ImmutableList.builder(); - - for (E element : list) { - if (element != null) { - builder.add(element); - } else { - builder.add(replacement); - } - } - - return builder.build(); + public static List replaceNulls(List list, E replacement) { + return transform(list, element -> element != null ? element : replacement); } } From 4a5c06398f0a007caa2b40d2bc95cb36f0d5e050 Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 6 Aug 2020 18:43:10 +0200 Subject: [PATCH 167/213] Refactor and fix multiple required items --- .../icon/InternalConfigurableIcon.java | 4 +- .../requirement/item/InventoryTakeHelper.java | 79 +++++++++++++++++++ .../icon/requirement/item/RemainingItem.java | 43 ++++++++++ .../requirement/{ => item}/RequiredItem.java | 53 ++----------- .../requirement/{ => item}/RequiredItems.java | 40 +++++----- .../attribute/RequiredItemsAttribute.java | 2 +- 6 files changed, 150 insertions(+), 71 deletions(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RemainingItem.java rename Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/{ => item}/RequiredItem.java (56%) rename Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/{ => item}/RequiredItems.java (54%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java index 0a1fdbb..630725e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java @@ -20,11 +20,11 @@ import me.filoghost.chestcommands.action.OpenMenuAction; import me.filoghost.chestcommands.api.ClickResult; import me.filoghost.chestcommands.api.MenuInventory; import me.filoghost.chestcommands.icon.requirement.RequiredExpLevel; -import me.filoghost.chestcommands.icon.requirement.RequiredItem; -import me.filoghost.chestcommands.icon.requirement.RequiredItems; import me.filoghost.chestcommands.icon.requirement.RequiredMoney; import me.filoghost.chestcommands.icon.requirement.RequiredPermission; import me.filoghost.chestcommands.icon.requirement.Requirement; +import me.filoghost.chestcommands.icon.requirement.item.RequiredItem; +import me.filoghost.chestcommands.icon.requirement.item.RequiredItems; import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.collection.CollectionUtils; import org.bukkit.Material; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java new file mode 100644 index 0000000..7aaf469 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java @@ -0,0 +1,79 @@ +package me.filoghost.chestcommands.icon.requirement.item; + +import me.filoghost.chestcommands.util.MaterialsHelper; +import me.filoghost.chestcommands.util.Preconditions; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +public class InventoryTakeHelper { + + private final PlayerInventory inventory; + private final List remainingItems; + + private boolean success; + + public InventoryTakeHelper(PlayerInventory inventory) { + this.inventory = inventory; + this.remainingItems = new ArrayList<>(); + + for (int slotIndex = 0; slotIndex < inventory.getSize(); slotIndex++) { + ItemStack item = inventory.getItem(slotIndex); + if (item != null && !MaterialsHelper.isAir(item.getType())) { + remainingItems.add(new RemainingItem(slotIndex, item)); + } + } + } + + public List prepareTakeItems(List requiredItems) { + List missingItems = new ArrayList<>(); + + // Sort required items: check required items with a restrictive durability first + List sortedRequiredItems = requiredItems.stream() + .sorted(Comparator.comparing(RequiredItem::hasRestrictiveDurability).reversed()) + .collect(Collectors.toList()); + + for (RequiredItem requiredItem : sortedRequiredItems) { + int remainingRequiredAmount = requiredItem.getAmount(); + + for (RemainingItem remainingItem : remainingItems) { + if (remainingItem.getAmount() > 0 && requiredItem.isMatchingType(remainingItem)) { + int takenAmount = remainingItem.subtract(remainingRequiredAmount); + remainingRequiredAmount -= takenAmount; + if (remainingRequiredAmount == 0) { + break; + } + } + } + + // Couldn't take the required amount of an item + if (remainingRequiredAmount > 0) { + missingItems.add(requiredItem); + } + } + + success = missingItems.isEmpty(); + return missingItems; + } + + public void applyTakeItems() { + Preconditions.checkState(success, "items take preparation was not run or successful"); + + for (RemainingItem remainingItem : remainingItems) { + int slotIndex = remainingItem.getSlotIndex(); + ItemStack inventoryItem = inventory.getItem(slotIndex); + if (remainingItem.getAmount() != inventoryItem.getAmount()) { + if (remainingItem.getAmount() > 0) { + inventoryItem.setAmount(remainingItem.getAmount()); + } else { + inventory.setItem(slotIndex, null); + } + } + } + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RemainingItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RemainingItem.java new file mode 100644 index 0000000..a96bf6c --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RemainingItem.java @@ -0,0 +1,43 @@ +package me.filoghost.chestcommands.icon.requirement.item; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +public class RemainingItem { + + private final int slotIndex; + private final Material material; + private final short durability; + private int amount; + + public RemainingItem(int slotIndex, ItemStack item) { + this.slotIndex = slotIndex; + this.material = item.getType(); + this.durability = item.getDurability(); + this.amount = item.getAmount(); + } + + public int getSlotIndex() { + return slotIndex; + } + + public Material getMaterial() { + return material; + } + + public short getDurability() { + return durability; + } + + public int getAmount() { + return amount; + } + + public int subtract(int minusAmount) { + int subtractedAmount = Math.min(minusAmount, this.amount); + + this.amount -= subtractedAmount; + return subtractedAmount; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java similarity index 56% rename from Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItem.java rename to Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java index a776249..48c4ae9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java @@ -12,12 +12,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.icon.requirement; +package me.filoghost.chestcommands.icon.requirement.item; import me.filoghost.chestcommands.util.Preconditions; import org.bukkit.Material; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; public class RequiredItem { @@ -56,55 +54,16 @@ public class RequiredItem { return isDurabilityRestrictive; } - public boolean isItemContainedIn(Inventory inventory) { - int amountFound = 0; - - for (ItemStack item : inventory.getContents()) { - if (isMatchingType(item)) { - amountFound += item.getAmount(); - } - } - - return amountFound >= amount; - } - - public boolean takeItemFrom(Inventory inventory) { - if (amount <= 0) { - return true; - } - - int itemsToTake = amount; // Start from amount and decrease - ItemStack[] contents = inventory.getContents(); - - for (int i = 0; i < contents.length; i++) { - ItemStack current = contents[i]; - - if (isMatchingType(current)) { - if (current.getAmount() > itemsToTake) { - current.setAmount(current.getAmount() - itemsToTake); - return true; - } else { - itemsToTake -= current.getAmount(); - inventory.setItem(i, new ItemStack(Material.AIR)); - } - } - - // The end - if (itemsToTake <= 0) return true; - } - - return false; - } - - private boolean isMatchingType(ItemStack item) { - return item != null && item.getType() == material && isMatchingDurability(item.getDurability()); + public boolean isMatchingType(RemainingItem item) { + return item != null && item.getMaterial() == material && isMatchingDurability(item.getDurability()); } private boolean isMatchingDurability(short durability) { - if (!isDurabilityRestrictive) { + if (isDurabilityRestrictive) { + return this.durability == durability; + } else { return true; } - return this.durability == durability; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItems.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java similarity index 54% rename from Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItems.java rename to Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java index 583f210..e44e386 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredItems.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java @@ -12,10 +12,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.icon.requirement; +package me.filoghost.chestcommands.icon.requirement.item; import com.google.common.collect.ImmutableList; import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.icon.requirement.Requirement; import me.filoghost.chestcommands.util.Utils; import org.bukkit.entity.Player; @@ -31,34 +32,31 @@ public class RequiredItems implements Requirement { @Override public boolean hasCost(Player player) { - boolean missingItems = false; - - for (RequiredItem item : items) { - if (!item.isItemContainedIn(player.getInventory())) { - missingItems = true; - player.sendMessage(ChestCommands.getLang().no_required_item - .replace("{material}", Utils.formatEnum(item.getMaterial())) - .replace("{amount}", Integer.toString(item.getAmount())) - .replace("{durability}", item.hasRestrictiveDurability() ? Short.toString(item.getDurability()) : ChestCommands.getLang().any) - ); - } + InventoryTakeHelper inventoryTakeHelper = new InventoryTakeHelper(player.getInventory()); + List missingItems = inventoryTakeHelper.prepareTakeItems(items); + + for (RequiredItem item : missingItems) { + player.sendMessage(ChestCommands.getLang().no_required_item + .replace("{material}", Utils.formatEnum(item.getMaterial())) + .replace("{amount}", Integer.toString(item.getAmount())) + .replace("{durability}", item.hasRestrictiveDurability() ? Short.toString(item.getDurability()) : ChestCommands.getLang().any) + ); } - return !missingItems; + return missingItems.isEmpty(); } @Override public boolean takeCost(Player player) { - boolean missingItems = false; - - for (RequiredItem item : items) { - boolean success = item.takeItemFrom(player.getInventory()); - if (!success) { - missingItems = true; - } + InventoryTakeHelper inventoryTakeHelper = new InventoryTakeHelper(player.getInventory()); + List missingItems = inventoryTakeHelper.prepareTakeItems(items); + + if (!missingItems.isEmpty()) { + return false; } - return !missingItems; + inventoryTakeHelper.applyTakeItems(); + return true; } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/RequiredItemsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/RequiredItemsAttribute.java index 12da173..904f117 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/RequiredItemsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/RequiredItemsAttribute.java @@ -15,7 +15,7 @@ package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -import me.filoghost.chestcommands.icon.requirement.RequiredItem; +import me.filoghost.chestcommands.icon.requirement.item.RequiredItem; import me.filoghost.chestcommands.parsing.ItemStackParser; import me.filoghost.chestcommands.parsing.ParseException; From 36bb378e69ec1fbad03dfc635cf089a5d1b6e91e Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 7 Aug 2020 10:15:30 +0200 Subject: [PATCH 168/213] Handle unexpected exceptions better at startup --- .../chestcommands/BaseJavaPlugin.java | 30 ++++++++++++++----- .../logging/PrintableErrorCollector.java | 13 ++------ .../filoghost/chestcommands/util/Utils.java | 9 ++++++ 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java b/Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java index d0fcb37..6fdaf68 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java @@ -14,6 +14,7 @@ */ package me.filoghost.chestcommands; +import me.filoghost.chestcommands.util.Utils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.plugin.java.JavaPlugin; @@ -28,29 +29,42 @@ public abstract class BaseJavaPlugin extends JavaPlugin { try { onCheckedEnable(); } catch (PluginEnableException e) { - criticalShutdown(e.getMessage()); + criticalShutdown(e.getMessage(), null); + } catch (Throwable t) { + criticalShutdown(null, t); } } protected abstract void onCheckedEnable() throws PluginEnableException; - private void criticalShutdown(String errorMessage) { - Bukkit.getConsoleSender().sendMessage(getFatalErrorPrefix() + " " + errorMessage); + private void criticalShutdown(String errorMessage, Throwable throwable) { + Bukkit.getConsoleSender().sendMessage(getErrorMessage(errorMessage, throwable)); Bukkit.getScheduler().runTaskLater(this, () -> { - Bukkit.getConsoleSender().sendMessage(getPostStartupMessage(errorMessage)); + Bukkit.getConsoleSender().sendMessage( + getFatalErrorPrefix() + "Fatal error while enabling the plugin. Check previous logs for more information."); }, 10); setEnabled(false); } - protected String getPostStartupMessage(String errorMessage) { + protected String getErrorMessage(String errorMessage, Throwable throwable) { List output = new ArrayList<>(); - output.add(getFatalErrorPrefix()); + if (throwable != null) { + output.add(getFatalErrorPrefix() + "Fatal unexpected error while enabling plugin:"); + } else { + output.add(getFatalErrorPrefix() + "Fatal error while enabling plugin:"); + } + if (throwable != null) { + output.add(" "); + output.add(Utils.getStackTraceString(throwable)); + } output.add(" "); - output.add(errorMessage); + if (errorMessage != null) { + output.add(errorMessage); + } output.add("The plugin has been disabled."); output.add(" "); @@ -58,7 +72,7 @@ public abstract class BaseJavaPlugin extends JavaPlugin { } private String getFatalErrorPrefix() { - return ChatColor.DARK_RED + "[" + getDescription().getName() + "] " + ChatColor.RED + "Fatal error while enabling plugin:"; + return ChatColor.DARK_RED + "[" + getDescription().getName() + "] " + ChatColor.RED; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java index 26e0b22..fea66dd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java @@ -20,13 +20,12 @@ import me.filoghost.chestcommands.config.framework.exception.ConfigSyntaxExcepti import me.filoghost.chestcommands.legacy.UpgradeExecutorException; import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException; import me.filoghost.chestcommands.parsing.ParseException; +import me.filoghost.chestcommands.util.Utils; import me.filoghost.chestcommands.util.logging.ErrorCollector; import me.filoghost.chestcommands.util.logging.ErrorInfo; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import java.io.PrintWriter; -import java.io.StringWriter; import java.util.ArrayList; import java.util.List; @@ -77,7 +76,7 @@ public class PrintableErrorCollector extends ErrorCollector { } } - private void printError(StringBuilder output, ErrorPrintInfo error) { + private static void printError(StringBuilder output, ErrorPrintInfo error) { output.append(ChatColor.YELLOW).append(error.getIndex()).append(") "); output.append(ChatColor.WHITE).append(MessagePartJoiner.join(error.getMessage())); @@ -90,17 +89,11 @@ public class PrintableErrorCollector extends ErrorCollector { if (error.getCause() != null) { output.append(ChatColor.DARK_GRAY); output.append("--------[ Exception details ]--------\n"); - output.append(getStackTraceString(error.getCause())); + output.append(Utils.getStackTraceString(error.getCause())); output.append("-------------------------------------\n"); } output.append(" \n"); output.append(ChatColor.RESET); } - private String getStackTraceString(Throwable throwable) { - StringWriter stringWriter = new StringWriter(); - throwable.printStackTrace(new PrintWriter(stringWriter)); - return stringWriter.toString(); - } - } diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java index d98e6e6..17e2742 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java @@ -14,6 +14,9 @@ */ package me.filoghost.chestcommands.util; +import java.io.PrintWriter; +import java.io.StringWriter; + public class Utils { public static boolean isClassLoaded(String name) { @@ -40,4 +43,10 @@ public class Utils { } } + public static String getStackTraceString(Throwable throwable) { + StringWriter stringWriter = new StringWriter(); + throwable.printStackTrace(new PrintWriter(stringWriter)); + return stringWriter.toString(); + } + } From d971b6e5145cc4aa0ad1bf9153d1595509b63608 Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 7 Aug 2020 11:11:46 +0200 Subject: [PATCH 169/213] Clarify comment --- .../chestcommands/placeholder/scanner/PlaceholderMatch.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java index 372a685..50a8065 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java @@ -43,7 +43,10 @@ public class PlaceholderMatch { } /** - * Expected format: {pluginName/placeholder: argument} + * Valid formats: + * {pluginName/placeholder: argument} + * {placeholder: argument} + * {placeholder} */ public static PlaceholderMatch parse(String placeholderContent) { String explicitPluginName = null; From a845dbc0aed0295dbf87073f198a52e0f85fd22b Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 7 Aug 2020 11:29:40 +0200 Subject: [PATCH 170/213] Refactor Strings --- .../filoghost/chestcommands/util/Strings.java | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java b/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java index 97cba05..56e5911 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java +++ b/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java @@ -17,13 +17,13 @@ package me.filoghost.chestcommands.util; public final class Strings { - public static String[] trimmedSplit(String input, String pattern) { - return trimmedSplit(input, pattern, 0); + public static String[] trimmedSplit(String string, String pattern) { + return trimmedSplit(string, pattern, 0); } - public static String[] trimmedSplit(String input, String pattern, int limit) { - String[] output = input.split(pattern, limit); + public static String[] trimmedSplit(String string, String pattern, int limit) { + String[] output = string.split(pattern, limit); for (int i = 0; i < output.length; i++) { output[i] = output[i].trim(); } @@ -31,26 +31,26 @@ public final class Strings { } - public static String stripChars(String input, char... removed) { - if (input == null || input.isEmpty() || removed.length == 0) { - return input; + public static String stripChars(String string, char... charsToRemove) { + if (isEmpty(string) || charsToRemove.length == 0) { + return string; } - char[] chars = input.toCharArray(); + StringBuilder result = new StringBuilder(string.length()); - int pos = 0; - for (int i = 0; i < chars.length; i++) { - if (!arrayContains(removed, chars[i])) { - chars[(pos++)] = chars[i]; + for (int i = 0; i < string.length(); i++) { + char c = string.charAt(i); + if (!arrayContains(charsToRemove, c)) { + result.append(c); } } - return new String(chars, 0, pos); + return result.toString(); } - private static boolean arrayContains(char[] arr, char match) { - for (char c : arr) { - if (c == match) { + private static boolean arrayContains(char[] array, char valueToFind) { + for (char c : array) { + if (c == valueToFind) { return true; } } @@ -58,41 +58,41 @@ public final class Strings { return false; } - public static String capitalizeFully(String input) { - if (input == null) { - return null; + public static String capitalizeFully(String string) { + if (isEmpty(string)) { + return string; } - String s = input.toLowerCase(); - - int strLen = s.length(); - StringBuilder output = new StringBuilder(strLen); + string = string.toLowerCase(); + int length = string.length(); + StringBuilder result = new StringBuilder(length); boolean capitalizeNext = true; - for (int i = 0; i < strLen; i++) { - char ch = s.charAt(i); - if (Character.isWhitespace(ch)) { - output.append(ch); + for (int i = 0; i < length; i++) { + char c = string.charAt(i); + + if (Character.isWhitespace(c)) { + result.append(c); capitalizeNext = true; } else if (capitalizeNext) { - output.append(Character.toTitleCase(ch)); + result.append(Character.toTitleCase(c)); capitalizeNext = false; } else { - output.append(ch); + result.append(c); } } - return output.toString(); + return result.toString(); } - public static String capitalizeFirst(String input) { - if (isEmpty(input)) { - return input; + public static String capitalizeFirst(String string) { + if (isEmpty(string)) { + return string; } - return Character.toTitleCase(input.charAt(0)) + input.substring(1); + return Character.toTitleCase(string.charAt(0)) + string.substring(1); } - public static boolean isEmpty(String s) { - return s == null || s.isEmpty(); + public static boolean isEmpty(String string) { + return string == null || string.isEmpty(); } } From 294dc05fa35f27a8a565b9efe0174bb4802db7dc Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 7 Aug 2020 14:36:43 +0200 Subject: [PATCH 171/213] Refactor actions --- .../chestcommands/action/Action.java | 18 +-------- .../chestcommands/action/BroadcastAction.java | 4 +- .../action/ChangeServerAction.java | 4 +- .../action/ConsoleCommandAction.java | 4 +- .../chestcommands/action/DisabledAction.java | 32 ++++++++++++++++ .../chestcommands/action/DragonBarAction.java | 27 +++++++------ .../chestcommands/action/GiveItemAction.java | 17 +++------ .../chestcommands/action/GiveMoneyAction.java | 18 ++++----- .../chestcommands/action/OpCommandAction.java | 4 +- .../chestcommands/action/OpenMenuAction.java | 11 +++--- .../chestcommands/action/PlaySoundAction.java | 38 ++++++++++--------- .../action/PlayerCommandAction.java | 4 +- .../action/SendMessageAction.java | 4 +- .../filoghost/chestcommands/config/Lang.java | 3 +- .../icon/requirement/RequiredMoney.java | 8 ++-- .../chestcommands/logging/ErrorMessages.java | 36 +++++++++++++++++- .../chestcommands/parsing/ActionParser.java | 4 +- .../chestcommands/parsing/NumberParser.java | 15 ++++++-- .../parsing/attribute/ActionsAttribute.java | 11 +++++- .../parsing/menu/MenuParser.java | 10 ++++- 20 files changed, 173 insertions(+), 99 deletions(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/action/DisabledAction.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java index 0e3230a..426d0eb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java @@ -16,22 +16,8 @@ package me.filoghost.chestcommands.action; import org.bukkit.entity.Player; -public abstract class Action { +public interface Action { - private String errorMessage; - - protected void disable(String errorMessage) { - this.errorMessage = errorMessage; - } - - public final void execute(Player player) { - if (errorMessage != null) { - player.sendMessage(errorMessage); - } else { - execute0(player); - } - } - - protected abstract void execute0(Player player); + void execute(Player player); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java index 0a94c06..37edba7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java @@ -19,7 +19,7 @@ import me.filoghost.chestcommands.util.Colors; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -public class BroadcastAction extends Action { +public class BroadcastAction implements Action { private final PlaceholderString message; @@ -28,7 +28,7 @@ public class BroadcastAction extends Action { } @Override - protected void execute0(Player player) { + public void execute(Player player) { Bukkit.broadcastMessage(message.getValue(player)); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java index 9c48b0b..e54a906 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java @@ -18,7 +18,7 @@ import me.filoghost.chestcommands.hook.BungeeCordHook; import me.filoghost.chestcommands.placeholder.PlaceholderString; import org.bukkit.entity.Player; -public class ChangeServerAction extends Action { +public class ChangeServerAction implements Action { private final PlaceholderString targetServer; @@ -27,7 +27,7 @@ public class ChangeServerAction extends Action { } @Override - protected void execute0(Player player) { + public void execute(Player player) { BungeeCordHook.connect(player, targetServer.getValue(player)); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java index b920f64..c23db2e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java @@ -18,7 +18,7 @@ import me.filoghost.chestcommands.placeholder.PlaceholderString; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -public class ConsoleCommandAction extends Action { +public class ConsoleCommandAction implements Action { private final PlaceholderString command; @@ -27,7 +27,7 @@ public class ConsoleCommandAction extends Action { } @Override - protected void execute0(Player player) { + public void execute(Player player) { Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.getValue(player)); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/DisabledAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/DisabledAction.java new file mode 100644 index 0000000..4caf9d3 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/DisabledAction.java @@ -0,0 +1,32 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.action; + +import org.bukkit.entity.Player; + +public class DisabledAction implements Action { + + private final String errorMessage; + + public DisabledAction(String errorMessage) { + this.errorMessage = errorMessage; + } + + @Override + public void execute(Player player) { + player.sendMessage(errorMessage); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java index 008cdb7..bef01b7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java @@ -15,41 +15,44 @@ package me.filoghost.chestcommands.action; import me.filoghost.chestcommands.hook.BarAPIHook; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.NumberParser; import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.chestcommands.placeholder.PlaceholderString; import me.filoghost.chestcommands.util.Colors; import me.filoghost.chestcommands.util.Strings; -import org.bukkit.ChatColor; import org.bukkit.entity.Player; -public class DragonBarAction extends Action { +public class DragonBarAction implements Action { - private PlaceholderString message; - private int seconds; + private final PlaceholderString message; + private final int seconds; + + public DragonBarAction(String serialiazedAction) throws ParseException { + String message; - public DragonBarAction(String serialiazedAction) { - seconds = 1; - String message = serialiazedAction; - String[] split = Strings.trimmedSplit(serialiazedAction, "\\|", 2); // Max of 2 pieces if (split.length > 1) { try { seconds = NumberParser.getStrictlyPositiveInteger(split[0]); message = split[1]; - } catch (ParseException ex) { - disable(ChatColor.RED + "Invalid dragon bar time \"" + split[0] + "\": " + ex.getMessage()); - return; + } catch (ParseException e) { + throw new ParseException(ErrorMessages.Parsing.invalidBossBarTime(split[0]), e); } + } else { + seconds = 1; + message = serialiazedAction; } this.message = PlaceholderString.of(Colors.addColors(message)); } @Override - protected void execute0(Player player) { + public void execute(Player player) { if (BarAPIHook.INSTANCE.isEnabled()) { BarAPIHook.setMessage(player, message.getValue(player), seconds); + } else { + player.sendMessage(ErrorMessages.User.configurationError("BarAPI plugin not found")); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java index 85956fd..b5c374a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java @@ -16,25 +16,20 @@ package me.filoghost.chestcommands.action; import me.filoghost.chestcommands.parsing.ItemStackParser; import me.filoghost.chestcommands.parsing.ParseException; -import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -public class GiveItemAction extends Action { +public class GiveItemAction implements Action { - private ItemStack itemToGive; + private final ItemStack itemToGive; - public GiveItemAction(String serializedAction) { - try { - ItemStackParser reader = new ItemStackParser(serializedAction, true); - itemToGive = reader.createStack(); - } catch (ParseException e) { - disable(ChatColor.RED + "Invalid item to give: " + e.getMessage()); - } + public GiveItemAction(String serializedAction) throws ParseException { + ItemStackParser reader = new ItemStackParser(serializedAction, true); + itemToGive = reader.createStack(); } @Override - protected void execute0(Player player) { + public void execute(Player player) { player.getInventory().addItem(itemToGive.clone()); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java index de15f04..7e84c4e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java @@ -15,29 +15,25 @@ package me.filoghost.chestcommands.action; import me.filoghost.chestcommands.hook.VaultEconomyHook; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.NumberParser; import me.filoghost.chestcommands.parsing.ParseException; -import org.bukkit.ChatColor; import org.bukkit.entity.Player; -public class GiveMoneyAction extends Action { +public class GiveMoneyAction implements Action { - private double moneyToGive; + private final double moneyToGive; - public GiveMoneyAction(String serializedAction) { - try { - moneyToGive = NumberParser.getStrictlyPositiveDouble(serializedAction); - } catch (ParseException e) { - disable(ChatColor.RED + "Invalid money amount \"" + serializedAction + "\": " + e.getMessage()); - } + public GiveMoneyAction(String serializedAction) throws ParseException { + moneyToGive = NumberParser.getStrictlyPositiveDouble(serializedAction); } @Override - protected void execute0(Player player) { + public void execute(Player player) { if (VaultEconomyHook.INSTANCE.isEnabled()) { VaultEconomyHook.giveMoney(player, moneyToGive); } else { - player.sendMessage(ChatColor.RED + "Vault with a compatible economy plugin not found. Please inform the staff."); + player.sendMessage(ErrorMessages.User.configurationError("Vault with a compatible economy plugin not found")); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java index 58db352..7881a0e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java @@ -17,7 +17,7 @@ package me.filoghost.chestcommands.action; import me.filoghost.chestcommands.placeholder.PlaceholderString; import org.bukkit.entity.Player; -public class OpCommandAction extends Action { +public class OpCommandAction implements Action { private final PlaceholderString command; @@ -26,7 +26,7 @@ public class OpCommandAction extends Action { } @Override - protected void execute0(Player player) { + public void execute(Player player) { if (player.isOp()) { player.chat("/" + command.getValue(player)); } else { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java index f6b3a6c..8ea97ea 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java @@ -15,13 +15,13 @@ package me.filoghost.chestcommands.action; import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.menu.InternalIconMenu; import me.filoghost.chestcommands.placeholder.PlaceholderString; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.entity.Player; -public class OpenMenuAction extends Action { +public class OpenMenuAction implements Action { private final PlaceholderString targetMenu; @@ -30,8 +30,9 @@ public class OpenMenuAction extends Action { } @Override - protected void execute0(final Player player) { - final InternalIconMenu menu = ChestCommands.getMenuManager().getMenuByFileName(targetMenu.getValue(player)); + public void execute(final Player player) { + String menuName = targetMenu.getValue(player); + final InternalIconMenu menu = ChestCommands.getMenuManager().getMenuByFileName(menuName); if (menu != null) { /* @@ -43,7 +44,7 @@ public class OpenMenuAction extends Action { }); } else { - player.sendMessage(ChatColor.RED + "Menu not found! Please inform the staff."); + player.sendMessage(ErrorMessages.User.configurationError("couldn't find the menu \"" + menuName + "\"")); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java index 6db31ab..05f0e1c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java @@ -14,54 +14,56 @@ */ package me.filoghost.chestcommands.action; +import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.parsing.NumberParser; +import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.chestcommands.util.Strings; import me.filoghost.chestcommands.util.collection.Registry; -import org.bukkit.ChatColor; import org.bukkit.Sound; import org.bukkit.entity.Player; import java.util.Optional; -public class PlaySoundAction extends Action { +public class PlaySoundAction implements Action { private static final Registry SOUNDS_REGISTRY = Registry.fromEnumValues(Sound.class); - private Sound sound; - private float pitch; - private float volume; - - public PlaySoundAction(String serializedAction) { - pitch = 1.0f; - volume = 1.0f; + private final Sound sound; + private final float pitch; + private final float volume; + public PlaySoundAction(String serializedAction) throws ParseException { String[] split = Strings.trimmedSplit(serializedAction, ",", 3); Optional sound = SOUNDS_REGISTRY.find(split[0]); if (!sound.isPresent()) { - disable(ChatColor.RED + "Invalid sound \"" + split[0] + "\"."); - return; + throw new ParseException(ErrorMessages.Parsing.unknownSound(split[0])); } this.sound = sound.get(); if (split.length > 1) { try { - pitch = Float.parseFloat(split[1]); - } catch (NumberFormatException e) { - // TODO + pitch = NumberParser.getFloat(split[1]); + } catch (ParseException e) { + throw new ParseException(ErrorMessages.Parsing.invalidSoundPitch(split[1]), e); } + } else { + pitch = 1.0f; } if (split.length > 2) { try { - volume = Float.parseFloat(split[2]); - } catch (NumberFormatException e) { - // TODO + volume = NumberParser.getFloat(split[2]); + } catch (ParseException e) { + throw new ParseException(ErrorMessages.Parsing.invalidSoundVolume(split[2]), e); } + } else { + volume = 1.0f; } } @Override - protected void execute0(Player player) { + public void execute(Player player) { player.playSound(player.getLocation(), sound, volume, pitch); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java index 5aff43f..9efeec7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java @@ -17,7 +17,7 @@ package me.filoghost.chestcommands.action; import me.filoghost.chestcommands.placeholder.PlaceholderString; import org.bukkit.entity.Player; -public class PlayerCommandAction extends Action { +public class PlayerCommandAction implements Action { private final PlaceholderString command; @@ -26,7 +26,7 @@ public class PlayerCommandAction extends Action { } @Override - protected void execute0(Player player) { + public void execute(Player player) { player.chat('/' + command.getValue(player)); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java index 16aa216..d085857 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java @@ -18,7 +18,7 @@ import me.filoghost.chestcommands.placeholder.PlaceholderString; import me.filoghost.chestcommands.util.Colors; import org.bukkit.entity.Player; -public class SendMessageAction extends Action { +public class SendMessageAction implements Action { private final PlaceholderString message; @@ -27,7 +27,7 @@ public class SendMessageAction extends Action { } @Override - protected void execute0(Player player) { + public void execute(Player player) { player.sendMessage(message.getValue(player)); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java index 3cdf819..a2a05ab 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java @@ -16,6 +16,7 @@ package me.filoghost.chestcommands.config; import me.filoghost.chestcommands.config.framework.mapped.MappedConfig; import me.filoghost.chestcommands.config.framework.mapped.modifier.ChatColors; +import me.filoghost.chestcommands.logging.ErrorMessages; @ChatColors public class Lang extends MappedConfig { @@ -25,7 +26,7 @@ public class Lang extends MappedConfig { public String no_required_item = "&cYou must have &e{amount}x {material} &c(durability: {durability}) for this."; public String no_money = "&cYou need {money}$ for this."; public String no_exp = "&cYou need {levels} XP levels for this."; - public String menu_not_found = "&cMenu not found! Please inform the staff."; + public String menu_not_found = "&cMenu not found! " + ErrorMessages.User.notifyStaffRequest; public String open_menu = "&aOpening the menu \"{menu}\"."; public String open_menu_others = "&aOpening the menu \"{menu}\" to {player}."; public String any = "any"; // Used in no_required_item when durability is not restrictive diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java index ae23779..8aeedd5 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java @@ -17,7 +17,7 @@ package me.filoghost.chestcommands.icon.requirement; import com.google.common.base.Preconditions; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.hook.VaultEconomyHook; -import org.bukkit.ChatColor; +import me.filoghost.chestcommands.logging.ErrorMessages; import org.bukkit.entity.Player; public class RequiredMoney implements Requirement { @@ -32,7 +32,9 @@ public class RequiredMoney implements Requirement { @Override public boolean hasCost(Player player) { if (!VaultEconomyHook.INSTANCE.isEnabled()) { - player.sendMessage(ChatColor.RED + "This action has a price, but Vault with a compatible economy plugin was not found. For security, the action has been blocked. Please inform the staff."); + player.sendMessage(ErrorMessages.User.configurationError( + "the item has a price, but Vault with a compatible economy plugin was not found. " + + "For security, the action has been blocked")); return false; } @@ -49,7 +51,7 @@ public class RequiredMoney implements Requirement { boolean success = VaultEconomyHook.takeMoney(player, moneyAmount); if (!success) { - player.sendMessage(ChatColor.RED + "Error: a money transaction couldn't be executed. Please inform the staff."); + player.sendMessage(ErrorMessages.User.configurationError("a money transaction couldn't be executed")); } return success; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java index 852e35b..b5de737 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java @@ -20,6 +20,7 @@ import me.filoghost.chestcommands.config.framework.mapped.MappedField; import me.filoghost.chestcommands.config.framework.mapped.converter.Converter; import me.filoghost.chestcommands.parsing.icon.AttributeType; import me.filoghost.chestcommands.parsing.icon.IconSettings; +import org.bukkit.ChatColor; import java.nio.file.Path; @@ -119,9 +120,9 @@ public class ErrorMessages { public static class Parsing { - public static final String invalidDouble = "value is not a valid decimal"; + public static final String invalidDecimal = "value is not a valid decimal"; public static final String invalidShort = "value is not a valid short integer"; - public static final String invalidInteger = "value not a valid integer"; + public static final String invalidInteger = "value is not a valid integer"; public static final String strictlyPositive = "value must be greater than zero"; public static final String zeroOrPositive = "value must be zero or greater"; @@ -167,6 +168,22 @@ public class ErrorMessages { return "invalid " + colorName + " color \"" + valueString + "\", value must be between 0 and 255"; } + public static String invalidBossBarTime(String timeString) { + return "invalid dragon bar time \"" + timeString + "\""; + } + + public static String invalidSoundPitch(String pitchString) { + return "invalid sound pitch \"" + pitchString + "\""; + } + + public static String invalidSoundVolume(String volumeString) { + return "invalid sound volume \"" + volumeString + "\""; + } + + public static String unknownSound(String soundString) { + return "unknown sound \"" + soundString + "\""; + } + } public static class Menu { @@ -183,6 +200,12 @@ public class ErrorMessages { return menuError(menuFile, "is missing the menu setting section"); } + public static String invalidSettingListElement(Path menuFile, String invalidSetting, String listElement) { + return menuError(menuFile, + "contains an invalid list element (\"" + listElement + "\") " + + "in the menu setting \"" + invalidSetting + "\""); + } + private static String menuError(Path menuFile, String errorMessage) { return "the menu \"" + formatPath(menuFile) + "\" " + errorMessage; } @@ -225,6 +248,15 @@ public class ErrorMessages { } } + public static class User { + + public static String notifyStaffRequest = "Please inform the staff."; + + public static String configurationError(String errorMessage) { + return ChatColor.RED + "Error: " + errorMessage + ". " + ErrorMessages.User.notifyStaffRequest; + } + + } private static String formatPath(Path path) { if (path.startsWith(ChestCommands.getDataFolderPath())) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java index c9fcab3..093f254 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java @@ -32,7 +32,7 @@ import java.util.regex.Pattern; public class ActionParser { - public static Action parse(String serializedAction) { + public static Action parse(String serializedAction) throws ParseException { for (ActionType actionType : ActionType.values()) { Matcher matcher = actionType.prefixPattern.matcher(serializedAction); if (matcher.find()) { @@ -72,7 +72,7 @@ public class ActionParser { @FunctionalInterface private interface ActionFactory { - Action create(String serializedAction); + Action create(String serializedAction) throws ParseException; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java index a7fa188..58d7a03 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java @@ -28,10 +28,18 @@ public class NumberParser { try { return Double.parseDouble(input); } catch (NumberFormatException ex) { - throw new ParseException(ErrorMessages.Parsing.invalidDouble); + throw new ParseException(ErrorMessages.Parsing.invalidDecimal); } } - + + public static float getFloat(String input) throws ParseException { + try { + return Float.parseFloat(input); + } catch (NumberFormatException ex) { + throw new ParseException(ErrorMessages.Parsing.invalidDecimal); + } + } + public static short getPositiveShort(String input) throws ParseException { short value = getShort(input); check(value >= 0, ErrorMessages.Parsing.zeroOrPositive); @@ -59,11 +67,10 @@ public class NumberParser { throw new ParseException(ErrorMessages.Parsing.invalidInteger); } } - + private static void check(boolean expression, String errorMessage) throws ParseException { if (!expression) { throw new ParseException(errorMessage); } } - } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ActionsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ActionsAttribute.java index 3f84cc0..75e3207 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ActionsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ActionsAttribute.java @@ -15,8 +15,11 @@ package me.filoghost.chestcommands.parsing.attribute; import me.filoghost.chestcommands.action.Action; +import me.filoghost.chestcommands.action.DisabledAction; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; +import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ActionParser; +import me.filoghost.chestcommands.parsing.ParseException; import java.util.ArrayList; import java.util.List; @@ -33,7 +36,13 @@ public class ActionsAttribute implements ApplicableIconAttribute { continue; // Skip } - actions.add(ActionParser.parse(serializedAction)); + try { + actions.add(ActionParser.parse(serializedAction)); + } catch (ParseException e) { + actions.add(new DisabledAction(ErrorMessages.User.configurationError( + "an action linked to clicking this icon was not executed because it was not valid"))); + errorHandler.onListElementError(serializedAction, e); + } } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index 5945e5c..d8aec1f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -15,6 +15,7 @@ package me.filoghost.chestcommands.parsing.menu; import me.filoghost.chestcommands.action.Action; +import me.filoghost.chestcommands.action.DisabledAction; import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.config.framework.ConfigSection; import me.filoghost.chestcommands.config.framework.EmptyConfigSection; @@ -136,7 +137,14 @@ public class MenuParser { for (String serializedAction : serializedOpenActions) { if (serializedAction != null && !serializedAction.isEmpty()) { - openActions.add(ActionParser.parse(serializedAction)); + try { + openActions.add(ActionParser.parse(serializedAction)); + } catch (ParseException e) { + errorCollector.add(ErrorMessages.Menu.invalidSettingListElement( + config.getSourceFile(), MenuSettingsNode.OPEN_ACTIONS, serializedAction), e); + openActions.add(new DisabledAction(ErrorMessages.User.configurationError( + "an action linked to opening this menu was not executed because it was not valid"))); + } } } From 1f1a9a20f815a2b5cefbd13cbe99925e2ab591b5 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 9 Aug 2020 20:43:06 +0200 Subject: [PATCH 172/213] Move attributes to main package and cleanup --- .../attribute/ActionsAttribute.java | 4 +- .../attribute/AmountAttribute.java | 4 +- .../attribute/AttributeErrorHandler.java | 2 +- .../attribute/BannerColorAttribute.java | 4 +- .../attribute/BannerPatternsAttribute.java | 4 +- .../attribute/ClickPermissionAttribute.java | 4 +- .../ClickPermissionMessageAttribute.java | 4 +- .../attribute/DurabilityAttribute.java | 4 +- .../attribute/EnchantmentsAttribute.java | 4 +- .../attribute/ExpLevelsAttribute.java | 4 +- .../attribute/IconAttribute.java | 7 ++- .../attribute/KeepOpenAttribute.java | 4 +- .../attribute/LeatherColorAttribute.java | 4 +- .../attribute/LoreAttribute.java | 4 +- .../attribute/MaterialAttribute.java | 4 +- .../attribute/NBTDataAttribute.java | 4 +- .../attribute/NameAttribute.java | 4 +- .../attribute/PositionAttribute.java | 8 +++- .../attribute/PriceAttribute.java | 4 +- .../attribute/RequiredItemsAttribute.java | 4 +- .../attribute/SkullOwnerAttribute.java | 4 +- .../attribute/ViewPermissionAttribute.java | 4 +- .../attribute/ApplicableIconAttribute.java | 23 ---------- .../parsing/icon/AttributeType.java | 44 +++++++++---------- .../parsing/icon/IconSettings.java | 9 ++-- .../parsing/menu/MenuParser.java | 2 +- 26 files changed, 77 insertions(+), 94 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/ActionsAttribute.java (93%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/AmountAttribute.java (90%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/AttributeErrorHandler.java (93%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/BannerColorAttribute.java (90%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/BannerPatternsAttribute.java (92%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/ClickPermissionAttribute.java (88%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/ClickPermissionMessageAttribute.java (88%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/DurabilityAttribute.java (88%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/EnchantmentsAttribute.java (93%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/ExpLevelsAttribute.java (90%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/IconAttribute.java (81%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/KeepOpenAttribute.java (90%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/LeatherColorAttribute.java (90%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/LoreAttribute.java (92%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/MaterialAttribute.java (92%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/NBTDataAttribute.java (91%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/NameAttribute.java (92%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/PositionAttribute.java (80%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/PriceAttribute.java (90%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/RequiredItemsAttribute.java (93%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/SkullOwnerAttribute.java (88%) rename Plugin/src/main/java/me/filoghost/chestcommands/{parsing => }/attribute/ViewPermissionAttribute.java (88%) delete mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ApplicableIconAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ActionsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ActionsAttribute.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ActionsAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/ActionsAttribute.java index 75e3207..e60d9ee 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ActionsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ActionsAttribute.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.DisabledAction; @@ -24,7 +24,7 @@ import me.filoghost.chestcommands.parsing.ParseException; import java.util.ArrayList; import java.util.List; -public class ActionsAttribute implements ApplicableIconAttribute { +public class ActionsAttribute implements IconAttribute { private final List actions; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/AmountAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/AmountAttribute.java similarity index 90% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/AmountAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/AmountAttribute.java index 679e8ce..f1fa126 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/AmountAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/AmountAttribute.java @@ -12,13 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ParseException; -public class AmountAttribute implements ApplicableIconAttribute { +public class AmountAttribute implements IconAttribute { private final int amount; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/AttributeErrorHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/AttributeErrorHandler.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/AttributeErrorHandler.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/AttributeErrorHandler.java index acc9759..8927ec6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/AttributeErrorHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/AttributeErrorHandler.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.parsing.ParseException; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/BannerColorAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerColorAttribute.java similarity index 90% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/BannerColorAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerColorAttribute.java index 6c0249d..7294c84 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/BannerColorAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerColorAttribute.java @@ -12,14 +12,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.parsing.ItemMetaParser; import me.filoghost.chestcommands.parsing.ParseException; import org.bukkit.DyeColor; -public class BannerColorAttribute implements ApplicableIconAttribute { +public class BannerColorAttribute implements IconAttribute { private final DyeColor dyeColor; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/BannerPatternsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerPatternsAttribute.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/BannerPatternsAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerPatternsAttribute.java index 36d96a5..55d4286 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/BannerPatternsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerPatternsAttribute.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.parsing.ItemMetaParser; @@ -22,7 +22,7 @@ import org.bukkit.block.banner.Pattern; import java.util.ArrayList; import java.util.List; -public class BannerPatternsAttribute implements ApplicableIconAttribute { +public class BannerPatternsAttribute implements IconAttribute { private final List patterns; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ClickPermissionAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionAttribute.java similarity index 88% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ClickPermissionAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionAttribute.java index cba87b2..94993ab 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ClickPermissionAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionAttribute.java @@ -12,11 +12,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -public class ClickPermissionAttribute implements ApplicableIconAttribute { +public class ClickPermissionAttribute implements IconAttribute { private final String clickPermission; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ClickPermissionMessageAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionMessageAttribute.java similarity index 88% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ClickPermissionMessageAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionMessageAttribute.java index 270eeea..d4e78e3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ClickPermissionMessageAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionMessageAttribute.java @@ -12,11 +12,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -public class ClickPermissionMessageAttribute implements ApplicableIconAttribute { +public class ClickPermissionMessageAttribute implements IconAttribute { private final String clickPermissionMessage; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/DurabilityAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/DurabilityAttribute.java similarity index 88% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/DurabilityAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/DurabilityAttribute.java index 750254d..fe022b6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/DurabilityAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/DurabilityAttribute.java @@ -12,11 +12,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -public class DurabilityAttribute implements ApplicableIconAttribute { +public class DurabilityAttribute implements IconAttribute { private final short durability; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/EnchantmentsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/EnchantmentsAttribute.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/EnchantmentsAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/EnchantmentsAttribute.java index 657c54b..f6fc1ef 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/EnchantmentsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/EnchantmentsAttribute.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.parsing.EnchantmentParser; @@ -23,7 +23,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -public class EnchantmentsAttribute implements ApplicableIconAttribute { +public class EnchantmentsAttribute implements IconAttribute { private final Map enchantments; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ExpLevelsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ExpLevelsAttribute.java similarity index 90% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ExpLevelsAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/ExpLevelsAttribute.java index b362f53..8fc4f59 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ExpLevelsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ExpLevelsAttribute.java @@ -12,13 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ParseException; -public class ExpLevelsAttribute implements ApplicableIconAttribute { +public class ExpLevelsAttribute implements IconAttribute { private final int expLevels; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/IconAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/IconAttribute.java similarity index 81% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/IconAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/IconAttribute.java index 35998c8..275deaa 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/IconAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/IconAttribute.java @@ -12,8 +12,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; + +import me.filoghost.chestcommands.icon.InternalConfigurableIcon; public interface IconAttribute { - + + void apply(InternalConfigurableIcon icon); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/KeepOpenAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/KeepOpenAttribute.java similarity index 90% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/KeepOpenAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/KeepOpenAttribute.java index 4695850..7631885 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/KeepOpenAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/KeepOpenAttribute.java @@ -12,12 +12,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.api.ClickResult; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -public class KeepOpenAttribute implements ApplicableIconAttribute { +public class KeepOpenAttribute implements IconAttribute { private final ClickResult clickResult; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/LeatherColorAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LeatherColorAttribute.java similarity index 90% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/LeatherColorAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/LeatherColorAttribute.java index 799fa86..39a60b3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/LeatherColorAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LeatherColorAttribute.java @@ -12,14 +12,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.parsing.ItemMetaParser; import me.filoghost.chestcommands.parsing.ParseException; import org.bukkit.Color; -public class LeatherColorAttribute implements ApplicableIconAttribute { +public class LeatherColorAttribute implements IconAttribute { private final Color color; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/LoreAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/LoreAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java index f68cadd..f547878 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/LoreAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; @@ -22,7 +22,7 @@ import org.bukkit.ChatColor; import java.util.List; -public class LoreAttribute implements ApplicableIconAttribute { +public class LoreAttribute implements IconAttribute { private final List lore; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/MaterialAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/MaterialAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java index 448f18e..9488436 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/MaterialAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.logging.ErrorMessages; @@ -22,7 +22,7 @@ import org.bukkit.Material; import java.util.Optional; -public class MaterialAttribute implements ApplicableIconAttribute { +public class MaterialAttribute implements IconAttribute { private final Material material; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/NBTDataAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NBTDataAttribute.java similarity index 91% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/NBTDataAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/NBTDataAttribute.java index b063ecb..a7506de 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/NBTDataAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NBTDataAttribute.java @@ -12,14 +12,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.chestcommands.util.nbt.parser.MojangsonParseException; import me.filoghost.chestcommands.util.nbt.parser.MojangsonParser; -public class NBTDataAttribute implements ApplicableIconAttribute { +public class NBTDataAttribute implements IconAttribute { private final String nbtData; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/NameAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/NameAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java index 8a566e8..b46e101 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/NameAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java @@ -12,14 +12,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.util.Colors; import org.bukkit.ChatColor; -public class NameAttribute implements ApplicableIconAttribute { +public class NameAttribute implements IconAttribute { private final String name; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/PositionAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/PositionAttribute.java similarity index 80% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/PositionAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/PositionAttribute.java index 848ea3e..4f15914 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/PositionAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/PositionAttribute.java @@ -12,7 +12,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; + +import me.filoghost.chestcommands.icon.InternalConfigurableIcon; public class PositionAttribute implements IconAttribute { @@ -26,4 +28,8 @@ public class PositionAttribute implements IconAttribute { return position; } + @Override + public void apply(InternalConfigurableIcon icon) { + // Position has no effect on the icon itself + } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/PriceAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/PriceAttribute.java similarity index 90% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/PriceAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/PriceAttribute.java index 4a99f67..3671764 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/PriceAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/PriceAttribute.java @@ -12,13 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ParseException; -public class PriceAttribute implements ApplicableIconAttribute { +public class PriceAttribute implements IconAttribute { private final double price; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/RequiredItemsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/RequiredItemsAttribute.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/RequiredItemsAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/RequiredItemsAttribute.java index 904f117..6da89de 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/RequiredItemsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/RequiredItemsAttribute.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.icon.requirement.item.RequiredItem; @@ -22,7 +22,7 @@ import me.filoghost.chestcommands.parsing.ParseException; import java.util.ArrayList; import java.util.List; -public class RequiredItemsAttribute implements ApplicableIconAttribute { +public class RequiredItemsAttribute implements IconAttribute { private final List requiredItems; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/SkullOwnerAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/SkullOwnerAttribute.java similarity index 88% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/SkullOwnerAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/SkullOwnerAttribute.java index dd7b810..9e4204d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/SkullOwnerAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/SkullOwnerAttribute.java @@ -12,11 +12,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -public class SkullOwnerAttribute implements ApplicableIconAttribute { +public class SkullOwnerAttribute implements IconAttribute { private final String skullOwner; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ViewPermissionAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ViewPermissionAttribute.java similarity index 88% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ViewPermissionAttribute.java rename to Plugin/src/main/java/me/filoghost/chestcommands/attribute/ViewPermissionAttribute.java index 094c863..e5bb9db 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ViewPermissionAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ViewPermissionAttribute.java @@ -12,11 +12,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.parsing.attribute; +package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -public class ViewPermissionAttribute implements ApplicableIconAttribute { +public class ViewPermissionAttribute implements IconAttribute { private final String viewPermission; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ApplicableIconAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ApplicableIconAttribute.java deleted file mode 100644 index 805d98b..0000000 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/attribute/ApplicableIconAttribute.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.parsing.attribute; - -import me.filoghost.chestcommands.icon.InternalConfigurableIcon; - -public interface ApplicableIconAttribute extends IconAttribute { - - void apply(InternalConfigurableIcon icon); - -} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java index ce2c980..9cbdaad 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java @@ -14,32 +14,32 @@ */ package me.filoghost.chestcommands.parsing.icon; +import me.filoghost.chestcommands.attribute.ActionsAttribute; +import me.filoghost.chestcommands.attribute.AmountAttribute; +import me.filoghost.chestcommands.attribute.AttributeErrorHandler; +import me.filoghost.chestcommands.attribute.BannerColorAttribute; +import me.filoghost.chestcommands.attribute.BannerPatternsAttribute; +import me.filoghost.chestcommands.attribute.ClickPermissionAttribute; +import me.filoghost.chestcommands.attribute.ClickPermissionMessageAttribute; +import me.filoghost.chestcommands.attribute.DurabilityAttribute; +import me.filoghost.chestcommands.attribute.EnchantmentsAttribute; +import me.filoghost.chestcommands.attribute.ExpLevelsAttribute; +import me.filoghost.chestcommands.attribute.IconAttribute; +import me.filoghost.chestcommands.attribute.KeepOpenAttribute; +import me.filoghost.chestcommands.attribute.LeatherColorAttribute; +import me.filoghost.chestcommands.attribute.LoreAttribute; +import me.filoghost.chestcommands.attribute.MaterialAttribute; +import me.filoghost.chestcommands.attribute.NBTDataAttribute; +import me.filoghost.chestcommands.attribute.NameAttribute; +import me.filoghost.chestcommands.attribute.PositionAttribute; +import me.filoghost.chestcommands.attribute.PriceAttribute; +import me.filoghost.chestcommands.attribute.RequiredItemsAttribute; +import me.filoghost.chestcommands.attribute.SkullOwnerAttribute; +import me.filoghost.chestcommands.attribute.ViewPermissionAttribute; import me.filoghost.chestcommands.config.framework.ConfigValue; import me.filoghost.chestcommands.config.framework.ConfigValueType; import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.parsing.attribute.ActionsAttribute; -import me.filoghost.chestcommands.parsing.attribute.AmountAttribute; -import me.filoghost.chestcommands.parsing.attribute.AttributeErrorHandler; -import me.filoghost.chestcommands.parsing.attribute.BannerColorAttribute; -import me.filoghost.chestcommands.parsing.attribute.BannerPatternsAttribute; -import me.filoghost.chestcommands.parsing.attribute.ClickPermissionAttribute; -import me.filoghost.chestcommands.parsing.attribute.ClickPermissionMessageAttribute; -import me.filoghost.chestcommands.parsing.attribute.DurabilityAttribute; -import me.filoghost.chestcommands.parsing.attribute.EnchantmentsAttribute; -import me.filoghost.chestcommands.parsing.attribute.ExpLevelsAttribute; -import me.filoghost.chestcommands.parsing.attribute.IconAttribute; -import me.filoghost.chestcommands.parsing.attribute.KeepOpenAttribute; -import me.filoghost.chestcommands.parsing.attribute.LeatherColorAttribute; -import me.filoghost.chestcommands.parsing.attribute.LoreAttribute; -import me.filoghost.chestcommands.parsing.attribute.MaterialAttribute; -import me.filoghost.chestcommands.parsing.attribute.NBTDataAttribute; -import me.filoghost.chestcommands.parsing.attribute.NameAttribute; -import me.filoghost.chestcommands.parsing.attribute.PositionAttribute; -import me.filoghost.chestcommands.parsing.attribute.PriceAttribute; -import me.filoghost.chestcommands.parsing.attribute.RequiredItemsAttribute; -import me.filoghost.chestcommands.parsing.attribute.SkullOwnerAttribute; -import me.filoghost.chestcommands.parsing.attribute.ViewPermissionAttribute; import java.util.HashMap; import java.util.Map; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java index 41461cd..9c6c2e0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java @@ -14,15 +14,14 @@ */ package me.filoghost.chestcommands.parsing.icon; +import me.filoghost.chestcommands.attribute.AttributeErrorHandler; +import me.filoghost.chestcommands.attribute.IconAttribute; import me.filoghost.chestcommands.config.framework.ConfigSection; import me.filoghost.chestcommands.config.framework.ConfigValue; import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.parsing.attribute.ApplicableIconAttribute; -import me.filoghost.chestcommands.parsing.attribute.AttributeErrorHandler; -import me.filoghost.chestcommands.parsing.attribute.IconAttribute; import me.filoghost.chestcommands.util.logging.ErrorCollector; import org.bukkit.Material; @@ -46,9 +45,7 @@ public class IconSettings { InternalConfigurableIcon icon = new InternalConfigurableIcon(Material.BEDROCK); for (IconAttribute attribute : attributes.values()) { - if (attribute instanceof ApplicableIconAttribute) { - ((ApplicableIconAttribute) attribute).apply(icon); - } + attribute.apply(icon); } return icon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index d8aec1f..a860462 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -16,6 +16,7 @@ package me.filoghost.chestcommands.parsing.menu; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.DisabledAction; +import me.filoghost.chestcommands.attribute.PositionAttribute; import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.config.framework.ConfigSection; import me.filoghost.chestcommands.config.framework.EmptyConfigSection; @@ -26,7 +27,6 @@ import me.filoghost.chestcommands.menu.InternalIconMenu; import me.filoghost.chestcommands.parsing.ActionParser; import me.filoghost.chestcommands.parsing.ItemStackParser; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.parsing.attribute.PositionAttribute; import me.filoghost.chestcommands.parsing.icon.AttributeType; import me.filoghost.chestcommands.parsing.icon.IconSettings; import me.filoghost.chestcommands.util.Colors; From b543c7d1f3a74751b14f2720c81dd173a8949ec4 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 10 Aug 2020 16:27:24 +0200 Subject: [PATCH 173/213] Create "Commons" module, remove "Utils" module --- API/pom.xml | 2 +- .../chestcommands/api/ChestCommandsAPI.java | 130 ++--- .../chestcommands/api/ClickResult.java | 44 +- .../chestcommands/api/ConfigurableIcon.java | 174 +++---- .../me/filoghost/chestcommands/api/Icon.java | 50 +- .../filoghost/chestcommands/api/IconMenu.java | 92 ++-- .../chestcommands/api/StaticIcon.java | 60 +-- .../api/internal/BackendAPI.java | 112 ++-- {Utils => Commons}/pom.xml | 4 +- .../me/filoghost/commons}/BaseJavaPlugin.java | 17 +- .../java/me/filoghost/commons}/Colors.java | 4 +- .../me/filoghost/commons/CommonsUtil.java | 19 +- .../filoghost/commons}/MaterialsHelper.java | 8 +- .../me/filoghost/commons}/Preconditions.java | 2 +- .../java/me/filoghost/commons}/Strings.java | 2 +- .../collection/CaseInsensitiveMap.java | 4 +- .../commons}/collection/CollectionUtils.java | 2 +- .../commons}/collection/Registry.java | 6 +- .../commons/command}/CommandException.java | 48 +- .../commons/command}/CommandFramework.java | 146 +++--- .../commons/command}/CommandValidate.java | 72 +-- .../commons/config}/BaseConfigManager.java | 6 +- .../me/filoghost/commons/config}/Config.java | 4 +- .../commons/config/ConfigErrors.java | 56 ++ .../commons/config}/ConfigLoader.java | 21 +- .../filoghost/commons/config}/ConfigPath.java | 2 +- .../commons/config}/ConfigSection.java | 8 +- .../commons/config}/ConfigValue.java | 8 +- .../commons/config}/ConfigValueType.java | 21 +- .../commons/config}/EmptyConfigSection.java | 2 +- .../config}/exception/ConfigException.java | 2 +- .../exception/ConfigLoadException.java | 2 +- .../exception/ConfigSaveException.java | 2 +- .../exception/ConfigSyntaxException.java | 2 +- .../exception/ConfigValueException.java | 2 +- .../exception/ConverterCastException.java | 2 +- .../InvalidConfigValueException.java | 2 +- .../MissingConfigValueException.java | 2 +- .../commons/config}/mapped/ConfigMapper.java | 32 +- .../commons/config}/mapped/IncludeStatic.java | 2 +- .../commons/config}/mapped/MappedConfig.java | 4 +- .../config}/mapped/MappedConfigLoader.java | 20 +- .../commons/config}/mapped/MappedField.java | 2 +- .../mapped/converter/BooleanConverter.java | 4 +- .../config}/mapped/converter/Converter.java | 14 +- .../mapped/converter/DoubleConverter.java | 4 +- .../mapped/converter/IntegerConverter.java | 4 +- .../mapped/converter/ListConverter.java | 6 +- .../mapped/converter/StringConverter.java | 4 +- .../config}/mapped/modifier/ChatColors.java | 2 +- .../mapped/modifier/ChatColorsModifier.java | 4 +- .../mapped/modifier/ValueModifier.java | 4 +- .../commons}/logging/ErrorCollector.java | 4 +- .../filoghost/commons}/logging/ErrorInfo.java | 2 +- .../me/filoghost/commons}/logging/Log.java | 2 +- Plugin/pom.xml | 6 +- .../chestcommands/ChestCommands.java | 489 +++++++++--------- .../filoghost/chestcommands/Permissions.java | 58 +-- .../chestcommands/action/Action.java | 46 +- .../chestcommands/action/BroadcastAction.java | 70 +-- .../action/ChangeServerAction.java | 68 +-- .../action/ConsoleCommandAction.java | 68 +-- .../chestcommands/action/DragonBarAction.java | 118 ++--- .../chestcommands/action/GiveItemAction.java | 72 +-- .../chestcommands/action/GiveMoneyAction.java | 80 +-- .../chestcommands/action/OpCommandAction.java | 78 +-- .../chestcommands/action/OpenMenuAction.java | 102 ++-- .../chestcommands/action/PlaySoundAction.java | 140 ++--- .../action/PlayerCommandAction.java | 66 +-- .../action/SendMessageAction.java | 68 +-- .../attribute/LoreAttribute.java | 4 +- .../attribute/MaterialAttribute.java | 2 +- .../attribute/NameAttribute.java | 2 +- .../chestcommands/command/CommandHandler.java | 324 ++++++------ .../chestcommands/config/ConfigManager.java | 14 +- .../config/CustomPlaceholders.java | 8 +- .../filoghost/chestcommands/config/Lang.java | 4 +- .../chestcommands/config/Settings.java | 4 +- .../chestcommands/hook/BarAPIHook.java | 88 ++-- .../chestcommands/hook/BungeeCordHook.java | 126 ++--- .../hook/PlaceholderAPIHook.java | 98 ++-- .../chestcommands/hook/PluginHook.java | 60 +-- .../chestcommands/hook/VaultEconomyHook.java | 188 +++---- .../icon/BaseConfigurableIcon.java | 6 +- .../icon/InternalConfigurableIcon.java | 4 +- .../icon/requirement/RequiredPermission.java | 2 +- .../requirement/item/InventoryTakeHelper.java | 4 +- .../icon/requirement/item/RequiredItem.java | 2 +- .../chestcommands/inventory}/ArrayGrid.java | 2 +- .../chestcommands/inventory}/Grid.java | 4 +- .../inventory/InventoryGrid.java | 1 - .../inventory/MenuInventoryHolder.java | 2 +- .../chestcommands/legacy/Backup.java | 2 +- .../chestcommands/legacy/UpgradeList.java | 6 +- .../legacy/UpgradesExecutor.java | 4 +- .../legacy/upgrade/RegexUpgradeTask.java | 10 +- .../legacy/upgrade/UpgradeTask.java | 6 +- .../legacy/upgrade/YamlUpgradeTask.java | 8 +- .../v4_0/v4_0_MenuNodeExpandUpgradeTask.java | 8 +- .../v4_0_PlaceholdersFileUpgradeTask.java | 14 +- .../legacy/v4_0/v4_0_SettingsUpgradeTask.java | 2 +- .../listener/CommandListener.java | 122 ++--- .../listener/InventoryListener.java | 202 ++++---- .../chestcommands/listener/JoinListener.java | 86 +-- .../chestcommands/listener/SignListener.java | 254 ++++----- .../chestcommands/logging/ErrorMessages.java | 38 -- .../logging/MessagePartJoiner.java | 2 +- .../logging/PrintableErrorCollector.java | 12 +- .../chestcommands/menu/BaseIconMenu.java | 6 +- .../chestcommands/menu/InternalIconMenu.java | 2 +- .../chestcommands/menu/MenuManager.java | 272 +++++----- .../parsing/EnchantmentParser.java | 4 +- .../chestcommands/parsing/ItemMetaParser.java | 4 +- .../parsing/ItemStackParser.java | 6 +- .../parsing/icon/AttributeType.java | 6 +- .../parsing/icon/IconSettings.java | 8 +- .../parsing/menu/LoadedMenu.java | 2 +- .../parsing/menu/MenuOpenItem.java | 2 +- .../parsing/menu/MenuParser.java | 14 +- .../parsing/menu/MenuSettings.java | 2 +- .../placeholder/PlaceholderManager.java | 2 +- .../placeholder/PlaceholderStringList.java | 4 +- .../placeholder/scanner/PlaceholderMatch.java | 2 +- .../filoghost/chestcommands/util/Utils.java | 22 + .../chestcommands/util/nbt/NBTByte.java | 0 .../chestcommands/util/nbt/NBTByteArray.java | 0 .../chestcommands/util/nbt/NBTCompound.java | 8 +- .../chestcommands/util/nbt/NBTDouble.java | 0 .../chestcommands/util/nbt/NBTFloat.java | 0 .../chestcommands/util/nbt/NBTInt.java | 0 .../chestcommands/util/nbt/NBTIntArray.java | 0 .../chestcommands/util/nbt/NBTList.java | 7 +- .../chestcommands/util/nbt/NBTLong.java | 0 .../chestcommands/util/nbt/NBTLongArray.java | 0 .../chestcommands/util/nbt/NBTShort.java | 0 .../chestcommands/util/nbt/NBTString.java | 0 .../chestcommands/util/nbt/NBTTag.java | 0 .../chestcommands/util/nbt/NBTType.java | 0 .../nbt/parser/MojangsonParseException.java | 0 .../util/nbt/parser/MojangsonParser.java | 17 +- pom.xml | 2 +- 141 files changed, 2480 insertions(+), 2422 deletions(-) rename {Utils => Commons}/pom.xml (91%) rename {Plugin/src/main/java/me/filoghost/chestcommands => Commons/src/main/java/me/filoghost/commons}/BaseJavaPlugin.java (80%) rename {Utils/src/main/java/me/filoghost/chestcommands/util => Commons/src/main/java/me/filoghost/commons}/Colors.java (91%) rename Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java => Commons/src/main/java/me/filoghost/commons/CommonsUtil.java (72%) rename {Utils/src/main/java/me/filoghost/chestcommands/util => Commons/src/main/java/me/filoghost/commons}/MaterialsHelper.java (95%) rename {Utils/src/main/java/me/filoghost/chestcommands/util => Commons/src/main/java/me/filoghost/commons}/Preconditions.java (97%) rename {Utils/src/main/java/me/filoghost/chestcommands/util => Commons/src/main/java/me/filoghost/commons}/Strings.java (98%) rename {Utils/src/main/java/me/filoghost/chestcommands/util => Commons/src/main/java/me/filoghost/commons}/collection/CaseInsensitiveMap.java (95%) rename {Utils/src/main/java/me/filoghost/chestcommands/util => Commons/src/main/java/me/filoghost/commons}/collection/CollectionUtils.java (97%) rename {Utils/src/main/java/me/filoghost/chestcommands/util => Commons/src/main/java/me/filoghost/commons}/collection/Registry.java (94%) rename {Plugin/src/main/java/me/filoghost/chestcommands/command/framework => Commons/src/main/java/me/filoghost/commons/command}/CommandException.java (91%) rename {Plugin/src/main/java/me/filoghost/chestcommands/command/framework => Commons/src/main/java/me/filoghost/commons/command}/CommandFramework.java (93%) rename {Plugin/src/main/java/me/filoghost/chestcommands/command/framework => Commons/src/main/java/me/filoghost/commons/command}/CommandValidate.java (92%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/BaseConfigManager.java (88%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/Config.java (92%) create mode 100644 Commons/src/main/java/me/filoghost/commons/config/ConfigErrors.java rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/ConfigLoader.java (80%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/ConfigPath.java (93%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/ConfigSection.java (95%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/ConfigValue.java (87%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/ConfigValueType.java (89%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/EmptyConfigSection.java (94%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/exception/ConfigException.java (93%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/exception/ConfigLoadException.java (93%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/exception/ConfigSaveException.java (92%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/exception/ConfigSyntaxException.java (94%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/exception/ConfigValueException.java (92%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/exception/ConverterCastException.java (92%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/exception/InvalidConfigValueException.java (92%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/exception/MissingConfigValueException.java (92%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/mapped/ConfigMapper.java (80%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/mapped/IncludeStatic.java (93%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/mapped/MappedConfig.java (86%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/mapped/MappedConfigLoader.java (74%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/mapped/MappedField.java (97%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/mapped/converter/BooleanConverter.java (87%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/mapped/converter/Converter.java (73%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/mapped/converter/DoubleConverter.java (87%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/mapped/converter/IntegerConverter.java (87%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/mapped/converter/ListConverter.java (87%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/mapped/converter/StringConverter.java (87%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/mapped/modifier/ChatColors.java (93%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/mapped/modifier/ChatColorsModifier.java (89%) rename {Plugin/src/main/java/me/filoghost/chestcommands/config/framework => Commons/src/main/java/me/filoghost/commons/config}/mapped/modifier/ValueModifier.java (91%) rename {Utils/src/main/java/me/filoghost/chestcommands/util => Commons/src/main/java/me/filoghost/commons}/logging/ErrorCollector.java (95%) rename {Utils/src/main/java/me/filoghost/chestcommands/util => Commons/src/main/java/me/filoghost/commons}/logging/ErrorInfo.java (96%) rename {Utils/src/main/java/me/filoghost/chestcommands/util => Commons/src/main/java/me/filoghost/commons}/logging/Log.java (96%) rename {Utils/src/main/java/me/filoghost/chestcommands/util/collection => Plugin/src/main/java/me/filoghost/chestcommands/inventory}/ArrayGrid.java (95%) rename {Utils/src/main/java/me/filoghost/chestcommands/util/collection => Plugin/src/main/java/me/filoghost/chestcommands/inventory}/Grid.java (96%) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java rename {Utils => Plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java (100%) rename {Utils => Plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java (100%) rename {Utils => Plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java (98%) rename {Utils => Plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java (100%) rename {Utils => Plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java (100%) rename {Utils => Plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java (100%) rename {Utils => Plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java (100%) rename {Utils => Plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java (95%) rename {Utils => Plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java (100%) rename {Utils => Plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java (100%) rename {Utils => Plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java (100%) rename {Utils => Plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java (100%) rename {Utils => Plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java (100%) rename {Utils => Plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java (100%) rename {Utils => Plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java (100%) rename {Utils => Plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java (92%) diff --git a/API/pom.xml b/API/pom.xml index d5f0e0f..ff63c34 100644 --- a/API/pom.xml +++ b/API/pom.xml @@ -29,7 +29,7 @@ ${project.groupId} - chestcommands-utils + chestcommands-commons ${project.version} diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java index 562ecb4..4008e82 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java @@ -1,65 +1,65 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.api; - -import me.filoghost.chestcommands.api.internal.BackendAPI; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -public class ChestCommandsAPI { - - - private ChestCommandsAPI() {} - - - /** - * The API version is increased every time the API is modified. - * You can use it to require a minimum version, as features may - * be added (rarely removed) in future versions. - * - * @return the API version - */ - public static int getAPIVersion() { - return 1; - } - - - public static void registerPlaceholder(Plugin plugin, String identifier, PlaceholderReplacer placeholderReplacer) { - BackendAPI.getImplementation().registerPlaceholder(plugin, identifier, placeholderReplacer); - } - - - /** - * Checks if a menu with a given file name was loaded by the plugin. - * - * @return if the menu was found - */ - public static boolean isPluginMenu(String yamlFile) { - return BackendAPI.getImplementation().isPluginMenu(yamlFile); - } - - - /** - * Opens a menu loaded by ChestCommands to a player. - * NOTE: this method ignores permissions. - * - * @param player the player that will see the menu - * @param yamlFile the file name of the menu to open (with the .yml extension) - * @return if the menu was found and opened - */ - public static boolean openPluginMenu(Player player, String yamlFile) { - return BackendAPI.getImplementation().openPluginMenu(player, yamlFile); - } -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.api; + +import me.filoghost.chestcommands.api.internal.BackendAPI; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +public class ChestCommandsAPI { + + + private ChestCommandsAPI() {} + + + /** + * The API version is increased every time the API is modified. + * You can use it to require a minimum version, as features may + * be added (rarely removed) in future versions. + * + * @return the API version + */ + public static int getAPIVersion() { + return 1; + } + + + public static void registerPlaceholder(Plugin plugin, String identifier, PlaceholderReplacer placeholderReplacer) { + BackendAPI.getImplementation().registerPlaceholder(plugin, identifier, placeholderReplacer); + } + + + /** + * Checks if a menu with a given file name was loaded by the plugin. + * + * @return if the menu was found + */ + public static boolean isPluginMenu(String yamlFile) { + return BackendAPI.getImplementation().isPluginMenu(yamlFile); + } + + + /** + * Opens a menu loaded by ChestCommands to a player. + * NOTE: this method ignores permissions. + * + * @param player the player that will see the menu + * @param yamlFile the file name of the menu to open (with the .yml extension) + * @return if the menu was found and opened + */ + public static boolean openPluginMenu(Player player, String yamlFile) { + return BackendAPI.getImplementation().openPluginMenu(player, yamlFile); + } +} diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java b/API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java index 2404d45..ecf6c22 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java @@ -1,22 +1,22 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.api; - -public enum ClickResult { - - KEEP_OPEN, - CLOSE - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.api; + +public enum ClickResult { + + KEEP_OPEN, + CLOSE + +} diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java b/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java index 85be8a4..a16d030 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java @@ -1,87 +1,87 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.api; - -import me.filoghost.chestcommands.api.internal.BackendAPI; -import org.bukkit.Color; -import org.bukkit.DyeColor; -import org.bukkit.Material; -import org.bukkit.block.banner.Pattern; -import org.bukkit.enchantments.Enchantment; - -import java.util.List; -import java.util.Map; - -public interface ConfigurableIcon extends ClickableIcon { - - static ConfigurableIcon create(Material material) { - return BackendAPI.getImplementation().createConfigurableIcon(material); - } - - void setMaterial(Material material); - - Material getMaterial(); - - void setAmount(int amount); - - int getAmount(); - - void setDurability(short durability); - - short getDurability(); - - void setNBTData(String nbtData); - - String getNBTData(); - - void setName(String name); - - String getName(); - - void setLore(String... lore); - - void setLore(List lore); - - List getLore(); - - void setEnchantments(Map enchantments); - - Map getEnchantments(); - - void addEnchantment(Enchantment enchantment); - - void addEnchantment(Enchantment enchantment, Integer level); - - void removeEnchantment(Enchantment enchantment); - - Color getLeatherColor(); - - void setLeatherColor(Color leatherColor); - - String getSkullOwner(); - - void setSkullOwner(String skullOwner); - - DyeColor getBannerColor(); - - void setBannerColor(DyeColor bannerColor); - - List getBannerPatterns(); - - void setBannerPatterns(List bannerPatterns); - - void setPlaceholdersEnabled(boolean enabled); - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.api; + +import me.filoghost.chestcommands.api.internal.BackendAPI; +import org.bukkit.Color; +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.block.banner.Pattern; +import org.bukkit.enchantments.Enchantment; + +import java.util.List; +import java.util.Map; + +public interface ConfigurableIcon extends ClickableIcon { + + static ConfigurableIcon create(Material material) { + return BackendAPI.getImplementation().createConfigurableIcon(material); + } + + void setMaterial(Material material); + + Material getMaterial(); + + void setAmount(int amount); + + int getAmount(); + + void setDurability(short durability); + + short getDurability(); + + void setNBTData(String nbtData); + + String getNBTData(); + + void setName(String name); + + String getName(); + + void setLore(String... lore); + + void setLore(List lore); + + List getLore(); + + void setEnchantments(Map enchantments); + + Map getEnchantments(); + + void addEnchantment(Enchantment enchantment); + + void addEnchantment(Enchantment enchantment, Integer level); + + void removeEnchantment(Enchantment enchantment); + + Color getLeatherColor(); + + void setLeatherColor(Color leatherColor); + + String getSkullOwner(); + + void setSkullOwner(String skullOwner); + + DyeColor getBannerColor(); + + void setBannerColor(DyeColor bannerColor); + + List getBannerPatterns(); + + void setBannerPatterns(List bannerPatterns); + + void setPlaceholdersEnabled(boolean enabled); + +} diff --git a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java index f1d7de6..0b2848b 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java @@ -1,26 +1,26 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.api; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public interface Icon { - - ItemStack render(Player viewer); - - ClickResult onClick(MenuInventory menuInventory, Player clicker); - +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.api; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public interface Icon { + + ItemStack render(Player viewer); + + ClickResult onClick(MenuInventory menuInventory, Player clicker); + } \ No newline at end of file diff --git a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java index 1a02bdf..e8a12df 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java @@ -1,47 +1,47 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.api; - -import me.filoghost.chestcommands.api.internal.BackendAPI; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -public interface IconMenu { - - static IconMenu create(Plugin owner, String title, int rowCount) { - return BackendAPI.getImplementation().createIconMenu(owner, title, rowCount); - } - - void setIcon(int row, int column, Icon icon); - - Icon getIcon(int row, int column); - - String getTitle(); - - int getRowCount(); - - int getColumnCount(); - - /** - * Opens a view of the current menu configuration. - * Updating the menu doesn't automatically update all the views. - * - * @param player the player to which the menu will be displayed - */ - MenuInventory open(Player player); - - void refreshOpenInventories(); - +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.api; + +import me.filoghost.chestcommands.api.internal.BackendAPI; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +public interface IconMenu { + + static IconMenu create(Plugin owner, String title, int rowCount) { + return BackendAPI.getImplementation().createIconMenu(owner, title, rowCount); + } + + void setIcon(int row, int column, Icon icon); + + Icon getIcon(int row, int column); + + String getTitle(); + + int getRowCount(); + + int getColumnCount(); + + /** + * Opens a view of the current menu configuration. + * Updating the menu doesn't automatically update all the views. + * + * @param player the player to which the menu will be displayed + */ + MenuInventory open(Player player); + + void refreshOpenInventories(); + } \ No newline at end of file diff --git a/API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java b/API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java index 144fd99..4ea9525 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java @@ -1,30 +1,30 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.api; - -import me.filoghost.chestcommands.api.internal.BackendAPI; -import org.bukkit.inventory.ItemStack; - -public interface StaticIcon extends ClickableIcon { - - static StaticIcon create(ItemStack itemStack) { - return BackendAPI.getImplementation().createStaticIcon(itemStack); - } - - ItemStack getItemStack(); - - void setItemStack(ItemStack itemStack); - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.api; + +import me.filoghost.chestcommands.api.internal.BackendAPI; +import org.bukkit.inventory.ItemStack; + +public interface StaticIcon extends ClickableIcon { + + static StaticIcon create(ItemStack itemStack) { + return BackendAPI.getImplementation().createStaticIcon(itemStack); + } + + ItemStack getItemStack(); + + void setItemStack(ItemStack itemStack); + +} diff --git a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java index 16cb8b1..a91be13 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java @@ -1,56 +1,56 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.api.internal; - -import me.filoghost.chestcommands.api.ConfigurableIcon; -import me.filoghost.chestcommands.api.IconMenu; -import me.filoghost.chestcommands.api.PlaceholderReplacer; -import me.filoghost.chestcommands.api.StaticIcon; -import me.filoghost.chestcommands.util.Preconditions; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; - -public abstract class BackendAPI { - - private static BackendAPI implementation; - - public static void setImplementation(BackendAPI implementation) { - Preconditions.notNull(implementation, "implementation"); - Preconditions.checkState(BackendAPI.implementation == null, "implementation already set"); - - BackendAPI.implementation = implementation; - } - - public static BackendAPI getImplementation() { - Preconditions.checkState(implementation != null, "no implementation set"); - - return implementation; - } - - public abstract boolean isPluginMenu(String yamlFile); - - public abstract boolean openPluginMenu(Player player, String yamlFile); - - public abstract IconMenu createIconMenu(Plugin owner, String title, int rows); - - public abstract ConfigurableIcon createConfigurableIcon(Material material); - - public abstract StaticIcon createStaticIcon(ItemStack itemStack); - - public abstract void registerPlaceholder(Plugin plugin, String identifier, PlaceholderReplacer placeholderReplacer); - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.api.internal; + +import me.filoghost.chestcommands.api.ConfigurableIcon; +import me.filoghost.chestcommands.api.IconMenu; +import me.filoghost.chestcommands.api.PlaceholderReplacer; +import me.filoghost.chestcommands.api.StaticIcon; +import me.filoghost.commons.Preconditions; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +public abstract class BackendAPI { + + private static BackendAPI implementation; + + public static void setImplementation(BackendAPI implementation) { + Preconditions.notNull(implementation, "implementation"); + Preconditions.checkState(BackendAPI.implementation == null, "implementation already set"); + + BackendAPI.implementation = implementation; + } + + public static BackendAPI getImplementation() { + Preconditions.checkState(implementation != null, "no implementation set"); + + return implementation; + } + + public abstract boolean isPluginMenu(String yamlFile); + + public abstract boolean openPluginMenu(Player player, String yamlFile); + + public abstract IconMenu createIconMenu(Plugin owner, String title, int rows); + + public abstract ConfigurableIcon createConfigurableIcon(Material material); + + public abstract StaticIcon createStaticIcon(ItemStack itemStack); + + public abstract void registerPlaceholder(Plugin plugin, String identifier, PlaceholderReplacer placeholderReplacer); + +} diff --git a/Utils/pom.xml b/Commons/pom.xml similarity index 91% rename from Utils/pom.xml rename to Commons/pom.xml index ba37d4f..1529529 100644 --- a/Utils/pom.xml +++ b/Commons/pom.xml @@ -9,8 +9,8 @@ 4.0.0-SNAPSHOT - chestcommands-utils - ChestCommands Utils + chestcommands-commons + ChestCommands Commons diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java b/Commons/src/main/java/me/filoghost/commons/BaseJavaPlugin.java similarity index 80% rename from Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java rename to Commons/src/main/java/me/filoghost/commons/BaseJavaPlugin.java index 6fdaf68..aeb1f74 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/BaseJavaPlugin.java +++ b/Commons/src/main/java/me/filoghost/commons/BaseJavaPlugin.java @@ -12,9 +12,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands; +package me.filoghost.commons; -import me.filoghost.chestcommands.util.Utils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.plugin.java.JavaPlugin; @@ -27,6 +26,7 @@ public abstract class BaseJavaPlugin extends JavaPlugin { @Override public final void onEnable() { try { + // checkPackageRelocation(); TODO enable later onCheckedEnable(); } catch (PluginEnableException e) { criticalShutdown(e.getMessage(), null); @@ -35,6 +35,17 @@ public abstract class BaseJavaPlugin extends JavaPlugin { } } + private void checkPackageRelocation() { + // Prevent Maven's Relocate from changing strings too + final String defaultPackage = new String( + new byte[]{'m', 'e', '.', 'f', 'i', 'l', 'o', 'g', 'h', 'o', 's', 't', '.', 'c', 'o', 'm', 'm', 'o', 'n', 's'}); + + // Make sure package has been relocated + if (BaseJavaPlugin.class.getPackage().getName().equals(defaultPackage)) { + throw new IllegalStateException("not relocated correctly"); + } + } + protected abstract void onCheckedEnable() throws PluginEnableException; @@ -59,7 +70,7 @@ public abstract class BaseJavaPlugin extends JavaPlugin { } if (throwable != null) { output.add(" "); - output.add(Utils.getStackTraceString(throwable)); + output.add(CommonsUtil.getStackTraceString(throwable)); } output.add(" "); if (errorMessage != null) { diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Colors.java b/Commons/src/main/java/me/filoghost/commons/Colors.java similarity index 91% rename from Utils/src/main/java/me/filoghost/chestcommands/util/Colors.java rename to Commons/src/main/java/me/filoghost/commons/Colors.java index 4c7193b..1c82003 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Colors.java +++ b/Commons/src/main/java/me/filoghost/commons/Colors.java @@ -12,14 +12,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.util; +package me.filoghost.commons; import org.bukkit.ChatColor; public final class Colors { public static String addColors(String input) { - if (input == null || input.isEmpty()) { + if (Strings.isEmpty(input)) { return input; } return ChatColor.translateAlternateColorCodes('&', input); diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java b/Commons/src/main/java/me/filoghost/commons/CommonsUtil.java similarity index 72% rename from Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java rename to Commons/src/main/java/me/filoghost/commons/CommonsUtil.java index 17e2742..235e180 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Utils.java +++ b/Commons/src/main/java/me/filoghost/commons/CommonsUtil.java @@ -12,12 +12,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.util; +package me.filoghost.commons; import java.io.PrintWriter; import java.io.StringWriter; -public class Utils { +public class CommonsUtil { public static boolean isClassLoaded(String name) { try { @@ -28,21 +28,6 @@ public class Utils { } } - public static String formatEnum(Enum enumValue) { - return Strings.capitalizeFully(enumValue.name().replace("_", " ")); - } - - public static String addYamlExtension(String fileName) { - if (fileName == null) { - return null; - } - if (fileName.toLowerCase().endsWith(".yml")) { - return fileName; - } else { - return fileName + ".yml"; - } - } - public static String getStackTraceString(Throwable throwable) { StringWriter stringWriter = new StringWriter(); throwable.printStackTrace(new PrintWriter(stringWriter)); diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java b/Commons/src/main/java/me/filoghost/commons/MaterialsHelper.java similarity index 95% rename from Utils/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java rename to Commons/src/main/java/me/filoghost/commons/MaterialsHelper.java index 52b6ba0..55f75e0 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/MaterialsHelper.java +++ b/Commons/src/main/java/me/filoghost/commons/MaterialsHelper.java @@ -12,9 +12,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.util; +package me.filoghost.commons; -import me.filoghost.chestcommands.util.collection.Registry; +import me.filoghost.commons.collection.Registry; import org.bukkit.Material; import java.util.Collection; @@ -24,9 +24,9 @@ import java.util.Optional; public final class MaterialsHelper { // Material names have been changed in 1.13, when dolphins were added - private static final boolean USE_NEW_MATERIAL_NAMES = Utils.isClassLoaded("org.bukkit.entity.Dolphin"); + private static final boolean USE_NEW_MATERIAL_NAMES = CommonsUtil.isClassLoaded("org.bukkit.entity.Dolphin"); - // Default material names are ugly + // Registry of materials by numerical ID (before 1.13), name and aliases private static final Registry MATERIALS_REGISTRY = initMaterialsRegistry(); // Materials that are considered air (with 1.13+ compatibility) diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java b/Commons/src/main/java/me/filoghost/commons/Preconditions.java similarity index 97% rename from Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java rename to Commons/src/main/java/me/filoghost/commons/Preconditions.java index 93ff0fd..954ae67 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Preconditions.java +++ b/Commons/src/main/java/me/filoghost/commons/Preconditions.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.util; +package me.filoghost.commons; import org.bukkit.Material; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java b/Commons/src/main/java/me/filoghost/commons/Strings.java similarity index 98% rename from Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java rename to Commons/src/main/java/me/filoghost/commons/Strings.java index 56e5911..1ad58cf 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/Strings.java +++ b/Commons/src/main/java/me/filoghost/commons/Strings.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.util; +package me.filoghost.commons; public final class Strings { diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CaseInsensitiveMap.java b/Commons/src/main/java/me/filoghost/commons/collection/CaseInsensitiveMap.java similarity index 95% rename from Utils/src/main/java/me/filoghost/chestcommands/util/collection/CaseInsensitiveMap.java rename to Commons/src/main/java/me/filoghost/commons/collection/CaseInsensitiveMap.java index f8832cb..ea34550 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CaseInsensitiveMap.java +++ b/Commons/src/main/java/me/filoghost/commons/collection/CaseInsensitiveMap.java @@ -12,9 +12,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.util.collection; +package me.filoghost.commons.collection; -import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.commons.Preconditions; import java.util.Collection; import java.util.Collections; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java b/Commons/src/main/java/me/filoghost/commons/collection/CollectionUtils.java similarity index 97% rename from Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java rename to Commons/src/main/java/me/filoghost/commons/collection/CollectionUtils.java index 810f7d3..b8839a2 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/CollectionUtils.java +++ b/Commons/src/main/java/me/filoghost/commons/collection/CollectionUtils.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.util.collection; +package me.filoghost.commons.collection; import com.google.common.collect.ImmutableList; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/Registry.java b/Commons/src/main/java/me/filoghost/commons/collection/Registry.java similarity index 94% rename from Utils/src/main/java/me/filoghost/chestcommands/util/collection/Registry.java rename to Commons/src/main/java/me/filoghost/commons/collection/Registry.java index ce12310..3ecb2f8 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/Registry.java +++ b/Commons/src/main/java/me/filoghost/commons/collection/Registry.java @@ -12,10 +12,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.util.collection; +package me.filoghost.commons.collection; -import me.filoghost.chestcommands.util.Preconditions; -import me.filoghost.chestcommands.util.Strings; +import me.filoghost.commons.Preconditions; +import me.filoghost.commons.Strings; import java.util.HashMap; import java.util.Map; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandException.java b/Commons/src/main/java/me/filoghost/commons/command/CommandException.java similarity index 91% rename from Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandException.java rename to Commons/src/main/java/me/filoghost/commons/command/CommandException.java index 2b87790..37a69ec 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandException.java +++ b/Commons/src/main/java/me/filoghost/commons/command/CommandException.java @@ -1,25 +1,25 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.command.framework; - -public class CommandException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - public CommandException(String msg) { - super(msg); - } - +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.commons.command; + +public class CommandException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public CommandException(String msg) { + super(msg); + } + } \ No newline at end of file diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandFramework.java b/Commons/src/main/java/me/filoghost/commons/command/CommandFramework.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandFramework.java rename to Commons/src/main/java/me/filoghost/commons/command/CommandFramework.java index 6359596..49e0454 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandFramework.java +++ b/Commons/src/main/java/me/filoghost/commons/command/CommandFramework.java @@ -1,73 +1,73 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.command.framework; - -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.PluginCommand; -import org.bukkit.plugin.java.JavaPlugin; - -/** - * Wrapper for the default command executor. - */ -public abstract class CommandFramework implements CommandExecutor { - - private final String label; - - - public CommandFramework(String label) { - this.label = label; - } - - - public abstract void execute(CommandSender sender, String label, String[] args); - - - /** - * Default implementation of Bukkit's command executor. - */ - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - try { - execute(sender, label, args); - - } catch (CommandException ex) { - if (ex.getMessage() != null && !ex.getMessage().isEmpty()) { - // Use RED by default - sender.sendMessage(ChatColor.RED + ex.getMessage()); - } - } - - return true; - } - - - /** - * Register a command through the framework. - */ - public static boolean register(JavaPlugin plugin, CommandFramework command) { - PluginCommand pluginCommand = plugin.getCommand(command.label); - - if (pluginCommand == null) { - return false; - } - - pluginCommand.setExecutor(command); - return true; - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.commons.command; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.PluginCommand; +import org.bukkit.plugin.java.JavaPlugin; + +/** + * Wrapper for the default command executor. + */ +public abstract class CommandFramework implements CommandExecutor { + + private final String label; + + + public CommandFramework(String label) { + this.label = label; + } + + + public abstract void execute(CommandSender sender, String label, String[] args); + + + /** + * Default implementation of Bukkit's command executor. + */ + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + try { + execute(sender, label, args); + + } catch (CommandException ex) { + if (ex.getMessage() != null && !ex.getMessage().isEmpty()) { + // Use RED by default + sender.sendMessage(ChatColor.RED + ex.getMessage()); + } + } + + return true; + } + + + /** + * Register a command through the framework. + */ + public static boolean register(JavaPlugin plugin, CommandFramework command) { + PluginCommand pluginCommand = plugin.getCommand(command.label); + + if (pluginCommand == null) { + return false; + } + + pluginCommand.setExecutor(command); + return true; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandValidate.java b/Commons/src/main/java/me/filoghost/commons/command/CommandValidate.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandValidate.java rename to Commons/src/main/java/me/filoghost/commons/command/CommandValidate.java index ae0fbdf..d57022b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/framework/CommandValidate.java +++ b/Commons/src/main/java/me/filoghost/commons/command/CommandValidate.java @@ -1,37 +1,37 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.command.framework; - -public class CommandValidate { - - public static void notNull(Object o, String msg) { - if (o == null) { - throw new CommandException(msg); - } - } - - public static void isTrue(boolean b, String msg) { - if (!b) { - throw new CommandException(msg); - } - } - - public static void minLength(Object[] array, int minLength, String msg) { - if (array.length < minLength) { - throw new CommandException(msg); - } - } - +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.commons.command; + +public class CommandValidate { + + public static void notNull(Object o, String msg) { + if (o == null) { + throw new CommandException(msg); + } + } + + public static void isTrue(boolean b, String msg) { + if (!b) { + throw new CommandException(msg); + } + } + + public static void minLength(Object[] array, int minLength, String msg) { + if (array.length < minLength) { + throw new CommandException(msg); + } + } + } \ No newline at end of file diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/BaseConfigManager.java b/Commons/src/main/java/me/filoghost/commons/config/BaseConfigManager.java similarity index 88% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/BaseConfigManager.java rename to Commons/src/main/java/me/filoghost/commons/config/BaseConfigManager.java index 3bc81a8..8b6a121 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/BaseConfigManager.java +++ b/Commons/src/main/java/me/filoghost/commons/config/BaseConfigManager.java @@ -12,10 +12,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework; +package me.filoghost.commons.config; -import me.filoghost.chestcommands.config.framework.mapped.MappedConfig; -import me.filoghost.chestcommands.config.framework.mapped.MappedConfigLoader; +import me.filoghost.commons.config.mapped.MappedConfig; +import me.filoghost.commons.config.mapped.MappedConfigLoader; import java.nio.file.Path; import java.util.function.Supplier; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java b/Commons/src/main/java/me/filoghost/commons/config/Config.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java rename to Commons/src/main/java/me/filoghost/commons/config/Config.java index 7a03da6..0ebd65a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/Config.java +++ b/Commons/src/main/java/me/filoghost/commons/config/Config.java @@ -12,9 +12,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework; +package me.filoghost.commons.config; -import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.commons.Preconditions; import org.bukkit.configuration.file.YamlConfiguration; import java.nio.file.Path; diff --git a/Commons/src/main/java/me/filoghost/commons/config/ConfigErrors.java b/Commons/src/main/java/me/filoghost/commons/config/ConfigErrors.java new file mode 100644 index 0000000..8a66a41 --- /dev/null +++ b/Commons/src/main/java/me/filoghost/commons/config/ConfigErrors.java @@ -0,0 +1,56 @@ +package me.filoghost.commons.config; + +import me.filoghost.commons.config.mapped.MappedConfig; +import me.filoghost.commons.config.mapped.MappedField; +import me.filoghost.commons.config.mapped.converter.Converter; + +import java.nio.file.Path; + +public class ConfigErrors { + + public static final String readIOException = "I/O exception while reading file"; + public static final String createDefaultIOException = "I/O exception while creating default file"; + public static final String writeDataIOException = "I/O exception while writing data to file"; + public static final String invalidYamlSyntax = "invalid YAML syntax"; + + public static final String valueNotSet = "value is not set"; + public static final String valueNotList = "value is not a list"; + public static final String valueNotBoolean = "value is not a boolean"; + public static final String valueNotNumber = "value is not a number"; + public static final String valueNotString = "value is not a string"; + public static final String valueNotSection = "value is not a configuration section"; + + public static String createParentFolderIOException(Path rootDataFolder, Path folder) { + return "I/O exception while creating parent directory \"" + formatPath(rootDataFolder, folder) + "\""; + } + + public static String mapperInitError(MappedConfig mappedConfig) { + return "couldn't initialize config mapper for class \"" + mappedConfig.getClass() + "\""; + } + + public static String fieldReadError(MappedConfig mappedConfig) { + return "couldn't read field values from class \"" + mappedConfig.getClass() + "\""; + } + + public static String fieldInjectError(MappedConfig mappedConfig) { + return "couldn't inject fields values in class \"" + mappedConfig.getClass() + "\""; + } + + public static String mapperFieldCannotBeNull(MappedField mappedField) { + return "mapped field \"" + mappedField.getFieldName() + "\" cannot be null by default"; + } + + public static String converterFailed(Object value, Converter converter) { + return "value of type \"" + value.getClass() + "\" couldn't be converted by \"" + converter.getClass() + "\""; + } + + private static String formatPath(Path rootDataFolder, Path path) { + if (path.startsWith(rootDataFolder)) { + // Remove root data folder prefix + return path.subpath(rootDataFolder.getNameCount(), path.getNameCount()).toString(); + } else { + return path.toString(); + } + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java b/Commons/src/main/java/me/filoghost/commons/config/ConfigLoader.java similarity index 80% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java rename to Commons/src/main/java/me/filoghost/commons/config/ConfigLoader.java index 151d1c4..5056bf6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigLoader.java +++ b/Commons/src/main/java/me/filoghost/commons/config/ConfigLoader.java @@ -12,13 +12,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework; +package me.filoghost.commons.config; -import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; -import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; -import me.filoghost.chestcommands.config.framework.exception.ConfigSyntaxException; -import me.filoghost.chestcommands.logging.ErrorMessages; -import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.commons.Preconditions; +import me.filoghost.commons.config.exception.ConfigLoadException; +import me.filoghost.commons.config.exception.ConfigSaveException; +import me.filoghost.commons.config.exception.ConfigSyntaxException; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; @@ -67,7 +66,7 @@ public class ConfigLoader { Files.createFile(file); } } catch (IOException e) { - throw new ConfigSaveException(ErrorMessages.Config.createDefaultIOException, e); + throw new ConfigSaveException(ConfigErrors.createDefaultIOException, e); } } @@ -103,9 +102,9 @@ public class ConfigLoader { try (BufferedReader reader = Files.newBufferedReader(file)) { yaml.load(reader); } catch (IOException e) { - throw new ConfigLoadException(ErrorMessages.Config.readIOException, e); + throw new ConfigLoadException(ConfigErrors.readIOException, e); } catch (InvalidConfigurationException e) { - throw new ConfigSyntaxException(ErrorMessages.Config.invalidYamlSyntax, e); + throw new ConfigSyntaxException(ConfigErrors.invalidYamlSyntax, e); } return new Config(yaml, file); @@ -119,7 +118,7 @@ public class ConfigLoader { try (BufferedWriter writer = Files.newBufferedWriter(file)) { writer.write(data); } catch (IOException e) { - throw new ConfigSaveException(ErrorMessages.Config.writeDataIOException, e); + throw new ConfigSaveException(ConfigErrors.writeDataIOException, e); } } @@ -128,7 +127,7 @@ public class ConfigLoader { try { Files.createDirectories(file.getParent()); } catch (IOException e) { - throw new ConfigSaveException(ErrorMessages.Config.createParentFolderIOException(file.getParent()), e); + throw new ConfigSaveException(ConfigErrors.createParentFolderIOException(rootDataFolder, file.getParent()), e); } } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigPath.java b/Commons/src/main/java/me/filoghost/commons/config/ConfigPath.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigPath.java rename to Commons/src/main/java/me/filoghost/commons/config/ConfigPath.java index 4ae8d9e..4b936f6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigPath.java +++ b/Commons/src/main/java/me/filoghost/commons/config/ConfigPath.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework; +package me.filoghost.commons.config; public interface ConfigPath { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java b/Commons/src/main/java/me/filoghost/commons/config/ConfigSection.java similarity index 95% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java rename to Commons/src/main/java/me/filoghost/commons/config/ConfigSection.java index c2a177f..71e4ed9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigSection.java +++ b/Commons/src/main/java/me/filoghost/commons/config/ConfigSection.java @@ -12,11 +12,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework; +package me.filoghost.commons.config; -import me.filoghost.chestcommands.config.framework.exception.InvalidConfigValueException; -import me.filoghost.chestcommands.config.framework.exception.MissingConfigValueException; -import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.commons.Preconditions; +import me.filoghost.commons.config.exception.InvalidConfigValueException; +import me.filoghost.commons.config.exception.MissingConfigValueException; import org.bukkit.configuration.ConfigurationSection; import java.util.List; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigValue.java b/Commons/src/main/java/me/filoghost/commons/config/ConfigValue.java similarity index 87% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigValue.java rename to Commons/src/main/java/me/filoghost/commons/config/ConfigValue.java index 7ccd581..4d55384 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigValue.java +++ b/Commons/src/main/java/me/filoghost/commons/config/ConfigValue.java @@ -12,11 +12,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework; +package me.filoghost.commons.config; -import me.filoghost.chestcommands.config.framework.exception.InvalidConfigValueException; -import me.filoghost.chestcommands.config.framework.exception.MissingConfigValueException; -import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.commons.Preconditions; +import me.filoghost.commons.config.exception.InvalidConfigValueException; +import me.filoghost.commons.config.exception.MissingConfigValueException; public class ConfigValue { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigValueType.java b/Commons/src/main/java/me/filoghost/commons/config/ConfigValueType.java similarity index 89% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigValueType.java rename to Commons/src/main/java/me/filoghost/commons/config/ConfigValueType.java index 26c89a3..ab2fbd7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/ConfigValueType.java +++ b/Commons/src/main/java/me/filoghost/commons/config/ConfigValueType.java @@ -12,11 +12,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework; +package me.filoghost.commons.config; -import me.filoghost.chestcommands.config.framework.exception.InvalidConfigValueException; -import me.filoghost.chestcommands.config.framework.exception.MissingConfigValueException; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.commons.config.exception.InvalidConfigValueException; +import me.filoghost.commons.config.exception.MissingConfigValueException; import org.bukkit.configuration.ConfigurationSection; import java.util.ArrayList; @@ -30,14 +29,14 @@ public class ConfigValueType { (Object value) -> value instanceof String || value instanceof Number || value instanceof Boolean || value instanceof Character, (Object value) -> value.toString(), (String value) -> value, - ErrorMessages.Config.valueNotString + ConfigErrors.valueNotString ); public static final ConfigValueType BOOLEAN = new ConfigValueType<>( (Object value) -> value instanceof Boolean, (Object value) -> (Boolean) value, (Boolean value) -> value, - ErrorMessages.Config.valueNotBoolean + ConfigErrors.valueNotBoolean ); public static final ConfigValueType LONG = newNumberType(Number::longValue); @@ -54,14 +53,14 @@ public class ConfigValueType { (Object value) -> value instanceof List, (Object value) -> (List) value, (List value) -> value, - ErrorMessages.Config.valueNotList + ConfigErrors.valueNotList ); public static final ConfigValueType CONFIG_SECTION = new ConfigValueType<>( (Object value) -> value instanceof ConfigurationSection, (Object value) -> new ConfigSection((ConfigurationSection) value), (ConfigSection value) -> value.getInternalYamlSection(), - ErrorMessages.Config.valueNotSection + ConfigErrors.valueNotSection ); private final Predicate isValidConfigValueFunction; @@ -86,7 +85,7 @@ public class ConfigValueType { protected T fromConfigValueRequired(Object rawConfigValue) throws MissingConfigValueException, InvalidConfigValueException { if (rawConfigValue == null) { - throw new MissingConfigValueException(ErrorMessages.Config.valueNotSet); + throw new MissingConfigValueException(ConfigErrors.valueNotSet); } if (isValidConfigValueFunction.test(rawConfigValue)) { @@ -122,7 +121,7 @@ public class ConfigValueType { (Object value) -> value instanceof Number, (Object value) -> toTypeFunction.apply((Number) value), (T value) -> value, - ErrorMessages.Config.valueNotNumber + ConfigErrors.valueNotNumber ); } @@ -141,7 +140,7 @@ public class ConfigValueType { return result; }, (List value) -> value, - ErrorMessages.Config.valueNotList + ConfigErrors.valueNotList ); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/EmptyConfigSection.java b/Commons/src/main/java/me/filoghost/commons/config/EmptyConfigSection.java similarity index 94% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/EmptyConfigSection.java rename to Commons/src/main/java/me/filoghost/commons/config/EmptyConfigSection.java index 88a1df8..defe67c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/EmptyConfigSection.java +++ b/Commons/src/main/java/me/filoghost/commons/config/EmptyConfigSection.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework; +package me.filoghost.commons.config; import org.bukkit.configuration.MemoryConfiguration; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigException.java b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigException.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigException.java rename to Commons/src/main/java/me/filoghost/commons/config/exception/ConfigException.java index 2b31296..14b3481 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigException.java +++ b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigException.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.exception; +package me.filoghost.commons.config.exception; public class ConfigException extends Exception { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigLoadException.java b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigLoadException.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigLoadException.java rename to Commons/src/main/java/me/filoghost/commons/config/exception/ConfigLoadException.java index 92b9185..2afb9d0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigLoadException.java +++ b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigLoadException.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.exception; +package me.filoghost.commons.config.exception; public class ConfigLoadException extends ConfigException { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSaveException.java b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSaveException.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSaveException.java rename to Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSaveException.java index 3feeb5c..0e753d6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSaveException.java +++ b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSaveException.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.exception; +package me.filoghost.commons.config.exception; public class ConfigSaveException extends ConfigException { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSyntaxException.java b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSyntaxException.java similarity index 94% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSyntaxException.java rename to Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSyntaxException.java index bebdd9e..628cddc 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigSyntaxException.java +++ b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSyntaxException.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.exception; +package me.filoghost.commons.config.exception; import org.bukkit.configuration.InvalidConfigurationException; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigValueException.java b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigValueException.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigValueException.java rename to Commons/src/main/java/me/filoghost/commons/config/exception/ConfigValueException.java index 6b37c16..9671f30 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConfigValueException.java +++ b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigValueException.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.exception; +package me.filoghost.commons.config.exception; public abstract class ConfigValueException extends ConfigException { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConverterCastException.java b/Commons/src/main/java/me/filoghost/commons/config/exception/ConverterCastException.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConverterCastException.java rename to Commons/src/main/java/me/filoghost/commons/config/exception/ConverterCastException.java index 6ce637d..cd55662 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/ConverterCastException.java +++ b/Commons/src/main/java/me/filoghost/commons/config/exception/ConverterCastException.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.exception; +package me.filoghost.commons.config.exception; public class ConverterCastException extends ConfigException { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/InvalidConfigValueException.java b/Commons/src/main/java/me/filoghost/commons/config/exception/InvalidConfigValueException.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/InvalidConfigValueException.java rename to Commons/src/main/java/me/filoghost/commons/config/exception/InvalidConfigValueException.java index 24840fe..1d1032d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/InvalidConfigValueException.java +++ b/Commons/src/main/java/me/filoghost/commons/config/exception/InvalidConfigValueException.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.exception; +package me.filoghost.commons.config.exception; public class InvalidConfigValueException extends ConfigValueException { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/MissingConfigValueException.java b/Commons/src/main/java/me/filoghost/commons/config/exception/MissingConfigValueException.java similarity index 92% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/MissingConfigValueException.java rename to Commons/src/main/java/me/filoghost/commons/config/exception/MissingConfigValueException.java index 1020a43..9393385 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/exception/MissingConfigValueException.java +++ b/Commons/src/main/java/me/filoghost/commons/config/exception/MissingConfigValueException.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.exception; +package me.filoghost.commons.config.exception; public class MissingConfigValueException extends ConfigValueException { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/ConfigMapper.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/ConfigMapper.java similarity index 80% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/ConfigMapper.java rename to Commons/src/main/java/me/filoghost/commons/config/mapped/ConfigMapper.java index d10fe88..08e74cb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/ConfigMapper.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/ConfigMapper.java @@ -12,23 +12,23 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.mapped; +package me.filoghost.commons.config.mapped; import com.google.common.collect.ImmutableList; -import me.filoghost.chestcommands.config.framework.ConfigSection; -import me.filoghost.chestcommands.config.framework.ConfigValue; -import me.filoghost.chestcommands.config.framework.ConfigValueType; -import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; -import me.filoghost.chestcommands.config.framework.exception.ConverterCastException; -import me.filoghost.chestcommands.config.framework.mapped.converter.BooleanConverter; -import me.filoghost.chestcommands.config.framework.mapped.converter.Converter; -import me.filoghost.chestcommands.config.framework.mapped.converter.DoubleConverter; -import me.filoghost.chestcommands.config.framework.mapped.converter.IntegerConverter; -import me.filoghost.chestcommands.config.framework.mapped.converter.ListConverter; -import me.filoghost.chestcommands.config.framework.mapped.converter.StringConverter; -import me.filoghost.chestcommands.config.framework.mapped.modifier.ChatColorsModifier; -import me.filoghost.chestcommands.config.framework.mapped.modifier.ValueModifier; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.commons.config.ConfigErrors; +import me.filoghost.commons.config.ConfigSection; +import me.filoghost.commons.config.ConfigValue; +import me.filoghost.commons.config.ConfigValueType; +import me.filoghost.commons.config.exception.ConfigLoadException; +import me.filoghost.commons.config.exception.ConverterCastException; +import me.filoghost.commons.config.mapped.converter.BooleanConverter; +import me.filoghost.commons.config.mapped.converter.Converter; +import me.filoghost.commons.config.mapped.converter.DoubleConverter; +import me.filoghost.commons.config.mapped.converter.IntegerConverter; +import me.filoghost.commons.config.mapped.converter.ListConverter; +import me.filoghost.commons.config.mapped.converter.StringConverter; +import me.filoghost.commons.config.mapped.modifier.ChatColorsModifier; +import me.filoghost.commons.config.mapped.modifier.ValueModifier; import java.lang.annotation.Annotation; import java.lang.reflect.Field; @@ -100,7 +100,7 @@ public class ConfigMapper { Object defaultValue = mappedField.getFromObject(mappedObject); if (defaultValue == null) { - throw new ReflectiveOperationException(ErrorMessages.Config.mapperFieldCannotBeNull(mappedField)); + throw new ReflectiveOperationException(ConfigErrors.mapperFieldCannotBeNull(mappedField)); } mappedFieldValues.put(mappedField, defaultValue); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/IncludeStatic.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/IncludeStatic.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/IncludeStatic.java rename to Commons/src/main/java/me/filoghost/commons/config/mapped/IncludeStatic.java index 60a8901..4305136 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/IncludeStatic.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/IncludeStatic.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.mapped; +package me.filoghost.commons.config.mapped; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfig.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfig.java similarity index 86% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfig.java rename to Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfig.java index 19258bd..36fdf88 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfig.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfig.java @@ -12,9 +12,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.mapped; +package me.filoghost.commons.config.mapped; -import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; +import me.filoghost.commons.config.exception.ConfigLoadException; public class MappedConfig { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfigLoader.java similarity index 74% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java rename to Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfigLoader.java index c40bf83..ec8cda8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedConfigLoader.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfigLoader.java @@ -12,14 +12,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.mapped; +package me.filoghost.commons.config.mapped; -import me.filoghost.chestcommands.config.framework.Config; -import me.filoghost.chestcommands.config.framework.ConfigLoader; -import me.filoghost.chestcommands.config.framework.ConfigValue; -import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; -import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.commons.config.Config; +import me.filoghost.commons.config.ConfigErrors; +import me.filoghost.commons.config.ConfigLoader; +import me.filoghost.commons.config.ConfigValue; +import me.filoghost.commons.config.exception.ConfigLoadException; +import me.filoghost.commons.config.exception.ConfigSaveException; import java.nio.file.Path; import java.util.Map; @@ -44,7 +44,7 @@ public class MappedConfigLoader { try { mapper = new ConfigMapper(mappedObject, config); } catch (ReflectiveOperationException e) { - throw new ConfigLoadException(ErrorMessages.Config.mapperInitError(mappedObject), e); + throw new ConfigLoadException(ConfigErrors.mapperInitError(mappedObject), e); } // Extract default values from fields @@ -52,7 +52,7 @@ public class MappedConfigLoader { try { defaultValues = mapper.toConfigValues(mapper.getFieldValues()); } catch (ReflectiveOperationException e) { - throw new ConfigLoadException(ErrorMessages.Config.fieldReadError(mappedObject), e); + throw new ConfigLoadException(ConfigErrors.fieldReadError(mappedObject), e); } } @@ -67,7 +67,7 @@ public class MappedConfigLoader { try { mapper.injectObjectFields(); } catch (ReflectiveOperationException e) { - throw new ConfigLoadException(ErrorMessages.Config.fieldInjectError(mappedObject), e); + throw new ConfigLoadException(ConfigErrors.fieldInjectError(mappedObject), e); } mappedObject.postLoad(); return mappedObject; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedField.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedField.java similarity index 97% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedField.java rename to Commons/src/main/java/me/filoghost/commons/config/mapped/MappedField.java index d7ec37c..822a3bf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/MappedField.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedField.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.mapped; +package me.filoghost.commons.config.mapped; import java.lang.annotation.Annotation; import java.lang.reflect.Field; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/BooleanConverter.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/BooleanConverter.java similarity index 87% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/BooleanConverter.java rename to Commons/src/main/java/me/filoghost/commons/config/mapped/converter/BooleanConverter.java index afaae7f..b3c6cda 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/BooleanConverter.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/BooleanConverter.java @@ -12,9 +12,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.mapped.converter; +package me.filoghost.commons.config.mapped.converter; -import me.filoghost.chestcommands.config.framework.ConfigValueType; +import me.filoghost.commons.config.ConfigValueType; import java.lang.reflect.Type; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/Converter.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/Converter.java similarity index 73% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/Converter.java rename to Commons/src/main/java/me/filoghost/commons/config/mapped/converter/Converter.java index c7fa213..a4190f3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/Converter.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/Converter.java @@ -12,13 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.mapped.converter; +package me.filoghost.commons.config.mapped.converter; -import me.filoghost.chestcommands.config.framework.ConfigValue; -import me.filoghost.chestcommands.config.framework.ConfigValueType; -import me.filoghost.chestcommands.config.framework.exception.ConverterCastException; -import me.filoghost.chestcommands.config.framework.mapped.MappedField; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.commons.config.ConfigErrors; +import me.filoghost.commons.config.ConfigValue; +import me.filoghost.commons.config.ConfigValueType; +import me.filoghost.commons.config.exception.ConverterCastException; +import me.filoghost.commons.config.mapped.MappedField; import java.lang.reflect.Type; @@ -40,7 +40,7 @@ public interface Converter { try { return ConfigValue.of(configValueType, (T) value); } catch (ClassCastException e) { - throw new ConverterCastException(ErrorMessages.Config.converterFailed(value, this), e); + throw new ConverterCastException(ConfigErrors.converterFailed(value, this), e); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/DoubleConverter.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/DoubleConverter.java similarity index 87% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/DoubleConverter.java rename to Commons/src/main/java/me/filoghost/commons/config/mapped/converter/DoubleConverter.java index 43ca7ed..77e6127 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/DoubleConverter.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/DoubleConverter.java @@ -12,9 +12,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.mapped.converter; +package me.filoghost.commons.config.mapped.converter; -import me.filoghost.chestcommands.config.framework.ConfigValueType; +import me.filoghost.commons.config.ConfigValueType; import java.lang.reflect.Type; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/IntegerConverter.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/IntegerConverter.java similarity index 87% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/IntegerConverter.java rename to Commons/src/main/java/me/filoghost/commons/config/mapped/converter/IntegerConverter.java index 5c40369..f53edbe 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/IntegerConverter.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/IntegerConverter.java @@ -12,9 +12,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.mapped.converter; +package me.filoghost.commons.config.mapped.converter; -import me.filoghost.chestcommands.config.framework.ConfigValueType; +import me.filoghost.commons.config.ConfigValueType; import java.lang.reflect.Type; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/ListConverter.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/ListConverter.java similarity index 87% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/ListConverter.java rename to Commons/src/main/java/me/filoghost/commons/config/mapped/converter/ListConverter.java index 3fe2d33..fa19841 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/ListConverter.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/ListConverter.java @@ -12,10 +12,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.mapped.converter; +package me.filoghost.commons.config.mapped.converter; -import me.filoghost.chestcommands.config.framework.ConfigValueType; -import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.commons.Preconditions; +import me.filoghost.commons.config.ConfigValueType; import java.lang.reflect.Type; import java.util.List; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/StringConverter.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/StringConverter.java similarity index 87% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/StringConverter.java rename to Commons/src/main/java/me/filoghost/commons/config/mapped/converter/StringConverter.java index acd14ec..60a9243 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/converter/StringConverter.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/StringConverter.java @@ -12,9 +12,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.mapped.converter; +package me.filoghost.commons.config.mapped.converter; -import me.filoghost.chestcommands.config.framework.ConfigValueType; +import me.filoghost.commons.config.ConfigValueType; import java.lang.reflect.Type; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColors.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColors.java similarity index 93% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColors.java rename to Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColors.java index db9c274..6ef0b8b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColors.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColors.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.mapped.modifier; +package me.filoghost.commons.config.mapped.modifier; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColorsModifier.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColorsModifier.java similarity index 89% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColorsModifier.java rename to Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColorsModifier.java index 49b2c44..ba4c2c9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ChatColorsModifier.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColorsModifier.java @@ -12,9 +12,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.mapped.modifier; +package me.filoghost.commons.config.mapped.modifier; -import me.filoghost.chestcommands.util.Colors; +import me.filoghost.commons.Colors; public class ChatColorsModifier implements ValueModifier { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ValueModifier.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ValueModifier.java similarity index 91% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ValueModifier.java rename to Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ValueModifier.java index 2a9b2f4..14666b7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/framework/mapped/modifier/ValueModifier.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ValueModifier.java @@ -12,9 +12,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.config.framework.mapped.modifier; +package me.filoghost.commons.config.mapped.modifier; -import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.commons.Preconditions; import java.lang.annotation.Annotation; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorCollector.java b/Commons/src/main/java/me/filoghost/commons/logging/ErrorCollector.java similarity index 95% rename from Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorCollector.java rename to Commons/src/main/java/me/filoghost/commons/logging/ErrorCollector.java index 9e246e2..68bf616 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorCollector.java +++ b/Commons/src/main/java/me/filoghost/commons/logging/ErrorCollector.java @@ -12,13 +12,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.util.logging; +package me.filoghost.commons.logging; import java.util.ArrayList; import java.util.List; /** - * This is a class to collect all the errors found while loading the plugin. + * This is a class to collect all the errors found while loading a plugin. */ public abstract class ErrorCollector { diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorInfo.java b/Commons/src/main/java/me/filoghost/commons/logging/ErrorInfo.java similarity index 96% rename from Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorInfo.java rename to Commons/src/main/java/me/filoghost/commons/logging/ErrorInfo.java index 23a471d..e6cec33 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/logging/ErrorInfo.java +++ b/Commons/src/main/java/me/filoghost/commons/logging/ErrorInfo.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.util.logging; +package me.filoghost.commons.logging; import java.util.ArrayList; import java.util.Collections; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/logging/Log.java b/Commons/src/main/java/me/filoghost/commons/logging/Log.java similarity index 96% rename from Utils/src/main/java/me/filoghost/chestcommands/util/logging/Log.java rename to Commons/src/main/java/me/filoghost/commons/logging/Log.java index 894b351..c768d6f 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/logging/Log.java +++ b/Commons/src/main/java/me/filoghost/commons/logging/Log.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.util.logging; +package me.filoghost.commons.logging; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 66ffb30..1fb43e6 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -88,7 +88,7 @@ ${project.groupId} - chestcommands-utils + chestcommands-commons ${project.version} @@ -125,11 +125,11 @@ org.bstats - me.filoghost.chestcommands.metrics + me.filoghost.commons.metrics me.filoghost.updatechecker - me.filoghost.chestcommands.updater + me.filoghost.commons.updater diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 92bf0db..61c3b34 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -1,244 +1,245 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands; - -import me.filoghost.chestcommands.api.internal.BackendAPI; -import me.filoghost.chestcommands.command.CommandHandler; -import me.filoghost.chestcommands.command.framework.CommandFramework; -import me.filoghost.chestcommands.config.ConfigManager; -import me.filoghost.chestcommands.config.CustomPlaceholders; -import me.filoghost.chestcommands.config.Lang; -import me.filoghost.chestcommands.config.Settings; -import me.filoghost.chestcommands.config.framework.ConfigLoader; -import me.filoghost.chestcommands.hook.BarAPIHook; -import me.filoghost.chestcommands.hook.BungeeCordHook; -import me.filoghost.chestcommands.hook.PlaceholderAPIHook; -import me.filoghost.chestcommands.hook.VaultEconomyHook; -import me.filoghost.chestcommands.legacy.UpgradeExecutorException; -import me.filoghost.chestcommands.legacy.UpgradesExecutor; -import me.filoghost.chestcommands.listener.CommandListener; -import me.filoghost.chestcommands.listener.InventoryListener; -import me.filoghost.chestcommands.listener.JoinListener; -import me.filoghost.chestcommands.listener.SignListener; -import me.filoghost.chestcommands.logging.ErrorMessages; -import me.filoghost.chestcommands.logging.PrintableErrorCollector; -import me.filoghost.chestcommands.menu.MenuManager; -import me.filoghost.chestcommands.parsing.menu.LoadedMenu; -import me.filoghost.chestcommands.placeholder.PlaceholderManager; -import me.filoghost.chestcommands.task.TickingTask; -import me.filoghost.chestcommands.util.Utils; -import me.filoghost.chestcommands.util.logging.ErrorCollector; -import me.filoghost.chestcommands.util.logging.Log; -import me.filoghost.updatechecker.UpdateChecker; -import org.bstats.bukkit.MetricsLite; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; - -public class ChestCommands extends BaseJavaPlugin { - - - public static final String CHAT_PREFIX = ChatColor.DARK_GREEN + "[" + ChatColor.GREEN + "ChestCommands" + ChatColor.DARK_GREEN + "] " + ChatColor.GREEN; - - private static Plugin pluginInstance; - private static Path dataFolderPath; - - private static ConfigManager configManager; - private static MenuManager menuManager; - private static Settings settings; - private static Lang lang; - private static CustomPlaceholders placeholders; - - private static ErrorCollector lastLoadErrors; - private static String newVersion; - - @Override - protected void onCheckedEnable() throws PluginEnableException { - if (!Utils.isClassLoaded("org.bukkit.inventory.ItemFlag")) { // ItemFlag was added in 1.8 - if (Bukkit.getVersion().contains("(MC: 1.8)")) { - throw new PluginEnableException("ChestCommands requires a more recent version of Bukkit 1.8 to run."); - } else { - throw new PluginEnableException("ChestCommands requires at least Bukkit 1.8 to run."); - } - } - - if (pluginInstance != null || System.getProperty("ChestCommandsLoaded") != null) { - Log.warning("Please do not use /reload or plugin reloaders. Use the command \"/cc reload\" instead."); - return; - } - - System.setProperty("ChestCommandsLoaded", "true"); - - pluginInstance = this; - dataFolderPath = getDataFolder().toPath(); - Log.setLogger(getLogger()); - configManager = new ConfigManager(getDataFolderPath()); - menuManager = new MenuManager(); - settings = new Settings(); - lang = new Lang(); - placeholders = new CustomPlaceholders(); - - BackendAPI.setImplementation(new DefaultBackendAPI()); - - VaultEconomyHook.INSTANCE.setup(); - BarAPIHook.INSTANCE.setup(); - PlaceholderAPIHook.INSTANCE.setup(); - BungeeCordHook.INSTANCE.setup(); - - if (VaultEconomyHook.INSTANCE.isEnabled()) { - Log.info("Hooked Vault"); - } else { - Log.warning("Couldn't find Vault and a compatible economy plugin! Money-related features will not work."); - } - - if (BarAPIHook.INSTANCE.isEnabled()) { - Log.info("Hooked BarAPI"); - } - - if (PlaceholderAPIHook.INSTANCE.isEnabled()) { - Log.info("Hooked PlaceholderAPI"); - } - - if (settings.update_notifications) { - UpdateChecker.run(this, 56919, (String newVersion) -> { - ChestCommands.newVersion = newVersion; - - Log.info("Found a new version: " + newVersion + " (yours: v" + getDescription().getVersion() + ")"); - Log.info("Download the update on Bukkit Dev:"); - Log.info("https://dev.bukkit.org/projects/chest-commands"); - }); - } - - // Start bStats metrics - int pluginID = 3658; - new MetricsLite(this, pluginID); - - Bukkit.getPluginManager().registerEvents(new CommandListener(menuManager), this); - Bukkit.getPluginManager().registerEvents(new InventoryListener(menuManager), this); - Bukkit.getPluginManager().registerEvents(new JoinListener(), this); - Bukkit.getPluginManager().registerEvents(new SignListener(menuManager), this); - - CommandFramework.register(this, new CommandHandler(menuManager, "chestcommands")); - - ErrorCollector errorCollector = load(); - - if (errorCollector.hasErrors()) { - errorCollector.logToConsole(); - Bukkit.getScheduler().runTaskLater(this, () -> { - Bukkit.getConsoleSender().sendMessage( - ChestCommands.CHAT_PREFIX + ChatColor.RED + "Encountered " + errorCollector.getErrorsCount() + " error(s) on load. " - + "Check previous console logs or run \"/chestcommands errors\" to see them again."); - }, 10L); - } - - Bukkit.getScheduler().runTaskTimer(this, new TickingTask(), 1L, 1L); - } - - @Override - public void onDisable() { - closeAllMenus(); - } - - public static ErrorCollector load() { - ErrorCollector errorCollector = new PrintableErrorCollector(); - menuManager.clear(); - boolean isFreshInstall = !Files.isDirectory(configManager.getRootDataFolder()); - try { - Files.createDirectories(configManager.getRootDataFolder()); - } catch (IOException e) { - errorCollector.add(ErrorMessages.Config.createDataFolderIOException, e); - return errorCollector; - } - - UpgradesExecutor upgradeExecutor = new UpgradesExecutor(configManager); - - try { - boolean allUpgradesSuccessful = upgradeExecutor.run(isFreshInstall, errorCollector); - if (!allUpgradesSuccessful) { - errorCollector.add(ErrorMessages.Upgrade.failedSomeUpgrades); - } - } catch (UpgradeExecutorException e) { - errorCollector.add(ErrorMessages.Upgrade.genericExecutorError, e); - errorCollector.add(ErrorMessages.Upgrade.failedSomeUpgrades); - } - - settings = configManager.tryLoadSettings(errorCollector); - lang = configManager.tryLoadLang(errorCollector); - placeholders = configManager.tryLoadCustomPlaceholders(errorCollector); - PlaceholderManager.setStaticPlaceholders(placeholders.getPlaceholders()); - - // Create the menu folder with the example menu - if (!Files.isDirectory(configManager.getMenusFolder())) { - ConfigLoader exampleMenuLoader = configManager.getConfigLoader(configManager.getMenusFolder().resolve("example.yml")); - configManager.tryCreateDefault(errorCollector, exampleMenuLoader); - } - - List loadedMenus = configManager.tryLoadMenus(errorCollector); - for (LoadedMenu loadedMenu : loadedMenus) { - menuManager.registerMenu(loadedMenu, errorCollector); - } - - ChestCommands.lastLoadErrors = errorCollector; - return errorCollector; - } - - public static void closeAllMenus() { - for (Player player : Bukkit.getOnlinePlayers()) { - if (MenuManager.getOpenMenuInventory(player) != null) { - player.closeInventory(); - } - } - } - - - public static Plugin getPluginInstance() { - return pluginInstance; - } - - public static Path getDataFolderPath() { - return dataFolderPath; - } - - public static MenuManager getMenuManager() { - return menuManager; - } - - public static Settings getSettings() { - return settings; - } - - public static Lang getLang() { - return lang; - } - - public static boolean hasNewVersion() { - return newVersion != null; - } - - public static String getNewVersion() { - return newVersion; - } - - public static ErrorCollector getLastLoadErrors() { - return lastLoadErrors; - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands; + +import me.filoghost.chestcommands.api.internal.BackendAPI; +import me.filoghost.chestcommands.command.CommandHandler; +import me.filoghost.chestcommands.config.ConfigManager; +import me.filoghost.chestcommands.config.CustomPlaceholders; +import me.filoghost.chestcommands.config.Lang; +import me.filoghost.chestcommands.config.Settings; +import me.filoghost.chestcommands.hook.BarAPIHook; +import me.filoghost.chestcommands.hook.BungeeCordHook; +import me.filoghost.chestcommands.hook.PlaceholderAPIHook; +import me.filoghost.chestcommands.hook.VaultEconomyHook; +import me.filoghost.chestcommands.legacy.UpgradeExecutorException; +import me.filoghost.chestcommands.legacy.UpgradesExecutor; +import me.filoghost.chestcommands.listener.CommandListener; +import me.filoghost.chestcommands.listener.InventoryListener; +import me.filoghost.chestcommands.listener.JoinListener; +import me.filoghost.chestcommands.listener.SignListener; +import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.PrintableErrorCollector; +import me.filoghost.chestcommands.menu.MenuManager; +import me.filoghost.chestcommands.parsing.menu.LoadedMenu; +import me.filoghost.chestcommands.placeholder.PlaceholderManager; +import me.filoghost.chestcommands.task.TickingTask; +import me.filoghost.commons.BaseJavaPlugin; +import me.filoghost.commons.CommonsUtil; +import me.filoghost.commons.command.CommandFramework; +import me.filoghost.commons.config.ConfigLoader; +import me.filoghost.commons.logging.ErrorCollector; +import me.filoghost.commons.logging.Log; +import me.filoghost.updatechecker.UpdateChecker; +import org.bstats.bukkit.MetricsLite; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +public class ChestCommands extends BaseJavaPlugin { + + + public static final String CHAT_PREFIX = ChatColor.DARK_GREEN + "[" + ChatColor.GREEN + "ChestCommands" + ChatColor.DARK_GREEN + "] " + ChatColor.GREEN; + + private static Plugin pluginInstance; + private static Path dataFolderPath; + + private static ConfigManager configManager; + private static MenuManager menuManager; + private static Settings settings; + private static Lang lang; + private static CustomPlaceholders placeholders; + + private static ErrorCollector lastLoadErrors; + private static String newVersion; + + @Override + protected void onCheckedEnable() throws PluginEnableException { + if (!CommonsUtil.isClassLoaded("org.bukkit.inventory.ItemFlag")) { // ItemFlag was added in 1.8 + if (Bukkit.getVersion().contains("(MC: 1.8)")) { + throw new PluginEnableException("ChestCommands requires a more recent version of Bukkit 1.8 to run."); + } else { + throw new PluginEnableException("ChestCommands requires at least Bukkit 1.8 to run."); + } + } + + if (pluginInstance != null || System.getProperty("ChestCommandsLoaded") != null) { + Log.warning("Please do not use /reload or plugin reloaders. Use the command \"/cc reload\" instead."); + return; + } + + System.setProperty("ChestCommandsLoaded", "true"); + + pluginInstance = this; + dataFolderPath = getDataFolder().toPath(); + Log.setLogger(getLogger()); + configManager = new ConfigManager(getDataFolderPath()); + menuManager = new MenuManager(); + settings = new Settings(); + lang = new Lang(); + placeholders = new CustomPlaceholders(); + + BackendAPI.setImplementation(new DefaultBackendAPI()); + + VaultEconomyHook.INSTANCE.setup(); + BarAPIHook.INSTANCE.setup(); + PlaceholderAPIHook.INSTANCE.setup(); + BungeeCordHook.INSTANCE.setup(); + + if (VaultEconomyHook.INSTANCE.isEnabled()) { + Log.info("Hooked Vault"); + } else { + Log.warning("Couldn't find Vault and a compatible economy plugin! Money-related features will not work."); + } + + if (BarAPIHook.INSTANCE.isEnabled()) { + Log.info("Hooked BarAPI"); + } + + if (PlaceholderAPIHook.INSTANCE.isEnabled()) { + Log.info("Hooked PlaceholderAPI"); + } + + if (settings.update_notifications) { + UpdateChecker.run(this, 56919, (String newVersion) -> { + ChestCommands.newVersion = newVersion; + + Log.info("Found a new version: " + newVersion + " (yours: v" + getDescription().getVersion() + ")"); + Log.info("Download the update on Bukkit Dev:"); + Log.info("https://dev.bukkit.org/projects/chest-commands"); + }); + } + + // Start bStats metrics + int pluginID = 3658; + new MetricsLite(this, pluginID); + + Bukkit.getPluginManager().registerEvents(new CommandListener(menuManager), this); + Bukkit.getPluginManager().registerEvents(new InventoryListener(menuManager), this); + Bukkit.getPluginManager().registerEvents(new JoinListener(), this); + Bukkit.getPluginManager().registerEvents(new SignListener(menuManager), this); + + CommandFramework.register(this, new CommandHandler(menuManager, "chestcommands")); + + ErrorCollector errorCollector = load(); + + if (errorCollector.hasErrors()) { + errorCollector.logToConsole(); + Bukkit.getScheduler().runTaskLater(this, () -> { + Bukkit.getConsoleSender().sendMessage( + ChestCommands.CHAT_PREFIX + ChatColor.RED + "Encountered " + errorCollector.getErrorsCount() + " error(s) on load. " + + "Check previous console logs or run \"/chestcommands errors\" to see them again."); + }, 10L); + } + + Bukkit.getScheduler().runTaskTimer(this, new TickingTask(), 1L, 1L); + } + + @Override + public void onDisable() { + closeAllMenus(); + } + + public static ErrorCollector load() { + ErrorCollector errorCollector = new PrintableErrorCollector(); + menuManager.clear(); + boolean isFreshInstall = !Files.isDirectory(configManager.getRootDataFolder()); + try { + Files.createDirectories(configManager.getRootDataFolder()); + } catch (IOException e) { + errorCollector.add(ErrorMessages.Config.createDataFolderIOException, e); + return errorCollector; + } + + UpgradesExecutor upgradeExecutor = new UpgradesExecutor(configManager); + + try { + boolean allUpgradesSuccessful = upgradeExecutor.run(isFreshInstall, errorCollector); + if (!allUpgradesSuccessful) { + errorCollector.add(ErrorMessages.Upgrade.failedSomeUpgrades); + } + } catch (UpgradeExecutorException e) { + errorCollector.add(ErrorMessages.Upgrade.genericExecutorError, e); + errorCollector.add(ErrorMessages.Upgrade.failedSomeUpgrades); + } + + settings = configManager.tryLoadSettings(errorCollector); + lang = configManager.tryLoadLang(errorCollector); + placeholders = configManager.tryLoadCustomPlaceholders(errorCollector); + PlaceholderManager.setStaticPlaceholders(placeholders.getPlaceholders()); + + // Create the menu folder with the example menu + if (!Files.isDirectory(configManager.getMenusFolder())) { + ConfigLoader exampleMenuLoader = configManager.getConfigLoader(configManager.getMenusFolder().resolve("example.yml")); + configManager.tryCreateDefault(errorCollector, exampleMenuLoader); + } + + List loadedMenus = configManager.tryLoadMenus(errorCollector); + for (LoadedMenu loadedMenu : loadedMenus) { + menuManager.registerMenu(loadedMenu, errorCollector); + } + + ChestCommands.lastLoadErrors = errorCollector; + return errorCollector; + } + + public static void closeAllMenus() { + for (Player player : Bukkit.getOnlinePlayers()) { + if (MenuManager.getOpenMenuInventory(player) != null) { + player.closeInventory(); + } + } + } + + + public static Plugin getPluginInstance() { + return pluginInstance; + } + + public static Path getDataFolderPath() { + return dataFolderPath; + } + + public static MenuManager getMenuManager() { + return menuManager; + } + + public static Settings getSettings() { + return settings; + } + + public static Lang getLang() { + return lang; + } + + public static boolean hasNewVersion() { + return newVersion != null; + } + + public static String getNewVersion() { + return newVersion; + } + + public static ErrorCollector getLastLoadErrors() { + return lastLoadErrors; + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java b/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java index 9a929da..13e247d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java @@ -1,29 +1,29 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands; - -public class Permissions { - - public static final String - - BASE_PREFIX = "chestcommands.", - COMMAND_PREFIX = BASE_PREFIX + "command.", - OPEN_MENU_PREFIX = BASE_PREFIX + "open.", - - UPDATE_NOTIFICATIONS = BASE_PREFIX + "update", - SEE_ERRORS = BASE_PREFIX + "errors", - SIGN_CREATE = BASE_PREFIX + "sign"; - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands; + +public class Permissions { + + public static final String + + BASE_PREFIX = "chestcommands.", + COMMAND_PREFIX = BASE_PREFIX + "command.", + OPEN_MENU_PREFIX = BASE_PREFIX + "open.", + + UPDATE_NOTIFICATIONS = BASE_PREFIX + "update", + SEE_ERRORS = BASE_PREFIX + "errors", + SIGN_CREATE = BASE_PREFIX + "sign"; + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java index 426d0eb..f60f0bb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java @@ -1,23 +1,23 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.action; - -import org.bukkit.entity.Player; - -public interface Action { - - void execute(Player player); - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.action; + +import org.bukkit.entity.Player; + +public interface Action { + + void execute(Player player); + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java index 37edba7..0fd4531 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java @@ -1,35 +1,35 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.action; - -import me.filoghost.chestcommands.placeholder.PlaceholderString; -import me.filoghost.chestcommands.util.Colors; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -public class BroadcastAction implements Action { - - private final PlaceholderString message; - - public BroadcastAction(String serializedAction) { - message = PlaceholderString.of(Colors.addColors(serializedAction)); - } - - @Override - public void execute(Player player) { - Bukkit.broadcastMessage(message.getValue(player)); - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.action; + +import me.filoghost.chestcommands.placeholder.PlaceholderString; +import me.filoghost.commons.Colors; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class BroadcastAction implements Action { + + private final PlaceholderString message; + + public BroadcastAction(String serializedAction) { + message = PlaceholderString.of(Colors.addColors(serializedAction)); + } + + @Override + public void execute(Player player) { + Bukkit.broadcastMessage(message.getValue(player)); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java index e54a906..eb7ba5a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java @@ -1,34 +1,34 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.action; - -import me.filoghost.chestcommands.hook.BungeeCordHook; -import me.filoghost.chestcommands.placeholder.PlaceholderString; -import org.bukkit.entity.Player; - -public class ChangeServerAction implements Action { - - private final PlaceholderString targetServer; - - public ChangeServerAction(String serializedAction) { - targetServer = PlaceholderString.of(serializedAction); - } - - @Override - public void execute(Player player) { - BungeeCordHook.connect(player, targetServer.getValue(player)); - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.action; + +import me.filoghost.chestcommands.hook.BungeeCordHook; +import me.filoghost.chestcommands.placeholder.PlaceholderString; +import org.bukkit.entity.Player; + +public class ChangeServerAction implements Action { + + private final PlaceholderString targetServer; + + public ChangeServerAction(String serializedAction) { + targetServer = PlaceholderString.of(serializedAction); + } + + @Override + public void execute(Player player) { + BungeeCordHook.connect(player, targetServer.getValue(player)); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java index c23db2e..1926968 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java @@ -1,34 +1,34 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.action; - -import me.filoghost.chestcommands.placeholder.PlaceholderString; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -public class ConsoleCommandAction implements Action { - - private final PlaceholderString command; - - public ConsoleCommandAction(String serializedAction) { - command = PlaceholderString.of(serializedAction); - } - - @Override - public void execute(Player player) { - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.getValue(player)); - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.action; + +import me.filoghost.chestcommands.placeholder.PlaceholderString; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class ConsoleCommandAction implements Action { + + private final PlaceholderString command; + + public ConsoleCommandAction(String serializedAction) { + command = PlaceholderString.of(serializedAction); + } + + @Override + public void execute(Player player) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.getValue(player)); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java index bef01b7..3f91aa5 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java @@ -1,59 +1,59 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.action; - -import me.filoghost.chestcommands.hook.BarAPIHook; -import me.filoghost.chestcommands.logging.ErrorMessages; -import me.filoghost.chestcommands.parsing.NumberParser; -import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.placeholder.PlaceholderString; -import me.filoghost.chestcommands.util.Colors; -import me.filoghost.chestcommands.util.Strings; -import org.bukkit.entity.Player; - -public class DragonBarAction implements Action { - - private final PlaceholderString message; - private final int seconds; - - public DragonBarAction(String serialiazedAction) throws ParseException { - String message; - - String[] split = Strings.trimmedSplit(serialiazedAction, "\\|", 2); // Max of 2 pieces - if (split.length > 1) { - try { - seconds = NumberParser.getStrictlyPositiveInteger(split[0]); - message = split[1]; - } catch (ParseException e) { - throw new ParseException(ErrorMessages.Parsing.invalidBossBarTime(split[0]), e); - } - } else { - seconds = 1; - message = serialiazedAction; - } - - this.message = PlaceholderString.of(Colors.addColors(message)); - } - - @Override - public void execute(Player player) { - if (BarAPIHook.INSTANCE.isEnabled()) { - BarAPIHook.setMessage(player, message.getValue(player), seconds); - } else { - player.sendMessage(ErrorMessages.User.configurationError("BarAPI plugin not found")); - } - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.action; + +import me.filoghost.chestcommands.hook.BarAPIHook; +import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.parsing.NumberParser; +import me.filoghost.chestcommands.parsing.ParseException; +import me.filoghost.chestcommands.placeholder.PlaceholderString; +import me.filoghost.commons.Colors; +import me.filoghost.commons.Strings; +import org.bukkit.entity.Player; + +public class DragonBarAction implements Action { + + private final PlaceholderString message; + private final int seconds; + + public DragonBarAction(String serialiazedAction) throws ParseException { + String message; + + String[] split = Strings.trimmedSplit(serialiazedAction, "\\|", 2); // Max of 2 pieces + if (split.length > 1) { + try { + seconds = NumberParser.getStrictlyPositiveInteger(split[0]); + message = split[1]; + } catch (ParseException e) { + throw new ParseException(ErrorMessages.Parsing.invalidBossBarTime(split[0]), e); + } + } else { + seconds = 1; + message = serialiazedAction; + } + + this.message = PlaceholderString.of(Colors.addColors(message)); + } + + @Override + public void execute(Player player) { + if (BarAPIHook.INSTANCE.isEnabled()) { + BarAPIHook.setMessage(player, message.getValue(player), seconds); + } else { + player.sendMessage(ErrorMessages.User.configurationError("BarAPI plugin not found")); + } + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java index b5c374a..9cd140c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java @@ -1,36 +1,36 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.action; - -import me.filoghost.chestcommands.parsing.ItemStackParser; -import me.filoghost.chestcommands.parsing.ParseException; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public class GiveItemAction implements Action { - - private final ItemStack itemToGive; - - public GiveItemAction(String serializedAction) throws ParseException { - ItemStackParser reader = new ItemStackParser(serializedAction, true); - itemToGive = reader.createStack(); - } - - @Override - public void execute(Player player) { - player.getInventory().addItem(itemToGive.clone()); - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.action; + +import me.filoghost.chestcommands.parsing.ItemStackParser; +import me.filoghost.chestcommands.parsing.ParseException; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class GiveItemAction implements Action { + + private final ItemStack itemToGive; + + public GiveItemAction(String serializedAction) throws ParseException { + ItemStackParser reader = new ItemStackParser(serializedAction, true); + itemToGive = reader.createStack(); + } + + @Override + public void execute(Player player) { + player.getInventory().addItem(itemToGive.clone()); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java index 7e84c4e..fc70aeb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java @@ -1,40 +1,40 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.action; - -import me.filoghost.chestcommands.hook.VaultEconomyHook; -import me.filoghost.chestcommands.logging.ErrorMessages; -import me.filoghost.chestcommands.parsing.NumberParser; -import me.filoghost.chestcommands.parsing.ParseException; -import org.bukkit.entity.Player; - -public class GiveMoneyAction implements Action { - - private final double moneyToGive; - - public GiveMoneyAction(String serializedAction) throws ParseException { - moneyToGive = NumberParser.getStrictlyPositiveDouble(serializedAction); - } - - @Override - public void execute(Player player) { - if (VaultEconomyHook.INSTANCE.isEnabled()) { - VaultEconomyHook.giveMoney(player, moneyToGive); - } else { - player.sendMessage(ErrorMessages.User.configurationError("Vault with a compatible economy plugin not found")); - } - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.action; + +import me.filoghost.chestcommands.hook.VaultEconomyHook; +import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.parsing.NumberParser; +import me.filoghost.chestcommands.parsing.ParseException; +import org.bukkit.entity.Player; + +public class GiveMoneyAction implements Action { + + private final double moneyToGive; + + public GiveMoneyAction(String serializedAction) throws ParseException { + moneyToGive = NumberParser.getStrictlyPositiveDouble(serializedAction); + } + + @Override + public void execute(Player player) { + if (VaultEconomyHook.INSTANCE.isEnabled()) { + VaultEconomyHook.giveMoney(player, moneyToGive); + } else { + player.sendMessage(ErrorMessages.User.configurationError("Vault with a compatible economy plugin not found")); + } + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java index 7881a0e..457819e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java @@ -1,39 +1,39 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.action; - -import me.filoghost.chestcommands.placeholder.PlaceholderString; -import org.bukkit.entity.Player; - -public class OpCommandAction implements Action { - - private final PlaceholderString command; - - public OpCommandAction(String serializedAction) { - command = PlaceholderString.of(serializedAction); - } - - @Override - public void execute(Player player) { - if (player.isOp()) { - player.chat("/" + command.getValue(player)); - } else { - player.setOp(true); - player.chat("/" + command.getValue(player)); - player.setOp(false); - } - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.action; + +import me.filoghost.chestcommands.placeholder.PlaceholderString; +import org.bukkit.entity.Player; + +public class OpCommandAction implements Action { + + private final PlaceholderString command; + + public OpCommandAction(String serializedAction) { + command = PlaceholderString.of(serializedAction); + } + + @Override + public void execute(Player player) { + if (player.isOp()) { + player.chat("/" + command.getValue(player)); + } else { + player.setOp(true); + player.chat("/" + command.getValue(player)); + player.setOp(false); + } + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java index 8ea97ea..7ba1b84 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java @@ -1,51 +1,51 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.action; - -import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.logging.ErrorMessages; -import me.filoghost.chestcommands.menu.InternalIconMenu; -import me.filoghost.chestcommands.placeholder.PlaceholderString; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -public class OpenMenuAction implements Action { - - private final PlaceholderString targetMenu; - - public OpenMenuAction(String serializedAction) { - targetMenu = PlaceholderString.of(serializedAction); - } - - @Override - public void execute(final Player player) { - String menuName = targetMenu.getValue(player); - final InternalIconMenu menu = ChestCommands.getMenuManager().getMenuByFileName(menuName); - - if (menu != null) { - /* - * Delay the task, since this action is executed in ClickInventoryEvent - * and opening another inventory in the same moment is not a good idea. - */ - Bukkit.getScheduler().runTask(ChestCommands.getPluginInstance(), () -> { - menu.openCheckingPermission(player); - }); - - } else { - player.sendMessage(ErrorMessages.User.configurationError("couldn't find the menu \"" + menuName + "\"")); - } - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.action; + +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.menu.InternalIconMenu; +import me.filoghost.chestcommands.placeholder.PlaceholderString; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class OpenMenuAction implements Action { + + private final PlaceholderString targetMenu; + + public OpenMenuAction(String serializedAction) { + targetMenu = PlaceholderString.of(serializedAction); + } + + @Override + public void execute(final Player player) { + String menuName = targetMenu.getValue(player); + final InternalIconMenu menu = ChestCommands.getMenuManager().getMenuByFileName(menuName); + + if (menu != null) { + /* + * Delay the task, since this action is executed in ClickInventoryEvent + * and opening another inventory in the same moment is not a good idea. + */ + Bukkit.getScheduler().runTask(ChestCommands.getPluginInstance(), () -> { + menu.openCheckingPermission(player); + }); + + } else { + player.sendMessage(ErrorMessages.User.configurationError("couldn't find the menu \"" + menuName + "\"")); + } + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java index 05f0e1c..b7eacc4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java @@ -1,70 +1,70 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.action; - -import me.filoghost.chestcommands.logging.ErrorMessages; -import me.filoghost.chestcommands.parsing.NumberParser; -import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.util.Strings; -import me.filoghost.chestcommands.util.collection.Registry; -import org.bukkit.Sound; -import org.bukkit.entity.Player; - -import java.util.Optional; - -public class PlaySoundAction implements Action { - - private static final Registry SOUNDS_REGISTRY = Registry.fromEnumValues(Sound.class); - - private final Sound sound; - private final float pitch; - private final float volume; - - public PlaySoundAction(String serializedAction) throws ParseException { - String[] split = Strings.trimmedSplit(serializedAction, ",", 3); - - Optional sound = SOUNDS_REGISTRY.find(split[0]); - if (!sound.isPresent()) { - throw new ParseException(ErrorMessages.Parsing.unknownSound(split[0])); - } - this.sound = sound.get(); - - if (split.length > 1) { - try { - pitch = NumberParser.getFloat(split[1]); - } catch (ParseException e) { - throw new ParseException(ErrorMessages.Parsing.invalidSoundPitch(split[1]), e); - } - } else { - pitch = 1.0f; - } - - if (split.length > 2) { - try { - volume = NumberParser.getFloat(split[2]); - } catch (ParseException e) { - throw new ParseException(ErrorMessages.Parsing.invalidSoundVolume(split[2]), e); - } - } else { - volume = 1.0f; - } - } - - @Override - public void execute(Player player) { - player.playSound(player.getLocation(), sound, volume, pitch); - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.action; + +import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.parsing.NumberParser; +import me.filoghost.chestcommands.parsing.ParseException; +import me.filoghost.commons.Strings; +import me.filoghost.commons.collection.Registry; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import java.util.Optional; + +public class PlaySoundAction implements Action { + + private static final Registry SOUNDS_REGISTRY = Registry.fromEnumValues(Sound.class); + + private final Sound sound; + private final float pitch; + private final float volume; + + public PlaySoundAction(String serializedAction) throws ParseException { + String[] split = Strings.trimmedSplit(serializedAction, ",", 3); + + Optional sound = SOUNDS_REGISTRY.find(split[0]); + if (!sound.isPresent()) { + throw new ParseException(ErrorMessages.Parsing.unknownSound(split[0])); + } + this.sound = sound.get(); + + if (split.length > 1) { + try { + pitch = NumberParser.getFloat(split[1]); + } catch (ParseException e) { + throw new ParseException(ErrorMessages.Parsing.invalidSoundPitch(split[1]), e); + } + } else { + pitch = 1.0f; + } + + if (split.length > 2) { + try { + volume = NumberParser.getFloat(split[2]); + } catch (ParseException e) { + throw new ParseException(ErrorMessages.Parsing.invalidSoundVolume(split[2]), e); + } + } else { + volume = 1.0f; + } + } + + @Override + public void execute(Player player) { + player.playSound(player.getLocation(), sound, volume, pitch); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java index 9efeec7..85a8cf9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java @@ -1,33 +1,33 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.action; - -import me.filoghost.chestcommands.placeholder.PlaceholderString; -import org.bukkit.entity.Player; - -public class PlayerCommandAction implements Action { - - private final PlaceholderString command; - - public PlayerCommandAction(String serializedAction) { - command = PlaceholderString.of(serializedAction); - } - - @Override - public void execute(Player player) { - player.chat('/' + command.getValue(player)); - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.action; + +import me.filoghost.chestcommands.placeholder.PlaceholderString; +import org.bukkit.entity.Player; + +public class PlayerCommandAction implements Action { + + private final PlaceholderString command; + + public PlayerCommandAction(String serializedAction) { + command = PlaceholderString.of(serializedAction); + } + + @Override + public void execute(Player player) { + player.chat('/' + command.getValue(player)); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java index d085857..b45d01c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java @@ -1,34 +1,34 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.action; - -import me.filoghost.chestcommands.placeholder.PlaceholderString; -import me.filoghost.chestcommands.util.Colors; -import org.bukkit.entity.Player; - -public class SendMessageAction implements Action { - - private final PlaceholderString message; - - public SendMessageAction(String serializedAction) { - message = PlaceholderString.of(Colors.addColors(serializedAction)); - } - - @Override - public void execute(Player player) { - player.sendMessage(message.getValue(player)); - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.action; + +import me.filoghost.chestcommands.placeholder.PlaceholderString; +import me.filoghost.commons.Colors; +import org.bukkit.entity.Player; + +public class SendMessageAction implements Action { + + private final PlaceholderString message; + + public SendMessageAction(String serializedAction) { + message = PlaceholderString.of(Colors.addColors(serializedAction)); + } + + @Override + public void execute(Player player) { + player.sendMessage(message.getValue(player)); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java index f547878..7d7ac19 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java @@ -16,8 +16,8 @@ package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -import me.filoghost.chestcommands.util.Colors; -import me.filoghost.chestcommands.util.collection.CollectionUtils; +import me.filoghost.commons.Colors; +import me.filoghost.commons.collection.CollectionUtils; import org.bukkit.ChatColor; import java.util.List; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java index 9488436..b34b0ba 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java @@ -17,7 +17,7 @@ package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.util.MaterialsHelper; +import me.filoghost.commons.MaterialsHelper; import org.bukkit.Material; import java.util.Optional; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java index b46e101..fa32ec9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java @@ -16,7 +16,7 @@ package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -import me.filoghost.chestcommands.util.Colors; +import me.filoghost.commons.Colors; import org.bukkit.ChatColor; public class NameAttribute implements IconAttribute { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index 1a6e8a2..32f512c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -1,162 +1,162 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.command; - -import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.Permissions; -import me.filoghost.chestcommands.command.framework.CommandFramework; -import me.filoghost.chestcommands.command.framework.CommandValidate; -import me.filoghost.chestcommands.menu.InternalIconMenu; -import me.filoghost.chestcommands.menu.MenuManager; -import me.filoghost.chestcommands.util.Utils; -import me.filoghost.chestcommands.util.logging.ErrorCollector; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.entity.Player; - -public class CommandHandler extends CommandFramework { - - private final MenuManager menuManager; - - public CommandHandler(MenuManager menuManager, String label) { - super(label); - this.menuManager = menuManager; - } - - @SuppressWarnings("deprecation") - @Override - public void execute(CommandSender sender, String label, String[] args) { - if (args.length == 0) { - // This info is accessible to anyone. Please don't remove it, remember that Chest Commands is developed for free - sender.sendMessage(ChestCommands.CHAT_PREFIX); - sender.sendMessage(ChatColor.GREEN + "Version: " + ChatColor.GRAY + ChestCommands.getPluginInstance().getDescription().getVersion()); - sender.sendMessage(ChatColor.GREEN + "Developer: " + ChatColor.GRAY + "filoghost"); - sender.sendMessage(ChatColor.GREEN + "Commands: " + ChatColor.GRAY + "/" + label + " help"); - return; - } - - - if (args[0].equalsIgnoreCase("help")) { - checkCommandPermission(sender, "help"); - sender.sendMessage(ChestCommands.CHAT_PREFIX + "Commands:"); - sender.sendMessage(ChatColor.WHITE + "/" + label + " reload" + ChatColor.GRAY + " - Reloads the plugin."); - sender.sendMessage(ChatColor.WHITE + "/" + label + " errors" + ChatColor.GRAY + " - Displays the last load errors on the console."); - sender.sendMessage(ChatColor.WHITE + "/" + label + " list" + ChatColor.GRAY + " - Lists the loaded menus."); - sender.sendMessage(ChatColor.WHITE + "/" + label + " open [player]" + ChatColor.GRAY + " - Opens a menu for a player."); - return; - } - - - if (args[0].equalsIgnoreCase("errors")) { - checkCommandPermission(sender, "errors"); - ErrorCollector errorCollector = ChestCommands.getLastLoadErrors(); - - if (errorCollector.hasErrors()) { - errorCollector.logToConsole(); - sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Last time the plugin loaded, " + errorCollector.getErrorsCount() + " error(s) were found."); - if (!(sender instanceof ConsoleCommandSender)) { - sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Errors were printed on the console."); - } - } else { - sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.GREEN + "Last plugin load was successful, no errors logged."); - } - return; - } - - - if (args[0].equalsIgnoreCase("reload")) { - checkCommandPermission(sender, "reload"); - - ChestCommands.closeAllMenus(); - - ErrorCollector errorCollector = ChestCommands.load(); - - if (!errorCollector.hasErrors()) { - sender.sendMessage(ChestCommands.CHAT_PREFIX + "Plugin reloaded."); - } else { - errorCollector.logToConsole(); - sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Plugin reloaded with " + errorCollector.getErrorsCount() + " error(s)."); - if (!(sender instanceof ConsoleCommandSender)) { - sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Please check the console."); - } - } - return; - } - - - if (args[0].equalsIgnoreCase("open")) { - checkCommandPermission(sender, "open"); - CommandValidate.minLength(args, 2, "Usage: /" + label + " open [player]"); - - Player target; - - if (sender instanceof Player) { - if (args.length > 2) { - checkCommandPermission(sender, "open.others"); - target = Bukkit.getPlayerExact(args[2]); - } else { - target = (Player) sender; - } - } else { - CommandValidate.minLength(args, 3, "You must specify a player from the console."); - target = Bukkit.getPlayerExact(args[2]); - } - - CommandValidate.notNull(target, "That player is not online."); - - String menuName = Utils.addYamlExtension(args[1]); - InternalIconMenu menu = menuManager.getMenuByFileName(menuName); - CommandValidate.notNull(menu, "The menu \"" + menuName + "\" was not found."); - - if (!sender.hasPermission(menu.getOpenPermission())) { - menu.sendNoOpenPermissionMessage(sender); - return; - } - - if (sender.getName().equalsIgnoreCase(target.getName())) { - if (!ChestCommands.getLang().open_menu.isEmpty()) { - sender.sendMessage(ChestCommands.getLang().open_menu.replace("{menu}", menuName)); - } - } else { - if (!ChestCommands.getLang().open_menu_others.isEmpty()) { - sender.sendMessage(ChestCommands.getLang().open_menu_others.replace("{menu}", menuName).replace("{player}", target.getName())); - } - } - - menu.open(target); - return; - } - - - if (args[0].equalsIgnoreCase("list")) { - checkCommandPermission(sender, "list"); - sender.sendMessage(ChestCommands.CHAT_PREFIX + "Loaded menus:"); - for (String file : menuManager.getMenuFileNames()) { - sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.WHITE + file); - } - - return; - } - - sender.sendMessage(ChatColor.RED + "Unknown sub-command \"" + args[0] + "\"."); - } - - private void checkCommandPermission(CommandSender sender, String commandPermission) { - CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + commandPermission), "You don't have permission."); - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.command; + +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.Permissions; +import me.filoghost.chestcommands.menu.InternalIconMenu; +import me.filoghost.chestcommands.menu.MenuManager; +import me.filoghost.chestcommands.util.Utils; +import me.filoghost.commons.command.CommandFramework; +import me.filoghost.commons.command.CommandValidate; +import me.filoghost.commons.logging.ErrorCollector; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; + +public class CommandHandler extends CommandFramework { + + private final MenuManager menuManager; + + public CommandHandler(MenuManager menuManager, String label) { + super(label); + this.menuManager = menuManager; + } + + @SuppressWarnings("deprecation") + @Override + public void execute(CommandSender sender, String label, String[] args) { + if (args.length == 0) { + // This info is accessible to anyone. Please don't remove it, remember that Chest Commands is developed for free + sender.sendMessage(ChestCommands.CHAT_PREFIX); + sender.sendMessage(ChatColor.GREEN + "Version: " + ChatColor.GRAY + ChestCommands.getPluginInstance().getDescription().getVersion()); + sender.sendMessage(ChatColor.GREEN + "Developer: " + ChatColor.GRAY + "filoghost"); + sender.sendMessage(ChatColor.GREEN + "Commands: " + ChatColor.GRAY + "/" + label + " help"); + return; + } + + + if (args[0].equalsIgnoreCase("help")) { + checkCommandPermission(sender, "help"); + sender.sendMessage(ChestCommands.CHAT_PREFIX + "Commands:"); + sender.sendMessage(ChatColor.WHITE + "/" + label + " reload" + ChatColor.GRAY + " - Reloads the plugin."); + sender.sendMessage(ChatColor.WHITE + "/" + label + " errors" + ChatColor.GRAY + " - Displays the last load errors on the console."); + sender.sendMessage(ChatColor.WHITE + "/" + label + " list" + ChatColor.GRAY + " - Lists the loaded menus."); + sender.sendMessage(ChatColor.WHITE + "/" + label + " open [player]" + ChatColor.GRAY + " - Opens a menu for a player."); + return; + } + + + if (args[0].equalsIgnoreCase("errors")) { + checkCommandPermission(sender, "errors"); + ErrorCollector errorCollector = ChestCommands.getLastLoadErrors(); + + if (errorCollector.hasErrors()) { + errorCollector.logToConsole(); + sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Last time the plugin loaded, " + errorCollector.getErrorsCount() + " error(s) were found."); + if (!(sender instanceof ConsoleCommandSender)) { + sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Errors were printed on the console."); + } + } else { + sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.GREEN + "Last plugin load was successful, no errors logged."); + } + return; + } + + + if (args[0].equalsIgnoreCase("reload")) { + checkCommandPermission(sender, "reload"); + + ChestCommands.closeAllMenus(); + + ErrorCollector errorCollector = ChestCommands.load(); + + if (!errorCollector.hasErrors()) { + sender.sendMessage(ChestCommands.CHAT_PREFIX + "Plugin reloaded."); + } else { + errorCollector.logToConsole(); + sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Plugin reloaded with " + errorCollector.getErrorsCount() + " error(s)."); + if (!(sender instanceof ConsoleCommandSender)) { + sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Please check the console."); + } + } + return; + } + + + if (args[0].equalsIgnoreCase("open")) { + checkCommandPermission(sender, "open"); + CommandValidate.minLength(args, 2, "Usage: /" + label + " open [player]"); + + Player target; + + if (sender instanceof Player) { + if (args.length > 2) { + checkCommandPermission(sender, "open.others"); + target = Bukkit.getPlayerExact(args[2]); + } else { + target = (Player) sender; + } + } else { + CommandValidate.minLength(args, 3, "You must specify a player from the console."); + target = Bukkit.getPlayerExact(args[2]); + } + + CommandValidate.notNull(target, "That player is not online."); + + String menuName = Utils.addYamlExtension(args[1]); + InternalIconMenu menu = menuManager.getMenuByFileName(menuName); + CommandValidate.notNull(menu, "The menu \"" + menuName + "\" was not found."); + + if (!sender.hasPermission(menu.getOpenPermission())) { + menu.sendNoOpenPermissionMessage(sender); + return; + } + + if (sender.getName().equalsIgnoreCase(target.getName())) { + if (!ChestCommands.getLang().open_menu.isEmpty()) { + sender.sendMessage(ChestCommands.getLang().open_menu.replace("{menu}", menuName)); + } + } else { + if (!ChestCommands.getLang().open_menu_others.isEmpty()) { + sender.sendMessage(ChestCommands.getLang().open_menu_others.replace("{menu}", menuName).replace("{player}", target.getName())); + } + } + + menu.open(target); + return; + } + + + if (args[0].equalsIgnoreCase("list")) { + checkCommandPermission(sender, "list"); + sender.sendMessage(ChestCommands.CHAT_PREFIX + "Loaded menus:"); + for (String file : menuManager.getMenuFileNames()) { + sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.WHITE + file); + } + + return; + } + + sender.sendMessage(ChatColor.RED + "Unknown sub-command \"" + args[0] + "\"."); + } + + private void checkCommandPermission(CommandSender sender, String commandPermission) { + CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + commandPermission), "You don't have permission."); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java index 8e90537..b761cb4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java @@ -14,16 +14,16 @@ */ package me.filoghost.chestcommands.config; -import me.filoghost.chestcommands.config.framework.BaseConfigManager; -import me.filoghost.chestcommands.config.framework.Config; -import me.filoghost.chestcommands.config.framework.ConfigLoader; -import me.filoghost.chestcommands.config.framework.exception.ConfigException; -import me.filoghost.chestcommands.config.framework.mapped.MappedConfigLoader; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.menu.LoadedMenu; import me.filoghost.chestcommands.parsing.menu.MenuParser; -import me.filoghost.chestcommands.util.Preconditions; -import me.filoghost.chestcommands.util.logging.ErrorCollector; +import me.filoghost.commons.Preconditions; +import me.filoghost.commons.config.BaseConfigManager; +import me.filoghost.commons.config.Config; +import me.filoghost.commons.config.ConfigLoader; +import me.filoghost.commons.config.exception.ConfigException; +import me.filoghost.commons.config.mapped.MappedConfigLoader; +import me.filoghost.commons.logging.ErrorCollector; import java.io.IOException; import java.nio.file.FileVisitOption; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java index d72fea9..c7e42c1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java @@ -14,12 +14,12 @@ */ package me.filoghost.chestcommands.config; -import me.filoghost.chestcommands.config.framework.Config; -import me.filoghost.chestcommands.config.framework.ConfigSection; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.placeholder.StaticPlaceholder; -import me.filoghost.chestcommands.util.Colors; -import me.filoghost.chestcommands.util.logging.ErrorCollector; +import me.filoghost.commons.Colors; +import me.filoghost.commons.config.Config; +import me.filoghost.commons.config.ConfigSection; +import me.filoghost.commons.logging.ErrorCollector; import java.util.ArrayList; import java.util.List; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java index a2a05ab..f8bd4e9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java @@ -14,9 +14,9 @@ */ package me.filoghost.chestcommands.config; -import me.filoghost.chestcommands.config.framework.mapped.MappedConfig; -import me.filoghost.chestcommands.config.framework.mapped.modifier.ChatColors; import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.commons.config.mapped.MappedConfig; +import me.filoghost.commons.config.mapped.modifier.ChatColors; @ChatColors public class Lang extends MappedConfig { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java index b293123..89d714c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java @@ -14,8 +14,8 @@ */ package me.filoghost.chestcommands.config; -import me.filoghost.chestcommands.config.framework.mapped.MappedConfig; -import me.filoghost.chestcommands.config.framework.mapped.modifier.ChatColors; +import me.filoghost.commons.config.mapped.MappedConfig; +import me.filoghost.commons.config.mapped.modifier.ChatColors; @ChatColors public class Settings extends MappedConfig { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java index 69237b8..d773203 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java @@ -1,44 +1,44 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.hook; - -import me.confuser.barapi.BarAPI; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -public enum BarAPIHook implements PluginHook { - - INSTANCE; - - private boolean enabled; - - @Override - public void setup() { - enabled = Bukkit.getPluginManager().getPlugin("BarAPI") != null; - } - - @Override - public boolean isEnabled() { - return enabled; - } - - @SuppressWarnings("deprecation") - public static void setMessage(Player player, String message, int seconds) { - INSTANCE.checkEnabledState(); - - BarAPI.setMessage(player, message, seconds); - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.hook; + +import me.confuser.barapi.BarAPI; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public enum BarAPIHook implements PluginHook { + + INSTANCE; + + private boolean enabled; + + @Override + public void setup() { + enabled = Bukkit.getPluginManager().getPlugin("BarAPI") != null; + } + + @Override + public boolean isEnabled() { + return enabled; + } + + @SuppressWarnings("deprecation") + public static void setMessage(Player player, String message, int seconds) { + INSTANCE.checkEnabledState(); + + BarAPI.setMessage(player, message, seconds); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java index 79223de..fd6d233 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java @@ -1,63 +1,63 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.hook; - -import me.filoghost.chestcommands.ChestCommands; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -public enum BungeeCordHook implements PluginHook { - - INSTANCE; - - @Override - public void setup() { - if (!Bukkit.getMessenger().isOutgoingChannelRegistered(ChestCommands.getPluginInstance(), "BungeeCord")) { - Bukkit.getMessenger().registerOutgoingPluginChannel(ChestCommands.getPluginInstance(), "BungeeCord"); - } - } - - @Override - public boolean isEnabled() { - return true; - } - - public static void connect(Player player, String server) { - INSTANCE.checkEnabledState(); - - if (server.length() == 0) { - player.sendMessage(ChatColor.RED + "Target server was an empty string, cannot connect to it."); - return; - } - - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); - - try { - dataOutputStream.writeUTF("Connect"); - dataOutputStream.writeUTF(server); // Target Server - } catch (IOException ex) { - throw new AssertionError(); - } - - player.sendPluginMessage(ChestCommands.getPluginInstance(), "BungeeCord", byteArrayOutputStream.toByteArray()); - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.hook; + +import me.filoghost.chestcommands.ChestCommands; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +public enum BungeeCordHook implements PluginHook { + + INSTANCE; + + @Override + public void setup() { + if (!Bukkit.getMessenger().isOutgoingChannelRegistered(ChestCommands.getPluginInstance(), "BungeeCord")) { + Bukkit.getMessenger().registerOutgoingPluginChannel(ChestCommands.getPluginInstance(), "BungeeCord"); + } + } + + @Override + public boolean isEnabled() { + return true; + } + + public static void connect(Player player, String server) { + INSTANCE.checkEnabledState(); + + if (server.length() == 0) { + player.sendMessage(ChatColor.RED + "Target server was an empty string, cannot connect to it."); + return; + } + + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); + + try { + dataOutputStream.writeUTF("Connect"); + dataOutputStream.writeUTF(server); // Target Server + } catch (IOException ex) { + throw new AssertionError(); + } + + player.sendPluginMessage(ChestCommands.getPluginInstance(), "BungeeCord", byteArrayOutputStream.toByteArray()); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java index e4d612a..63bc833 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java @@ -1,49 +1,49 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.hook; - -import me.clip.placeholderapi.PlaceholderAPI; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -public enum PlaceholderAPIHook implements PluginHook { - - INSTANCE; - - private boolean enabled; - - @Override - public void setup() { - enabled = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null; - } - - @Override - public boolean isEnabled() { - return enabled; - } - - public static boolean hasPlaceholders(String message) { - INSTANCE.checkEnabledState(); - - return PlaceholderAPI.containsPlaceholders(message); - } - - public static String setPlaceholders(String message, Player viewer) { - INSTANCE.checkEnabledState(); - - return PlaceholderAPI.setPlaceholders(viewer, message); - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.hook; + +import me.clip.placeholderapi.PlaceholderAPI; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public enum PlaceholderAPIHook implements PluginHook { + + INSTANCE; + + private boolean enabled; + + @Override + public void setup() { + enabled = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null; + } + + @Override + public boolean isEnabled() { + return enabled; + } + + public static boolean hasPlaceholders(String message) { + INSTANCE.checkEnabledState(); + + return PlaceholderAPI.containsPlaceholders(message); + } + + public static String setPlaceholders(String message, Player viewer) { + INSTANCE.checkEnabledState(); + + return PlaceholderAPI.setPlaceholders(viewer, message); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java index 9436ac5..c3a5eef 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java @@ -1,30 +1,30 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.hook; - -import me.filoghost.chestcommands.util.Preconditions; - -public interface PluginHook { - - - void setup(); - - boolean isEnabled(); - - default void checkEnabledState() { - Preconditions.checkState(isEnabled(), "Plugin hook " + getClass().getSimpleName() + " is not enabled"); - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.hook; + +import me.filoghost.commons.Preconditions; + +public interface PluginHook { + + + void setup(); + + boolean isEnabled(); + + default void checkEnabledState() { + Preconditions.checkState(isEnabled(), "Plugin hook " + getClass().getSimpleName() + " is not enabled"); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java index 1bb6931..ea3cbf9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java @@ -1,94 +1,94 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.hook; - -import me.filoghost.chestcommands.util.Preconditions; -import net.milkbowl.vault.economy.Economy; -import net.milkbowl.vault.economy.EconomyResponse; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.RegisteredServiceProvider; - -public enum VaultEconomyHook implements PluginHook { - - INSTANCE; - - private Economy economy; - - @Override - public void setup() { - economy = null; - - if (Bukkit.getPluginManager().getPlugin("Vault") == null) { - return; - } - - RegisteredServiceProvider economyServiceProvider = Bukkit.getServicesManager().getRegistration(Economy.class); - if (economyServiceProvider == null) { - return; - } - - economy = economyServiceProvider.getProvider(); - } - - @Override - public boolean isEnabled() { - return economy != null; - } - - public static double getMoney(Player player) { - INSTANCE.checkEnabledState(); - return INSTANCE.economy.getBalance(player, player.getWorld().getName()); - } - - public static boolean hasMoney(Player player, double minimum) { - INSTANCE.checkEnabledState(); - checkPositiveAmount(minimum); - - double balance = INSTANCE.economy.getBalance(player, player.getWorld().getName()); - return balance >= minimum; - } - - /** - * @return true if the operation was successful. - */ - public static boolean takeMoney(Player player, double amount) { - INSTANCE.checkEnabledState(); - checkPositiveAmount(amount); - - EconomyResponse response = INSTANCE.economy.withdrawPlayer(player, player.getWorld().getName(), amount); - return response.transactionSuccess(); - } - - public static boolean giveMoney(Player player, double amount) { - INSTANCE.checkEnabledState(); - checkPositiveAmount(amount); - - EconomyResponse response = INSTANCE.economy.depositPlayer(player, player.getWorld().getName(), amount); - return response.transactionSuccess(); - } - - private static void checkPositiveAmount(double amount) { - Preconditions.checkArgument(amount >= 0.0, "amount cannot be negative"); - } - - public static String formatMoney(double amount) { - if (INSTANCE.economy != null) { - return INSTANCE.economy.format(amount); - } else { - return Double.toString(amount); - } - } -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.hook; + +import me.filoghost.commons.Preconditions; +import net.milkbowl.vault.economy.Economy; +import net.milkbowl.vault.economy.EconomyResponse; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.RegisteredServiceProvider; + +public enum VaultEconomyHook implements PluginHook { + + INSTANCE; + + private Economy economy; + + @Override + public void setup() { + economy = null; + + if (Bukkit.getPluginManager().getPlugin("Vault") == null) { + return; + } + + RegisteredServiceProvider economyServiceProvider = Bukkit.getServicesManager().getRegistration(Economy.class); + if (economyServiceProvider == null) { + return; + } + + economy = economyServiceProvider.getProvider(); + } + + @Override + public boolean isEnabled() { + return economy != null; + } + + public static double getMoney(Player player) { + INSTANCE.checkEnabledState(); + return INSTANCE.economy.getBalance(player, player.getWorld().getName()); + } + + public static boolean hasMoney(Player player, double minimum) { + INSTANCE.checkEnabledState(); + checkPositiveAmount(minimum); + + double balance = INSTANCE.economy.getBalance(player, player.getWorld().getName()); + return balance >= minimum; + } + + /** + * @return true if the operation was successful. + */ + public static boolean takeMoney(Player player, double amount) { + INSTANCE.checkEnabledState(); + checkPositiveAmount(amount); + + EconomyResponse response = INSTANCE.economy.withdrawPlayer(player, player.getWorld().getName(), amount); + return response.transactionSuccess(); + } + + public static boolean giveMoney(Player player, double amount) { + INSTANCE.checkEnabledState(); + checkPositiveAmount(amount); + + EconomyResponse response = INSTANCE.economy.depositPlayer(player, player.getWorld().getName(), amount); + return response.transactionSuccess(); + } + + private static void checkPositiveAmount(double amount) { + Preconditions.checkArgument(amount >= 0.0, "amount cannot be negative"); + } + + public static String formatMoney(double amount) { + if (INSTANCE.economy != null) { + return INSTANCE.economy.format(amount); + } else { + return Double.toString(amount); + } + } +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java index 4ede5b1..8c6a16f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java @@ -17,9 +17,9 @@ package me.filoghost.chestcommands.icon; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.placeholder.PlaceholderString; import me.filoghost.chestcommands.placeholder.PlaceholderStringList; -import me.filoghost.chestcommands.util.Preconditions; -import me.filoghost.chestcommands.util.collection.CollectionUtils; -import me.filoghost.chestcommands.util.logging.Log; +import me.filoghost.commons.Preconditions; +import me.filoghost.commons.collection.CollectionUtils; +import me.filoghost.commons.logging.Log; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Color; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java index 630725e..1198955 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java @@ -25,8 +25,8 @@ import me.filoghost.chestcommands.icon.requirement.RequiredPermission; import me.filoghost.chestcommands.icon.requirement.Requirement; import me.filoghost.chestcommands.icon.requirement.item.RequiredItem; import me.filoghost.chestcommands.icon.requirement.item.RequiredItems; -import me.filoghost.chestcommands.util.Preconditions; -import me.filoghost.chestcommands.util.collection.CollectionUtils; +import me.filoghost.commons.Preconditions; +import me.filoghost.commons.collection.CollectionUtils; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java index da20afc..e1dc869 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java @@ -15,7 +15,7 @@ package me.filoghost.chestcommands.icon.requirement; import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.util.Strings; +import me.filoghost.commons.Strings; import org.bukkit.entity.Player; public class RequiredPermission implements Requirement { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java index 7aaf469..76de825 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java @@ -1,7 +1,7 @@ package me.filoghost.chestcommands.icon.requirement.item; -import me.filoghost.chestcommands.util.MaterialsHelper; -import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.commons.MaterialsHelper; +import me.filoghost.commons.Preconditions; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java index 48c4ae9..38efab6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java @@ -14,7 +14,7 @@ */ package me.filoghost.chestcommands.icon.requirement.item; -import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.commons.Preconditions; import org.bukkit.Material; public class RequiredItem { diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/ArrayGrid.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/ArrayGrid.java similarity index 95% rename from Utils/src/main/java/me/filoghost/chestcommands/util/collection/ArrayGrid.java rename to Plugin/src/main/java/me/filoghost/chestcommands/inventory/ArrayGrid.java index cccee7c..a9f370a 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/ArrayGrid.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/ArrayGrid.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.util.collection; +package me.filoghost.chestcommands.inventory; public class ArrayGrid extends Grid { diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/Grid.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/Grid.java similarity index 96% rename from Utils/src/main/java/me/filoghost/chestcommands/util/collection/Grid.java rename to Plugin/src/main/java/me/filoghost/chestcommands/inventory/Grid.java index 947c57d..8483a48 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/collection/Grid.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/Grid.java @@ -12,9 +12,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package me.filoghost.chestcommands.util.collection; +package me.filoghost.chestcommands.inventory; -import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.commons.Preconditions; /* * Example: diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java index baeb8cf..a7640e4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java @@ -14,7 +14,6 @@ */ package me.filoghost.chestcommands.inventory; -import me.filoghost.chestcommands.util.collection.Grid; import org.bukkit.Bukkit; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java index ccde737..7c59fb6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java @@ -14,7 +14,7 @@ */ package me.filoghost.chestcommands.inventory; -import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.commons.Preconditions; import org.bukkit.Bukkit; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java index ccb3818..b22ac45 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java @@ -14,7 +14,7 @@ */ package me.filoghost.chestcommands.legacy; -import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.commons.Preconditions; import java.io.IOException; import java.nio.file.Files; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java index b1df271..5a38ae6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java @@ -16,7 +16,6 @@ package me.filoghost.chestcommands.legacy; import com.google.common.collect.ImmutableList; import me.filoghost.chestcommands.config.ConfigManager; -import me.filoghost.chestcommands.config.framework.ConfigLoader; import me.filoghost.chestcommands.legacy.upgrade.Upgrade; import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask; import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException; @@ -26,8 +25,9 @@ import me.filoghost.chestcommands.legacy.v4_0.v4_0_MenuNodeRenameUpgradeTask; import me.filoghost.chestcommands.legacy.v4_0.v4_0_PlaceholdersFileUpgradeTask; import me.filoghost.chestcommands.legacy.v4_0.v4_0_SettingsUpgradeTask; import me.filoghost.chestcommands.logging.ErrorMessages; -import me.filoghost.chestcommands.util.collection.CollectionUtils; -import me.filoghost.chestcommands.util.logging.Log; +import me.filoghost.commons.collection.CollectionUtils; +import me.filoghost.commons.config.ConfigLoader; +import me.filoghost.commons.logging.Log; import java.io.IOException; import java.nio.file.Path; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java index 4fbadfb..8d86f3d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java @@ -19,8 +19,8 @@ import me.filoghost.chestcommands.legacy.upgrade.Upgrade; import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask; import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException; import me.filoghost.chestcommands.logging.ErrorMessages; -import me.filoghost.chestcommands.util.logging.ErrorCollector; -import me.filoghost.chestcommands.util.logging.Log; +import me.filoghost.commons.logging.ErrorCollector; +import me.filoghost.commons.logging.Log; import java.io.IOException; import java.nio.file.Path; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java index 8d090b2..7825a76 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java @@ -14,9 +14,9 @@ */ package me.filoghost.chestcommands.legacy.upgrade; -import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; -import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.commons.config.ConfigErrors; +import me.filoghost.commons.config.exception.ConfigLoadException; +import me.filoghost.commons.config.exception.ConfigSaveException; import java.io.IOException; import java.nio.file.Files; @@ -58,7 +58,7 @@ public abstract class RegexUpgradeTask extends UpgradeTask { try { lines = Files.readAllLines(file); } catch (IOException e) { - throw new ConfigLoadException(ErrorMessages.Config.readIOException, e); + throw new ConfigLoadException(ConfigErrors.readIOException, e); } this.linesStream = lines.stream(); @@ -76,7 +76,7 @@ public abstract class RegexUpgradeTask extends UpgradeTask { try { Files.write(file, newContents); } catch (IOException e) { - throw new ConfigSaveException(ErrorMessages.Config.writeDataIOException, e); + throw new ConfigSaveException(ConfigErrors.writeDataIOException, e); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java index 788c76c..616bfa0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java @@ -14,11 +14,11 @@ */ package me.filoghost.chestcommands.legacy.upgrade; -import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; -import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; import me.filoghost.chestcommands.legacy.Backup; import me.filoghost.chestcommands.logging.ErrorMessages; -import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.commons.Preconditions; +import me.filoghost.commons.config.exception.ConfigLoadException; +import me.filoghost.commons.config.exception.ConfigSaveException; import java.io.IOException; import java.nio.file.Path; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java index e4c3a27..665b027 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java @@ -14,10 +14,10 @@ */ package me.filoghost.chestcommands.legacy.upgrade; -import me.filoghost.chestcommands.config.framework.Config; -import me.filoghost.chestcommands.config.framework.ConfigLoader; -import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; -import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; +import me.filoghost.commons.config.Config; +import me.filoghost.commons.config.ConfigLoader; +import me.filoghost.commons.config.exception.ConfigLoadException; +import me.filoghost.commons.config.exception.ConfigSaveException; import java.nio.file.Path; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java index 2e83844..93f83dd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java @@ -15,13 +15,13 @@ package me.filoghost.chestcommands.legacy.v4_0; import me.filoghost.chestcommands.config.ConfigManager; -import me.filoghost.chestcommands.config.framework.Config; -import me.filoghost.chestcommands.config.framework.ConfigSection; -import me.filoghost.chestcommands.config.framework.ConfigValueType; import me.filoghost.chestcommands.legacy.upgrade.YamlUpgradeTask; import me.filoghost.chestcommands.parsing.icon.AttributeType; import me.filoghost.chestcommands.parsing.menu.MenuSettingsNode; -import me.filoghost.chestcommands.util.Strings; +import me.filoghost.commons.Strings; +import me.filoghost.commons.config.Config; +import me.filoghost.commons.config.ConfigSection; +import me.filoghost.commons.config.ConfigValueType; import java.nio.file.Path; import java.util.ArrayList; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java index 0e69718..6818e0b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java @@ -15,13 +15,13 @@ package me.filoghost.chestcommands.legacy.v4_0; import me.filoghost.chestcommands.config.ConfigManager; -import me.filoghost.chestcommands.config.framework.Config; -import me.filoghost.chestcommands.config.framework.ConfigLoader; -import me.filoghost.chestcommands.config.framework.exception.ConfigLoadException; -import me.filoghost.chestcommands.config.framework.exception.ConfigSaveException; import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask; -import me.filoghost.chestcommands.logging.ErrorMessages; -import me.filoghost.chestcommands.util.Strings; +import me.filoghost.commons.Strings; +import me.filoghost.commons.config.Config; +import me.filoghost.commons.config.ConfigErrors; +import me.filoghost.commons.config.ConfigLoader; +import me.filoghost.commons.config.exception.ConfigLoadException; +import me.filoghost.commons.config.exception.ConfigSaveException; import org.apache.commons.lang.StringEscapeUtils; import java.io.IOException; @@ -62,7 +62,7 @@ public class v4_0_PlaceholdersFileUpgradeTask extends UpgradeTask { try { lines = Files.readAllLines(oldPlaceholdersFile); } catch (IOException e) { - throw new ConfigLoadException(ErrorMessages.Config.readIOException, e); + throw new ConfigLoadException(ConfigErrors.readIOException, e); } for (String line : lines) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java index d4439a2..62cf798 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java @@ -15,8 +15,8 @@ package me.filoghost.chestcommands.legacy.v4_0; import me.filoghost.chestcommands.config.ConfigManager; -import me.filoghost.chestcommands.config.framework.Config; import me.filoghost.chestcommands.legacy.upgrade.YamlUpgradeTask; +import me.filoghost.commons.config.Config; public class v4_0_SettingsUpgradeTask extends YamlUpgradeTask { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java index fcb4890..a5cecf9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java @@ -1,61 +1,61 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.listener; - -import me.filoghost.chestcommands.menu.InternalIconMenu; -import me.filoghost.chestcommands.menu.MenuManager; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; - -public class CommandListener implements Listener { - - private final MenuManager menuManager; - - public CommandListener(MenuManager menuManager) { - this.menuManager = menuManager; - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onCommand(PlayerCommandPreprocessEvent event) { - String command = getCommandName(event.getMessage()); - if (command == null) { - return; - } - - InternalIconMenu menu = menuManager.getMenuByOpenCommand(command); - if (menu == null) { - return; - } - - event.setCancelled(true); - menu.openCheckingPermission(event.getPlayer()); - } - - private static String getCommandName(String fullCommand) { - if (!fullCommand.startsWith("/")) { - return null; - } - - int firstSpace = fullCommand.indexOf(' '); - if (firstSpace >= 1) { - return fullCommand.substring(1, firstSpace); - } else { - return fullCommand.substring(1); - } - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.listener; + +import me.filoghost.chestcommands.menu.InternalIconMenu; +import me.filoghost.chestcommands.menu.MenuManager; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +public class CommandListener implements Listener { + + private final MenuManager menuManager; + + public CommandListener(MenuManager menuManager) { + this.menuManager = menuManager; + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onCommand(PlayerCommandPreprocessEvent event) { + String command = getCommandName(event.getMessage()); + if (command == null) { + return; + } + + InternalIconMenu menu = menuManager.getMenuByOpenCommand(command); + if (menu == null) { + return; + } + + event.setCancelled(true); + menu.openCheckingPermission(event.getPlayer()); + } + + private static String getCommandName(String fullCommand) { + if (!fullCommand.startsWith("/")) { + return null; + } + + int firstSpace = fullCommand.indexOf(' '); + if (firstSpace >= 1) { + return fullCommand.substring(1, firstSpace); + } else { + return fullCommand.substring(1); + } + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index bfd1fc8..4c9133c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -1,101 +1,101 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.listener; - -import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.api.ClickResult; -import me.filoghost.chestcommands.inventory.DefaultMenuInventory; -import me.filoghost.chestcommands.inventory.DefaultMenuInventory.SlotClickHandler; -import me.filoghost.chestcommands.menu.MenuManager; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.Inventory; - -import java.util.Map; -import java.util.WeakHashMap; - -public class InventoryListener implements Listener { - - private final MenuManager menuManager; - private final Map antiClickSpam; - - public InventoryListener(MenuManager menuManager) { - this.menuManager = menuManager; - this.antiClickSpam = new WeakHashMap<>(); - } - - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false) - public void onInteract(PlayerInteractEvent event) { - if (event.hasItem() && event.getAction() != Action.PHYSICAL) { - menuManager.openMenuByItem(event.getPlayer(), event.getItem(), event.getAction()); - } - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) - public void onEarlyInventoryClick(InventoryClickEvent event) { - if (MenuManager.isMenuInventory(event.getInventory())) { - // Cancel the event as early as possible - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) - public void onLateInventoryClick(InventoryClickEvent event) { - Inventory inventory = event.getInventory(); - DefaultMenuInventory menuInventory = MenuManager.getOpenMenuInventory(inventory); - if (menuInventory == null) { - return; - } - - // Cancel the event again just in case a plugin un-cancels it - event.setCancelled(true); - - int slot = event.getRawSlot(); - Player clicker = (Player) event.getWhoClicked(); - SlotClickHandler slotClickHandler = menuInventory.getSlotClickHandler(slot, clicker); - if (slotClickHandler == null) { - return; - } - - Long cooldownUntil = antiClickSpam.get(clicker); - long now = System.currentTimeMillis(); - int minDelay = ChestCommands.getSettings().anti_click_spam_delay; - - if (minDelay > 0) { - if (cooldownUntil != null && cooldownUntil > now) { - return; - } else { - antiClickSpam.put(clicker, now + minDelay); - } - } - - // Only handle the click AFTER the event has finished - Bukkit.getScheduler().runTask(ChestCommands.getPluginInstance(), () -> { - ClickResult result = slotClickHandler.onClick(); - - if (result == ClickResult.CLOSE) { - clicker.closeInventory(); - } - }); - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.listener; + +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.api.ClickResult; +import me.filoghost.chestcommands.inventory.DefaultMenuInventory; +import me.filoghost.chestcommands.inventory.DefaultMenuInventory.SlotClickHandler; +import me.filoghost.chestcommands.menu.MenuManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.Inventory; + +import java.util.Map; +import java.util.WeakHashMap; + +public class InventoryListener implements Listener { + + private final MenuManager menuManager; + private final Map antiClickSpam; + + public InventoryListener(MenuManager menuManager) { + this.menuManager = menuManager; + this.antiClickSpam = new WeakHashMap<>(); + } + + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false) + public void onInteract(PlayerInteractEvent event) { + if (event.hasItem() && event.getAction() != Action.PHYSICAL) { + menuManager.openMenuByItem(event.getPlayer(), event.getItem(), event.getAction()); + } + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) + public void onEarlyInventoryClick(InventoryClickEvent event) { + if (MenuManager.isMenuInventory(event.getInventory())) { + // Cancel the event as early as possible + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) + public void onLateInventoryClick(InventoryClickEvent event) { + Inventory inventory = event.getInventory(); + DefaultMenuInventory menuInventory = MenuManager.getOpenMenuInventory(inventory); + if (menuInventory == null) { + return; + } + + // Cancel the event again just in case a plugin un-cancels it + event.setCancelled(true); + + int slot = event.getRawSlot(); + Player clicker = (Player) event.getWhoClicked(); + SlotClickHandler slotClickHandler = menuInventory.getSlotClickHandler(slot, clicker); + if (slotClickHandler == null) { + return; + } + + Long cooldownUntil = antiClickSpam.get(clicker); + long now = System.currentTimeMillis(); + int minDelay = ChestCommands.getSettings().anti_click_spam_delay; + + if (minDelay > 0) { + if (cooldownUntil != null && cooldownUntil > now) { + return; + } else { + antiClickSpam.put(clicker, now + minDelay); + } + } + + // Only handle the click AFTER the event has finished + Bukkit.getScheduler().runTask(ChestCommands.getPluginInstance(), () -> { + ClickResult result = slotClickHandler.onClick(); + + if (result == ClickResult.CLOSE) { + clicker.closeInventory(); + } + }); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java index a789dd7..0043831 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java @@ -1,43 +1,43 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.listener; - -import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.Permissions; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -public class JoinListener implements Listener { - - @EventHandler - public void onJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - - if (ChestCommands.getLastLoadErrors().hasErrors() && player.hasPermission(Permissions.SEE_ERRORS)) { - player.sendMessage( - ChestCommands.CHAT_PREFIX + ChatColor.RED + "The plugin found " + ChestCommands.getLastLoadErrors().getErrorsCount() - + " error(s) last time it was loaded. You can see them by doing \"/cc reload\" in the console."); - } - - if (ChestCommands.hasNewVersion() && ChestCommands.getSettings().update_notifications && player.hasPermission(Permissions.UPDATE_NOTIFICATIONS)) { - player.sendMessage(ChestCommands.CHAT_PREFIX + "Found an update: " + ChestCommands.getNewVersion() + ". Download:"); - player.sendMessage(ChatColor.DARK_GREEN + ">> " + ChatColor.GREEN + "http://dev.bukkit.org/bukkit-plugins/chest-commands"); - } - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.listener; + +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.Permissions; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +public class JoinListener implements Listener { + + @EventHandler + public void onJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + + if (ChestCommands.getLastLoadErrors().hasErrors() && player.hasPermission(Permissions.SEE_ERRORS)) { + player.sendMessage( + ChestCommands.CHAT_PREFIX + ChatColor.RED + "The plugin found " + ChestCommands.getLastLoadErrors().getErrorsCount() + + " error(s) last time it was loaded. You can see them by doing \"/cc reload\" in the console."); + } + + if (ChestCommands.hasNewVersion() && ChestCommands.getSettings().update_notifications && player.hasPermission(Permissions.UPDATE_NOTIFICATIONS)) { + player.sendMessage(ChestCommands.CHAT_PREFIX + "Found an update: " + ChestCommands.getNewVersion() + ". Download:"); + player.sendMessage(ChatColor.DARK_GREEN + ">> " + ChatColor.GREEN + "http://dev.bukkit.org/bukkit-plugins/chest-commands"); + } + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java index bc871f1..c85b90d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java @@ -1,127 +1,127 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.listener; - -import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.Permissions; -import me.filoghost.chestcommands.menu.InternalIconMenu; -import me.filoghost.chestcommands.menu.MenuManager; -import me.filoghost.chestcommands.util.Utils; -import org.bukkit.ChatColor; -import org.bukkit.block.BlockState; -import org.bukkit.block.Sign; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.block.SignChangeEvent; -import org.bukkit.event.player.PlayerInteractEvent; - -public class SignListener implements Listener { - - private static final int HEADER_LINE = 0; - private static final int FILENAME_LINE = 1; - - private static final String SIGN_CREATION_TRIGGER = "[menu]"; - - private static final ChatColor VALID_SIGN_COLOR = ChatColor.DARK_BLUE; - private static final String VALID_SIGN_HEADER = VALID_SIGN_COLOR + SIGN_CREATION_TRIGGER; - - private final MenuManager menuManager; - - public SignListener(MenuManager menuManager) { - this.menuManager = menuManager; - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void onSignClick(PlayerInteractEvent event) { - if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { - return; - } - - BlockState clickedBlockState = event.getClickedBlock().getState(); - - if (!(clickedBlockState instanceof Sign)) { - return; - } - - Sign sign = (Sign) clickedBlockState; - - if (!sign.getLine(HEADER_LINE).equalsIgnoreCase(VALID_SIGN_HEADER)) { - return; - } - - String menuFileName = Utils.addYamlExtension(sign.getLine(FILENAME_LINE).trim()); - InternalIconMenu menu = menuManager.getMenuByFileName(menuFileName); - - if (menu == null) { - event.getPlayer().sendMessage(ChestCommands.getLang().menu_not_found); - return; - } - - menu.openCheckingPermission(event.getPlayer()); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void onCreateMenuSign(SignChangeEvent event) { - Player player = event.getPlayer(); - - if (isCreatingMenuSign(event.getLine(HEADER_LINE)) && canCreateMenuSign(player)) { - String menuFileName = event.getLine(FILENAME_LINE).trim(); - - if (menuFileName.isEmpty()) { - event.setCancelled(true); - player.sendMessage(ChatColor.RED + "You must write a menu name in the second line."); - return; - } - - menuFileName = Utils.addYamlExtension(menuFileName); - - InternalIconMenu iconMenu = menuManager.getMenuByFileName(menuFileName); - if (iconMenu == null) { - event.setCancelled(true); - player.sendMessage(ChatColor.RED + "Menu \"" + menuFileName + "\" was not found."); - return; - } - - event.setLine(HEADER_LINE, VALID_SIGN_COLOR + event.getLine(HEADER_LINE)); - player.sendMessage(ChatColor.GREEN + "Successfully created a sign for the menu " + menuFileName + "."); - } - } - - - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onSignChangeMonitor(SignChangeEvent event) { - // Prevent players without permissions from creating menu signs - if (isValidMenuSign(event.getLine(HEADER_LINE)) && !canCreateMenuSign(event.getPlayer())) { - event.setLine(HEADER_LINE, ChatColor.stripColor(event.getLine(HEADER_LINE))); - } - } - - private boolean isCreatingMenuSign(String headerLine) { - return headerLine.equalsIgnoreCase(SIGN_CREATION_TRIGGER); - } - - private boolean isValidMenuSign(String headerLine) { - return headerLine.equalsIgnoreCase(VALID_SIGN_HEADER); - } - - private boolean canCreateMenuSign(Player player) { - return player.hasPermission(Permissions.SIGN_CREATE); - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.listener; + +import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.Permissions; +import me.filoghost.chestcommands.menu.InternalIconMenu; +import me.filoghost.chestcommands.menu.MenuManager; +import me.filoghost.chestcommands.util.Utils; +import org.bukkit.ChatColor; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +public class SignListener implements Listener { + + private static final int HEADER_LINE = 0; + private static final int FILENAME_LINE = 1; + + private static final String SIGN_CREATION_TRIGGER = "[menu]"; + + private static final ChatColor VALID_SIGN_COLOR = ChatColor.DARK_BLUE; + private static final String VALID_SIGN_HEADER = VALID_SIGN_COLOR + SIGN_CREATION_TRIGGER; + + private final MenuManager menuManager; + + public SignListener(MenuManager menuManager) { + this.menuManager = menuManager; + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onSignClick(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { + return; + } + + BlockState clickedBlockState = event.getClickedBlock().getState(); + + if (!(clickedBlockState instanceof Sign)) { + return; + } + + Sign sign = (Sign) clickedBlockState; + + if (!sign.getLine(HEADER_LINE).equalsIgnoreCase(VALID_SIGN_HEADER)) { + return; + } + + String menuFileName = Utils.addYamlExtension(sign.getLine(FILENAME_LINE).trim()); + InternalIconMenu menu = menuManager.getMenuByFileName(menuFileName); + + if (menu == null) { + event.getPlayer().sendMessage(ChestCommands.getLang().menu_not_found); + return; + } + + menu.openCheckingPermission(event.getPlayer()); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onCreateMenuSign(SignChangeEvent event) { + Player player = event.getPlayer(); + + if (isCreatingMenuSign(event.getLine(HEADER_LINE)) && canCreateMenuSign(player)) { + String menuFileName = event.getLine(FILENAME_LINE).trim(); + + if (menuFileName.isEmpty()) { + event.setCancelled(true); + player.sendMessage(ChatColor.RED + "You must write a menu name in the second line."); + return; + } + + menuFileName = Utils.addYamlExtension(menuFileName); + + InternalIconMenu iconMenu = menuManager.getMenuByFileName(menuFileName); + if (iconMenu == null) { + event.setCancelled(true); + player.sendMessage(ChatColor.RED + "Menu \"" + menuFileName + "\" was not found."); + return; + } + + event.setLine(HEADER_LINE, VALID_SIGN_COLOR + event.getLine(HEADER_LINE)); + player.sendMessage(ChatColor.GREEN + "Successfully created a sign for the menu " + menuFileName + "."); + } + } + + + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onSignChangeMonitor(SignChangeEvent event) { + // Prevent players without permissions from creating menu signs + if (isValidMenuSign(event.getLine(HEADER_LINE)) && !canCreateMenuSign(event.getPlayer())) { + event.setLine(HEADER_LINE, ChatColor.stripColor(event.getLine(HEADER_LINE))); + } + } + + private boolean isCreatingMenuSign(String headerLine) { + return headerLine.equalsIgnoreCase(SIGN_CREATION_TRIGGER); + } + + private boolean isValidMenuSign(String headerLine) { + return headerLine.equalsIgnoreCase(VALID_SIGN_HEADER); + } + + private boolean canCreateMenuSign(Player player) { + return player.hasPermission(Permissions.SIGN_CREATE); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java index b5de737..c1b99ad 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java @@ -15,9 +15,6 @@ package me.filoghost.chestcommands.logging; import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.config.framework.mapped.MappedConfig; -import me.filoghost.chestcommands.config.framework.mapped.MappedField; -import me.filoghost.chestcommands.config.framework.mapped.converter.Converter; import me.filoghost.chestcommands.parsing.icon.AttributeType; import me.filoghost.chestcommands.parsing.icon.IconSettings; import org.bukkit.ChatColor; @@ -28,18 +25,7 @@ public class ErrorMessages { public static class Config { - public static final String readIOException = "I/O exception while reading file"; - public static final String createDefaultIOException = "I/O exception while creating default file"; - public static final String writeDataIOException = "I/O exception while writing data to file"; public static final String createDataFolderIOException = "plugin failed to load, couldn't create data folder"; - public static final String invalidYamlSyntax = "invalid YAML syntax"; - - public static final String valueNotSet = "value is not set"; - public static final String valueNotList = "value is not a list"; - public static final String valueNotBoolean = "value is not a boolean"; - public static final String valueNotNumber = "value is not a number"; - public static final String valueNotString = "value is not a string"; - public static final String valueNotSection = "value is not a configuration section"; public static String menuListIOException(Path menuFolder) { return "couldn't fetch menu files inside the folder \"" + menuFolder + "\""; @@ -57,30 +43,6 @@ public class ErrorMessages { return "error in \"" + configFile + "\": placeholder cannot be longer than 100 character (" + placeholder + ")."; } - public static String createParentFolderIOException(Path folder) { - return "I/O exception while creating parent directory \"" + formatPath(folder) + "\""; - } - - public static String mapperInitError(MappedConfig mappedConfig) { - return "couldn't initialize config mapper for class \"" + mappedConfig.getClass() + "\""; - } - - public static String fieldReadError(MappedConfig mappedConfig) { - return "couldn't read field values from class \"" + mappedConfig.getClass() + "\""; - } - - public static String fieldInjectError(MappedConfig mappedConfig) { - return "couldn't inject fields values in class \"" + mappedConfig.getClass() + "\""; - } - - public static String mapperFieldCannotBeNull(MappedField mappedField) { - return "mapped field \"" + mappedField.getFieldName() + "\" cannot be null by default"; - } - - public static String converterFailed(Object value, Converter converter) { - return "value of type \"" + value.getClass() + "\" couldn't be converted by \"" + converter.getClass() + "\""; - } - } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java index f46acbf..dd088d3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java @@ -14,7 +14,7 @@ */ package me.filoghost.chestcommands.logging; -import me.filoghost.chestcommands.util.Strings; +import me.filoghost.commons.Strings; import java.util.List; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java index fea66dd..4dcd5b9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java @@ -15,14 +15,14 @@ package me.filoghost.chestcommands.logging; import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.config.framework.exception.ConfigException; -import me.filoghost.chestcommands.config.framework.exception.ConfigSyntaxException; import me.filoghost.chestcommands.legacy.UpgradeExecutorException; import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.util.Utils; -import me.filoghost.chestcommands.util.logging.ErrorCollector; -import me.filoghost.chestcommands.util.logging.ErrorInfo; +import me.filoghost.commons.CommonsUtil; +import me.filoghost.commons.config.exception.ConfigException; +import me.filoghost.commons.config.exception.ConfigSyntaxException; +import me.filoghost.commons.logging.ErrorCollector; +import me.filoghost.commons.logging.ErrorInfo; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -89,7 +89,7 @@ public class PrintableErrorCollector extends ErrorCollector { if (error.getCause() != null) { output.append(ChatColor.DARK_GRAY); output.append("--------[ Exception details ]--------\n"); - output.append(Utils.getStackTraceString(error.getCause())); + output.append(CommonsUtil.getStackTraceString(error.getCause())); output.append("-------------------------------------\n"); } output.append(" \n"); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java index bb7c0b2..bd23f3a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java @@ -17,10 +17,10 @@ package me.filoghost.chestcommands.menu; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.api.IconMenu; import me.filoghost.chestcommands.api.MenuInventory; +import me.filoghost.chestcommands.inventory.ArrayGrid; import me.filoghost.chestcommands.inventory.DefaultMenuInventory; -import me.filoghost.chestcommands.util.Preconditions; -import me.filoghost.chestcommands.util.collection.ArrayGrid; -import me.filoghost.chestcommands.util.collection.Grid; +import me.filoghost.chestcommands.inventory.Grid; +import me.filoghost.commons.Preconditions; import org.bukkit.Bukkit; import org.bukkit.entity.Player; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java index 718dc19..7856484 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java @@ -19,7 +19,7 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.api.MenuInventory; -import me.filoghost.chestcommands.util.collection.CollectionUtils; +import me.filoghost.commons.collection.CollectionUtils; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java index ada8d4f..4703d91 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java @@ -1,136 +1,136 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package me.filoghost.chestcommands.menu; - -import me.filoghost.chestcommands.inventory.DefaultMenuInventory; -import me.filoghost.chestcommands.inventory.MenuInventoryHolder; -import me.filoghost.chestcommands.logging.ErrorMessages; -import me.filoghost.chestcommands.parsing.menu.LoadedMenu; -import me.filoghost.chestcommands.parsing.menu.MenuOpenItem; -import me.filoghost.chestcommands.util.collection.CaseInsensitiveMap; -import me.filoghost.chestcommands.util.logging.ErrorCollector; -import org.bukkit.entity.Player; -import org.bukkit.event.block.Action; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryView; -import org.bukkit.inventory.ItemStack; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public class MenuManager { - - private static Map menusByFile; - private static Map menusByOpenCommand; - private static Map menusByOpenItem; - - public MenuManager() { - menusByFile = new CaseInsensitiveMap<>(); - menusByOpenCommand = new CaseInsensitiveMap<>(); - menusByOpenItem = new HashMap<>(); - } - - public void clear() { - menusByFile.clear(); - menusByOpenCommand.clear(); - menusByOpenItem.clear(); - } - - public InternalIconMenu getMenuByFileName(String fileName) { - return menusByFile.get(fileName); - } - - public void registerMenu(LoadedMenu loadedMenu, ErrorCollector errorCollector) { - InternalIconMenu menu = loadedMenu.getMenu(); - - String fileName = loadedMenu.getSourceFile().getFileName().toString(); - InternalIconMenu sameNameMenu = menusByFile.get(fileName); - if (sameNameMenu != null) { - errorCollector.add(ErrorMessages.Menu.duplicateMenuName(sameNameMenu.getSourceFile(), loadedMenu.getSourceFile())); - } - menusByFile.put(fileName, menu); - - if (loadedMenu.getOpenCommands() != null) { - for (String openCommand : loadedMenu.getOpenCommands()) { - if (!openCommand.isEmpty()) { - InternalIconMenu sameCommandMenu = menusByOpenCommand.get(openCommand); - if (sameCommandMenu != null) { - errorCollector.add(ErrorMessages.Menu.duplicateMenuCommand(sameCommandMenu.getSourceFile(), loadedMenu.getSourceFile(), openCommand)); - } - menusByOpenCommand.put(openCommand, menu); - } - } - } - - if (loadedMenu.getOpenItem() != null) { - menusByOpenItem.put(loadedMenu.getOpenItem(), menu); - } - } - - public void openMenuByItem(Player player, ItemStack itemInHand, Action clickAction) { - menusByOpenItem.forEach((openItem, menu) -> { - if (openItem.matches(itemInHand, clickAction)) { - menu.openCheckingPermission(player); - } - }); - } - - public InternalIconMenu getMenuByOpenCommand(String openCommand) { - return menusByOpenCommand.get(openCommand); - } - - public Collection getMenuFileNames() { - return Collections.unmodifiableCollection(menusByFile.keySet()); - } - - public static boolean isMenuInventory(Inventory inventory) { - return getMenuInventoryHolder(inventory) != null; - } - - public static DefaultMenuInventory getOpenMenuInventory(Player player) { - InventoryView view = player.getOpenInventory(); - if (view == null) { - return null; - } - - DefaultMenuInventory menuInventory = getOpenMenuInventory(view.getTopInventory()); - if (menuInventory == null) { - menuInventory = getOpenMenuInventory(view.getBottomInventory()); - } - - return menuInventory; - } - - - public static DefaultMenuInventory getOpenMenuInventory(Inventory inventory) { - MenuInventoryHolder inventoryHolder = getMenuInventoryHolder(inventory); - if (inventoryHolder != null) { - return inventoryHolder.getMenuInventory(); - } else { - return null; - } - } - - private static MenuInventoryHolder getMenuInventoryHolder(Inventory inventory) { - if (inventory.getHolder() instanceof MenuInventoryHolder) { - return (MenuInventoryHolder) inventory.getHolder(); - } else { - return null; - } - } - -} +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package me.filoghost.chestcommands.menu; + +import me.filoghost.chestcommands.inventory.DefaultMenuInventory; +import me.filoghost.chestcommands.inventory.MenuInventoryHolder; +import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.parsing.menu.LoadedMenu; +import me.filoghost.chestcommands.parsing.menu.MenuOpenItem; +import me.filoghost.commons.collection.CaseInsensitiveMap; +import me.filoghost.commons.logging.ErrorCollector; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.ItemStack; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public class MenuManager { + + private static Map menusByFile; + private static Map menusByOpenCommand; + private static Map menusByOpenItem; + + public MenuManager() { + menusByFile = new CaseInsensitiveMap<>(); + menusByOpenCommand = new CaseInsensitiveMap<>(); + menusByOpenItem = new HashMap<>(); + } + + public void clear() { + menusByFile.clear(); + menusByOpenCommand.clear(); + menusByOpenItem.clear(); + } + + public InternalIconMenu getMenuByFileName(String fileName) { + return menusByFile.get(fileName); + } + + public void registerMenu(LoadedMenu loadedMenu, ErrorCollector errorCollector) { + InternalIconMenu menu = loadedMenu.getMenu(); + + String fileName = loadedMenu.getSourceFile().getFileName().toString(); + InternalIconMenu sameNameMenu = menusByFile.get(fileName); + if (sameNameMenu != null) { + errorCollector.add(ErrorMessages.Menu.duplicateMenuName(sameNameMenu.getSourceFile(), loadedMenu.getSourceFile())); + } + menusByFile.put(fileName, menu); + + if (loadedMenu.getOpenCommands() != null) { + for (String openCommand : loadedMenu.getOpenCommands()) { + if (!openCommand.isEmpty()) { + InternalIconMenu sameCommandMenu = menusByOpenCommand.get(openCommand); + if (sameCommandMenu != null) { + errorCollector.add(ErrorMessages.Menu.duplicateMenuCommand(sameCommandMenu.getSourceFile(), loadedMenu.getSourceFile(), openCommand)); + } + menusByOpenCommand.put(openCommand, menu); + } + } + } + + if (loadedMenu.getOpenItem() != null) { + menusByOpenItem.put(loadedMenu.getOpenItem(), menu); + } + } + + public void openMenuByItem(Player player, ItemStack itemInHand, Action clickAction) { + menusByOpenItem.forEach((openItem, menu) -> { + if (openItem.matches(itemInHand, clickAction)) { + menu.openCheckingPermission(player); + } + }); + } + + public InternalIconMenu getMenuByOpenCommand(String openCommand) { + return menusByOpenCommand.get(openCommand); + } + + public Collection getMenuFileNames() { + return Collections.unmodifiableCollection(menusByFile.keySet()); + } + + public static boolean isMenuInventory(Inventory inventory) { + return getMenuInventoryHolder(inventory) != null; + } + + public static DefaultMenuInventory getOpenMenuInventory(Player player) { + InventoryView view = player.getOpenInventory(); + if (view == null) { + return null; + } + + DefaultMenuInventory menuInventory = getOpenMenuInventory(view.getTopInventory()); + if (menuInventory == null) { + menuInventory = getOpenMenuInventory(view.getBottomInventory()); + } + + return menuInventory; + } + + + public static DefaultMenuInventory getOpenMenuInventory(Inventory inventory) { + MenuInventoryHolder inventoryHolder = getMenuInventoryHolder(inventory); + if (inventoryHolder != null) { + return inventoryHolder.getMenuInventory(); + } else { + return null; + } + } + + private static MenuInventoryHolder getMenuInventoryHolder(Inventory inventory) { + if (inventory.getHolder() instanceof MenuInventoryHolder) { + return (MenuInventoryHolder) inventory.getHolder(); + } else { + return null; + } + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java index f1b45bd..20ae6fa 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java @@ -15,8 +15,8 @@ package me.filoghost.chestcommands.parsing; import me.filoghost.chestcommands.logging.ErrorMessages; -import me.filoghost.chestcommands.util.Strings; -import me.filoghost.chestcommands.util.collection.Registry; +import me.filoghost.commons.Strings; +import me.filoghost.commons.collection.Registry; import org.bukkit.enchantments.Enchantment; import java.util.Optional; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java index 5c5dfc3..b6003b3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java @@ -15,8 +15,8 @@ package me.filoghost.chestcommands.parsing; import me.filoghost.chestcommands.logging.ErrorMessages; -import me.filoghost.chestcommands.util.Strings; -import me.filoghost.chestcommands.util.collection.Registry; +import me.filoghost.commons.Strings; +import me.filoghost.commons.collection.Registry; import org.bukkit.Color; import org.bukkit.DyeColor; import org.bukkit.block.banner.Pattern; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java index ae6a154..4348e8a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java @@ -15,9 +15,9 @@ package me.filoghost.chestcommands.parsing; import me.filoghost.chestcommands.logging.ErrorMessages; -import me.filoghost.chestcommands.util.MaterialsHelper; -import me.filoghost.chestcommands.util.Preconditions; -import me.filoghost.chestcommands.util.Strings; +import me.filoghost.commons.MaterialsHelper; +import me.filoghost.commons.Preconditions; +import me.filoghost.commons.Strings; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java index 9cbdaad..5457738 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java @@ -36,10 +36,10 @@ import me.filoghost.chestcommands.attribute.PriceAttribute; import me.filoghost.chestcommands.attribute.RequiredItemsAttribute; import me.filoghost.chestcommands.attribute.SkullOwnerAttribute; import me.filoghost.chestcommands.attribute.ViewPermissionAttribute; -import me.filoghost.chestcommands.config.framework.ConfigValue; -import me.filoghost.chestcommands.config.framework.ConfigValueType; -import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; import me.filoghost.chestcommands.parsing.ParseException; +import me.filoghost.commons.config.ConfigValue; +import me.filoghost.commons.config.ConfigValueType; +import me.filoghost.commons.config.exception.ConfigValueException; import java.util.HashMap; import java.util.Map; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java index 9c6c2e0..c7fca0a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java @@ -16,13 +16,13 @@ package me.filoghost.chestcommands.parsing.icon; import me.filoghost.chestcommands.attribute.AttributeErrorHandler; import me.filoghost.chestcommands.attribute.IconAttribute; -import me.filoghost.chestcommands.config.framework.ConfigSection; -import me.filoghost.chestcommands.config.framework.ConfigValue; -import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.chestcommands.util.logging.ErrorCollector; +import me.filoghost.commons.config.ConfigSection; +import me.filoghost.commons.config.ConfigValue; +import me.filoghost.commons.config.exception.ConfigValueException; +import me.filoghost.commons.logging.ErrorCollector; import org.bukkit.Material; import java.nio.file.Path; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java index 32dba22..7aa7078 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java @@ -16,7 +16,7 @@ package me.filoghost.chestcommands.parsing.menu; import com.google.common.collect.ImmutableList; import me.filoghost.chestcommands.menu.InternalIconMenu; -import me.filoghost.chestcommands.util.collection.CollectionUtils; +import me.filoghost.commons.collection.CollectionUtils; import java.nio.file.Path; import java.util.List; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java index 53dd390..9448bca 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java @@ -14,7 +14,7 @@ */ package me.filoghost.chestcommands.parsing.menu; -import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.commons.Preconditions; import org.bukkit.Material; import org.bukkit.event.block.Action; import org.bukkit.inventory.ItemStack; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index a860462..fc940c6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -17,11 +17,6 @@ package me.filoghost.chestcommands.parsing.menu; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.DisabledAction; import me.filoghost.chestcommands.attribute.PositionAttribute; -import me.filoghost.chestcommands.config.framework.Config; -import me.filoghost.chestcommands.config.framework.ConfigSection; -import me.filoghost.chestcommands.config.framework.EmptyConfigSection; -import me.filoghost.chestcommands.config.framework.exception.ConfigValueException; -import me.filoghost.chestcommands.config.framework.exception.MissingConfigValueException; import me.filoghost.chestcommands.logging.ErrorMessages; import me.filoghost.chestcommands.menu.InternalIconMenu; import me.filoghost.chestcommands.parsing.ActionParser; @@ -29,8 +24,13 @@ import me.filoghost.chestcommands.parsing.ItemStackParser; import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.chestcommands.parsing.icon.AttributeType; import me.filoghost.chestcommands.parsing.icon.IconSettings; -import me.filoghost.chestcommands.util.Colors; -import me.filoghost.chestcommands.util.logging.ErrorCollector; +import me.filoghost.commons.Colors; +import me.filoghost.commons.config.Config; +import me.filoghost.commons.config.ConfigSection; +import me.filoghost.commons.config.EmptyConfigSection; +import me.filoghost.commons.config.exception.ConfigValueException; +import me.filoghost.commons.config.exception.MissingConfigValueException; +import me.filoghost.commons.logging.ErrorCollector; import org.bukkit.ChatColor; import java.util.ArrayList; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java index 02441db..08690c4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java @@ -16,7 +16,7 @@ package me.filoghost.chestcommands.parsing.menu; import com.google.common.collect.ImmutableList; import me.filoghost.chestcommands.action.Action; -import me.filoghost.chestcommands.util.collection.CollectionUtils; +import me.filoghost.commons.collection.CollectionUtils; import java.util.List; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java index 1f408d2..77c2535 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java @@ -18,7 +18,7 @@ import me.filoghost.chestcommands.api.PlaceholderReplacer; import me.filoghost.chestcommands.hook.PlaceholderAPIHook; import me.filoghost.chestcommands.placeholder.scanner.PlaceholderMatch; import me.filoghost.chestcommands.placeholder.scanner.PlaceholderScanner; -import me.filoghost.chestcommands.util.Preconditions; +import me.filoghost.commons.Preconditions; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java index 9bc23f7..0ada6af 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java @@ -15,8 +15,8 @@ package me.filoghost.chestcommands.placeholder; import com.google.common.collect.ImmutableList; -import me.filoghost.chestcommands.util.Preconditions; -import me.filoghost.chestcommands.util.collection.CollectionUtils; +import me.filoghost.commons.Preconditions; +import me.filoghost.commons.collection.CollectionUtils; import org.bukkit.entity.Player; import java.util.List; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java index 50a8065..d0de2fd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java @@ -14,7 +14,7 @@ */ package me.filoghost.chestcommands.placeholder.scanner; -import me.filoghost.chestcommands.util.Strings; +import me.filoghost.commons.Strings; import java.util.Objects; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java new file mode 100644 index 0000000..7023997 --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java @@ -0,0 +1,22 @@ +package me.filoghost.chestcommands.util; + +import me.filoghost.commons.Strings; + +public class Utils { + + public static String formatEnum(Enum enumValue) { + return Strings.capitalizeFully(enumValue.name().replace("_", " ")); + } + + public static String addYamlExtension(String fileName) { + if (fileName == null) { + return null; + } + if (fileName.toLowerCase().endsWith(".yml")) { + return fileName; + } else { + return fileName + ".yml"; + } + } + +} diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java similarity index 100% rename from Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java similarity index 100% rename from Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java similarity index 98% rename from Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java index 57cacba..c424794 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java @@ -1,6 +1,12 @@ package me.filoghost.chestcommands.util.nbt; -import java.util.*; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; import java.util.function.BiConsumer; import java.util.regex.Pattern; diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java similarity index 100% rename from Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java similarity index 100% rename from Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java similarity index 100% rename from Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java similarity index 100% rename from Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java similarity index 95% rename from Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java index d5d07ad..fecbb03 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java @@ -1,6 +1,11 @@ package me.filoghost.chestcommands.util.nbt; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; /** * The {@code TAG_List} tag. diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java similarity index 100% rename from Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java similarity index 100% rename from Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java similarity index 100% rename from Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java similarity index 100% rename from Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java similarity index 100% rename from Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java similarity index 100% rename from Utils/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java similarity index 100% rename from Utils/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java diff --git a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java similarity index 92% rename from Utils/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java rename to Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java index d390aea..a954b9a 100644 --- a/Utils/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java @@ -1,11 +1,24 @@ package me.filoghost.chestcommands.util.nbt.parser; +import me.filoghost.chestcommands.util.nbt.NBTByte; +import me.filoghost.chestcommands.util.nbt.NBTByteArray; +import me.filoghost.chestcommands.util.nbt.NBTCompound; +import me.filoghost.chestcommands.util.nbt.NBTDouble; +import me.filoghost.chestcommands.util.nbt.NBTFloat; +import me.filoghost.chestcommands.util.nbt.NBTInt; +import me.filoghost.chestcommands.util.nbt.NBTIntArray; +import me.filoghost.chestcommands.util.nbt.NBTList; +import me.filoghost.chestcommands.util.nbt.NBTLong; +import me.filoghost.chestcommands.util.nbt.NBTLongArray; +import me.filoghost.chestcommands.util.nbt.NBTShort; +import me.filoghost.chestcommands.util.nbt.NBTString; +import me.filoghost.chestcommands.util.nbt.NBTTag; +import me.filoghost.chestcommands.util.nbt.NBTType; + import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; -import me.filoghost.chestcommands.util.nbt.*; - public final class MojangsonParser { private static final Pattern diff --git a/pom.xml b/pom.xml index 81bca38..8dd20b9 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ API Plugin - Utils + Commons From a21daff5f6e2af2232e983a748fdaeacc708051c Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 10 Aug 2020 16:58:00 +0200 Subject: [PATCH 174/213] Refactor ErrorCollector --- .../commons/logging/ErrorCollector.java | 13 ++++----- .../logging/{ErrorInfo.java => ErrorLog.java} | 29 ++++++------------- .../chestcommands/ChestCommands.java | 4 +-- .../chestcommands/config/ConfigManager.java | 4 +-- .../legacy/UpgradesExecutor.java | 4 +-- .../logging/PrintableErrorCollector.java | 8 ++--- .../parsing/icon/IconSettings.java | 4 +-- .../parsing/menu/MenuParser.java | 19 ++++++------ 8 files changed, 36 insertions(+), 49 deletions(-) rename Commons/src/main/java/me/filoghost/commons/logging/{ErrorInfo.java => ErrorLog.java} (60%) diff --git a/Commons/src/main/java/me/filoghost/commons/logging/ErrorCollector.java b/Commons/src/main/java/me/filoghost/commons/logging/ErrorCollector.java index 68bf616..f2c43d7 100644 --- a/Commons/src/main/java/me/filoghost/commons/logging/ErrorCollector.java +++ b/Commons/src/main/java/me/filoghost/commons/logging/ErrorCollector.java @@ -22,17 +22,14 @@ import java.util.List; */ public abstract class ErrorCollector { - protected final List errors = new ArrayList<>(); + protected final List errors = new ArrayList<>(); - public ErrorInfo add(String message) { - return add(message, null); + public void add(String... messageParts) { + add(null, messageParts); } - public ErrorInfo add(String message, Throwable throwable) { - ErrorInfo errorInfo = new ErrorInfo(message); - errorInfo.setCause(throwable); - errors.add(errorInfo); - return errorInfo; + public void add(Throwable cause, String... messageParts) { + errors.add(new ErrorLog(cause, messageParts)); } public int getErrorsCount() { diff --git a/Commons/src/main/java/me/filoghost/commons/logging/ErrorInfo.java b/Commons/src/main/java/me/filoghost/commons/logging/ErrorLog.java similarity index 60% rename from Commons/src/main/java/me/filoghost/commons/logging/ErrorInfo.java rename to Commons/src/main/java/me/filoghost/commons/logging/ErrorLog.java index e6cec33..bfdba0c 100644 --- a/Commons/src/main/java/me/filoghost/commons/logging/ErrorInfo.java +++ b/Commons/src/main/java/me/filoghost/commons/logging/ErrorLog.java @@ -14,35 +14,24 @@ */ package me.filoghost.commons.logging; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import com.google.common.collect.ImmutableList; -public class ErrorInfo { +public class ErrorLog { - private final List message; - private Throwable cause; + private final ImmutableList message; + private final Throwable cause; - protected ErrorInfo(String messagePart) { - this.message = new ArrayList<>(); - this.message.add(messagePart); + protected ErrorLog(Throwable cause, String[] message) { + this.message = ImmutableList.copyOf(message); + this.cause = cause; } - public ErrorInfo appendMessage(String messagePart) { - message.add(messagePart); - return this; - } - - public List getMessage() { - return Collections.unmodifiableList(message); + public ImmutableList getMessage() { + return message; } public Throwable getCause() { return cause; } - public void setCause(Throwable cause) { - this.cause = cause; - } - } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 61c3b34..b638a32 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -165,7 +165,7 @@ public class ChestCommands extends BaseJavaPlugin { try { Files.createDirectories(configManager.getRootDataFolder()); } catch (IOException e) { - errorCollector.add(ErrorMessages.Config.createDataFolderIOException, e); + errorCollector.add(e, ErrorMessages.Config.createDataFolderIOException); return errorCollector; } @@ -177,7 +177,7 @@ public class ChestCommands extends BaseJavaPlugin { errorCollector.add(ErrorMessages.Upgrade.failedSomeUpgrades); } } catch (UpgradeExecutorException e) { - errorCollector.add(ErrorMessages.Upgrade.genericExecutorError, e); + errorCollector.add(e, ErrorMessages.Upgrade.genericExecutorError); errorCollector.add(ErrorMessages.Upgrade.failedSomeUpgrades); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java index b761cb4..5403a06 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java @@ -101,7 +101,7 @@ public class ConfigManager extends BaseConfigManager { } private void logConfigInitException(ErrorCollector errorCollector, Path file, ConfigException e) { - errorCollector.add(ErrorMessages.Config.initException(file), e); + errorCollector.add(e, ErrorMessages.Config.initException(file)); } public List tryLoadMenus(ErrorCollector errorCollector) { @@ -111,7 +111,7 @@ public class ConfigManager extends BaseConfigManager { try { menuFiles = getMenuFiles(); } catch (IOException e) { - errorCollector.add(ErrorMessages.Config.menuListIOException(getMenusFolder()), e); + errorCollector.add(e, ErrorMessages.Config.menuListIOException(getMenusFolder())); return Collections.emptyList(); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java index 8d86f3d..a8580b2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java @@ -90,7 +90,7 @@ public class UpgradesExecutor { try { upgradeTasks = upgrade.createUpgradeTasks(configManager); } catch (UpgradeTaskException e) { - errorCollector.add(ErrorMessages.Upgrade.failedToPrepareUpgradeTasks, e); + errorCollector.add(e, ErrorMessages.Upgrade.failedToPrepareUpgradeTasks); return false; } @@ -103,7 +103,7 @@ public class UpgradesExecutor { } } catch (UpgradeTaskException e) { allTasksSuccessful = false; - errorCollector.add(ErrorMessages.Upgrade.failedSingleUpgrade(upgradeTask.getOriginalFile()), e); + errorCollector.add(e, ErrorMessages.Upgrade.failedSingleUpgrade(upgradeTask.getOriginalFile())); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java index 4dcd5b9..790f839 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java @@ -22,7 +22,7 @@ import me.filoghost.commons.CommonsUtil; import me.filoghost.commons.config.exception.ConfigException; import me.filoghost.commons.config.exception.ConfigSyntaxException; import me.filoghost.commons.logging.ErrorCollector; -import me.filoghost.commons.logging.ErrorInfo; +import me.filoghost.commons.logging.ErrorLog; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -41,7 +41,7 @@ public class PrintableErrorCollector extends ErrorCollector { output.append(" \n"); int index = 1; - for (ErrorInfo error : errors) { + for (ErrorLog error : errors) { ErrorPrintInfo printFormat = getErrorPrintInfo(index, error); printError(output, printFormat); index++; @@ -51,8 +51,8 @@ public class PrintableErrorCollector extends ErrorCollector { Bukkit.getConsoleSender().sendMessage(output.toString()); } - private ErrorPrintInfo getErrorPrintInfo(int index, ErrorInfo error) { - List message = new ArrayList<>(error.getMessage()); + private ErrorPrintInfo getErrorPrintInfo(int index, ErrorLog error) { + List message = new ArrayList<>(error.getMessage().asList()); String details = null; Throwable cause = error.getCause(); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java index c7fca0a..4acde9c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java @@ -64,7 +64,7 @@ public class IconSettings { } AttributeErrorHandler errorHandler = (String listElement, ParseException e) -> { - errorCollector.add(ErrorMessages.Menu.invalidAttributeListElement(this, attributeName, listElement), e); + errorCollector.add(e, ErrorMessages.Menu.invalidAttributeListElement(this, attributeName, listElement)); }; ConfigValue configValue = config.get(attributeName); @@ -72,7 +72,7 @@ public class IconSettings { attributes.put(attributeType, iconAttribute); } catch (ParseException | ConfigValueException e) { - errorCollector.add(ErrorMessages.Menu.invalidAttribute(this, attributeName), e); + errorCollector.add(e, ErrorMessages.Menu.invalidAttribute(this, attributeName)); } } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index fc940c6..c14a85a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -74,13 +74,15 @@ public class MenuParser { int column = positionX.getPosition() - 1; if (row < 0 || row >= iconMenu.getRowCount()) { - errorCollector.add(ErrorMessages.Menu.invalidAttribute(iconSettings, AttributeType.POSITION_Y)) - .appendMessage("it must be between 1 and " + iconMenu.getRowCount()); + errorCollector.add( + ErrorMessages.Menu.invalidAttribute(iconSettings, AttributeType.POSITION_Y), + "it must be between 1 and " + iconMenu.getRowCount()); return; } if (column < 0 || column >= iconMenu.getColumnCount()) { - errorCollector.add(ErrorMessages.Menu.invalidAttribute(iconSettings, AttributeType.POSITION_X)) - .appendMessage(("it must be between 1 and " + iconMenu.getColumnCount())); + errorCollector.add( + ErrorMessages.Menu.invalidAttribute(iconSettings, AttributeType.POSITION_X), + "it must be between 1 and " + iconMenu.getColumnCount()); return; } @@ -140,8 +142,8 @@ public class MenuParser { try { openActions.add(ActionParser.parse(serializedAction)); } catch (ParseException e) { - errorCollector.add(ErrorMessages.Menu.invalidSettingListElement( - config.getSourceFile(), MenuSettingsNode.OPEN_ACTIONS, serializedAction), e); + errorCollector.add(e, ErrorMessages.Menu.invalidSettingListElement( + config.getSourceFile(), MenuSettingsNode.OPEN_ACTIONS, serializedAction)); openActions.add(new DisabledAction(ErrorMessages.User.configurationError( "an action linked to opening this menu was not executed because it was not valid"))); } @@ -170,8 +172,7 @@ public class MenuParser { menuSettings.setOpenItem(openItem); } catch (ParseException e) { - errorCollector.add( - ErrorMessages.Menu.invalidSetting(config.getSourceFile(), MenuSettingsNode.OPEN_ITEM_MATERIAL), e); + errorCollector.add(e, ErrorMessages.Menu.invalidSetting(config.getSourceFile(), MenuSettingsNode.OPEN_ITEM_MATERIAL)); } } } @@ -191,7 +192,7 @@ public class MenuParser { if (e instanceof MissingConfigValueException) { errorCollector.add(ErrorMessages.Menu.missingSetting(config.getSourceFile(), missingSetting)); } else { - errorCollector.add(ErrorMessages.Menu.invalidSetting(config.getSourceFile(), missingSetting), e); + errorCollector.add(e, ErrorMessages.Menu.invalidSetting(config.getSourceFile(), missingSetting)); } } From acfa123c9571214e092fcb5532f70077baec8401 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 10 Aug 2020 18:16:32 +0200 Subject: [PATCH 175/213] Cleanup 1.13 detection --- .../java/me/filoghost/commons/MaterialsHelper.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Commons/src/main/java/me/filoghost/commons/MaterialsHelper.java b/Commons/src/main/java/me/filoghost/commons/MaterialsHelper.java index 55f75e0..b5dfb94 100644 --- a/Commons/src/main/java/me/filoghost/commons/MaterialsHelper.java +++ b/Commons/src/main/java/me/filoghost/commons/MaterialsHelper.java @@ -23,9 +23,6 @@ import java.util.Optional; public final class MaterialsHelper { - // Material names have been changed in 1.13, when dolphins were added - private static final boolean USE_NEW_MATERIAL_NAMES = CommonsUtil.isClassLoaded("org.bukkit.entity.Dolphin"); - // Registry of materials by numerical ID (before 1.13), name and aliases private static final Registry MATERIALS_REGISTRY = initMaterialsRegistry(); @@ -36,11 +33,11 @@ public final class MaterialsHelper { @SuppressWarnings("deprecation") private static Registry initMaterialsRegistry() { Registry materialsRegistry = Registry.fromEnumValues(Material.class); - - if (!USE_NEW_MATERIAL_NAMES) { - // Add numerical IDs in versions before 1.13 + + // Add numerical IDs in legacy versions (the Tag class was added in 1.13) + if (!CommonsUtil.isClassLoaded("org.bukkit.Tag")) { for (Material material : Material.values()) { - materialsRegistry.put(String.valueOf(material.getId()), material); + materialsRegistry.put(Integer.toString(material.getId()), material); } } From f09d9c176648285d3b922dc2410f67e8b50d14ef Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 10 Aug 2020 21:06:40 +0200 Subject: [PATCH 176/213] Always display all required items --- .../requirement/item/InventoryTakeHelper.java | 4 ++-- .../icon/requirement/item/RequiredItems.java | 21 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java index 76de825..b6f2bc7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java @@ -29,7 +29,7 @@ public class InventoryTakeHelper { } } - public List prepareTakeItems(List requiredItems) { + public boolean prepareTakeItems(List requiredItems) { List missingItems = new ArrayList<>(); // Sort required items: check required items with a restrictive durability first @@ -57,7 +57,7 @@ public class InventoryTakeHelper { } success = missingItems.isEmpty(); - return missingItems; + return success; } public void applyTakeItems() { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java index e44e386..b653496 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java @@ -33,25 +33,26 @@ public class RequiredItems implements Requirement { @Override public boolean hasCost(Player player) { InventoryTakeHelper inventoryTakeHelper = new InventoryTakeHelper(player.getInventory()); - List missingItems = inventoryTakeHelper.prepareTakeItems(items); + boolean hasItems = inventoryTakeHelper.prepareTakeItems(items); - for (RequiredItem item : missingItems) { - player.sendMessage(ChestCommands.getLang().no_required_item - .replace("{material}", Utils.formatEnum(item.getMaterial())) - .replace("{amount}", Integer.toString(item.getAmount())) - .replace("{durability}", item.hasRestrictiveDurability() ? Short.toString(item.getDurability()) : ChestCommands.getLang().any) - ); + if (!hasItems) { + for (RequiredItem item : items) { + player.sendMessage(ChestCommands.getLang().no_required_item + .replace("{material}", Utils.formatEnum(item.getMaterial())) + .replace("{amount}", Integer.toString(item.getAmount())) + .replace("{durability}", item.hasRestrictiveDurability() ? Short.toString(item.getDurability()) : ChestCommands.getLang().any)); + } } - return missingItems.isEmpty(); + return hasItems; } @Override public boolean takeCost(Player player) { InventoryTakeHelper inventoryTakeHelper = new InventoryTakeHelper(player.getInventory()); - List missingItems = inventoryTakeHelper.prepareTakeItems(items); + boolean hasItems = inventoryTakeHelper.prepareTakeItems(items); - if (!missingItems.isEmpty()) { + if (!hasItems) { return false; } From 78549188acadd523c3a578c28a6e46f5211bc0f2 Mon Sep 17 00:00:00 2001 From: filoghost Date: Tue, 11 Aug 2020 10:35:08 +0200 Subject: [PATCH 177/213] Add license info to pom.xml --- pom.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index 8dd20b9..c8df814 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,14 @@ scm:git:git@github.com:filoghost/ChestCommands.git + + + GNU General Public License, Version 3 + https://www.gnu.org/licenses/gpl-3.0.txt + repo + + + UTF-8 1.8 From 4b4a79fc33a0a3156cc14d579f739c74bc313869 Mon Sep 17 00:00:00 2001 From: filoghost Date: Wed, 12 Aug 2020 10:38:26 +0200 Subject: [PATCH 178/213] Add copyright headers and shorten license headers --- .../chestcommands/api/ChestCommandsAPI.java | 13 ++----------- .../filoghost/chestcommands/api/ClickHandler.java | 13 ++----------- .../me/filoghost/chestcommands/api/ClickResult.java | 13 ++----------- .../filoghost/chestcommands/api/ClickableIcon.java | 13 ++----------- .../chestcommands/api/ConfigurableIcon.java | 13 ++----------- .../java/me/filoghost/chestcommands/api/Icon.java | 13 ++----------- .../me/filoghost/chestcommands/api/IconMenu.java | 13 ++----------- .../filoghost/chestcommands/api/MenuInventory.java | 13 ++----------- .../chestcommands/api/PlaceholderReplacer.java | 13 ++----------- .../me/filoghost/chestcommands/api/StaticIcon.java | 13 ++----------- .../chestcommands/api/internal/BackendAPI.java | 13 ++----------- .../java/me/filoghost/commons/BaseJavaPlugin.java | 13 ++----------- .../src/main/java/me/filoghost/commons/Colors.java | 13 ++----------- .../main/java/me/filoghost/commons/CommonsUtil.java | 13 ++----------- .../java/me/filoghost/commons/MaterialsHelper.java | 13 ++----------- .../java/me/filoghost/commons/Preconditions.java | 13 ++----------- .../src/main/java/me/filoghost/commons/Strings.java | 13 ++----------- .../commons/collection/CaseInsensitiveMap.java | 13 ++----------- .../commons/collection/CollectionUtils.java | 13 ++----------- .../me/filoghost/commons/collection/Registry.java | 13 ++----------- .../filoghost/commons/command/CommandException.java | 13 ++----------- .../filoghost/commons/command/CommandFramework.java | 13 ++----------- .../filoghost/commons/command/CommandValidate.java | 13 ++----------- .../filoghost/commons/config/BaseConfigManager.java | 13 ++----------- .../java/me/filoghost/commons/config/Config.java | 13 ++----------- .../me/filoghost/commons/config/ConfigErrors.java | 5 +++++ .../me/filoghost/commons/config/ConfigLoader.java | 13 ++----------- .../me/filoghost/commons/config/ConfigPath.java | 13 ++----------- .../me/filoghost/commons/config/ConfigSection.java | 13 ++----------- .../me/filoghost/commons/config/ConfigValue.java | 13 ++----------- .../filoghost/commons/config/ConfigValueType.java | 13 ++----------- .../commons/config/EmptyConfigSection.java | 13 ++----------- .../commons/config/exception/ConfigException.java | 13 ++----------- .../config/exception/ConfigLoadException.java | 13 ++----------- .../config/exception/ConfigSaveException.java | 13 ++----------- .../config/exception/ConfigSyntaxException.java | 13 ++----------- .../config/exception/ConfigValueException.java | 13 ++----------- .../config/exception/ConverterCastException.java | 13 ++----------- .../exception/InvalidConfigValueException.java | 13 ++----------- .../exception/MissingConfigValueException.java | 13 ++----------- .../commons/config/mapped/ConfigMapper.java | 13 ++----------- .../commons/config/mapped/IncludeStatic.java | 13 ++----------- .../commons/config/mapped/MappedConfig.java | 13 ++----------- .../commons/config/mapped/MappedConfigLoader.java | 13 ++----------- .../commons/config/mapped/MappedField.java | 13 ++----------- .../config/mapped/converter/BooleanConverter.java | 13 ++----------- .../commons/config/mapped/converter/Converter.java | 13 ++----------- .../config/mapped/converter/DoubleConverter.java | 13 ++----------- .../config/mapped/converter/IntegerConverter.java | 13 ++----------- .../config/mapped/converter/ListConverter.java | 13 ++----------- .../config/mapped/converter/StringConverter.java | 13 ++----------- .../commons/config/mapped/modifier/ChatColors.java | 13 ++----------- .../config/mapped/modifier/ChatColorsModifier.java | 13 ++----------- .../config/mapped/modifier/ValueModifier.java | 13 ++----------- .../filoghost/commons/logging/ErrorCollector.java | 13 ++----------- .../java/me/filoghost/commons/logging/ErrorLog.java | 13 ++----------- .../main/java/me/filoghost/commons/logging/Log.java | 13 ++----------- .../me/filoghost/chestcommands/ChestCommands.java | 13 ++----------- .../filoghost/chestcommands/DefaultBackendAPI.java | 13 ++----------- .../me/filoghost/chestcommands/Permissions.java | 13 ++----------- .../me/filoghost/chestcommands/action/Action.java | 13 ++----------- .../chestcommands/action/BroadcastAction.java | 13 ++----------- .../chestcommands/action/ChangeServerAction.java | 13 ++----------- .../chestcommands/action/ConsoleCommandAction.java | 13 ++----------- .../chestcommands/action/DisabledAction.java | 13 ++----------- .../chestcommands/action/DragonBarAction.java | 13 ++----------- .../chestcommands/action/GiveItemAction.java | 13 ++----------- .../chestcommands/action/GiveMoneyAction.java | 13 ++----------- .../chestcommands/action/OpCommandAction.java | 13 ++----------- .../chestcommands/action/OpenMenuAction.java | 13 ++----------- .../chestcommands/action/PlaySoundAction.java | 13 ++----------- .../chestcommands/action/PlayerCommandAction.java | 13 ++----------- .../chestcommands/action/SendMessageAction.java | 13 ++----------- .../chestcommands/attribute/ActionsAttribute.java | 13 ++----------- .../chestcommands/attribute/AmountAttribute.java | 13 ++----------- .../attribute/AttributeErrorHandler.java | 13 ++----------- .../attribute/BannerColorAttribute.java | 13 ++----------- .../attribute/BannerPatternsAttribute.java | 13 ++----------- .../attribute/ClickPermissionAttribute.java | 13 ++----------- .../attribute/ClickPermissionMessageAttribute.java | 13 ++----------- .../attribute/DurabilityAttribute.java | 13 ++----------- .../attribute/EnchantmentsAttribute.java | 13 ++----------- .../chestcommands/attribute/ExpLevelsAttribute.java | 13 ++----------- .../chestcommands/attribute/IconAttribute.java | 13 ++----------- .../chestcommands/attribute/KeepOpenAttribute.java | 13 ++----------- .../attribute/LeatherColorAttribute.java | 13 ++----------- .../chestcommands/attribute/LoreAttribute.java | 13 ++----------- .../chestcommands/attribute/MaterialAttribute.java | 13 ++----------- .../chestcommands/attribute/NBTDataAttribute.java | 13 ++----------- .../chestcommands/attribute/NameAttribute.java | 13 ++----------- .../chestcommands/attribute/PositionAttribute.java | 13 ++----------- .../chestcommands/attribute/PriceAttribute.java | 13 ++----------- .../attribute/RequiredItemsAttribute.java | 13 ++----------- .../attribute/SkullOwnerAttribute.java | 13 ++----------- .../attribute/ViewPermissionAttribute.java | 13 ++----------- .../chestcommands/command/CommandHandler.java | 13 ++----------- .../chestcommands/config/ConfigManager.java | 13 ++----------- .../chestcommands/config/CustomPlaceholders.java | 13 ++----------- .../me/filoghost/chestcommands/config/Lang.java | 13 ++----------- .../me/filoghost/chestcommands/config/Settings.java | 13 ++----------- .../me/filoghost/chestcommands/hook/BarAPIHook.java | 13 ++----------- .../chestcommands/hook/BungeeCordHook.java | 13 ++----------- .../chestcommands/hook/PlaceholderAPIHook.java | 13 ++----------- .../me/filoghost/chestcommands/hook/PluginHook.java | 13 ++----------- .../chestcommands/hook/VaultEconomyHook.java | 13 ++----------- .../chestcommands/icon/APIConfigurableIcon.java | 13 ++----------- .../filoghost/chestcommands/icon/APIStaticIcon.java | 13 ++----------- .../chestcommands/icon/BaseConfigurableIcon.java | 13 ++----------- .../icon/InternalConfigurableIcon.java | 13 ++----------- .../chestcommands/icon/RefreshableIcon.java | 13 ++----------- .../icon/requirement/RequiredExpLevel.java | 13 ++----------- .../icon/requirement/RequiredMoney.java | 13 ++----------- .../icon/requirement/RequiredPermission.java | 13 ++----------- .../chestcommands/icon/requirement/Requirement.java | 13 ++----------- .../icon/requirement/item/InventoryTakeHelper.java | 5 +++++ .../icon/requirement/item/RemainingItem.java | 5 +++++ .../icon/requirement/item/RequiredItem.java | 13 ++----------- .../icon/requirement/item/RequiredItems.java | 13 ++----------- .../chestcommands/inventory/ArrayGrid.java | 13 ++----------- .../inventory/DefaultMenuInventory.java | 13 ++----------- .../me/filoghost/chestcommands/inventory/Grid.java | 13 ++----------- .../chestcommands/inventory/InventoryGrid.java | 13 ++----------- .../inventory/MenuInventoryHolder.java | 13 ++----------- .../me/filoghost/chestcommands/legacy/Backup.java | 13 ++----------- .../legacy/UpgradeExecutorException.java | 13 ++----------- .../filoghost/chestcommands/legacy/UpgradeList.java | 13 ++----------- .../chestcommands/legacy/UpgradesDoneRegistry.java | 13 ++----------- .../chestcommands/legacy/UpgradesExecutor.java | 13 ++----------- .../chestcommands/legacy/upgrade/RegexReplacer.java | 13 ++----------- .../legacy/upgrade/RegexUpgradeTask.java | 13 ++----------- .../chestcommands/legacy/upgrade/Upgrade.java | 13 ++----------- .../chestcommands/legacy/upgrade/UpgradeTask.java | 13 ++----------- .../legacy/upgrade/UpgradeTaskException.java | 13 ++----------- .../legacy/upgrade/YamlUpgradeTask.java | 13 ++----------- .../legacy/v4_0/v4_0_LangUpgradeTask.java | 13 ++----------- .../legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java | 13 ++----------- .../legacy/v4_0/v4_0_MenuNodeRenameUpgradeTask.java | 13 ++----------- .../v4_0/v4_0_PlaceholdersFileUpgradeTask.java | 13 ++----------- .../legacy/v4_0/v4_0_SettingsUpgradeTask.java | 13 ++----------- .../chestcommands/listener/CommandListener.java | 13 ++----------- .../chestcommands/listener/InventoryListener.java | 13 ++----------- .../chestcommands/listener/JoinListener.java | 13 ++----------- .../chestcommands/listener/SignListener.java | 13 ++----------- .../chestcommands/logging/ErrorMessages.java | 13 ++----------- .../chestcommands/logging/ErrorPrintInfo.java | 13 ++----------- .../chestcommands/logging/MessagePartJoiner.java | 13 ++----------- .../logging/PrintableErrorCollector.java | 13 ++----------- .../filoghost/chestcommands/menu/APIIconMenu.java | 13 ++----------- .../filoghost/chestcommands/menu/BaseIconMenu.java | 13 ++----------- .../chestcommands/menu/InternalIconMenu.java | 13 ++----------- .../filoghost/chestcommands/menu/MenuManager.java | 13 ++----------- .../chestcommands/parsing/ActionParser.java | 13 ++----------- .../chestcommands/parsing/EnchantmentParser.java | 13 ++----------- .../chestcommands/parsing/ItemMetaParser.java | 13 ++----------- .../chestcommands/parsing/ItemStackParser.java | 13 ++----------- .../chestcommands/parsing/NumberParser.java | 13 ++----------- .../chestcommands/parsing/ParseException.java | 13 ++----------- .../chestcommands/parsing/icon/AttributeType.java | 13 ++----------- .../chestcommands/parsing/icon/IconSettings.java | 13 ++----------- .../chestcommands/parsing/menu/ClickType.java | 13 ++----------- .../chestcommands/parsing/menu/LoadedMenu.java | 13 ++----------- .../chestcommands/parsing/menu/MenuOpenItem.java | 13 ++----------- .../chestcommands/parsing/menu/MenuParser.java | 13 ++----------- .../chestcommands/parsing/menu/MenuSettings.java | 13 ++----------- .../parsing/menu/MenuSettingsNode.java | 13 ++----------- .../placeholder/DefaultPlaceholder.java | 13 ++----------- .../chestcommands/placeholder/PlaceholderCache.java | 13 ++----------- .../placeholder/PlaceholderManager.java | 13 ++----------- .../placeholder/PlaceholderRegistry.java | 13 ++----------- .../placeholder/PlaceholderString.java | 13 ++----------- .../placeholder/PlaceholderStringList.java | 13 ++----------- .../placeholder/StaticPlaceholder.java | 13 ++----------- .../placeholder/scanner/PlaceholderMatch.java | 13 ++----------- .../placeholder/scanner/PlaceholderScanner.java | 13 ++----------- .../filoghost/chestcommands/task/TickingTask.java | 13 ++----------- .../java/me/filoghost/chestcommands/util/Utils.java | 5 +++++ .../filoghost/chestcommands/util/nbt/NBTByte.java | 5 +++++ .../chestcommands/util/nbt/NBTByteArray.java | 5 +++++ .../chestcommands/util/nbt/NBTCompound.java | 5 +++++ .../filoghost/chestcommands/util/nbt/NBTDouble.java | 5 +++++ .../filoghost/chestcommands/util/nbt/NBTFloat.java | 5 +++++ .../me/filoghost/chestcommands/util/nbt/NBTInt.java | 5 +++++ .../chestcommands/util/nbt/NBTIntArray.java | 5 +++++ .../filoghost/chestcommands/util/nbt/NBTList.java | 5 +++++ .../filoghost/chestcommands/util/nbt/NBTLong.java | 5 +++++ .../chestcommands/util/nbt/NBTLongArray.java | 5 +++++ .../filoghost/chestcommands/util/nbt/NBTShort.java | 5 +++++ .../filoghost/chestcommands/util/nbt/NBTString.java | 5 +++++ .../me/filoghost/chestcommands/util/nbt/NBTTag.java | 5 +++++ .../filoghost/chestcommands/util/nbt/NBTType.java | 5 +++++ .../util/nbt/parser/MojangsonParseException.java | 5 +++++ .../util/nbt/parser/MojangsonParser.java | 5 +++++ 192 files changed, 444 insertions(+), 1892 deletions(-) diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java index 4008e82..b07433b 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.api; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java b/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java index 225eac6..1e54d7c 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.api; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java b/API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java index ecf6c22..62cfc6a 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.api; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java b/API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java index f6ff824..d4e263e 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.api; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java b/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java index a16d030..e284d5d 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.api; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java index 0b2848b..9856e4e 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/Icon.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.api; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java index e8a12df..83b0148 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.api; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java b/API/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java index 9c80889..9be876a 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.api; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/PlaceholderReplacer.java b/API/src/main/java/me/filoghost/chestcommands/api/PlaceholderReplacer.java index 9805161..61b4b39 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/PlaceholderReplacer.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/PlaceholderReplacer.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.api; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java b/API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java index 4ea9525..c2f3b35 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.api; diff --git a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java index a91be13..415a1cd 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.api.internal; diff --git a/Commons/src/main/java/me/filoghost/commons/BaseJavaPlugin.java b/Commons/src/main/java/me/filoghost/commons/BaseJavaPlugin.java index aeb1f74..d707b0c 100644 --- a/Commons/src/main/java/me/filoghost/commons/BaseJavaPlugin.java +++ b/Commons/src/main/java/me/filoghost/commons/BaseJavaPlugin.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons; diff --git a/Commons/src/main/java/me/filoghost/commons/Colors.java b/Commons/src/main/java/me/filoghost/commons/Colors.java index 1c82003..c8475b1 100644 --- a/Commons/src/main/java/me/filoghost/commons/Colors.java +++ b/Commons/src/main/java/me/filoghost/commons/Colors.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons; diff --git a/Commons/src/main/java/me/filoghost/commons/CommonsUtil.java b/Commons/src/main/java/me/filoghost/commons/CommonsUtil.java index 235e180..5bb716b 100644 --- a/Commons/src/main/java/me/filoghost/commons/CommonsUtil.java +++ b/Commons/src/main/java/me/filoghost/commons/CommonsUtil.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons; diff --git a/Commons/src/main/java/me/filoghost/commons/MaterialsHelper.java b/Commons/src/main/java/me/filoghost/commons/MaterialsHelper.java index b5dfb94..55f637c 100644 --- a/Commons/src/main/java/me/filoghost/commons/MaterialsHelper.java +++ b/Commons/src/main/java/me/filoghost/commons/MaterialsHelper.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons; diff --git a/Commons/src/main/java/me/filoghost/commons/Preconditions.java b/Commons/src/main/java/me/filoghost/commons/Preconditions.java index 954ae67..e8f2ec1 100644 --- a/Commons/src/main/java/me/filoghost/commons/Preconditions.java +++ b/Commons/src/main/java/me/filoghost/commons/Preconditions.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons; diff --git a/Commons/src/main/java/me/filoghost/commons/Strings.java b/Commons/src/main/java/me/filoghost/commons/Strings.java index 1ad58cf..264ea8b 100644 --- a/Commons/src/main/java/me/filoghost/commons/Strings.java +++ b/Commons/src/main/java/me/filoghost/commons/Strings.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons; diff --git a/Commons/src/main/java/me/filoghost/commons/collection/CaseInsensitiveMap.java b/Commons/src/main/java/me/filoghost/commons/collection/CaseInsensitiveMap.java index ea34550..75abbad 100644 --- a/Commons/src/main/java/me/filoghost/commons/collection/CaseInsensitiveMap.java +++ b/Commons/src/main/java/me/filoghost/commons/collection/CaseInsensitiveMap.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.collection; diff --git a/Commons/src/main/java/me/filoghost/commons/collection/CollectionUtils.java b/Commons/src/main/java/me/filoghost/commons/collection/CollectionUtils.java index b8839a2..a824e8c 100644 --- a/Commons/src/main/java/me/filoghost/commons/collection/CollectionUtils.java +++ b/Commons/src/main/java/me/filoghost/commons/collection/CollectionUtils.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.collection; diff --git a/Commons/src/main/java/me/filoghost/commons/collection/Registry.java b/Commons/src/main/java/me/filoghost/commons/collection/Registry.java index 3ecb2f8..f1cc4fc 100644 --- a/Commons/src/main/java/me/filoghost/commons/collection/Registry.java +++ b/Commons/src/main/java/me/filoghost/commons/collection/Registry.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.collection; diff --git a/Commons/src/main/java/me/filoghost/commons/command/CommandException.java b/Commons/src/main/java/me/filoghost/commons/command/CommandException.java index 37a69ec..8009b93 100644 --- a/Commons/src/main/java/me/filoghost/commons/command/CommandException.java +++ b/Commons/src/main/java/me/filoghost/commons/command/CommandException.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.command; diff --git a/Commons/src/main/java/me/filoghost/commons/command/CommandFramework.java b/Commons/src/main/java/me/filoghost/commons/command/CommandFramework.java index 49e0454..cf4ef10 100644 --- a/Commons/src/main/java/me/filoghost/commons/command/CommandFramework.java +++ b/Commons/src/main/java/me/filoghost/commons/command/CommandFramework.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.command; diff --git a/Commons/src/main/java/me/filoghost/commons/command/CommandValidate.java b/Commons/src/main/java/me/filoghost/commons/command/CommandValidate.java index d57022b..4ce084c 100644 --- a/Commons/src/main/java/me/filoghost/commons/command/CommandValidate.java +++ b/Commons/src/main/java/me/filoghost/commons/command/CommandValidate.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.command; diff --git a/Commons/src/main/java/me/filoghost/commons/config/BaseConfigManager.java b/Commons/src/main/java/me/filoghost/commons/config/BaseConfigManager.java index 8b6a121..0aaf6ea 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/BaseConfigManager.java +++ b/Commons/src/main/java/me/filoghost/commons/config/BaseConfigManager.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config; diff --git a/Commons/src/main/java/me/filoghost/commons/config/Config.java b/Commons/src/main/java/me/filoghost/commons/config/Config.java index 0ebd65a..7475547 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/Config.java +++ b/Commons/src/main/java/me/filoghost/commons/config/Config.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config; diff --git a/Commons/src/main/java/me/filoghost/commons/config/ConfigErrors.java b/Commons/src/main/java/me/filoghost/commons/config/ConfigErrors.java index 8a66a41..2e425c9 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/ConfigErrors.java +++ b/Commons/src/main/java/me/filoghost/commons/config/ConfigErrors.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ package me.filoghost.commons.config; import me.filoghost.commons.config.mapped.MappedConfig; diff --git a/Commons/src/main/java/me/filoghost/commons/config/ConfigLoader.java b/Commons/src/main/java/me/filoghost/commons/config/ConfigLoader.java index 5056bf6..c1b0568 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/ConfigLoader.java +++ b/Commons/src/main/java/me/filoghost/commons/config/ConfigLoader.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config; diff --git a/Commons/src/main/java/me/filoghost/commons/config/ConfigPath.java b/Commons/src/main/java/me/filoghost/commons/config/ConfigPath.java index 4b936f6..dae85e2 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/ConfigPath.java +++ b/Commons/src/main/java/me/filoghost/commons/config/ConfigPath.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config; diff --git a/Commons/src/main/java/me/filoghost/commons/config/ConfigSection.java b/Commons/src/main/java/me/filoghost/commons/config/ConfigSection.java index 71e4ed9..58d7eb3 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/ConfigSection.java +++ b/Commons/src/main/java/me/filoghost/commons/config/ConfigSection.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config; diff --git a/Commons/src/main/java/me/filoghost/commons/config/ConfigValue.java b/Commons/src/main/java/me/filoghost/commons/config/ConfigValue.java index 4d55384..40f7397 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/ConfigValue.java +++ b/Commons/src/main/java/me/filoghost/commons/config/ConfigValue.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config; diff --git a/Commons/src/main/java/me/filoghost/commons/config/ConfigValueType.java b/Commons/src/main/java/me/filoghost/commons/config/ConfigValueType.java index ab2fbd7..bdd4943 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/ConfigValueType.java +++ b/Commons/src/main/java/me/filoghost/commons/config/ConfigValueType.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config; diff --git a/Commons/src/main/java/me/filoghost/commons/config/EmptyConfigSection.java b/Commons/src/main/java/me/filoghost/commons/config/EmptyConfigSection.java index defe67c..7c5896e 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/EmptyConfigSection.java +++ b/Commons/src/main/java/me/filoghost/commons/config/EmptyConfigSection.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config; diff --git a/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigException.java b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigException.java index 14b3481..f18324c 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigException.java +++ b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigException.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.exception; diff --git a/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigLoadException.java b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigLoadException.java index 2afb9d0..07d6ef0 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigLoadException.java +++ b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigLoadException.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.exception; diff --git a/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSaveException.java b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSaveException.java index 0e753d6..ec995ed 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSaveException.java +++ b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSaveException.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.exception; diff --git a/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSyntaxException.java b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSyntaxException.java index 628cddc..240e8fa 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSyntaxException.java +++ b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSyntaxException.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.exception; diff --git a/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigValueException.java b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigValueException.java index 9671f30..14061ad 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigValueException.java +++ b/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigValueException.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.exception; diff --git a/Commons/src/main/java/me/filoghost/commons/config/exception/ConverterCastException.java b/Commons/src/main/java/me/filoghost/commons/config/exception/ConverterCastException.java index cd55662..af89a58 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/exception/ConverterCastException.java +++ b/Commons/src/main/java/me/filoghost/commons/config/exception/ConverterCastException.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.exception; diff --git a/Commons/src/main/java/me/filoghost/commons/config/exception/InvalidConfigValueException.java b/Commons/src/main/java/me/filoghost/commons/config/exception/InvalidConfigValueException.java index 1d1032d..e7a8867 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/exception/InvalidConfigValueException.java +++ b/Commons/src/main/java/me/filoghost/commons/config/exception/InvalidConfigValueException.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.exception; diff --git a/Commons/src/main/java/me/filoghost/commons/config/exception/MissingConfigValueException.java b/Commons/src/main/java/me/filoghost/commons/config/exception/MissingConfigValueException.java index 9393385..21801fe 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/exception/MissingConfigValueException.java +++ b/Commons/src/main/java/me/filoghost/commons/config/exception/MissingConfigValueException.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.exception; diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/ConfigMapper.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/ConfigMapper.java index 08e74cb..91afec2 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/mapped/ConfigMapper.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/ConfigMapper.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.mapped; diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/IncludeStatic.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/IncludeStatic.java index 4305136..e12829d 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/mapped/IncludeStatic.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/IncludeStatic.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.mapped; diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfig.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfig.java index 36fdf88..8028006 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfig.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfig.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.mapped; diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfigLoader.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfigLoader.java index ec8cda8..0b9c9d3 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfigLoader.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfigLoader.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.mapped; diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedField.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedField.java index 822a3bf..b69865a 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedField.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedField.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.mapped; diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/BooleanConverter.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/BooleanConverter.java index b3c6cda..257000b 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/BooleanConverter.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/BooleanConverter.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.mapped.converter; diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/Converter.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/Converter.java index a4190f3..2c3b81d 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/Converter.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/Converter.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.mapped.converter; diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/DoubleConverter.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/DoubleConverter.java index 77e6127..c951303 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/DoubleConverter.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/DoubleConverter.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.mapped.converter; diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/IntegerConverter.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/IntegerConverter.java index f53edbe..35de8fe 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/IntegerConverter.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/IntegerConverter.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.mapped.converter; diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/ListConverter.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/ListConverter.java index fa19841..5717c0e 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/ListConverter.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/ListConverter.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.mapped.converter; diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/StringConverter.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/StringConverter.java index 60a9243..3458399 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/StringConverter.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/StringConverter.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.mapped.converter; diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColors.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColors.java index 6ef0b8b..3f8c490 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColors.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColors.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.mapped.modifier; diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColorsModifier.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColorsModifier.java index ba4c2c9..3d5dd7e 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColorsModifier.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColorsModifier.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.mapped.modifier; diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ValueModifier.java b/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ValueModifier.java index 14666b7..fc257d7 100644 --- a/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ValueModifier.java +++ b/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ValueModifier.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.config.mapped.modifier; diff --git a/Commons/src/main/java/me/filoghost/commons/logging/ErrorCollector.java b/Commons/src/main/java/me/filoghost/commons/logging/ErrorCollector.java index f2c43d7..4f187ab 100644 --- a/Commons/src/main/java/me/filoghost/commons/logging/ErrorCollector.java +++ b/Commons/src/main/java/me/filoghost/commons/logging/ErrorCollector.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.logging; diff --git a/Commons/src/main/java/me/filoghost/commons/logging/ErrorLog.java b/Commons/src/main/java/me/filoghost/commons/logging/ErrorLog.java index bfdba0c..7ea2afe 100644 --- a/Commons/src/main/java/me/filoghost/commons/logging/ErrorLog.java +++ b/Commons/src/main/java/me/filoghost/commons/logging/ErrorLog.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.logging; diff --git a/Commons/src/main/java/me/filoghost/commons/logging/Log.java b/Commons/src/main/java/me/filoghost/commons/logging/Log.java index c768d6f..031d615 100644 --- a/Commons/src/main/java/me/filoghost/commons/logging/Log.java +++ b/Commons/src/main/java/me/filoghost/commons/logging/Log.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.commons.logging; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index b638a32..a64d1b9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java b/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java index ee12362..21d31fc 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java b/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java index 13e247d..7ca067b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java index f60f0bb..f0554ed 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java index 0fd4531..69cb8e6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java index eb7ba5a..1cecda7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java index 1926968..3ce2660 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/DisabledAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/DisabledAction.java index 4caf9d3..52a0c47 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/DisabledAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/DisabledAction.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java index 3f91aa5..772a50a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java index 9cd140c..035d501 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java index fc70aeb..5781d94 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java index 457819e..1da8b27 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java index 7ba1b84..47ea3d8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java index b7eacc4..773cbf8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java index 85a8cf9..883da09 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java index b45d01c..aecfbab 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.action; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ActionsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ActionsAttribute.java index e60d9ee..29413b1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ActionsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ActionsAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/AmountAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/AmountAttribute.java index f1fa126..871a61c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/AmountAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/AmountAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/AttributeErrorHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/AttributeErrorHandler.java index 8927ec6..f61ed3d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/AttributeErrorHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/AttributeErrorHandler.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerColorAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerColorAttribute.java index 7294c84..0f73c75 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerColorAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerColorAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerPatternsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerPatternsAttribute.java index 55d4286..3cddeea 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerPatternsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerPatternsAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionAttribute.java index 94993ab..4c26176 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionMessageAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionMessageAttribute.java index d4e78e3..3b734ed 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionMessageAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionMessageAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/DurabilityAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/DurabilityAttribute.java index fe022b6..1de4fc1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/DurabilityAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/DurabilityAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/EnchantmentsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/EnchantmentsAttribute.java index f6fc1ef..bd115ab 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/EnchantmentsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/EnchantmentsAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ExpLevelsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ExpLevelsAttribute.java index 8fc4f59..c47c9cb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ExpLevelsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ExpLevelsAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/IconAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/IconAttribute.java index 275deaa..f3ca62e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/IconAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/IconAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/KeepOpenAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/KeepOpenAttribute.java index 7631885..3ec66aa 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/KeepOpenAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/KeepOpenAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LeatherColorAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LeatherColorAttribute.java index 39a60b3..1d1a3bf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LeatherColorAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LeatherColorAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java index 7d7ac19..d1c51fb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java index b34b0ba..1c476c8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NBTDataAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NBTDataAttribute.java index a7506de..184d3ae 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NBTDataAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NBTDataAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java index fa32ec9..637dbe8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/PositionAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/PositionAttribute.java index 4f15914..4e87842 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/PositionAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/PositionAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/PriceAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/PriceAttribute.java index 3671764..38d9c8e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/PriceAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/PriceAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/RequiredItemsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/RequiredItemsAttribute.java index 6da89de..1e88fdd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/RequiredItemsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/RequiredItemsAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/SkullOwnerAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/SkullOwnerAttribute.java index 9e4204d..e756492 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/SkullOwnerAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/SkullOwnerAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ViewPermissionAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ViewPermissionAttribute.java index e5bb9db..c6262cd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ViewPermissionAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ViewPermissionAttribute.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.attribute; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index 32f512c..99ec5a9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.command; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java index 5403a06..3263972 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.config; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java index c7e42c1..505b25f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.config; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java index f8bd4e9..d549b88 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.config; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java index 89d714c..7a8aa41 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.config; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java index d773203..70739d7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.hook; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java index fd6d233..07214af 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.hook; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java index 63bc833..2712847 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.hook; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java index c3a5eef..0d336ed 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.hook; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java b/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java index ea3cbf9..fbd48b9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.hook; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIConfigurableIcon.java index 2304fbb..8bf5295 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIConfigurableIcon.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.icon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java index 6e16ea2..dd96b78 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.icon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java index 8c6a16f..b7723f0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.icon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java index 1198955..b893002 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.icon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/RefreshableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/RefreshableIcon.java index 279be2a..81d8a04 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/RefreshableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/RefreshableIcon.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.icon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java index 3d4c959..5ecf235 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.icon.requirement; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java index 8aeedd5..383fc27 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.icon.requirement; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java index e1dc869..8337aae 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.icon.requirement; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/Requirement.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/Requirement.java index 17d67ac..1915e16 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/Requirement.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/Requirement.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.icon.requirement; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java index b6f2bc7..71ec463 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ package me.filoghost.chestcommands.icon.requirement.item; import me.filoghost.commons.MaterialsHelper; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RemainingItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RemainingItem.java index a96bf6c..1944628 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RemainingItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RemainingItem.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ package me.filoghost.chestcommands.icon.requirement.item; import org.bukkit.Material; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java index 38efab6..e3a96b0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.icon.requirement.item; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java index b653496..7fbafa3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.icon.requirement.item; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/ArrayGrid.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/ArrayGrid.java index a9f370a..29fa339 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/ArrayGrid.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/ArrayGrid.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.inventory; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java index eef5d15..c54f961 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.inventory; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/Grid.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/Grid.java index 8483a48..c390267 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/Grid.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/Grid.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.inventory; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java index a7640e4..1616cbc 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.inventory; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java index 7c59fb6..5af6fbc 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.inventory; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java index b22ac45..fcb7960 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.legacy; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeExecutorException.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeExecutorException.java index 376fb20..12dca04 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeExecutorException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeExecutorException.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.legacy; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java index 5a38ae6..aa475bc 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.legacy; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java index 37e495f..20e5118 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.legacy; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java index a8580b2..3fc295d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.legacy; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexReplacer.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexReplacer.java index c084b1e..184a617 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexReplacer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexReplacer.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.legacy.upgrade; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java index 7825a76..5cc52ef 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.legacy.upgrade; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java index 091dc4e..02f2af4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.legacy.upgrade; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java index 616bfa0..b7ddd04 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.legacy.upgrade; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTaskException.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTaskException.java index 18db42a..d0ae06c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTaskException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTaskException.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.legacy.upgrade; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java index 665b027..c89a334 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.legacy.upgrade; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_LangUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_LangUpgradeTask.java index a9a5f8d..d7ca502 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_LangUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_LangUpgradeTask.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.legacy.v4_0; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java index 93f83dd..0698712 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.legacy.v4_0; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeRenameUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeRenameUpgradeTask.java index 135cc3b..51e2884 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeRenameUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeRenameUpgradeTask.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.legacy.v4_0; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java index 6818e0b..dd16d14 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.legacy.v4_0; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java index 62cf798..054354d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.legacy.v4_0; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java index a5cecf9..6605944 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.listener; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index 4c9133c..4ac8ba4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.listener; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java index 0043831..166597c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.listener; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java index c85b90d..ba74942 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.listener; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java index c1b99ad..59ca707 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.logging; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorPrintInfo.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorPrintInfo.java index c0cf0e6..8d966c8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorPrintInfo.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorPrintInfo.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.logging; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java index dd088d3..9d50b5c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.logging; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java index 790f839..64adbc3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.logging; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java index 881f612..435badd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.menu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java index bd23f3a..f471a9a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.menu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java index 7856484..da10034 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.menu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java index 4703d91..4a0a964 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.menu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java index 093f254..4fd1dde 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.parsing; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java index 20ae6fa..1c1dda8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.parsing; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java index b6003b3..55f3ff3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.parsing; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java index 4348e8a..636ab7d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.parsing; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java index 58d7a03..4f8bc53 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.parsing; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ParseException.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ParseException.java index 348476e..93746ab 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ParseException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ParseException.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.parsing; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java index 5457738..0e64b1b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.parsing.icon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java index 4acde9c..c43d6df 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.parsing.icon; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/ClickType.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/ClickType.java index 1a265eb..dcca7fd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/ClickType.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/ClickType.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.parsing.menu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java index 7aa7078..65a3e68 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.parsing.menu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java index 9448bca..567b296 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.parsing.menu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index c14a85a..61cd37a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.parsing.menu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java index 08690c4..16ec6a5 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.parsing.menu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettingsNode.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettingsNode.java index 5bbc866..144d5db 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettingsNode.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettingsNode.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.parsing.menu; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholder.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholder.java index 9b224a6..af5c084 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholder.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholder.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.placeholder; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderCache.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderCache.java index 093fc14..a51b0a3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderCache.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderCache.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.placeholder; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java index 77c2535..706ee06 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.placeholder; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderRegistry.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderRegistry.java index 9129154..73a9ea0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderRegistry.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderRegistry.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.placeholder; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderString.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderString.java index 6a1860a..fd1ef4e 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderString.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderString.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.placeholder; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java index 0ada6af..c7b4a5f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.placeholder; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/StaticPlaceholder.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/StaticPlaceholder.java index dcfe556..247fe9d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/StaticPlaceholder.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/StaticPlaceholder.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.placeholder; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java index d0de2fd..1eeb896 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.placeholder.scanner; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java index 1f1cb0f..15ca214 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.placeholder.scanner; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java index 78db376..bc8ef33 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java @@ -1,16 +1,7 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Copyright (C) filoghost and contributors * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ package me.filoghost.chestcommands.task; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java index 7023997..f7a4727 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ package me.filoghost.chestcommands.util; import me.filoghost.commons.Strings; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java index ae1f80a..91be0e2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) Jan Schultke + * + * SPDX-License-Identifier: MIT + */ package me.filoghost.chestcommands.util.nbt; /** diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java index e1458d3..bf71e86 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) Jan Schultke + * + * SPDX-License-Identifier: MIT + */ package me.filoghost.chestcommands.util.nbt; import java.util.Arrays; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java index c424794..23341a4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) Jan Schultke + * + * SPDX-License-Identifier: MIT + */ package me.filoghost.chestcommands.util.nbt; import java.util.Collections; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java index 37999b6..2245a48 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) Jan Schultke + * + * SPDX-License-Identifier: MIT + */ package me.filoghost.chestcommands.util.nbt; /** diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java index 6ba50ec..75cb101 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) Jan Schultke + * + * SPDX-License-Identifier: MIT + */ package me.filoghost.chestcommands.util.nbt; /** diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java index f479352..7fa95eb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) Jan Schultke + * + * SPDX-License-Identifier: MIT + */ package me.filoghost.chestcommands.util.nbt; /** diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java index 2643858..bf07c9d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) Jan Schultke + * + * SPDX-License-Identifier: MIT + */ package me.filoghost.chestcommands.util.nbt; import java.util.Arrays; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java index fecbb03..7c8d5c7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) Jan Schultke + * + * SPDX-License-Identifier: MIT + */ package me.filoghost.chestcommands.util.nbt; import java.util.ArrayList; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java index 30500e6..33cca56 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) Jan Schultke + * + * SPDX-License-Identifier: MIT + */ package me.filoghost.chestcommands.util.nbt; /** diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java index e5e5a7b..d605bc1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) Jan Schultke + * + * SPDX-License-Identifier: MIT + */ package me.filoghost.chestcommands.util.nbt; import java.util.Arrays; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java index 23fdcec..5287a78 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) Jan Schultke + * + * SPDX-License-Identifier: MIT + */ package me.filoghost.chestcommands.util.nbt; /** diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java index d8c8111..7a8572a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) Jan Schultke + * + * SPDX-License-Identifier: MIT + */ package me.filoghost.chestcommands.util.nbt; /** diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java index a1d331b..e57168c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) Jan Schultke + * + * SPDX-License-Identifier: MIT + */ package me.filoghost.chestcommands.util.nbt; /** diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java index 03c1be3..636d9e9 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) Jan Schultke + * + * SPDX-License-Identifier: MIT + */ package me.filoghost.chestcommands.util.nbt; /** diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java index 02f1619..3fd8cac 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) Jan Schultke + * + * SPDX-License-Identifier: MIT + */ package me.filoghost.chestcommands.util.nbt.parser; import java.io.IOException; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java index a954b9a..e07a864 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java @@ -1,3 +1,8 @@ +/* + * Copyright (C) Jan Schultke + * + * SPDX-License-Identifier: MIT + */ package me.filoghost.chestcommands.util.nbt.parser; import me.filoghost.chestcommands.util.nbt.NBTByte; From ab3c04d301310963c7b0ed40c687bc45cd7a7241 Mon Sep 17 00:00:00 2001 From: filoghost Date: Wed, 12 Aug 2020 20:54:11 +0200 Subject: [PATCH 179/213] Fix relocation --- Plugin/pom.xml | 294 ++++++++++++++++++++++++------------------------- 1 file changed, 147 insertions(+), 147 deletions(-) diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 1fb43e6..2a43153 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -1,148 +1,148 @@ - - - 4.0.0 - - - me.filoghost.chestcommands - chestcommands-parent - 4.0.0-SNAPSHOT - - - chestcommands-plugin - ChestCommands Plugin - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/groups/public/ - - - - vault-repo - http://nexus.hc.to/content/repositories/pub_releases - - - - confuser-repo - https://ci.frostcast.net/plugin/repository/everything/ - - - - codemc-repo - https://repo.codemc.io/repository/maven-public/ - - - - placeholderapi-repo - https://repo.extendedclip.com/content/repositories/placeholderapi/ - - - - - - org.bukkit - bukkit - ${bukkit.version} - provided - - - - net.milkbowl.vault - VaultAPI - 1.6 - provided - - - - me.confuser - BarAPI - 3.5 - provided - - - - me.clip - placeholderapi - 2.9.2 - provided - - - - org.bstats - bstats-bukkit-lite - 1.7 - - - - me.filoghost.updatechecker - updatechecker - 1.0.0 - - - - ${project.groupId} - chestcommands-api - ${project.version} - - - - ${project.groupId} - chestcommands-commons - ${project.version} - - - - - - - src/main/resources - true - - - .. - - LICENSE.txt - THIRD-PARTY.txt - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.1 - - false - - - *:* - - META-INF/ - - - - - - org.bstats - me.filoghost.commons.metrics - - - me.filoghost.updatechecker - me.filoghost.commons.updater - - - - - - package - - shade - - - - - - - + + + 4.0.0 + + + me.filoghost.chestcommands + chestcommands-parent + 4.0.0-SNAPSHOT + + + chestcommands-plugin + ChestCommands Plugin + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + + vault-repo + http://nexus.hc.to/content/repositories/pub_releases + + + + confuser-repo + https://ci.frostcast.net/plugin/repository/everything/ + + + + codemc-repo + https://repo.codemc.io/repository/maven-public/ + + + + placeholderapi-repo + https://repo.extendedclip.com/content/repositories/placeholderapi/ + + + + + + org.bukkit + bukkit + ${bukkit.version} + provided + + + + net.milkbowl.vault + VaultAPI + 1.6 + provided + + + + me.confuser + BarAPI + 3.5 + provided + + + + me.clip + placeholderapi + 2.9.2 + provided + + + + org.bstats + bstats-bukkit-lite + 1.7 + + + + me.filoghost.updatechecker + updatechecker + 1.0.0 + + + + ${project.groupId} + chestcommands-api + ${project.version} + + + + ${project.groupId} + chestcommands-commons + ${project.version} + + + + + + + src/main/resources + true + + + .. + + LICENSE.txt + THIRD-PARTY.txt + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + false + + + *:* + + META-INF/ + + + + + + org.bstats + me.filoghost.chestcommands.metrics + + + me.filoghost.updatechecker + me.filoghost.chestcommands.updater + + + + + + package + + shade + + + + + + + \ No newline at end of file From 1a28ce824b732db330d910826df70d5f60bb71af Mon Sep 17 00:00:00 2001 From: filoghost Date: Wed, 12 Aug 2020 21:05:42 +0200 Subject: [PATCH 180/213] Add third party licenses --- Plugin/pom.xml | 1 + THIRD-PARTY.txt | 17 ++-- licenses/LICENSE-EisenNBT.txt | 21 +++++ licenses/LICENSE-bStats.txt | 165 ++++++++++++++++++++++++++++++++++ 4 files changed, 197 insertions(+), 7 deletions(-) create mode 100644 licenses/LICENSE-EisenNBT.txt create mode 100644 licenses/LICENSE-bStats.txt diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 2a43153..06ab577 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -104,6 +104,7 @@ LICENSE.txt THIRD-PARTY.txt + licenses/* diff --git a/THIRD-PARTY.txt b/THIRD-PARTY.txt index 9169408..2c7e2ca 100644 --- a/THIRD-PARTY.txt +++ b/THIRD-PARTY.txt @@ -1,9 +1,12 @@ -Chest Commands contains code from the following third party projects, listed with their license information. +Chest Commands contains code from the following third-party open source +projects, listed with their license information. -[bStats Metrics] -URL: https://github.com/Bastian/bStats-Metrics -License: GNU Lesser General Public License v3.0 +bStats Metrics + URL: https://github.com/Bastian/bStats-Metrics + License name: GNU Lesser General Public License v3.0 + License file: /licenses/LICENSE-bStats.txt -[EisenNBT] -URL: https://github.com/Eisenwave/eisen-nbt -License: MIT License \ No newline at end of file +EisenNBT + URL: https://github.com/Eisenwave/eisen-nbt + License name: MIT License + License file: /licenses/LICENSE-EisenNBT.txt \ No newline at end of file diff --git a/licenses/LICENSE-EisenNBT.txt b/licenses/LICENSE-EisenNBT.txt new file mode 100644 index 0000000..18c6916 --- /dev/null +++ b/licenses/LICENSE-EisenNBT.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Jan Schultke + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/licenses/LICENSE-bStats.txt b/licenses/LICENSE-bStats.txt new file mode 100644 index 0000000..65c5ca8 --- /dev/null +++ b/licenses/LICENSE-bStats.txt @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. From e258946f3123dd90dc8be948d0ea1b98a529773e Mon Sep 17 00:00:00 2001 From: filoghost Date: Wed, 12 Aug 2020 21:07:47 +0200 Subject: [PATCH 181/213] Rename metrics package --- Plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 06ab577..2199703 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -125,7 +125,7 @@ - org.bstats + org.bstats.bukkit me.filoghost.chestcommands.metrics From c11b9aa68706e9fa3b5ca156465d511c1ddf5734 Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 13 Aug 2020 14:06:09 +0200 Subject: [PATCH 182/213] Add META-INF back --- Plugin/pom.xml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 2199703..030ac02 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -108,18 +108,36 @@ + + + org.apache.maven.plugins + maven-jar-plugin + 3.2.0 + + + + true + + + ${project.version} + + + + + org.apache.maven.plugins maven-shade-plugin 3.2.1 false + false *:* - META-INF/ + META-INF/maven/ From 4e216720c83cd62f228e548d6e4be96e51acf283 Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 13 Aug 2020 14:43:22 +0200 Subject: [PATCH 183/213] Move dependency versions to root POM --- API/pom.xml | 10 ------ Commons/pom.xml | 9 ------ Plugin/pom.xml | 39 ----------------------- pom.xml | 84 ++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 83 insertions(+), 59 deletions(-) diff --git a/API/pom.xml b/API/pom.xml index ff63c34..5513188 100644 --- a/API/pom.xml +++ b/API/pom.xml @@ -12,25 +12,15 @@ chestcommands-api ChestCommands API - - - spigot-repo - https://hub.spigotmc.org/nexus/content/groups/public/ - - - org.bukkit bukkit - ${bukkit.version} - provided ${project.groupId} chestcommands-commons - ${project.version} diff --git a/Commons/pom.xml b/Commons/pom.xml index 1529529..601900b 100644 --- a/Commons/pom.xml +++ b/Commons/pom.xml @@ -12,19 +12,10 @@ chestcommands-commons ChestCommands Commons - - - spigot-repo - https://hub.spigotmc.org/nexus/content/groups/public/ - - - org.bukkit bukkit - ${bukkit.version} - provided diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 030ac02..548008e 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -12,84 +12,45 @@ chestcommands-plugin ChestCommands Plugin - - - spigot-repo - https://hub.spigotmc.org/nexus/content/groups/public/ - - - - vault-repo - http://nexus.hc.to/content/repositories/pub_releases - - - - confuser-repo - https://ci.frostcast.net/plugin/repository/everything/ - - - - codemc-repo - https://repo.codemc.io/repository/maven-public/ - - - - placeholderapi-repo - https://repo.extendedclip.com/content/repositories/placeholderapi/ - - - org.bukkit bukkit - ${bukkit.version} - provided net.milkbowl.vault VaultAPI - 1.6 - provided me.confuser BarAPI - 3.5 - provided me.clip placeholderapi - 2.9.2 - provided org.bstats bstats-bukkit-lite - 1.7 me.filoghost.updatechecker updatechecker - 1.0.0 ${project.groupId} chestcommands-api - ${project.version} ${project.groupId} chestcommands-commons - ${project.version} diff --git a/pom.xml b/pom.xml index c8df814..9b75521 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,6 @@ 1.8 1.8 true - 1.8-R0.1-SNAPSHOT @@ -39,6 +38,89 @@ Commons + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + vault-repo + http://nexus.hc.to/content/repositories/pub_releases + + + + confuser-repo + https://ci.frostcast.net/plugin/repository/everything/ + + + + codemc-repo + https://repo.codemc.io/repository/maven-public/ + + + + placeholderapi-repo + https://repo.extendedclip.com/content/repositories/placeholderapi/ + + + + + + + org.bukkit + bukkit + 1.8-R0.1-SNAPSHOT + provided + + + + net.milkbowl.vault + VaultAPI + 1.6 + provided + + + + me.confuser + BarAPI + 3.5 + provided + + + + me.clip + placeholderapi + 2.9.2 + provided + + + + org.bstats + bstats-bukkit-lite + 1.7 + + + + me.filoghost.updatechecker + updatechecker + 1.0.0 + + + + ${project.groupId} + chestcommands-api + ${project.version} + + + + ${project.groupId} + chestcommands-commons + ${project.version} + + + + From e95b7764c0afd9b60d3691195347d4600c34db32 Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 13 Aug 2020 14:44:54 +0200 Subject: [PATCH 184/213] Move plugin versions to root POM --- Plugin/pom.xml | 2 -- pom.xml | 7 +++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 548008e..77af9ba 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -74,7 +74,6 @@ org.apache.maven.plugins maven-jar-plugin - 3.2.0 @@ -90,7 +89,6 @@ org.apache.maven.plugins maven-shade-plugin - 3.2.1 false false diff --git a/pom.xml b/pom.xml index 9b75521..223948b 100644 --- a/pom.xml +++ b/pom.xml @@ -127,6 +127,7 @@ org.apache.maven.plugins maven-jar-plugin + 3.2.0 false @@ -136,6 +137,12 @@ + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.3 + From e06c5baa62def666e3b84a5a79f792fc897497a6 Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 13 Aug 2020 14:48:11 +0200 Subject: [PATCH 185/213] Add maven-enforcer-plugin --- pom.xml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pom.xml b/pom.xml index 223948b..f7394de 100644 --- a/pom.xml +++ b/pom.xml @@ -143,8 +143,39 @@ maven-shade-plugin 3.2.3 + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M3 + + + + + org.apache.maven.plugins + maven-enforcer-plugin + + + + enforce + + + + + + [3.6.0,) + + + [1.8,) + + + + + + + From 48dca34de33a47e2ccda2a16977c6dae88384250 Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 13 Aug 2020 14:52:51 +0200 Subject: [PATCH 186/213] Add build number on development builds --- Plugin/pom.xml | 29 ++++++++++++++++++++++++- Plugin/src/main/resources/plugin.yml | 2 +- pom.xml | 32 ++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 77af9ba..a60bed6 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -71,6 +71,33 @@ + + org.apache.maven.plugins + maven-antrun-plugin + + + + set-plugin-version + validate + + run + + + true + + + + + + + + + + + + + + org.apache.maven.plugins maven-jar-plugin @@ -80,7 +107,7 @@ true - ${project.version} + ${project.pluginVersion} diff --git a/Plugin/src/main/resources/plugin.yml b/Plugin/src/main/resources/plugin.yml index b2fe7e2..eb33aed 100644 --- a/Plugin/src/main/resources/plugin.yml +++ b/Plugin/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: ChestCommands main: me.filoghost.chestcommands.ChestCommands -version: ${project.version} +version: ${project.pluginVersion} api-version: 1.13 softdepend: [Vault, BarAPI, PlaceholderAPI] diff --git a/pom.xml b/pom.xml index f7394de..f7393f9 100644 --- a/pom.xml +++ b/pom.xml @@ -149,6 +149,38 @@ maven-enforcer-plugin 3.0.0-M3 + + + org.apache.maven.plugins + maven-antrun-plugin + 3.0.0 + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.apache.maven.plugins + maven-antrun-plugin + [0.0,) + + run + + + + + + + + + + From a1930e9de75957eb0a68033ba6969a4dba2eb23c Mon Sep 17 00:00:00 2001 From: filoghost Date: Thu, 13 Aug 2020 14:53:14 +0200 Subject: [PATCH 187/213] Add default Maven goal --- pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pom.xml b/pom.xml index f7393f9..6abb06e 100644 --- a/pom.xml +++ b/pom.xml @@ -122,6 +122,8 @@ + clean package + From 01a3b2914e6af0bc51872a8f4be7271f5f83de82 Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 14 Aug 2020 10:21:01 +0200 Subject: [PATCH 188/213] Add basic argument checks for API --- .../chestcommands/api/ChestCommandsAPI.java | 10 +++++----- .../me/filoghost/chestcommands/api/IconMenu.java | 2 +- .../chestcommands/api/internal/BackendAPI.java | 4 ++-- .../chestcommands/DefaultBackendAPI.java | 14 ++++++++++---- .../chestcommands/icon/APIStaticIcon.java | 3 +++ .../chestcommands/icon/BaseConfigurableIcon.java | 15 +++++++++++---- .../icon/requirement/item/RequiredItem.java | 2 +- .../filoghost/chestcommands/menu/APIIconMenu.java | 2 ++ .../chestcommands/menu/BaseIconMenu.java | 4 +++- .../placeholder/PlaceholderManager.java | 3 +++ 10 files changed, 41 insertions(+), 18 deletions(-) diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java index b07433b..d06c065 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java @@ -37,8 +37,8 @@ public class ChestCommandsAPI { * * @return if the menu was found */ - public static boolean isPluginMenu(String yamlFile) { - return BackendAPI.getImplementation().isPluginMenu(yamlFile); + public static boolean pluginMenuExists(String menuFileName) { + return BackendAPI.getImplementation().pluginMenuExists(menuFileName); } @@ -47,10 +47,10 @@ public class ChestCommandsAPI { * NOTE: this method ignores permissions. * * @param player the player that will see the menu - * @param yamlFile the file name of the menu to open (with the .yml extension) + * @param menuFileName the file name of the menu to open (with the .yml extension) * @return if the menu was found and opened */ - public static boolean openPluginMenu(Player player, String yamlFile) { - return BackendAPI.getImplementation().openPluginMenu(player, yamlFile); + public static boolean openPluginMenu(Player player, String menuFileName) { + return BackendAPI.getImplementation().openPluginMenu(player, menuFileName); } } diff --git a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java index 83b0148..c4451eb 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java @@ -33,6 +33,6 @@ public interface IconMenu { */ MenuInventory open(Player player); - void refreshOpenInventories(); + void refreshOpenMenuInventories(); } \ No newline at end of file diff --git a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java index 415a1cd..b1107e9 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java @@ -32,9 +32,9 @@ public abstract class BackendAPI { return implementation; } - public abstract boolean isPluginMenu(String yamlFile); + public abstract boolean pluginMenuExists(String menuFileName); - public abstract boolean openPluginMenu(Player player, String yamlFile); + public abstract boolean openPluginMenu(Player player, String menuFileName); public abstract IconMenu createIconMenu(Plugin owner, String title, int rows); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java b/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java index 21d31fc..27c3ccc 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java @@ -15,6 +15,7 @@ import me.filoghost.chestcommands.icon.APIStaticIcon; import me.filoghost.chestcommands.menu.APIIconMenu; import me.filoghost.chestcommands.menu.InternalIconMenu; import me.filoghost.chestcommands.placeholder.PlaceholderManager; +import me.filoghost.commons.Preconditions; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -23,13 +24,18 @@ import org.bukkit.plugin.Plugin; public class DefaultBackendAPI extends BackendAPI { @Override - public boolean isPluginMenu(String yamlFile) { - return ChestCommands.getMenuManager().getMenuByFileName(yamlFile) != null; + public boolean pluginMenuExists(String menuFileName) { + Preconditions.notNull(menuFileName, "menuFileName"); + + return ChestCommands.getMenuManager().getMenuByFileName(menuFileName) != null; } @Override - public boolean openPluginMenu(Player player, String yamlFile) { - InternalIconMenu menu = ChestCommands.getMenuManager().getMenuByFileName(yamlFile); + public boolean openPluginMenu(Player player, String menuFileName) { + Preconditions.notNull(player, "player"); + Preconditions.notNull(menuFileName, "menuFileName"); + + InternalIconMenu menu = ChestCommands.getMenuManager().getMenuByFileName(menuFileName); if (menu != null) { menu.open(player); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java index dd96b78..e8ec803 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java @@ -7,6 +7,7 @@ package me.filoghost.chestcommands.icon; import me.filoghost.chestcommands.api.ClickHandler; import me.filoghost.chestcommands.api.StaticIcon; +import me.filoghost.commons.Preconditions; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -16,6 +17,7 @@ public class APIStaticIcon implements StaticIcon { private ClickHandler clickHandler; public APIStaticIcon(ItemStack itemStack) { + Preconditions.notNull(itemStack, "itemStack"); this.itemStack = itemStack; } @@ -26,6 +28,7 @@ public class APIStaticIcon implements StaticIcon { @Override public void setItemStack(ItemStack itemStack) { + Preconditions.notNull(itemStack, "itemStack"); this.itemStack = itemStack; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java index b7723f0..9e1ec49 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java @@ -8,6 +8,8 @@ package me.filoghost.chestcommands.icon; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.placeholder.PlaceholderString; import me.filoghost.chestcommands.placeholder.PlaceholderStringList; +import me.filoghost.chestcommands.util.nbt.parser.MojangsonParseException; +import me.filoghost.chestcommands.util.nbt.parser.MojangsonParser; import me.filoghost.commons.Preconditions; import me.filoghost.commons.collection.CollectionUtils; import me.filoghost.commons.logging.Log; @@ -51,7 +53,6 @@ public abstract class BaseConfigurableIcon implements Icon { protected ItemStack cachedRendering; // Cache the rendered item when possible and if state hasn't changed public BaseConfigurableIcon(Material material) { - Preconditions.checkArgumentNotAir(material, "material"); this.material = material; this.amount = 1; } @@ -67,7 +68,6 @@ public abstract class BaseConfigurableIcon implements Icon { } public void setMaterial(Material material) { - Preconditions.checkArgumentNotAir(material, "material"); this.material = material; cachedRendering = null; } @@ -77,7 +77,7 @@ public abstract class BaseConfigurableIcon implements Icon { } public void setAmount(int amount) { - Preconditions.checkArgument(amount >= 1, "Amount must 1 or greater"); + Preconditions.checkArgument(amount > 0, "amount must be greater than 0"); this.amount = Math.min(amount, 127); cachedRendering = null; } @@ -87,7 +87,7 @@ public abstract class BaseConfigurableIcon implements Icon { } public void setDurability(short durability) { - Preconditions.checkArgument(durability >= 0, "Durability must not be negative"); + Preconditions.checkArgument(durability >= 0, "durability must be 0 or greater"); this.durability = durability; cachedRendering = null; } @@ -97,6 +97,13 @@ public abstract class BaseConfigurableIcon implements Icon { } public void setNBTData(String nbtData) { + if (nbtData != null) { + try { + MojangsonParser.parse(nbtData); + } catch (MojangsonParseException e) { + throw new IllegalArgumentException("invalid nbtData", e); + } + } this.nbtData = nbtData; cachedRendering = null; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java index e3a96b0..5ab0b5a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java @@ -35,7 +35,7 @@ public class RequiredItem { } public void setRestrictiveDurability(short durability) { - Preconditions.checkArgument(durability >= 0, "Durability cannot be negative"); + Preconditions.checkArgument(durability >= 0, "durability must be 0 or greater"); this.durability = durability; isDurabilityRestrictive = true; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java index 435badd..32a1989 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java @@ -5,6 +5,7 @@ */ package me.filoghost.chestcommands.menu; +import me.filoghost.commons.Preconditions; import org.bukkit.plugin.Plugin; public class APIIconMenu extends BaseIconMenu { @@ -13,6 +14,7 @@ public class APIIconMenu extends BaseIconMenu { public APIIconMenu(Plugin owner, String title, int rows) { super(title, rows); + Preconditions.notNull(owner, "owner"); this.owner = owner; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java index f471a9a..ac1f1cd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java @@ -23,6 +23,8 @@ public abstract class BaseIconMenu implements IconMenu { public BaseIconMenu(String title, int rows) { + Preconditions.notNull(title, "title"); + Preconditions.checkArgument(rows > 0, "rows must be greater than 0"); this.title = title; this.icons = new ArrayGrid<>(rows, 9); } @@ -66,7 +68,7 @@ public abstract class BaseIconMenu implements IconMenu { } @Override - public void refreshOpenInventories() { + public void refreshOpenMenuInventories() { for (Player player : Bukkit.getOnlinePlayers()) { DefaultMenuInventory menuInventory = MenuManager.getOpenMenuInventory(player); if (menuInventory != null && menuInventory.getIconMenu() == this) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java index 706ee06..27888bc 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java @@ -106,8 +106,11 @@ public class PlaceholderManager { } public static void registerPluginPlaceholder(Plugin plugin, String identifier, PlaceholderReplacer placeholderReplacer) { + Preconditions.notNull(plugin, "plugin"); + Preconditions.notNull(identifier, "identifier"); Preconditions.checkArgument(1 <= identifier.length() && identifier.length() <= 30, "identifier length must be between 1 and 30"); Preconditions.checkArgument(identifier.matches("[a-zA-Z0-9_]+"), "identifier must contain only letters, numbers and underscores"); + Preconditions.notNull(placeholderReplacer, "placeholderReplacer"); relativePlaceholderRegistry.registerExternalPlaceholder(plugin, identifier, placeholderReplacer); } From 7bccf9131e26bbbebe21fd7be7cbee4d7d3b1408 Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 14 Aug 2020 11:28:47 +0200 Subject: [PATCH 189/213] Make Maven API dependency on commons non-transitive --- API/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/API/pom.xml b/API/pom.xml index 5513188..93b53bf 100644 --- a/API/pom.xml +++ b/API/pom.xml @@ -21,6 +21,7 @@ ${project.groupId} chestcommands-commons + true From 5681eeb352f6a584c55a170f1a802ac84fa950e1 Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 14 Aug 2020 15:02:30 +0200 Subject: [PATCH 190/213] Allow air as icon material --- .../chestcommands/action/GiveItemAction.java | 1 + .../chestcommands/attribute/MaterialAttribute.java | 13 ++----------- .../attribute/RequiredItemsAttribute.java | 1 + .../chestcommands/logging/ErrorMessages.java | 1 + .../chestcommands/parsing/ItemStackParser.java | 11 +++++------ .../chestcommands/parsing/MaterialParser.java | 14 ++++++++++++++ .../chestcommands/parsing/menu/MenuParser.java | 1 + 7 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 Plugin/src/main/java/me/filoghost/chestcommands/parsing/MaterialParser.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java index 035d501..0b98bd4 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java @@ -16,6 +16,7 @@ public class GiveItemAction implements Action { public GiveItemAction(String serializedAction) throws ParseException { ItemStackParser reader = new ItemStackParser(serializedAction, true); + reader.checkNotAir(); itemToGive = reader.createStack(); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java index 1c476c8..989545f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java @@ -6,25 +6,16 @@ package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.parsing.MaterialParser; import me.filoghost.chestcommands.parsing.ParseException; -import me.filoghost.commons.MaterialsHelper; import org.bukkit.Material; -import java.util.Optional; - public class MaterialAttribute implements IconAttribute { private final Material material; public MaterialAttribute(String serializedMaterial, AttributeErrorHandler errorHandler) throws ParseException { - Optional material = MaterialsHelper.matchMaterial(serializedMaterial); - - if (!material.isPresent() || MaterialsHelper.isAir(material.get())) { - throw new ParseException(ErrorMessages.Parsing.unknownMaterial(serializedMaterial)); - } - - this.material = material.get(); + this.material = MaterialParser.parseMaterial(serializedMaterial); } @Override diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/RequiredItemsAttribute.java b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/RequiredItemsAttribute.java index 1e88fdd..a24b49b 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/RequiredItemsAttribute.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/attribute/RequiredItemsAttribute.java @@ -23,6 +23,7 @@ public class RequiredItemsAttribute implements IconAttribute { for (String serializedItem : serializedRequiredItems) { try { ItemStackParser itemReader = new ItemStackParser(serializedItem, true); + itemReader.checkNotAir(); RequiredItem requiredItem = new RequiredItem(itemReader.getMaterial(), itemReader.getAmount()); if (itemReader.hasExplicitDurability()) { requiredItem.setRestrictiveDurability(itemReader.getDurability()); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java index 59ca707..ace14a2 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java @@ -84,6 +84,7 @@ public class ErrorMessages { public static final String invalidPatternFormat = "value must match the format \"pattern:color\""; public static final String unknownAttribute = "unknown attribute"; + public static String materialCannotBeAir = "material cannot be air"; public static String unknownMaterial(String materialString) { return "unknown material \"" + materialString + "\""; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java index 636ab7d..d643be8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java @@ -12,8 +12,6 @@ import me.filoghost.commons.Strings; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import java.util.Optional; - public class ItemStackParser { private final Material material; @@ -60,12 +58,13 @@ public class ItemStackParser { input = splitByColons[0]; } - Optional material = MaterialsHelper.matchMaterial(input); + this.material = MaterialParser.parseMaterial(input); + } - if (!material.isPresent() || MaterialsHelper.isAir(material.get())) { - throw new ParseException(ErrorMessages.Parsing.unknownMaterial(input)); + public void checkNotAir() throws ParseException { + if (MaterialsHelper.isAir(material)) { + throw new ParseException(ErrorMessages.Parsing.materialCannotBeAir); } - this.material = material.get(); } public Material getMaterial() { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/MaterialParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/MaterialParser.java new file mode 100644 index 0000000..9c9f93d --- /dev/null +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/MaterialParser.java @@ -0,0 +1,14 @@ +package me.filoghost.chestcommands.parsing; + +import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.commons.MaterialsHelper; +import org.bukkit.Material; + +public class MaterialParser { + + public static Material parseMaterial(String materialName) throws ParseException { + return MaterialsHelper.matchMaterial(materialName) + .orElseThrow(() -> new ParseException(ErrorMessages.Parsing.unknownMaterial(materialName))); + } + +} diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index 61cd37a..6357add 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -152,6 +152,7 @@ public class MenuParser { if (leftClick || rightClick) { try { ItemStackParser itemReader = new ItemStackParser(openItemMaterial, false); + itemReader.checkNotAir(); ClickType clickType = ClickType.fromOptions(leftClick, rightClick); MenuOpenItem openItem = new MenuOpenItem(itemReader.getMaterial(), clickType); From 0eb908504a276bcf2111f0e19447f0da77c507b1 Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 14 Aug 2020 16:30:45 +0200 Subject: [PATCH 191/213] Use scope "provided" rather than optional in POM --- API/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/API/pom.xml b/API/pom.xml index 93b53bf..f2cee33 100644 --- a/API/pom.xml +++ b/API/pom.xml @@ -21,7 +21,7 @@ ${project.groupId} chestcommands-commons - true + provided From e15c5fc77fa6cf6d88956627b7614f487ce67ba9 Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 14 Aug 2020 16:52:07 +0200 Subject: [PATCH 192/213] Update README link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d77a04..29bd67c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ChestCommands =================== -Bukkit Page: http://dev.bukkit.org/bukkit-plugins/chest-commands +Bukkit Page: http://dev.bukkit.org/projects/chest-commands Chest Commands is free software/open source, and is distributed under the [GPL 3.0 License](https://opensource.org/licenses/GPL-3.0). It contains third-party code, see the included THIRD-PARTY.txt file for the license information on third-party code. From e4d6c8aed59b20b9070d13fc12a417894736c3f5 Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 14 Aug 2020 17:25:27 +0200 Subject: [PATCH 193/213] Use lowercase module folder names --- {API => api}/pom.xml | 0 .../me/filoghost/chestcommands/api/ChestCommandsAPI.java | 0 .../java/me/filoghost/chestcommands/api/ClickHandler.java | 0 .../java/me/filoghost/chestcommands/api/ClickResult.java | 0 .../java/me/filoghost/chestcommands/api/ClickableIcon.java | 0 .../me/filoghost/chestcommands/api/ConfigurableIcon.java | 0 .../src/main/java/me/filoghost/chestcommands/api/Icon.java | 0 .../main/java/me/filoghost/chestcommands/api/IconMenu.java | 0 .../java/me/filoghost/chestcommands/api/MenuInventory.java | 0 .../me/filoghost/chestcommands/api/PlaceholderReplacer.java | 0 .../java/me/filoghost/chestcommands/api/StaticIcon.java | 0 .../me/filoghost/chestcommands/api/internal/BackendAPI.java | 0 {Commons => commons}/pom.xml | 0 .../src/main/java/me/filoghost/commons/BaseJavaPlugin.java | 0 .../src/main/java/me/filoghost/commons/Colors.java | 0 .../src/main/java/me/filoghost/commons/CommonsUtil.java | 0 .../src/main/java/me/filoghost/commons/MaterialsHelper.java | 0 .../src/main/java/me/filoghost/commons/Preconditions.java | 0 .../src/main/java/me/filoghost/commons/Strings.java | 0 .../me/filoghost/commons/collection/CaseInsensitiveMap.java | 0 .../me/filoghost/commons/collection/CollectionUtils.java | 0 .../main/java/me/filoghost/commons/collection/Registry.java | 0 .../java/me/filoghost/commons/command/CommandException.java | 0 .../java/me/filoghost/commons/command/CommandFramework.java | 0 .../java/me/filoghost/commons/command/CommandValidate.java | 0 .../java/me/filoghost/commons/config/BaseConfigManager.java | 0 .../src/main/java/me/filoghost/commons/config/Config.java | 0 .../main/java/me/filoghost/commons/config/ConfigErrors.java | 0 .../main/java/me/filoghost/commons/config/ConfigLoader.java | 0 .../main/java/me/filoghost/commons/config/ConfigPath.java | 0 .../java/me/filoghost/commons/config/ConfigSection.java | 0 .../main/java/me/filoghost/commons/config/ConfigValue.java | 0 .../java/me/filoghost/commons/config/ConfigValueType.java | 0 .../me/filoghost/commons/config/EmptyConfigSection.java | 0 .../filoghost/commons/config/exception/ConfigException.java | 0 .../commons/config/exception/ConfigLoadException.java | 0 .../commons/config/exception/ConfigSaveException.java | 0 .../commons/config/exception/ConfigSyntaxException.java | 0 .../commons/config/exception/ConfigValueException.java | 0 .../commons/config/exception/ConverterCastException.java | 0 .../config/exception/InvalidConfigValueException.java | 0 .../config/exception/MissingConfigValueException.java | 0 .../me/filoghost/commons/config/mapped/ConfigMapper.java | 0 .../me/filoghost/commons/config/mapped/IncludeStatic.java | 0 .../me/filoghost/commons/config/mapped/MappedConfig.java | 0 .../filoghost/commons/config/mapped/MappedConfigLoader.java | 0 .../me/filoghost/commons/config/mapped/MappedField.java | 0 .../commons/config/mapped/converter/BooleanConverter.java | 0 .../commons/config/mapped/converter/Converter.java | 0 .../commons/config/mapped/converter/DoubleConverter.java | 0 .../commons/config/mapped/converter/IntegerConverter.java | 0 .../commons/config/mapped/converter/ListConverter.java | 0 .../commons/config/mapped/converter/StringConverter.java | 0 .../commons/config/mapped/modifier/ChatColors.java | 0 .../commons/config/mapped/modifier/ChatColorsModifier.java | 0 .../commons/config/mapped/modifier/ValueModifier.java | 0 .../java/me/filoghost/commons/logging/ErrorCollector.java | 0 .../main/java/me/filoghost/commons/logging/ErrorLog.java | 0 .../src/main/java/me/filoghost/commons/logging/Log.java | 0 {Plugin => plugin}/pom.xml | 0 .../main/java/me/filoghost/chestcommands/ChestCommands.java | 0 .../java/me/filoghost/chestcommands/DefaultBackendAPI.java | 0 .../main/java/me/filoghost/chestcommands/Permissions.java | 0 .../main/java/me/filoghost/chestcommands/action/Action.java | 0 .../me/filoghost/chestcommands/action/BroadcastAction.java | 0 .../filoghost/chestcommands/action/ChangeServerAction.java | 0 .../chestcommands/action/ConsoleCommandAction.java | 0 .../me/filoghost/chestcommands/action/DisabledAction.java | 0 .../me/filoghost/chestcommands/action/DragonBarAction.java | 0 .../me/filoghost/chestcommands/action/GiveItemAction.java | 0 .../me/filoghost/chestcommands/action/GiveMoneyAction.java | 0 .../me/filoghost/chestcommands/action/OpCommandAction.java | 0 .../me/filoghost/chestcommands/action/OpenMenuAction.java | 0 .../me/filoghost/chestcommands/action/PlaySoundAction.java | 0 .../filoghost/chestcommands/action/PlayerCommandAction.java | 0 .../filoghost/chestcommands/action/SendMessageAction.java | 0 .../filoghost/chestcommands/attribute/ActionsAttribute.java | 0 .../filoghost/chestcommands/attribute/AmountAttribute.java | 0 .../chestcommands/attribute/AttributeErrorHandler.java | 0 .../chestcommands/attribute/BannerColorAttribute.java | 0 .../chestcommands/attribute/BannerPatternsAttribute.java | 0 .../chestcommands/attribute/ClickPermissionAttribute.java | 0 .../attribute/ClickPermissionMessageAttribute.java | 0 .../chestcommands/attribute/DurabilityAttribute.java | 0 .../chestcommands/attribute/EnchantmentsAttribute.java | 0 .../chestcommands/attribute/ExpLevelsAttribute.java | 0 .../me/filoghost/chestcommands/attribute/IconAttribute.java | 0 .../chestcommands/attribute/KeepOpenAttribute.java | 0 .../chestcommands/attribute/LeatherColorAttribute.java | 0 .../me/filoghost/chestcommands/attribute/LoreAttribute.java | 0 .../chestcommands/attribute/MaterialAttribute.java | 0 .../filoghost/chestcommands/attribute/NBTDataAttribute.java | 0 .../me/filoghost/chestcommands/attribute/NameAttribute.java | 0 .../chestcommands/attribute/PositionAttribute.java | 0 .../filoghost/chestcommands/attribute/PriceAttribute.java | 0 .../chestcommands/attribute/RequiredItemsAttribute.java | 0 .../chestcommands/attribute/SkullOwnerAttribute.java | 0 .../chestcommands/attribute/ViewPermissionAttribute.java | 0 .../me/filoghost/chestcommands/command/CommandHandler.java | 0 .../me/filoghost/chestcommands/config/ConfigManager.java | 0 .../filoghost/chestcommands/config/CustomPlaceholders.java | 0 .../main/java/me/filoghost/chestcommands/config/Lang.java | 0 .../java/me/filoghost/chestcommands/config/Settings.java | 0 .../java/me/filoghost/chestcommands/hook/BarAPIHook.java | 0 .../me/filoghost/chestcommands/hook/BungeeCordHook.java | 0 .../me/filoghost/chestcommands/hook/PlaceholderAPIHook.java | 0 .../java/me/filoghost/chestcommands/hook/PluginHook.java | 0 .../me/filoghost/chestcommands/hook/VaultEconomyHook.java | 0 .../filoghost/chestcommands/icon/APIConfigurableIcon.java | 0 .../java/me/filoghost/chestcommands/icon/APIStaticIcon.java | 0 .../filoghost/chestcommands/icon/BaseConfigurableIcon.java | 0 .../chestcommands/icon/InternalConfigurableIcon.java | 0 .../me/filoghost/chestcommands/icon/RefreshableIcon.java | 0 .../chestcommands/icon/requirement/RequiredExpLevel.java | 0 .../chestcommands/icon/requirement/RequiredMoney.java | 0 .../chestcommands/icon/requirement/RequiredPermission.java | 0 .../chestcommands/icon/requirement/Requirement.java | 0 .../icon/requirement/item/InventoryTakeHelper.java | 0 .../chestcommands/icon/requirement/item/RemainingItem.java | 0 .../chestcommands/icon/requirement/item/RequiredItem.java | 0 .../chestcommands/icon/requirement/item/RequiredItems.java | 0 .../me/filoghost/chestcommands/inventory/ArrayGrid.java | 0 .../chestcommands/inventory/DefaultMenuInventory.java | 0 .../java/me/filoghost/chestcommands/inventory/Grid.java | 0 .../me/filoghost/chestcommands/inventory/InventoryGrid.java | 0 .../chestcommands/inventory/MenuInventoryHolder.java | 0 .../main/java/me/filoghost/chestcommands/legacy/Backup.java | 0 .../chestcommands/legacy/UpgradeExecutorException.java | 0 .../java/me/filoghost/chestcommands/legacy/UpgradeList.java | 0 .../chestcommands/legacy/UpgradesDoneRegistry.java | 0 .../me/filoghost/chestcommands/legacy/UpgradesExecutor.java | 0 .../chestcommands/legacy/upgrade/RegexReplacer.java | 0 .../chestcommands/legacy/upgrade/RegexUpgradeTask.java | 0 .../me/filoghost/chestcommands/legacy/upgrade/Upgrade.java | 0 .../filoghost/chestcommands/legacy/upgrade/UpgradeTask.java | 0 .../chestcommands/legacy/upgrade/UpgradeTaskException.java | 0 .../chestcommands/legacy/upgrade/YamlUpgradeTask.java | 0 .../chestcommands/legacy/v4_0/v4_0_LangUpgradeTask.java | 0 .../legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java | 0 .../legacy/v4_0/v4_0_MenuNodeRenameUpgradeTask.java | 0 .../legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java | 0 .../chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java | 0 .../filoghost/chestcommands/listener/CommandListener.java | 0 .../filoghost/chestcommands/listener/InventoryListener.java | 0 .../me/filoghost/chestcommands/listener/JoinListener.java | 0 .../me/filoghost/chestcommands/listener/SignListener.java | 0 .../me/filoghost/chestcommands/logging/ErrorMessages.java | 0 .../me/filoghost/chestcommands/logging/ErrorPrintInfo.java | 0 .../filoghost/chestcommands/logging/MessagePartJoiner.java | 0 .../chestcommands/logging/PrintableErrorCollector.java | 0 .../java/me/filoghost/chestcommands/menu/APIIconMenu.java | 0 .../java/me/filoghost/chestcommands/menu/BaseIconMenu.java | 0 .../me/filoghost/chestcommands/menu/InternalIconMenu.java | 0 .../java/me/filoghost/chestcommands/menu/MenuManager.java | 0 .../me/filoghost/chestcommands/parsing/ActionParser.java | 0 .../filoghost/chestcommands/parsing/EnchantmentParser.java | 0 .../me/filoghost/chestcommands/parsing/ItemMetaParser.java | 0 .../me/filoghost/chestcommands/parsing/ItemStackParser.java | 0 .../me/filoghost/chestcommands/parsing/MaterialParser.java | 0 .../me/filoghost/chestcommands/parsing/NumberParser.java | 0 .../me/filoghost/chestcommands/parsing/ParseException.java | 0 .../filoghost/chestcommands/parsing/icon/AttributeType.java | 0 .../filoghost/chestcommands/parsing/icon/IconSettings.java | 0 .../me/filoghost/chestcommands/parsing/menu/ClickType.java | 0 .../me/filoghost/chestcommands/parsing/menu/LoadedMenu.java | 0 .../filoghost/chestcommands/parsing/menu/MenuOpenItem.java | 0 .../me/filoghost/chestcommands/parsing/menu/MenuParser.java | 0 .../filoghost/chestcommands/parsing/menu/MenuSettings.java | 0 .../chestcommands/parsing/menu/MenuSettingsNode.java | 0 .../chestcommands/placeholder/DefaultPlaceholder.java | 0 .../chestcommands/placeholder/PlaceholderCache.java | 0 .../chestcommands/placeholder/PlaceholderManager.java | 0 .../chestcommands/placeholder/PlaceholderRegistry.java | 0 .../chestcommands/placeholder/PlaceholderString.java | 0 .../chestcommands/placeholder/PlaceholderStringList.java | 0 .../chestcommands/placeholder/StaticPlaceholder.java | 0 .../chestcommands/placeholder/scanner/PlaceholderMatch.java | 0 .../placeholder/scanner/PlaceholderScanner.java | 0 .../java/me/filoghost/chestcommands/task/TickingTask.java | 0 .../main/java/me/filoghost/chestcommands/util/Utils.java | 0 .../java/me/filoghost/chestcommands/util/nbt/NBTByte.java | 0 .../me/filoghost/chestcommands/util/nbt/NBTByteArray.java | 0 .../me/filoghost/chestcommands/util/nbt/NBTCompound.java | 0 .../java/me/filoghost/chestcommands/util/nbt/NBTDouble.java | 0 .../java/me/filoghost/chestcommands/util/nbt/NBTFloat.java | 0 .../java/me/filoghost/chestcommands/util/nbt/NBTInt.java | 0 .../me/filoghost/chestcommands/util/nbt/NBTIntArray.java | 0 .../java/me/filoghost/chestcommands/util/nbt/NBTList.java | 0 .../java/me/filoghost/chestcommands/util/nbt/NBTLong.java | 0 .../me/filoghost/chestcommands/util/nbt/NBTLongArray.java | 0 .../java/me/filoghost/chestcommands/util/nbt/NBTShort.java | 0 .../java/me/filoghost/chestcommands/util/nbt/NBTString.java | 0 .../java/me/filoghost/chestcommands/util/nbt/NBTTag.java | 0 .../java/me/filoghost/chestcommands/util/nbt/NBTType.java | 0 .../util/nbt/parser/MojangsonParseException.java | 0 .../chestcommands/util/nbt/parser/MojangsonParser.java | 0 .../src/main/resources/custom-placeholders.yml | 0 {Plugin => plugin}/src/main/resources/menu/example.yml | 0 {Plugin => plugin}/src/main/resources/plugin.yml | 0 pom.xml | 6 +++--- 200 files changed, 3 insertions(+), 3 deletions(-) rename {API => api}/pom.xml (100%) rename {API => api}/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java (100%) rename {API => api}/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java (100%) rename {API => api}/src/main/java/me/filoghost/chestcommands/api/ClickResult.java (100%) rename {API => api}/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java (100%) rename {API => api}/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java (100%) rename {API => api}/src/main/java/me/filoghost/chestcommands/api/Icon.java (100%) rename {API => api}/src/main/java/me/filoghost/chestcommands/api/IconMenu.java (100%) rename {API => api}/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java (100%) rename {API => api}/src/main/java/me/filoghost/chestcommands/api/PlaceholderReplacer.java (100%) rename {API => api}/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java (100%) rename {API => api}/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java (100%) rename {Commons => commons}/pom.xml (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/BaseJavaPlugin.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/Colors.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/CommonsUtil.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/MaterialsHelper.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/Preconditions.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/Strings.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/collection/CaseInsensitiveMap.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/collection/CollectionUtils.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/collection/Registry.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/command/CommandException.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/command/CommandFramework.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/command/CommandValidate.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/BaseConfigManager.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/Config.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/ConfigErrors.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/ConfigLoader.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/ConfigPath.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/ConfigSection.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/ConfigValue.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/ConfigValueType.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/EmptyConfigSection.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/exception/ConfigException.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/exception/ConfigLoadException.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/exception/ConfigSaveException.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/exception/ConfigSyntaxException.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/exception/ConfigValueException.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/exception/ConverterCastException.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/exception/InvalidConfigValueException.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/exception/MissingConfigValueException.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/mapped/ConfigMapper.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/mapped/IncludeStatic.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/mapped/MappedConfig.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/mapped/MappedConfigLoader.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/mapped/MappedField.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/mapped/converter/BooleanConverter.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/mapped/converter/Converter.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/mapped/converter/DoubleConverter.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/mapped/converter/IntegerConverter.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/mapped/converter/ListConverter.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/mapped/converter/StringConverter.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColors.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColorsModifier.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/config/mapped/modifier/ValueModifier.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/logging/ErrorCollector.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/logging/ErrorLog.java (100%) rename {Commons => commons}/src/main/java/me/filoghost/commons/logging/Log.java (100%) rename {Plugin => plugin}/pom.xml (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/ChestCommands.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/Permissions.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/action/Action.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/action/DisabledAction.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/ActionsAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/AmountAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/AttributeErrorHandler.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/BannerColorAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/BannerPatternsAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionMessageAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/DurabilityAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/EnchantmentsAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/ExpLevelsAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/IconAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/KeepOpenAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/LeatherColorAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/NBTDataAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/PositionAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/PriceAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/RequiredItemsAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/SkullOwnerAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/attribute/ViewPermissionAttribute.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/config/Lang.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/config/Settings.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/icon/APIConfigurableIcon.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/icon/RefreshableIcon.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/icon/requirement/Requirement.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RemainingItem.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/inventory/ArrayGrid.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/inventory/Grid.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/legacy/Backup.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/legacy/UpgradeExecutorException.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexReplacer.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTaskException.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_LangUpgradeTask.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeRenameUpgradeTask.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/listener/SignListener.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/logging/ErrorPrintInfo.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/parsing/MaterialParser.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/parsing/ParseException.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/parsing/menu/ClickType.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettingsNode.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholder.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderCache.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderRegistry.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderString.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/placeholder/StaticPlaceholder.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/task/TickingTask.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/util/Utils.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java (100%) rename {Plugin => plugin}/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java (100%) rename {Plugin => plugin}/src/main/resources/custom-placeholders.yml (100%) rename {Plugin => plugin}/src/main/resources/menu/example.yml (100%) rename {Plugin => plugin}/src/main/resources/plugin.yml (100%) diff --git a/API/pom.xml b/api/pom.xml similarity index 100% rename from API/pom.xml rename to api/pom.xml diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java b/api/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java similarity index 100% rename from API/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java rename to api/src/main/java/me/filoghost/chestcommands/api/ChestCommandsAPI.java diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java b/api/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java similarity index 100% rename from API/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java rename to api/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java b/api/src/main/java/me/filoghost/chestcommands/api/ClickResult.java similarity index 100% rename from API/src/main/java/me/filoghost/chestcommands/api/ClickResult.java rename to api/src/main/java/me/filoghost/chestcommands/api/ClickResult.java diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java b/api/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java similarity index 100% rename from API/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java rename to api/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java diff --git a/API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java b/api/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java similarity index 100% rename from API/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java rename to api/src/main/java/me/filoghost/chestcommands/api/ConfigurableIcon.java diff --git a/API/src/main/java/me/filoghost/chestcommands/api/Icon.java b/api/src/main/java/me/filoghost/chestcommands/api/Icon.java similarity index 100% rename from API/src/main/java/me/filoghost/chestcommands/api/Icon.java rename to api/src/main/java/me/filoghost/chestcommands/api/Icon.java diff --git a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java b/api/src/main/java/me/filoghost/chestcommands/api/IconMenu.java similarity index 100% rename from API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java rename to api/src/main/java/me/filoghost/chestcommands/api/IconMenu.java diff --git a/API/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java b/api/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java similarity index 100% rename from API/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java rename to api/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java diff --git a/API/src/main/java/me/filoghost/chestcommands/api/PlaceholderReplacer.java b/api/src/main/java/me/filoghost/chestcommands/api/PlaceholderReplacer.java similarity index 100% rename from API/src/main/java/me/filoghost/chestcommands/api/PlaceholderReplacer.java rename to api/src/main/java/me/filoghost/chestcommands/api/PlaceholderReplacer.java diff --git a/API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java b/api/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java similarity index 100% rename from API/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java rename to api/src/main/java/me/filoghost/chestcommands/api/StaticIcon.java diff --git a/API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java b/api/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java similarity index 100% rename from API/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java rename to api/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java diff --git a/Commons/pom.xml b/commons/pom.xml similarity index 100% rename from Commons/pom.xml rename to commons/pom.xml diff --git a/Commons/src/main/java/me/filoghost/commons/BaseJavaPlugin.java b/commons/src/main/java/me/filoghost/commons/BaseJavaPlugin.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/BaseJavaPlugin.java rename to commons/src/main/java/me/filoghost/commons/BaseJavaPlugin.java diff --git a/Commons/src/main/java/me/filoghost/commons/Colors.java b/commons/src/main/java/me/filoghost/commons/Colors.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/Colors.java rename to commons/src/main/java/me/filoghost/commons/Colors.java diff --git a/Commons/src/main/java/me/filoghost/commons/CommonsUtil.java b/commons/src/main/java/me/filoghost/commons/CommonsUtil.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/CommonsUtil.java rename to commons/src/main/java/me/filoghost/commons/CommonsUtil.java diff --git a/Commons/src/main/java/me/filoghost/commons/MaterialsHelper.java b/commons/src/main/java/me/filoghost/commons/MaterialsHelper.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/MaterialsHelper.java rename to commons/src/main/java/me/filoghost/commons/MaterialsHelper.java diff --git a/Commons/src/main/java/me/filoghost/commons/Preconditions.java b/commons/src/main/java/me/filoghost/commons/Preconditions.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/Preconditions.java rename to commons/src/main/java/me/filoghost/commons/Preconditions.java diff --git a/Commons/src/main/java/me/filoghost/commons/Strings.java b/commons/src/main/java/me/filoghost/commons/Strings.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/Strings.java rename to commons/src/main/java/me/filoghost/commons/Strings.java diff --git a/Commons/src/main/java/me/filoghost/commons/collection/CaseInsensitiveMap.java b/commons/src/main/java/me/filoghost/commons/collection/CaseInsensitiveMap.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/collection/CaseInsensitiveMap.java rename to commons/src/main/java/me/filoghost/commons/collection/CaseInsensitiveMap.java diff --git a/Commons/src/main/java/me/filoghost/commons/collection/CollectionUtils.java b/commons/src/main/java/me/filoghost/commons/collection/CollectionUtils.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/collection/CollectionUtils.java rename to commons/src/main/java/me/filoghost/commons/collection/CollectionUtils.java diff --git a/Commons/src/main/java/me/filoghost/commons/collection/Registry.java b/commons/src/main/java/me/filoghost/commons/collection/Registry.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/collection/Registry.java rename to commons/src/main/java/me/filoghost/commons/collection/Registry.java diff --git a/Commons/src/main/java/me/filoghost/commons/command/CommandException.java b/commons/src/main/java/me/filoghost/commons/command/CommandException.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/command/CommandException.java rename to commons/src/main/java/me/filoghost/commons/command/CommandException.java diff --git a/Commons/src/main/java/me/filoghost/commons/command/CommandFramework.java b/commons/src/main/java/me/filoghost/commons/command/CommandFramework.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/command/CommandFramework.java rename to commons/src/main/java/me/filoghost/commons/command/CommandFramework.java diff --git a/Commons/src/main/java/me/filoghost/commons/command/CommandValidate.java b/commons/src/main/java/me/filoghost/commons/command/CommandValidate.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/command/CommandValidate.java rename to commons/src/main/java/me/filoghost/commons/command/CommandValidate.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/BaseConfigManager.java b/commons/src/main/java/me/filoghost/commons/config/BaseConfigManager.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/BaseConfigManager.java rename to commons/src/main/java/me/filoghost/commons/config/BaseConfigManager.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/Config.java b/commons/src/main/java/me/filoghost/commons/config/Config.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/Config.java rename to commons/src/main/java/me/filoghost/commons/config/Config.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/ConfigErrors.java b/commons/src/main/java/me/filoghost/commons/config/ConfigErrors.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/ConfigErrors.java rename to commons/src/main/java/me/filoghost/commons/config/ConfigErrors.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/ConfigLoader.java b/commons/src/main/java/me/filoghost/commons/config/ConfigLoader.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/ConfigLoader.java rename to commons/src/main/java/me/filoghost/commons/config/ConfigLoader.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/ConfigPath.java b/commons/src/main/java/me/filoghost/commons/config/ConfigPath.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/ConfigPath.java rename to commons/src/main/java/me/filoghost/commons/config/ConfigPath.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/ConfigSection.java b/commons/src/main/java/me/filoghost/commons/config/ConfigSection.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/ConfigSection.java rename to commons/src/main/java/me/filoghost/commons/config/ConfigSection.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/ConfigValue.java b/commons/src/main/java/me/filoghost/commons/config/ConfigValue.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/ConfigValue.java rename to commons/src/main/java/me/filoghost/commons/config/ConfigValue.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/ConfigValueType.java b/commons/src/main/java/me/filoghost/commons/config/ConfigValueType.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/ConfigValueType.java rename to commons/src/main/java/me/filoghost/commons/config/ConfigValueType.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/EmptyConfigSection.java b/commons/src/main/java/me/filoghost/commons/config/EmptyConfigSection.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/EmptyConfigSection.java rename to commons/src/main/java/me/filoghost/commons/config/EmptyConfigSection.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigException.java b/commons/src/main/java/me/filoghost/commons/config/exception/ConfigException.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/exception/ConfigException.java rename to commons/src/main/java/me/filoghost/commons/config/exception/ConfigException.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigLoadException.java b/commons/src/main/java/me/filoghost/commons/config/exception/ConfigLoadException.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/exception/ConfigLoadException.java rename to commons/src/main/java/me/filoghost/commons/config/exception/ConfigLoadException.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSaveException.java b/commons/src/main/java/me/filoghost/commons/config/exception/ConfigSaveException.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSaveException.java rename to commons/src/main/java/me/filoghost/commons/config/exception/ConfigSaveException.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSyntaxException.java b/commons/src/main/java/me/filoghost/commons/config/exception/ConfigSyntaxException.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/exception/ConfigSyntaxException.java rename to commons/src/main/java/me/filoghost/commons/config/exception/ConfigSyntaxException.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/exception/ConfigValueException.java b/commons/src/main/java/me/filoghost/commons/config/exception/ConfigValueException.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/exception/ConfigValueException.java rename to commons/src/main/java/me/filoghost/commons/config/exception/ConfigValueException.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/exception/ConverterCastException.java b/commons/src/main/java/me/filoghost/commons/config/exception/ConverterCastException.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/exception/ConverterCastException.java rename to commons/src/main/java/me/filoghost/commons/config/exception/ConverterCastException.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/exception/InvalidConfigValueException.java b/commons/src/main/java/me/filoghost/commons/config/exception/InvalidConfigValueException.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/exception/InvalidConfigValueException.java rename to commons/src/main/java/me/filoghost/commons/config/exception/InvalidConfigValueException.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/exception/MissingConfigValueException.java b/commons/src/main/java/me/filoghost/commons/config/exception/MissingConfigValueException.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/exception/MissingConfigValueException.java rename to commons/src/main/java/me/filoghost/commons/config/exception/MissingConfigValueException.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/ConfigMapper.java b/commons/src/main/java/me/filoghost/commons/config/mapped/ConfigMapper.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/mapped/ConfigMapper.java rename to commons/src/main/java/me/filoghost/commons/config/mapped/ConfigMapper.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/IncludeStatic.java b/commons/src/main/java/me/filoghost/commons/config/mapped/IncludeStatic.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/mapped/IncludeStatic.java rename to commons/src/main/java/me/filoghost/commons/config/mapped/IncludeStatic.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfig.java b/commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfig.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfig.java rename to commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfig.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfigLoader.java b/commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfigLoader.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfigLoader.java rename to commons/src/main/java/me/filoghost/commons/config/mapped/MappedConfigLoader.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/MappedField.java b/commons/src/main/java/me/filoghost/commons/config/mapped/MappedField.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/mapped/MappedField.java rename to commons/src/main/java/me/filoghost/commons/config/mapped/MappedField.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/BooleanConverter.java b/commons/src/main/java/me/filoghost/commons/config/mapped/converter/BooleanConverter.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/mapped/converter/BooleanConverter.java rename to commons/src/main/java/me/filoghost/commons/config/mapped/converter/BooleanConverter.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/Converter.java b/commons/src/main/java/me/filoghost/commons/config/mapped/converter/Converter.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/mapped/converter/Converter.java rename to commons/src/main/java/me/filoghost/commons/config/mapped/converter/Converter.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/DoubleConverter.java b/commons/src/main/java/me/filoghost/commons/config/mapped/converter/DoubleConverter.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/mapped/converter/DoubleConverter.java rename to commons/src/main/java/me/filoghost/commons/config/mapped/converter/DoubleConverter.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/IntegerConverter.java b/commons/src/main/java/me/filoghost/commons/config/mapped/converter/IntegerConverter.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/mapped/converter/IntegerConverter.java rename to commons/src/main/java/me/filoghost/commons/config/mapped/converter/IntegerConverter.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/ListConverter.java b/commons/src/main/java/me/filoghost/commons/config/mapped/converter/ListConverter.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/mapped/converter/ListConverter.java rename to commons/src/main/java/me/filoghost/commons/config/mapped/converter/ListConverter.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/converter/StringConverter.java b/commons/src/main/java/me/filoghost/commons/config/mapped/converter/StringConverter.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/mapped/converter/StringConverter.java rename to commons/src/main/java/me/filoghost/commons/config/mapped/converter/StringConverter.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColors.java b/commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColors.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColors.java rename to commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColors.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColorsModifier.java b/commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColorsModifier.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColorsModifier.java rename to commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ChatColorsModifier.java diff --git a/Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ValueModifier.java b/commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ValueModifier.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ValueModifier.java rename to commons/src/main/java/me/filoghost/commons/config/mapped/modifier/ValueModifier.java diff --git a/Commons/src/main/java/me/filoghost/commons/logging/ErrorCollector.java b/commons/src/main/java/me/filoghost/commons/logging/ErrorCollector.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/logging/ErrorCollector.java rename to commons/src/main/java/me/filoghost/commons/logging/ErrorCollector.java diff --git a/Commons/src/main/java/me/filoghost/commons/logging/ErrorLog.java b/commons/src/main/java/me/filoghost/commons/logging/ErrorLog.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/logging/ErrorLog.java rename to commons/src/main/java/me/filoghost/commons/logging/ErrorLog.java diff --git a/Commons/src/main/java/me/filoghost/commons/logging/Log.java b/commons/src/main/java/me/filoghost/commons/logging/Log.java similarity index 100% rename from Commons/src/main/java/me/filoghost/commons/logging/Log.java rename to commons/src/main/java/me/filoghost/commons/logging/Log.java diff --git a/Plugin/pom.xml b/plugin/pom.xml similarity index 100% rename from Plugin/pom.xml rename to plugin/pom.xml diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java rename to plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java b/plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java rename to plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java b/plugin/src/main/java/me/filoghost/chestcommands/Permissions.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/Permissions.java rename to plugin/src/main/java/me/filoghost/chestcommands/Permissions.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java b/plugin/src/main/java/me/filoghost/chestcommands/action/Action.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/action/Action.java rename to plugin/src/main/java/me/filoghost/chestcommands/action/Action.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java b/plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java rename to plugin/src/main/java/me/filoghost/chestcommands/action/BroadcastAction.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java b/plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java rename to plugin/src/main/java/me/filoghost/chestcommands/action/ChangeServerAction.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java b/plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java rename to plugin/src/main/java/me/filoghost/chestcommands/action/ConsoleCommandAction.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/DisabledAction.java b/plugin/src/main/java/me/filoghost/chestcommands/action/DisabledAction.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/action/DisabledAction.java rename to plugin/src/main/java/me/filoghost/chestcommands/action/DisabledAction.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java b/plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java rename to plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java b/plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java rename to plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java b/plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java rename to plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java b/plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java rename to plugin/src/main/java/me/filoghost/chestcommands/action/OpCommandAction.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java b/plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java rename to plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java b/plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java rename to plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java b/plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java rename to plugin/src/main/java/me/filoghost/chestcommands/action/PlayerCommandAction.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java b/plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java rename to plugin/src/main/java/me/filoghost/chestcommands/action/SendMessageAction.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ActionsAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/ActionsAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/ActionsAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/ActionsAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/AmountAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/AmountAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/AmountAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/AmountAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/AttributeErrorHandler.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/AttributeErrorHandler.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/AttributeErrorHandler.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/AttributeErrorHandler.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerColorAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerColorAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerColorAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerColorAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerPatternsAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerPatternsAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerPatternsAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/BannerPatternsAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionMessageAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionMessageAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionMessageAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/ClickPermissionMessageAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/DurabilityAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/DurabilityAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/DurabilityAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/DurabilityAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/EnchantmentsAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/EnchantmentsAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/EnchantmentsAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/EnchantmentsAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ExpLevelsAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/ExpLevelsAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/ExpLevelsAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/ExpLevelsAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/IconAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/IconAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/IconAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/IconAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/KeepOpenAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/KeepOpenAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/KeepOpenAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/KeepOpenAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LeatherColorAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/LeatherColorAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/LeatherColorAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/LeatherColorAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/MaterialAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NBTDataAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/NBTDataAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/NBTDataAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/NBTDataAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/PositionAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/PositionAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/PositionAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/PositionAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/PriceAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/PriceAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/PriceAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/PriceAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/RequiredItemsAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/RequiredItemsAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/RequiredItemsAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/RequiredItemsAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/SkullOwnerAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/SkullOwnerAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/SkullOwnerAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/SkullOwnerAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/attribute/ViewPermissionAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/ViewPermissionAttribute.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/attribute/ViewPermissionAttribute.java rename to plugin/src/main/java/me/filoghost/chestcommands/attribute/ViewPermissionAttribute.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java rename to plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java b/plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java rename to plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java b/plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java rename to plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java b/plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java rename to plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java b/plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java rename to plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java b/plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java rename to plugin/src/main/java/me/filoghost/chestcommands/hook/BarAPIHook.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java b/plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java rename to plugin/src/main/java/me/filoghost/chestcommands/hook/BungeeCordHook.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java b/plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java rename to plugin/src/main/java/me/filoghost/chestcommands/hook/PlaceholderAPIHook.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java b/plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java rename to plugin/src/main/java/me/filoghost/chestcommands/hook/PluginHook.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java b/plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java rename to plugin/src/main/java/me/filoghost/chestcommands/hook/VaultEconomyHook.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIConfigurableIcon.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/APIConfigurableIcon.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/icon/APIConfigurableIcon.java rename to plugin/src/main/java/me/filoghost/chestcommands/icon/APIConfigurableIcon.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java rename to plugin/src/main/java/me/filoghost/chestcommands/icon/APIStaticIcon.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java rename to plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java rename to plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/RefreshableIcon.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/RefreshableIcon.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/icon/RefreshableIcon.java rename to plugin/src/main/java/me/filoghost/chestcommands/icon/RefreshableIcon.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java rename to plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java rename to plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java rename to plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/Requirement.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/Requirement.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/Requirement.java rename to plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/Requirement.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java rename to plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/InventoryTakeHelper.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RemainingItem.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RemainingItem.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RemainingItem.java rename to plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RemainingItem.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java rename to plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItem.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java rename to plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/ArrayGrid.java b/plugin/src/main/java/me/filoghost/chestcommands/inventory/ArrayGrid.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/inventory/ArrayGrid.java rename to plugin/src/main/java/me/filoghost/chestcommands/inventory/ArrayGrid.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java b/plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java rename to plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/Grid.java b/plugin/src/main/java/me/filoghost/chestcommands/inventory/Grid.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/inventory/Grid.java rename to plugin/src/main/java/me/filoghost/chestcommands/inventory/Grid.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java b/plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java rename to plugin/src/main/java/me/filoghost/chestcommands/inventory/InventoryGrid.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java b/plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java rename to plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeExecutorException.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeExecutorException.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeExecutorException.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeExecutorException.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesDoneRegistry.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexReplacer.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexReplacer.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexReplacer.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexReplacer.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/RegexUpgradeTask.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/Upgrade.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTaskException.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTaskException.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTaskException.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTaskException.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_LangUpgradeTask.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_LangUpgradeTask.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_LangUpgradeTask.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_LangUpgradeTask.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeRenameUpgradeTask.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeRenameUpgradeTask.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeRenameUpgradeTask.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeRenameUpgradeTask.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_SettingsUpgradeTask.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java b/plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java rename to plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java rename to plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java b/plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java rename to plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java b/plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java rename to plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java b/plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java rename to plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorPrintInfo.java b/plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorPrintInfo.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorPrintInfo.java rename to plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorPrintInfo.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java b/plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java rename to plugin/src/main/java/me/filoghost/chestcommands/logging/MessagePartJoiner.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java b/plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java rename to plugin/src/main/java/me/filoghost/chestcommands/logging/PrintableErrorCollector.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java b/plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java rename to plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java b/plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java rename to plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java b/plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java rename to plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java b/plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java rename to plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java rename to plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java rename to plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java rename to plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java rename to plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/MaterialParser.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/MaterialParser.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/MaterialParser.java rename to plugin/src/main/java/me/filoghost/chestcommands/parsing/MaterialParser.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java rename to plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/ParseException.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/ParseException.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/ParseException.java rename to plugin/src/main/java/me/filoghost/chestcommands/parsing/ParseException.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java rename to plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/AttributeType.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java rename to plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/ClickType.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/ClickType.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/ClickType.java rename to plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/ClickType.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java rename to plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java rename to plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuOpenItem.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java rename to plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java rename to plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettingsNode.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettingsNode.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettingsNode.java rename to plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettingsNode.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholder.java b/plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholder.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholder.java rename to plugin/src/main/java/me/filoghost/chestcommands/placeholder/DefaultPlaceholder.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderCache.java b/plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderCache.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderCache.java rename to plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderCache.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java b/plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java rename to plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderRegistry.java b/plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderRegistry.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderRegistry.java rename to plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderRegistry.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderString.java b/plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderString.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderString.java rename to plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderString.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java b/plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java rename to plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderStringList.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/StaticPlaceholder.java b/plugin/src/main/java/me/filoghost/chestcommands/placeholder/StaticPlaceholder.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/placeholder/StaticPlaceholder.java rename to plugin/src/main/java/me/filoghost/chestcommands/placeholder/StaticPlaceholder.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java b/plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java rename to plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderMatch.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java b/plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java rename to plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java b/plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java rename to plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java b/plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java rename to plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java b/plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java rename to plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByte.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java b/plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java rename to plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTByteArray.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java b/plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java rename to plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTCompound.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java b/plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java rename to plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTDouble.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java b/plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java rename to plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTFloat.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java b/plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java rename to plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTInt.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java b/plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java rename to plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTIntArray.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java b/plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java rename to plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTList.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java b/plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java rename to plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLong.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java b/plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java rename to plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTLongArray.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java b/plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java rename to plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTShort.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java b/plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java rename to plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTString.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java b/plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java rename to plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTTag.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java b/plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java rename to plugin/src/main/java/me/filoghost/chestcommands/util/nbt/NBTType.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java b/plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java rename to plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParseException.java diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java b/plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java similarity index 100% rename from Plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java rename to plugin/src/main/java/me/filoghost/chestcommands/util/nbt/parser/MojangsonParser.java diff --git a/Plugin/src/main/resources/custom-placeholders.yml b/plugin/src/main/resources/custom-placeholders.yml similarity index 100% rename from Plugin/src/main/resources/custom-placeholders.yml rename to plugin/src/main/resources/custom-placeholders.yml diff --git a/Plugin/src/main/resources/menu/example.yml b/plugin/src/main/resources/menu/example.yml similarity index 100% rename from Plugin/src/main/resources/menu/example.yml rename to plugin/src/main/resources/menu/example.yml diff --git a/Plugin/src/main/resources/plugin.yml b/plugin/src/main/resources/plugin.yml similarity index 100% rename from Plugin/src/main/resources/plugin.yml rename to plugin/src/main/resources/plugin.yml diff --git a/pom.xml b/pom.xml index 6abb06e..dd98cef 100644 --- a/pom.xml +++ b/pom.xml @@ -33,9 +33,9 @@ - API - Plugin - Commons + commons + api + plugin From de5dd3b3ef88f2d6ea4024794f0a3b632e8b19fb Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 14 Aug 2020 17:54:27 +0200 Subject: [PATCH 194/213] Rename class --- .../chestcommands/ChestCommands.java | 10 +++---- .../chestcommands/action/DragonBarAction.java | 6 ++--- .../chestcommands/action/GiveMoneyAction.java | 4 +-- .../chestcommands/action/OpenMenuAction.java | 4 +-- .../chestcommands/action/PlaySoundAction.java | 8 +++--- .../attribute/ActionsAttribute.java | 4 +-- .../attribute/AmountAttribute.java | 4 +-- .../attribute/ExpLevelsAttribute.java | 4 +-- .../attribute/PriceAttribute.java | 4 +-- .../chestcommands/config/ConfigManager.java | 6 ++--- .../config/CustomPlaceholders.java | 6 ++--- .../filoghost/chestcommands/config/Lang.java | 4 +-- .../icon/requirement/RequiredMoney.java | 6 ++--- .../chestcommands/legacy/UpgradeList.java | 4 +-- .../legacy/UpgradesExecutor.java | 10 +++---- .../legacy/upgrade/UpgradeTask.java | 8 +++--- .../{ErrorMessages.java => Errors.java} | 4 +-- .../chestcommands/menu/MenuManager.java | 6 ++--- .../parsing/EnchantmentParser.java | 6 ++--- .../chestcommands/parsing/ItemMetaParser.java | 14 +++++----- .../parsing/ItemStackParser.java | 8 +++--- .../chestcommands/parsing/MaterialParser.java | 4 +-- .../chestcommands/parsing/NumberParser.java | 16 ++++++------ .../parsing/icon/IconSettings.java | 8 +++--- .../parsing/menu/MenuParser.java | 26 +++++++++---------- 25 files changed, 92 insertions(+), 92 deletions(-) rename plugin/src/main/java/me/filoghost/chestcommands/logging/{ErrorMessages.java => Errors.java} (99%) diff --git a/plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index a64d1b9..002c5bd 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -21,7 +21,7 @@ import me.filoghost.chestcommands.listener.CommandListener; import me.filoghost.chestcommands.listener.InventoryListener; import me.filoghost.chestcommands.listener.JoinListener; import me.filoghost.chestcommands.listener.SignListener; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.chestcommands.logging.PrintableErrorCollector; import me.filoghost.chestcommands.menu.MenuManager; import me.filoghost.chestcommands.parsing.menu.LoadedMenu; @@ -156,7 +156,7 @@ public class ChestCommands extends BaseJavaPlugin { try { Files.createDirectories(configManager.getRootDataFolder()); } catch (IOException e) { - errorCollector.add(e, ErrorMessages.Config.createDataFolderIOException); + errorCollector.add(e, Errors.Config.createDataFolderIOException); return errorCollector; } @@ -165,11 +165,11 @@ public class ChestCommands extends BaseJavaPlugin { try { boolean allUpgradesSuccessful = upgradeExecutor.run(isFreshInstall, errorCollector); if (!allUpgradesSuccessful) { - errorCollector.add(ErrorMessages.Upgrade.failedSomeUpgrades); + errorCollector.add(Errors.Upgrade.failedSomeUpgrades); } } catch (UpgradeExecutorException e) { - errorCollector.add(e, ErrorMessages.Upgrade.genericExecutorError); - errorCollector.add(ErrorMessages.Upgrade.failedSomeUpgrades); + errorCollector.add(e, Errors.Upgrade.genericExecutorError); + errorCollector.add(Errors.Upgrade.failedSomeUpgrades); } settings = configManager.tryLoadSettings(errorCollector); diff --git a/plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java b/plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java index 772a50a..9af3a0a 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java @@ -6,7 +6,7 @@ package me.filoghost.chestcommands.action; import me.filoghost.chestcommands.hook.BarAPIHook; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.chestcommands.parsing.NumberParser; import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.chestcommands.placeholder.PlaceholderString; @@ -28,7 +28,7 @@ public class DragonBarAction implements Action { seconds = NumberParser.getStrictlyPositiveInteger(split[0]); message = split[1]; } catch (ParseException e) { - throw new ParseException(ErrorMessages.Parsing.invalidBossBarTime(split[0]), e); + throw new ParseException(Errors.Parsing.invalidBossBarTime(split[0]), e); } } else { seconds = 1; @@ -43,7 +43,7 @@ public class DragonBarAction implements Action { if (BarAPIHook.INSTANCE.isEnabled()) { BarAPIHook.setMessage(player, message.getValue(player), seconds); } else { - player.sendMessage(ErrorMessages.User.configurationError("BarAPI plugin not found")); + player.sendMessage(Errors.User.configurationError("BarAPI plugin not found")); } } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java b/plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java index 5781d94..c53e7c7 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java @@ -6,7 +6,7 @@ package me.filoghost.chestcommands.action; import me.filoghost.chestcommands.hook.VaultEconomyHook; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.chestcommands.parsing.NumberParser; import me.filoghost.chestcommands.parsing.ParseException; import org.bukkit.entity.Player; @@ -24,7 +24,7 @@ public class GiveMoneyAction implements Action { if (VaultEconomyHook.INSTANCE.isEnabled()) { VaultEconomyHook.giveMoney(player, moneyToGive); } else { - player.sendMessage(ErrorMessages.User.configurationError("Vault with a compatible economy plugin not found")); + player.sendMessage(Errors.User.configurationError("Vault with a compatible economy plugin not found")); } } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java b/plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java index 47ea3d8..effd8b0 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java @@ -6,7 +6,7 @@ package me.filoghost.chestcommands.action; import me.filoghost.chestcommands.ChestCommands; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.chestcommands.menu.InternalIconMenu; import me.filoghost.chestcommands.placeholder.PlaceholderString; import org.bukkit.Bukkit; @@ -35,7 +35,7 @@ public class OpenMenuAction implements Action { }); } else { - player.sendMessage(ErrorMessages.User.configurationError("couldn't find the menu \"" + menuName + "\"")); + player.sendMessage(Errors.User.configurationError("couldn't find the menu \"" + menuName + "\"")); } } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java b/plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java index 773cbf8..e11466e 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/action/PlaySoundAction.java @@ -5,7 +5,7 @@ */ package me.filoghost.chestcommands.action; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.chestcommands.parsing.NumberParser; import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.commons.Strings; @@ -28,7 +28,7 @@ public class PlaySoundAction implements Action { Optional sound = SOUNDS_REGISTRY.find(split[0]); if (!sound.isPresent()) { - throw new ParseException(ErrorMessages.Parsing.unknownSound(split[0])); + throw new ParseException(Errors.Parsing.unknownSound(split[0])); } this.sound = sound.get(); @@ -36,7 +36,7 @@ public class PlaySoundAction implements Action { try { pitch = NumberParser.getFloat(split[1]); } catch (ParseException e) { - throw new ParseException(ErrorMessages.Parsing.invalidSoundPitch(split[1]), e); + throw new ParseException(Errors.Parsing.invalidSoundPitch(split[1]), e); } } else { pitch = 1.0f; @@ -46,7 +46,7 @@ public class PlaySoundAction implements Action { try { volume = NumberParser.getFloat(split[2]); } catch (ParseException e) { - throw new ParseException(ErrorMessages.Parsing.invalidSoundVolume(split[2]), e); + throw new ParseException(Errors.Parsing.invalidSoundVolume(split[2]), e); } } else { volume = 1.0f; diff --git a/plugin/src/main/java/me/filoghost/chestcommands/attribute/ActionsAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/ActionsAttribute.java index 29413b1..3297af5 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/attribute/ActionsAttribute.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/attribute/ActionsAttribute.java @@ -8,7 +8,7 @@ package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.DisabledAction; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.chestcommands.parsing.ActionParser; import me.filoghost.chestcommands.parsing.ParseException; @@ -30,7 +30,7 @@ public class ActionsAttribute implements IconAttribute { try { actions.add(ActionParser.parse(serializedAction)); } catch (ParseException e) { - actions.add(new DisabledAction(ErrorMessages.User.configurationError( + actions.add(new DisabledAction(Errors.User.configurationError( "an action linked to clicking this icon was not executed because it was not valid"))); errorHandler.onListElementError(serializedAction, e); } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/attribute/AmountAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/AmountAttribute.java index 871a61c..7879b9e 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/attribute/AmountAttribute.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/attribute/AmountAttribute.java @@ -6,7 +6,7 @@ package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.chestcommands.parsing.ParseException; public class AmountAttribute implements IconAttribute { @@ -15,7 +15,7 @@ public class AmountAttribute implements IconAttribute { public AmountAttribute(int amount, AttributeErrorHandler errorHandler) throws ParseException { if (amount < 0) { - throw new ParseException(ErrorMessages.Parsing.zeroOrPositive); + throw new ParseException(Errors.Parsing.zeroOrPositive); } this.amount = amount; } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/attribute/ExpLevelsAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/ExpLevelsAttribute.java index c47c9cb..c7fe465 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/attribute/ExpLevelsAttribute.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/attribute/ExpLevelsAttribute.java @@ -6,7 +6,7 @@ package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.chestcommands.parsing.ParseException; public class ExpLevelsAttribute implements IconAttribute { @@ -15,7 +15,7 @@ public class ExpLevelsAttribute implements IconAttribute { public ExpLevelsAttribute(int expLevels, AttributeErrorHandler errorHandler) throws ParseException { if (expLevels < 0) { - throw new ParseException(ErrorMessages.Parsing.zeroOrPositive); + throw new ParseException(Errors.Parsing.zeroOrPositive); } this.expLevels = expLevels; } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/attribute/PriceAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/PriceAttribute.java index 38d9c8e..17b0e86 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/attribute/PriceAttribute.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/attribute/PriceAttribute.java @@ -6,7 +6,7 @@ package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.chestcommands.parsing.ParseException; public class PriceAttribute implements IconAttribute { @@ -15,7 +15,7 @@ public class PriceAttribute implements IconAttribute { public PriceAttribute(double price, AttributeErrorHandler errorHandler) throws ParseException { if (price < 0) { - throw new ParseException(ErrorMessages.Parsing.zeroOrPositive); + throw new ParseException(Errors.Parsing.zeroOrPositive); } this.price = price; } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java b/plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java index 3263972..54b5fa0 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java @@ -5,7 +5,7 @@ */ package me.filoghost.chestcommands.config; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.chestcommands.parsing.menu.LoadedMenu; import me.filoghost.chestcommands.parsing.menu.MenuParser; import me.filoghost.commons.Preconditions; @@ -92,7 +92,7 @@ public class ConfigManager extends BaseConfigManager { } private void logConfigInitException(ErrorCollector errorCollector, Path file, ConfigException e) { - errorCollector.add(e, ErrorMessages.Config.initException(file)); + errorCollector.add(e, Errors.Config.initException(file)); } public List tryLoadMenus(ErrorCollector errorCollector) { @@ -102,7 +102,7 @@ public class ConfigManager extends BaseConfigManager { try { menuFiles = getMenuFiles(); } catch (IOException e) { - errorCollector.add(e, ErrorMessages.Config.menuListIOException(getMenusFolder())); + errorCollector.add(e, Errors.Config.menuListIOException(getMenusFolder())); return Collections.emptyList(); } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java b/plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java index 505b25f..5c87e1f 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/config/CustomPlaceholders.java @@ -5,7 +5,7 @@ */ package me.filoghost.chestcommands.config; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.chestcommands.placeholder.StaticPlaceholder; import me.filoghost.commons.Colors; import me.filoghost.commons.config.Config; @@ -34,12 +34,12 @@ public class CustomPlaceholders { } if (placeholder.length() == 0) { - errorCollector.add(ErrorMessages.Config.emptyPlaceholder(config.getSourceFile())); + errorCollector.add(Errors.Config.emptyPlaceholder(config.getSourceFile())); continue; } if (placeholder.length() > 100) { - errorCollector.add(ErrorMessages.Config.tooLongPlaceholder(config.getSourceFile(), placeholder)); + errorCollector.add(Errors.Config.tooLongPlaceholder(config.getSourceFile(), placeholder)); continue; } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java b/plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java index d549b88..87b164b 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java @@ -5,7 +5,7 @@ */ package me.filoghost.chestcommands.config; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.commons.config.mapped.MappedConfig; import me.filoghost.commons.config.mapped.modifier.ChatColors; @@ -17,7 +17,7 @@ public class Lang extends MappedConfig { public String no_required_item = "&cYou must have &e{amount}x {material} &c(durability: {durability}) for this."; public String no_money = "&cYou need {money}$ for this."; public String no_exp = "&cYou need {levels} XP levels for this."; - public String menu_not_found = "&cMenu not found! " + ErrorMessages.User.notifyStaffRequest; + public String menu_not_found = "&cMenu not found! " + Errors.User.notifyStaffRequest; public String open_menu = "&aOpening the menu \"{menu}\"."; public String open_menu_others = "&aOpening the menu \"{menu}\" to {player}."; public String any = "any"; // Used in no_required_item when durability is not restrictive diff --git a/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java index 383fc27..21c911b 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java @@ -8,7 +8,7 @@ package me.filoghost.chestcommands.icon.requirement; import com.google.common.base.Preconditions; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.hook.VaultEconomyHook; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import org.bukkit.entity.Player; public class RequiredMoney implements Requirement { @@ -23,7 +23,7 @@ public class RequiredMoney implements Requirement { @Override public boolean hasCost(Player player) { if (!VaultEconomyHook.INSTANCE.isEnabled()) { - player.sendMessage(ErrorMessages.User.configurationError( + player.sendMessage(Errors.User.configurationError( "the item has a price, but Vault with a compatible economy plugin was not found. " + "For security, the action has been blocked")); return false; @@ -42,7 +42,7 @@ public class RequiredMoney implements Requirement { boolean success = VaultEconomyHook.takeMoney(player, moneyAmount); if (!success) { - player.sendMessage(ErrorMessages.User.configurationError("a money transaction couldn't be executed")); + player.sendMessage(Errors.User.configurationError("a money transaction couldn't be executed")); } return success; diff --git a/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java index aa475bc..e1d4649 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java @@ -15,7 +15,7 @@ import me.filoghost.chestcommands.legacy.v4_0.v4_0_MenuNodeExpandUpgradeTask; import me.filoghost.chestcommands.legacy.v4_0.v4_0_MenuNodeRenameUpgradeTask; import me.filoghost.chestcommands.legacy.v4_0.v4_0_PlaceholdersFileUpgradeTask; import me.filoghost.chestcommands.legacy.v4_0.v4_0_SettingsUpgradeTask; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.commons.collection.CollectionUtils; import me.filoghost.commons.config.ConfigLoader; import me.filoghost.commons.logging.Log; @@ -68,7 +68,7 @@ public class UpgradeList { try { return configManager.getMenuFiles(); } catch (IOException e) { - throw new UpgradeTaskException(ErrorMessages.Upgrade.menuListIOException, e); + throw new UpgradeTaskException(Errors.Upgrade.menuListIOException, e); } } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java index 3fc295d..88da099 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradesExecutor.java @@ -9,7 +9,7 @@ import me.filoghost.chestcommands.config.ConfigManager; import me.filoghost.chestcommands.legacy.upgrade.Upgrade; import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask; import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.commons.logging.ErrorCollector; import me.filoghost.commons.logging.Log; @@ -35,7 +35,7 @@ public class UpgradesExecutor { upgradesDoneRegistry = new UpgradesDoneRegistry(upgradesDoneFile); } catch (IOException e) { // Upgrades can't proceed if metadata file is not read correctly - throw new UpgradeExecutorException(ErrorMessages.Upgrade.metadataReadError(upgradesDoneFile), e); + throw new UpgradeExecutorException(Errors.Upgrade.metadataReadError(upgradesDoneFile), e); } if (isFreshInstall) { @@ -51,7 +51,7 @@ public class UpgradesExecutor { upgradesDoneRegistry.save(); } catch (IOException e) { // Upgrades can't proceed if metadata file is not saved correctly - throw new UpgradeExecutorException(ErrorMessages.Upgrade.metadataSaveError(upgradesDoneFile), e); + throw new UpgradeExecutorException(Errors.Upgrade.metadataSaveError(upgradesDoneFile), e); } return allUpgradesSuccessful; @@ -81,7 +81,7 @@ public class UpgradesExecutor { try { upgradeTasks = upgrade.createUpgradeTasks(configManager); } catch (UpgradeTaskException e) { - errorCollector.add(e, ErrorMessages.Upgrade.failedToPrepareUpgradeTasks); + errorCollector.add(e, Errors.Upgrade.failedToPrepareUpgradeTasks); return false; } @@ -94,7 +94,7 @@ public class UpgradesExecutor { } } catch (UpgradeTaskException e) { allTasksSuccessful = false; - errorCollector.add(e, ErrorMessages.Upgrade.failedSingleUpgrade(upgradeTask.getOriginalFile())); + errorCollector.add(e, Errors.Upgrade.failedSingleUpgrade(upgradeTask.getOriginalFile())); } } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java index b7ddd04..4b9c2ae 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/UpgradeTask.java @@ -6,7 +6,7 @@ package me.filoghost.chestcommands.legacy.upgrade; import me.filoghost.chestcommands.legacy.Backup; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.commons.Preconditions; import me.filoghost.commons.config.exception.ConfigLoadException; import me.filoghost.commons.config.exception.ConfigSaveException; @@ -30,20 +30,20 @@ public abstract class UpgradeTask { try { computeChanges(); } catch (ConfigLoadException e) { - throw new UpgradeTaskException(ErrorMessages.Upgrade.loadError(getOriginalFile()), e); + throw new UpgradeTaskException(Errors.Upgrade.loadError(getOriginalFile()), e); } if (saveRequired) { try { backup.addFile(getOriginalFile()); } catch (IOException e) { - throw new UpgradeTaskException(ErrorMessages.Upgrade.backupError(getOriginalFile()), e); + throw new UpgradeTaskException(Errors.Upgrade.backupError(getOriginalFile()), e); } try { saveChanges(); } catch (ConfigSaveException e) { - throw new UpgradeTaskException(ErrorMessages.Upgrade.saveError(getUpgradedFile()), e); + throw new UpgradeTaskException(Errors.Upgrade.saveError(getUpgradedFile()), e); } return true; diff --git a/plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java b/plugin/src/main/java/me/filoghost/chestcommands/logging/Errors.java similarity index 99% rename from plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java rename to plugin/src/main/java/me/filoghost/chestcommands/logging/Errors.java index ace14a2..0d2ff88 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/logging/ErrorMessages.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/logging/Errors.java @@ -12,7 +12,7 @@ import org.bukkit.ChatColor; import java.nio.file.Path; -public class ErrorMessages { +public class Errors { public static class Config { @@ -207,7 +207,7 @@ public class ErrorMessages { public static String notifyStaffRequest = "Please inform the staff."; public static String configurationError(String errorMessage) { - return ChatColor.RED + "Error: " + errorMessage + ". " + ErrorMessages.User.notifyStaffRequest; + return ChatColor.RED + "Error: " + errorMessage + ". " + Errors.User.notifyStaffRequest; } } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java b/plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java index 4a0a964..d59ae5b 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java @@ -7,7 +7,7 @@ package me.filoghost.chestcommands.menu; import me.filoghost.chestcommands.inventory.DefaultMenuInventory; import me.filoghost.chestcommands.inventory.MenuInventoryHolder; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.chestcommands.parsing.menu.LoadedMenu; import me.filoghost.chestcommands.parsing.menu.MenuOpenItem; import me.filoghost.commons.collection.CaseInsensitiveMap; @@ -51,7 +51,7 @@ public class MenuManager { String fileName = loadedMenu.getSourceFile().getFileName().toString(); InternalIconMenu sameNameMenu = menusByFile.get(fileName); if (sameNameMenu != null) { - errorCollector.add(ErrorMessages.Menu.duplicateMenuName(sameNameMenu.getSourceFile(), loadedMenu.getSourceFile())); + errorCollector.add(Errors.Menu.duplicateMenuName(sameNameMenu.getSourceFile(), loadedMenu.getSourceFile())); } menusByFile.put(fileName, menu); @@ -60,7 +60,7 @@ public class MenuManager { if (!openCommand.isEmpty()) { InternalIconMenu sameCommandMenu = menusByOpenCommand.get(openCommand); if (sameCommandMenu != null) { - errorCollector.add(ErrorMessages.Menu.duplicateMenuCommand(sameCommandMenu.getSourceFile(), loadedMenu.getSourceFile(), openCommand)); + errorCollector.add(Errors.Menu.duplicateMenuCommand(sameCommandMenu.getSourceFile(), loadedMenu.getSourceFile(), openCommand)); } menusByOpenCommand.put(openCommand, menu); } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java index 1c1dda8..43765c4 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/parsing/EnchantmentParser.java @@ -5,7 +5,7 @@ */ package me.filoghost.chestcommands.parsing; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.commons.Strings; import me.filoghost.commons.collection.Registry; import org.bukkit.enchantments.Enchantment; @@ -55,7 +55,7 @@ public class EnchantmentParser { try { level = NumberParser.getStrictlyPositiveInteger(levelSplit[1]); } catch (ParseException e) { - throw new ParseException(ErrorMessages.Parsing.invalidEnchantmentLevel(levelSplit[1]), e); + throw new ParseException(Errors.Parsing.invalidEnchantmentLevel(levelSplit[1]), e); } input = levelSplit[0]; } @@ -65,7 +65,7 @@ public class EnchantmentParser { if (enchantment.isPresent()) { return new EnchantmentDetails(enchantment.get(), level); } else { - throw new ParseException(ErrorMessages.Parsing.unknownEnchantmentType(input)); + throw new ParseException(Errors.Parsing.unknownEnchantmentType(input)); } } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java index 55f3ff3..603e20a 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemMetaParser.java @@ -5,7 +5,7 @@ */ package me.filoghost.chestcommands.parsing; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.commons.Strings; import me.filoghost.commons.collection.Registry; import org.bukkit.Color; @@ -25,7 +25,7 @@ public final class ItemMetaParser { String[] split = Strings.trimmedSplit(input, ","); if (split.length != 3) { - throw new ParseException(ErrorMessages.Parsing.invalidColorFormat); + throw new ParseException(Errors.Parsing.invalidColorFormat); } int red = parseColor(split[0], "red"); @@ -41,11 +41,11 @@ public final class ItemMetaParser { try { value = NumberParser.getInteger(valueString); } catch (ParseException e) { - throw new ParseException(ErrorMessages.Parsing.invalidColorNumber(valueString, colorName), e); + throw new ParseException(Errors.Parsing.invalidColorNumber(valueString, colorName), e); } if (value < 0 || value > 255) { - throw new ParseException(ErrorMessages.Parsing.invalidColorRange(valueString, colorName)); + throw new ParseException(Errors.Parsing.invalidColorRange(valueString, colorName)); } return value; @@ -53,17 +53,17 @@ public final class ItemMetaParser { public static DyeColor parseDyeColor(String input) throws ParseException { return DYE_COLORS_REGISTRY.find(input) - .orElseThrow(() -> new ParseException(ErrorMessages.Parsing.unknownDyeColor(input))); + .orElseThrow(() -> new ParseException(Errors.Parsing.unknownDyeColor(input))); } public static Pattern parseBannerPattern(String input) throws ParseException { String[] split = Strings.trimmedSplit(input, ":"); if (split.length != 2) { - throw new ParseException(ErrorMessages.Parsing.invalidPatternFormat); + throw new ParseException(Errors.Parsing.invalidPatternFormat); } PatternType patternType = PATTERN_TYPES_REGISTRY.find(split[0]) - .orElseThrow(() -> new ParseException(ErrorMessages.Parsing.unknownPatternType(split[0]))); + .orElseThrow(() -> new ParseException(Errors.Parsing.unknownPatternType(split[0]))); DyeColor patternColor = parseDyeColor(split[1]); return new Pattern(patternColor, patternType); diff --git a/plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java index d643be8..2729fcc 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/parsing/ItemStackParser.java @@ -5,7 +5,7 @@ */ package me.filoghost.chestcommands.parsing; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.commons.MaterialsHelper; import me.filoghost.commons.Preconditions; import me.filoghost.commons.Strings; @@ -33,7 +33,7 @@ public class ItemStackParser { try { this.amount = NumberParser.getStrictlyPositiveInteger(splitAmount[1]); } catch (ParseException e) { - throw new ParseException(ErrorMessages.Parsing.invalidAmount(splitAmount[1]), e); + throw new ParseException(Errors.Parsing.invalidAmount(splitAmount[1]), e); } // Only keep the first part as input @@ -49,7 +49,7 @@ public class ItemStackParser { try { this.durability = NumberParser.getPositiveShort(splitByColons[1]); } catch (ParseException e) { - throw new ParseException(ErrorMessages.Parsing.invalidDurability(splitByColons[1]), e); + throw new ParseException(Errors.Parsing.invalidDurability(splitByColons[1]), e); } this.hasExplicitDurability = true; @@ -63,7 +63,7 @@ public class ItemStackParser { public void checkNotAir() throws ParseException { if (MaterialsHelper.isAir(material)) { - throw new ParseException(ErrorMessages.Parsing.materialCannotBeAir); + throw new ParseException(Errors.Parsing.materialCannotBeAir); } } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/parsing/MaterialParser.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/MaterialParser.java index 9c9f93d..13900f5 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/parsing/MaterialParser.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/parsing/MaterialParser.java @@ -1,6 +1,6 @@ package me.filoghost.chestcommands.parsing; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.commons.MaterialsHelper; import org.bukkit.Material; @@ -8,7 +8,7 @@ public class MaterialParser { public static Material parseMaterial(String materialName) throws ParseException { return MaterialsHelper.matchMaterial(materialName) - .orElseThrow(() -> new ParseException(ErrorMessages.Parsing.unknownMaterial(materialName))); + .orElseThrow(() -> new ParseException(Errors.Parsing.unknownMaterial(materialName))); } } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java index 4f8bc53..db377b9 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/parsing/NumberParser.java @@ -5,13 +5,13 @@ */ package me.filoghost.chestcommands.parsing; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; public class NumberParser { public static double getStrictlyPositiveDouble(String input) throws ParseException { double value = getDouble(input); - check(value > 0.0, ErrorMessages.Parsing.strictlyPositive); + check(value > 0.0, Errors.Parsing.strictlyPositive); return value; } @@ -19,7 +19,7 @@ public class NumberParser { try { return Double.parseDouble(input); } catch (NumberFormatException ex) { - throw new ParseException(ErrorMessages.Parsing.invalidDecimal); + throw new ParseException(Errors.Parsing.invalidDecimal); } } @@ -27,13 +27,13 @@ public class NumberParser { try { return Float.parseFloat(input); } catch (NumberFormatException ex) { - throw new ParseException(ErrorMessages.Parsing.invalidDecimal); + throw new ParseException(Errors.Parsing.invalidDecimal); } } public static short getPositiveShort(String input) throws ParseException { short value = getShort(input); - check(value >= 0, ErrorMessages.Parsing.zeroOrPositive); + check(value >= 0, Errors.Parsing.zeroOrPositive); return value; } @@ -41,13 +41,13 @@ public class NumberParser { try { return Short.parseShort(input); } catch (NumberFormatException ex) { - throw new ParseException(ErrorMessages.Parsing.invalidShort); + throw new ParseException(Errors.Parsing.invalidShort); } } public static int getStrictlyPositiveInteger(String input) throws ParseException { int value = getInteger(input); - check(value > 0, ErrorMessages.Parsing.strictlyPositive); + check(value > 0, Errors.Parsing.strictlyPositive); return value; } @@ -55,7 +55,7 @@ public class NumberParser { try { return Integer.parseInt(input); } catch (NumberFormatException ex) { - throw new ParseException(ErrorMessages.Parsing.invalidInteger); + throw new ParseException(Errors.Parsing.invalidInteger); } } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java index c43d6df..bebeb88 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/parsing/icon/IconSettings.java @@ -8,7 +8,7 @@ package me.filoghost.chestcommands.parsing.icon; import me.filoghost.chestcommands.attribute.AttributeErrorHandler; import me.filoghost.chestcommands.attribute.IconAttribute; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.chestcommands.parsing.ParseException; import me.filoghost.commons.config.ConfigSection; import me.filoghost.commons.config.ConfigValue; @@ -51,11 +51,11 @@ public class IconSettings { try { AttributeType attributeType = AttributeType.fromAttributeName(attributeName); if (attributeType == null) { - throw new ParseException(ErrorMessages.Parsing.unknownAttribute); + throw new ParseException(Errors.Parsing.unknownAttribute); } AttributeErrorHandler errorHandler = (String listElement, ParseException e) -> { - errorCollector.add(e, ErrorMessages.Menu.invalidAttributeListElement(this, attributeName, listElement)); + errorCollector.add(e, Errors.Menu.invalidAttributeListElement(this, attributeName, listElement)); }; ConfigValue configValue = config.get(attributeName); @@ -63,7 +63,7 @@ public class IconSettings { attributes.put(attributeType, iconAttribute); } catch (ParseException | ConfigValueException e) { - errorCollector.add(e, ErrorMessages.Menu.invalidAttribute(this, attributeName)); + errorCollector.add(e, Errors.Menu.invalidAttribute(this, attributeName)); } } } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index 6357add..f1f9db5 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -8,7 +8,7 @@ package me.filoghost.chestcommands.parsing.menu; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.DisabledAction; import me.filoghost.chestcommands.attribute.PositionAttribute; -import me.filoghost.chestcommands.logging.ErrorMessages; +import me.filoghost.chestcommands.logging.Errors; import me.filoghost.chestcommands.menu.InternalIconMenu; import me.filoghost.chestcommands.parsing.ActionParser; import me.filoghost.chestcommands.parsing.ItemStackParser; @@ -52,12 +52,12 @@ public class MenuParser { PositionAttribute positionY = (PositionAttribute) iconSettings.getAttributeValue(AttributeType.POSITION_Y); if (positionX == null) { - errorCollector.add(ErrorMessages.Menu.missingAttribute(iconSettings, AttributeType.POSITION_X)); + errorCollector.add(Errors.Menu.missingAttribute(iconSettings, AttributeType.POSITION_X)); return; } if (positionY == null) { - errorCollector.add(ErrorMessages.Menu.missingAttribute(iconSettings, AttributeType.POSITION_Y)); + errorCollector.add(Errors.Menu.missingAttribute(iconSettings, AttributeType.POSITION_Y)); return; } @@ -66,23 +66,23 @@ public class MenuParser { if (row < 0 || row >= iconMenu.getRowCount()) { errorCollector.add( - ErrorMessages.Menu.invalidAttribute(iconSettings, AttributeType.POSITION_Y), + Errors.Menu.invalidAttribute(iconSettings, AttributeType.POSITION_Y), "it must be between 1 and " + iconMenu.getRowCount()); return; } if (column < 0 || column >= iconMenu.getColumnCount()) { errorCollector.add( - ErrorMessages.Menu.invalidAttribute(iconSettings, AttributeType.POSITION_X), + Errors.Menu.invalidAttribute(iconSettings, AttributeType.POSITION_X), "it must be between 1 and " + iconMenu.getColumnCount()); return; } if (iconMenu.getIcon(row, column) != null) { - errorCollector.add(ErrorMessages.Menu.iconOverridesAnother(iconSettings)); + errorCollector.add(Errors.Menu.iconOverridesAnother(iconSettings)); } if (iconSettings.getAttributeValue(AttributeType.MATERIAL) == null) { - errorCollector.add(ErrorMessages.Menu.missingAttribute(iconSettings, AttributeType.MATERIAL)); + errorCollector.add(Errors.Menu.missingAttribute(iconSettings, AttributeType.MATERIAL)); } iconMenu.setIcon(row, column, iconSettings.createIcon()); @@ -92,7 +92,7 @@ public class MenuParser { private static MenuSettings loadMenuSettings(Config config, ErrorCollector errorCollector) { ConfigSection settingsSection = config.getConfigSection(MenuSettingsNode.ROOT_SECTION); if (settingsSection == null) { - errorCollector.add(ErrorMessages.Menu.missingSettingsSection(config.getSourceFile())); + errorCollector.add(Errors.Menu.missingSettingsSection(config.getSourceFile())); settingsSection = new EmptyConfigSection(); } @@ -133,9 +133,9 @@ public class MenuParser { try { openActions.add(ActionParser.parse(serializedAction)); } catch (ParseException e) { - errorCollector.add(e, ErrorMessages.Menu.invalidSettingListElement( + errorCollector.add(e, Errors.Menu.invalidSettingListElement( config.getSourceFile(), MenuSettingsNode.OPEN_ACTIONS, serializedAction)); - openActions.add(new DisabledAction(ErrorMessages.User.configurationError( + openActions.add(new DisabledAction(Errors.User.configurationError( "an action linked to opening this menu was not executed because it was not valid"))); } } @@ -164,7 +164,7 @@ public class MenuParser { menuSettings.setOpenItem(openItem); } catch (ParseException e) { - errorCollector.add(e, ErrorMessages.Menu.invalidSetting(config.getSourceFile(), MenuSettingsNode.OPEN_ITEM_MATERIAL)); + errorCollector.add(e, Errors.Menu.invalidSetting(config.getSourceFile(), MenuSettingsNode.OPEN_ITEM_MATERIAL)); } } } @@ -182,9 +182,9 @@ public class MenuParser { private static void addMenuSettingError(ErrorCollector errorCollector, Config config, String missingSetting, ConfigValueException e) { if (e instanceof MissingConfigValueException) { - errorCollector.add(ErrorMessages.Menu.missingSetting(config.getSourceFile(), missingSetting)); + errorCollector.add(Errors.Menu.missingSetting(config.getSourceFile(), missingSetting)); } else { - errorCollector.add(e, ErrorMessages.Menu.invalidSetting(config.getSourceFile(), missingSetting)); + errorCollector.add(e, Errors.Menu.invalidSetting(config.getSourceFile(), missingSetting)); } } From 94ab7624f738a58a2de6b55e502a9871a85995d3 Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 14 Aug 2020 18:39:04 +0200 Subject: [PATCH 195/213] Use common formatPath method --- .../java/me/filoghost/commons/config/ConfigErrors.java | 2 +- .../java/me/filoghost/chestcommands/logging/Errors.java | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/commons/src/main/java/me/filoghost/commons/config/ConfigErrors.java b/commons/src/main/java/me/filoghost/commons/config/ConfigErrors.java index 2e425c9..aa65f2c 100644 --- a/commons/src/main/java/me/filoghost/commons/config/ConfigErrors.java +++ b/commons/src/main/java/me/filoghost/commons/config/ConfigErrors.java @@ -49,7 +49,7 @@ public class ConfigErrors { return "value of type \"" + value.getClass() + "\" couldn't be converted by \"" + converter.getClass() + "\""; } - private static String formatPath(Path rootDataFolder, Path path) { + public static String formatPath(Path rootDataFolder, Path path) { if (path.startsWith(rootDataFolder)) { // Remove root data folder prefix return path.subpath(rootDataFolder.getNameCount(), path.getNameCount()).toString(); diff --git a/plugin/src/main/java/me/filoghost/chestcommands/logging/Errors.java b/plugin/src/main/java/me/filoghost/chestcommands/logging/Errors.java index 0d2ff88..05b9f03 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/logging/Errors.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/logging/Errors.java @@ -8,6 +8,7 @@ package me.filoghost.chestcommands.logging; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.parsing.icon.AttributeType; import me.filoghost.chestcommands.parsing.icon.IconSettings; +import me.filoghost.commons.config.ConfigErrors; import org.bukkit.ChatColor; import java.nio.file.Path; @@ -213,12 +214,7 @@ public class Errors { } private static String formatPath(Path path) { - if (path.startsWith(ChestCommands.getDataFolderPath())) { - // Remove "/plugins/ChestCommands" prefix - return path.subpath(ChestCommands.getDataFolderPath().getNameCount(), path.getNameCount()).toString(); - } else { - return path.toString(); - } + return ConfigErrors.formatPath(ChestCommands.getDataFolderPath(), path); } } From c89cda66e587935b07d8c98cbd92e41bfe0d6ade Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 15 Aug 2020 10:53:37 +0200 Subject: [PATCH 196/213] Make configuration values static --- .../chestcommands/ChestCommands.java | 19 +++--------------- .../attribute/LoreAttribute.java | 4 ++-- .../attribute/NameAttribute.java | 4 ++-- .../chestcommands/command/CommandHandler.java | 9 +++++---- .../chestcommands/config/ConfigManager.java | 10 ++++------ .../filoghost/chestcommands/config/Lang.java | 20 ++++++++++--------- .../chestcommands/config/Settings.java | 10 ++++++---- .../icon/requirement/RequiredExpLevel.java | 4 ++-- .../icon/requirement/RequiredMoney.java | 4 ++-- .../icon/requirement/RequiredPermission.java | 4 ++-- .../icon/requirement/item/RequiredItems.java | 6 +++--- .../listener/InventoryListener.java | 3 ++- .../chestcommands/listener/JoinListener.java | 3 ++- .../chestcommands/listener/SignListener.java | 4 ++-- .../chestcommands/menu/InternalIconMenu.java | 4 ++-- 15 files changed, 50 insertions(+), 58 deletions(-) diff --git a/plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 002c5bd..12033b9 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -9,7 +9,6 @@ import me.filoghost.chestcommands.api.internal.BackendAPI; import me.filoghost.chestcommands.command.CommandHandler; import me.filoghost.chestcommands.config.ConfigManager; import me.filoghost.chestcommands.config.CustomPlaceholders; -import me.filoghost.chestcommands.config.Lang; import me.filoghost.chestcommands.config.Settings; import me.filoghost.chestcommands.hook.BarAPIHook; import me.filoghost.chestcommands.hook.BungeeCordHook; @@ -55,8 +54,6 @@ public class ChestCommands extends BaseJavaPlugin { private static ConfigManager configManager; private static MenuManager menuManager; - private static Settings settings; - private static Lang lang; private static CustomPlaceholders placeholders; private static ErrorCollector lastLoadErrors; @@ -84,8 +81,6 @@ public class ChestCommands extends BaseJavaPlugin { Log.setLogger(getLogger()); configManager = new ConfigManager(getDataFolderPath()); menuManager = new MenuManager(); - settings = new Settings(); - lang = new Lang(); placeholders = new CustomPlaceholders(); BackendAPI.setImplementation(new DefaultBackendAPI()); @@ -109,7 +104,7 @@ public class ChestCommands extends BaseJavaPlugin { Log.info("Hooked PlaceholderAPI"); } - if (settings.update_notifications) { + if (Settings.update_notifications) { UpdateChecker.run(this, 56919, (String newVersion) -> { ChestCommands.newVersion = newVersion; @@ -172,8 +167,8 @@ public class ChestCommands extends BaseJavaPlugin { errorCollector.add(Errors.Upgrade.failedSomeUpgrades); } - settings = configManager.tryLoadSettings(errorCollector); - lang = configManager.tryLoadLang(errorCollector); + configManager.tryLoadSettings(errorCollector); + configManager.tryLoadLang(errorCollector); placeholders = configManager.tryLoadCustomPlaceholders(errorCollector); PlaceholderManager.setStaticPlaceholders(placeholders.getPlaceholders()); @@ -213,14 +208,6 @@ public class ChestCommands extends BaseJavaPlugin { return menuManager; } - public static Settings getSettings() { - return settings; - } - - public static Lang getLang() { - return lang; - } - public static boolean hasNewVersion() { return newVersion != null; } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java index d1c51fb..4411d05 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java @@ -5,7 +5,7 @@ */ package me.filoghost.chestcommands.attribute; -import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.config.Settings; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.commons.Colors; import me.filoghost.commons.collection.CollectionUtils; @@ -26,7 +26,7 @@ public class LoreAttribute implements IconAttribute { if (line.isEmpty()) { return line; } else if (line.charAt(0) != ChatColor.COLOR_CHAR) { - return ChestCommands.getSettings().default_color__lore + Colors.addColors(line); + return Settings.default_color__lore + Colors.addColors(line); } else { return Colors.addColors(line); } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java index 637dbe8..2fdef46 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java @@ -5,7 +5,7 @@ */ package me.filoghost.chestcommands.attribute; -import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.config.Settings; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.commons.Colors; import org.bukkit.ChatColor; @@ -24,7 +24,7 @@ public class NameAttribute implements IconAttribute { } if (input.charAt(0) != ChatColor.COLOR_CHAR) { - return ChestCommands.getSettings().default_color__name + Colors.addColors(input); + return Settings.default_color__name + Colors.addColors(input); } else { return Colors.addColors(input); } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index 99ec5a9..b4e44c0 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -7,6 +7,7 @@ package me.filoghost.chestcommands.command; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; +import me.filoghost.chestcommands.config.Lang; import me.filoghost.chestcommands.menu.InternalIconMenu; import me.filoghost.chestcommands.menu.MenuManager; import me.filoghost.chestcommands.util.Utils; @@ -119,12 +120,12 @@ public class CommandHandler extends CommandFramework { } if (sender.getName().equalsIgnoreCase(target.getName())) { - if (!ChestCommands.getLang().open_menu.isEmpty()) { - sender.sendMessage(ChestCommands.getLang().open_menu.replace("{menu}", menuName)); + if (!Lang.open_menu.isEmpty()) { + sender.sendMessage(Lang.open_menu.replace("{menu}", menuName)); } } else { - if (!ChestCommands.getLang().open_menu_others.isEmpty()) { - sender.sendMessage(ChestCommands.getLang().open_menu_others.replace("{menu}", menuName).replace("{player}", target.getName())); + if (!Lang.open_menu_others.isEmpty()) { + sender.sendMessage(Lang.open_menu_others.replace("{menu}", menuName).replace("{player}", target.getName())); } } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java b/plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java index 54b5fa0..77642c4 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/config/ConfigManager.java @@ -40,21 +40,19 @@ public class ConfigManager extends BaseConfigManager { langConfigLoader = getMappedConfigLoader("lang.yml", Lang::new); } - public Settings tryLoadSettings(ErrorCollector errorCollector) { + public void tryLoadSettings(ErrorCollector errorCollector) { try { - return settingsConfigLoader.init(); + settingsConfigLoader.init(); } catch (ConfigException e) { logConfigInitException(errorCollector, settingsConfigLoader.getFile(), e); - return new Settings(); } } - public Lang tryLoadLang(ErrorCollector errorCollector) { + public void tryLoadLang(ErrorCollector errorCollector) { try { - return langConfigLoader.init(); + langConfigLoader.init(); } catch (ConfigException e) { logConfigInitException(errorCollector, langConfigLoader.getFile(), e); - return new Lang(); } } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java b/plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java index 87b164b..0f30b8b 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java @@ -6,20 +6,22 @@ package me.filoghost.chestcommands.config; import me.filoghost.chestcommands.logging.Errors; +import me.filoghost.commons.config.mapped.IncludeStatic; import me.filoghost.commons.config.mapped.MappedConfig; import me.filoghost.commons.config.mapped.modifier.ChatColors; @ChatColors +@IncludeStatic public class Lang extends MappedConfig { - public String no_open_permission = "&cYou don't have permission &e{permission} &cto use this menu."; - public String default_no_icon_permission = "&cYou don't have permission for this icon."; - public String no_required_item = "&cYou must have &e{amount}x {material} &c(durability: {durability}) for this."; - public String no_money = "&cYou need {money}$ for this."; - public String no_exp = "&cYou need {levels} XP levels for this."; - public String menu_not_found = "&cMenu not found! " + Errors.User.notifyStaffRequest; - public String open_menu = "&aOpening the menu \"{menu}\"."; - public String open_menu_others = "&aOpening the menu \"{menu}\" to {player}."; - public String any = "any"; // Used in no_required_item when durability is not restrictive + public static String no_open_permission = "&cYou don't have permission &e{permission} &cto use this menu."; + public static String default_no_icon_permission = "&cYou don't have permission for this icon."; + public static String no_required_item = "&cYou must have &e{amount}x {material} &c(durability: {durability}) for this."; + public static String no_money = "&cYou need {money}$ for this."; + public static String no_exp = "&cYou need {levels} XP levels for this."; + public static String menu_not_found = "&cMenu not found! " + Errors.User.notifyStaffRequest; + public static String open_menu = "&aOpening the menu \"{menu}\"."; + public static String open_menu_others = "&aOpening the menu \"{menu}\" to {player}."; + public static String any = "any"; // Used in no_required_item when durability is not restrictive } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java b/plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java index 7a8aa41..86fc1c5 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/config/Settings.java @@ -5,16 +5,18 @@ */ package me.filoghost.chestcommands.config; +import me.filoghost.commons.config.mapped.IncludeStatic; import me.filoghost.commons.config.mapped.MappedConfig; import me.filoghost.commons.config.mapped.modifier.ChatColors; @ChatColors +@IncludeStatic public class Settings extends MappedConfig { - public String default_color__name = "&f"; - public String default_color__lore = "&7"; - public boolean update_notifications = true; - public int anti_click_spam_delay = 200; + public static String default_color__name = "&f"; + public static String default_color__lore = "&7"; + public static boolean update_notifications = true; + public static int anti_click_spam_delay = 200; public Settings() { setHeader( diff --git a/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java index 5ecf235..e2b2d0c 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredExpLevel.java @@ -6,7 +6,7 @@ package me.filoghost.chestcommands.icon.requirement; import com.google.common.base.Preconditions; -import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.config.Lang; import org.bukkit.entity.Player; public class RequiredExpLevel implements Requirement { @@ -21,7 +21,7 @@ public class RequiredExpLevel implements Requirement { @Override public boolean hasCost(Player player) { if (player.getLevel() < levels) { - player.sendMessage(ChestCommands.getLang().no_exp.replace("{levels}", Integer.toString(levels))); + player.sendMessage(Lang.no_exp.replace("{levels}", Integer.toString(levels))); return false; } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java index 21c911b..7a60e5f 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredMoney.java @@ -6,7 +6,7 @@ package me.filoghost.chestcommands.icon.requirement; import com.google.common.base.Preconditions; -import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.config.Lang; import me.filoghost.chestcommands.hook.VaultEconomyHook; import me.filoghost.chestcommands.logging.Errors; import org.bukkit.entity.Player; @@ -30,7 +30,7 @@ public class RequiredMoney implements Requirement { } if (!VaultEconomyHook.hasMoney(player, moneyAmount)) { - player.sendMessage(ChestCommands.getLang().no_money.replace("{money}", VaultEconomyHook.formatMoney(moneyAmount))); + player.sendMessage(Lang.no_money.replace("{money}", VaultEconomyHook.formatMoney(moneyAmount))); return false; } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java index 8337aae..afd5eee 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java @@ -5,7 +5,7 @@ */ package me.filoghost.chestcommands.icon.requirement; -import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.config.Lang; import me.filoghost.commons.Strings; import org.bukkit.entity.Player; @@ -48,7 +48,7 @@ public class RequiredPermission implements Requirement { if (noPermissionMessage != null) { player.sendMessage(noPermissionMessage); } else { - player.sendMessage(ChestCommands.getLang().default_no_icon_permission); + player.sendMessage(Lang.default_no_icon_permission); } return false; } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java index 7fbafa3..ce696f2 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/item/RequiredItems.java @@ -6,7 +6,7 @@ package me.filoghost.chestcommands.icon.requirement.item; import com.google.common.collect.ImmutableList; -import me.filoghost.chestcommands.ChestCommands; +import me.filoghost.chestcommands.config.Lang; import me.filoghost.chestcommands.icon.requirement.Requirement; import me.filoghost.chestcommands.util.Utils; import org.bukkit.entity.Player; @@ -28,10 +28,10 @@ public class RequiredItems implements Requirement { if (!hasItems) { for (RequiredItem item : items) { - player.sendMessage(ChestCommands.getLang().no_required_item + player.sendMessage(Lang.no_required_item .replace("{material}", Utils.formatEnum(item.getMaterial())) .replace("{amount}", Integer.toString(item.getAmount())) - .replace("{durability}", item.hasRestrictiveDurability() ? Short.toString(item.getDurability()) : ChestCommands.getLang().any)); + .replace("{durability}", item.hasRestrictiveDurability() ? Short.toString(item.getDurability()) : Lang.any)); } } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index 4ac8ba4..6efb09a 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -7,6 +7,7 @@ package me.filoghost.chestcommands.listener; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.api.ClickResult; +import me.filoghost.chestcommands.config.Settings; import me.filoghost.chestcommands.inventory.DefaultMenuInventory; import me.filoghost.chestcommands.inventory.DefaultMenuInventory.SlotClickHandler; import me.filoghost.chestcommands.menu.MenuManager; @@ -69,7 +70,7 @@ public class InventoryListener implements Listener { Long cooldownUntil = antiClickSpam.get(clicker); long now = System.currentTimeMillis(); - int minDelay = ChestCommands.getSettings().anti_click_spam_delay; + int minDelay = Settings.anti_click_spam_delay; if (minDelay > 0) { if (cooldownUntil != null && cooldownUntil > now) { diff --git a/plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java b/plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java index 166597c..61b986f 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/listener/JoinListener.java @@ -7,6 +7,7 @@ package me.filoghost.chestcommands.listener; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; +import me.filoghost.chestcommands.config.Settings; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -25,7 +26,7 @@ public class JoinListener implements Listener { + " error(s) last time it was loaded. You can see them by doing \"/cc reload\" in the console."); } - if (ChestCommands.hasNewVersion() && ChestCommands.getSettings().update_notifications && player.hasPermission(Permissions.UPDATE_NOTIFICATIONS)) { + if (ChestCommands.hasNewVersion() && Settings.update_notifications && player.hasPermission(Permissions.UPDATE_NOTIFICATIONS)) { player.sendMessage(ChestCommands.CHAT_PREFIX + "Found an update: " + ChestCommands.getNewVersion() + ". Download:"); player.sendMessage(ChatColor.DARK_GREEN + ">> " + ChatColor.GREEN + "http://dev.bukkit.org/bukkit-plugins/chest-commands"); } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java b/plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java index ba74942..01a71c7 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java @@ -5,8 +5,8 @@ */ package me.filoghost.chestcommands.listener; -import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; +import me.filoghost.chestcommands.config.Lang; import me.filoghost.chestcommands.menu.InternalIconMenu; import me.filoghost.chestcommands.menu.MenuManager; import me.filoghost.chestcommands.util.Utils; @@ -59,7 +59,7 @@ public class SignListener implements Listener { InternalIconMenu menu = menuManager.getMenuByFileName(menuFileName); if (menu == null) { - event.getPlayer().sendMessage(ChestCommands.getLang().menu_not_found); + event.getPlayer().sendMessage(Lang.menu_not_found); return; } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java b/plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java index da10034..3d52714 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java @@ -6,10 +6,10 @@ package me.filoghost.chestcommands.menu; import com.google.common.collect.ImmutableList; -import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.api.MenuInventory; +import me.filoghost.chestcommands.config.Lang; import me.filoghost.commons.collection.CollectionUtils; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -71,7 +71,7 @@ public class InternalIconMenu extends BaseIconMenu { } public void sendNoOpenPermissionMessage(CommandSender sender) { - String noPermMessage = ChestCommands.getLang().no_open_permission; + String noPermMessage = Lang.no_open_permission; if (noPermMessage != null && !noPermMessage.isEmpty()) { sender.sendMessage(noPermMessage.replace("{permission}", this.openPermission)); } From 60fd565727e29324f9e5c20e86148634525dcc28 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 15 Aug 2020 10:54:37 +0200 Subject: [PATCH 197/213] Make fields final --- .../main/java/me/filoghost/chestcommands/logging/Errors.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/me/filoghost/chestcommands/logging/Errors.java b/plugin/src/main/java/me/filoghost/chestcommands/logging/Errors.java index 05b9f03..c527286 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/logging/Errors.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/logging/Errors.java @@ -85,7 +85,7 @@ public class Errors { public static final String invalidPatternFormat = "value must match the format \"pattern:color\""; public static final String unknownAttribute = "unknown attribute"; - public static String materialCannotBeAir = "material cannot be air"; + public static final String materialCannotBeAir = "material cannot be air"; public static String unknownMaterial(String materialString) { return "unknown material \"" + materialString + "\""; @@ -205,7 +205,7 @@ public class Errors { public static class User { - public static String notifyStaffRequest = "Please inform the staff."; + public static final String notifyStaffRequest = "Please inform the staff."; public static String configurationError(String errorMessage) { return ChatColor.RED + "Error: " + errorMessage + ". " + Errors.User.notifyStaffRequest; From 97fdba6e3e949ee4adf901243c072702d60db789 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 15 Aug 2020 10:56:41 +0200 Subject: [PATCH 198/213] Always add default color on non-empty lines --- .../chestcommands/attribute/LoreAttribute.java | 7 ++----- .../chestcommands/attribute/NameAttribute.java | 13 ++++--------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java index 4411d05..6dc2a10 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/attribute/LoreAttribute.java @@ -9,7 +9,6 @@ import me.filoghost.chestcommands.config.Settings; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.commons.Colors; import me.filoghost.commons.collection.CollectionUtils; -import org.bukkit.ChatColor; import java.util.List; @@ -23,12 +22,10 @@ public class LoreAttribute implements IconAttribute { private List colorLore(List input) { return CollectionUtils.transform(input, line -> { - if (line.isEmpty()) { - return line; - } else if (line.charAt(0) != ChatColor.COLOR_CHAR) { + if (!line.isEmpty()) { return Settings.default_color__lore + Colors.addColors(line); } else { - return Colors.addColors(line); + return line; } }); } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java b/plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java index 2fdef46..5b46fc3 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/attribute/NameAttribute.java @@ -8,7 +8,6 @@ package me.filoghost.chestcommands.attribute; import me.filoghost.chestcommands.config.Settings; import me.filoghost.chestcommands.icon.InternalConfigurableIcon; import me.filoghost.commons.Colors; -import org.bukkit.ChatColor; public class NameAttribute implements IconAttribute { @@ -18,15 +17,11 @@ public class NameAttribute implements IconAttribute { this.name = colorName(name); } - private String colorName(String input) { - if (input == null || input.isEmpty()) { - return input; - } - - if (input.charAt(0) != ChatColor.COLOR_CHAR) { - return Settings.default_color__name + Colors.addColors(input); + private String colorName(String name) { + if (!name.isEmpty()) { + return Settings.default_color__name + Colors.addColors(name); } else { - return Colors.addColors(input); + return name; } } From 988d7207a3aca4e1703e1d76ec3bde4ef06c5105 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 15 Aug 2020 11:56:22 +0200 Subject: [PATCH 199/213] Remove unneeded values from lang.yml --- .../chestcommands/command/CommandHandler.java | 9 ++------- .../me/filoghost/chestcommands/config/Lang.java | 2 -- .../me/filoghost/chestcommands/legacy/Backup.java | 4 ++++ .../legacy/upgrade/YamlUpgradeTask.java | 8 ++++++++ .../legacy/v4_0/v4_0_LangUpgradeTask.java | 13 ++++++++----- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index b4e44c0..6b89ff1 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -7,7 +7,6 @@ package me.filoghost.chestcommands.command; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; -import me.filoghost.chestcommands.config.Lang; import me.filoghost.chestcommands.menu.InternalIconMenu; import me.filoghost.chestcommands.menu.MenuManager; import me.filoghost.chestcommands.util.Utils; @@ -120,13 +119,9 @@ public class CommandHandler extends CommandFramework { } if (sender.getName().equalsIgnoreCase(target.getName())) { - if (!Lang.open_menu.isEmpty()) { - sender.sendMessage(Lang.open_menu.replace("{menu}", menuName)); - } + sender.sendMessage(ChatColor.GREEN + "Opening the menu " + menuName + "."); } else { - if (!Lang.open_menu_others.isEmpty()) { - sender.sendMessage(Lang.open_menu_others.replace("{menu}", menuName).replace("{player}", target.getName())); - } + sender.sendMessage(ChatColor.GREEN + "Opening the menu " + menuName + " to " + target.getName() + "."); } menu.open(target); diff --git a/plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java b/plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java index 0f30b8b..44a635f 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/config/Lang.java @@ -20,8 +20,6 @@ public class Lang extends MappedConfig { public static String no_money = "&cYou need {money}$ for this."; public static String no_exp = "&cYou need {levels} XP levels for this."; public static String menu_not_found = "&cMenu not found! " + Errors.User.notifyStaffRequest; - public static String open_menu = "&aOpening the menu \"{menu}\"."; - public static String open_menu_others = "&aOpening the menu \"{menu}\" to {player}."; public static String any = "any"; // Used in no_required_item when durability is not restrictive } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java index fcb7960..12644b4 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/legacy/Backup.java @@ -37,9 +37,13 @@ public class Backup { Preconditions.checkArgument(fileToBackup.startsWith(dataFolder), "file is not inside data folder"); Path destination = backupFolder.resolve(dataFolder.relativize(fileToBackup)); Files.createDirectories(destination.getParent()); + + // Add backup file if no already present if (!Files.isRegularFile(destination)) { Files.copy(fileToBackup, destination); } + + // Add README file if not already present if (!Files.isRegularFile(infoFile)) { Files.write(infoFile, Arrays.asList( "Files in this folders are copies of original configuration files that have been automatically upgraded.", diff --git a/plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java index c89a334..b357e36 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/legacy/upgrade/YamlUpgradeTask.java @@ -55,4 +55,12 @@ public abstract class YamlUpgradeTask extends UpgradeTask { } } + protected void replaceStringValue(Config settingsConfig, String node, String target, String replacement) { + String value = settingsConfig.getString(node); + if (value.contains(target)) { + settingsConfig.setString(node, value.replace(target, replacement)); + setSaveRequired(); + } + } + } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_LangUpgradeTask.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_LangUpgradeTask.java index d7ca502..2cc0c33 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_LangUpgradeTask.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_LangUpgradeTask.java @@ -6,17 +6,20 @@ package me.filoghost.chestcommands.legacy.v4_0; import me.filoghost.chestcommands.config.ConfigManager; -import me.filoghost.chestcommands.legacy.upgrade.RegexUpgradeTask; +import me.filoghost.chestcommands.legacy.upgrade.YamlUpgradeTask; +import me.filoghost.commons.config.Config; -public class v4_0_LangUpgradeTask extends RegexUpgradeTask { +public class v4_0_LangUpgradeTask extends YamlUpgradeTask { public v4_0_LangUpgradeTask(ConfigManager configManager) { - super(configManager.getRootDataFolder().resolve("lang.yml")); + super(configManager.getConfigLoader("lang.yml")); } @Override - protected void computeRegexChanges() { - replaceString("{datavalue}", "{durability}"); + public void computeYamlChanges(Config settingsConfig) { + removeNode(settingsConfig, "open-menu"); + removeNode(settingsConfig, "open-menu-others"); + replaceStringValue(settingsConfig, "no-required-item", "{datavalue}", "{durability}"); } } From b2f2af7256f01a458048db80d7af8f858e7b0abe Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 15 Aug 2020 14:44:46 +0200 Subject: [PATCH 200/213] Remove action aliases --- .../chestcommands/parsing/ActionParser.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java index 4fd1dde..dac98ac 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/parsing/ActionParser.java @@ -39,24 +39,25 @@ public class ActionParser { private enum ActionType { - CONSOLE_COMMAND("console:", ConsoleCommandAction::new), - OP_COMMAND("op:", OpCommandAction::new), - OPEN("(open|menu):", OpenMenuAction::new), - SERVER("server:?", ChangeServerAction::new), // The colon is optional - TELL("tell:", SendMessageAction::new), - BROADCAST("broadcast:", BroadcastAction::new), - GIVE_ITEM("give:", GiveItemAction::new), - GIVE_MONEY("give-?money:", GiveMoneyAction::new), - SOUND("sound:", PlaySoundAction::new), - BOSS_BAR("dragon-?bar:", DragonBarAction::new); + CONSOLE_COMMAND("console", ConsoleCommandAction::new), + OP_COMMAND("op", OpCommandAction::new), + OPEN("open", OpenMenuAction::new), + SERVER("server", ChangeServerAction::new), // The colon is optional + TELL("tell", SendMessageAction::new), + BROADCAST("broadcast", BroadcastAction::new), + GIVE_ITEM("give", GiveItemAction::new), + GIVE_MONEY("give-money", GiveMoneyAction::new), + SOUND("sound", PlaySoundAction::new), + BOSS_BAR("dragon-bar", DragonBarAction::new); private final Pattern prefixPattern; private final ActionFactory actionFactory; - ActionType(String prefixPattern, ActionFactory actionFactory) { - this.prefixPattern = Pattern.compile("^" + prefixPattern, Pattern.CASE_INSENSITIVE); // Case insensitive and only at the beginning + ActionType(String prefix, ActionFactory actionFactory) { + // Non-default actions must match the format "{prefix}: {content}" + this.prefixPattern = Pattern.compile("^" + Pattern.quote(prefix) + ":", Pattern.CASE_INSENSITIVE); this.actionFactory = actionFactory; } From c84668e538189cbd3fa8f735182ac50ca4a42d94 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 15 Aug 2020 15:04:24 +0200 Subject: [PATCH 201/213] Automatically upgrade old action prefixes --- .../chestcommands/legacy/UpgradeList.java | 4 +- ... => v4_0_MenuNodeReformatUpgradeTask.java} | 42 ++++++++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) rename plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/{v4_0_MenuNodeExpandUpgradeTask.java => v4_0_MenuNodeReformatUpgradeTask.java} (76%) diff --git a/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java index e1d4649..49cf1ba 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java @@ -11,7 +11,7 @@ import me.filoghost.chestcommands.legacy.upgrade.Upgrade; import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask; import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException; import me.filoghost.chestcommands.legacy.v4_0.v4_0_LangUpgradeTask; -import me.filoghost.chestcommands.legacy.v4_0.v4_0_MenuNodeExpandUpgradeTask; +import me.filoghost.chestcommands.legacy.v4_0.v4_0_MenuNodeReformatUpgradeTask; import me.filoghost.chestcommands.legacy.v4_0.v4_0_MenuNodeRenameUpgradeTask; import me.filoghost.chestcommands.legacy.v4_0.v4_0_PlaceholdersFileUpgradeTask; import me.filoghost.chestcommands.legacy.v4_0.v4_0_SettingsUpgradeTask; @@ -40,7 +40,7 @@ public class UpgradeList { multiTaskUpgrade("v4.0-menus-reformat", (configManager) -> { String legacyCommandSeparator = readLegacyCommandSeparator(configManager); return createMenuTasks(configManager, - file -> new v4_0_MenuNodeExpandUpgradeTask(configManager, file, legacyCommandSeparator)); + file -> new v4_0_MenuNodeReformatUpgradeTask(configManager, file, legacyCommandSeparator)); }), // Upgrade config after reading the command separator for menus diff --git a/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeReformatUpgradeTask.java similarity index 76% rename from plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeReformatUpgradeTask.java index 0698712..fbd2ffe 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeExpandUpgradeTask.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeReformatUpgradeTask.java @@ -20,11 +20,11 @@ import java.util.Collections; import java.util.List; import java.util.regex.Pattern; -public class v4_0_MenuNodeExpandUpgradeTask extends YamlUpgradeTask { +public class v4_0_MenuNodeReformatUpgradeTask extends YamlUpgradeTask { private final String legacyCommandSeparator; - public v4_0_MenuNodeExpandUpgradeTask(ConfigManager configManager, Path menuFile, String legacyCommandSeparator) { + public v4_0_MenuNodeReformatUpgradeTask(ConfigManager configManager, Path menuFile, String legacyCommandSeparator) { super(configManager.getConfigLoader(menuFile)); this.legacyCommandSeparator = legacyCommandSeparator; } @@ -50,17 +50,49 @@ public class v4_0_MenuNodeExpandUpgradeTask extends YamlUpgradeTask { private void upgradeMenuSettings(ConfigSection section) { expandInlineList(section, MenuSettingsNode.COMMANDS, ";"); expandInlineList(section, MenuSettingsNode.OPEN_ACTIONS, legacyCommandSeparator); + updateActionPrefixes(section, MenuSettingsNode.OPEN_ACTIONS); } private void upgradeIcon(ConfigSection section) { - expandInlineList(section, AttributeType.ACTIONS.getAttributeName(), legacyCommandSeparator); expandInlineList(section, AttributeType.ENCHANTMENTS.getAttributeName(), ";"); - + expandInlineList(section, AttributeType.ACTIONS.getAttributeName(), legacyCommandSeparator); + updateActionPrefixes(section, AttributeType.ACTIONS.getAttributeName()); expandSingletonList(section, AttributeType.REQUIRED_ITEMS.getAttributeName()); - expandInlineItemstack(section); } + private void updateActionPrefixes(ConfigSection config, String node) { + List actions = config.getStringList(node); + if (actions == null) { + return; + } + + for (int i = 0; i < actions.size(); i++) { + String oldAction = actions.get(i); + String newAction = oldAction; + newAction = replacePrefix(newAction, "menu:", "open:"); + newAction = replacePrefix(newAction, "givemoney:", "give-money:"); + newAction = replacePrefix(newAction, "dragonbar:", "dragon-bar:"); + newAction = replacePrefix(newAction, "server ", "server: "); + + if (!newAction.equals(oldAction)) { + setSaveRequired(); + actions.set(i, newAction); + } + } + + config.setStringList(node, actions); + } + + private String replacePrefix(String action, String oldPrefix, String newPrefix) { + if (action.startsWith(oldPrefix)) { + setSaveRequired(); + return newPrefix + action.substring(oldPrefix.length()); + } else { + return action; + } + } + private void expandInlineItemstack(ConfigSection section) { String material = section.getString(AttributeType.MATERIAL.getAttributeName()); if (material == null) { From 96934a10873546b4e33e174e6f9d4de67caf3091 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 15 Aug 2020 16:19:34 +0200 Subject: [PATCH 202/213] Fix default custom-placeholders.yml --- plugin/src/main/resources/custom-placeholders.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugin/src/main/resources/custom-placeholders.yml b/plugin/src/main/resources/custom-placeholders.yml index f32b8f0..afd0b34 100644 --- a/plugin/src/main/resources/custom-placeholders.yml +++ b/plugin/src/main/resources/custom-placeholders.yml @@ -7,7 +7,8 @@ # # Another use would be for defining colors, symbols, or text decorations. # -'{custom_placeholder}': 'This line is a custom placeholder.' -'{primary_color}': '&b' -'{secondary_color}': '&7' -'{separator}': '&8[====|====|====|====|====|====|====|====]' \ No newline at end of file +placeholders: + '{custom_placeholder}': 'This line is a custom placeholder.' + '{primary_color}': '&b' + '{secondary_color}': '&7' + '{separator}': '&8[====|====|====|====|====|====|====|====]' \ No newline at end of file From 862acff45cb935d7eb2959a2c28396f2e5b597e8 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 15 Aug 2020 17:17:47 +0200 Subject: [PATCH 203/213] Fix NullPointerException when using air as material --- .../icon/BaseConfigurableIcon.java | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java index 9e1ec49..390110a 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java @@ -275,34 +275,36 @@ public abstract class BaseConfigurableIcon implements Icon { // Then apply data from config nodes, overwriting NBT data if there are conflicting values ItemMeta itemMeta = itemStack.getItemMeta(); - itemMeta.setDisplayName(renderName(viewer)); - itemMeta.setLore(renderLore(viewer)); + if (itemMeta != null) { + itemMeta.setDisplayName(renderName(viewer)); + itemMeta.setLore(renderLore(viewer)); - if (leatherColor != null && itemMeta instanceof LeatherArmorMeta) { - ((LeatherArmorMeta) itemMeta).setColor(leatherColor); - } - - if (skullOwner != null && itemMeta instanceof SkullMeta) { - String skullOwner = this.skullOwner.getValue(viewer); - ((SkullMeta) itemMeta).setOwner(skullOwner); - } - - if (itemMeta instanceof BannerMeta) { - BannerMeta bannerMeta = (BannerMeta) itemMeta; - if (bannerColor != null) { - bannerMeta.setBaseColor(bannerColor); + if (leatherColor != null && itemMeta instanceof LeatherArmorMeta) { + ((LeatherArmorMeta) itemMeta).setColor(leatherColor); } - if (bannerPatterns != null) { - ((BannerMeta) itemMeta).setPatterns(bannerPatterns); - } - } - - // Hide all text details (damage, enchantments, potions, etc,) - if (itemMeta.getItemFlags().isEmpty()) { - itemMeta.addItemFlags(ItemFlag.values()); - } - itemStack.setItemMeta(itemMeta); + if (skullOwner != null && itemMeta instanceof SkullMeta) { + String skullOwner = this.skullOwner.getValue(viewer); + ((SkullMeta) itemMeta).setOwner(skullOwner); + } + + if (itemMeta instanceof BannerMeta) { + BannerMeta bannerMeta = (BannerMeta) itemMeta; + if (bannerColor != null) { + bannerMeta.setBaseColor(bannerColor); + } + if (bannerPatterns != null) { + ((BannerMeta) itemMeta).setPatterns(bannerPatterns); + } + } + + // Hide all text details (damage, enchantments, potions, etc,) + if (itemMeta.getItemFlags().isEmpty()) { + itemMeta.addItemFlags(ItemFlag.values()); + } + + itemStack.setItemMeta(itemMeta); + } if (enchantments != null) { enchantments.forEach(itemStack::addUnsafeEnchantment); From 7fa48ac3c484839796d56250a0e2438f9d3bdda6 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 15 Aug 2020 17:29:56 +0200 Subject: [PATCH 204/213] Fix icon caching --- .../chestcommands/icon/BaseConfigurableIcon.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java index 390110a..6cd9b95 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/icon/BaseConfigurableIcon.java @@ -58,13 +58,17 @@ public abstract class BaseConfigurableIcon implements Icon { } protected boolean shouldCacheRendering() { - if (placeholdersEnabled) { + if (placeholdersEnabled && hasDynamicPlaceholders()) { return false; + } else { + return true; } + } - return (name == null || !name.hasDynamicPlaceholders()) - && (lore == null || !lore.hasDynamicPlaceholders()) - && (skullOwner == null || !skullOwner.hasDynamicPlaceholders()); + private boolean hasDynamicPlaceholders() { + return (name != null && name.hasDynamicPlaceholders()) + || (lore != null && lore.hasDynamicPlaceholders()) + || (skullOwner != null && skullOwner.hasDynamicPlaceholders()); } public void setMaterial(Material material) { From 4faee01be547c7241726f8ab9a54f7560b21216c Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 15 Aug 2020 20:37:29 +0200 Subject: [PATCH 205/213] Rename classes --- .../me/filoghost/chestcommands/legacy/UpgradeList.java | 8 ++++---- ...UpgradeTask.java => v4_0_MenuReformatUpgradeTask.java} | 4 ++-- ...UpgradeTask.java => v4_0_PlaceholdersUpgradeTask.java} | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) rename plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/{v4_0_MenuNodeReformatUpgradeTask.java => v4_0_MenuReformatUpgradeTask.java} (96%) rename plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/{v4_0_PlaceholdersFileUpgradeTask.java => v4_0_PlaceholdersUpgradeTask.java} (95%) diff --git a/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java index 49cf1ba..d3c4f4a 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/legacy/UpgradeList.java @@ -11,9 +11,9 @@ import me.filoghost.chestcommands.legacy.upgrade.Upgrade; import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask; import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException; import me.filoghost.chestcommands.legacy.v4_0.v4_0_LangUpgradeTask; -import me.filoghost.chestcommands.legacy.v4_0.v4_0_MenuNodeReformatUpgradeTask; import me.filoghost.chestcommands.legacy.v4_0.v4_0_MenuNodeRenameUpgradeTask; -import me.filoghost.chestcommands.legacy.v4_0.v4_0_PlaceholdersFileUpgradeTask; +import me.filoghost.chestcommands.legacy.v4_0.v4_0_MenuReformatUpgradeTask; +import me.filoghost.chestcommands.legacy.v4_0.v4_0_PlaceholdersUpgradeTask; import me.filoghost.chestcommands.legacy.v4_0.v4_0_SettingsUpgradeTask; import me.filoghost.chestcommands.logging.Errors; import me.filoghost.commons.collection.CollectionUtils; @@ -40,12 +40,12 @@ public class UpgradeList { multiTaskUpgrade("v4.0-menus-reformat", (configManager) -> { String legacyCommandSeparator = readLegacyCommandSeparator(configManager); return createMenuTasks(configManager, - file -> new v4_0_MenuNodeReformatUpgradeTask(configManager, file, legacyCommandSeparator)); + file -> new v4_0_MenuReformatUpgradeTask(configManager, file, legacyCommandSeparator)); }), // Upgrade config after reading the command separator for menus singleTaskUpgrade("v4.0-config", v4_0_SettingsUpgradeTask::new), - singleTaskUpgrade("v4.0-placeholders", v4_0_PlaceholdersFileUpgradeTask::new), + singleTaskUpgrade("v4.0-placeholders", v4_0_PlaceholdersUpgradeTask::new), singleTaskUpgrade("v4.0-lang", v4_0_LangUpgradeTask::new) ); diff --git a/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeReformatUpgradeTask.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuReformatUpgradeTask.java similarity index 96% rename from plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeReformatUpgradeTask.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuReformatUpgradeTask.java index fbd2ffe..b92b84d 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuNodeReformatUpgradeTask.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_MenuReformatUpgradeTask.java @@ -20,11 +20,11 @@ import java.util.Collections; import java.util.List; import java.util.regex.Pattern; -public class v4_0_MenuNodeReformatUpgradeTask extends YamlUpgradeTask { +public class v4_0_MenuReformatUpgradeTask extends YamlUpgradeTask { private final String legacyCommandSeparator; - public v4_0_MenuNodeReformatUpgradeTask(ConfigManager configManager, Path menuFile, String legacyCommandSeparator) { + public v4_0_MenuReformatUpgradeTask(ConfigManager configManager, Path menuFile, String legacyCommandSeparator) { super(configManager.getConfigLoader(menuFile)); this.legacyCommandSeparator = legacyCommandSeparator; } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java b/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersUpgradeTask.java similarity index 95% rename from plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java rename to plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersUpgradeTask.java index dd16d14..67d0fa3 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersFileUpgradeTask.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/legacy/v4_0/v4_0_PlaceholdersUpgradeTask.java @@ -20,13 +20,13 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.List; -public class v4_0_PlaceholdersFileUpgradeTask extends UpgradeTask { +public class v4_0_PlaceholdersUpgradeTask extends UpgradeTask { private final Path oldPlaceholdersFile; private final ConfigLoader newPlaceholdersConfigLoader; private Config updatedConfig; - public v4_0_PlaceholdersFileUpgradeTask(ConfigManager configManager) { + public v4_0_PlaceholdersUpgradeTask(ConfigManager configManager) { this.oldPlaceholdersFile = configManager.getRootDataFolder().resolve("placeholders.yml"); this.newPlaceholdersConfigLoader = configManager.getConfigLoader("custom-placeholders.yml"); } From f873b4badd52ca20b44741139097332c60a83f05 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 16 Aug 2020 10:41:34 +0200 Subject: [PATCH 206/213] New update checker that considers versions with "DEV" as development versions --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index dd98cef..04da293 100644 --- a/pom.xml +++ b/pom.xml @@ -104,7 +104,7 @@ me.filoghost.updatechecker updatechecker - 1.0.0 + 1.0.1 From 055ca91e60d2a56955773b4f09e1cdf44c88a44f Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 16 Aug 2020 11:20:41 +0200 Subject: [PATCH 207/213] Add UpdateChecker license info --- THIRD-PARTY.txt | 7 ++++++- licenses/LICENSE-UpdateChecker.txt | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 licenses/LICENSE-UpdateChecker.txt diff --git a/THIRD-PARTY.txt b/THIRD-PARTY.txt index 2c7e2ca..e57df31 100644 --- a/THIRD-PARTY.txt +++ b/THIRD-PARTY.txt @@ -9,4 +9,9 @@ bStats Metrics EisenNBT URL: https://github.com/Eisenwave/eisen-nbt License name: MIT License - License file: /licenses/LICENSE-EisenNBT.txt \ No newline at end of file + License file: /licenses/LICENSE-EisenNBT.txt + +Update Checker + URL: https://github.com/filoghost/UpdateChecker + License name: MIT License + License file: /licenses/LICENSE-UpdateChecker.txt \ No newline at end of file diff --git a/licenses/LICENSE-UpdateChecker.txt b/licenses/LICENSE-UpdateChecker.txt new file mode 100644 index 0000000..d9413ed --- /dev/null +++ b/licenses/LICENSE-UpdateChecker.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (C) filoghost + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 009ed1dde04b03750f014ba496f87eadd411da70 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 16 Aug 2020 11:56:12 +0200 Subject: [PATCH 208/213] Relocate commons to main package --- plugin/pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin/pom.xml b/plugin/pom.xml index a60bed6..f6e4488 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -136,6 +136,10 @@ me.filoghost.updatechecker me.filoghost.chestcommands.updater + + me.filoghost.commons + me.filoghost.chestcommands.commons + From 33bf169adf680a1ff807d8b49143ec17471f6bd1 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 16 Aug 2020 14:45:21 +0200 Subject: [PATCH 209/213] Display money in example menu --- plugin/src/main/resources/menu/example.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/src/main/resources/menu/example.yml b/plugin/src/main/resources/menu/example.yml index c075935..ec71c79 100644 --- a/plugin/src/main/resources/menu/example.yml +++ b/plugin/src/main/resources/menu/example.yml @@ -134,11 +134,13 @@ economy-give: - 'This action will be executed' - 'only if you have at least 50$.' - 'It gives you a gold ingot.' + - '' + - 'Current money: {money}' PRICE: 50 ACTIONS: - 'tell: &aYou have paid 50$' - 'give: gold ingot' - + KEEP-OPEN: true economy-take: MATERIAL: gold ingot @@ -148,11 +150,14 @@ economy-take: LORE: - 'This icon is the opposite of the previous.' - 'It will take you a gold ingot and give you $50.' + - '' + - 'Current money: {money}' REQUIRED-ITEMS: - gold ingot ACTIONS: - 'tell: &aYou have been paid 50$' - 'give-money: 50' + KEEP-OPEN: true formatting-codes: From 10f62a1cfb34781e8120cdf5cf07e4742f8bd0a9 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 16 Aug 2020 14:58:23 +0200 Subject: [PATCH 210/213] Fix exception on required permission --- .../icon/InternalConfigurableIcon.java | 15 ++++++++++++--- .../icon/requirement/RequiredPermission.java | 8 ++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java index b893002..b973c16 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java @@ -52,15 +52,24 @@ public class InternalConfigurableIcon extends BaseConfigurableIcon implements Re } public void setClickPermission(String permission) { - this.clickPermission = new RequiredPermission(permission); + if (this.clickPermission == null) { + this.clickPermission = new RequiredPermission(); + } + this.clickPermission.setPermission(permission); } public void setNoClickPermissionMessage(String clickNoPermissionMessage) { - clickPermission.setNoPermissionMessage(clickNoPermissionMessage); + if (this.clickPermission == null) { + this.clickPermission = new RequiredPermission(); + } + this.clickPermission.setNoPermissionMessage(clickNoPermissionMessage); } public void setViewPermission(String viewPermission) { - this.viewPermission = new RequiredPermission(viewPermission); + if (this.viewPermission == null) { + this.viewPermission = new RequiredPermission(); + } + this.viewPermission.setPermission(viewPermission); } public void setRequiredMoney(double requiredMoney) { diff --git a/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java index afd5eee..c27606b 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java @@ -11,11 +11,11 @@ import org.bukkit.entity.Player; public class RequiredPermission implements Requirement { - private final String permission; - private final boolean negated; + private String permission; + private boolean negated; private String noPermissionMessage; - - public RequiredPermission(String permission) { + + public void setPermission(String permission) { if (permission != null) { permission = permission.trim(); } From a01789dfa3d801f2ed591b49d86039f569593d75 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 16 Aug 2020 15:38:12 +0200 Subject: [PATCH 211/213] Fix view permission not preventing players from clicking an icon --- .../chestcommands/icon/IconPermission.java | 55 +++++++++++++ .../icon/InternalConfigurableIcon.java | 45 ++++++----- .../icon/requirement/RequiredPermission.java | 78 ------------------- 3 files changed, 80 insertions(+), 98 deletions(-) create mode 100644 plugin/src/main/java/me/filoghost/chestcommands/icon/IconPermission.java delete mode 100644 plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java diff --git a/plugin/src/main/java/me/filoghost/chestcommands/icon/IconPermission.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/IconPermission.java new file mode 100644 index 0000000..35e6d00 --- /dev/null +++ b/plugin/src/main/java/me/filoghost/chestcommands/icon/IconPermission.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.chestcommands.icon; + +import me.filoghost.commons.Strings; +import org.bukkit.entity.Player; + +public class IconPermission { + + private final String permission; + private final boolean negated; + + public IconPermission(String permission) { + if (permission != null) { + permission = permission.trim(); + } + + if (Strings.isEmpty(permission)) { + this.permission = null; + negated = false; + } else { + if (permission.startsWith("-")) { + this.permission = permission.substring(1); + negated = true; + } else { + this.permission = permission; + negated = false; + } + } + } + + private boolean hasPermission(Player player) { + if (isEmpty()) { + return true; + } + + if (negated) { + return !player.hasPermission(permission); + } else { + return player.hasPermission(permission); + } + } + + public boolean isEmpty() { + return this.permission == null; + } + + public static boolean hasPermission(Player player, IconPermission permission) { + return permission == null || permission.hasPermission(player); + } + +} diff --git a/plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java index b973c16..09f4bb1 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java @@ -10,9 +10,9 @@ import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.OpenMenuAction; import me.filoghost.chestcommands.api.ClickResult; import me.filoghost.chestcommands.api.MenuInventory; +import me.filoghost.chestcommands.config.Lang; import me.filoghost.chestcommands.icon.requirement.RequiredExpLevel; import me.filoghost.chestcommands.icon.requirement.RequiredMoney; -import me.filoghost.chestcommands.icon.requirement.RequiredPermission; import me.filoghost.chestcommands.icon.requirement.Requirement; import me.filoghost.chestcommands.icon.requirement.item.RequiredItem; import me.filoghost.chestcommands.icon.requirement.item.RequiredItems; @@ -27,16 +27,17 @@ import java.util.List; public class InternalConfigurableIcon extends BaseConfigurableIcon implements RefreshableIcon { - private RequiredPermission viewPermission; + private IconPermission viewPermission; + private IconPermission clickPermission; + private String noClickPermissionMessage; - private RequiredPermission clickPermission; private RequiredMoney requiredMoney; private RequiredExpLevel requiredExpLevel; private RequiredItems requiredItems; - private ImmutableList clickActions; + private ImmutableList clickActions; private ClickResult clickResult; - + public InternalConfigurableIcon(Material material) { super(material); setPlaceholdersEnabled(true); @@ -44,7 +45,7 @@ public class InternalConfigurableIcon extends BaseConfigurableIcon implements Re } public boolean canViewIcon(Player player) { - return viewPermission == null || viewPermission.hasPermission(player); + return IconPermission.hasPermission(player, viewPermission); } public boolean hasViewPermission() { @@ -52,24 +53,15 @@ public class InternalConfigurableIcon extends BaseConfigurableIcon implements Re } public void setClickPermission(String permission) { - if (this.clickPermission == null) { - this.clickPermission = new RequiredPermission(); - } - this.clickPermission.setPermission(permission); + this.clickPermission = new IconPermission(permission); } - public void setNoClickPermissionMessage(String clickNoPermissionMessage) { - if (this.clickPermission == null) { - this.clickPermission = new RequiredPermission(); - } - this.clickPermission.setNoPermissionMessage(clickNoPermissionMessage); + public void setNoClickPermissionMessage(String noClickPermissionMessage) { + this.noClickPermissionMessage = noClickPermissionMessage; } public void setViewPermission(String viewPermission) { - if (this.viewPermission == null) { - this.viewPermission = new RequiredPermission(); - } - this.viewPermission.setPermission(viewPermission); + this.viewPermission = new IconPermission(viewPermission); } public void setRequiredMoney(double requiredMoney) { @@ -123,8 +115,21 @@ public class InternalConfigurableIcon extends BaseConfigurableIcon implements Re @Override public ClickResult onClick(MenuInventory menuInventory, Player player) { + if (!IconPermission.hasPermission(player, viewPermission)) { + return ClickResult.KEEP_OPEN; + } + + if (!IconPermission.hasPermission(player, clickPermission)) { + if (noClickPermissionMessage != null) { + player.sendMessage(noClickPermissionMessage); + } else { + player.sendMessage(Lang.default_no_icon_permission); + } + return clickResult; + } + // Check all the requirements - Requirement[] requirements = {clickPermission, requiredMoney, requiredExpLevel, requiredItems}; + Requirement[] requirements = {requiredMoney, requiredExpLevel, requiredItems}; boolean hasAllRequirements = Requirement.hasAllCosts(player, requirements); if (!hasAllRequirements) { return clickResult; diff --git a/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java deleted file mode 100644 index c27606b..0000000 --- a/plugin/src/main/java/me/filoghost/chestcommands/icon/requirement/RequiredPermission.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.chestcommands.icon.requirement; - -import me.filoghost.chestcommands.config.Lang; -import me.filoghost.commons.Strings; -import org.bukkit.entity.Player; - -public class RequiredPermission implements Requirement { - - private String permission; - private boolean negated; - private String noPermissionMessage; - - public void setPermission(String permission) { - if (permission != null) { - permission = permission.trim(); - } - - if (Strings.isEmpty(permission)) { - this.permission = null; - negated = false; - } else { - if (permission.startsWith("-")) { - this.permission = permission.substring(1); - negated = true; - } else { - this.permission = permission; - negated = false; - } - } - } - - - public void setNoPermissionMessage(String noPermissionMessage) { - this.noPermissionMessage = noPermissionMessage; - } - - - @Override - public boolean hasCost(Player player) { - if (hasPermission(player)) { - return true; - } else { - if (noPermissionMessage != null) { - player.sendMessage(noPermissionMessage); - } else { - player.sendMessage(Lang.default_no_icon_permission); - } - return false; - } - } - - public boolean hasPermission(Player player) { - if (isEmpty()) { - return true; - } - - if (negated) { - return !player.hasPermission(permission); - } else { - return player.hasPermission(permission); - } - } - - @Override - public boolean takeCost(Player player) { - return true; - } - - public boolean isEmpty() { - return this.permission == null; - } - -} From c3501816468ae0aaaedaef36a53bfed7f11789f3 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 16 Aug 2020 15:52:15 +0200 Subject: [PATCH 212/213] Rename API classes and methods --- .../chestcommands/api/ClickHandler.java | 2 +- .../chestcommands/api/ClickableIcon.java | 4 +-- .../me/filoghost/chestcommands/api/Icon.java | 2 +- .../api/{IconMenu.java => Menu.java} | 10 +++--- .../api/{MenuInventory.java => MenuView.java} | 4 +-- .../api/internal/BackendAPI.java | 4 +-- .../chestcommands/ChestCommands.java | 2 +- .../chestcommands/DefaultBackendAPI.java | 12 +++---- .../chestcommands/action/OpenMenuAction.java | 4 +-- .../chestcommands/command/CommandHandler.java | 4 +-- .../icon/InternalConfigurableIcon.java | 6 ++-- ...enuInventory.java => DefaultMenuView.java} | 12 +++---- .../inventory/MenuInventoryHolder.java | 12 +++---- .../listener/CommandListener.java | 4 +-- .../listener/InventoryListener.java | 10 +++--- .../chestcommands/listener/SignListener.java | 8 ++--- .../menu/{APIIconMenu.java => APIMenu.java} | 4 +-- .../menu/{BaseIconMenu.java => BaseMenu.java} | 26 +++++++-------- ...nternalIconMenu.java => InternalMenu.java} | 8 ++--- .../chestcommands/menu/MenuManager.java | 32 +++++++++---------- .../parsing/menu/LoadedMenu.java | 8 ++--- .../parsing/menu/MenuParser.java | 26 +++++++-------- .../chestcommands/task/TickingTask.java | 16 +++++----- 23 files changed, 110 insertions(+), 110 deletions(-) rename api/src/main/java/me/filoghost/chestcommands/api/{IconMenu.java => Menu.java} (71%) rename api/src/main/java/me/filoghost/chestcommands/api/{MenuInventory.java => MenuView.java} (78%) rename plugin/src/main/java/me/filoghost/chestcommands/inventory/{DefaultMenuInventory.java => DefaultMenuView.java} (85%) rename plugin/src/main/java/me/filoghost/chestcommands/menu/{APIIconMenu.java => APIMenu.java} (78%) rename plugin/src/main/java/me/filoghost/chestcommands/menu/{BaseIconMenu.java => BaseMenu.java} (64%) rename plugin/src/main/java/me/filoghost/chestcommands/menu/{InternalIconMenu.java => InternalMenu.java} (89%) diff --git a/api/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java b/api/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java index 1e54d7c..4e0cb27 100644 --- a/api/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java +++ b/api/src/main/java/me/filoghost/chestcommands/api/ClickHandler.java @@ -14,6 +14,6 @@ public interface ClickHandler { * @param player the player that clicked on the inventory * @return true if the inventory should be closed, false otherwise */ - ClickResult onClick(MenuInventory menuInventory, Player player); + ClickResult onClick(MenuView menuView, Player player); } diff --git a/api/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java b/api/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java index d4e263e..639f71e 100644 --- a/api/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java +++ b/api/src/main/java/me/filoghost/chestcommands/api/ClickableIcon.java @@ -14,9 +14,9 @@ public interface ClickableIcon extends Icon { ClickHandler getClickHandler(); @Override - default ClickResult onClick(MenuInventory menuInventory, Player clicker) { + default ClickResult onClick(MenuView menuView, Player clicker) { if (getClickHandler() != null) { - return getClickHandler().onClick(menuInventory, clicker); + return getClickHandler().onClick(menuView, clicker); } else { return ClickResult.KEEP_OPEN; } diff --git a/api/src/main/java/me/filoghost/chestcommands/api/Icon.java b/api/src/main/java/me/filoghost/chestcommands/api/Icon.java index 9856e4e..1ea8221 100644 --- a/api/src/main/java/me/filoghost/chestcommands/api/Icon.java +++ b/api/src/main/java/me/filoghost/chestcommands/api/Icon.java @@ -12,6 +12,6 @@ public interface Icon { ItemStack render(Player viewer); - ClickResult onClick(MenuInventory menuInventory, Player clicker); + ClickResult onClick(MenuView menuView, Player clicker); } \ No newline at end of file diff --git a/api/src/main/java/me/filoghost/chestcommands/api/IconMenu.java b/api/src/main/java/me/filoghost/chestcommands/api/Menu.java similarity index 71% rename from api/src/main/java/me/filoghost/chestcommands/api/IconMenu.java rename to api/src/main/java/me/filoghost/chestcommands/api/Menu.java index c4451eb..a338015 100644 --- a/api/src/main/java/me/filoghost/chestcommands/api/IconMenu.java +++ b/api/src/main/java/me/filoghost/chestcommands/api/Menu.java @@ -9,10 +9,10 @@ import me.filoghost.chestcommands.api.internal.BackendAPI; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -public interface IconMenu { +public interface Menu { - static IconMenu create(Plugin owner, String title, int rowCount) { - return BackendAPI.getImplementation().createIconMenu(owner, title, rowCount); + static Menu create(Plugin owner, String title, int rowCount) { + return BackendAPI.getImplementation().createMenu(owner, title, rowCount); } void setIcon(int row, int column, Icon icon); @@ -31,8 +31,8 @@ public interface IconMenu { * * @param player the player to which the menu will be displayed */ - MenuInventory open(Player player); + MenuView open(Player player); - void refreshOpenMenuInventories(); + void refreshMenuViews(); } \ No newline at end of file diff --git a/api/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java b/api/src/main/java/me/filoghost/chestcommands/api/MenuView.java similarity index 78% rename from api/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java rename to api/src/main/java/me/filoghost/chestcommands/api/MenuView.java index 9be876a..c31a422 100644 --- a/api/src/main/java/me/filoghost/chestcommands/api/MenuInventory.java +++ b/api/src/main/java/me/filoghost/chestcommands/api/MenuView.java @@ -7,12 +7,12 @@ package me.filoghost.chestcommands.api; import org.bukkit.entity.Player; -public interface MenuInventory { +public interface MenuView { void refresh(); Player getViewer(); - IconMenu getIconMenu(); + Menu getMenu(); } diff --git a/api/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java b/api/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java index b1107e9..5c3d9d4 100644 --- a/api/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java +++ b/api/src/main/java/me/filoghost/chestcommands/api/internal/BackendAPI.java @@ -6,7 +6,7 @@ package me.filoghost.chestcommands.api.internal; import me.filoghost.chestcommands.api.ConfigurableIcon; -import me.filoghost.chestcommands.api.IconMenu; +import me.filoghost.chestcommands.api.Menu; import me.filoghost.chestcommands.api.PlaceholderReplacer; import me.filoghost.chestcommands.api.StaticIcon; import me.filoghost.commons.Preconditions; @@ -36,7 +36,7 @@ public abstract class BackendAPI { public abstract boolean openPluginMenu(Player player, String menuFileName); - public abstract IconMenu createIconMenu(Plugin owner, String title, int rows); + public abstract Menu createMenu(Plugin owner, String title, int rows); public abstract ConfigurableIcon createConfigurableIcon(Material material); diff --git a/plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 12033b9..14293bc 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -189,7 +189,7 @@ public class ChestCommands extends BaseJavaPlugin { public static void closeAllMenus() { for (Player player : Bukkit.getOnlinePlayers()) { - if (MenuManager.getOpenMenuInventory(player) != null) { + if (MenuManager.getOpenMenuView(player) != null) { player.closeInventory(); } } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java b/plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java index 27c3ccc..f8924c1 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/DefaultBackendAPI.java @@ -6,14 +6,14 @@ package me.filoghost.chestcommands; import me.filoghost.chestcommands.api.ConfigurableIcon; -import me.filoghost.chestcommands.api.IconMenu; +import me.filoghost.chestcommands.api.Menu; import me.filoghost.chestcommands.api.PlaceholderReplacer; import me.filoghost.chestcommands.api.StaticIcon; import me.filoghost.chestcommands.api.internal.BackendAPI; import me.filoghost.chestcommands.icon.APIConfigurableIcon; import me.filoghost.chestcommands.icon.APIStaticIcon; -import me.filoghost.chestcommands.menu.APIIconMenu; -import me.filoghost.chestcommands.menu.InternalIconMenu; +import me.filoghost.chestcommands.menu.APIMenu; +import me.filoghost.chestcommands.menu.InternalMenu; import me.filoghost.chestcommands.placeholder.PlaceholderManager; import me.filoghost.commons.Preconditions; import org.bukkit.Material; @@ -35,7 +35,7 @@ public class DefaultBackendAPI extends BackendAPI { Preconditions.notNull(player, "player"); Preconditions.notNull(menuFileName, "menuFileName"); - InternalIconMenu menu = ChestCommands.getMenuManager().getMenuByFileName(menuFileName); + InternalMenu menu = ChestCommands.getMenuManager().getMenuByFileName(menuFileName); if (menu != null) { menu.open(player); @@ -51,8 +51,8 @@ public class DefaultBackendAPI extends BackendAPI { } @Override - public IconMenu createIconMenu(Plugin owner, String title, int rows) { - return new APIIconMenu(owner, title, rows); + public Menu createMenu(Plugin owner, String title, int rows) { + return new APIMenu(owner, title, rows); } @Override diff --git a/plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java b/plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java index effd8b0..0f17da5 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/action/OpenMenuAction.java @@ -7,7 +7,7 @@ package me.filoghost.chestcommands.action; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.logging.Errors; -import me.filoghost.chestcommands.menu.InternalIconMenu; +import me.filoghost.chestcommands.menu.InternalMenu; import me.filoghost.chestcommands.placeholder.PlaceholderString; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -23,7 +23,7 @@ public class OpenMenuAction implements Action { @Override public void execute(final Player player) { String menuName = targetMenu.getValue(player); - final InternalIconMenu menu = ChestCommands.getMenuManager().getMenuByFileName(menuName); + final InternalMenu menu = ChestCommands.getMenuManager().getMenuByFileName(menuName); if (menu != null) { /* diff --git a/plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java b/plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java index 6b89ff1..14899cf 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/command/CommandHandler.java @@ -7,7 +7,7 @@ package me.filoghost.chestcommands.command; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.Permissions; -import me.filoghost.chestcommands.menu.InternalIconMenu; +import me.filoghost.chestcommands.menu.InternalMenu; import me.filoghost.chestcommands.menu.MenuManager; import me.filoghost.chestcommands.util.Utils; import me.filoghost.commons.command.CommandFramework; @@ -110,7 +110,7 @@ public class CommandHandler extends CommandFramework { CommandValidate.notNull(target, "That player is not online."); String menuName = Utils.addYamlExtension(args[1]); - InternalIconMenu menu = menuManager.getMenuByFileName(menuName); + InternalMenu menu = menuManager.getMenuByFileName(menuName); CommandValidate.notNull(menu, "The menu \"" + menuName + "\" was not found."); if (!sender.hasPermission(menu.getOpenPermission())) { diff --git a/plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java b/plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java index 09f4bb1..e925b27 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/icon/InternalConfigurableIcon.java @@ -9,7 +9,7 @@ import com.google.common.collect.ImmutableList; import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.OpenMenuAction; import me.filoghost.chestcommands.api.ClickResult; -import me.filoghost.chestcommands.api.MenuInventory; +import me.filoghost.chestcommands.api.MenuView; import me.filoghost.chestcommands.config.Lang; import me.filoghost.chestcommands.icon.requirement.RequiredExpLevel; import me.filoghost.chestcommands.icon.requirement.RequiredMoney; @@ -114,7 +114,7 @@ public class InternalConfigurableIcon extends BaseConfigurableIcon implements Re } @Override - public ClickResult onClick(MenuInventory menuInventory, Player player) { + public ClickResult onClick(MenuView menuView, Player player) { if (!IconPermission.hasPermission(player, viewPermission)) { return ClickResult.KEEP_OPEN; } @@ -154,7 +154,7 @@ public class InternalConfigurableIcon extends BaseConfigurableIcon implements Re } // Update the menu after taking requirement costs and executing all actions - menuInventory.refresh(); + menuView.refresh(); // Force menu to stay open if actions open another menu if (hasOpenMenuAction) { diff --git a/plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java b/plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuView.java similarity index 85% rename from plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java rename to plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuView.java index c54f961..0d8a5b3 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuInventory.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuView.java @@ -7,22 +7,22 @@ package me.filoghost.chestcommands.inventory; import me.filoghost.chestcommands.api.ClickResult; import me.filoghost.chestcommands.api.Icon; -import me.filoghost.chestcommands.api.MenuInventory; +import me.filoghost.chestcommands.api.MenuView; import me.filoghost.chestcommands.icon.RefreshableIcon; -import me.filoghost.chestcommands.menu.BaseIconMenu; +import me.filoghost.chestcommands.menu.BaseMenu; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; /** * Represents a particular view of a menu. */ -public class DefaultMenuInventory implements MenuInventory { +public class DefaultMenuView implements MenuView { - private final BaseIconMenu menu; + private final BaseMenu menu; private final InventoryGrid bukkitInventory; private final Player viewer; - public DefaultMenuInventory(BaseIconMenu menu, Player viewer) { + public DefaultMenuView(BaseMenu menu, Player viewer) { this.menu = menu; this.viewer = viewer; this.bukkitInventory = new InventoryGrid(new MenuInventoryHolder(this), menu.getRowCount(), menu.getTitle()); @@ -63,7 +63,7 @@ public class DefaultMenuInventory implements MenuInventory { } @Override - public BaseIconMenu getIconMenu() { + public BaseMenu getMenu() { return menu; } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java b/plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java index 5af6fbc..9f53dfc 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/inventory/MenuInventoryHolder.java @@ -12,11 +12,11 @@ import org.bukkit.inventory.InventoryHolder; public class MenuInventoryHolder implements InventoryHolder { - private final DefaultMenuInventory menuInventory; + private final DefaultMenuView menuView; - public MenuInventoryHolder(DefaultMenuInventory menuInventory) { - Preconditions.notNull(menuInventory, "menuInventory"); - this.menuInventory = menuInventory; + public MenuInventoryHolder(DefaultMenuView menuView) { + Preconditions.notNull(menuView, "menuView"); + this.menuView = menuView; } @Override @@ -30,7 +30,7 @@ public class MenuInventoryHolder implements InventoryHolder { return Bukkit.createInventory(null, 9); } - public DefaultMenuInventory getMenuInventory() { - return menuInventory; + public DefaultMenuView getMenuView() { + return menuView; } } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java b/plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java index 6605944..883ef95 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/listener/CommandListener.java @@ -5,7 +5,7 @@ */ package me.filoghost.chestcommands.listener; -import me.filoghost.chestcommands.menu.InternalIconMenu; +import me.filoghost.chestcommands.menu.InternalMenu; import me.filoghost.chestcommands.menu.MenuManager; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -27,7 +27,7 @@ public class CommandListener implements Listener { return; } - InternalIconMenu menu = menuManager.getMenuByOpenCommand(command); + InternalMenu menu = menuManager.getMenuByOpenCommand(command); if (menu == null) { return; } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index 6efb09a..631ab10 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -8,8 +8,8 @@ package me.filoghost.chestcommands.listener; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.api.ClickResult; import me.filoghost.chestcommands.config.Settings; -import me.filoghost.chestcommands.inventory.DefaultMenuInventory; -import me.filoghost.chestcommands.inventory.DefaultMenuInventory.SlotClickHandler; +import me.filoghost.chestcommands.inventory.DefaultMenuView; +import me.filoghost.chestcommands.inventory.DefaultMenuView.SlotClickHandler; import me.filoghost.chestcommands.menu.MenuManager; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -53,8 +53,8 @@ public class InventoryListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) public void onLateInventoryClick(InventoryClickEvent event) { Inventory inventory = event.getInventory(); - DefaultMenuInventory menuInventory = MenuManager.getOpenMenuInventory(inventory); - if (menuInventory == null) { + DefaultMenuView menuView = MenuManager.getOpenMenuView(inventory); + if (menuView == null) { return; } @@ -63,7 +63,7 @@ public class InventoryListener implements Listener { int slot = event.getRawSlot(); Player clicker = (Player) event.getWhoClicked(); - SlotClickHandler slotClickHandler = menuInventory.getSlotClickHandler(slot, clicker); + SlotClickHandler slotClickHandler = menuView.getSlotClickHandler(slot, clicker); if (slotClickHandler == null) { return; } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java b/plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java index 01a71c7..2a16834 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/listener/SignListener.java @@ -7,7 +7,7 @@ package me.filoghost.chestcommands.listener; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.config.Lang; -import me.filoghost.chestcommands.menu.InternalIconMenu; +import me.filoghost.chestcommands.menu.InternalMenu; import me.filoghost.chestcommands.menu.MenuManager; import me.filoghost.chestcommands.util.Utils; import org.bukkit.ChatColor; @@ -56,7 +56,7 @@ public class SignListener implements Listener { } String menuFileName = Utils.addYamlExtension(sign.getLine(FILENAME_LINE).trim()); - InternalIconMenu menu = menuManager.getMenuByFileName(menuFileName); + InternalMenu menu = menuManager.getMenuByFileName(menuFileName); if (menu == null) { event.getPlayer().sendMessage(Lang.menu_not_found); @@ -81,8 +81,8 @@ public class SignListener implements Listener { menuFileName = Utils.addYamlExtension(menuFileName); - InternalIconMenu iconMenu = menuManager.getMenuByFileName(menuFileName); - if (iconMenu == null) { + InternalMenu menu = menuManager.getMenuByFileName(menuFileName); + if (menu == null) { event.setCancelled(true); player.sendMessage(ChatColor.RED + "Menu \"" + menuFileName + "\" was not found."); return; diff --git a/plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java b/plugin/src/main/java/me/filoghost/chestcommands/menu/APIMenu.java similarity index 78% rename from plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java rename to plugin/src/main/java/me/filoghost/chestcommands/menu/APIMenu.java index 32a1989..17b4826 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/menu/APIIconMenu.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/menu/APIMenu.java @@ -8,11 +8,11 @@ package me.filoghost.chestcommands.menu; import me.filoghost.commons.Preconditions; import org.bukkit.plugin.Plugin; -public class APIIconMenu extends BaseIconMenu { +public class APIMenu extends BaseMenu { private final Plugin owner; - public APIIconMenu(Plugin owner, String title, int rows) { + public APIMenu(Plugin owner, String title, int rows) { super(title, rows); Preconditions.notNull(owner, "owner"); this.owner = owner; diff --git a/plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java b/plugin/src/main/java/me/filoghost/chestcommands/menu/BaseMenu.java similarity index 64% rename from plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java rename to plugin/src/main/java/me/filoghost/chestcommands/menu/BaseMenu.java index ac1f1cd..4bb153c 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/menu/BaseMenu.java @@ -6,23 +6,23 @@ package me.filoghost.chestcommands.menu; import me.filoghost.chestcommands.api.Icon; -import me.filoghost.chestcommands.api.IconMenu; -import me.filoghost.chestcommands.api.MenuInventory; +import me.filoghost.chestcommands.api.Menu; +import me.filoghost.chestcommands.api.MenuView; import me.filoghost.chestcommands.inventory.ArrayGrid; -import me.filoghost.chestcommands.inventory.DefaultMenuInventory; +import me.filoghost.chestcommands.inventory.DefaultMenuView; import me.filoghost.chestcommands.inventory.Grid; import me.filoghost.commons.Preconditions; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -public abstract class BaseIconMenu implements IconMenu { +public abstract class BaseMenu implements Menu { protected final String title; protected final Grid icons; - public BaseIconMenu(String title, int rows) { + public BaseMenu(String title, int rows) { Preconditions.notNull(title, "title"); Preconditions.checkArgument(rows > 0, "rows must be greater than 0"); this.title = title; @@ -59,20 +59,20 @@ public abstract class BaseIconMenu implements IconMenu { } @Override - public MenuInventory open(Player player) { + public MenuView open(Player player) { Preconditions.notNull(player, "player"); - DefaultMenuInventory menuInventory = new DefaultMenuInventory(this, player); - menuInventory.open(player); - return menuInventory; + DefaultMenuView menuView = new DefaultMenuView(this, player); + menuView.open(player); + return menuView; } @Override - public void refreshOpenMenuInventories() { + public void refreshMenuViews() { for (Player player : Bukkit.getOnlinePlayers()) { - DefaultMenuInventory menuInventory = MenuManager.getOpenMenuInventory(player); - if (menuInventory != null && menuInventory.getIconMenu() == this) { - menuInventory.refresh(); + DefaultMenuView menuView = MenuManager.getOpenMenuView(player); + if (menuView != null && menuView.getMenu() == this) { + menuView.refresh(); } } } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java b/plugin/src/main/java/me/filoghost/chestcommands/menu/InternalMenu.java similarity index 89% rename from plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java rename to plugin/src/main/java/me/filoghost/chestcommands/menu/InternalMenu.java index 3d52714..34fddf1 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/menu/InternalIconMenu.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/menu/InternalMenu.java @@ -8,7 +8,7 @@ package me.filoghost.chestcommands.menu; import com.google.common.collect.ImmutableList; import me.filoghost.chestcommands.Permissions; import me.filoghost.chestcommands.action.Action; -import me.filoghost.chestcommands.api.MenuInventory; +import me.filoghost.chestcommands.api.MenuView; import me.filoghost.chestcommands.config.Lang; import me.filoghost.commons.collection.CollectionUtils; import org.bukkit.command.CommandSender; @@ -17,7 +17,7 @@ import org.bukkit.entity.Player; import java.nio.file.Path; import java.util.List; -public class InternalIconMenu extends BaseIconMenu { +public class InternalMenu extends BaseMenu { private final Path sourceFile; private final String openPermission; @@ -25,7 +25,7 @@ public class InternalIconMenu extends BaseIconMenu { private ImmutableList openActions; private int refreshTicks; - public InternalIconMenu(String title, int rows, Path sourceFile) { + public InternalMenu(String title, int rows, Path sourceFile) { super(title, rows); this.sourceFile = sourceFile; this.openPermission = Permissions.OPEN_MENU_PREFIX + sourceFile.getFileName(); @@ -52,7 +52,7 @@ public class InternalIconMenu extends BaseIconMenu { } @Override - public MenuInventory open(Player player) { + public MenuView open(Player player) { if (openActions != null) { for (Action openAction : openActions) { openAction.execute(player); diff --git a/plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java b/plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java index d59ae5b..5310a31 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/menu/MenuManager.java @@ -5,7 +5,7 @@ */ package me.filoghost.chestcommands.menu; -import me.filoghost.chestcommands.inventory.DefaultMenuInventory; +import me.filoghost.chestcommands.inventory.DefaultMenuView; import me.filoghost.chestcommands.inventory.MenuInventoryHolder; import me.filoghost.chestcommands.logging.Errors; import me.filoghost.chestcommands.parsing.menu.LoadedMenu; @@ -25,9 +25,9 @@ import java.util.Map; public class MenuManager { - private static Map menusByFile; - private static Map menusByOpenCommand; - private static Map menusByOpenItem; + private static Map menusByFile; + private static Map menusByOpenCommand; + private static Map menusByOpenItem; public MenuManager() { menusByFile = new CaseInsensitiveMap<>(); @@ -41,15 +41,15 @@ public class MenuManager { menusByOpenItem.clear(); } - public InternalIconMenu getMenuByFileName(String fileName) { + public InternalMenu getMenuByFileName(String fileName) { return menusByFile.get(fileName); } public void registerMenu(LoadedMenu loadedMenu, ErrorCollector errorCollector) { - InternalIconMenu menu = loadedMenu.getMenu(); + InternalMenu menu = loadedMenu.getMenu(); String fileName = loadedMenu.getSourceFile().getFileName().toString(); - InternalIconMenu sameNameMenu = menusByFile.get(fileName); + InternalMenu sameNameMenu = menusByFile.get(fileName); if (sameNameMenu != null) { errorCollector.add(Errors.Menu.duplicateMenuName(sameNameMenu.getSourceFile(), loadedMenu.getSourceFile())); } @@ -58,7 +58,7 @@ public class MenuManager { if (loadedMenu.getOpenCommands() != null) { for (String openCommand : loadedMenu.getOpenCommands()) { if (!openCommand.isEmpty()) { - InternalIconMenu sameCommandMenu = menusByOpenCommand.get(openCommand); + InternalMenu sameCommandMenu = menusByOpenCommand.get(openCommand); if (sameCommandMenu != null) { errorCollector.add(Errors.Menu.duplicateMenuCommand(sameCommandMenu.getSourceFile(), loadedMenu.getSourceFile(), openCommand)); } @@ -80,7 +80,7 @@ public class MenuManager { }); } - public InternalIconMenu getMenuByOpenCommand(String openCommand) { + public InternalMenu getMenuByOpenCommand(String openCommand) { return menusByOpenCommand.get(openCommand); } @@ -92,25 +92,25 @@ public class MenuManager { return getMenuInventoryHolder(inventory) != null; } - public static DefaultMenuInventory getOpenMenuInventory(Player player) { + public static DefaultMenuView getOpenMenuView(Player player) { InventoryView view = player.getOpenInventory(); if (view == null) { return null; } - DefaultMenuInventory menuInventory = getOpenMenuInventory(view.getTopInventory()); - if (menuInventory == null) { - menuInventory = getOpenMenuInventory(view.getBottomInventory()); + DefaultMenuView menuView = getOpenMenuView(view.getTopInventory()); + if (menuView == null) { + menuView = getOpenMenuView(view.getBottomInventory()); } - return menuInventory; + return menuView; } - public static DefaultMenuInventory getOpenMenuInventory(Inventory inventory) { + public static DefaultMenuView getOpenMenuView(Inventory inventory) { MenuInventoryHolder inventoryHolder = getMenuInventoryHolder(inventory); if (inventoryHolder != null) { - return inventoryHolder.getMenuInventory(); + return inventoryHolder.getMenuView(); } else { return null; } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java index 65a3e68..ea77b32 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/LoadedMenu.java @@ -6,7 +6,7 @@ package me.filoghost.chestcommands.parsing.menu; import com.google.common.collect.ImmutableList; -import me.filoghost.chestcommands.menu.InternalIconMenu; +import me.filoghost.chestcommands.menu.InternalMenu; import me.filoghost.commons.collection.CollectionUtils; import java.nio.file.Path; @@ -14,19 +14,19 @@ import java.util.List; public class LoadedMenu { - private final InternalIconMenu menu; + private final InternalMenu menu; private final Path sourceFile; private final ImmutableList openCommands; private final MenuOpenItem openItem; - public LoadedMenu(InternalIconMenu menu, Path menuFile, List openCommands, MenuOpenItem openItem) { + public LoadedMenu(InternalMenu menu, Path menuFile, List openCommands, MenuOpenItem openItem) { this.menu = menu; this.sourceFile = menuFile; this.openCommands = CollectionUtils.immutableCopy(openCommands); this.openItem = openItem; } - public InternalIconMenu getMenu() { + public InternalMenu getMenu() { return menu; } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index f1f9db5..10ba38b 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -9,7 +9,7 @@ import me.filoghost.chestcommands.action.Action; import me.filoghost.chestcommands.action.DisabledAction; import me.filoghost.chestcommands.attribute.PositionAttribute; import me.filoghost.chestcommands.logging.Errors; -import me.filoghost.chestcommands.menu.InternalIconMenu; +import me.filoghost.chestcommands.menu.InternalMenu; import me.filoghost.chestcommands.parsing.ActionParser; import me.filoghost.chestcommands.parsing.ItemStackParser; import me.filoghost.chestcommands.parsing.ParseException; @@ -34,20 +34,20 @@ public class MenuParser { MenuSettings menuSettings = loadMenuSettings(menuConfig, errorCollector); List iconSettingsList = loadIconSettingsList(menuConfig, errorCollector); - InternalIconMenu iconMenu = new InternalIconMenu(menuSettings.getTitle(), menuSettings.getRows(), menuConfig.getSourceFile()); + InternalMenu menu = new InternalMenu(menuSettings.getTitle(), menuSettings.getRows(), menuConfig.getSourceFile()); for (IconSettings iconSettings : iconSettingsList) { - tryAddIconToMenu(iconMenu, iconSettings, errorCollector); + tryAddIconToMenu(menu, iconSettings, errorCollector); } - iconMenu.setRefreshTicks(menuSettings.getRefreshTicks()); - iconMenu.setOpenActions(menuSettings.getOpenActions()); + menu.setRefreshTicks(menuSettings.getRefreshTicks()); + menu.setOpenActions(menuSettings.getOpenActions()); - return new LoadedMenu(iconMenu, menuConfig.getSourceFile(), menuSettings.getCommands(), menuSettings.getOpenItem()); + return new LoadedMenu(menu, menuConfig.getSourceFile(), menuSettings.getCommands(), menuSettings.getOpenItem()); } - private static void tryAddIconToMenu(InternalIconMenu iconMenu, IconSettings iconSettings, ErrorCollector errorCollector) { + private static void tryAddIconToMenu(InternalMenu menu, IconSettings iconSettings, ErrorCollector errorCollector) { PositionAttribute positionX = (PositionAttribute) iconSettings.getAttributeValue(AttributeType.POSITION_X); PositionAttribute positionY = (PositionAttribute) iconSettings.getAttributeValue(AttributeType.POSITION_Y); @@ -64,20 +64,20 @@ public class MenuParser { int row = positionY.getPosition() - 1; int column = positionX.getPosition() - 1; - if (row < 0 || row >= iconMenu.getRowCount()) { + if (row < 0 || row >= menu.getRowCount()) { errorCollector.add( Errors.Menu.invalidAttribute(iconSettings, AttributeType.POSITION_Y), - "it must be between 1 and " + iconMenu.getRowCount()); + "it must be between 1 and " + menu.getRowCount()); return; } - if (column < 0 || column >= iconMenu.getColumnCount()) { + if (column < 0 || column >= menu.getColumnCount()) { errorCollector.add( Errors.Menu.invalidAttribute(iconSettings, AttributeType.POSITION_X), - "it must be between 1 and " + iconMenu.getColumnCount()); + "it must be between 1 and " + menu.getColumnCount()); return; } - if (iconMenu.getIcon(row, column) != null) { + if (menu.getIcon(row, column) != null) { errorCollector.add(Errors.Menu.iconOverridesAnother(iconSettings)); } @@ -85,7 +85,7 @@ public class MenuParser { errorCollector.add(Errors.Menu.missingAttribute(iconSettings, AttributeType.MATERIAL)); } - iconMenu.setIcon(row, column, iconSettings.createIcon()); + menu.setIcon(row, column, iconSettings.createIcon()); } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java b/plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java index bc8ef33..7627b9e 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/task/TickingTask.java @@ -5,8 +5,8 @@ */ package me.filoghost.chestcommands.task; -import me.filoghost.chestcommands.inventory.DefaultMenuInventory; -import me.filoghost.chestcommands.menu.InternalIconMenu; +import me.filoghost.chestcommands.inventory.DefaultMenuView; +import me.filoghost.chestcommands.menu.InternalMenu; import me.filoghost.chestcommands.menu.MenuManager; import me.filoghost.chestcommands.placeholder.PlaceholderManager; import org.bukkit.Bukkit; @@ -18,24 +18,24 @@ public class TickingTask implements Runnable { @Override public void run() { - updateInventories(); + updateMenus(); PlaceholderManager.onTick(); currentTick++; } - private void updateInventories() { + private void updateMenus() { for (Player player : Bukkit.getOnlinePlayers()) { - DefaultMenuInventory menuInventory = MenuManager.getOpenMenuInventory(player); + DefaultMenuView menuView = MenuManager.getOpenMenuView(player); - if (menuInventory == null || !(menuInventory.getIconMenu() instanceof InternalIconMenu)) { + if (menuView == null || !(menuView.getMenu() instanceof InternalMenu)) { continue; } - int refreshTicks = ((InternalIconMenu) menuInventory.getIconMenu()).getRefreshTicks(); + int refreshTicks = ((InternalMenu) menuView.getMenu()).getRefreshTicks(); if (refreshTicks > 0 && currentTick % refreshTicks == 0) { - menuInventory.refresh(); + menuView.refresh(); } } } From 8e54e55e3a510f0cc0bbd64f9365d66976fdf770 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 16 Aug 2020 16:03:26 +0200 Subject: [PATCH 213/213] Simplify code --- .../inventory/DefaultMenuView.java | 18 ++---------------- .../listener/InventoryListener.java | 8 ++++---- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuView.java b/plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuView.java index 0d8a5b3..89f0a9b 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuView.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/inventory/DefaultMenuView.java @@ -5,7 +5,6 @@ */ package me.filoghost.chestcommands.inventory; -import me.filoghost.chestcommands.api.ClickResult; import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.api.MenuView; import me.filoghost.chestcommands.icon.RefreshableIcon; @@ -49,17 +48,12 @@ public class DefaultMenuView implements MenuView { viewer.openInventory(bukkitInventory.getInventory()); } - public SlotClickHandler getSlotClickHandler(int slot, Player clicker) { + public Icon getIcon(int slot) { if (slot < 0 || slot >= bukkitInventory.getSize()) { return null; } - Icon icon = menu.getIcons().getByIndex(slot); - if (icon == null) { - return null; - } - - return () -> icon.onClick(this, clicker); + return menu.getIcons().getByIndex(slot); } @Override @@ -72,12 +66,4 @@ public class DefaultMenuView implements MenuView { return viewer; } - - @FunctionalInterface - public interface SlotClickHandler { - - ClickResult onClick(); - - } - } diff --git a/plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index 631ab10..faee40a 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -7,9 +7,9 @@ package me.filoghost.chestcommands.listener; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.api.ClickResult; +import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.config.Settings; import me.filoghost.chestcommands.inventory.DefaultMenuView; -import me.filoghost.chestcommands.inventory.DefaultMenuView.SlotClickHandler; import me.filoghost.chestcommands.menu.MenuManager; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -63,8 +63,8 @@ public class InventoryListener implements Listener { int slot = event.getRawSlot(); Player clicker = (Player) event.getWhoClicked(); - SlotClickHandler slotClickHandler = menuView.getSlotClickHandler(slot, clicker); - if (slotClickHandler == null) { + Icon icon = menuView.getIcon(slot); + if (icon == null) { return; } @@ -82,7 +82,7 @@ public class InventoryListener implements Listener { // Only handle the click AFTER the event has finished Bukkit.getScheduler().runTask(ChestCommands.getPluginInstance(), () -> { - ClickResult result = slotClickHandler.onClick(); + ClickResult result = icon.onClick(menuView, clicker); if (result == ClickResult.CLOSE) { clicker.closeInventory();