Skip to content
Draft
14 changes: 7 additions & 7 deletions src/me/ryanhamshire/PopulationDensity/BlockEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void onBlockBreak(BlockBreakEvent breakEvent)
Block block = breakEvent.getBlock();

//if the player is not in managed world, do nothing (let vanilla code and other plugins do whatever)
if (!player.getWorld().equals(PopulationDensity.ManagedWorld)) return;
if (!PopulationDensity.ManagedWorlds.contains(player.getWorld())) return;

//otherwise figure out which region that block is in
Location blockLocation = block.getLocation();
Expand Down Expand Up @@ -151,7 +151,7 @@ public void onBlockFromTo(BlockFromToEvent event)
}

//if not in managed world, do nothing
if (!from.getWorld().equals(PopulationDensity.ManagedWorld)) return;
if (!PopulationDensity.ManagedWorlds.contains(from.getWorld())) return;

//region posts are at sea level at the lowest, so no need to check build permissions under that
if (from.getY() < PopulationDensity.instance.minimumRegionPostY) return;
Expand Down Expand Up @@ -180,7 +180,7 @@ public void onBlockPlace(BlockPlaceEvent placeEvent)
Block block = placeEvent.getBlock();

//if not in managed world, do nothing
if (!player.getWorld().equals(PopulationDensity.ManagedWorld)) return;
if (!PopulationDensity.ManagedWorlds.contains(player.getWorld())) return;

Location blockLocation = block.getLocation();

Expand Down Expand Up @@ -246,7 +246,7 @@ public void onBlockDamage(BlockDamageEvent damageEvent)
if (player == null || (!Tag.WALL_SIGNS.isTagged(block.getType()) && !Tag.SIGNS.isTagged(block.getType()))) return;

//if the player is not in managed world, do nothing
if (!player.getWorld().equals(PopulationDensity.ManagedWorld)) return;
if (!PopulationDensity.ManagedWorlds.contains(player.getWorld())) return;

if (!this.nearRegionPost(block.getLocation(), RegionCoordinates.fromLocation(block.getLocation()), 1)) return;

Expand All @@ -258,7 +258,7 @@ public void onBlockPistonExtend(BlockPistonExtendEvent event)
{
Block pistonBlock = event.getBlock();

if (!pistonBlock.getWorld().equals(PopulationDensity.ManagedWorld)) return;
if (!PopulationDensity.ManagedWorlds.contains(pistonBlock.getWorld())) return;

RegionCoordinates pistonRegion = RegionCoordinates.fromLocation(pistonBlock.getLocation());
if (this.nearRegionPost(pistonBlock.getLocation(), pistonRegion, PopulationDensity.instance.postProtectionRadius + 12))
Expand All @@ -280,7 +280,7 @@ public void onBlockPistonRetract(BlockPistonRetractEvent event)
{
Block pistonBlock = event.getBlock();

if (!pistonBlock.getWorld().equals(PopulationDensity.ManagedWorld)) return;
if (!PopulationDensity.ManagedWorlds.contains(pistonBlock.getWorld())) return;

RegionCoordinates pistonRegion = RegionCoordinates.fromLocation(pistonBlock.getLocation());
if (this.nearRegionPost(pistonBlock.getLocation(), pistonRegion, PopulationDensity.instance.postProtectionRadius + 12))
Expand Down Expand Up @@ -312,7 +312,7 @@ private boolean nearRegionPost(Location location, RegionCoordinates region, int
location.getBlockX() <= postLocation.getBlockX() + howClose &&
location.getBlockZ() >= postLocation.getBlockZ() - howClose &&
location.getBlockZ() <= postLocation.getBlockZ() + howClose &&
location.getBlockY() >= PopulationDensity.ManagedWorld.getHighestBlockYAt(postLocation) - 4
location.getBlockY() >= location.getWorld().getHighestBlockYAt(postLocation) - 4
);
}
}
138 changes: 64 additions & 74 deletions src/me/ryanhamshire/PopulationDensity/DataStore.java

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/me/ryanhamshire/PopulationDensity/EntityEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void onEntityExplode(EntityExplodeEvent explodeEvent)

