add maxClaims config/permission #close 90

This commit is contained in:
Flemmli97 2021-09-02 14:07:56 +02:00
parent 26435a5df0
commit 9006b4ddf3
7 changed files with 18 additions and 9 deletions

View File

@ -249,14 +249,14 @@ public class Claim implements IPermissionContainer {
}
if (!this.isAdminClaim()) {
Config.GlobalType global = ConfigHandler.config.getGlobal(this.world, perm);
if(!global.canModify()) {
if (!global.canModify()) {
if (global.getValue() || (player != null && this.isAdminIgnore(player)))
return true;
if (message)
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
return false;
}
if(ConfigHandler.config.offlineProtectActivation != -1 && (LogoutTracker.getInstance(this.world.getServer()).justLoggedOut(this.getOwner()) || this.getOwnerPlayer().isPresent())) {
if (ConfigHandler.config.offlineProtectActivation != -1 && (LogoutTracker.getInstance(this.world.getServer()).justLoggedOut(this.getOwner()) || this.getOwnerPlayer().isPresent())) {
return global == Config.GlobalType.NONE || global.getValue();
}
}

View File

@ -14,6 +14,7 @@ import io.github.flemmli97.flan.api.data.IPlayerData;
import io.github.flemmli97.flan.api.permission.ClaimPermission;
import io.github.flemmli97.flan.api.permission.PermissionRegistry;
import io.github.flemmli97.flan.config.ConfigHandler;
import io.github.flemmli97.flan.integration.permissions.PermissionNodeHandler;
import io.github.flemmli97.flan.player.EnumDisplayType;
import io.github.flemmli97.flan.player.EnumEditMode;
import io.github.flemmli97.flan.player.OfflinePlayerData;
@ -89,6 +90,10 @@ public class ClaimStorage implements IPermissionStorage {
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.minClaimSize, ConfigHandler.config.minClaimsize), Formatting.RED), false);
return false;
}
if (ConfigHandler.config.maxClaims != -1 && !PermissionNodeHandler.permBelowEqVal(player, PermissionNodeHandler.permMaxClaims, this.playerClaimMap.getOrDefault(player.getUuid(), Sets.newHashSet()).size() + 1, ConfigHandler.config.maxClaims)) {
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.maxClaims), Formatting.RED), false);
return false;
}
if (!data.canUseClaimBlocks(claim.getPlane())) {
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.notEnoughBlocks, Formatting.RED), false);
return false;

View File

@ -17,7 +17,6 @@ import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@ -33,6 +32,7 @@ public class Config {
public int ticksForNextBlock = 600;
public int minClaimsize = 100;
public int defaultClaimDepth = 10;
public int maxClaims = -1;
public boolean lenientBlockEntityCheck;
public List<String> ignoredBlocks = Lists.newArrayList(
"universal_graves:grave"
@ -127,6 +127,7 @@ public class Config {
this.ticksForNextBlock = ConfigHandler.fromJson(obj, "ticksForNextBlock", this.ticksForNextBlock);
this.minClaimsize = ConfigHandler.fromJson(obj, "minClaimsize", this.minClaimsize);
this.defaultClaimDepth = ConfigHandler.fromJson(obj, "defaultClaimDepth", this.defaultClaimDepth);
this.maxClaims = ConfigHandler.fromJson(obj, "maxClaims", this.maxClaims);
this.lenientBlockEntityCheck = ConfigHandler.fromJson(obj, "lenientBlockEntityCheck", this.lenientBlockEntityCheck);
this.ignoredBlocks.clear();
ConfigHandler.arryFromJson(obj, "ignoredBlocks").forEach(e -> this.ignoredBlocks.add(e.getAsString()));
@ -206,6 +207,7 @@ public class Config {
obj.addProperty("ticksForNextBlock", this.ticksForNextBlock);
obj.addProperty("minClaimsize", this.minClaimsize);
obj.addProperty("defaultClaimDepth", this.defaultClaimDepth);
obj.addProperty("maxClaims", this.maxClaims);
JsonArray blocks = new JsonArray();
this.ignoredBlocks.forEach(blocks::add);
obj.add("ignoredBlocks", blocks);

View File

@ -38,6 +38,7 @@ public class LangConfig {
public String cantClaimHere = "Sorry you cant claim here";
public String minClaimSize = "This is too small. Minimum claimsize is %d";
public String maxClaims = "Maximum amount of claims reached";
public String landClaimDisabledWorld = "Claiming is disabled in this world";
public String editMode = "Editing mode set to %s";
public String notEnoughBlocks = "Not enough claim blocks";

View File

@ -18,7 +18,7 @@ public class PlayerEvents {
}
public static void onLogout(PlayerEntity player) {
if(player.getServer() != null)
if (player.getServer() != null)
LogoutTracker.getInstance(player.getServer()).track(player.getUuid());
}
}

View File

@ -45,6 +45,7 @@ public class PermissionNodeHandler {
public static final String cmdTeleport = "flan.command.teleport";
public static final String permClaimBlocks = "flan.claim.blocks.max";
public static final String permMaxClaims = "flan.claims.amount";
public static boolean perm(ServerCommandSource src, String perm) {
return perm(src, perm, false);

View File

@ -14,11 +14,11 @@ public class LogoutTracker {
private final Set<UUID> trackerUUID = new HashSet<>();
public static LogoutTracker getInstance(MinecraftServer server) {
return ((LogoutImpl)server).getInstance();
return ((LogoutImpl) server).getInstance();
}
public void track(UUID player) {
if(ConfigHandler.config.offlineProtectActivation == -1)
if (ConfigHandler.config.offlineProtectActivation == -1)
return;
this.trackerUUID.add(player);
this.tracker.add(new LogoutTicket(player));
@ -32,9 +32,9 @@ public class LogoutTracker {
this.tracker.stream().filter(LogoutTicket::tick)
.collect(Collectors.toSet())
.forEach(ticket -> {
this.tracker.remove(ticket);
this.trackerUUID.remove(ticket.uuid);
});
this.tracker.remove(ticket);
this.trackerUUID.remove(ticket.uuid);
});
}
private static class LogoutTicket {