diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 44fbaea..3439594 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -10,7 +10,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index eecc2ad..b6d1cb1 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -12,5 +12,5 @@
-
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 0421a09..4b773d9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
com.backtobedrock
AugmentedHardcore
- 3.3.7
+ 3.3.8-groupban-SNAPSHOT
jar
8
@@ -112,5 +112,11 @@
ConfigUpdater
2.0-SNAPSHOT
+
+ net.luckperms
+ api
+ 5.3
+ provided
+
\ No newline at end of file
diff --git a/src/com/backtobedrock/augmentedhardcore/AugmentedHardcore.java b/src/com/backtobedrock/augmentedhardcore/AugmentedHardcore.java
index c60843e..e95b692 100644
--- a/src/com/backtobedrock/augmentedhardcore/AugmentedHardcore.java
+++ b/src/com/backtobedrock/augmentedhardcore/AugmentedHardcore.java
@@ -7,6 +7,9 @@
import com.backtobedrock.augmentedhardcore.domain.enums.StorageType;
import com.backtobedrock.augmentedhardcore.eventListeners.*;
import com.backtobedrock.augmentedhardcore.eventListeners.dependencies.ListenerCombatLogX;
+import com.backtobedrock.augmentedhardcore.groups.DummyGroupHandler;
+import com.backtobedrock.augmentedhardcore.groups.GroupHandler;
+import com.backtobedrock.augmentedhardcore.groups.LuckPermsGroupHandler;
import com.backtobedrock.augmentedhardcore.guis.AbstractGui;
import com.backtobedrock.augmentedhardcore.guis.GuiMyStats;
import com.backtobedrock.augmentedhardcore.mappers.Patch;
@@ -55,6 +58,8 @@ public class AugmentedHardcore extends JavaPlugin implements Listener {
//runnables
private UpdateChecker updateChecker;
+ private static GroupHandler groupHandler;
+
@Override
public void onEnable() {
this.initialize();
@@ -81,6 +86,13 @@ public void onEnable() {
super.onEnable();
}
+ /**
+ * @return The group handler.
+ */
+ public static GroupHandler getGroupHandler() {
+ return groupHandler;
+ }
+
@Override
public void onDisable() {
this.stopping = true;
@@ -171,6 +183,15 @@ public void initialize() {
this.serverRepository = new ServerRepository();
}
+ AugmentedHardcore.groupHandler = new DummyGroupHandler();
+ Object luckPermsPlugin = Bukkit.getPluginManager().getPlugin("LuckPerms");
+ if(luckPermsPlugin != null) {
+ String groupBanTimeAttributeName = this.configurations.getDeathBanConfiguration().getGroupBanTimeAttributeName();
+ if(groupBanTimeAttributeName != null) {
+ AugmentedHardcore.groupHandler = new LuckPermsGroupHandler(groupBanTimeAttributeName);
+ }
+ }
+
//register event listeners
this.registerListeners();
}
diff --git a/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationDeathBan.java b/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationDeathBan.java
index 688a858..cfc2a50 100644
--- a/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationDeathBan.java
+++ b/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationDeathBan.java
@@ -29,8 +29,9 @@ public class ConfigurationDeathBan {
private final String spectatorBanRespawnWorld;
private final List commandsOnDeathBan;
private final List disableBanInWorlds;
+ private final String groupBanTimeAttributeName;
- public ConfigurationDeathBan(boolean useDeathBan, EnumMap banTimes, BanList.Type banType, BanTimeType banTimeType, GrowthType banTimeByPlaytimeGrowthType, boolean selfHarmBan, boolean lightningOnDeathBan, String spectatorBanRespawnWorld, List commandsOnDeathBan, List disableBanInWorlds) {
+ public ConfigurationDeathBan(boolean useDeathBan, EnumMap banTimes, BanList.Type banType, BanTimeType banTimeType, GrowthType banTimeByPlaytimeGrowthType, boolean selfHarmBan, boolean lightningOnDeathBan, String spectatorBanRespawnWorld, List commandsOnDeathBan, List disableBanInWorlds, String groupBanTimeAttributeName) {
this.useDeathBan = useDeathBan;
this.banTimes = banTimes;
this.banType = banType;
@@ -41,6 +42,7 @@ public ConfigurationDeathBan(boolean useDeathBan, EnumMap cCommandsOnDeathBan = section.getStringList("CommandsOnDeathBan");
List cDisableBanInWorlds = section.getStringList("DisableBanInWorlds").stream().map(String::toLowerCase).toList();
+ String cGroupBanTimeAttributeName = section.getString("GroupBanTimeAttributeName", null);
//loop over all damage causes
ConfigurationSection banTimesConfigurations = section.getConfigurationSection("BanTimes");
@@ -83,7 +86,8 @@ public static ConfigurationDeathBan deserialize(ConfigurationSection section) {
cLightningOnDeathBan,
cSpectatorBanRespawnWorld,
cCommandsOnDeathBan,
- cDisableBanInWorlds
+ cDisableBanInWorlds,
+ cGroupBanTimeAttributeName
);
}
@@ -95,6 +99,10 @@ public List getDisableBanInWorlds() {
return disableBanInWorlds;
}
+ public String getGroupBanTimeAttributeName() {
+ return groupBanTimeAttributeName;
+ }
+
public BanList.Type getBanType() {
return banType;
}
diff --git a/src/com/backtobedrock/augmentedhardcore/domain/enums/BanTimeType.java b/src/com/backtobedrock/augmentedhardcore/domain/enums/BanTimeType.java
index 0152f72..89a5cfb 100644
--- a/src/com/backtobedrock/augmentedhardcore/domain/enums/BanTimeType.java
+++ b/src/com/backtobedrock/augmentedhardcore/domain/enums/BanTimeType.java
@@ -2,7 +2,9 @@
import com.backtobedrock.augmentedhardcore.AugmentedHardcore;
import com.backtobedrock.augmentedhardcore.domain.data.PlayerData;
+import com.backtobedrock.augmentedhardcore.groups.GroupHandler;
import com.backtobedrock.augmentedhardcore.utilities.MessageUtils;
+import org.bukkit.Bukkit;
import org.bukkit.Statistic;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
@@ -10,6 +12,7 @@
import java.time.LocalDateTime;
public enum BanTimeType {
+ GROUP,
STATIC,
BANCOUNT,
PLAYTIME,
@@ -18,6 +21,19 @@ public enum BanTimeType {
public int getBantime(Player player, PlayerData playerData, int max) {
GrowthType growthType = JavaPlugin.getPlugin(AugmentedHardcore.class).getConfigurations().getDeathBanConfiguration().getBanTimeByPlaytimeGrowthType();
switch (this) {
+ case GROUP:
+ try {
+ GroupHandler groupHandler = AugmentedHardcore.getGroupHandler();
+ String textValue = (String)groupHandler.getAttribute(player);
+ if(!textValue.isEmpty()) {
+ return Integer.parseInt(textValue);
+ }
+ Bukkit.getLogger().warning("No ban time value found in group attribute.");
+ } catch(Exception e) {
+ Bukkit.getLogger().warning("Failed to determine ban time value based on group, configuration invalid: " + e);
+ e.printStackTrace();
+ }
+ return 0;
case STATIC:
return max;
case BANCOUNT:
diff --git a/src/com/backtobedrock/augmentedhardcore/groups/DummyGroupHandler.java b/src/com/backtobedrock/augmentedhardcore/groups/DummyGroupHandler.java
new file mode 100644
index 0000000..202c3ec
--- /dev/null
+++ b/src/com/backtobedrock/augmentedhardcore/groups/DummyGroupHandler.java
@@ -0,0 +1,17 @@
+package com.backtobedrock.augmentedhardcore.groups;
+
+import org.bukkit.entity.Player;
+
+/**
+ * Dummy group handler is used if LuckPerms is not
+ * available, to avoid hard class dependencies.
+ *
+ * @author Marcel Schoen
+ */
+public class DummyGroupHandler implements GroupHandler {
+
+ @Override
+ public Object getAttribute(Player player) {
+ return "";
+ }
+}
diff --git a/src/com/backtobedrock/augmentedhardcore/groups/GroupHandler.java b/src/com/backtobedrock/augmentedhardcore/groups/GroupHandler.java
new file mode 100644
index 0000000..fd958f8
--- /dev/null
+++ b/src/com/backtobedrock/augmentedhardcore/groups/GroupHandler.java
@@ -0,0 +1,17 @@
+package com.backtobedrock.augmentedhardcore.groups;
+
+import org.bukkit.entity.Player;
+
+/**
+ * Handles processing group attributes of a player.
+ *
+ * @author Marcel Schoen
+ */
+public interface GroupHandler {
+
+ /**
+ * @param player The player for which to look up the group attribute value.
+ * @return The attribute value (or null).
+ */
+ Object getAttribute(Player player);
+}
diff --git a/src/com/backtobedrock/augmentedhardcore/groups/LuckPermsGroupHandler.java b/src/com/backtobedrock/augmentedhardcore/groups/LuckPermsGroupHandler.java
new file mode 100644
index 0000000..23a99b5
--- /dev/null
+++ b/src/com/backtobedrock/augmentedhardcore/groups/LuckPermsGroupHandler.java
@@ -0,0 +1,50 @@
+package com.backtobedrock.augmentedhardcore.groups;
+
+import net.luckperms.api.LuckPerms;
+import net.luckperms.api.model.group.Group;
+import net.luckperms.api.model.user.User;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.RegisteredServiceProvider;
+
+/**
+ * Reads the configured ban-time meta attribute from
+ * the player's LuckPerms group.
+ *
+ * @author Marcel Schoen
+ */
+public class LuckPermsGroupHandler implements GroupHandler {
+
+ private LuckPerms luckPerms = null;
+ private String attributeName = null;
+
+ /**
+ * @param attributeName The configured name of the LuckPerms group attribute.
+ */
+ public LuckPermsGroupHandler(String attributeName) {
+ RegisteredServiceProvider provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class);
+ if (provider != null) {
+ luckPerms = provider.getProvider();
+ this.attributeName = attributeName;
+ } else {
+ Bukkit.getLogger().warning("LuckPerms group handler not available!");
+ }
+ }
+
+ @Override
+ public Object getAttribute(Player player) {
+ if(luckPerms != null) {
+ User user = luckPerms.getPlayerAdapter(Player.class).getUser(player);
+ String groupName = user.getPrimaryGroup();
+ Group group = luckPerms.getGroupManager().getGroup(groupName);
+ Bukkit.getLogger().info( "Group name: " + groupName + ", group: " + group.getName() + ", attribute name: " + attributeName);
+ if(group != null) {
+ return luckPerms.getGroupManager().getGroup(groupName).getCachedData().getMetaData().getMetaValue(attributeName);
+ }
+ } else {
+ Bukkit.getLogger().warning("LuckPerms API not available, cannot resolve attribute '"
+ + attributeName + "'!");
+ }
+ return "";
+ }
+}
diff --git a/src/resources/config.yml b/src/resources/config.yml
index dd6ae39..15aa1cf 100644
--- a/src/resources/config.yml
+++ b/src/resources/config.yml
@@ -379,6 +379,10 @@ BanType: name
#What ban time type should be used for calculating the bantime?
#Static: Above times will be used for bans.
+#Group: The ban time will be the number of seconds defined in the metadata of the LuckPerms
+# group the player is member of. The metadata of the group must contain an attribute
+# that defines the bantime of the players in this group. See config setting 'GroupBanTimeAttributeName'
+# below to specify the name of the metadata attribute.
#BanCount: The amount of (times death banned * 35) will be used for determining the bantime.
# Bantimes will increase the more death banned the player has been.
# Above times will be used as maximum ban time.
@@ -391,6 +395,15 @@ BanType: name
# -> static/bancount/playtime/timesincelastdeath
BanTimeType: static
+# IF "BanTimeType" is set to "group":
+# Name of LuckPerms group meta attribute containing the ban time in number of minutes.
+# Example LuckPerms group config lines:
+#
+# meta:
+# - bantime:
+# value: '960'
+GroupBanTimeAttributeName: bantime
+
#At what rate should the ban time by playtime grow?
#Linear: a constant increase in bantime the more bancount/playtime/timesincelastdeath(P) you have (constant increase).
# Function: [(P+MBT/60) OR MBT]. MBT -> max ban time