//otherwise if it's close to a region post
Location regionCenter = PopulationDensity.getRegionCenter(region, false);
regionCenter.setY(PopulationDensity.ManagedWorld.getHighestBlockYAt(regionCenter));
regionCenter.setY(location.getWorld().getHighestBlockYAt(regionCenter));
if (regionCenter.distanceSquared(location) < 225) //225 = 15 * 15
{
explodeEvent.blockList().clear(); //All the noise and terror, none of the destruction (whew!).
Expand Down Expand Up @@ -135,7 +135,7 @@ public void onItemDespawn(ItemDespawnEvent event)
if (!saplings.contains(item.getType())) return;

//only care about the newest region
if (!PopulationDensity.instance.dataStore.getOpenRegion().equals(RegionCoordinates.fromLocation(entity.getLocation())))
if (!PopulationDensity.instance.dataStore.getOpenRegion(event.getLocation().getWorld()).equals(RegionCoordinates.fromLocation(entity.getLocation())))
return;

//only replace these blocks with saplings
Expand Down Expand Up @@ -243,7 +243,7 @@ public void onEntitySpawn(CreatureSpawnEvent event)
//natural spawns may cause animal spawns to keep new player resources available
if (reason == SpawnReason.NATURAL)
{
if (PopulationDensity.ManagedWorld == null || event.getLocation().getWorld() != PopulationDensity.ManagedWorld)
if (!PopulationDensity.ManagedWorlds.contains(event.getLocation().getWorld()))
return;

//when an animal naturally spawns, grow grass around it
Expand All @@ -256,7 +256,7 @@ public void onEntitySpawn(CreatureSpawnEvent event)
if (entity instanceof Monster && PopulationDensity.instance.respawnAnimals)
{
//only do this if the spawn is in the newest region
if (!PopulationDensity.instance.dataStore.getOpenRegion().equals(RegionCoordinates.fromLocation(entity.getLocation())))
if (!PopulationDensity.instance.dataStore.getOpenRegion(entity.getWorld()).equals(RegionCoordinates.fromLocation(entity.getLocation())))
return;

//if it's on grass, there's a 1/100 chance it will also spawn a group of animals
Expand Down
2 changes: 1 addition & 1 deletion src/me/ryanhamshire/PopulationDensity/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public enum Messages
{
NoManagedWorld,
WorldNotManaged,
NoBreakPost,
NoBreakSpawn,
NoBuildPost,
Expand Down
10 changes: 4 additions & 6 deletions src/me/ryanhamshire/PopulationDensity/PlayerEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ else if (entry.playerName.equals(player.getName()))
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerJoin(PlayerJoinEvent event)
{

Player joiningPlayer = event.getPlayer();

PopulationDensity.instance.resetIdleTimer(joiningPlayer);
Expand All @@ -246,7 +245,7 @@ public void onPlayerJoin(PlayerJoinEvent event)
if (!joiningPlayer.hasPlayedBefore())
{
// his home region is the open region
RegionCoordinates openRegion = this.dataStore.getOpenRegion();
RegionCoordinates openRegion = this.dataStore.getOpenRegion(joiningPlayer.getWorld());
playerData.homeRegion = openRegion;
PopulationDensity.AddLogEntry("Assigned new player "
+ joiningPlayer.getName() + " to region "
Expand Down Expand Up @@ -284,7 +283,7 @@ public void onPlayerJoin(PlayerJoinEvent event)

if (playerData.homeRegion == null)
{
playerData.homeRegion = PopulationDensity.instance.dataStore.getOpenRegion();
playerData.homeRegion = PopulationDensity.instance.dataStore.getOpenRegion(joiningPlayer.getWorld());
}
}

Expand Down Expand Up @@ -349,7 +348,7 @@ public void onPlayerRespawn(PlayerRespawnEvent respawnEvent)
{
if (!PopulationDensity.instance.respawnInHomeRegion)
{
if (PopulationDensity.ManagedWorld == respawnEvent.getRespawnLocation().getWorld())
if (PopulationDensity.ManagedWorlds.contains(respawnEvent.getRespawnLocation().getWorld()))
{
PopulationDensity.removeMonstersAround(respawnEvent.getRespawnLocation());
}
Expand All @@ -369,8 +368,7 @@ public void onPlayerRespawn(PlayerRespawnEvent respawnEvent)
Location homeRegionCenter = PopulationDensity.getRegionCenter(playerData.homeRegion, false);

// aim for two blocks above the highest block and teleport
homeRegionCenter.setY(PopulationDensity.ManagedWorld
.getHighestBlockYAt(homeRegionCenter) + 2);
homeRegionCenter.setY(player.getWorld().getHighestBlockYAt(homeRegionCenter) + 2);
respawnEvent.setRespawnLocation(homeRegionCenter);

PopulationDensity.removeMonstersAround(homeRegionCenter);
Expand Down
Loading