From 44e05ca99e6428398c99a4d31dd1bd0cee0ea2f3 Mon Sep 17 00:00:00 2001 From: DaniFoldi Date: Tue, 18 May 2021 20:51:21 +0200 Subject: [PATCH] Minor bugfixes --- README.md | 16 +- build.gradle | 2 +- .../bungeegui/command/PluginCommand.java | 4 +- .../bungeegui/main/BungeeGuiAPI.java | 5 + .../danifoldi/bungeegui/main/GuiHandler.java | 11 +- .../bungeegui/main/PlaceholderHandler.java | 7 +- .../bungeegui/main/ProtocolSoundFixer.java | 110 -------- .../danifoldi/bungeegui/util/ConfigUtil.java | 17 +- .../com/danifoldi/bungeegui/util/MapUtil.java | 27 ++ .../com/danifoldi/bungeegui/util/Message.java | 37 +-- .../danifoldi/bungeegui/util/SoundUtil.java | 59 +++- ...ProxyversionUtil.java => VersionUtil.java} | 10 +- src/main/resources/config.yml | 251 +++++++++++------- 13 files changed, 302 insertions(+), 254 deletions(-) delete mode 100644 src/main/java/com/danifoldi/bungeegui/main/ProtocolSoundFixer.java create mode 100644 src/main/java/com/danifoldi/bungeegui/util/MapUtil.java rename src/main/java/com/danifoldi/bungeegui/util/{ProxyversionUtil.java => VersionUtil.java} (78%) diff --git a/README.md b/README.md index 1b9b176..58f582e 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ - Full color support (with RGB where applicable) in all content - Many placeholders - Targeted GUIs +- Utility commands that can be used as click actions or separately ## Setup tutorial @@ -24,7 +25,7 @@ Optional dependencies: *PremiumVanish*, *LuckPerms*. ## Plugin configuration -All data of the plugin is saved in the `config.yml` file of the plugin's folder. You can apply any changes and then `/bguireload` for the plugin to reload the config. +All data of the plugin is saved in the `config.yml` file of the plugin's folder. You can apply any changes and then `/bgui reload` for the plugin to reload the config. **messages** @@ -90,6 +91,8 @@ If a player does not have the permission to run the commands, you can still use Setting many `owner:` playerheads will delay the GUI opening, so unless you need it to be dynamic, `texture:` is recommended. +Show the player their own head by setting the data to `owner:{player}`. + See the example `config.yml` that is auto-generated or in the repository for some GUI ideas. You can specify multiple slots with one item, and they will be cloned. @@ -103,6 +106,8 @@ You can specify multiple slots with one item, and they will be cloned. Valid sound list: [here](https://github.com/Exceptionflug/protocolize/blob/master/protocolize-world/src/main/java/de/exceptionflug/protocolize/world/Sound.java) Valid soundcategory list: [here](https://github.com/Exceptionflug/protocolize/blob/master/protocolize-world/src/main/java/de/exceptionflug/protocolize/world/SoundCategory.java) +You can send custom sounds with `custom:`. + ___Expressions are evaluated in order___ **configVersion** @@ -111,6 +116,11 @@ This should say `3`. If there are any config changes, the value will be incremen --- +## Commands + +The plugin registers the command `/bungeegui` with many subcommands that contain useful utility functions. +A list of these will be added here shortly. You can view them in-game with instructions on how to use each. + ## Placeholders All messages support the placeholders in the table below. The API can be used to register additional placeholders. You can escape placeholders with `%%`. @@ -167,7 +177,7 @@ All messages support the placeholders in the table below. The API can be used to ## Permissions The default permission to open a GUI is `bungeegui.gui.`. You can override this in the config of each GUI. -The permission to reload the plugin is `bungeegui.command.reload`. +The permission for each of the utility commands is `bungeegui.command.`. You can see the complete list in-game by typing `/bgui`. ## API Usage @@ -175,6 +185,8 @@ BungeeGUI provides an API which you can use to open and close GUIs for players a All available methods have JavaDocs provided in `BungeeGuiAPI.java`. [Click here](https://github.com/DaniFoldi/BungeeGUI/blob/main/src/main/java/com/danifoldi/bungeegui/main/BungeeGuiAPI.java) to see the available methods and how to use them. +NOTE: the placeholder registry is currently in beta, and the API will likely be changed. + ## Notes I developed this plugin in my free time. Please use the Issues page on GitHub (linked above) if you believe you found a bug, or would like a new feature added. I cannot guarantee any form of support, or any updates. diff --git a/build.gradle b/build.gradle index 1e24714..65ab14a 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'com.danifoldi' -version '1.2.1' +version '1.2.2' sourceCompatibility = JavaVersion.VERSION_11 repositories { diff --git a/src/main/java/com/danifoldi/bungeegui/command/PluginCommand.java b/src/main/java/com/danifoldi/bungeegui/command/PluginCommand.java index dd7bfb1..af35ad6 100644 --- a/src/main/java/com/danifoldi/bungeegui/command/PluginCommand.java +++ b/src/main/java/com/danifoldi/bungeegui/command/PluginCommand.java @@ -25,7 +25,7 @@ public class PluginCommand extends Command implements TabExecutor { - private final List commands = List.of("actionbar", "broadcast", "chat", "close", "guis", "info", "log", "open", "reload", "send", "sound", "title"); + private final List commands = List.of("actionbar", "broadcast", "chat", "close", "guis", "log", "open", "reload", "send", "sound", "title"); private final Logger logger; @Inject @@ -98,7 +98,7 @@ public void execute(CommandSender sender, String[] args) { ProxiedPlayer player = ProxyServer.getInstance().getPlayer(args[1]); if (player == null) { - sender.sendMessage(Message.TARGET_NOT_FOUND.toComponent(null)); + sender.sendMessage(Message.TARGET_NOT_FOUND.toComponent(null, Pair.of("target", args[1]))); return; } player.chat(Message.colorCodes(BungeeGuiAPI.getInstance().parsePlaceholders(player, skip(args, 2)))); diff --git a/src/main/java/com/danifoldi/bungeegui/main/BungeeGuiAPI.java b/src/main/java/com/danifoldi/bungeegui/main/BungeeGuiAPI.java index a5d9c8a..fd4c355 100644 --- a/src/main/java/com/danifoldi/bungeegui/main/BungeeGuiAPI.java +++ b/src/main/java/com/danifoldi/bungeegui/main/BungeeGuiAPI.java @@ -1,6 +1,7 @@ package com.danifoldi.bungeegui.main; import com.danifoldi.bungeegui.gui.GuiGrid; +import io.netty.util.internal.UnstableApi; import net.md_5.bungee.api.connection.ProxiedPlayer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -131,7 +132,9 @@ public long reloadGuis() { * Register a custom placeholder for use later * @param name - the name of the placeholder without % symbols * @param placeholder - the function to be called on the player when the placeholder is requested + * @implNote if the function returns null, the placeholder isn't parsed, the argument can be null if the parse target is the console */ + @UnstableApi public void registerPlaceholder(String name, Function placeholder) { placeholderHandler.register(name, placeholder); } @@ -140,6 +143,7 @@ public void registerPlaceholder(String name, Function pla * Unregister a custom placeholder * @param name - the name of the placeholder to unregister */ + @UnstableApi public void unregisterPlaceholder(String name) { placeholderHandler.unregister(name); } @@ -150,6 +154,7 @@ public void unregisterPlaceholder(String name) { * @param text - the text to replace placeholders in * @return the text with the placeholders replaced */ + @UnstableApi public String parsePlaceholders(ProxiedPlayer player, String text) { return placeholderHandler.parse(player, text); } diff --git a/src/main/java/com/danifoldi/bungeegui/main/GuiHandler.java b/src/main/java/com/danifoldi/bungeegui/main/GuiHandler.java index 442c5a2..1032550 100644 --- a/src/main/java/com/danifoldi/bungeegui/main/GuiHandler.java +++ b/src/main/java/com/danifoldi/bungeegui/main/GuiHandler.java @@ -271,16 +271,7 @@ String getGuiTarget(UUID uuid) { } String getGuiName(GuiGrid gui) { - // TODO this needs to be improved - for (Map.Entry menu: menus.entrySet()) { - if (menu.getValue() != gui) { - continue; - } - - return menu.getKey(); - } - - return ""; + return menus.entrySet().stream().filter(m -> m.getValue().equals(gui)).map(Map.Entry::getKey).findFirst().orElse(""); } List getGuis() { diff --git a/src/main/java/com/danifoldi/bungeegui/main/PlaceholderHandler.java b/src/main/java/com/danifoldi/bungeegui/main/PlaceholderHandler.java index 137821c..eb7a179 100644 --- a/src/main/java/com/danifoldi/bungeegui/main/PlaceholderHandler.java +++ b/src/main/java/com/danifoldi/bungeegui/main/PlaceholderHandler.java @@ -1,7 +1,7 @@ package com.danifoldi.bungeegui.main; import com.danifoldi.bungeegui.util.NumberUtil; -import com.danifoldi.bungeegui.util.ProxyversionUtil; +import com.danifoldi.bungeegui.util.VersionUtil; import de.exceptionflug.protocolize.api.protocol.ProtocolAPI; import de.myzelyam.api.vanish.BungeeVanishAPI; import net.luckperms.api.LuckPermsProvider; @@ -68,13 +68,12 @@ String parse(ProxiedPlayer player, String text) { int iter = 0; boolean changed = true; - while (changed && iter < 16) { + while (changed && iter < 8) { changed = false; for (Map.Entry> placeholder : builtinPlaceholders.entrySet()) { try { if (result.contains("%" + placeholder.getKey() + "%")) { - System.out.println(placeholder.getKey()); final String value = placeholder.getValue().apply(player); if (value == null) { continue; @@ -151,7 +150,7 @@ void registerBuiltins() { if (player == null) { return ""; } - return ProxyversionUtil.find(player.getPendingConnection().getVersion()).getVersion(); + return VersionUtil.find(player.getPendingConnection().getVersion()).getVersion(); }); registerBuiltin("max", player -> String.valueOf(proxyServer.getConfig().getPlayerLimit())); registerBuiltin("online", player -> String.valueOf(proxyServer.getOnlineCount())); diff --git a/src/main/java/com/danifoldi/bungeegui/main/ProtocolSoundFixer.java b/src/main/java/com/danifoldi/bungeegui/main/ProtocolSoundFixer.java deleted file mode 100644 index 6a93986..0000000 --- a/src/main/java/com/danifoldi/bungeegui/main/ProtocolSoundFixer.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.danifoldi.bungeegui.main; - -import de.exceptionflug.protocolize.api.event.PacketSendEvent; -import de.exceptionflug.protocolize.api.handler.PacketAdapter; -import de.exceptionflug.protocolize.api.protocol.Stream; -import de.exceptionflug.protocolize.world.Sound; -import de.exceptionflug.protocolize.world.packet.NamedSoundEffect; - -import javax.inject.Inject; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -// TODO remove once Protocolize has this correctly -public class ProtocolSoundFixer extends PacketAdapter { - @Inject - public ProtocolSoundFixer() { - super(Stream.UPSTREAM, NamedSoundEffect.class); - - } - - @Override - public void send(PacketSendEvent event) { - if (!enabled) { - return; - } - String sound = event.getPacket().getSound() == null ? event.getPacket().getSoundObject().getSoundName(event.getPlayer().getPendingConnection().getVersion()) : event.getPacket().getSound(); - event.getPacket().setSound(replace(sound)); - event.getPacket().setSound((Sound)null); - } - - private boolean enabled = true; - - void enable() { - enabled = true; - } - void disable() { - enabled = false; - } - - private final Map rewrites = convertToMap( - "zombie.villager_", "zombie_villager.", - "armor.stand", "armor_stand", - "cave.spider", "cave_spider", - "dragon.fireball", "dragon_fireball", - "elder.guardian", "elder_guardian", - "ender.dragon", "ender_dragon", - "ender.eye", "ender_eye", - "firework.rocket", "firework_rocket", - "iron.golem", "iron_golem", - "item.frame", "item_frame", - "leash.knot", "leash_knot", - "lightning.bolt", "lightning_bolt", - "polar.bear", "polar_bear", - "shulker.box", "shulker_box", - "snow.golem", "snow_golem", - "ender.pearl", "ender_pearl", - "puffer.fish", "puffer_fish", - "tropical.fish", "tropical_fish", - "wither.skeleton", "wither_skeleton", - "zombie.horse", "zombie_horse", - "zombie.pigman", "zombie_pigman", - "fishing.bobber", "fishing_bobber", - "zombie.villager", "zombie_villager", - "power.select", "power_select", - "bubble.column", "bubble_column", - "bubble.pop", "bubble_pop", - "upwards.ambient", "upwards_ambient", - "upwards.inside", "upwards_inside", - "whirlpool.ambient", "whirlpool_ambient", - "whirlpool.inside", "whirlpool_inside", - "coral.block", "coral_block", - "note.block", "note_block", - "hurt.drown", "hurt_drown", - "hurt.on.fire", "hurt_on_fire", - "slime.block", "slime_block", - "blow.out", "blow_out", - "blow.up", "blow_up" - ); - - private String replace(String original) { - if (original == null) { - return null; - } - String replacement = original; - for (Map.Entry rewrite: rewrites.entrySet()) { - if (rewrite.getKey() == null || rewrite.getValue() == null) { - continue; - } - replacement = replacement.replace(rewrite.getKey(), rewrite.getValue()); - } - return replacement; - } - - private Map convertToMap(String... input) { - Map map = new HashMap<>(); - - Iterator iterator = Arrays.stream(input).iterator(); - - while (iterator.hasNext()) { - String key = iterator.next(); - if (iterator.hasNext()) { - map.put(key, iterator.next()); - } - } - - return map; - } -} diff --git a/src/main/java/com/danifoldi/bungeegui/util/ConfigUtil.java b/src/main/java/com/danifoldi/bungeegui/util/ConfigUtil.java index c1cf82f..797f1fd 100644 --- a/src/main/java/com/danifoldi/bungeegui/util/ConfigUtil.java +++ b/src/main/java/com/danifoldi/bungeegui/util/ConfigUtil.java @@ -48,9 +48,24 @@ private static void upgrade(FileConfig config, int oldVersion, int newVersion) { ensureValue(config, "messages.commandHelp", Message.COMMAND_HELP.getDefaultValue()); ensureValue(config, "messages.commandReload", Message.COMMAND_RELOAD.getDefaultValue()); ensureValue(config, "messages.commandGuis", Message.COMMAND_GUIS.getDefaultValue()); - ensureValue(config, "messages.noPermission", Message.NO_PERMISSION.getDefaultValue()); + ensureValue(config, "messages.commandBroadcast", Message.COMMAND_BROADCAST.getDefaultValue()); + ensureValue(config, "messages.commandLog", Message.COMMAND_LOG.getDefaultValue()); + ensureValue(config, "messages.commandSend", Message.COMMAND_SEND.getDefaultValue()); + ensureValue(config, "messages.commandChat", Message.COMMAND_CHAT.getDefaultValue()); + ensureValue(config, "messages.commandActionbar", Message.COMMAND_ACTIONBAR.getDefaultValue()); + ensureValue(config, "messages.commandTitle", Message.COMMAND_TITLE.getDefaultValue()); + ensureValue(config, "messages.commandSound", Message.COMMAND_SOUND.getDefaultValue()); + ensureValue(config, "messages.commandOpen", Message.COMMAND_OPEN.getDefaultValue()); + ensureValue(config, "messages.commandClose", Message.COMMAND_CLOSE.getDefaultValue()); ensureValue(config, "messages.guiListTop", Message.GUI_LIST_TOP.getDefaultValue()); ensureValue(config, "messages.guiListItem", Message.GUI_LIST_ITEM.getDefaultValue()); + ensureValue(config, "messages.guiNotFound", Message.GUI_NOT_FOUND.getDefaultValue()); + ensureValue(config, "messages.guiTargetRequired", Message.GUI_TARGET_REQUIRED.getDefaultValue()); + ensureValue(config, "messages.invalidProperty", Message.INVALID_PROPERTY.getDefaultValue()); + ensureValue(config, "messages.serverNotFound", Message.SERVER_NOT_FOUND.getDefaultValue()); + ensureValue(config, "messages.emptyMessage", Message.EMPTY_MESSAGE.getDefaultValue()); + ensureValue(config, "messages.noPermission", Message.NO_PERMISSION.getDefaultValue()); + ensureValue(config, "messages.targetRequired", Message.TARGET_REQUIRED.getDefaultValue()); ensureValue(config, "debugLevel", "ALL"); } diff --git a/src/main/java/com/danifoldi/bungeegui/util/MapUtil.java b/src/main/java/com/danifoldi/bungeegui/util/MapUtil.java new file mode 100644 index 0000000..26fa3ad --- /dev/null +++ b/src/main/java/com/danifoldi/bungeegui/util/MapUtil.java @@ -0,0 +1,27 @@ +package com.danifoldi.bungeegui.util; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +public class MapUtil { + public static Map convertToMap(String... input) { + Map map = new HashMap<>(); + + Iterator iterator = Arrays.stream(input).iterator(); + + while (iterator.hasNext()) { + String key = iterator.next(); + if (iterator.hasNext()) { + map.put(key, iterator.next()); + } + } + + return map; + } + + private MapUtil() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/main/java/com/danifoldi/bungeegui/util/Message.java b/src/main/java/com/danifoldi/bungeegui/util/Message.java index 283a1fa..f647d40 100644 --- a/src/main/java/com/danifoldi/bungeegui/util/Message.java +++ b/src/main/java/com/danifoldi/bungeegui/util/Message.java @@ -21,28 +21,28 @@ public enum Message { SERVER_DISABLED("serverDisabled", "&cYou can't use this command on this server"), TARGET_BYPASS("targetBypass", "&cThis player can't be targeted with this command"), TARGET_NOT_FOUND("targetNotFound", "&cTarget {target} could not be found"), - RELOAD_SUCCESS("reloadSuccess", "&bPlugin reloaded successfully in &l{time}ms"), - COMMAND_HELP("commandHelp", "&7---- &6&l%bungeegui% help &7----"), - COMMAND_RELOAD("commandReload", "/bungeegui reload &7- Reload the plugin"), - COMMAND_GUIS("commandGuis", "/bungeegui guis &7- List the loaded GUIs"), - COMMAND_BROADCAST("commandBroadcast", "/bungeegui broadcast all|s:|p: &7- Send a message to one or more players"), - COMMAND_LOG("commandLog", "/bungeegui log &7- Log a message into the console"), - COMMAND_SEND("commandSend", "/bungeegui send all|s:|p: &7- Send a player to a server"), - COMMAND_CHAT("commandChat", "/bungeegui chat &7- Send a message to chat as a player"), - COMMAND_ACTIONBAR("commandActionbar", "/bungeegui actionbar all|s:|p: &7- Show a player a message in their action bar"), - COMMAND_TITLE("commandTitle", "/bungeegui title all|s:|p: title|subtitle fadeIn stay fadeOut "), - COMMAND_SOUND("commandSound", "/bungeegui sound all|s:|p: [soundcategory] [volume] [pitch]"), - COMMAND_OPEN("commandOpen", "/bungeegui open all|s:|p: [target]"), - COMMAND_CLOSE("commandClose", "/bungeegui close "), - ACTION_COMPLETE("actionComplete", "&bAction completed for {count} players"), + RELOAD_SUCCESS("reloadSuccess", "&aPlugin reloaded successfully in &l{time}ms"), + COMMAND_HELP("commandHelp", "&0------------ &e&l%bungeegui% commands &0------------"), + COMMAND_RELOAD("commandReload", "&0- &6/bgui &lreload&r &0- &7Reload the plugin"), + COMMAND_GUIS("commandGuis", "&0- &6/bgui &lguis&r &0- &7List the loaded GUIs"), + COMMAND_BROADCAST("commandBroadcast", "&0- &6/bgui &lbroadcast&r &7all&f|&7s:&6&f|&7p:&6 &6 &0- &7Send a message to one or more players"), + COMMAND_LOG("commandLog", "&0- &6/bgui &llog&r &6 &0- &7Log a message into the console"), + COMMAND_SEND("commandSend", "&0- &6/bgui &lsend&r &7all&f|&7s:&6&f|&7p:&6 &6 &0- &7Send a player to a server"), + COMMAND_CHAT("commandChat", "&0- &6/bgui &lchat&r &6 &6 &0- &7Send a message to chat as a player"), + COMMAND_ACTIONBAR("commandActionbar", "&0- &6/bgui &lactionbar&r &7all&f|&7s:&6&f|&7p:&6 &6 &0- &7Show a player a message in their action bar"), + COMMAND_TITLE("commandTitle", "&0- &6/bgui <itle&r &7all&f|&7s:&6&f|&7p:&6 &7title&f|&7subtitle &6 &6 &6 &6 &0- &7Send title to players"), + COMMAND_SOUND("commandSound", "&0- &6/bgui &lsound&r &7all&f|&7s:&6&f|&7p:&6 &6 &6[category] &6[volume] &6[pitch] &0- &7Play a sound for players"), + COMMAND_OPEN("commandOpen", "&0- &6/bgui &lopen&r &7all&f|&7s:&6&f|&7p:&6 &6 &6[target] &0- &7Open a GUI for players"), + COMMAND_CLOSE("commandClose", "&0- &6/bgui &lclose&r &6 &0- &7Close the GUI for players"), + ACTION_COMPLETE("actionComplete", "&aAction completed for {count} players"), GUI_NOT_FOUND("guiNotFound", "&cGUI {name} not found"), GUI_TARGET_REQUIRED("guiTargetRequired", "&cThis GUI requires a target player"), INVALID_PROPERTY("invalidProperty", "&cA property is invalid"), SERVER_NOT_FOUND("serverNotFound", "&cServer {name} not found"), EMPTY_MESSAGE("emptyMessage", "&cMessage can't be empty"), NO_PERMISSION("noPermission", "&cYou don't have permission to execute that command"), - GUI_LIST_TOP("guiListTop", "&6{count} GUIs are loaded:"), - GUI_LIST_ITEM("guiListItem", "&7- &6&l{name}"); + GUI_LIST_TOP("guiListTop", "&a{count} GUIs are loaded:"), + GUI_LIST_ITEM("guiListItem", "&0- &6{name}"); private static Map messages = new HashMap<>(); public static void setMessageProvider(Config config) { @@ -72,6 +72,9 @@ public String getDefaultValue() { public static String replace(String text, Pair... replacements) { String result = text; for (Pair replacement: replacements) { + if (replacement.getFirst() == null || replacement.getSecond() == null) { + continue; + } result = result.replace("{" + replacement.getFirst() + "}", replacement.getSecond()); } @@ -106,7 +109,7 @@ public static void send(ProxiedPlayer player, String value, Pair @SafeVarargs public final BaseComponent[] toComponent(ProxiedPlayer player, Pair... replacements) { - if (!Message.messages.containsKey(messageId) || Message.messages.get(messageId).equals("")) { + if (!Message.messages.containsKey(messageId) || Message.messages.get(messageId) == null || Message.messages.get(messageId).equals("")) { toComponent(player, defaultValue, replacements); } diff --git a/src/main/java/com/danifoldi/bungeegui/util/SoundUtil.java b/src/main/java/com/danifoldi/bungeegui/util/SoundUtil.java index 50654e5..6d33a83 100644 --- a/src/main/java/com/danifoldi/bungeegui/util/SoundUtil.java +++ b/src/main/java/com/danifoldi/bungeegui/util/SoundUtil.java @@ -7,13 +7,16 @@ import de.exceptionflug.protocolize.world.packet.NamedSoundEffect; import net.md_5.bungee.api.connection.ProxiedPlayer; +import java.util.Map; + public class SoundUtil { public static void playSound(ProxiedPlayer player, String soundName, SoundCategory category, float volume, float pitch) { NamedSoundEffect soundEffect = new NamedSoundEffect(); soundEffect.setCategory(category); soundEffect.setPitch(pitch); soundEffect.setVolume(volume); - soundEffect.setSound(StringUtil.get(soundName).getSecond()); + Pair name = StringUtil.get(soundName); + soundEffect.setSound(name.getFirst().equalsIgnoreCase("custom") ? name.getSecond() : correct(name.getSecond())); Location location = WorldModule.getLocation(player.getUniqueId()); soundEffect.setX(location.getX()); soundEffect.setY(location.getY()); @@ -34,6 +37,60 @@ public static boolean isValidSound(String soundName) { return true; } + private static final Map rewrites = MapUtil.convertToMap( + "zombie.villager_", "zombie_villager.", + "armor.stand", "armor_stand", + "cave.spider", "cave_spider", + "dragon.fireball", "dragon_fireball", + "elder.guardian", "elder_guardian", + "ender.dragon", "ender_dragon", + "ender.eye", "ender_eye", + "firework.rocket", "firework_rocket", + "iron.golem", "iron_golem", + "item.frame", "item_frame", + "leash.knot", "leash_knot", + "lightning.bolt", "lightning_bolt", + "polar.bear", "polar_bear", + "shulker.box", "shulker_box", + "snow.golem", "snow_golem", + "ender.pearl", "ender_pearl", + "puffer.fish", "puffer_fish", + "tropical.fish", "tropical_fish", + "wither.skeleton", "wither_skeleton", + "zombie.horse", "zombie_horse", + "zombie.pigman", "zombie_pigman", + "fishing.bobber", "fishing_bobber", + "zombie.villager", "zombie_villager", + "power.select", "power_select", + "bubble.column", "bubble_column", + "bubble.pop", "bubble_pop", + "upwards.ambient", "upwards_ambient", + "upwards.inside", "upwards_inside", + "whirlpool.ambient", "whirlpool_ambient", + "whirlpool.inside", "whirlpool_inside", + "coral.block", "coral_block", + "note.block", "note_block", + "hurt.drown", "hurt_drown", + "hurt.on.fire", "hurt_on_fire", + "slime.block", "slime_block", + "blow.out", "blow_out", + "blow.up", "blow_up" + ); + + private static String correct(String original) { + if (original == null) { + return null; + } + String replacement = original; + for (Map.Entry rewrite: rewrites.entrySet()) { + if (rewrite.getKey() == null || rewrite.getValue() == null) { + continue; + } + replacement = replacement.replace(rewrite.getKey(), rewrite.getValue()); + } + return replacement; + } + private SoundUtil() { throw new UnsupportedOperationException(); } diff --git a/src/main/java/com/danifoldi/bungeegui/util/ProxyversionUtil.java b/src/main/java/com/danifoldi/bungeegui/util/VersionUtil.java similarity index 78% rename from src/main/java/com/danifoldi/bungeegui/util/ProxyversionUtil.java rename to src/main/java/com/danifoldi/bungeegui/util/VersionUtil.java index 120a23e..5641cb9 100644 --- a/src/main/java/com/danifoldi/bungeegui/util/ProxyversionUtil.java +++ b/src/main/java/com/danifoldi/bungeegui/util/VersionUtil.java @@ -2,7 +2,7 @@ import java.util.Arrays; -public enum ProxyversionUtil { +public enum VersionUtil { UNKNOWN (999), v1_16_5 (754), v1_16_4 (754), @@ -55,16 +55,16 @@ public enum ProxyversionUtil { private final int protocolVersion; - ProxyversionUtil(int protocolVersion) { + VersionUtil(int protocolVersion) { this.protocolVersion = protocolVersion; } - public static ProxyversionUtil find(int protocolVersion) { - return Arrays.stream(ProxyversionUtil.values()).filter(p -> p.protocolVersion == protocolVersion).findFirst().orElse(UNKNOWN); + public static VersionUtil find(int protocolVersion) { + return Arrays.stream(VersionUtil.values()).filter(p -> p.protocolVersion == protocolVersion).findFirst().orElse(UNKNOWN); } public String getVersion() { - for (ProxyversionUtil version: ProxyversionUtil.values()) { + for (VersionUtil version: VersionUtil.values()) { if (version.protocolVersion == protocolVersion) { return version.toString().replace("v", "").replace("_", "."); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 9c4c1a2..fc316f5 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -3,114 +3,40 @@ messages: targetRequired: '&cThis command requires a target player' noSelfTarget: '&cYou can''t target yourself with this command' targetBypass: '&cThis player can''t be targeted with this command' - reloadSuccess: '&9Plugin reloaded successfully in &l{time}ms' + reloadSuccess: '&aPlugin reloaded successfully in &l{time}ms' serverDisabled: '&cYou can''t use this command on this server' - commandHelp: '&7---- &6&l%bungeegui% help &7----' - commandReload: '/bungeegui reload &7- Reload the plugin' - commandGuis: '/bungeegui guis &7 - List the loaded GUIs' - commandBroadcast: '/bungeegui broadcast all|s:|p: &7- Send a message to one or more players' - commandLog: '/bungeegui log &7- Log a message into the console' - commandSend: '/bungeegui send all|s:|p: &7- Send a player to a server' - commandChat: '/bungeegui chat &7- Send a message to chat as a player' - commandActionbar: '/bungeegui actionbar all|s:|p: &7- Show a player a message in their action bar' - commandTitle: '/bungeegui title all|s:|p: title|subtitle fadeIn stay fadeOut ' - commandSound: '/bungeegui sound all|s:|p: [soundcategory] [volume] [pitch]' - commandOpen: '/bungeegui open all|s:|p: [target]' - commandClose: '/bungeegui close ' - actionComplete: '&bAction completed for {count} players' + commandHelp: '&0------------ &e&l%bungeegui% commands &0------------' + commandReload: '&0- &6/bgui &lreload&r &0- &7Reload the plugin' + commandGuis: '&0- &6/bgui &lguis&r &0- &7List the loaded GUIs' + commandBroadcast: '&0- &6/bgui &lbroadcast&r &7all&f|&7s:&6&f|&7p:&6 &6 &0- &7Send a message to one or more players' + commandLog: '&0- &6/bgui &llog&r &6 &0- &7Log a message into the console' + commandSend: '&0- &6/bgui &lsend&r &7all&f|&7s:&6&f|&7p:&6 &6 &0- &7Send a player to a server' + commandChat: '&0- &6/bgui &lchat&r &6 &6 &0- &7Send a message to chat as a player' + commandActionbar: '&0- &6/bgui &lactionbar&r &7all&f|&7s:&6&f|&7p:&6 &6 &0- &7Show a player a message in their action bar' + commandTitle: '&0- &6/bgui <itle&r &7all&f|&7s:&6&f|&7p:&6 &7title&f|&7subtitle &6 &6 &6 &6 &0- &7Send title to players' + commandSound: '&0- &6/bgui &lsound&r &7all&f|&7s:&6&f|&7p:&6 &6 &6[category] &6[volume] &6[pitch] &0- &7Play a sound for players' + commandOpen: '&0- &6/bgui &lopen&r &7all&f|&7s:&6&f|&7p:&6 &6 &6[target] &0- &7Open a GUI for players' + commandClose: '&0- &6/bgui &lclose&r &6 &0- &7Close the GUI for players' + actionComplete: '&aAction completed for {count} players' guiNotFound: '&cGUI {name} not found' guiTargetRequired: '&cThis GUI requires a target player' invalidProperty: '&cA property is invalid' serverNotFound: '&cServer {name} not found' emptyMessage: '&cMessage can''t be empty' noPermission: '&cYou don''t have permission to execute that command' - guiListTop: '&6{count} GUIs are loaded:' - guiListItem: '&7- &6&l{name}' + guiListTop: '&a{count} GUIs are loaded:' + guiListItem: '&0- &6{name}' guis: servermenu: - aliases: [servers, lobby] + aliases: + - lobby + - servers size: 54 title: '&d&lExampleCraft &dserver menu' items: - '0': + 'row0,row5,column0,column8': type: white_stained_glass_pane - name: '' - '1': - type: white_stained_glass_pane - name: '' - '2': - type: white_stained_glass_pane - name: '' - '3': - type: white_stained_glass_pane - name: '' - '4': - type: white_stained_glass_pane - name: '' - '5': - type: white_stained_glass_pane - name: '' - '6': - type: white_stained_glass_pane - name: '' - '7': - type: white_stained_glass_pane - name: '' - '8': - type: white_stained_glass_pane - name: '' - '9': - type: white_stained_glass_pane - name: '' - '17': - type: white_stained_glass_pane - name: '' - '18': - type: white_stained_glass_pane - name: '' - '26': - type: white_stained_glass_pane - name: '' - '27': - type: white_stained_glass_pane - name: '' - '35': - type: white_stained_glass_pane - name: '' - '36': - type: white_stained_glass_pane - name: '' - '44': - type: white_stained_glass_pane - name: '' - '45': - type: white_stained_glass_pane - name: '' - '46': - type: white_stained_glass_pane - name: '' - '47': - type: white_stained_glass_pane - name: '' - '48': - type: white_stained_glass_pane - name: '' - '49': - type: white_stained_glass_pane - name: '' - '50': - type: white_stained_glass_pane - name: '' - '51': - type: white_stained_glass_pane - name: '' - '52': - type: white_stained_glass_pane - name: '' - '53': - type: white_stained_glass_pane - name: '' '20': type: player_head name: '&aEconomy server' @@ -146,13 +72,7 @@ guis: size: 45 title: '&6BungeeGui Authors' items: - '0': - type: nether_star - '8': - type: nether_star - '36': - type: nether_star - '44': + '0,8,36,44': type: nether_star '21': type: player_head @@ -166,6 +86,135 @@ guis: name: '&c&lHgeX' lore: - '&4Plugin developer' + stats: + aliases: + - stats + size: 45 + title: '&4&lStatistics' + openSound: + sound: block_beacon_activate + volume: 0.4 + closeable: false + items: + row0,row4,column0,column8: + type: red_stained_glass_pane + enchanted: true + clickSound: + sound: entity_villager_no + '13': + type: player_head + data: texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzI3NDA3NjFkYmQ0MmY3NmU0ZjEyYzQ4ZWMwOTlhY2RjMWM2OTI3MmFiNTc2MzU3OWJiZTkxYzVmNTg2NTZkNyJ9fX0= + name: '%bungeegui%' + lore: [ 'Guis loaded: %guicount%', 'Description: %plugin_description@BungeeGUI%', + 'Version: %plugin_version@BungeeGUI%', 'Author: %plugin_author@BungeeGUI%', + 'Main class: %plugin_main@BungeeGUI%', 'Depends: %plugin_depends@BungeeGUI%', + 'Softdepends: %plugin_softdepends@BungeeGUI%' ] + '21': + type: player_head + data: owner:{player} + name: '%name%' + lore: [ '&4Ping: %ping%', '&5Server: %servername%', '&7Vanished: %vanished%', + 'Version: %version%', 'Client locale: %locale%', 'Luckperms group: %luckperms_group%', + 'Luckperms name: %luckperms_prefix%%displayname%%luckperms_suffix%' ] + '23': + type: player_head + data: texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOGQxOWM2ODQ2MTY2NmFhY2Q3NjI4ZTM0YTFlMmFkMzlmZTRmMmJkZTMyZTIzMTk2M2VmM2IzNTUzMyJ9fX0= + name: '%proxyname%' + lore: [ 'Version: %proxyversion%', '&4Memory: %ram_used% / %ram_total% MB', + '&5Players: %online_visible% / %max%', '&6Plugins: %plugincount%', 'Servers: + %servercount%' ] + '31': + type: player_head + data: texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjYwYjAwNGYzNjBlMjg4NTVjY2YxMjM1YzJiZGVhMGEyOTk3YjBiYzAzMjU4ZTJkYzI0YWI4YTI1NzBhZWE2In19fQ== + name: '%servername%' + lore: [ 'MOTD: %motd@%servername%%', 'Players: %online_visible@%servername%% + / %max@%servername%%', 'Version: %version@%servername%%', 'Restricted: + %restricted@%servername%% (Accessible: %canaccess@%servername%%)' ] + '16': + type: barrier + clickSound: + sound: block_beacon_deactivate + volume: 0.4 + name: '&cClose' + commands: [ '' ] + sounds: + aliases: + - mobs + - sounds + title: '&5&lTest &d&lSounds' + items: + 'row0even,row5odd,column0even,column8even': + type: pink_stained_glass_pane + 'row0odd,row5even,column0odd,column8odd': + type: purple_stained_glass_pane + '10': + type: zombie_head + clickSound: + sound: entity_zombie_ambient + '12': + type: creeper_head + clickSound: + sound: entity_creeper_primed + '14': + type: player_head + data: texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTcxNTI4NzZiYzNhOTZkZDJhMjI5OTI0NWVkYjNiZWVmNjQ3YzhhNTZhYzg4NTNhNjg3YzNlN2I1ZDhiYiJ9fX0= + clickSound: + sound: entity_puffer_fish_blow_up + '16': + type: player_head + data: texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZmNhNDQ1NzQ5MjUxYmRkODk4ZmI4M2Y2Njc4NDRlMzhhMWRmZjc5YTE1MjlmNzlhNDI0NDdhMDU5OTMxMGVhNCJ9fX0= + clickSound: + sound: entity_skeleton_ambient + '20': + type: player_head + data: texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzEzNWY1ODM4ZTUxNTg1ZTE1OTQyZThmMmYxY2MzNmRhOTYzMDcwZGRkNWJhMzVhZjk1ZWQzN2ViNmMzIn19fQ== + clickSound: + sound: entity_parrot_ambient + '22': + type: player_head + data: texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzQwMDk3MjcxYmI2ODBmZTk4MWU4NTllOGJhOTNmZWEyOGI4MTNiMTA0MmJkMjc3ZWEzMzI5YmVjNDkzZWVmMyJ9fX0= + clickSound: + sound: entity_cat_ambient + '24': + type: player_head + data: texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNmU4OWQ3NDQ3NWIyZmMxYTJiMjE1Y2ZjY2ZkODY1NTkyYjg1ODQzYjkyNjBlZjY3MzA0YzJkYmNjNGJiMCJ9fX0= + clickSound: + sound: entity_wolf_howl + volume: 0.2 + '28': + type: player_head + data: texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjA3MmQ4Y2I4Mzk1YzJiYzg0NTQ3ZTZhYzliOGVkZWVkNzhjODY1OGMwZWQxYjg4M2M2MjljM2E3ZTkwIn19fQ== + clickSound: + sound: entity_polar_bear_warning + '30': + type: player_head + data: texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODk1YWVlYzZiODQyYWRhODY2OWY4NDZkNjViYzQ5NzYyNTk3ODI0YWI5NDRmMjJmNDViZjNiYmI5NDFhYmU2YyJ9fX0= + clickSound: + sound: entity_slime_jump + '32': + type: player_head + data: texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvN2YzN2Q1MjRjM2VlZDE3MWNlMTQ5ODg3ZWExZGVlNGVkMzk5OTA0NzI3ZDUyMTg2NTY4OGVjZTNiYWM3NWUifX19 + clickSound: + sound: entity_chicken_ambient + '34': + type: player_head + data: texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGJkYTFkZjgwYmZhMzE0ODUzMzhkOTYzMzgzZDhkZTI2ZjA1ZjI5MzRmODc1Njk2ODYyNDU0ZTdjNzBmNDVmNiJ9fX0= + clickSound: + sound: entity_cow_ambient + '38': + type: dragon_head + clickSound: + sound: entity_ender_dragon_ambient + '40': + type: player_head + data: texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjVjNGQyNGFmZmRkNDgxMDI2MjAzNjE1MjdkMjE1NmUxOGMyMjNiYWU1MTg5YWM0Mzk4MTU2NDNmM2NmZjlkIn19fQ== + clickSound: + sound: block_shulker_box_open + '42': + type: player_head + data: texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZGYwMDg1ODkyNmNkOGNkZjNmMWNmNzFlMjEwY2RlNWRhZjg3MDgzMjA1NDdiZDZkZjU3OTU4NTljNjhkOWIzZiJ9fX0= + clickSound: + sound: entity_panda_worried_ambient configVersion: 3 debugLevel: all \ No newline at end of file