mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
- Create tag command
- Fix bug fixes
This commit is contained in:
parent
ab0666ebeb
commit
355a930c89
@ -21,13 +21,14 @@ import dev.plex.storage.StorageType;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.world.CustomWorld;
|
||||
import java.util.UUID;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Plex extends JavaPlugin
|
||||
@ -81,8 +82,7 @@ public class Plex extends JavaPlugin
|
||||
{
|
||||
PlexUtils.testConnections();
|
||||
PlexLog.log("Connected to " + storageType.name().toUpperCase());
|
||||
}
|
||||
catch (Exception e)
|
||||
} catch (Exception e)
|
||||
{
|
||||
PlexLog.error("Failed to connect to " + storageType.name().toUpperCase());
|
||||
e.printStackTrace();
|
||||
@ -96,8 +96,7 @@ public class Plex extends JavaPlugin
|
||||
{
|
||||
redisConnection.getJedis();
|
||||
PlexLog.log("Connected to Redis!");
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
PlexLog.log("Redis is disabled in the configuration file, not connecting.");
|
||||
}
|
||||
@ -105,8 +104,7 @@ public class Plex extends JavaPlugin
|
||||
if (storageType == StorageType.MONGODB)
|
||||
{
|
||||
mongoPlayerData = new MongoPlayerData();
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
sqlPlayerData = new SQLPlayerData();
|
||||
}
|
||||
@ -139,6 +137,23 @@ public class Plex extends JavaPlugin
|
||||
@Override
|
||||
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())
|
||||
{
|
||||
PlexLog.log("Disabling Redis/Jedis. No memory leaks in this Anarchy server!");
|
||||
|
@ -260,7 +260,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||
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())));
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import dev.plex.rank.enums.Rank;
|
||||
import java.util.List;
|
||||
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.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -37,7 +38,7 @@ public class ListCMD extends PlexCommand
|
||||
for (int i = 0; i < players.size(); 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)
|
||||
{
|
||||
component = component.append(Component.text(",")).append(Component.space());
|
||||
|
80
src/main/java/dev/plex/command/impl/TagCMD.java
Normal file
80
src/main/java/dev/plex/command/impl/TagCMD.java
Normal 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();
|
||||
}
|
||||
}
|
@ -32,7 +32,6 @@ public class CommandHandler extends PlexBase
|
||||
commands.add(new BanCMD());
|
||||
commands.add(new CommandSpyCMD());
|
||||
commands.add(new CreativeCMD());
|
||||
|
||||
commands.add(new FlatlandsCMD());
|
||||
commands.add(new FreezeCMD());
|
||||
commands.add(new ListCMD());
|
||||
@ -43,6 +42,7 @@ public class CommandHandler extends PlexBase
|
||||
commands.add(new PunishmentsCMD());
|
||||
commands.add(new SpectatorCMD());
|
||||
commands.add(new SurvivalCMD());
|
||||
commands.add(new TagCMD());
|
||||
commands.add(new UnbanCMD());
|
||||
commands.add(new UnfreezeCMD());
|
||||
commands.add(new WorldCMD());
|
||||
|
@ -41,7 +41,7 @@ public class ChatListener extends PlexListener
|
||||
{
|
||||
if (hasPrefix)
|
||||
{
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(prefix)
|
||||
return Component.empty().append(LegacyComponentSerializer.legacyAmpersand().deserialize(prefix))
|
||||
.append(Component.space())
|
||||
.append(sourceDisplayName)
|
||||
.append(Component.space())
|
||||
|
@ -36,6 +36,7 @@ public class ServerListener extends PlexListener
|
||||
List<String> samples = plugin.config.getStringList("server.sample");
|
||||
if (!samples.isEmpty())
|
||||
{
|
||||
event.getPlayerSample().clear();
|
||||
event.getPlayerSample().addAll(samples.stream().map(string -> string.replace("&", "§")).map(Bukkit::createProfile).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,9 @@ titles:
|
||||
banning:
|
||||
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
|
||||
commands:
|
||||
|
Loading…
Reference in New Issue
Block a user