This commit is contained in:
Telesphoreo 2022-05-04 18:23:04 -05:00
parent 9d5794dcfd
commit 457b6f4124
No known key found for this signature in database
GPG Key ID: B5CDDEBA526C0130
4 changed files with 41 additions and 22 deletions

View File

@ -29,6 +29,7 @@ import dev.plex.world.CustomWorld;
import java.io.File; import java.io.File;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -71,7 +72,8 @@ public class Plex extends JavaPlugin
private UpdateChecker updateChecker; private UpdateChecker updateChecker;
private String system; private String system;
private Permission permissions; public Permission permissions;
public Chat chat;
public static Plex get() public static Plex get()
{ {
@ -128,11 +130,14 @@ public class Plex extends JavaPlugin
e.printStackTrace(); e.printStackTrace();
} }
if (system.equalsIgnoreCase("permissions") && !getServer().getPluginManager().isPluginEnabled("Vault") && !setupPermissions()) if (system.equalsIgnoreCase("permissions") && !getServer().getPluginManager().isPluginEnabled("Vault"))
{ {
throw new RuntimeException("Vault is required to run on the server if you use permissions!"); throw new RuntimeException("Vault is required to run on the server if you use permissions!");
} }
permissions = setupPermissions();
chat = setupChat();
updateChecker = new UpdateChecker(); updateChecker = new UpdateChecker();
PlexLog.log("Update checking enabled"); PlexLog.log("Update checking enabled");
@ -241,10 +246,27 @@ public class Plex extends JavaPlugin
}); });
} }
public boolean setupPermissions() public Permission setupPermissions()
{ {
RegisteredServiceProvider<Permission> rsp = Bukkit.getServicesManager().getRegistration(Permission.class); RegisteredServiceProvider<Permission> rsp = Bukkit.getServicesManager().getRegistration(Permission.class);
permissions = rsp.getProvider(); permissions = rsp.getProvider();
return permissions != null; return permissions;
}
public Chat setupChat()
{
RegisteredServiceProvider<Chat> rsp = Bukkit.getServicesManager().getRegistration(Chat.class);
chat = rsp.getProvider();
return chat;
}
public Permission getVaultPermissions()
{
return permissions;
}
public Chat getVaultChat()
{
return chat;
} }
} }

View File

@ -55,7 +55,7 @@ public class PlexCMD extends PlexCommand
plugin.getRankManager().importDefaultRanks(); plugin.getRankManager().importDefaultRanks();
send(sender, "Imported ranks"); send(sender, "Imported ranks");
plugin.setSystem(plugin.config.getString("system")); plugin.setSystem(plugin.config.getString("system"));
if (!plugin.setupPermissions() && plugin.getSystem().equalsIgnoreCase("permissions") && !plugin.getServer().getPluginManager().isPluginEnabled("Vault")) if (plugin.getSystem().equalsIgnoreCase("permissions") && !plugin.getServer().getPluginManager().isPluginEnabled("Vault"))
{ {
throw new RuntimeException("Vault is required to run on the server if you use permissions!"); throw new RuntimeException("Vault is required to run on the server if you use permissions!");
} }

View File

@ -23,22 +23,15 @@ import org.jetbrains.annotations.NotNull;
@Toggleable("chat.enabled") @Toggleable("chat.enabled")
public class ChatListener extends PlexListener public class ChatListener extends PlexListener
{ {
private final static TextReplacementConfig URL_REPLACEMENT_CONFIG = TextReplacementConfig private final static TextReplacementConfig URL_REPLACEMENT_CONFIG = TextReplacementConfig.builder().match("(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]").replacement((matchResult, builder) -> Component.empty().content(matchResult.group()).clickEvent(ClickEvent.openUrl(matchResult.group()))).build();
.builder()
.match("(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]")
.replacement((matchResult, builder) -> Component.empty()
.content(matchResult.group())
.clickEvent(ClickEvent.openUrl(
matchResult.group()
))).build();
private final PlexChatRenderer renderer = new PlexChatRenderer(); private final PlexChatRenderer renderer = new PlexChatRenderer();
@EventHandler @EventHandler
public void onChat(AsyncChatEvent event) public void onChat(AsyncChatEvent event)
{ {
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(event.getPlayer().getUniqueId()); PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(event.getPlayer().getUniqueId());
Component prefix = plugin.getRankManager().getPrefix(plexPlayer); Component prefix = plugin.getRankManager().getPrefix(plexPlayer);
if (prefix != null) if (prefix != null)
{ {
renderer.hasPrefix = true; renderer.hasPrefix = true;
@ -49,6 +42,7 @@ public class ChatListener extends PlexListener
renderer.hasPrefix = false; renderer.hasPrefix = false;
renderer.prefix = null; renderer.prefix = null;
} }
event.renderer(renderer); event.renderer(renderer);
} }
@ -69,14 +63,7 @@ public class ChatListener extends PlexListener
component = component.append(prefix); component = component.append(prefix);
} }
return component return component.append(Component.space()).append(PlexUtils.mmDeserialize(plugin.config.getString("chat.name-color", "<white>") + MiniMessage.builder().tags(TagResolver.resolver(StandardTags.color(), StandardTags.rainbow(), StandardTags.decorations(), StandardTags.gradient(), StandardTags.transition())).build().serialize(sourceDisplayName))).append(Component.space()).append(Component.text("»").color(NamedTextColor.GRAY)).append(Component.space()).append(SafeMiniMessage.mmDeserializeWithoutEvents(text)).replaceText(URL_REPLACEMENT_CONFIG);
.append(Component.space())
.append(PlexUtils.mmDeserialize(plugin.config.getString("chat.name-color", "<white>") + MiniMessage.builder().tags(TagResolver.resolver(StandardTags.color(), StandardTags.rainbow(), StandardTags.decorations(), StandardTags.gradient(), StandardTags.transition())).build().serialize(sourceDisplayName)))
.append(Component.space())
.append(Component.text("»").color(NamedTextColor.GRAY))
.append(Component.space())
.append(SafeMiniMessage.mmDeserializeWithoutEvents(text))
.replaceText(URL_REPLACEMENT_CONFIG);
} }
} }
} }

View File

@ -15,6 +15,9 @@ import java.util.stream.Collectors;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONTokener; import org.json.JSONTokener;
@ -113,6 +116,13 @@ public class RankManager
{ {
return player.getRankFromString().getPrefix(); return player.getRankFromString().getPrefix();
} }
if (Plex.get().getSystem().equalsIgnoreCase("permissions"))
{
Player bukkitPlayer = Bukkit.getPlayer(player.getUuid());
String group = Plex.get().getVaultPermissions().getPrimaryGroup(bukkitPlayer);
String vaultPrefix = Plex.get().getVaultChat().getGroupPrefix(bukkitPlayer.getWorld(), group);
return LegacyComponentSerializer.legacyAmpersand().deserialize(vaultPrefix);
}
return null; return null;
} }