Archived
Vault -> LuckPerms 5.5
This commit is contained in:
1 parent
47cfaf7496
commit
b5a15f362a
7 files changed
+117
-22
No files matched your search
+1
-1
@@ -58,7 +58,7 @@ dependencies {
|
||||
compileOnly("jakarta.xml.bind:jakarta.xml.bind-api:4.0.0") // Import jakarta xml bind API.
|
||||
compileOnly("mysql:mysql-connector-java:8.0.32") // Import mysql connector API.
|
||||
compileOnly("org.purpurmc.purpur:purpur-api:1.19.4-R0.1-SNAPSHOT") // Declare Purpur API version to be packaged.
|
||||
compileOnly("com.github.MilkBowl:VaultAPI:1.7") // Import Vault API.
|
||||
compileOnly("net.luckperms:api:5.5") // Import LuckPerms API.
|
||||
compileOnlyApi(project(":libs:Utilities-OG")) // Import TrueOG Network Utilities-OG Java API (from source).
|
||||
implementation("org.jooq:jooq:3.18.4") // Import jooq API.
|
||||
implementation("org.reactivestreams:reactive-streams:1.0.4") // Import reactive streams API.
|
||||
|
||||
@@ -2,11 +2,18 @@ package uk.hotten.staffog;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import lombok.Getter;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.context.MutableContextSet;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import net.luckperms.api.platform.PlayerAdapter;
|
||||
import net.luckperms.api.query.QueryOptions;
|
||||
import net.trueog.utilitiesog.UtilitiesOG;
|
||||
import uk.hotten.staffog.commands.ChatReportCommand;
|
||||
import uk.hotten.staffog.commands.KickCommand;
|
||||
@@ -26,7 +33,9 @@ public class StaffOGPlugin extends JavaPlugin {
|
||||
private static StaffOGPlugin plugin;
|
||||
|
||||
@Getter
|
||||
private static Permission vaultPerms;
|
||||
private static LuckPerms luckPerms;
|
||||
|
||||
private static PlayerAdapter<Player> luckPermsPlayerAdapter;
|
||||
|
||||
@Getter
|
||||
private static String reportWebAddress;
|
||||
@@ -47,10 +56,11 @@ public class StaffOGPlugin extends JavaPlugin {
|
||||
|
||||
this.saveDefaultConfig();
|
||||
|
||||
if (!setupVaultPerms()) {
|
||||
if (!setupLuckPerms()) {
|
||||
|
||||
Console.error("Vault not found. Plugin will be disabled.");
|
||||
Console.error("LuckPerms not found. Plugin will be disabled.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
@@ -82,18 +92,100 @@ public class StaffOGPlugin extends JavaPlugin {
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
if (DatabaseManager.getInstance() == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
DatabaseManager.getInstance().setStatEntry("server_status", "offline");
|
||||
DatabaseManager.getInstance().setStatEntry("player_count", "0");
|
||||
DatabaseManager.getInstance().setStatEntry("staff_count", "0");
|
||||
|
||||
}
|
||||
|
||||
private boolean setupVaultPerms() {
|
||||
private boolean setupLuckPerms() {
|
||||
|
||||
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
|
||||
vaultPerms = rsp.getProvider();
|
||||
RegisteredServiceProvider<LuckPerms> rsp = getServer().getServicesManager().getRegistration(LuckPerms.class);
|
||||
if (rsp == null) {
|
||||
|
||||
return vaultPerms != null;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
luckPerms = rsp.getProvider();
|
||||
if (luckPerms == null) {
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
luckPermsPlayerAdapter = luckPerms.getPlayerAdapter(Player.class);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public static boolean hasPermission(Player player, String permission) {
|
||||
|
||||
return luckPermsPlayerAdapter.getPermissionData(player).checkPermission(permission).asBoolean();
|
||||
|
||||
}
|
||||
|
||||
public static boolean hasPermission(UUID uuid, String username, String worldName, String permission) {
|
||||
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
|
||||
Console.error("Offline LuckPerms permission checks must not run on the main server thread.");
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
boolean wasLoaded = luckPerms.getUserManager().isLoaded(uuid);
|
||||
User user;
|
||||
try {
|
||||
|
||||
user = luckPerms.getUserManager().loadUser(uuid, username).get();
|
||||
|
||||
} catch (InterruptedException error) {
|
||||
|
||||
Thread.currentThread().interrupt();
|
||||
Console.error("Interrupted while loading LuckPerms user for permission check.");
|
||||
return false;
|
||||
|
||||
} catch (ExecutionException error) {
|
||||
|
||||
Console.error("Failed to load LuckPerms user for permission check.");
|
||||
error.printStackTrace();
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
QueryOptions queryOptions = withWorldContext(luckPerms.getContextManager().getStaticQueryOptions(),
|
||||
worldName);
|
||||
return user.getCachedData().getPermissionData(queryOptions).checkPermission(permission).asBoolean();
|
||||
|
||||
} finally {
|
||||
|
||||
if (!wasLoaded) {
|
||||
|
||||
luckPerms.getUserManager().cleanupUser(user);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static QueryOptions withWorldContext(QueryOptions queryOptions, String worldName) {
|
||||
|
||||
MutableContextSet contexts = queryOptions.context().mutableCopy();
|
||||
contexts.removeAll("world");
|
||||
contexts.add("world", worldName);
|
||||
|
||||
return queryOptions.toBuilder().context(contexts).build();
|
||||
|
||||
}
|
||||
|
||||
@@ -127,4 +219,4 @@ public class StaffOGPlugin extends JavaPlugin {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class LinkPanelCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
final String code = sm.createLinkCode(player.getUniqueId(),
|
||||
StaffOGPlugin.getVaultPerms().has(player, "staffog.paneladmin"));
|
||||
StaffOGPlugin.hasPermission(player, "staffog.paneladmin"));
|
||||
if (code == null) {
|
||||
|
||||
UtilitiesOG.trueogMessage(player,
|
||||
@@ -61,4 +61,4 @@ public class LinkPanelCommand implements CommandExecutor {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@ package uk.hotten.staffog.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.time.DateUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@@ -46,13 +46,15 @@ public class TempPunishCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
final Date currentTime = new Date(System.currentTimeMillis());
|
||||
final Calendar until = Calendar.getInstance();
|
||||
until.setTime(currentTime);
|
||||
final long untilTime;
|
||||
switch (StringUtils.lowerCase(args[1])) {
|
||||
|
||||
case "d" -> untilTime = DateUtils.addDays(currentTime, amount).getTime();
|
||||
case "w" -> untilTime = DateUtils.addWeeks(currentTime, amount).getTime();
|
||||
case "m" -> untilTime = DateUtils.addMonths(currentTime, amount).getTime();
|
||||
case "y" -> untilTime = DateUtils.addYears(currentTime, amount).getTime();
|
||||
case "d" -> until.add(Calendar.DAY_OF_MONTH, amount);
|
||||
case "w" -> until.add(Calendar.WEEK_OF_YEAR, amount);
|
||||
case "m" -> until.add(Calendar.MONTH, amount);
|
||||
case "y" -> until.add(Calendar.YEAR, amount);
|
||||
default -> {
|
||||
|
||||
UtilitiesOG.trueogMessage((Player) sender,
|
||||
@@ -63,6 +65,8 @@ public class TempPunishCommand implements CommandExecutor {
|
||||
|
||||
}
|
||||
|
||||
untilTime = until.getTimeInMillis();
|
||||
|
||||
final PunishType commandType;
|
||||
if (StringUtils.contains(StringUtils.lowerCase(label), "tempban")) {
|
||||
|
||||
@@ -130,4 +134,4 @@ public class TempPunishCommand implements CommandExecutor {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class DataEventListener implements Listener {
|
||||
int amount = 0;
|
||||
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||
|
||||
if (StaffOGPlugin.getVaultPerms().has(p, "staffog.isstaff")) {
|
||||
if (StaffOGPlugin.hasPermission(p, "staffog.isstaff")) {
|
||||
|
||||
amount++;
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package uk.hotten.staffog.security;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
@@ -19,7 +18,7 @@ public class SecurityEventListener implements Listener {
|
||||
SecurityManager sm = SecurityManager.getInstance();
|
||||
UUID uuid = event.getUniqueId();
|
||||
|
||||
if (!StaffOGPlugin.getVaultPerms().playerHas("world", Bukkit.getOfflinePlayer(uuid), "staffog.panelaccess")) {
|
||||
if (!StaffOGPlugin.hasPermission(uuid, event.getName(), "world", "staffog.panelaccess")) {
|
||||
|
||||
return;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ version: 1.0
|
||||
api-version: 1.19
|
||||
author: Gxorge
|
||||
description: Punishment system for TrueOG.
|
||||
depend: [Vault]
|
||||
depend: [LuckPerms]
|
||||
|
||||
commands:
|
||||
linkpanel:
|
||||
|
||||
Reference in new issue
Block a user