mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
Begin work on implementing ranks
This commit is contained in:
parent
9043005d62
commit
86f3fd8d29
@ -52,6 +52,8 @@ public class Plex extends JavaPlugin
|
||||
|
||||
private AdminList adminList;
|
||||
|
||||
private String ranksOrPermissions;
|
||||
|
||||
public static Plex get()
|
||||
{
|
||||
return plugin;
|
||||
@ -87,7 +89,8 @@ 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,7 +99,8 @@ public class Plex extends JavaPlugin
|
||||
if (storageType == StorageType.MONGODB)
|
||||
{
|
||||
mongoPlayerData = new MongoPlayerData();
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlPlayerData = new SQLPlayerData();
|
||||
}
|
||||
@ -104,9 +108,12 @@ public class Plex extends JavaPlugin
|
||||
new ListenerHandler(); // this doesn't need a variable.
|
||||
new CommandHandler();
|
||||
|
||||
ranksOrPermissions = config.getString("commands.permissions");
|
||||
|
||||
rankManager = new RankManager();
|
||||
rankManager.generateDefaultRanks();
|
||||
rankManager.importDefaultRanks();
|
||||
adminList = new AdminList();
|
||||
PlexLog.log("Rank Manager initialized");
|
||||
|
||||
punishmentManager = new PunishmentManager();
|
||||
@ -119,8 +126,6 @@ public class Plex extends JavaPlugin
|
||||
serviceManager.startServices();
|
||||
PlexLog.log("Started " + serviceManager.serviceCount() + " services.");
|
||||
|
||||
adminList = new AdminList();
|
||||
|
||||
generateWorlds();
|
||||
|
||||
reloadPlayers();
|
||||
|
@ -13,6 +13,7 @@ import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
@ -85,12 +86,30 @@ public abstract class PlexCommand extends Command
|
||||
Player player = (Player)sender;
|
||||
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||
|
||||
if (plugin.getRanksOrPermissions().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
Component component = this.execute(sender, args);
|
||||
@ -146,6 +165,21 @@ public abstract class PlexCommand extends Command
|
||||
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)
|
||||
{
|
||||
@ -159,13 +193,13 @@ public abstract class PlexCommand extends Command
|
||||
return true;
|
||||
}
|
||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||
return Plex.get().getRankManager().isAdmin(plexPlayer);
|
||||
return plugin.getRankManager().isAdmin(plexPlayer);
|
||||
}
|
||||
|
||||
protected boolean isAdmin(String name)
|
||||
{
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(name);
|
||||
return Plex.get().getRankManager().isAdmin(plexPlayer);
|
||||
return plugin.getRankManager().isAdmin(plexPlayer);
|
||||
}
|
||||
|
||||
protected boolean isSeniorAdmin(CommandSender sender)
|
||||
@ -175,7 +209,7 @@ public abstract class PlexCommand extends Command
|
||||
return true;
|
||||
}
|
||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||
return Plex.get().getRankManager().isSeniorAdmin(plexPlayer);
|
||||
return plugin.getRankManager().isSeniorAdmin(plexPlayer);
|
||||
}
|
||||
|
||||
protected UUID getUUID(CommandSender sender)
|
||||
|
@ -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;
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CommandPermissions
|
||||
@ -11,4 +12,6 @@ public @interface CommandPermissions
|
||||
Rank level() default Rank.IMPOSTOR;
|
||||
|
||||
RequiredCommandSource source() default RequiredCommandSource.ANY;
|
||||
|
||||
String permission() default "plex.donotgivethispermission"; // No idea what to put here
|
||||
}
|
@ -11,11 +11,10 @@ import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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")
|
||||
public class AdminworldCMD extends PlexCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
|
28
src/main/java/dev/plex/command/impl/DeopAllCMD.java
Normal file
28
src/main/java/dev/plex/command/impl/DeopAllCMD.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
@ -12,7 +12,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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)
|
||||
public class ListCMD extends PlexCommand
|
||||
{
|
||||
|
@ -14,7 +14,6 @@ import org.bukkit.entity.Player;
|
||||
@CommandPermissions(level = Rank.ADMIN)
|
||||
public class OpAllCMD extends PlexCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
|
@ -13,11 +13,11 @@ import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(name = "rank", description = "Displays your rank")
|
||||
public class RankCMD extends PlexCommand {
|
||||
|
||||
public class RankCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args) {
|
||||
return tl("yourRank", getPlexPlayer((Player) sender).getRank());
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
return tl("yourRank", getPlexPlayer((Player)sender).getRank());
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,7 @@ import dev.plex.command.impl.AdminworldCMD;
|
||||
import dev.plex.command.impl.AdventureCMD;
|
||||
import dev.plex.command.impl.BanCMD;
|
||||
import dev.plex.command.impl.CreativeCMD;
|
||||
import dev.plex.command.impl.DeopAllCMD;
|
||||
import dev.plex.command.impl.FlatlandsCMD;
|
||||
import dev.plex.command.impl.FreezeCMD;
|
||||
import dev.plex.command.impl.ListCMD;
|
||||
@ -33,6 +34,7 @@ public class CommandHandler
|
||||
commands.add(new AdventureCMD());
|
||||
commands.add(new BanCMD());
|
||||
commands.add(new CreativeCMD());
|
||||
commands.add(new DeopAllCMD());
|
||||
commands.add(new FlatlandsCMD());
|
||||
commands.add(new FreezeCMD());
|
||||
commands.add(new ListCMD());
|
||||
|
@ -34,13 +34,15 @@ public class PlayerListener extends PlexListener
|
||||
|
||||
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.setName(player.getName()); //set the name of the player
|
||||
plexPlayer.setIps(Collections.singletonList(player.getAddress().getAddress().getHostAddress().trim())); //set the arraylist of ips
|
||||
|
||||
DataUtils.insert(plexPlayer); // insert data in some wack db
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||
}
|
||||
|
||||
@ -87,10 +89,7 @@ public class PlayerListener extends PlexListener
|
||||
sqlPlayerData.update(plexPlayer);
|
||||
}
|
||||
|
||||
|
||||
PlayerCache.getPlexPlayerMap().remove(event.getPlayer().getUniqueId()); //remove them from cache
|
||||
PlayerCache.getPunishedPlayerMap().remove(event.getPlayer().getUniqueId());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -63,6 +63,11 @@ public class RankManager
|
||||
}
|
||||
}
|
||||
|
||||
public Rank getRankFromString(String rank)
|
||||
{
|
||||
return Rank.valueOf(rank.toUpperCase());
|
||||
}
|
||||
|
||||
public void importDefaultRanks()
|
||||
{
|
||||
if (!defaultRanks.exists())
|
||||
|
@ -5,6 +5,11 @@ server:
|
||||
motd: "%servername% - Minecraft %mcversion%"
|
||||
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:
|
||||
central:
|
||||
storage: sqlite # Use mariadb, mongodb, or sqlite here
|
||||
|
@ -30,6 +30,7 @@ noAdminWorldBlockBreak: "<e>You are not allowed to break blocks in the admin wor
|
||||
playerWorldTeleport: "You have been teleported to <v>."
|
||||
# 1: the command sender who opped everyone
|
||||
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
|
||||
# 2: the person who has been opped
|
||||
oppedPlayer: "<b><v> - Opped <v>"
|
||||
@ -42,6 +43,7 @@ unfrozePlayer: "<b><v> - Unfroze <v>"
|
||||
noPermission: "<e>You cannot use this 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!"
|
||||
noPermissionNode: "<e>You must have the permission: <v> 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!"
|
||||
# 1: the username of the name history
|
||||
|
Loading…
Reference in New Issue
Block a user