Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
Minor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniFoldi committed May 18, 2021
1 parent 3d183ca commit 44e05ca
Show file tree
Hide file tree
Showing 13 changed files with 302 additions and 254 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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**
Expand Down Expand Up @@ -90,6 +91,8 @@ If a player does not have the permission to run the commands, you can still use

Setting many `owner:<UUID/name>` playerheads will delay the GUI opening, so unless you need it to be dynamic, `texture:<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.
Expand All @@ -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:<soundName>`.

___Expressions are evaluated in order___

**configVersion**
Expand All @@ -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 `%%`.
Expand Down Expand Up @@ -167,14 +177,16 @@ 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.<guiname>`. 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.<command>`. You can see the complete list in-game by typing `/bgui`.

## API Usage

BungeeGUI provides an API which you can use to open and close GUIs for players and more. You can obtain the API instance with `BungeeGuiAPI.getInstance()`.

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.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'com.danifoldi'
version '1.2.1'
version '1.2.2'
sourceCompatibility = JavaVersion.VERSION_11

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public class PluginCommand extends Command implements TabExecutor {

private final List<String> commands = List.of("actionbar", "broadcast", "chat", "close", "guis", "info", "log", "open", "reload", "send", "sound", "title");
private final List<String> commands = List.of("actionbar", "broadcast", "chat", "close", "guis", "log", "open", "reload", "send", "sound", "title");
private final Logger logger;

@Inject
Expand Down Expand Up @@ -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))));
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/danifoldi/bungeegui/main/BungeeGuiAPI.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<ProxiedPlayer, String> placeholder) {
placeholderHandler.register(name, placeholder);
}
Expand All @@ -140,6 +143,7 @@ public void registerPlaceholder(String name, Function<ProxiedPlayer, String> pla
* Unregister a custom placeholder
* @param name - the name of the placeholder to unregister
*/
@UnstableApi
public void unregisterPlaceholder(String name) {
placeholderHandler.unregister(name);
}
Expand All @@ -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);
}
Expand Down
11 changes: 1 addition & 10 deletions src/main/java/com/danifoldi/bungeegui/main/GuiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,7 @@ String getGuiTarget(UUID uuid) {
}

String getGuiName(GuiGrid gui) {
// TODO this needs to be improved
for (Map.Entry<String, GuiGrid> 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<String> getGuis() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<String, Function<ProxiedPlayer, String>> 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;
Expand Down Expand Up @@ -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()));
Expand Down
110 changes: 0 additions & 110 deletions src/main/java/com/danifoldi/bungeegui/main/ProtocolSoundFixer.java

This file was deleted.

17 changes: 16 additions & 1 deletion src/main/java/com/danifoldi/bungeegui/util/ConfigUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/danifoldi/bungeegui/util/MapUtil.java
Original file line number Diff line number Diff line change
@@ -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<String, String> convertToMap(String... input) {
Map<String, String> map = new HashMap<>();

Iterator<String> 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();
}
}
Loading

0 comments on commit 44e05ca

Please sign in to comment.