From 5f1d012f6992fd2faa083ba1a00af3ae8f63ece8 Mon Sep 17 00:00:00 2001 From: Daniel V Date: Sun, 18 Feb 2024 16:56:38 -0500 Subject: [PATCH] General fixes for the next release. --- .../lokka30/phantomworlds/PhantomWorlds.java | 9 +++- .../commandsredux/PWCommand.java | 6 +-- .../params/PotionEffectParameter.java | 20 ++++---- .../params/SettingParameter.java | 22 +++------ .../sub/set/SetEffectsCommand.java | 46 +++++++++++++++---- .../player/PlayerChangeWorldListener.java | 27 +++++++---- src/main/resources/messages.yml | 2 +- src/main/resources/plugin.yml | 45 ++++++++++++++++++ 8 files changed, 125 insertions(+), 52 deletions(-) diff --git a/src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java b/src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java index 86dc9a0..43562b8 100644 --- a/src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java +++ b/src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java @@ -1,6 +1,7 @@ package me.lokka30.phantomworlds; import dev.rollczi.litecommands.LiteCommands; +import dev.rollczi.litecommands.argument.ArgumentKey; import dev.rollczi.litecommands.bukkit.LiteBukkitFactory; import me.lokka30.microlib.files.YamlConfigFile; import me.lokka30.microlib.maths.QuickTimer; @@ -228,10 +229,14 @@ void registerCommands() { this.command = LiteBukkitFactory.builder() .commands(new PWCommand()) + .settings(settings -> settings + .fallbackPrefix("phantomworlds") + .nativePermissions(false) + ) .argument(GameMode.class, new GamemodeParameter()) .argument(PortalType.class, new PortalParameter()) - .argument(List.class, new PotionEffectParameter()) - .argument(List.class, new SettingParameter()) + .argument(String.class, ArgumentKey.of("world-setting"), new SettingParameter()) + .argument(String.class, ArgumentKey.of("potion-effects"), new PotionEffectParameter()) .argument(World.class, new AliasWorldParameter()) .argument(WorldFolder.class, new WorldFolderParameter()).build(); } diff --git a/src/main/java/me/lokka30/phantomworlds/commandsredux/PWCommand.java b/src/main/java/me/lokka30/phantomworlds/commandsredux/PWCommand.java index 4d25d4a..a84ffad 100644 --- a/src/main/java/me/lokka30/phantomworlds/commandsredux/PWCommand.java +++ b/src/main/java/me/lokka30/phantomworlds/commandsredux/PWCommand.java @@ -57,7 +57,7 @@ * @author creatorfromhell * @since 2.0.5.0 */ -@Command(name = "phantomworlds", aliases = "pw") +@Command(name = "phantomworlds", aliases = {"pw"}) public class PWCommand { @Execute(name = "backup", aliases = {"archive", "bu"}) @@ -70,7 +70,7 @@ public void backup(@Context CommandSender commandSender, @OptionalArg("world") f @Execute(name = "create", aliases = {"+", "new"}) @Permission("phantomworlds.command.phantomworlds.create") @Description("command.phantomworlds.help.create") - public void create(@Context CommandSender commandSender, @Arg("world name") final String name, @Arg("environment")World.Environment environment, @OptionalArg("world-setting") List settings) { + public void create(@Context CommandSender commandSender, @Arg("world name") final String name, @Arg("environment")World.Environment environment, @Arg("world-setting") List settings) { CreateCommand.onCommand(commandSender, name, environment, settings); } @@ -133,7 +133,7 @@ public void reload(@Context CommandSender commandSender) { @Execute(name = "set effects", aliases = {"set eff"}) @Permission("phantomworlds.command.phantomworlds.set.effects") @Description("command.phantomworlds.help.seteffects") - public void setEffects(@Context CommandSender commandSender, @Arg("world") World world, @OptionalArg("potion-effects") List effects) { + public void setEffects(@Context CommandSender commandSender, @Arg("world") World world, @Arg("potion-effects") List effects) { SetEffectsCommand.onCommand(commandSender, world, effects); } diff --git a/src/main/java/me/lokka30/phantomworlds/commandsredux/params/PotionEffectParameter.java b/src/main/java/me/lokka30/phantomworlds/commandsredux/params/PotionEffectParameter.java index 5eedb2c..aaf284d 100644 --- a/src/main/java/me/lokka30/phantomworlds/commandsredux/params/PotionEffectParameter.java +++ b/src/main/java/me/lokka30/phantomworlds/commandsredux/params/PotionEffectParameter.java @@ -27,7 +27,6 @@ import org.bukkit.potion.PotionEffectType; import java.util.ArrayList; -import java.util.Collections; import java.util.List; /** @@ -36,27 +35,24 @@ * @author creatorfromhell * @since 2.0.5.0 */ -public class PotionEffectParameter extends ArgumentResolver { +public class PotionEffectParameter extends ArgumentResolver { private static final List POTION_EFFECTS = new ArrayList<>(); static { - for (PotionEffectType value : PotionEffectType.values()) { - POTION_EFFECTS.add(value.getName()); + for(PotionEffectType value : PotionEffectType.values()) { + POTION_EFFECTS.add(value.getKey() + ",duration,amplifier"); + POTION_EFFECTS.add(value.getKey() + ",-1,1"); } } @Override - protected ParseResult parse(Invocation invocation, Argument context, String argument) { - return ParseResult.success(Collections.singletonList(argument)); + protected ParseResult parse(Invocation invocation, Argument context, String argument) { + return ParseResult.success(argument); } @Override - public SuggestionResult suggest(Invocation invocation, Argument argument, SuggestionContext context) { - - if(argument.getKeyName().equalsIgnoreCase("potion-effects")) { - return SuggestionResult.of(POTION_EFFECTS); - } - return SuggestionResult.of(new ArrayList<>()); + public SuggestionResult suggest(Invocation invocation, Argument argument, SuggestionContext context) { + return SuggestionResult.of(POTION_EFFECTS); } } diff --git a/src/main/java/me/lokka30/phantomworlds/commandsredux/params/SettingParameter.java b/src/main/java/me/lokka30/phantomworlds/commandsredux/params/SettingParameter.java index 5dabd30..491d9f9 100644 --- a/src/main/java/me/lokka30/phantomworlds/commandsredux/params/SettingParameter.java +++ b/src/main/java/me/lokka30/phantomworlds/commandsredux/params/SettingParameter.java @@ -1,7 +1,7 @@ package me.lokka30.phantomworlds.commandsredux.params; /* * Phantom Worlds - * Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar + * Copyright (C) 2023 Daniel "creatorfromhell" Vidmar * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -26,28 +26,20 @@ import me.lokka30.phantomworlds.PhantomWorlds; import org.bukkit.command.CommandSender; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - /** - * Setting + * SettingParameterRedux * * @author creatorfromhell * @since 2.0.5.0 */ -public class SettingParameter extends ArgumentResolver { +public class SettingParameter extends ArgumentResolver { @Override - protected ParseResult parse(Invocation invocation, Argument context, String argument) { - return ParseResult.success(Collections.singletonList(argument)); + protected ParseResult parse(Invocation invocation, Argument context, String argument) { + return ParseResult.success(argument); } @Override - public SuggestionResult suggest(Invocation invocation, Argument argument, SuggestionContext context) { - - if(argument.getKeyName().equalsIgnoreCase("world-setting")) { - return SuggestionResult.of(PhantomWorlds.createTabs); - } - return SuggestionResult.of(new ArrayList<>()); + public SuggestionResult suggest(Invocation invocation, Argument argument, SuggestionContext context) { + return SuggestionResult.of(PhantomWorlds.createTabs); } } \ No newline at end of file diff --git a/src/main/java/me/lokka30/phantomworlds/commandsredux/sub/set/SetEffectsCommand.java b/src/main/java/me/lokka30/phantomworlds/commandsredux/sub/set/SetEffectsCommand.java index 4d4f50e..d2d3cd8 100644 --- a/src/main/java/me/lokka30/phantomworlds/commandsredux/sub/set/SetEffectsCommand.java +++ b/src/main/java/me/lokka30/phantomworlds/commandsredux/sub/set/SetEffectsCommand.java @@ -40,19 +40,47 @@ public static void onCommand(final CommandSender sender, final World world, fina return; } + final StringBuilder eff = new StringBuilder(); + final World finalWorld = (world == null)? ((Player)sender).getWorld() : world; final String cfgPath = "worlds-to-load." + finalWorld.getName(); - if(PhantomWorlds.instance().data.getConfig().contains(cfgPath)) { - //PhantomWorlds manages this world so let's set the spawn here for better accuracy. - PhantomWorlds.instance().data.getConfig().set(cfgPath + ".effects", String.join(", ", effects)); - - try { - PhantomWorlds.instance().data.save(); - } catch(final IOException ex) { - throw new RuntimeException(ex); + + for(String effString : effects) { + + if(eff.length() > 0) { + eff.append(", "); + } + + final String[] effSettings = effString.split(","); + + int duration = -1; + if(effSettings.length > 1) { + try { + duration = Integer.parseInt(effSettings[1]); + } catch(NumberFormatException ignore) { + } } + + int amplifier = 1; + if(effSettings.length > 2) { + try { + amplifier = Integer.parseInt(effSettings[2]); + } catch(NumberFormatException ignore) { + } + } + + eff.append(effSettings[0]); + + PhantomWorlds.instance().data.getConfig().set(cfgPath + ".effects." + effSettings[0] + ".duration", duration); + PhantomWorlds.instance().data.getConfig().set(cfgPath + ".effects." + effSettings[0] + ".amplifier", amplifier); + } + + try { + PhantomWorlds.instance().data.save(); + } catch(final IOException ex) { + throw new RuntimeException(ex); } (new MultiMessage( @@ -62,7 +90,7 @@ public static void onCommand(final CommandSender sender, final World world, fina PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"), true), new MultiMessage.Placeholder("world", finalWorld.getName(), false), - new MultiMessage.Placeholder("effects", effects.toString(), false) + new MultiMessage.Placeholder("effects", eff.toString(), false) ))).send(sender); } } \ No newline at end of file diff --git a/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerChangeWorldListener.java b/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerChangeWorldListener.java index d6ab0a1..f519e2a 100644 --- a/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerChangeWorldListener.java +++ b/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerChangeWorldListener.java @@ -20,6 +20,7 @@ import me.lokka30.phantomworlds.PhantomWorlds; import org.bukkit.GameMode; import org.bukkit.Location; +import org.bukkit.NamespacedKey; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerChangedWorldEvent; @@ -61,26 +62,32 @@ public void onChangeWorld(PlayerChangedWorldEvent event) { event.getPlayer().setGameMode(mode); } + System.out.println("Effects Checks"); + final String cfgPrevPath = "worlds-to-load." + event.getFrom().getName(); - if(PhantomWorlds.instance().getConfig().contains(cfgPrevPath + ".effects") && - PhantomWorlds.instance().getConfig().isConfigurationSection(cfgPrevPath + ".effects")) { - for(final String effName : PhantomWorlds.instance().getConfig().getConfigurationSection(cfgPrevPath + ".effects").getKeys(false)) { + if(PhantomWorlds.instance().data.getConfig().contains(cfgPrevPath + ".effects") && + PhantomWorlds.instance().data.getConfig().isConfigurationSection(cfgPrevPath + ".effects")) { + for(final String effName : PhantomWorlds.instance().data.getConfig().getConfigurationSection(cfgPrevPath + ".effects").getKeys(false)) { - final PotionEffectType type = PotionEffectType.getByName(effName); + final PotionEffectType type = PotionEffectType.getByKey(NamespacedKey.fromString(effName)); if(type != null) { event.getPlayer().removePotionEffect(type); } } } - if(PhantomWorlds.instance().getConfig().contains(cfgPath + ".effects") && - PhantomWorlds.instance().getConfig().isConfigurationSection(cfgPath + ".effects") && !event.getPlayer().hasPermission("phantomworlds.world.bypass.effects")) { + if(PhantomWorlds.instance().data.getConfig().contains(cfgPath + ".effects") && + PhantomWorlds.instance().data.getConfig().isConfigurationSection(cfgPath + ".effects") && !event.getPlayer().hasPermission("phantomworlds.world.bypass.effects")) { + + System.out.println("Apply effects."); + + for(final String effName : PhantomWorlds.instance().data.getConfig().getConfigurationSection(cfgPath + ".effects").getKeys(false)) { + final int duration = PhantomWorlds.instance().data.getConfig().getInt(cfgPath + ".effects." + effName + ".duration", -1); + final int amplifier = PhantomWorlds.instance().data.getConfig().getInt(cfgPath + ".effects." + effName + ".amplifier", 1); - for(final String effName : PhantomWorlds.instance().getConfig().getConfigurationSection(cfgPath + ".effects").getKeys(false)) { - final int duration = PhantomWorlds.instance().getConfig().getInt(cfgPath + ".effects." + effName, 60); - final int amplifier = PhantomWorlds.instance().getConfig().getInt(cfgPath + ".effects." + effName, 1); - final PotionEffectType type = PotionEffectType.getByName(effName); + System.out.println("Apply effect: " + effName); + final PotionEffectType type = PotionEffectType.getByKey(NamespacedKey.fromString(effName)); if(type != null) { final PotionEffect effect = new PotionEffect(type, duration, amplifier); event.getPlayer().addPotionEffect(effect); diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index e7cfd76..14d0a91 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -29,7 +29,7 @@ command: - '&8 &m->&b /%label% set whitelist &8- &7set whether there is a whitelist for this world or not.' - '&8 &m->&b /%label% setspawn &8- &7set the spawnpoint of a world' - '&8 &m->&b /%label% delete &8- &7delete a world' - - '&8 &m->&b /%label% backup &8- &backup a world' + - '&8 &m->&b /%label% backup &8- &7Backup a world' - '&8 &m->&b /%label% unload &8- &7unload a loaded world' - '&8 &m->&b /%label% load &8- &7load an unloaded world' - '&8 &m->&b /%label% reload &8- &7reload all config & data files' diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 362f944..c4d20ac 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -28,6 +28,16 @@ permissions: phantomworlds.knows-vanished-users: true phantomworlds.command.phantomworlds.*: true + + phantomworlds.world.bypass.gamemode: + default: op + description: 'Used to bypass the gamemode setting for worlds.' + + + phantomworlds.world.bypass.effects: + default: op + description: 'Used to bypass the effects setting for worlds.' + phantomworlds.knows-vanished-users: default: op description: 'Users with this permission will ignore the status of vanished players when using commands from PhantomWorlds, such as in tab-completion suggestions.' @@ -37,12 +47,19 @@ permissions: description: 'Ability to run all /pw commands.' children: phantomworlds.command.phantomworlds: true + phantomworlds.command.phantomworlds.backup: true phantomworlds.command.phantomworlds.compatibility: true phantomworlds.command.phantomworlds.create: true phantomworlds.command.phantomworlds.debug: true + phantomworlds.command.phantomworlds.import: true phantomworlds.command.phantomworlds.info: true phantomworlds.command.phantomworlds.list: true + phantomworlds.command.phantomworlds.load: true phantomworlds.command.phantomworlds.setspawn: true + phantomworlds.command.phantomworlds.set.effects: true + phantomworlds.command.phantomworlds.set.gamemode: true + phantomworlds.command.phantomworlds.set.portal: true + phantomworlds.command.phantomworlds.set.whitelist: true phantomworlds.command.phantomworlds.teleport: true phantomworlds.command.phantomworlds.spawn: true phantomworlds.command.phantomworlds.unload: true @@ -52,6 +69,10 @@ permissions: default: op description: 'Ability to run /pw' + phantomworlds.command.phantomworlds.backup: + default: op + description: 'Ability to run /pw backup' + phantomworlds.command.phantomworlds.compatibility: default: op description: 'Ability to run /pw compatibility' @@ -64,6 +85,10 @@ permissions: default: op description: 'Ability to run /pw create' + phantomworlds.command.phantomworlds.import: + default: op + description: 'Ability to run /pw import' + phantomworlds.command.phantomworlds.info: default: true description: 'Ability to run /pw info' @@ -72,10 +97,30 @@ permissions: default: op description: 'Ability to run /pw list' + phantomworlds.command.phantomworlds.load: + default: op + description: 'Ability to run /pw load' + phantomworlds.command.phantomworlds.setspawn: default: op description: 'Ability to run /pw setspawn' + phantomworlds.command.phantomworlds.set.effects: + default: op + description: 'Ability to run /pw set effects' + + phantomworlds.command.phantomworlds.set.gamemode: + default: op + description: 'Ability to run /pw set gamemode' + + phantomworlds.command.phantomworlds.set.portal: + default: op + description: 'Ability to run /pw set portal' + + phantomworlds.command.phantomworlds.set.whitelist: + default: op + description: 'Ability to run /pw set whitelist' + phantomworlds.command.phantomworlds.teleport: default: op description: 'Ability to run /pw teleport'