Skip to content

Commit

Permalink
Fix NPEs
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Dec 22, 2021
1 parent 14c3886 commit 3f1465d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
7 changes: 3 additions & 4 deletions src/main/java/world/bentobox/limits/Limits.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public JoinListener getJoinListener() {
private void registerPlaceholders(GameModeAddon gm) {
if (getPlugin().getPlaceholdersManager() == null) return;
Arrays.stream(Material.values())
.filter(m -> m.isBlock())
.forEach(m -> registerCountAndLimitPlaceholders(m, gm));
.filter(m -> m.isBlock())
.forEach(m -> registerCountAndLimitPlaceholders(m, gm));
}

/**
Expand Down Expand Up @@ -171,8 +171,7 @@ private int getCount(@Nullable User user, Material m, GameModeAddon gm) {
if (is == null) {
return 0;
}
return getBlockLimitListener().getIsland(gm.getIslands().getIsland(gm.getOverWorld(), user).getUniqueId()).
getBlockCount(m);
return getBlockLimitListener().getIsland(gm.getIslands().getIsland(gm.getOverWorld(), user).getUniqueId()).getBlockCount(m);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/world/bentobox/limits/commands/LimitTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ private void addEntityGroupLimits(IslandBlockCount ibc, Island island) {
Map<EntityGroup, Integer> groupmap = addon.getSettings().getGroupLimitDefinitions().stream().collect(Collectors.toMap(e -> e, e -> e.getLimit()));
Map<String, EntityGroup> groupbyname = groupmap.keySet().stream().collect(Collectors.toMap(e -> e.getName(), e -> e));
// Merge in any permission-based limits
if (ibc != null) ibc.getEntityGroupLimits().entrySet().stream()
if (ibc == null) {
return;
}
ibc.getEntityGroupLimits().entrySet().stream()
.filter(e -> groupbyname.containsKey(e.getKey()))
.forEach(e -> groupmap.put(groupbyname.get(e.getKey()), e.getValue()));

ibc.getEntityGroupLimitsOffset().entrySet().forEach(o ->
groupmap.put(groupbyname.get(o.getKey()), (groupmap.getOrDefault(o.getKey(), 0) + o.getValue())));
groupmap.forEach((v, limit) -> {
Expand Down Expand Up @@ -186,7 +190,7 @@ private void addMaterialIcons(IslandBlockCount ibc, Map<Material, Integer> matLi
pib.icon(B2M.getOrDefault(en.getKey(), en.getKey()));

int count = ibc == null ? 0 : ibc.getBlockCounts().getOrDefault(en.getKey(), 0);
int value = en.getValue() + ibc.getBlockLimitsOffset().getOrDefault(en.getKey(), 0);
int value = en.getValue() + (ibc == null ? 0 : ibc.getBlockLimitsOffset().getOrDefault(en.getKey(), 0));
String color = count >= value ? user.getTranslation("island.limits.max-color") : user.getTranslation("island.limits.regular-color");
pib.description(color
+ user.getTranslation("island.limits.block-limit-syntax",
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/world/bentobox/limits/listeners/JoinListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
import world.bentobox.bentobox.api.events.team.TeamSetownerEvent;
Expand Down Expand Up @@ -52,6 +53,7 @@ public JoinListener(Limits addon) {
*/
public void checkPerms(Player player, String permissionPrefix, String islandId, String gameMode) {
IslandBlockCount ibc = addon.getBlockLimitListener().getIsland(islandId);
BentoBox.getInstance().logDebug("Check perms ibc == null? " + ibc == null);
// Check permissions
if (ibc != null) {
// Clear permission limits
Expand All @@ -60,7 +62,7 @@ public void checkPerms(Player player, String permissionPrefix, String islandId,
ibc.getBlockLimits().clear();
}
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
if (!perms.getValue()
if (!perms.getValue()
|| !perms.getPermission().startsWith(permissionPrefix)
|| badSyntaxCheck(perms, player.getName(), permissionPrefix)) {
continue;
Expand All @@ -79,6 +81,8 @@ public void checkPerms(Player player, String permissionPrefix, String islandId,
}
// Make an ibc if required
if (ibc == null) {

BentoBox.getInstance().logDebug("Making new IBC");
ibc = new IslandBlockCount(islandId, gameMode);
}
// Get the value
Expand All @@ -93,7 +97,9 @@ public void checkPerms(Player player, String permissionPrefix, String islandId,
runNullCheckAndSet(ibc, l);
}
// Check removed permissions

if (ibc == null) {
BentoBox.getInstance().logDebug("IBC is still null");
}
// If any changes have been made then store it - don't make files unless they are needed
if (ibc != null) addon.getBlockLimitListener().setIsland(islandId, ibc);
}
Expand Down Expand Up @@ -145,7 +151,7 @@ private void runNullCheckAndSet(@Nullable IslandBlockCount ibc, @NonNull Limits
ibc.setEntityLimit(et, Math.max(ibc.getEntityLimit(et), value));
}
}

}

private void logError(String name, String perm, String error) {
Expand All @@ -163,6 +169,7 @@ public void onNewIsland(IslandEvent e) {
&& !e.getReason().equals(Reason.REGISTERED)) {
return;
}
BentoBox.getInstance().logDebug("Island Event " + e.getReason());
setOwnerPerms(e.getIsland(), e.getOwner());
}

Expand Down

0 comments on commit 3f1465d

Please sign in to comment.