Fixed structures like trees being able to grow outside border

This commit is contained in:
BuildTools 2019-09-22 19:15:22 -06:00
parent b7958e3af2
commit 3acef806e9
2 changed files with 547 additions and 485 deletions

View File

@ -502,4 +502,15 @@ public class Island {
public com.songoda.skyblock.island.Island getIsland() { public com.songoda.skyblock.island.Island getIsland() {
return handle; return handle;
} }
@Override
public boolean equals(Object object) {
if (!(object instanceof Island))
return false;
Island other = (Island) object;
if (!other.getIslandUUID().equals(getIslandUUID()))
return false;
return true;
}
} }

View File

@ -0,0 +1,51 @@
package com.songoda.skyblock.listeners;
import org.bukkit.block.BlockState;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.StructureGrowEvent;
import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.island.Island;
import com.songoda.skyblock.island.IslandManager;
import com.songoda.skyblock.world.WorldManager;
public class Grow implements Listener {
private final SkyBlock skyblock;
public Grow(SkyBlock skyblock) {
this.skyblock = skyblock;
}
/**
* Checks that a structure like a tree is not growing outside or into another island.
* @author LimeGlass
*/
@EventHandler
public void onStructureGrow(StructureGrowEvent event) {
WorldManager worldManager = skyblock.getWorldManager();
if (!worldManager.isIslandWorld(event.getWorld()))
return;
IslandManager islandManager = skyblock.getIslandManager();
Island origin = islandManager.getIslandAtLocation(event.getLocation());
for (BlockState state : event.getBlocks()) {
Island growingTo = islandManager.getIslandAtLocation(state.getLocation());
// This block is ok to continue as it's not related to Skyblock islands.
if (origin == null && growingTo == null)
continue;
// A block from the structure is outside/inside that it's not suppose to.
if (origin == null || growingTo == null) {
event.getBlocks().remove(state);
continue;
}
// The structure is growing from one island to another.
if (!origin.getIslandUUID().equals(growingTo.getIslandUUID())) {
event.getBlocks().remove(state);
continue;
}
}
}
}