diff --git a/commons/pom.xml b/commons/pom.xml
index da810f1f..b9c8e8b1 100644
--- a/commons/pom.xml
+++ b/commons/pom.xml
@@ -6,7 +6,7 @@
me.totalfreedom
TotalFreedomMod
- 2023.02
+ 2023.03
commons
@@ -39,10 +39,17 @@
provided
+
+ net.luckperms
+ api
+ 5.4
+ provided
+
+
org.bstats
bstats-bukkit
- 3.0.0
+ 3.0.1
compile
diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java
index 7cf69fdf..1273aabd 100644
--- a/commons/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java
+++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java
@@ -87,10 +87,8 @@ public class AntiSpam extends FreedomService
@EventHandler(priority = EventPriority.LOW)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
{
- String command = event.getMessage();
final Player player = event.getPlayer();
final FPlayer fPlayer = plugin.pl.getPlayer(player);
- fPlayer.setLastCommand(command);
if (fPlayer.allCommandsBlocked())
{
diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java
index 00c51f00..60e14504 100644
--- a/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java
+++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java
@@ -110,6 +110,7 @@ public class TotalFreedomMod extends JavaPlugin
public CoreProtectBridge cpb;
public WorldEditBridge web;
public WorldGuardBridge wgb;
+ public LuckPermsBridge lpb;
public static TotalFreedomMod getPlugin()
{
@@ -335,6 +336,7 @@ public class TotalFreedomMod extends JavaPlugin
ldb = new LibsDisguisesBridge();
web = new WorldEditBridge();
wgb = new WorldGuardBridge();
+ lpb = new LuckPermsBridge();
}
private void initFun()
diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java
index 73a81894..0b5fdc95 100644
--- a/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java
+++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java
@@ -1,14 +1,9 @@
package me.totalfreedom.totalfreedommod.admin;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.*;
-
-import com.google.common.base.Strings;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.player.FPlayer;
-import me.totalfreedom.totalfreedommod.rank.Rank;
-import me.totalfreedom.totalfreedommod.util.FConverter;
+import me.totalfreedom.totalfreedommod.rank.DisplayableGroup;
+import me.totalfreedom.totalfreedommod.rank.GroupProvider;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang.StringUtils;
@@ -16,12 +11,16 @@ import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.*;
+
public class Admin
{
private final List ips = new ArrayList<>();
private UUID uuid;
private boolean active = true;
- private Rank rank = Rank.ADMIN;
+ private DisplayableGroup rank = GroupProvider.ADMIN.getGroup();
private Date lastLogin = new Date();
private Boolean commandSpy = false;
private Boolean potionSpy = false;
@@ -39,15 +38,14 @@ public class Admin
{
this.uuid = UUID.fromString(resultSet.getString("uuid"));
this.active = resultSet.getBoolean("active");
- this.rank = Rank.findRank(resultSet.getString("rank"));
+ this.rank = GroupProvider.fromArgument(resultSet.getString("rank")).getGroup();
this.ips.clear();
this.ips.addAll(FUtil.stringToList(resultSet.getString("ips")));
this.lastLogin = new Date(resultSet.getLong("last_login"));
this.commandSpy = resultSet.getBoolean("command_spy");
this.potionSpy = resultSet.getBoolean("potion_spy");
this.acFormat = resultSet.getString("ac_format");
- }
- catch (SQLException e)
+ } catch (SQLException e)
{
FLog.severe("Failed to load admin: " + e.getMessage());
}
@@ -71,18 +69,17 @@ public class Admin
public Map toSQLStorable()
{
- Map map = new HashMap()
- {{
- put("uuid", uuid.toString());
- put("active", active);
- put("rank", rank.toString());
- put("ips", FUtil.listToString(ips));
- put("last_login", lastLogin.getTime());
- put("command_spy", commandSpy);
- put("potion_spy", potionSpy);
- put("ac_format", acFormat);
- }};
- return map;
+ HashMap map = new HashMap<>();
+ map.put("uuid", uuid.toString());
+ map.put("active", active);
+ map.put("rank", rank.toString());
+ map.put("ips", FUtil.listToString(ips));
+ map.put("last_login", lastLogin.getTime());
+ map.put("command_spy", commandSpy);
+ map.put("potion_spy", potionSpy);
+ map.put("ac_format", acFormat);
+ return map;
+
}
// Util IP methods
@@ -154,50 +151,51 @@ public class Admin
}
}
- private void setActiveSplitWorkToReduceComplexity(TotalFreedomMod plugin) {
- if (getRank().isAtLeast(Rank.ADMIN))
+ private void setActiveSplitWorkToReduceComplexity(TotalFreedomMod plugin)
{
- if (plugin.btb != null)
+ if (getRank().isAtLeast(GroupProvider.ADMIN.getGroup()))
{
- plugin.btb.killTelnetSessions(getName());
- }
-
- // Ensure admins don't have admin functionality when removed (FS-222)
- AdminList.vanished.remove(getName());
-
- if (plugin.esb != null)
- {
- plugin.esb.setVanished(getName(), false);
- }
-
- setCommandSpy(false);
- setPotionSpy(false);
-
- Server server = Bukkit.getServer();
- Player player = server.getPlayer(getUuid());
-
- if (player != null)
- {
- // Update chats
- FPlayer freedomPlayer = plugin.pl.getPlayer(player);
- freedomPlayer.removeAdminFunctionality();
-
- // Disable vanish
- for (Player player1 : server.getOnlinePlayers())
+ if (plugin.btb != null)
{
- player1.showPlayer(plugin, player);
+ plugin.btb.killTelnetSessions(getName());
}
+
+ // Ensure admins don't have admin functionality when removed (FS-222)
+ AdminList.vanished.remove(getUuid());
+
+ if (plugin.esb != null)
+ {
+ plugin.esb.setVanished(getName(), false);
+ }
+
+ setCommandSpy(false);
+ setPotionSpy(false);
+
+ Server server = Bukkit.getServer();
+ Player player = server.getPlayer(getUuid());
+
+ if (player != null)
+ {
+ // Update chats
+ FPlayer freedomPlayer = plugin.pl.getPlayer(player);
+ freedomPlayer.removeAdminFunctionality();
+
+ // Disable vanish
+ for (Player player1 : server.getOnlinePlayers())
+ {
+ player1.showPlayer(plugin, player);
+ }
+ }
+
}
-
}
-}
- public Rank getRank()
+ public DisplayableGroup getRank()
{
return rank;
}
- public void setRank(Rank rank)
+ public void setRank(DisplayableGroup rank)
{
this.rank = rank;
}
diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java
index dec3e8ed..b546a49d 100644
--- a/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java
+++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java
@@ -8,6 +8,7 @@ import java.util.*;
import java.util.concurrent.TimeUnit;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
+import me.totalfreedom.totalfreedommod.rank.GroupProvider;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
@@ -133,7 +134,9 @@ public class AdminList extends FreedomService
return false;
}
- return admin.getRank().ordinal() >= Rank.SENIOR_ADMIN.ordinal();
+ return admin.getRank().getLuckPermsGroup().getWeight().orElse(0)
+ >= GroupProvider.SENIOR_ADMIN.getGroup().getLuckPermsGroup().getWeight().orElse(1);
+ // We don't want this to return true if there's no group weight available.
}
public Admin getAdmin(CommandSender sender)
@@ -286,29 +289,23 @@ public class AdminList extends FreedomService
public void deactivateOldEntries(boolean verbose)
{
- for (Admin admin : allAdmins)
+ allAdmins.stream()
+ .filter(admin -> admin.isActive() && !admin.getRank().isAtLeast(GroupProvider.SENIOR_ADMIN.getGroup()))
+ .forEach(admin ->
{
- if (!admin.isActive() || admin.getRank().isAtLeast(Rank.SENIOR_ADMIN))
- {
- continue;
- }
-
final Date lastLogin = admin.getLastLogin();
final long lastLoginHours = TimeUnit.HOURS.convert(new Date().getTime() - lastLogin.getTime(), TimeUnit.MILLISECONDS);
-
if (lastLoginHours < ConfigEntry.ADMINLIST_CLEAN_THESHOLD_HOURS.getInteger())
{
- continue;
+ return;
}
-
if (verbose)
{
FUtil.adminAction("TotalFreedomMod", "Deactivating admin " + admin.getName() + ", inactive for " + lastLoginHours + " hours", true);
}
-
admin.setActive(false);
save(admin);
- }
+ });
updateTables();
}
diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/LuckPermsBridge.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/LuckPermsBridge.java
new file mode 100644
index 00000000..c75e4fe4
--- /dev/null
+++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/LuckPermsBridge.java
@@ -0,0 +1,29 @@
+package me.totalfreedom.totalfreedommod.bridge;
+
+import net.luckperms.api.LuckPerms;
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.RegisteredServiceProvider;
+import org.bukkit.plugin.UnknownDependencyException;
+
+import java.util.concurrent.Executor;
+
+public class LuckPermsBridge
+{
+ private final LuckPerms luckPerms;
+
+ public LuckPermsBridge()
+ {
+ RegisteredServiceProvider provider = Bukkit.getServicesManager()
+ .getRegistration(LuckPerms.class);
+
+ if (provider == null) throw new UnknownDependencyException("LuckPerms must be present!");
+
+ this.luckPerms = provider.getProvider();
+ }
+
+ public LuckPerms getAPI()
+ {
+ return luckPerms;
+ }
+}
diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandPermissions.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandPermissions.java
index 2cf2d2c6..44d61c63 100644
--- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandPermissions.java
+++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandPermissions.java
@@ -2,13 +2,15 @@ package me.totalfreedom.totalfreedommod.command;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+
+import me.totalfreedom.totalfreedommod.rank.GroupProvider;
import me.totalfreedom.totalfreedommod.rank.Rank;
@Retention(RetentionPolicy.RUNTIME)
public @interface CommandPermissions
{
- Rank rank() default Rank.NON_OP;
+ String permission() default "default";
SourceType source() default SourceType.BOTH;
diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminchat.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminchat.java
index 5c2e6403..cb7f9b31 100644
--- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminchat.java
+++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminchat.java
@@ -1,14 +1,13 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.player.FPlayer;
-import me.totalfreedom.totalfreedommod.rank.Rank;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-@CommandPermissions(rank = Rank.ADMIN, source = SourceType.BOTH)
+@CommandPermissions(permission = "adminchat", source = SourceType.BOTH)
@CommandParameters(description = "Talk privately with other admins on the server.", usage = "/ [message]", aliases = "o,sc,ac,staffchat")
public class Command_adminchat extends FreedomCommand
{
@@ -27,8 +26,7 @@ public class Command_adminchat extends FreedomCommand
FPlayer userinfo = plugin.pl.getPlayer(playerSender);
userinfo.setAdminChat(!userinfo.inAdminChat());
msgNew("Admin chat turned .", Placeholder.unparsed("status", userinfo.inAdminChat() ? "on" : "off"));
- }
- else
+ } else
{
plugin.cm.adminChat(sender, StringUtils.join(args, " "));
}
diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_admininfo.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_admininfo.java
index 2fe7ea73..25821da4 100644
--- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_admininfo.java
+++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_admininfo.java
@@ -2,12 +2,11 @@ package me.totalfreedom.totalfreedommod.command;
import java.util.List;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
-import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-@CommandPermissions(rank = Rank.OP, source = SourceType.BOTH)
+@CommandPermissions(permission = "admininfo", source = SourceType.BOTH)
@CommandParameters(description = "Information on how to apply for admin.", usage = "/", aliases = "si,ai,staffinfo")
public class Command_admininfo extends FreedomCommand
{
diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminmode.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminmode.java
index e50a87bc..f1ac034c 100644
--- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminmode.java
+++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminmode.java
@@ -4,14 +4,13 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
-import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.Component;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-@CommandPermissions(rank = Rank.ADMIN, source = SourceType.BOTH)
+@CommandPermissions(permission = "adminmode", source = SourceType.BOTH)
@CommandParameters(description = "Denies joining of operators and only allows admins to join.", usage = "/ [on | off]", aliases = "staffmode")
public class Command_adminmode extends FreedomCommand
{
diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java
index e691443a..fe4c08bd 100644
--- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java
+++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java
@@ -4,7 +4,6 @@ import io.papermc.lib.PaperLib;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.world.WorldTime;
import me.totalfreedom.totalfreedommod.world.WorldWeather;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
@@ -13,7 +12,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-@CommandPermissions(rank = Rank.OP, source = SourceType.BOTH)
+@CommandPermissions(permission = "adminworld", source = SourceType.BOTH)
@CommandParameters(description = "Allows for admins to configure time, and weather of the AdminWorld, and allows for admins and ops to go to the AdminWorld.",
usage = "/ [time | weather ]",
aliases = "sw,aw,staffworld")
@@ -50,7 +49,7 @@ public class Command_adminworld extends FreedomCommand
{
switch (commandMode)
{
- case TELEPORT:
+ case TELEPORT ->
{
if (!(sender instanceof Player) || playerSender == null)
{
@@ -61,8 +60,7 @@ public class Command_adminworld extends FreedomCommand
try
{
adminWorld = plugin.wm.adminworld.getWorld();
- }
- catch (Exception ignored)
+ } catch (Exception ignored)
{
}
@@ -70,15 +68,13 @@ public class Command_adminworld extends FreedomCommand
{
msgNew("Going to the main world.");
PaperLib.teleportAsync(playerSender, server.getWorlds().get(0).getSpawnLocation());
- }
- else
+ } else
{
msgNew("Going to the AdminWorld.");
plugin.wm.adminworld.sendToWorld(playerSender);
}
- break;
}
- case TIME:
+ case TIME ->
{
assertCommandPerms(sender, playerSender);
@@ -89,20 +85,17 @@ public class Command_adminworld extends FreedomCommand
{
plugin.wm.adminworld.setTimeOfDay(timeOfDay);
msgNew("AdminWorld time set to: