diff --git a/Core/src/main/java/dev/mrshawn/deathmessages/DeathMessages.java b/Core/src/main/java/dev/mrshawn/deathmessages/DeathMessages.java index 9e4b25e2..66798841 100644 --- a/Core/src/main/java/dev/mrshawn/deathmessages/DeathMessages.java +++ b/Core/src/main/java/dev/mrshawn/deathmessages/DeathMessages.java @@ -17,7 +17,6 @@ import dev.mrshawn.deathmessages.listeners.EntityDamageByBlock; import dev.mrshawn.deathmessages.listeners.EntityDamageByEntity; import dev.mrshawn.deathmessages.listeners.EntityDeath; -import dev.mrshawn.deathmessages.listeners.OnChat; import dev.mrshawn.deathmessages.listeners.OnInteract; import dev.mrshawn.deathmessages.listeners.OnJoin; import dev.mrshawn.deathmessages.listeners.OnMove; @@ -78,12 +77,13 @@ public class DeathMessages extends JavaPlugin { private static EventPriority eventPriority = EventPriority.HIGH; - // Dreeam - eg. 1.20.2-R0.1-SNAPSHOT -> 20, replace string before first decimal point, then replace all string after the second decimal point + // Dreeam - e.g. 1.20.2-R0.1-SNAPSHOT -> 20, replace string before first decimal point, then replace all string after the second decimal point public final static int majorVersion = Integer.parseInt(Bukkit.getServer().getBukkitVersion() .replaceFirst("^(\\d+)\\.", "") .replaceAll("\\.(.+)", "") ); + @Override public void onEnable() { instance = this; LOGGER = LogManager.getLogger(instance.getName()); @@ -107,6 +107,7 @@ public void onEnable() { public void onLoad() { } + @Override public void onDisable() { if (this.adventure != null) { this.adventure.close(); @@ -134,7 +135,6 @@ private void initListeners() { new EntityDamageByBlock(), new EntityDamageByEntity(), new EntityDeath(), - new OnChat(), new OnInteract(), new OnJoin(), new OnMove(), diff --git a/Core/src/main/java/dev/mrshawn/deathmessages/commands/CommandEdit.java b/Core/src/main/java/dev/mrshawn/deathmessages/commands/CommandEdit.java deleted file mode 100644 index e2c9cfc6..00000000 --- a/Core/src/main/java/dev/mrshawn/deathmessages/commands/CommandEdit.java +++ /dev/null @@ -1,180 +0,0 @@ -package dev.mrshawn.deathmessages.commands; - -import dev.mrshawn.deathmessages.DeathMessages; -import dev.mrshawn.deathmessages.config.legacy.EntityDeathMessages; -import dev.mrshawn.deathmessages.config.legacy.PlayerDeathMessages; -import dev.mrshawn.deathmessages.enums.DamageTypes; -import dev.mrshawn.deathmessages.enums.Permission; -import dev.mrshawn.deathmessages.utils.Assets; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TextReplacementConfig; -import net.kyori.adventure.text.format.NamedTextColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.EntityType; - -import java.util.List; - -// Dreeam - Really useless -@Deprecated -public class CommandEdit extends DeathMessagesCommand { - - @Override - public String command() { - return "edit"; - } - - @Override - public void onCommand(CommandSender sender, String[] args) { - // /dm edit (remove=placeholder) - if (!sender.hasPermission(Permission.DEATHMESSAGES_COMMAND_EDIT.getValue())) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.No-Permission")); - return; - } - - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Component.text("You are trying to use a deprecated command. Command edit will be removed since DeathMessages 1.4.19", NamedTextColor.RED)); - - if (args.length <= 3) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Usage")); - } else { - if (args[0].equalsIgnoreCase("player")) { - String mobName = args[1]; - String damageType = args[3]; - boolean exists = false; - for (EntityType entityType : EntityType.values()) { - // Check isAlive as getSimpleName could be null if the entity is not living - if (entityType.isAlive() && entityType.getEntityClass().getSimpleName().equalsIgnoreCase(mobName)) { - exists = true; - break; - } - } - if (!exists) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Invalid-Mob-Type")); - return; - } - if (!DamageTypes.getFriendlyNames().contains(damageType)) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Invalid-Damage-Type")); - return; - } - if (args[4].equalsIgnoreCase("add")) { - if (args[2].equalsIgnoreCase("solo")) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Adding-Start")); - Assets.addingMessage.put(sender.getName(), "Solo:" + mobName + ":" + damageType); - } else if (args[2].equalsIgnoreCase("gang")) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Adding-Start")); - Assets.addingMessage.put(sender.getName(), "Gang:" + mobName + ":" + damageType); - } else { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Invalid-Arguments")); - } - } else if (args[4].equalsIgnoreCase("remove")) { - if (args[5] == null) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Invalid-Arguments")); - return; - } - if (!Assets.isNumeric(args[5])) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Invalid-Placeholder")); - return; - } - int placeholder = Integer.parseInt(args[5]) - 1; - if (args[2].equalsIgnoreCase("solo")) { - List list = PlayerDeathMessages.getInstance().getConfig().getStringList("Mobs." + mobName + ".Solo." + damageType); - if (list.get(placeholder) == null) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Invalid-Selection")); - return; - } - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Removed-Message").replaceText(TextReplacementConfig.builder().matchLiteral("%message%").replacement(list.get(placeholder)).build())); - list.remove(placeholder); - PlayerDeathMessages.getInstance().getConfig().set("Mobs." + mobName + ".Solo." + damageType, list); - PlayerDeathMessages.getInstance().save(); - PlayerDeathMessages.getInstance().reload(); - } else if (args[2].equalsIgnoreCase("gang")) { - List list = PlayerDeathMessages.getInstance().getConfig().getStringList("Mobs." + mobName + ".Gang." + damageType); - if (list.get(placeholder) == null) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Invalid-Selection")); - return; - } - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Removed-Message").replaceText(TextReplacementConfig.builder().matchLiteral("%message%").replacement(list.get(placeholder)).build())); - list.remove(placeholder); - PlayerDeathMessages.getInstance().getConfig().set("Mobs." + mobName + ".Gang." + damageType, list); - PlayerDeathMessages.getInstance().save(); - PlayerDeathMessages.getInstance().reload(); - } - - - } else if (args[4].equalsIgnoreCase("list")) { - int placeholder = 1; - if (args[2].equalsIgnoreCase("solo")) { - List list = PlayerDeathMessages.getInstance().getConfig().getStringList("Mobs." + mobName + ".Solo." + damageType); - for (String messages : list) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.convertFromLegacy("[" + placeholder + "] " + messages).replaceText(Assets.prefix)); - placeholder++; - } - } else if (args[2].equalsIgnoreCase("gang")) { - List list = PlayerDeathMessages.getInstance().getConfig().getStringList("Mobs." + mobName + ".Gang." + damageType); - for (String messages : list) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.convertFromLegacy("[" + placeholder + "] " + messages).replaceText(Assets.prefix)); - placeholder++; - } - } else { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Invalid-Arguments")); - } - } else { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Invalid-Arguments")); - } - } else if (args[0].equalsIgnoreCase("entity")) { - String mobName = args[1]; - String damageType = args[2]; - boolean exists = false; - for (EntityType entityType : EntityType.values()) { - // Check isAlive as getSimpleName could be null if the entity is not living - if (entityType.isAlive() && entityType.getEntityClass().getSimpleName().equalsIgnoreCase(mobName)) { - exists = true; - break; - } - } - if (!exists) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Invalid-Mob-Type")); - return; - } - if (!DamageTypes.getFriendlyNames().contains(damageType)) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Invalid-Damage-Type")); - return; - } - if (args[3].equalsIgnoreCase("add")) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Adding-Start")); - Assets.addingMessage.put(sender.getName(), mobName + ":" + damageType); - } else if (args[3].equalsIgnoreCase("remove")) { - if (args[4] == null) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Invalid-Arguments")); - return; - } - if (!Assets.isNumeric(args[4])) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Invalid-Placeholder")); - return; - } - int placeholder = Integer.parseInt(args[4]) - 1; - List list = EntityDeathMessages.getInstance().getConfig().getStringList("Entities." + mobName + "." + damageType); - if (list.get(placeholder) == null) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Invalid-Selection")); - return; - } - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Removed-Message").replaceText(TextReplacementConfig.builder().matchLiteral("%message%").replacement(list.get(placeholder)).build())); - list.remove(placeholder); - EntityDeathMessages.getInstance().getConfig().set("Entities." + mobName + "." + damageType, list); - EntityDeathMessages.getInstance().save(); - EntityDeathMessages.getInstance().reload(); - - - } else if (args[3].equalsIgnoreCase("list")) { - int placeholder = 1; - List list = EntityDeathMessages.getInstance().getConfig().getStringList("Entities." + mobName + "." + damageType); - for (String messages : list) { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.convertFromLegacy("[" + placeholder + "] " + messages).replaceText(Assets.prefix)); - placeholder++; - } - } else { - DeathMessages.getInstance().adventure().sender(sender).sendMessage(Assets.formatMessage("Commands.DeathMessages.Sub-Commands.Edit.Invalid-Arguments")); - } - } - } - } -} diff --git a/Core/src/main/java/dev/mrshawn/deathmessages/commands/TabCompleter.java b/Core/src/main/java/dev/mrshawn/deathmessages/commands/TabCompleter.java index 6fc7671b..a8a5734b 100644 --- a/Core/src/main/java/dev/mrshawn/deathmessages/commands/TabCompleter.java +++ b/Core/src/main/java/dev/mrshawn/deathmessages/commands/TabCompleter.java @@ -1,10 +1,8 @@ package dev.mrshawn.deathmessages.commands; -import dev.mrshawn.deathmessages.enums.DamageTypes; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -25,7 +23,6 @@ public List onTabComplete(CommandSender sender, Command command, String "backup", "blacklist", "discordlog", - "edit", "reload", "restore", "toggle", @@ -57,54 +54,6 @@ public List onTabComplete(CommandSender sender, Command command, String ); } - // Dreeam TODO - Command edit Will be removed since DeathMessages 1.4.19 - if (args[0].equalsIgnoreCase("edit")) { - if (args.length == 3) { - // /dm edit - if (args[1].equalsIgnoreCase("player") || args[1].equalsIgnoreCase("entity")) { - arguments.clear(); - // Not checking config cause we can add sections if we want - // List mobNames = new ArrayList<>(PlayerDeathMessages.getInstance().getConfig() - // .getConfigurationSection("Mobs").getKeys(false)); - for (EntityType entityType : EntityType.values()) { - if (entityType.isAlive()) { - arguments.add(entityType.getEntityClass().getSimpleName().toLowerCase()); - } - } - return arguments; - } - } else if (args.length == 4) { - // /dm edit - if (args[1].equalsIgnoreCase("player")) { - return Arrays.asList( - "solo", - "gang" - ); - } else if (args[1].equalsIgnoreCase("entity")) { - return DamageTypes.getFriendlyNames(); - } - } else if (args.length == 5) { - // /dm edit - if (args[1].equalsIgnoreCase("player")) { - return DamageTypes.getFriendlyNames(); - } else if (args[1].equalsIgnoreCase("entity")) { - return Arrays.asList( - "add", - "remove", - "list" - ); - } - } else if (args.length == 6) { - // /dm edit - if (args[1].equalsIgnoreCase("player")) { - return Arrays.asList( - "add", - "remove", - "list" - ); - } - } - } return null; } } diff --git a/Core/src/main/java/dev/mrshawn/deathmessages/enums/DeathModes.java b/Core/src/main/java/dev/mrshawn/deathmessages/enums/DeathModes.java index e5301209..b025f8d3 100644 --- a/Core/src/main/java/dev/mrshawn/deathmessages/enums/DeathModes.java +++ b/Core/src/main/java/dev/mrshawn/deathmessages/enums/DeathModes.java @@ -1,6 +1,7 @@ package dev.mrshawn.deathmessages.enums; public enum DeathModes { + BASIC_MODE("Basic-Mode"), MOBS("Mobs"); diff --git a/Core/src/main/java/dev/mrshawn/deathmessages/utils/Assets.java b/Core/src/main/java/dev/mrshawn/deathmessages/utils/Assets.java index fa0df888..2247e100 100644 --- a/Core/src/main/java/dev/mrshawn/deathmessages/utils/Assets.java +++ b/Core/src/main/java/dev/mrshawn/deathmessages/utils/Assets.java @@ -52,7 +52,6 @@ import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Optional; import java.util.concurrent.ThreadLocalRandom; @@ -64,8 +63,6 @@ public class Assets { // Dreeam TODO - to figure out why the value defined in private static field will not change with the change of the config value //private static final CommentedConfiguration config = Settings.getInstance().getConfig(); //private static final boolean addPrefix = config.getBoolean(Config.ADD_PREFIX_TO_ALL_MESSAGES(); - public static final HashMap addingMessage = new HashMap<>(); - public static boolean isNumeric(String s) { for (char c : s.toCharArray()) { return Character.isDigit(c); @@ -1023,6 +1020,7 @@ private static Component getI18nName(ItemStack i, Player p) { private static Component getI18nName(LivingEntity mob) { // Dreeam - TODO Component i18nName; + if (Config.settings.DISPLAY_I18N_MOB_NAME()) { i18nName = Component.empty(); } else { diff --git a/Core/src/main/java/dev/mrshawn/deathmessages/utils/EventUtils.java b/Core/src/main/java/dev/mrshawn/deathmessages/utils/EventUtils.java index fb4223db..94ff5c39 100644 --- a/Core/src/main/java/dev/mrshawn/deathmessages/utils/EventUtils.java +++ b/Core/src/main/java/dev/mrshawn/deathmessages/utils/EventUtils.java @@ -1,17 +1,14 @@ package dev.mrshawn.deathmessages.utils; import dev.mrshawn.deathmessages.DeathMessages; -import org.bukkit.Bukkit; + import org.bukkit.event.Listener; -import org.bukkit.plugin.PluginManager; public class EventUtils { public static void registerEvents(Listener... listeners) { - PluginManager pluginManager = Bukkit.getPluginManager(); - for (Listener listener : listeners) { - pluginManager.registerEvents(listener, DeathMessages.getInstance()); + DeathMessages.getInstance().getServer().getPluginManager().registerEvents(listener, DeathMessages.getInstance()); } } } \ No newline at end of file