From ab23e198046379c0dc7f5f09fd56024195dbaef1 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 6 Jan 2022 18:53:42 +0000 Subject: [PATCH] Updated eco --- build.gradle | 2 +- .../com/willfp/ecobosses/bosses/EcoBoss.java | 6 +- .../ecobosses/commands/CommandEcobosses.java | 11 +- .../ecobosses/commands/CommandGive.java | 133 +++++----- .../ecobosses/commands/CommandKillall.java | 19 +- .../ecobosses/commands/CommandReload.java | 15 +- .../ecobosses/commands/CommandSpawn.java | 232 +++++++++--------- .../ecobosses/config/BaseBossConfig.java | 7 +- .../willfp/ecobosses/config/CustomConfig.java | 4 +- 9 files changed, 213 insertions(+), 216 deletions(-) diff --git a/build.gradle b/build.gradle index da45916..aa45195 100644 --- a/build.gradle +++ b/build.gradle @@ -47,7 +47,7 @@ allprojects { } dependencies { - compileOnly 'com.willfp:eco:6.9.0' + compileOnly 'com.willfp:eco:6.17.1' compileOnly 'org.jetbrains:annotations:19.0.0' diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBoss.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBoss.java index 074c4e7..fef1636 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBoss.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBoss.java @@ -500,15 +500,15 @@ public class EcoBoss extends PluginDependent { // Messages this.spawnMessages = new ArrayList<>(); - for (String string : this.getConfig().getStrings("broadcast.spawn")) { + for (String string : this.getConfig().getFormattedStrings("broadcast.spawn")) { this.spawnMessages.add(StringUtils.format(string)); } this.deathMessages = new ArrayList<>(); - for (String string : this.getConfig().getStrings("broadcast.death")) { + for (String string : this.getConfig().getFormattedStrings("broadcast.death")) { this.deathMessages.add(StringUtils.format(string)); } this.despawnMessages = new ArrayList<>(); - for (String string : this.getConfig().getStrings("broadcast.despawn")) { + for (String string : this.getConfig().getFormattedStrings("broadcast.despawn")) { this.despawnMessages.add(StringUtils.format(string)); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandEcobosses.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandEcobosses.java index 628aada..d555776 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandEcobosses.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandEcobosses.java @@ -1,10 +1,12 @@ package com.willfp.ecobosses.commands; -import com.willfp.eco.core.command.CommandHandler; import com.willfp.eco.core.command.impl.PluginCommand; import com.willfp.ecobosses.EcoBossesPlugin; +import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; +import java.util.List; + public class CommandEcobosses extends PluginCommand { /** * Instantiate a new executor for /ebdrop. @@ -20,9 +22,8 @@ public class CommandEcobosses extends PluginCommand { } @Override - public CommandHandler getHandler() { - return (sender, args) -> { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-command")); - }; + public void onExecute(@NotNull final CommandSender sender, + @NotNull final List args) { + sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-command")); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandGive.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandGive.java index b650e29..d283ae1 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandGive.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandGive.java @@ -2,13 +2,12 @@ package com.willfp.ecobosses.commands; import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.command.CommandHandler; -import com.willfp.eco.core.command.TabCompleteHandler; import com.willfp.eco.core.command.impl.Subcommand; import com.willfp.eco.core.config.updating.ConfigUpdater; import com.willfp.ecobosses.bosses.EcoBoss; import com.willfp.ecobosses.bosses.EcoBosses; import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.util.StringUtil; @@ -62,90 +61,88 @@ public class CommandGive extends Subcommand { } @Override - public CommandHandler getHandler() { - return (sender, args) -> { - if (args.isEmpty()) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-player")); - return; + public void onExecute(@NotNull final CommandSender sender, + @NotNull final List args) { + if (args.isEmpty()) { + sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-player")); + return; + } + + if (args.size() == 1) { + sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-boss")); + return; + } + + int amount = 1; + + if (args.size() > 2) { + try { + amount = Integer.parseInt(args.get(2)); + } catch (NumberFormatException ignored) { + // do nothing } + } - if (args.size() == 1) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-boss")); - return; - } + String recieverName = args.get(0); + Player reciever = Bukkit.getPlayer(recieverName); - int amount = 1; + if (reciever == null) { + sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player")); + return; + } - if (args.size() > 2) { - try { - amount = Integer.parseInt(args.get(2)); - } catch (NumberFormatException ignored) { - // do nothing - } - } + String key = args.get(1); - String recieverName = args.get(0); - Player reciever = Bukkit.getPlayer(recieverName); + EcoBoss boss = EcoBosses.getByName(key); - if (reciever == null) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player")); - return; - } + if (boss == null || boss.getSpawnEgg() == null) { + sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-boss")); + return; + } - String key = args.get(1); + String message = this.getPlugin().getLangYml().getMessage("give-success"); + message = message.replace("%boss%", boss.getName()).replace("%recipient%", reciever.getName()); + sender.sendMessage(message); - EcoBoss boss = EcoBosses.getByName(key); - - if (boss == null || boss.getSpawnEgg() == null) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-boss")); - return; - } - - String message = this.getPlugin().getLangYml().getMessage("give-success"); - message = message.replace("%boss%", boss.getName()).replace("%recipient%", reciever.getName()); - sender.sendMessage(message); - - ItemStack itemStack = boss.getSpawnEgg(); - itemStack.setAmount(amount); - reciever.getInventory().addItem(itemStack); - }; + ItemStack itemStack = boss.getSpawnEgg(); + itemStack.setAmount(amount); + reciever.getInventory().addItem(itemStack); } @Override - public TabCompleteHandler getTabCompleter() { - return (sender, args) -> { - List completions = new ArrayList<>(); + public List tabComplete(@NotNull final CommandSender sender, + @NotNull final List args) { + List completions = new ArrayList<>(); - if (args.isEmpty()) { - // Currently, this case is not ever reached - return BOSS_NAMES; - } + if (args.isEmpty()) { + // Currently, this case is not ever reached + return BOSS_NAMES; + } - if (args.size() == 1) { - StringUtil.copyPartialMatches(args.get(0), Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()), completions); - return completions; - } + if (args.size() == 1) { + StringUtil.copyPartialMatches(args.get(0), Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()), completions); + return completions; + } - if (args.size() == 2) { - StringUtil.copyPartialMatches(args.get(1), BOSS_NAMES, completions); + if (args.size() == 2) { + StringUtil.copyPartialMatches(args.get(1), BOSS_NAMES, completions); - Collections.sort(completions); - return completions; - } + Collections.sort(completions); + return completions; + } - if (args.size() == 3) { - StringUtil.copyPartialMatches(args.get(2), NUMBERS, completions); + if (args.size() == 3) { + StringUtil.copyPartialMatches(args.get(2), NUMBERS, completions); - completions.sort((s1, s2) -> { - int t1 = Integer.parseInt(s1); - int t2 = Integer.parseInt(s2); - return t1 - t2; - }); + completions.sort((s1, s2) -> { + int t1 = Integer.parseInt(s1); + int t2 = Integer.parseInt(s2); + return t1 - t2; + }); - return completions; - } + return completions; + } - return new ArrayList<>(0); - }; + return new ArrayList<>(0); } } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandKillall.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandKillall.java index d49c5dd..77abb5c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandKillall.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandKillall.java @@ -1,11 +1,13 @@ package com.willfp.ecobosses.commands; -import com.willfp.eco.core.command.CommandHandler; import com.willfp.eco.core.command.impl.Subcommand; import com.willfp.ecobosses.EcoBossesPlugin; import com.willfp.ecobosses.bosses.util.BossUtils; +import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; +import java.util.List; + public class CommandKillall extends Subcommand { /** * Instantiate a new executor for /ebspawn. @@ -17,14 +19,13 @@ public class CommandKillall extends Subcommand { } @Override - public CommandHandler getHandler() { - return (sender, args) -> { - boolean force = false; - if (args.size() == 1) { - force = args.get(0).equalsIgnoreCase("force"); - } + public void onExecute(@NotNull final CommandSender sender, + @NotNull final List args) { + boolean force = false; + if (args.size() == 1) { + force = args.get(0).equalsIgnoreCase("force"); + } - sender.sendMessage(this.getPlugin().getLangYml().getMessage("killall").replace("%amount%", String.valueOf(BossUtils.killAllBosses(force)))); - }; + sender.sendMessage(this.getPlugin().getLangYml().getMessage("killall").replace("%amount%", String.valueOf(BossUtils.killAllBosses(force)))); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandReload.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandReload.java index 42ef30b..914498e 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandReload.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandReload.java @@ -1,10 +1,12 @@ package com.willfp.ecobosses.commands; -import com.willfp.eco.core.command.CommandHandler; import com.willfp.eco.core.command.impl.Subcommand; import com.willfp.ecobosses.EcoBossesPlugin; +import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; +import java.util.List; + public class CommandReload extends Subcommand { /** * Instantiate a new executor for /ebreload. @@ -16,11 +18,10 @@ public class CommandReload extends Subcommand { } @Override - public CommandHandler getHandler() { - return (sender, args) -> { - this.getPlugin().reload(); - this.getPlugin().reload(); - sender.sendMessage(this.getPlugin().getLangYml().getMessage("reloaded")); - }; + public void onExecute(@NotNull final CommandSender sender, + @NotNull final List args) { + this.getPlugin().reload(); + this.getPlugin().reload(); + sender.sendMessage(this.getPlugin().getLangYml().getMessage("reloaded")); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandSpawn.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandSpawn.java index a24f2b6..daf433b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandSpawn.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandSpawn.java @@ -1,7 +1,5 @@ package com.willfp.ecobosses.commands; -import com.willfp.eco.core.command.CommandHandler; -import com.willfp.eco.core.command.TabCompleteHandler; import com.willfp.eco.core.command.impl.Subcommand; import com.willfp.eco.core.config.updating.ConfigUpdater; import com.willfp.ecobosses.EcoBossesPlugin; @@ -10,6 +8,7 @@ import com.willfp.ecobosses.bosses.EcoBosses; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; @@ -53,158 +52,155 @@ public class CommandSpawn extends Subcommand { } @Override - public CommandHandler getHandler() { - return (sender, args) -> { - if (args.isEmpty()) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("specify-boss")); - return; - } + public void onExecute(@NotNull final CommandSender sender, + @NotNull final List args) { + if (args.isEmpty()) { + sender.sendMessage(this.getPlugin().getLangYml().getMessage("specify-boss")); + return; + } - String bossName = args.get(0); + String bossName = args.get(0); - EcoBoss boss = EcoBosses.getByName(bossName.toLowerCase()); + EcoBoss boss = EcoBosses.getByName(bossName.toLowerCase()); - if (boss == null) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("specify-boss")); - return; - } + if (boss == null) { + sender.sendMessage(this.getPlugin().getLangYml().getMessage("specify-boss")); + return; + } - Location location = null; + Location location = null; - if (sender instanceof Player) { - location = ((Player) sender).getLocation(); - } + if (sender instanceof Player) { + location = ((Player) sender).getLocation(); + } - if (args.size() >= 4) { - String xString = args.get(1); - String yString = args.get(2); - String zString = args.get(3); + if (args.size() >= 4) { + String xString = args.get(1); + String yString = args.get(2); + String zString = args.get(3); - double xPos; - double yPos; - double zPos; + double xPos; + double yPos; + double zPos; - if (xString.startsWith("~") && sender instanceof Player) { - String xDiff = xString.replace("~", ""); - String yDiff = yString.replace("~", ""); - String zDiff = zString.replace("~", ""); + if (xString.startsWith("~") && sender instanceof Player) { + String xDiff = xString.replace("~", ""); + String yDiff = yString.replace("~", ""); + String zDiff = zString.replace("~", ""); - if (xDiff.isEmpty()) { - xPos = ((Player) sender).getLocation().getX(); - } else { - try { - xPos = ((Player) sender).getLocation().getX() + Double.parseDouble(xDiff); - } catch (NumberFormatException e) { - xPos = ((Player) sender).getLocation().getX(); - } - } - - if (yDiff.isEmpty()) { - yPos = ((Player) sender).getLocation().getY(); - } else { - try { - yPos = ((Player) sender).getLocation().getY() + Double.parseDouble(yDiff); - } catch (NumberFormatException e) { - yPos = ((Player) sender).getLocation().getY(); - } - } - - if (zDiff.isEmpty()) { - zPos = ((Player) sender).getLocation().getZ(); - } else { - try { - zPos = ((Player) sender).getLocation().getZ() + Double.parseDouble(yDiff); - } catch (NumberFormatException e) { - zPos = ((Player) sender).getLocation().getZ(); - } - } + if (xDiff.isEmpty()) { + xPos = ((Player) sender).getLocation().getX(); } else { try { - xPos = Double.parseDouble(xString); - yPos = Double.parseDouble(yString); - zPos = Double.parseDouble(zString); + xPos = ((Player) sender).getLocation().getX() + Double.parseDouble(xDiff); } catch (NumberFormatException e) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-location")); - return; + xPos = ((Player) sender).getLocation().getX(); } } - location = new Location(null, xPos, yPos, zPos); + if (yDiff.isEmpty()) { + yPos = ((Player) sender).getLocation().getY(); + } else { + try { + yPos = ((Player) sender).getLocation().getY() + Double.parseDouble(yDiff); + } catch (NumberFormatException e) { + yPos = ((Player) sender).getLocation().getY(); + } + } + + if (zDiff.isEmpty()) { + zPos = ((Player) sender).getLocation().getZ(); + } else { + try { + zPos = ((Player) sender).getLocation().getZ() + Double.parseDouble(yDiff); + } catch (NumberFormatException e) { + zPos = ((Player) sender).getLocation().getZ(); + } + } + } else { + try { + xPos = Double.parseDouble(xString); + yPos = Double.parseDouble(yString); + zPos = Double.parseDouble(zString); + } catch (NumberFormatException e) { + sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-location")); + return; + } } - World world = null; - if (sender instanceof Player) { - world = ((Player) sender).getWorld(); - } + location = new Location(null, xPos, yPos, zPos); + } - if (args.size() >= 5) { - world = Bukkit.getWorld(args.get(4)); - } + World world = null; + if (sender instanceof Player) { + world = ((Player) sender).getWorld(); + } - if (location == null) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-location")); - return; - } + if (args.size() >= 5) { + world = Bukkit.getWorld(args.get(4)); + } - location.setWorld(world); + if (location == null) { + sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-location")); + return; + } - if (world == null) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-world")); - return; - } + location.setWorld(world); - boss.spawn(location); - sender.sendMessage(this.getPlugin().getLangYml().getMessage("spawned")); - }; + if (world == null) { + sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-world")); + return; + } + + boss.spawn(location); + sender.sendMessage(this.getPlugin().getLangYml().getMessage("spawned")); } @Override - public TabCompleteHandler getTabCompleter() { - return (sender, args) -> { + public List tabComplete(@NotNull final CommandSender sender, + @NotNull final List args) { + List completions = new ArrayList<>(); - List completions = new ArrayList<>(); + if (args.isEmpty()) { + // Currently, this case is not ever reached + return new ArrayList<>(); + } - if (args.isEmpty()) { - // Currently, this case is not ever reached - return new ArrayList<>(); - } + if (args.size() == 1) { + StringUtil.copyPartialMatches(args.get(0), BOSS_NAMES, completions); - if (args.size() == 1) { - StringUtil.copyPartialMatches(args.get(0), BOSS_NAMES, completions); + Collections.sort(completions); + return completions; + } - Collections.sort(completions); - return completions; - } + if (args.size() == 2) { + StringUtil.copyPartialMatches(args.get(1), TILDE, completions); - if (args.size() == 2) { - StringUtil.copyPartialMatches(args.get(1), TILDE, completions); + Collections.sort(completions); + return completions; + } - Collections.sort(completions); - return completions; - } + if (args.size() == 3) { + StringUtil.copyPartialMatches(args.get(2), TILDE, completions); - if (args.size() == 3) { - StringUtil.copyPartialMatches(args.get(2), TILDE, completions); + Collections.sort(completions); + return completions; + } - Collections.sort(completions); - return completions; - } + if (args.size() == 4) { + StringUtil.copyPartialMatches(args.get(3), TILDE, completions); - if (args.size() == 4) { - StringUtil.copyPartialMatches(args.get(3), TILDE, completions); + Collections.sort(completions); + return completions; + } - Collections.sort(completions); - return completions; - } + if (args.size() == 5) { + StringUtil.copyPartialMatches(args.get(4), Bukkit.getWorlds().stream().map(World::getName).collect(Collectors.toList()), completions); - if (args.size() == 5) { - StringUtil.copyPartialMatches(args.get(4), Bukkit.getWorlds().stream().map(World::getName).collect(Collectors.toList()), completions); + Collections.sort(completions); + return completions; + } - Collections.sort(completions); - return completions; - } - - return new ArrayList<>(0); - }; + return new ArrayList<>(0); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/config/BaseBossConfig.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/config/BaseBossConfig.java index dd934fb..3ba4a77 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/config/BaseBossConfig.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/config/BaseBossConfig.java @@ -1,16 +1,17 @@ package com.willfp.ecobosses.config; -import com.willfp.eco.core.config.yaml.YamlExtendableConfig; +import com.willfp.eco.core.config.ConfigType; +import com.willfp.eco.core.config.ExtendableConfig; import com.willfp.ecobosses.EcoBossesPlugin; import org.jetbrains.annotations.NotNull; -public class BaseBossConfig extends YamlExtendableConfig { +public class BaseBossConfig extends ExtendableConfig { /** * Create new EcoBoss config. * * @param configName The name of the config. */ public BaseBossConfig(@NotNull final String configName) { - super(configName, true, EcoBossesPlugin.getInstance(), EcoBossesPlugin.class, "bosses/"); + super(configName, true, EcoBossesPlugin.getInstance(), EcoBossesPlugin.class, "bosses/", ConfigType.YAML); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/config/CustomConfig.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/config/CustomConfig.java index 087390b..d4a1ec7 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/config/CustomConfig.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/config/CustomConfig.java @@ -1,11 +1,11 @@ package com.willfp.ecobosses.config; -import com.willfp.eco.core.config.yaml.YamlTransientConfig; +import com.willfp.eco.core.config.TransientConfig; import lombok.Getter; import org.bukkit.configuration.file.YamlConfiguration; import org.jetbrains.annotations.NotNull; -public class CustomConfig extends YamlTransientConfig { +public class CustomConfig extends TransientConfig { /** * The name of the config. */