Begin work on implementing ranks

This commit is contained in:
Telesphoreo 2022-01-29 16:35:48 -06:00
parent 9043005d62
commit 86f3fd8d29
14 changed files with 118 additions and 27 deletions

View File

@ -52,6 +52,8 @@ public class Plex extends JavaPlugin
private AdminList adminList; private AdminList adminList;
private String ranksOrPermissions;
public static Plex get() public static Plex get()
{ {
return plugin; return plugin;
@ -87,7 +89,8 @@ 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,7 +99,8 @@ 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();
} }
@ -104,10 +108,13 @@ public class Plex extends JavaPlugin
new ListenerHandler(); // this doesn't need a variable. new ListenerHandler(); // this doesn't need a variable.
new CommandHandler(); new CommandHandler();
rankManager = new RankManager(); ranksOrPermissions = config.getString("commands.permissions");
rankManager.generateDefaultRanks();
rankManager.importDefaultRanks(); rankManager = new RankManager();
PlexLog.log("Rank Manager initialized"); rankManager.generateDefaultRanks();
rankManager.importDefaultRanks();
adminList = new AdminList();
PlexLog.log("Rank Manager initialized");
punishmentManager = new PunishmentManager(); punishmentManager = new PunishmentManager();
banManager = new BanManager(); banManager = new BanManager();
@ -119,8 +126,6 @@ public class Plex extends JavaPlugin
serviceManager.startServices(); serviceManager.startServices();
PlexLog.log("Started " + serviceManager.serviceCount() + " services."); PlexLog.log("Started " + serviceManager.serviceCount() + " services.");
adminList = new AdminList();
generateWorlds(); generateWorlds();
reloadPlayers(); reloadPlayers();

View File

@ -13,6 +13,7 @@ import dev.plex.command.exception.PlayerNotFoundException;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank; import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.Arrays; import java.util.Arrays;
import java.util.UUID; import java.util.UUID;
@ -85,9 +86,27 @@ public abstract class PlexCommand extends Command
Player player = (Player)sender; Player player = (Player)sender;
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId()); PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
if (plugin.getRanksOrPermissions().equalsIgnoreCase("ranks"))
{ {
send(sender, tl("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMSG()))); if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
{
send(sender, tl("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMSG())));
return true;
}
}
else if (plugin.getRanksOrPermissions().equalsIgnoreCase("permissions"))
{
if (!player.hasPermission(perms.permission()))
{
send(sender, tl("noPermissionNode", perms.permission()));
return true;
}
}
else
{
PlexLog.error("Neither permissions or ranks were selected to be used in the configuration file!");
send(sender, "There is a server misconfiguration. Please alert a developer or the owner");
return true; return true;
} }
} }
@ -146,6 +165,21 @@ public abstract class PlexCommand extends Command
audience.sendMessage(component); audience.sendMessage(component);
} }
protected void checkRank(Player player, Rank rank, String permission)
{
PlexPlayer plexPlayer = getPlexPlayer(player);
if (plugin.getRanksOrPermissions().equalsIgnoreCase("ranks"))
{
send(player, "test ranks");
}
else if (plugin.getRanksOrPermissions().equalsIgnoreCase("permissions"))
{
if (!player.hasPermission(permission))
{
send(player, "test permissions");
}
}
}
protected boolean isAdmin(PlexPlayer plexPlayer) protected boolean isAdmin(PlexPlayer plexPlayer)
{ {
@ -159,13 +193,13 @@ public abstract class PlexCommand extends Command
return true; return true;
} }
PlexPlayer plexPlayer = getPlexPlayer(player); PlexPlayer plexPlayer = getPlexPlayer(player);
return Plex.get().getRankManager().isAdmin(plexPlayer); return plugin.getRankManager().isAdmin(plexPlayer);
} }
protected boolean isAdmin(String name) protected boolean isAdmin(String name)
{ {
PlexPlayer plexPlayer = DataUtils.getPlayer(name); PlexPlayer plexPlayer = DataUtils.getPlayer(name);
return Plex.get().getRankManager().isAdmin(plexPlayer); return plugin.getRankManager().isAdmin(plexPlayer);
} }
protected boolean isSeniorAdmin(CommandSender sender) protected boolean isSeniorAdmin(CommandSender sender)
@ -175,7 +209,7 @@ public abstract class PlexCommand extends Command
return true; return true;
} }
PlexPlayer plexPlayer = getPlexPlayer(player); PlexPlayer plexPlayer = getPlexPlayer(player);
return Plex.get().getRankManager().isSeniorAdmin(plexPlayer); return plugin.getRankManager().isSeniorAdmin(plexPlayer);
} }
protected UUID getUUID(CommandSender sender) protected UUID getUUID(CommandSender sender)

