diff --git a/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java b/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java index b630e87b..ef7e8217 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java +++ b/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java @@ -138,7 +138,7 @@ public class LootChestRegion { } /* - * no location has been found after the X iterations, return null and + * No location has been found after the X iterations, return null and * cancel chest spawning. worst case scenario, should not happen too * often except if the player is in a really NARROW zone */ @@ -148,8 +148,8 @@ public class LootChestRegion { public Location tryRandomDirection(Location center) { /* - * chooses a random direction and get the block in that direction which - * has the same height as the player + * Chooses a random direction and get the block in + * that direction which has the same height as the player */ double a = random.nextDouble() * 2 * Math.PI; Vector dir = new Vector(Math.cos(a), 0, Math.sin(a)) @@ -157,8 +157,8 @@ public class LootChestRegion { Location random = center.add(dir); /* - * go up and down at the same time till it finds a non-solid block with - * a solid block underneath + * Go up and down at the same time till it finds + * a non-solid block with a solid block underneath */ for (int h = 0; h <= algOptions.height * 2; h++) { int z = h % 2 == 0 ? h / 2 : -(h + 1) / 2; // bijective from N to Z diff --git a/src/main/java/net/Indyuce/mmocore/manager/LootChestManager.java b/src/main/java/net/Indyuce/mmocore/manager/LootChestManager.java index b7805bf5..4dab3230 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/LootChestManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/LootChestManager.java @@ -1,10 +1,6 @@ package net.Indyuce.mmocore.manager; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.logging.Level; import org.bukkit.Location; @@ -14,23 +10,33 @@ import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.ConfigFile; import net.Indyuce.mmocore.loot.chest.LootChest; import net.Indyuce.mmocore.loot.chest.LootChestRegion; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class LootChestManager implements MMOCoreManager { - /* - * all active loot chests in the server + /** + * Active loot chests in the server */ private final Set active = new HashSet<>(); + /** + * Registered loot chest regions + */ private final Map regions = new HashMap<>(); public boolean hasRegion(String id) { return regions.containsKey(id); } - public LootChestRegion getRegion(String id) { - return regions.get(id); - } + /** + * @return Region with specific identifier + * @throws NullPointerException if not found + */ + @NotNull + public LootChestRegion getRegion(String id) { + return Objects.requireNonNull(regions.get(id), "Could not find region with ID '" + id + "'"); + } public Collection getRegions() { return regions.values(); @@ -48,6 +54,7 @@ public class LootChestManager implements MMOCoreManager { active.remove(chest); } + @Nullable public LootChest getChest(Location loc) { for (LootChest chest : active)