mirror of
https://github.com/BentoBoxWorld/Limits.git
synced 2024-11-22 18:46:02 +01:00
Fixes permissions
Code cleanup
This commit is contained in:
parent
1c2a3a7c94
commit
148daf63f3
@ -43,13 +43,13 @@ example: `bskyblock.island.limit.hopper.10`
|
||||
|
||||
Permissions activate when the player logs in.
|
||||
|
||||
Usage permissions are:
|
||||
Usage permissions are (put the gamemode name, e.g. acidisland at the front):
|
||||
|
||||
```
|
||||
limits.player.limits:
|
||||
GAMEMODE_NAME.limits.player.limits:
|
||||
description: Player can use limits command
|
||||
default: true
|
||||
limits.admin.limits:
|
||||
GAMEMODE_NAME.limits.admin.limits:
|
||||
description: Player can use admin limits command
|
||||
default: op
|
||||
```
|
||||
|
@ -1,6 +1,5 @@
|
||||
package bentobox.addon.limits;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -11,8 +10,8 @@ import org.bukkit.entity.EntityType;
|
||||
|
||||
public class Settings {
|
||||
|
||||
private Map<EntityType, Integer> limits = new HashMap<>();
|
||||
private List<String> gameModes = new ArrayList<>();
|
||||
private final Map<EntityType, Integer> limits = new HashMap<>();
|
||||
private final List<String> gameModes;
|
||||
|
||||
public Settings(Limits addon) {
|
||||
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package bentobox.addon.limits.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -20,11 +17,11 @@ import world.bentobox.bentobox.util.Util;
|
||||
*/
|
||||
public class AdminCommand extends CompositeCommand {
|
||||
|
||||
private Limits addon;
|
||||
private final Limits addon;
|
||||
|
||||
/**
|
||||
* Top level command
|
||||
* @param addon
|
||||
* Admin command
|
||||
* @param addon - addon
|
||||
*/
|
||||
public AdminCommand(Limits addon, CompositeCommand parent) {
|
||||
super(parent, "limits");
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package bentobox.addon.limits.commands;
|
||||
|
||||
import java.util.Map;
|
||||
@ -24,9 +21,9 @@ import world.bentobox.bentobox.util.Util;
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class LimitPanel {
|
||||
class LimitPanel {
|
||||
|
||||
private Limits addon;
|
||||
private final Limits addon;
|
||||
|
||||
/**
|
||||
* @param addon - limit addon
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package bentobox.addon.limits.commands;
|
||||
|
||||
import java.util.List;
|
||||
@ -16,11 +13,11 @@ import world.bentobox.bentobox.api.user.User;
|
||||
*/
|
||||
public class PlayerCommand extends CompositeCommand {
|
||||
|
||||
private Limits addon;
|
||||
private final Limits addon;
|
||||
|
||||
/**
|
||||
* Top level command
|
||||
* @param addon
|
||||
* @param addon - addon
|
||||
*/
|
||||
public PlayerCommand(Limits addon, CompositeCommand parent) {
|
||||
super(parent, "limits");
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package bentobox.addon.limits.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -49,17 +46,17 @@ public class BlockLimitsListener implements Listener {
|
||||
/**
|
||||
* Blocks that are not counted
|
||||
*/
|
||||
public static final List<Material> DO_NOT_COUNT = Arrays.asList(Material.LAVA, Material.WATER, Material.AIR, Material.FIRE, Material.END_PORTAL, Material.NETHER_PORTAL);
|
||||
private static final List<Material> DO_NOT_COUNT = Arrays.asList(Material.LAVA, Material.WATER, Material.AIR, Material.FIRE, Material.END_PORTAL, Material.NETHER_PORTAL);
|
||||
|
||||
/**
|
||||
* Save every 10 blocks of change
|
||||
*/
|
||||
private static final Integer CHANGE_LIMIT = 9;
|
||||
private Limits addon;
|
||||
private Map<String, IslandBlockCount> islandCountMap = new HashMap<>();
|
||||
private Map<String, Integer> saveMap = new HashMap<>();
|
||||
private Database<IslandBlockCount> handler;
|
||||
private Map<World, Map<Material, Integer>> worldLimitMap = new HashMap<>();
|
||||
private final Limits addon;
|
||||
private final Map<String, IslandBlockCount> islandCountMap = new HashMap<>();
|
||||
private final Map<String, Integer> saveMap = new HashMap<>();
|
||||
private final Database<IslandBlockCount> handler;
|
||||
private final Map<World, Map<Material, Integer>> worldLimitMap = new HashMap<>();
|
||||
private Map<Material, Integer> defaultLimitMap = new HashMap<>();
|
||||
|
||||
public BlockLimitsListener(Limits addon) {
|
||||
@ -272,7 +269,7 @@ public class BlockLimitsListener implements Listener {
|
||||
* @param id - island id
|
||||
* @return limit amount if at limit or -1 if no limit
|
||||
*/
|
||||
public int checkLimit(World w, Material m, String id) {
|
||||
private int checkLimit(World w, Material m, String id) {
|
||||
// Check island limits
|
||||
IslandBlockCount island = islandCountMap.get(id);
|
||||
if (island.isBlockLimited(m)) {
|
||||
@ -301,14 +298,14 @@ public class BlockLimitsListener implements Listener {
|
||||
// Merge limits
|
||||
Map<Material, Integer> result = new HashMap<>();
|
||||
// Default
|
||||
defaultLimitMap.forEach((k,v) -> result.put(k, v));
|
||||
defaultLimitMap.forEach(result::put);
|
||||
// World
|
||||
if (worldLimitMap.containsKey(w)) {
|
||||
worldLimitMap.get(w).forEach((k,v) -> result.put(k, v));
|
||||
worldLimitMap.get(w).forEach(result::put);
|
||||
}
|
||||
// Island
|
||||
if (islandCountMap.containsKey(id)) {
|
||||
islandCountMap.get(id).getBlockLimits().forEach((k,v) -> result.put(k, v));
|
||||
islandCountMap.get(id).getBlockLimits().forEach(result::put);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -27,10 +27,10 @@ import world.bentobox.bentobox.database.Database;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class EntityLimitsListener implements Listener {
|
||||
class EntityLimitsListener implements Listener {
|
||||
private final Limits addon;
|
||||
|
||||
private Database<EntityLimitsDO> handler;
|
||||
private final Database<EntityLimitsDO> handler;
|
||||
|
||||
/**
|
||||
* Handles entity and natural limitations
|
||||
@ -81,9 +81,7 @@ public class EntityLimitsListener implements Listener {
|
||||
Map<UUID, String> spawnLoc = new HashMap<>();
|
||||
Arrays.stream(e.getChunk().getEntities()).filter(x -> x.hasMetadata("spawnLoc")).forEach(entity -> {
|
||||
// Get the meta data
|
||||
entity.getMetadata("spawnLoc").stream().filter(y -> y.getOwningPlugin().equals(addon.getPlugin())).forEach(v -> {
|
||||
spawnLoc.put(entity.getUniqueId(), v.asString());
|
||||
});
|
||||
entity.getMetadata("spawnLoc").stream().filter(y -> y.getOwningPlugin().equals(addon.getPlugin())).forEach(v -> spawnLoc.put(entity.getUniqueId(), v.asString()));
|
||||
});
|
||||
if (!spawnLoc.isEmpty()) {
|
||||
eld.setSpawnLoc(spawnLoc);
|
||||
@ -213,7 +211,7 @@ public class EntityLimitsListener implements Listener {
|
||||
|
||||
/**
|
||||
* Checks if new entities can be added to island
|
||||
* @param island
|
||||
* @param island - island
|
||||
* @param bypass - true if this is being done by a player with authorization to bypass limits
|
||||
* @param ent - the entity
|
||||
* @return true if at the limit, false if not
|
||||
|
@ -21,7 +21,7 @@ import bentobox.addon.limits.objects.IslandBlockCount;
|
||||
*/
|
||||
public class JoinListener implements Listener {
|
||||
|
||||
private Limits addon;
|
||||
private final Limits addon;
|
||||
|
||||
public JoinListener(Limits addon) {
|
||||
this.addon = addon;
|
||||
@ -38,7 +38,7 @@ public class JoinListener implements Listener {
|
||||
});
|
||||
}
|
||||
|
||||
private boolean checkPerms(Player player, String permissionPrefix, String islandId, String gameMode) {
|
||||
private void checkPerms(Player player, String permissionPrefix, String islandId, String gameMode) {
|
||||
IslandBlockCount ibc = addon.getBlockLimitListener().getIsland(islandId);
|
||||
int limit = -1;
|
||||
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
|
||||
@ -47,17 +47,17 @@ public class JoinListener implements Listener {
|
||||
String[] split = perms.getPermission().split("\\.");
|
||||
if (split.length != 5) {
|
||||
logError(player.getName(), perms.getPermission(), "format must be " + permissionPrefix + "MATERIAL.NUMBER");
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
Material m = Material.getMaterial(split[3].toUpperCase(Locale.ENGLISH));
|
||||
if (m == null) {
|
||||
logError(player.getName(), perms.getPermission(), split[3].toUpperCase(Locale.ENGLISH) + " is not a valid material");
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
// Get the max value should there be more than one
|
||||
if (perms.getPermission().contains(permissionPrefix + ".*")) {
|
||||
logError(player.getName(), perms.getPermission(), "wildcards are not allowed");
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
if (!NumberUtils.isDigits(split[4])) {
|
||||
logError(player.getName(), perms.getPermission(), "the last part MUST be a number!");
|
||||
@ -75,7 +75,6 @@ public class JoinListener implements Listener {
|
||||
if (ibc != null) {
|
||||
addon.getBlockLimitListener().setIsland(islandId, ibc);
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package bentobox.addon.limits.objects;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -86,13 +83,8 @@ public class EntityLimitsDO implements DataObject {
|
||||
}
|
||||
EntityLimitsDO other = (EntityLimitsDO) obj;
|
||||
if (uniqueId == null) {
|
||||
if (other.uniqueId != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!uniqueId.equals(other.uniqueId)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return other.uniqueId == null;
|
||||
} else return uniqueId.equals(other.uniqueId);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package bentobox.addon.limits.objects;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -102,7 +99,7 @@ public class IslandBlockCount implements DataObject {
|
||||
*/
|
||||
public boolean isAtLimit(Material m) {
|
||||
// Check island limits first
|
||||
return blockLimits.containsKey(m) ? blockCount.getOrDefault(m, 0) >= blockLimits.get(m) : false;
|
||||
return blockLimits.containsKey(m) && blockCount.getOrDefault(m, 0) >= blockLimits.get(m);
|
||||
}
|
||||
|
||||
public boolean isBlockLimited(Material m) {
|
||||
|
@ -7,9 +7,21 @@ authors: tastybento
|
||||
softdepend: AcidIsland, BSkyBlock, CaveBlock, SkyGrid
|
||||
|
||||
permissions:
|
||||
limits.player.limits:
|
||||
acidisland.limits.player.limits:
|
||||
description: Player can use limits command
|
||||
default: true
|
||||
limits.admin.limits:
|
||||
acidisland.limits.admin.limits:
|
||||
description: Player can use admin limits command
|
||||
default: op
|
||||
bskyblock.limits.player.limits:
|
||||
description: Player can use limits command
|
||||
default: true
|
||||
bskyblock.limits.admin.limits:
|
||||
description: Player can use admin limits command
|
||||
default: op
|
||||
caveblock.limits.player.limits:
|
||||
description: Player can use limits command
|
||||
default: true
|
||||
caveblock.limits.admin.limits:
|
||||
description: Player can use admin limits command
|
||||
default: op
|
||||
|
Loading…
Reference in New Issue
Block a user