View File

@ -0,0 +1,10 @@
package dev.plex.command.annotation;
import dev.plex.rank.enums.Rank;
public @interface CheckPermission
{
String permission() default "";
Rank rank() default Rank.IMPOSTOR;
}

View File

@ -4,6 +4,7 @@ import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank; import dev.plex.rank.enums.Rank;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import org.bukkit.permissions.Permission;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface CommandPermissions public @interface CommandPermissions
@ -11,4 +12,6 @@ public @interface CommandPermissions
Rank level() default Rank.IMPOSTOR; Rank level() default Rank.IMPOSTOR;
RequiredCommandSource source() default RequiredCommandSource.ANY; RequiredCommandSource source() default RequiredCommandSource.ANY;
String permission() default "plex.donotgivethispermission"; // No idea what to put here
} }

View File

@ -11,11 +11,10 @@ import org.bukkit.Location;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = RequiredCommandSource.IN_GAME) @CommandPermissions(level = Rank.ADMIN, permission = "plex.adminworld", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "adminworld", aliases = "aw", description = "Teleport to the adminworld") @CommandParameters(name = "adminworld", aliases = "aw", description = "Teleport to the adminworld")
public class AdminworldCMD extends PlexCommand public class AdminworldCMD extends PlexCommand
{ {
@Override @Override
public Component execute(CommandSender sender, String[] args) public Component execute(CommandSender sender, String[] args)
{ {

View File

@ -0,0 +1,28 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandParameters(name = "deopall", description = "Deop everyone on the server", aliases = "deopa")
@CommandPermissions(level = Rank.ADMIN)
public class DeopAllCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
{
for (Player player : Bukkit.getOnlinePlayers())
{
player.setOp(false);
}
PlexUtils.broadcast(tl("deoppedAllPlayers", sender.getName()));
return null;
}
}

View File

@ -12,7 +12,7 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandParameters(name = "list", description = "Freeze a player on the server", usage = "/<command> <player>") @CommandParameters(name = "list", description = "Show a list of all online players", usage = "/<command> <player>")
@CommandPermissions(level = Rank.OP) @CommandPermissions(level = Rank.OP)
public class ListCMD extends PlexCommand public class ListCMD extends PlexCommand
{ {

View File

@ -14,7 +14,6 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN) @CommandPermissions(level = Rank.ADMIN)
public class OpAllCMD extends PlexCommand public class OpAllCMD extends PlexCommand
{ {
@Override @Override
public Component execute(CommandSender sender, String[] args) public Component execute(CommandSender sender, String[] args)
{ {

View File

@ -13,11 +13,11 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME) @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "rank", description = "Displays your rank") @CommandParameters(name = "rank", description = "Displays your rank")
public class RankCMD extends PlexCommand { public class RankCMD extends PlexCommand
{
@Override @Override
public Component execute(CommandSender sender, String[] args) { public Component execute(CommandSender sender, String[] args)
return tl("yourRank", getPlexPlayer((Player) sender).getRank()); {
return tl("yourRank", getPlexPlayer((Player)sender).getRank());
} }
} }

View File

@ -7,6 +7,7 @@ import dev.plex.command.impl.AdminworldCMD;
import dev.plex.command.impl.AdventureCMD; import dev.plex.command.impl.AdventureCMD;
import dev.plex.command.impl.BanCMD; import dev.plex.command.impl.BanCMD;
import dev.plex.command.impl.CreativeCMD; import dev.plex.command.impl.CreativeCMD;
import dev.plex.command.impl.DeopAllCMD;
import dev.plex.command.impl.FlatlandsCMD; import dev.plex.command.impl.FlatlandsCMD;
import dev.plex.command.impl.FreezeCMD; import dev.plex.command.impl.FreezeCMD;
import dev.plex.command.impl.ListCMD; import dev.plex.command.impl.ListCMD;
@ -33,6 +34,7 @@ public class CommandHandler
commands.add(new AdventureCMD()); commands.add(new AdventureCMD());
commands.add(new BanCMD()); commands.add(new BanCMD());
commands.add(new CreativeCMD()); commands.add(new CreativeCMD());
commands.add(new DeopAllCMD());
commands.add(new FlatlandsCMD()); commands.add(new FlatlandsCMD());
commands.add(new FreezeCMD()); commands.add(new FreezeCMD());
commands.add(new ListCMD()); commands.add(new ListCMD());

View File

@ -34,13 +34,15 @@ public class PlayerListener extends PlexListener
if (!DataUtils.hasPlayedBefore(player.getUniqueId())) if (!DataUtils.hasPlayedBefore(player.getUniqueId()))
{ {
PlexLog.log("A player with this name has not joined the server before, creating new entry."); // funi msg PlexLog.log("A player with this name has not joined the server before, creating new entry.");
plexPlayer = new PlexPlayer(player.getUniqueId()); //it doesn't! okay so now create the object plexPlayer = new PlexPlayer(player.getUniqueId()); //it doesn't! okay so now create the object
plexPlayer.setName(player.getName()); //set the name of the player plexPlayer.setName(player.getName()); //set the name of the player
plexPlayer.setIps(Collections.singletonList(player.getAddress().getAddress().getHostAddress().trim())); //set the arraylist of ips plexPlayer.setIps(Collections.singletonList(player.getAddress().getAddress().getHostAddress().trim())); //set the arraylist of ips
DataUtils.insert(plexPlayer); // insert data in some wack db DataUtils.insert(plexPlayer); // insert data in some wack db
} else { }
else
{
plexPlayer = DataUtils.getPlayer(player.getUniqueId()); plexPlayer = DataUtils.getPlayer(player.getUniqueId());
} }
@ -87,10 +89,7 @@ public class PlayerListener extends PlexListener
sqlPlayerData.update(plexPlayer); sqlPlayerData.update(plexPlayer);
} }
PlayerCache.getPlexPlayerMap().remove(event.getPlayer().getUniqueId()); //remove them from cache PlayerCache.getPlexPlayerMap().remove(event.getPlayer().getUniqueId()); //remove them from cache
PlayerCache.getPunishedPlayerMap().remove(event.getPlayer().getUniqueId()); PlayerCache.getPunishedPlayerMap().remove(event.getPlayer().getUniqueId());
} }
} }

