mirror of
https://github.com/BentoBoxWorld/Limits.git
synced 2024-09-27 14:12:57 +02:00
Fix NPEs
This commit is contained in:
parent
14c38869df
commit
3f1465d6ef
@ -134,8 +134,8 @@ public class Limits extends Addon {
|
|||||||
private void registerPlaceholders(GameModeAddon gm) {
|
private void registerPlaceholders(GameModeAddon gm) {
|
||||||
if (getPlugin().getPlaceholdersManager() == null) return;
|
if (getPlugin().getPlaceholdersManager() == null) return;
|
||||||
Arrays.stream(Material.values())
|
Arrays.stream(Material.values())
|
||||||
.filter(m -> m.isBlock())
|
.filter(m -> m.isBlock())
|
||||||
.forEach(m -> registerCountAndLimitPlaceholders(m, gm));
|
.forEach(m -> registerCountAndLimitPlaceholders(m, gm));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -171,8 +171,7 @@ public class Limits extends Addon {
|
|||||||
if (is == null) {
|
if (is == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return getBlockLimitListener().getIsland(gm.getIslands().getIsland(gm.getOverWorld(), user).getUniqueId()).
|
return getBlockLimitListener().getIsland(gm.getIslands().getIsland(gm.getOverWorld(), user).getUniqueId()).getBlockCount(m);
|
||||||
getBlockCount(m);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,9 +104,13 @@ public class LimitTab implements Tab {
|
|||||||
Map<EntityGroup, Integer> groupmap = addon.getSettings().getGroupLimitDefinitions().stream().collect(Collectors.toMap(e -> e, e -> e.getLimit()));
|
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));
|
Map<String, EntityGroup> groupbyname = groupmap.keySet().stream().collect(Collectors.toMap(e -> e.getName(), e -> e));
|
||||||
// Merge in any permission-based limits
|
// 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()))
|
.filter(e -> groupbyname.containsKey(e.getKey()))
|
||||||
.forEach(e -> groupmap.put(groupbyname.get(e.getKey()), e.getValue()));
|
.forEach(e -> groupmap.put(groupbyname.get(e.getKey()), e.getValue()));
|
||||||
|
|
||||||
ibc.getEntityGroupLimitsOffset().entrySet().forEach(o ->
|
ibc.getEntityGroupLimitsOffset().entrySet().forEach(o ->
|
||||||
groupmap.put(groupbyname.get(o.getKey()), (groupmap.getOrDefault(o.getKey(), 0) + o.getValue())));
|
groupmap.put(groupbyname.get(o.getKey()), (groupmap.getOrDefault(o.getKey(), 0) + o.getValue())));
|
||||||
groupmap.forEach((v, limit) -> {
|
groupmap.forEach((v, limit) -> {
|
||||||
@ -186,7 +190,7 @@ public class LimitTab implements Tab {
|
|||||||
pib.icon(B2M.getOrDefault(en.getKey(), en.getKey()));
|
pib.icon(B2M.getOrDefault(en.getKey(), en.getKey()));
|
||||||
|
|
||||||
int count = ibc == null ? 0 : ibc.getBlockCounts().getOrDefault(en.getKey(), 0);
|
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");
|
String color = count >= value ? user.getTranslation("island.limits.max-color") : user.getTranslation("island.limits.regular-color");
|
||||||
pib.description(color
|
pib.description(color
|
||||||
+ user.getTranslation("island.limits.block-limit-syntax",
|
+ user.getTranslation("island.limits.block-limit-syntax",
|
||||||
|
@ -20,6 +20,7 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
|
|||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
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;
|
||||||
import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
|
import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
|
||||||
import world.bentobox.bentobox.api.events.team.TeamSetownerEvent;
|
import world.bentobox.bentobox.api.events.team.TeamSetownerEvent;
|
||||||
@ -52,6 +53,7 @@ public class JoinListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
public void checkPerms(Player player, String permissionPrefix, String islandId, String gameMode) {
|
public void checkPerms(Player player, String permissionPrefix, String islandId, String gameMode) {
|
||||||
IslandBlockCount ibc = addon.getBlockLimitListener().getIsland(islandId);
|
IslandBlockCount ibc = addon.getBlockLimitListener().getIsland(islandId);
|
||||||
|
BentoBox.getInstance().logDebug("Check perms ibc == null? " + ibc == null);
|
||||||
// Check permissions
|
// Check permissions
|
||||||
if (ibc != null) {
|
if (ibc != null) {
|
||||||
// Clear permission limits
|
// Clear permission limits
|
||||||
@ -79,6 +81,8 @@ public class JoinListener implements Listener {
|
|||||||
}
|
}
|
||||||
// Make an ibc if required
|
// Make an ibc if required
|
||||||
if (ibc == null) {
|
if (ibc == null) {
|
||||||
|
|
||||||
|
BentoBox.getInstance().logDebug("Making new IBC");
|
||||||
ibc = new IslandBlockCount(islandId, gameMode);
|
ibc = new IslandBlockCount(islandId, gameMode);
|
||||||
}
|
}
|
||||||
// Get the value
|
// Get the value
|
||||||
@ -93,7 +97,9 @@ public class JoinListener implements Listener {
|
|||||||
runNullCheckAndSet(ibc, l);
|
runNullCheckAndSet(ibc, l);
|
||||||
}
|
}
|
||||||
// Check removed permissions
|
// 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 any changes have been made then store it - don't make files unless they are needed
|
||||||
if (ibc != null) addon.getBlockLimitListener().setIsland(islandId, ibc);
|
if (ibc != null) addon.getBlockLimitListener().setIsland(islandId, ibc);
|
||||||
}
|
}
|
||||||
@ -163,6 +169,7 @@ public class JoinListener implements Listener {
|
|||||||
&& !e.getReason().equals(Reason.REGISTERED)) {
|
&& !e.getReason().equals(Reason.REGISTERED)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
BentoBox.getInstance().logDebug("Island Event " + e.getReason());
|
||||||
setOwnerPerms(e.getIsland(), e.getOwner());
|
setOwnerPerms(e.getIsland(), e.getOwner());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user