Fixes permissions

Code cleanup
This commit is contained in:
tastybento 2019-02-09 10:30:02 -08:00
parent 1c2a3a7c94
commit 148daf63f3
11 changed files with 48 additions and 63 deletions

View File

@ -43,13 +43,13 @@ example: `bskyblock.island.limit.hopper.10`
Permissions activate when the player logs in. 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 description: Player can use limits command
default: true default: true
limits.admin.limits: GAMEMODE_NAME.limits.admin.limits:
description: Player can use admin limits command description: Player can use admin limits command
default: op default: op
``` ```

View File

@ -1,6 +1,5 @@
package bentobox.addon.limits; package bentobox.addon.limits;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -11,8 +10,8 @@ import org.bukkit.entity.EntityType;
public class Settings { public class Settings {
private Map<EntityType, Integer> limits = new HashMap<>(); private final Map<EntityType, Integer> limits = new HashMap<>();
private List<String> gameModes = new ArrayList<>(); private final List<String> gameModes;
public Settings(Limits addon) { public Settings(Limits addon) {

View File

@ -1,6 +1,3 @@
/**
*
*/
package bentobox.addon.limits.commands; package bentobox.addon.limits.commands;
import java.util.ArrayList; import java.util.ArrayList;
@ -20,11 +17,11 @@ import world.bentobox.bentobox.util.Util;
*/ */
public class AdminCommand extends CompositeCommand { public class AdminCommand extends CompositeCommand {
private Limits addon; private final Limits addon;
/** /**
* Top level command * Admin command
* @param addon * @param addon - addon
*/ */
public AdminCommand(Limits addon, CompositeCommand parent) { public AdminCommand(Limits addon, CompositeCommand parent) {
super(parent, "limits"); super(parent, "limits");

View File

@ -1,6 +1,3 @@
/**
*
*/
package bentobox.addon.limits.commands; package bentobox.addon.limits.commands;
import java.util.Map; import java.util.Map;
@ -24,9 +21,9 @@ import world.bentobox.bentobox.util.Util;
* @author tastybento * @author tastybento
* *
*/ */
public class LimitPanel { class LimitPanel {
private Limits addon; private final Limits addon;
/** /**
* @param addon - limit addon * @param addon - limit addon

View File

@ -1,6 +1,3 @@
/**
*
*/
package bentobox.addon.limits.commands; package bentobox.addon.limits.commands;
import java.util.List; import java.util.List;
@ -16,11 +13,11 @@ import world.bentobox.bentobox.api.user.User;
*/ */
public class PlayerCommand extends CompositeCommand { public class PlayerCommand extends CompositeCommand {
private Limits addon; private final Limits addon;
/** /**
* Top level command * Top level command
* @param addon * @param addon - addon
*/ */
public PlayerCommand(Limits addon, CompositeCommand parent) { public PlayerCommand(Limits addon, CompositeCommand parent) {
super(parent, "limits"); super(parent, "limits");

View File

@ -1,6 +1,3 @@
/**
*
*/
package bentobox.addon.limits.listeners; package bentobox.addon.limits.listeners;
import java.util.ArrayList; import java.util.ArrayList;
@ -49,17 +46,17 @@ public class BlockLimitsListener implements Listener {
/** /**
* Blocks that are not counted * 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 * Save every 10 blocks of change
*/ */
private static final Integer CHANGE_LIMIT = 9; private static final Integer CHANGE_LIMIT = 9;
private Limits addon; private final Limits addon;
private Map<String, IslandBlockCount> islandCountMap = new HashMap<>(); private final Map<String, IslandBlockCount> islandCountMap = new HashMap<>();
private Map<String, Integer> saveMap = new HashMap<>(); private final Map<String, Integer> saveMap = new HashMap<>();
private Database<IslandBlockCount> handler; private final Database<IslandBlockCount> handler;
private Map<World, Map<Material, Integer>> worldLimitMap = new HashMap<>(); private final Map<World, Map<Material, Integer>> worldLimitMap = new HashMap<>();
private Map<Material, Integer> defaultLimitMap = new HashMap<>(); private Map<Material, Integer> defaultLimitMap = new HashMap<>();
public BlockLimitsListener(Limits addon) { public BlockLimitsListener(Limits addon) {
@ -272,7 +269,7 @@ public class BlockLimitsListener implements Listener {
* @param id - island id * @param id - island id
* @return limit amount if at limit or -1 if no limit * @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 // Check island limits
IslandBlockCount island = islandCountMap.get(id); IslandBlockCount island = islandCountMap.get(id);
if (island.isBlockLimited(m)) { if (island.isBlockLimited(m)) {
@ -301,14 +298,14 @@ public class BlockLimitsListener implements Listener {
// Merge limits // Merge limits
Map<Material, Integer> result = new HashMap<>(); Map<Material, Integer> result = new HashMap<>();
// Default // Default
defaultLimitMap.forEach((k,v) -> result.put(k, v)); defaultLimitMap.forEach(result::put);
// World // World
if (worldLimitMap.containsKey(w)) { if (worldLimitMap.containsKey(w)) {
worldLimitMap.get(w).forEach((k,v) -> result.put(k, v)); worldLimitMap.get(w).forEach(result::put);
} }
// Island // Island
if (islandCountMap.containsKey(id)) { if (islandCountMap.containsKey(id)) {
islandCountMap.get(id).getBlockLimits().forEach((k,v) -> result.put(k, v)); islandCountMap.get(id).getBlockLimits().forEach(result::put);
} }
return result; return result;
} }

View File

@ -27,10 +27,10 @@ import world.bentobox.bentobox.database.Database;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
public class EntityLimitsListener implements Listener { class EntityLimitsListener implements Listener {
private final Limits addon; private final Limits addon;
private Database<EntityLimitsDO> handler; private final Database<EntityLimitsDO> handler;
/** /**
* Handles entity and natural limitations * Handles entity and natural limitations
@ -81,9 +81,7 @@ public class EntityLimitsListener implements Listener {
Map<UUID, String> spawnLoc = new HashMap<>(); Map<UUID, String> spawnLoc = new HashMap<>();
Arrays.stream(e.getChunk().getEntities()).filter(x -> x.hasMetadata("spawnLoc")).forEach(entity -> { Arrays.stream(e.getChunk().getEntities()).filter(x -> x.hasMetadata("spawnLoc")).forEach(entity -> {
// Get the meta data // Get the meta data
entity.getMetadata("spawnLoc").stream().filter(y -> y.getOwningPlugin().equals(addon.getPlugin())).forEach(v -> { entity.getMetadata("spawnLoc").stream().filter(y -> y.getOwningPlugin().equals(addon.getPlugin())).forEach(v -> spawnLoc.put(entity.getUniqueId(), v.asString()));
spawnLoc.put(entity.getUniqueId(), v.asString());
});
}); });
if (!spawnLoc.isEmpty()) { if (!spawnLoc.isEmpty()) {
eld.setSpawnLoc(spawnLoc); eld.setSpawnLoc(spawnLoc);
@ -213,7 +211,7 @@ public class EntityLimitsListener implements Listener {
/** /**
* Checks if new entities can be added to island * 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 bypass - true if this is being done by a player with authorization to bypass limits
* @param ent - the entity * @param ent - the entity
* @return true if at the limit, false if not * @return true if at the limit, false if not

View File

@ -21,7 +21,7 @@ import bentobox.addon.limits.objects.IslandBlockCount;
*/ */
public class JoinListener implements Listener { public class JoinListener implements Listener {
private Limits addon; private final Limits addon;
public JoinListener(Limits addon) { public JoinListener(Limits addon) {
this.addon = 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); IslandBlockCount ibc = addon.getBlockLimitListener().getIsland(islandId);
int limit = -1; int limit = -1;
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) { for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
@ -47,17 +47,17 @@ public class JoinListener implements Listener {
String[] split = perms.getPermission().split("\\."); String[] split = perms.getPermission().split("\\.");
if (split.length != 5) { if (split.length != 5) {
logError(player.getName(), perms.getPermission(), "format must be " + permissionPrefix + "MATERIAL.NUMBER"); logError(player.getName(), perms.getPermission(), "format must be " + permissionPrefix + "MATERIAL.NUMBER");
return false; return;
} }
Material m = Material.getMaterial(split[3].toUpperCase(Locale.ENGLISH)); Material m = Material.getMaterial(split[3].toUpperCase(Locale.ENGLISH));
if (m == null) { if (m == null) {
logError(player.getName(), perms.getPermission(), split[3].toUpperCase(Locale.ENGLISH) + " is not a valid material"); 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 // Get the max value should there be more than one
if (perms.getPermission().contains(permissionPrefix + ".*")) { if (perms.getPermission().contains(permissionPrefix + ".*")) {
logError(player.getName(), perms.getPermission(), "wildcards are not allowed"); logError(player.getName(), perms.getPermission(), "wildcards are not allowed");
return false; return;
} }
if (!NumberUtils.isDigits(split[4])) { if (!NumberUtils.isDigits(split[4])) {
logError(player.getName(), perms.getPermission(), "the last part MUST be a number!"); logError(player.getName(), perms.getPermission(), "the last part MUST be a number!");
@ -75,7 +75,6 @@ public class JoinListener implements Listener {
if (ibc != null) { if (ibc != null) {
addon.getBlockLimitListener().setIsland(islandId, ibc); addon.getBlockLimitListener().setIsland(islandId, ibc);
} }
return true;
} }

View File

@ -1,6 +1,3 @@
/**
*
*/
package bentobox.addon.limits.objects; package bentobox.addon.limits.objects;
import java.util.HashMap; import java.util.HashMap;
@ -86,13 +83,8 @@ public class EntityLimitsDO implements DataObject {
} }
EntityLimitsDO other = (EntityLimitsDO) obj; EntityLimitsDO other = (EntityLimitsDO) obj;
if (uniqueId == null) { if (uniqueId == null) {
if (other.uniqueId != null) { return other.uniqueId == null;
return false; } else return uniqueId.equals(other.uniqueId);
}
} else if (!uniqueId.equals(other.uniqueId)) {
return false;
}
return true;
} }

View File

@ -1,6 +1,3 @@
/**
*
*/
package bentobox.addon.limits.objects; package bentobox.addon.limits.objects;
import java.util.HashMap; import java.util.HashMap;
@ -102,7 +99,7 @@ public class IslandBlockCount implements DataObject {
*/ */
public boolean isAtLimit(Material m) { public boolean isAtLimit(Material m) {
// Check island limits first // 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) { public boolean isBlockLimited(Material m) {

View File

@ -7,9 +7,21 @@ authors: tastybento
softdepend: AcidIsland, BSkyBlock, CaveBlock, SkyGrid softdepend: AcidIsland, BSkyBlock, CaveBlock, SkyGrid
permissions: permissions:
limits.player.limits: acidisland.limits.player.limits:
description: Player can use limits command description: Player can use limits command
default: true 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 description: Player can use admin limits command
default: op default: op