View File

@ -63,6 +63,11 @@ public class RankManager
} }
} }
public Rank getRankFromString(String rank)
{
return Rank.valueOf(rank.toUpperCase());
}
public void importDefaultRanks() public void importDefaultRanks()
{ {
if (!defaultRanks.exists()) if (!defaultRanks.exists())

View File

@ -5,6 +5,11 @@ server:
motd: "%servername% - Minecraft %mcversion%" motd: "%servername% - Minecraft %mcversion%"
colorize_motd: true colorize_motd: true
# Settings for commands relating to Plex
commands:
# Should Plex use a "true op" system with ranks or only permission nodes
permissions: ranks
data: data:
central: central:
storage: sqlite # Use mariadb, mongodb, or sqlite here storage: sqlite # Use mariadb, mongodb, or sqlite here

View File

@ -30,6 +30,7 @@ noAdminWorldBlockBreak: "<e>You are not allowed to break blocks in the admin wor
playerWorldTeleport: "You have been teleported to <v>." playerWorldTeleport: "You have been teleported to <v>."
# 1: the command sender who opped everyone # 1: the command sender who opped everyone
oppedAllPlayers: "<b><v> - Opped all players on the server" oppedAllPlayers: "<b><v> - Opped all players on the server"
deoppedAllPlayers: "<b><v> - De-opped all players on the server"
# 1: the person who is opping # 1: the person who is opping
# 2: the person who has been opped # 2: the person who has been opped
oppedPlayer: "<b><v> - Opped <v>" oppedPlayer: "<b><v> - Opped <v>"
@ -42,6 +43,7 @@ unfrozePlayer: "<b><v> - Unfroze <v>"
noPermission: "<e>You cannot use this command!" noPermission: "<e>You cannot use this command!"
# 1: the login message (uncolored) of the rank required to use the command # 1: the login message (uncolored) of the rank required to use the command
noPermissionRank: "<e>You must be at least <v> rank to use this command!" noPermissionRank: "<e>You must be at least <v> rank to use this command!"
noPermissionNode: "<e>You must have the permission: <v> to use this command!"
noPermissionInGame: "<e>You must be in console to use this command!" noPermissionInGame: "<e>You must be in console to use this command!"
noPermissionConsole: "<e>You must be in-game to use this command!" noPermissionConsole: "<e>You must be in-game to use this command!"
# 1: the username of the name history # 1: the username of the name history