mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
- Fix world permissions handling and add more customization
This commit is contained in:
parent
3d3d92d72b
commit
455713db3c
@ -129,7 +129,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
{
|
{
|
||||||
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
||||||
{
|
{
|
||||||
send(sender, tl("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMSG())));
|
send(sender, tl("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage())));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,7 +262,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
{
|
{
|
||||||
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
||||||
{
|
{
|
||||||
throw new CommandFailException(PlexUtils.tl("noPermissionRank", ChatColor.stripColor(rank.getLoginMSG())));
|
throw new CommandFailException(PlexUtils.tl("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
|
@ -23,7 +23,7 @@ public class RankCMD extends PlexCommand
|
|||||||
if (!(playerSender == null))
|
if (!(playerSender == null))
|
||||||
{
|
{
|
||||||
Rank rank = getPlexPlayer(playerSender).getRankFromString();
|
Rank rank = getPlexPlayer(playerSender).getRankFromString();
|
||||||
return tl("yourRank", rank.getReadableString());
|
return tl("yourRank", rank.getReadable());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,6 @@ public class AdminListener extends PlexListener
|
|||||||
Rank newRank = event.getRank();
|
Rank newRank = event.getRank();
|
||||||
target.setRank(newRank.name().toLowerCase());
|
target.setRank(newRank.name().toLowerCase());
|
||||||
DataUtils.update(target);
|
DataUtils.update(target);
|
||||||
PlexUtils.broadcast(tl("adminSetRank", userSender, target.getName(), newRank.getReadableString()));
|
PlexUtils.broadcast(tl("adminSetRank", userSender, target.getName(), newRank.getReadable()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package dev.plex.listener.impl;
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
import dev.plex.Plex;
|
|
||||||
import dev.plex.cache.PlayerCache;
|
import dev.plex.cache.PlayerCache;
|
||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
@ -23,15 +22,11 @@ public class ChatListener extends PlexListener
|
|||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(event.getPlayer().getUniqueId());
|
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(event.getPlayer().getUniqueId());
|
||||||
|
|
||||||
if (!plexPlayer.getPrefix().isEmpty())
|
String prefix = plugin.getRankManager().getPrefix(plexPlayer);
|
||||||
|
if (!prefix.isEmpty())
|
||||||
{
|
{
|
||||||
renderer.hasPrefix = true;
|
renderer.hasPrefix = true;
|
||||||
renderer.prefix = plexPlayer.getPrefix();
|
renderer.prefix = prefix;
|
||||||
}
|
|
||||||
else if (Plex.get().getRankManager().isAdmin(plexPlayer))
|
|
||||||
{
|
|
||||||
renderer.hasPrefix = true;
|
|
||||||
renderer.prefix = plexPlayer.getRankFromString().getPrefix();
|
|
||||||
}
|
}
|
||||||
event.renderer(renderer);
|
event.renderer(renderer);
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,6 @@ import dev.plex.listener.PlexListener;
|
|||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.player.PunishedPlayer;
|
import dev.plex.player.PunishedPlayer;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.UUID;
|
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -19,6 +17,9 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PlayerListener extends PlexListener
|
public class PlayerListener extends PlexListener
|
||||||
{
|
{
|
||||||
private final MongoPlayerData mongoPlayerData = plugin.getMongoPlayerData() != null ? plugin.getMongoPlayerData() : null;
|
private final MongoPlayerData mongoPlayerData = plugin.getMongoPlayerData() != null ? plugin.getMongoPlayerData() : null;
|
||||||
@ -36,8 +37,7 @@ public class PlayerListener extends PlexListener
|
|||||||
{
|
{
|
||||||
player.setOp(true);
|
player.setOp(true);
|
||||||
PlexLog.debug("Automatically opped " + player.getName() + " since ranks are enabled.");
|
PlexLog.debug("Automatically opped " + player.getName() + " since ranks are enabled.");
|
||||||
}
|
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
|
||||||
{
|
{
|
||||||
player.setOp(false);
|
player.setOp(false);
|
||||||
PlexLog.debug("Automatically deopped " + player.getName() + " since ranks are disabled.");
|
PlexLog.debug("Automatically deopped " + player.getName() + " since ranks are disabled.");
|
||||||
@ -50,8 +50,7 @@ public class PlayerListener extends PlexListener
|
|||||||
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());
|
||||||
}
|
}
|
||||||
@ -62,13 +61,16 @@ public class PlayerListener extends PlexListener
|
|||||||
{
|
{
|
||||||
punishedPlayer = new PunishedPlayer(player.getUniqueId());
|
punishedPlayer = new PunishedPlayer(player.getUniqueId());
|
||||||
PlayerCache.getPunishedPlayerMap().put(player.getUniqueId(), punishedPlayer);
|
PlayerCache.getPunishedPlayerMap().put(player.getUniqueId(), punishedPlayer);
|
||||||
} else {
|
} else
|
||||||
|
{
|
||||||
punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());
|
punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());
|
||||||
}
|
}
|
||||||
punishedPlayer.convertPunishments();
|
punishedPlayer.convertPunishments();
|
||||||
|
|
||||||
assert plexPlayer != null;
|
assert plexPlayer != null;
|
||||||
|
|
||||||
|
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||||
|
{
|
||||||
if (plugin.getRankManager().isAdmin(plexPlayer))
|
if (plugin.getRankManager().isAdmin(plexPlayer))
|
||||||
{
|
{
|
||||||
Admin admin = new Admin(UUID.fromString(plexPlayer.getUuid()));
|
Admin admin = new Admin(UUID.fromString(plexPlayer.getUuid()));
|
||||||
@ -79,10 +81,10 @@ public class PlayerListener extends PlexListener
|
|||||||
if (!plexPlayer.getLoginMSG().isEmpty())
|
if (!plexPlayer.getLoginMSG().isEmpty())
|
||||||
{
|
{
|
||||||
event.joinMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(ChatColor.AQUA + player.getName() + " is " + plexPlayer.getLoginMSG()));
|
event.joinMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(ChatColor.AQUA + player.getName() + " is " + plexPlayer.getLoginMSG()));
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
event.joinMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(ChatColor.AQUA + player.getName() + " is " + plexPlayer.getRankFromString().getLoginMSG()));
|
event.joinMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(ChatColor.AQUA + player.getName() + " is " + plexPlayer.getRankFromString().getLoginMessage()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,8 +103,7 @@ public class PlayerListener extends PlexListener
|
|||||||
if (mongoPlayerData != null) //back to mongo checking
|
if (mongoPlayerData != null) //back to mongo checking
|
||||||
{
|
{
|
||||||
mongoPlayerData.update(plexPlayer); //update the player's document
|
mongoPlayerData.update(plexPlayer); //update the player's document
|
||||||
}
|
} else if (sqlPlayerData != null) //sql checking
|
||||||
else if (sqlPlayerData != null) //sql checking
|
|
||||||
{
|
{
|
||||||
sqlPlayerData.update(plexPlayer);
|
sqlPlayerData.update(plexPlayer);
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,29 @@
|
|||||||
package dev.plex.listener.impl;
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
import dev.plex.cache.PlayerCache;
|
import dev.plex.cache.PlayerCache;
|
||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
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.rank.enums.Title;
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
|
import dev.plex.util.PlexUtils;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||||
import static dev.plex.util.PlexUtils.tl;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class WorldListener extends PlexListener
|
public class WorldListener extends PlexListener
|
||||||
{
|
{
|
||||||
// TODO: Actually implement permissions for every world properly
|
|
||||||
private final String permission = plugin.config.getString("plex.adminworld.permission");
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockPlace(BlockPlaceEvent e)
|
public void onBlockPlace(BlockPlaceEvent e)
|
||||||
@ -23,28 +31,58 @@ public class WorldListener extends PlexListener
|
|||||||
Player player = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||||
World world = player.getWorld();
|
World world = player.getWorld();
|
||||||
switch (world.getName().toLowerCase())
|
if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
{
|
{
|
||||||
case "adminworld" -> {
|
String permission = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".permission");
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
if (permission == null) return;
|
||||||
|
if (player.hasPermission(permission)) return;
|
||||||
|
} else if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||||
{
|
{
|
||||||
if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN))
|
if (plugin.config.contains("worlds." + world.getName().toLowerCase() + ".requiredLevels"))
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
|
||||||
{
|
|
||||||
if (player.hasPermission(permission));
|
|
||||||
{
|
{
|
||||||
|
@NotNull List<String> requiredLevel = plugin.config.getStringList("worlds." + world.getName().toLowerCase() + ".requiredLevels");
|
||||||
|
if (checkLevel(plexPlayer, requiredLevel.toArray(String[]::new))) return;
|
||||||
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
player.sendMessage(tl("noAdminWorldBlockPlace"));
|
String noEdit = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".noEdit");
|
||||||
break;
|
if (noEdit != null)
|
||||||
|
{
|
||||||
|
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(noEdit));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockBreak(BlockBreakEvent e)
|
||||||
|
{
|
||||||
|
Player player = e.getPlayer();
|
||||||
|
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||||
|
World world = player.getWorld();
|
||||||
|
if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
|
{
|
||||||
|
String permission = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".permission");
|
||||||
|
if (permission == null) return;
|
||||||
|
if (player.hasPermission(permission)) return;
|
||||||
|
} else if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||||
|
{
|
||||||
|
if (plugin.config.contains("worlds." + world.getName().toLowerCase() + ".requiredLevels"))
|
||||||
|
{
|
||||||
|
@NotNull List<String> requiredLevel = plugin.config.getStringList("worlds." + world.getName().toLowerCase() + ".requiredLevels");
|
||||||
|
if (checkLevel(plexPlayer, requiredLevel.toArray(String[]::new))) return;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
String noEdit = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".noEdit");
|
||||||
|
if (noEdit != null)
|
||||||
|
{
|
||||||
|
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(noEdit));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -56,4 +94,40 @@ public class WorldListener extends PlexListener
|
|||||||
}
|
}
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkLevel(PlexPlayer player, String[] requiredList)
|
||||||
|
{
|
||||||
|
PlexLog.debug("Checking world required levels " + Arrays.toString(requiredList));
|
||||||
|
boolean hasAccess = false;
|
||||||
|
for (String required : requiredList)
|
||||||
|
{
|
||||||
|
PlexLog.debug("Checking if player has " + required);
|
||||||
|
if (required.startsWith("Title"))
|
||||||
|
{
|
||||||
|
String titleString = required.split("\\.")[1];
|
||||||
|
Title title = Title.valueOf(titleString.toUpperCase(Locale.ROOT));
|
||||||
|
switch (title)
|
||||||
|
{
|
||||||
|
case DEV -> {
|
||||||
|
hasAccess = PlexUtils.DEVELOPERS.contains(player.getUuid());
|
||||||
|
}
|
||||||
|
case MASTER_BUILDER -> {
|
||||||
|
hasAccess = Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(player.getName());
|
||||||
|
}
|
||||||
|
case OWNER -> {
|
||||||
|
hasAccess = Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName());
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (required.startsWith("Rank"))
|
||||||
|
{
|
||||||
|
String rankString = required.split("\\.")[1];
|
||||||
|
Rank rank = Rank.valueOf(rankString.toUpperCase(Locale.ROOT));
|
||||||
|
hasAccess = player.getRankFromString().isAtLeast(rank);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hasAccess;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,24 +0,0 @@
|
|||||||
package dev.plex.rank;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import java.util.List;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class DefaultRankObj
|
|
||||||
{
|
|
||||||
private final String prefix;
|
|
||||||
private final String loginMSG;
|
|
||||||
private final String readableName;
|
|
||||||
private final List<String> permissions;
|
|
||||||
|
|
||||||
public DefaultRankObj(Rank rank)
|
|
||||||
{
|
|
||||||
this.prefix = rank.getPrefix();
|
|
||||||
this.loginMSG = rank.getLoginMSG();
|
|
||||||
this.readableName = rank.getReadableString();
|
|
||||||
this.permissions = Lists.newArrayList();
|
|
||||||
permissions.add("example.permission");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +1,24 @@
|
|||||||
package dev.plex.rank;
|
package dev.plex.rank;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.gson.Gson;
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
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.rank.enums.Title;
|
||||||
import java.io.File;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.io.FileInputStream;
|
import lombok.SneakyThrows;
|
||||||
import java.io.FileWriter;
|
import org.json.JSONArray;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONTokener;
|
import org.json.JSONTokener;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class RankManager
|
public class RankManager
|
||||||
{
|
{
|
||||||
private final File defaultRanks;
|
private final File options;
|
||||||
|
|
||||||
public RankManager()
|
public RankManager()
|
||||||
{
|
{
|
||||||
@ -26,41 +28,23 @@ public class RankManager
|
|||||||
ranksFolder.mkdir();
|
ranksFolder.mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultRanks = new File(ranksFolder, "default-ranks.json");
|
options = new File(ranksFolder, "options.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
public void generateDefaultRanks()
|
public void generateDefaultRanks()
|
||||||
{
|
{
|
||||||
if (defaultRanks.exists())
|
if (options.exists())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
JSONObject object = new JSONObject();
|
||||||
{
|
object.put("ranks", new JSONArray().putAll(Arrays.stream(Rank.values()).map(Rank::toJSON).collect(Collectors.toList())));
|
||||||
defaultRanks.createNewFile();
|
object.put("titles", new JSONArray().putAll(Arrays.stream(Title.values()).map(Title::toJSON).collect(Collectors.toList())));
|
||||||
|
FileWriter writer = new FileWriter(options);
|
||||||
Map<String, DefaultRankObj> rankMap = Maps.newHashMap();
|
writer.append(object.toString(4));
|
||||||
for (Rank rank : Rank.values())
|
|
||||||
{
|
|
||||||
rankMap.put(rank.name().toUpperCase(), new DefaultRankObj(rank));
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject obj = new JSONObject();
|
|
||||||
if (obj.length() == 0)
|
|
||||||
{
|
|
||||||
obj.put("ranks", rankMap);
|
|
||||||
|
|
||||||
FileWriter writer = new FileWriter(defaultRanks);
|
|
||||||
writer.append(obj.toString(4));
|
|
||||||
writer.flush();
|
writer.flush();
|
||||||
writer.close();
|
writer.close();
|
||||||
PlexLog.log("Generating default-ranks.json");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rank getRankFromString(String rank)
|
public Rank getRankFromString(String rank)
|
||||||
@ -70,34 +54,60 @@ public class RankManager
|
|||||||
|
|
||||||
public void importDefaultRanks()
|
public void importDefaultRanks()
|
||||||
{
|
{
|
||||||
if (!defaultRanks.exists())
|
if (!options.exists())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try (FileInputStream fis = new FileInputStream(options))
|
||||||
{
|
{
|
||||||
FileInputStream stream = new FileInputStream(defaultRanks);
|
JSONTokener tokener = new JSONTokener(fis);
|
||||||
JSONTokener tokener = new JSONTokener(stream);
|
|
||||||
JSONObject object = new JSONObject(tokener);
|
JSONObject object = new JSONObject(tokener);
|
||||||
JSONObject rankObj = object.getJSONObject("ranks");
|
|
||||||
for (Rank rank : Rank.values())
|
JSONArray ranks = object.getJSONArray("ranks");
|
||||||
{
|
ranks.forEach(r -> {
|
||||||
if (rankObj.isNull(rank.name().toUpperCase()))
|
JSONObject rank = new JSONObject(r.toString());
|
||||||
{
|
String key = rank.keys().next();
|
||||||
continue;
|
Rank.valueOf(key).setLoginMessage(rank.getJSONObject(key).getString("loginMessage"));
|
||||||
}
|
Rank.valueOf(key).setPrefix(rank.getJSONObject(key).getString("prefix"));
|
||||||
rank.setLoginMessage(rankObj.getJSONObject(rank.name().toUpperCase()).getString("loginMSG"));
|
});
|
||||||
rank.setPrefix(rankObj.getJSONObject(rank.name().toUpperCase()).getString("prefix")); //should i even be doing this
|
|
||||||
rank.setHumanReadableString(rankObj.getJSONObject(rank.name().toUpperCase()).getString("readableName")); // i dont know
|
JSONArray titles = object.getJSONArray("titles");
|
||||||
rank.setPermissions(rankObj.getJSONObject(rank.name().toUpperCase()).getJSONArray("permissions").toList().stream().map(Object::toString).collect(Collectors.toList()));
|
titles.forEach(t -> {
|
||||||
}
|
JSONObject title = new JSONObject(t.toString());
|
||||||
}
|
String key = title.keys().next();
|
||||||
catch (IOException e)
|
Title.valueOf(key).setLoginMessage(title.getJSONObject(key).getString("loginMessage"));
|
||||||
|
Title.valueOf(key).setPrefix(title.getJSONObject(key).getString("prefix"));
|
||||||
|
});
|
||||||
|
} catch (IOException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrefix(PlexPlayer player)
|
||||||
|
{
|
||||||
|
if (!player.getPrefix().isEmpty())
|
||||||
|
{
|
||||||
|
return player.getPrefix();
|
||||||
|
}
|
||||||
|
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName()))
|
||||||
|
{
|
||||||
|
return Title.OWNER.getPrefix();
|
||||||
|
}
|
||||||
|
if (PlexUtils.DEVELOPERS.contains(player.getUuid())) // don't remove or we will front door ur mother
|
||||||
|
{
|
||||||
|
return Title.DEV.getPrefix();
|
||||||
|
}
|
||||||
|
if (Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(player.getName()))
|
||||||
|
{
|
||||||
|
return Title.MASTER_BUILDER.getPrefix();
|
||||||
|
}
|
||||||
|
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(player))
|
||||||
|
{
|
||||||
|
return player.getRankFromString().getPrefix();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAdmin(PlexPlayer plexPlayer)
|
public boolean isAdmin(PlexPlayer plexPlayer)
|
||||||
|
@ -1,23 +1,36 @@
|
|||||||
package dev.plex.rank.enums;
|
package dev.plex.rank.enums;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import java.util.List;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public enum Rank
|
public enum Rank
|
||||||
{
|
{
|
||||||
IMPOSTOR(-1, ChatColor.AQUA + "an " + ChatColor.YELLOW + "Impostor", "Impostor", ChatColor.YELLOW + "[Imp]"),
|
IMPOSTOR(-1, ChatColor.AQUA + "an " + ChatColor.YELLOW + "Impostor", "Impostor", "&8[&eImp&8]"),
|
||||||
NONOP(0, "a " + ChatColor.WHITE + "Non-Op", "Non-Op", ChatColor.WHITE + ""),
|
NONOP(0, "a " + ChatColor.WHITE + "Non-Op", "Non-Op", ""),
|
||||||
OP(1, "an " + ChatColor.GREEN + "Operator", "Operator", ChatColor.GREEN + "[OP]"),
|
OP(1, "an " + ChatColor.GREEN + "Operator", "Operator", "&8[&aOp&8]"),
|
||||||
ADMIN(2, "an " + ChatColor.DARK_GREEN + "Admin", "Admin", ChatColor.DARK_GREEN + "[Admin]"),
|
ADMIN(2, "an " + ChatColor.DARK_GREEN + "Admin", "Admin", "&8[&2Admin&8]"),
|
||||||
SENIOR_ADMIN(3, "a " + ChatColor.GOLD + "Senior Admin", "Senior Admin", ChatColor.GOLD + "[SrA]"),
|
SENIOR_ADMIN(3, "a " + ChatColor.GOLD + "Senior Admin", "Senior Admin", "&8[&6SrA&8]"),
|
||||||
EXECUTIVE(4, "an " + ChatColor.RED + "Executive", "Executive", ChatColor.RED + "[Exec]");
|
EXECUTIVE(4, "an " + ChatColor.RED + "Executive", "Executive", "&8[&cExec&8]");
|
||||||
|
|
||||||
private final int level;
|
private final int level;
|
||||||
|
|
||||||
|
@Setter
|
||||||
private String loginMessage;
|
private String loginMessage;
|
||||||
|
|
||||||
|
@Setter
|
||||||
private String readable;
|
private String readable;
|
||||||
|
|
||||||
|
@Setter
|
||||||
private String prefix;
|
private String prefix;
|
||||||
private List<String> permissions;
|
|
||||||
|
|
||||||
Rank(int level, String loginMessage, String readable, String prefix)
|
Rank(int level, String loginMessage, String readable, String prefix)
|
||||||
{
|
{
|
||||||
@ -25,56 +38,18 @@ public enum Rank
|
|||||||
this.loginMessage = loginMessage;
|
this.loginMessage = loginMessage;
|
||||||
this.readable = readable;
|
this.readable = readable;
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
this.permissions = Lists.newArrayList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPrefix()
|
|
||||||
{
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLoginMSG()
|
|
||||||
{
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', loginMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLevel()
|
|
||||||
{
|
|
||||||
return level;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getReadableString()
|
|
||||||
{
|
|
||||||
return readable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLoginMessage(String msg)
|
|
||||||
{
|
|
||||||
this.loginMessage = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrefix(String prefix)
|
|
||||||
{
|
|
||||||
this.prefix = prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHumanReadableString(String readable)
|
|
||||||
{
|
|
||||||
this.readable = readable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAtLeast(Rank rank)
|
public boolean isAtLeast(Rank rank)
|
||||||
{
|
{
|
||||||
return getLevel() >= rank.getLevel();
|
return this.level >= rank.getLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getPermissions()
|
public JSONObject toJSON()
|
||||||
{
|
{
|
||||||
return permissions;
|
JSONObject object = new JSONObject();
|
||||||
}
|
object.put("prefix", this.prefix);
|
||||||
|
object.put("loginMessage", this.loginMessage);
|
||||||
public void setPermissions(List<String> permissions)
|
return new JSONObject().put(this.name(), object);
|
||||||
{
|
|
||||||
this.permissions = permissions;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,41 @@
|
|||||||
package dev.plex.rank.enums;
|
package dev.plex.rank.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public enum Title
|
public enum Title
|
||||||
{
|
{
|
||||||
MASTER_BUILDER(0, ChatColor.AQUA + "a " + ChatColor.DARK_AQUA + "Master Builder", "Master Builder", ChatColor.DARK_AQUA + "[MB]"),
|
MASTER_BUILDER(0, ChatColor.AQUA + "a " + ChatColor.DARK_AQUA + "Master Builder", "Master Builder", "&8[&3Master Builder&8]"),
|
||||||
DEV(1, ChatColor.AQUA + "a " + ChatColor.DARK_PURPLE + "Developer", "Developer", ChatColor.DARK_PURPLE + "[DEV]"),
|
DEV(1, ChatColor.AQUA + "a " + ChatColor.DARK_PURPLE + "Developer", "Developer", "&8[&5Developer&8]"),
|
||||||
OWNER(2, ChatColor.AQUA + "an " + ChatColor.BLUE + "Owner", "Owner", ChatColor.BLUE + "[Owner]");
|
OWNER(2, ChatColor.AQUA + "an " + ChatColor.BLUE + "Owner", "Owner", "&8[&9Owner&8]");
|
||||||
|
|
||||||
private int level;
|
private final int level;
|
||||||
private String loginMSG;
|
|
||||||
|
@Setter
|
||||||
|
private String loginMessage;
|
||||||
|
|
||||||
|
@Setter
|
||||||
private String readable;
|
private String readable;
|
||||||
|
|
||||||
|
@Setter
|
||||||
private String prefix;
|
private String prefix;
|
||||||
|
|
||||||
Title(int level, String loginMSG, String readable, String prefix)
|
Title(int level, String loginMessage, String readable, String prefix)
|
||||||
{
|
{
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.loginMSG = loginMSG;
|
this.loginMessage = loginMessage;
|
||||||
this.readable = readable;
|
this.readable = readable;
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JSONObject toJSON()
|
||||||
|
{
|
||||||
|
JSONObject object = new JSONObject();
|
||||||
|
object.put("prefix", this.prefix);
|
||||||
|
object.put("loginMessage", this.loginMessage);
|
||||||
|
return new JSONObject().put(this.name(), object);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,10 @@ server:
|
|||||||
sample:
|
sample:
|
||||||
- "&cForums: https://forum.plex.us.org"
|
- "&cForums: https://forum.plex.us.org"
|
||||||
|
|
||||||
|
titles:
|
||||||
|
masterbuilders: []
|
||||||
|
owners: []
|
||||||
|
|
||||||
# Ban message is customized in the messages.yml file. The URL to appeal at is below.
|
# Ban message is customized in the messages.yml file. The URL to appeal at is below.
|
||||||
banning:
|
banning:
|
||||||
ban_url: "https://forum.plex.us.org"
|
ban_url: "https://forum.plex.us.org"
|
||||||
@ -33,10 +37,12 @@ data:
|
|||||||
port: 6379
|
port: 6379
|
||||||
password: ""
|
password: ""
|
||||||
|
|
||||||
|
# requiredLevel if permissions are ranks, else permissions
|
||||||
worlds:
|
worlds:
|
||||||
flatlands:
|
flatlands:
|
||||||
name: "Flatlands"
|
name: "Flatlands"
|
||||||
permission: "plex.world.flatlands"
|
permission: "plex.world.flatlands"
|
||||||
|
noEdit: "&cYou can't edit this world!"
|
||||||
parameters:
|
parameters:
|
||||||
grass_block: 1
|
grass_block: 1
|
||||||
dirt: 32
|
dirt: 32
|
||||||
@ -45,6 +51,9 @@ worlds:
|
|||||||
adminworld:
|
adminworld:
|
||||||
name: "Admin World"
|
name: "Admin World"
|
||||||
permission: "plex.world.adminworld"
|
permission: "plex.world.adminworld"
|
||||||
|
requiredLevels:
|
||||||
|
- "Rank.ADMIN" # Minimum rank requirement
|
||||||
|
noEdit: "&cYou can't edit this world!"
|
||||||
parameters:
|
parameters:
|
||||||
grass_block: 1
|
grass_block: 1
|
||||||
dirt: 32
|
dirt: 32
|
||||||
@ -53,6 +62,9 @@ worlds:
|
|||||||
masterbuilderworld:
|
masterbuilderworld:
|
||||||
name: "MasterBuilder World"
|
name: "MasterBuilder World"
|
||||||
permission: "plex.world.masterbuilderworld"
|
permission: "plex.world.masterbuilderworld"
|
||||||
|
requiredLevels:
|
||||||
|
- "Title.MASTER_BUILDER" # Title has no "minimum", so this will have to be their title
|
||||||
|
noEdit: "&cYou can't edit this world!"
|
||||||
parameters:
|
parameters:
|
||||||
grass_block: 1
|
grass_block: 1
|
||||||
dirt: 32
|
dirt: 32
|
||||||
|
@ -29,8 +29,7 @@ test: "this is a test message!"
|
|||||||
variableTest: "variable test with <v>!"
|
variableTest: "variable test with <v>!"
|
||||||
playerNotFound: "Player not found!"
|
playerNotFound: "Player not found!"
|
||||||
worldNotFound: "World not found!"
|
worldNotFound: "World not found!"
|
||||||
noAdminWorldBlockPlace: "<e>You are not allowed to place blocks in the admin world!"
|
|
||||||
noAdminWorldBlockBreak: "<e>You are not allowed to break blocks in the admin world!"
|
|
||||||
# 1: the world you have been teleported to
|
# 1: the world you have been teleported to
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user