- Create tag command

- Fix bug fixes
This commit is contained in:
Taah 2022-02-21 22:55:59 -08:00
parent ab0666ebeb
commit 355a930c89
8 changed files with 111 additions and 11 deletions

View File

@ -21,13 +21,14 @@ import dev.plex.storage.StorageType;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import dev.plex.world.CustomWorld; import dev.plex.world.CustomWorld;
import java.util.UUID;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.util.UUID;
@Getter @Getter
@Setter @Setter
public class Plex extends JavaPlugin public class Plex extends JavaPlugin
@ -81,8 +82,7 @@ public class Plex extends JavaPlugin
{ {
PlexUtils.testConnections(); PlexUtils.testConnections();
PlexLog.log("Connected to " + storageType.name().toUpperCase()); PlexLog.log("Connected to " + storageType.name().toUpperCase());
} } catch (Exception e)
catch (Exception e)
{ {
PlexLog.error("Failed to connect to " + storageType.name().toUpperCase()); PlexLog.error("Failed to connect to " + storageType.name().toUpperCase());
e.printStackTrace(); e.printStackTrace();
@ -96,8 +96,7 @@ public class Plex extends JavaPlugin
{ {
redisConnection.getJedis(); redisConnection.getJedis();
PlexLog.log("Connected to Redis!"); PlexLog.log("Connected to Redis!");
} } else
else
{ {
PlexLog.log("Redis is disabled in the configuration file, not connecting."); PlexLog.log("Redis is disabled in the configuration file, not connecting.");
} }
@ -105,8 +104,7 @@ public class Plex extends JavaPlugin
if (storageType == StorageType.MONGODB) if (storageType == StorageType.MONGODB)
{ {
mongoPlayerData = new MongoPlayerData(); mongoPlayerData = new MongoPlayerData();
} } else
else
{ {
sqlPlayerData = new SQLPlayerData(); sqlPlayerData = new SQLPlayerData();
} }
@ -139,6 +137,23 @@ public class Plex extends JavaPlugin
@Override @Override
public void onDisable() public void onDisable()
{ {
Bukkit.getOnlinePlayers().forEach(player ->
{
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId()); //get the player because it's literally impossible for them to not have an object
if (plugin.getRankManager().isAdmin(plexPlayer))
{
plugin.getAdminList().removeFromCache(UUID.fromString(plexPlayer.getUuid()));
}
if (mongoPlayerData != null) //back to mongo checking
{
mongoPlayerData.update(plexPlayer); //update the player's document
} else if (sqlPlayerData != null) //sql checking
{
sqlPlayerData.update(plexPlayer);
}
});
if (redisConnection.isEnabled() && redisConnection.getJedis().isConnected()) if (redisConnection.isEnabled() && redisConnection.getJedis().isConnected())
{ {
PlexLog.log("Disabling Redis/Jedis. No memory leaks in this Anarchy server!"); PlexLog.log("Disabling Redis/Jedis. No memory leaks in this Anarchy server!");

View File

@ -260,7 +260,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
PlexPlayer plexPlayer = getPlexPlayer(player); PlexPlayer plexPlayer = getPlexPlayer(player);
if (plugin.getSystem().equalsIgnoreCase("ranks")) if (plugin.getSystem().equalsIgnoreCase("ranks"))
{ {
if (!plexPlayer.getRankFromString().isAtLeast(getLevel())) if (!plexPlayer.getRankFromString().isAtLeast(rank))
{ {
throw new CommandFailException(PlexUtils.tl("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage()))); throw new CommandFailException(PlexUtils.tl("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
} }

View File

@ -8,6 +8,7 @@ import dev.plex.rank.enums.Rank;
import java.util.List; import java.util.List;
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.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -37,7 +38,7 @@ public class ListCMD extends PlexCommand
for (int i = 0; i < players.size(); i++) for (int i = 0; i < players.size(); i++)
{ {
Player player = players.get(i); Player player = players.get(i);
component = component.append(Component.text(getPlexPlayer(player).getRankFromString().getPrefix())).append(Component.space()).append(Component.text(player.getName()).color(NamedTextColor.WHITE)); component = component.append(LegacyComponentSerializer.legacyAmpersand().deserialize(getPlexPlayer(player).getRankFromString().getPrefix())).append(Component.space()).append(Component.text(player.getName()).color(NamedTextColor.WHITE));
if (i != players.size() - 1) if (i != players.size() - 1)
{ {
component = component.append(Component.text(",")).append(Component.space()); component = component.append(Component.text(",")).append(Component.space());

View File

@ -0,0 +1,80 @@
package dev.plex.command.impl;
import dev.plex.cache.DataUtils;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
//TODO: Redo Messages and have customizable messages
@CommandPermissions(level = Rank.OP, permission = "plex.tag", source = RequiredCommandSource.ANY)
@CommandParameters(name = "tag", aliases = "prefix", description = "Manages your prefix", usage = "/<command> <set | clear> <prefix | player>")
public class TagCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{
if (sender instanceof ConsoleCommandSender)
{
return usage("/tag clear <player>");
}
return usage();
}
if (args[0].equalsIgnoreCase("set"))
{
if (sender instanceof ConsoleCommandSender)
{
return tl("noPermissionConsole");
}
PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId());
if (args.length < 2)
{
return usage("/tag set <prefix>");
}
String prefix = StringUtils.join(args, " ", 1, args.length);
if (ChatColor.stripColor(prefix).length() > plugin.config.getInt("chat.max-tag-length", 16))
{
return componentFromString("The max length for a tag may only be " + plugin.config.getInt("chat.max-tag-length", 16));
}
player.setPrefix(prefix);
return Component.text("Your prefix has been set to ").color(NamedTextColor.AQUA).append(componentFromString(prefix));
}
if (args[0].equalsIgnoreCase("clear"))
{
if (args.length == 1)
{
if (sender instanceof ConsoleCommandSender)
{
return tl("noPermissionConsole");
}
PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId());
player.setPrefix("");
return Component.text("Your prefix has been cleared.").color(NamedTextColor.AQUA);
}
checkRank(sender, Rank.ADMIN, "plex.tag.clearother");
Player target = getNonNullPlayer(args[1]);
PlexPlayer plexTarget = DataUtils.getPlayer(target.getUniqueId());
plexTarget.setPrefix("");
return Component.text("You have cleared " + target.getName() + "'s prefix.").color(NamedTextColor.AQUA);
}
return usage();
}
}

View File

@ -32,7 +32,6 @@ public class CommandHandler extends PlexBase
commands.add(new BanCMD()); commands.add(new BanCMD());
commands.add(new CommandSpyCMD()); commands.add(new CommandSpyCMD());
commands.add(new CreativeCMD()); commands.add(new CreativeCMD());
commands.add(new FlatlandsCMD()); commands.add(new FlatlandsCMD());
commands.add(new FreezeCMD()); commands.add(new FreezeCMD());
commands.add(new ListCMD()); commands.add(new ListCMD());
@ -43,6 +42,7 @@ public class CommandHandler extends PlexBase
commands.add(new PunishmentsCMD()); commands.add(new PunishmentsCMD());
commands.add(new SpectatorCMD()); commands.add(new SpectatorCMD());
commands.add(new SurvivalCMD()); commands.add(new SurvivalCMD());
commands.add(new TagCMD());
commands.add(new UnbanCMD()); commands.add(new UnbanCMD());
commands.add(new UnfreezeCMD()); commands.add(new UnfreezeCMD());
commands.add(new WorldCMD()); commands.add(new WorldCMD());

View File

@ -41,7 +41,7 @@ public class ChatListener extends PlexListener
{ {
if (hasPrefix) if (hasPrefix)
{ {
return LegacyComponentSerializer.legacyAmpersand().deserialize(prefix) return Component.empty().append(LegacyComponentSerializer.legacyAmpersand().deserialize(prefix))
.append(Component.space()) .append(Component.space())
.append(sourceDisplayName) .append(sourceDisplayName)
.append(Component.space()) .append(Component.space())

View File

@ -36,6 +36,7 @@ public class ServerListener extends PlexListener
List<String> samples = plugin.config.getStringList("server.sample"); List<String> samples = plugin.config.getStringList("server.sample");
if (!samples.isEmpty()) if (!samples.isEmpty())
{ {
event.getPlayerSample().clear();
event.getPlayerSample().addAll(samples.stream().map(string -> string.replace("&", "§")).map(Bukkit::createProfile).collect(Collectors.toList())); event.getPlayerSample().addAll(samples.stream().map(string -> string.replace("&", "§")).map(Bukkit::createProfile).collect(Collectors.toList()));
} }
} }

View File

@ -16,6 +16,9 @@ titles:
banning: banning:
ban_url: "https://forum.plex.us.org" ban_url: "https://forum.plex.us.org"
chat:
max-tag-length: 16
name-color: 'f' #Color code for name color
# Settings for commands relating to Plex # Settings for commands relating to Plex
commands: commands: