mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Resolves #17
This commit is contained in:
parent
9d5794dcfd
commit
457b6f4124
@ -29,6 +29,7 @@ import dev.plex.world.CustomWorld;
|
||||
import java.io.File;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -71,7 +72,8 @@ public class Plex extends JavaPlugin
|
||||
private UpdateChecker updateChecker;
|
||||
private String system;
|
||||
|
||||
private Permission permissions;
|
||||
public Permission permissions;
|
||||
public Chat chat;
|
||||
|
||||
public static Plex get()
|
||||
{
|
||||
@ -128,11 +130,14 @@ public class Plex extends JavaPlugin
|
||||
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!");
|
||||
}
|
||||
|
||||
permissions = setupPermissions();
|
||||
chat = setupChat();
|
||||
|
||||
updateChecker = new UpdateChecker();
|
||||
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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public class PlexCMD extends PlexCommand
|
||||
plugin.getRankManager().importDefaultRanks();
|
||||
send(sender, "Imported ranks");
|
||||
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!");
|
||||
}
|
||||
|
@ -23,22 +23,15 @@ import org.jetbrains.annotations.NotNull;
|
||||
@Toggleable("chat.enabled")
|
||||
public class ChatListener extends PlexListener
|
||||
{
|
||||
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();
|
||||
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();
|
||||
private final PlexChatRenderer renderer = new PlexChatRenderer();
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncChatEvent event)
|
||||
{
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(event.getPlayer().getUniqueId());
|
||||
|
||||
Component prefix = plugin.getRankManager().getPrefix(plexPlayer);
|
||||
|
||||
if (prefix != null)
|
||||
{
|
||||
renderer.hasPrefix = true;
|
||||
@ -49,6 +42,7 @@ public class ChatListener extends PlexListener
|
||||
renderer.hasPrefix = false;
|
||||
renderer.prefix = null;
|
||||
}
|
||||
|
||||
event.renderer(renderer);
|
||||
}
|
||||
|
||||
@ -69,14 +63,7 @@ public class ChatListener extends PlexListener
|
||||
component = component.append(prefix);
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,9 @@ import java.util.stream.Collectors;
|
||||
import lombok.SneakyThrows;
|
||||
import net.kyori.adventure.text.Component;
|
||||
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.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
@ -113,6 +116,13 @@ public class RankManager
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user