mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-07 03:00:29 +01:00
Visitor spawn protection
This commit is contained in:
parent
2c8c6190ee
commit
33d589387f
@ -140,7 +140,7 @@ public class GeneratorManager {
|
||||
}
|
||||
|
||||
public Materials getRandomMaterials(Generator generator) {
|
||||
if (generator.getGeneratorMaterials() != null && generator.getGeneratorMaterials().size() != 0) {
|
||||
if (generator.getGeneratorMaterials() != null && generator.getGeneratorMaterials().stream().anyMatch(x -> x.getChance() > 0)) {
|
||||
List<Materials> weightedList = new ArrayList<>();
|
||||
for (GeneratorMaterial generatorMaterial : generator.getGeneratorMaterials())
|
||||
for (int i = 0; i < generatorMaterial.getChance() * 30; i++)
|
||||
|
@ -228,7 +228,7 @@ public class Block implements Listener {
|
||||
if (configLoad.getBoolean("Island.Spawn.Protection")) {
|
||||
boolean isObstructing = false;
|
||||
// Directly on the block
|
||||
if (LocationUtil.isLocationAffectingLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Main))) {
|
||||
if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world)) {
|
||||
isObstructing = true;
|
||||
}
|
||||
|
||||
@ -236,7 +236,7 @@ public class Block implements Listener {
|
||||
if (!isObstructing && event.getBlock().getState().getData() instanceof org.bukkit.material.Bed) {
|
||||
BlockFace bedDirection = ((org.bukkit.material.Bed) event.getBlock().getState().getData()).getFacing();
|
||||
org.bukkit.block.Block bedBlock = block.getRelative(bedDirection);
|
||||
if (LocationUtil.isLocationAffectingLocation(bedBlock.getLocation(), island.getLocation(world, IslandEnvironment.Main)))
|
||||
if (LocationUtil.isLocationAffectingIslandSpawn(bedBlock.getLocation(), island, world))
|
||||
isObstructing = true;
|
||||
}
|
||||
|
||||
@ -319,7 +319,7 @@ public class Block implements Listener {
|
||||
}
|
||||
|
||||
// Protect spawn
|
||||
if (LocationUtil.isLocationAffectingLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Main)) && configLoad.getBoolean("Island.Spawn.Protection")) {
|
||||
if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world) && configLoad.getBoolean("Island.Spawn.Protection")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -391,13 +391,13 @@ public class Block implements Listener {
|
||||
|
||||
if (configLoad.getBoolean("Island.Spawn.Protection")) {
|
||||
// Check exact block
|
||||
if (LocationUtil.isLocationAffectingLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Main))) {
|
||||
if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check block in direction
|
||||
if (LocationUtil.isLocationAffectingLocation(block.getRelative(event.getDirection()).getLocation(), island.getLocation(world, IslandEnvironment.Main))) {
|
||||
if (LocationUtil.isLocationAffectingIslandSpawn(block.getRelative(event.getDirection()).getLocation(), island, world)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -413,7 +413,7 @@ public class Block implements Listener {
|
||||
|
||||
// Check piston head
|
||||
if (configLoad.getBoolean("Island.Spawn.Protection")) {
|
||||
if (LocationUtil.isLocationAffectingLocation(event.getBlock().getRelative(event.getDirection()).getLocation(), island.getLocation(world, IslandEnvironment.Main))) {
|
||||
if (LocationUtil.isLocationAffectingIslandSpawn(event.getBlock().getRelative(event.getDirection()).getLocation(), island, world)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -445,7 +445,7 @@ public class Block implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (LocationUtil.isLocationAffectingLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Main)) && configLoad.getBoolean("Island.Spawn.Protection")) {
|
||||
if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world) && configLoad.getBoolean("Island.Spawn.Protection")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -482,7 +482,7 @@ public class Block implements Listener {
|
||||
|
||||
// Check spawn block protection
|
||||
IslandWorld world = worldManager.getIslandWorld(event.getBlock().getWorld());
|
||||
if (LocationUtil.isLocationAffectingLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Main))) {
|
||||
if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world)) {
|
||||
if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Spawn.Protection")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -586,7 +586,7 @@ public class Block implements Listener {
|
||||
|
||||
// Check spawn block protection
|
||||
IslandWorld world = worldManager.getIslandWorld(event.getBlock().getWorld());
|
||||
if (LocationUtil.isLocationAffectingLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Main))) {
|
||||
if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world)) {
|
||||
if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Spawn.Protection")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -660,7 +660,7 @@ public class Block implements Listener {
|
||||
Location islandLocation = island.getLocation(world, IslandEnvironment.Main);
|
||||
|
||||
for (org.bukkit.block.BlockState block : event.getBlocks()) {
|
||||
if (LocationUtil.isLocationAffectingLocation(block.getLocation(), islandLocation)) {
|
||||
if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -687,10 +687,9 @@ public class Block implements Listener {
|
||||
|
||||
// Check spawn block protection
|
||||
IslandWorld world = worldManager.getIslandWorld(event.getBlocks().get(0).getWorld());
|
||||
Location islandLocation = island.getLocation(world, IslandEnvironment.Main);
|
||||
|
||||
for (BlockState block : blocks) {
|
||||
if (LocationUtil.isLocationAffectingLocation(block.getLocation(), islandLocation)) {
|
||||
if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -708,10 +707,9 @@ public class Block implements Listener {
|
||||
|
||||
// Check spawn block protection
|
||||
IslandWorld world = worldManager.getIslandWorld(blocks.get(0).getWorld());
|
||||
Location islandLocation = island.getLocation(world, IslandEnvironment.Main);
|
||||
|
||||
for (org.bukkit.block.Block block : blocks) {
|
||||
if (LocationUtil.isLocationAffectingLocation(block.getLocation(), islandLocation)) {
|
||||
if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -739,9 +737,8 @@ public class Block implements Listener {
|
||||
|
||||
// Check spawn block protection
|
||||
IslandWorld world = worldManager.getIslandWorld(placeLocation.getWorld());
|
||||
Location islandLocation = island.getLocation(world, IslandEnvironment.Main);
|
||||
|
||||
if (LocationUtil.isLocationAffectingLocation(placeLocation.getLocation(), islandLocation)) {
|
||||
if (LocationUtil.isLocationAffectingIslandSpawn(placeLocation.getLocation(), island, world)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -77,8 +77,7 @@ public class Bucket implements Listener {
|
||||
|
||||
// Check spawn block protection
|
||||
IslandWorld world = worldManager.getIslandWorld(block.getWorld());
|
||||
Location islandLocation = island.getLocation(world, IslandEnvironment.Main);
|
||||
if (LocationUtil.isLocationAffectingLocation(block.getLocation(), islandLocation)) {
|
||||
if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world)) {
|
||||
event.setCancelled(true);
|
||||
skyblock.getMessageManager().sendMessage(player,
|
||||
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
|
||||
|
@ -418,8 +418,8 @@ public class Entity implements Listener {
|
||||
org.bukkit.block.Block block = event.getBlock();
|
||||
|
||||
// Check spawn block falling, this can be a bit glitchy, but it's better than nothing
|
||||
Location islandLocation = island.getLocation(world, IslandEnvironment.Main);
|
||||
if (LocationUtil.isLocationLocation(block.getLocation(), islandLocation.clone().subtract(0, 1, 0)) &&
|
||||
if ((LocationUtil.isLocationLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Main).clone().subtract(0, 1, 0))
|
||||
|| LocationUtil.isLocationLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Visitor).clone().subtract(0, 1, 0))) &&
|
||||
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Spawn.Protection")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -451,7 +451,7 @@ public class Entity implements Listener {
|
||||
return;
|
||||
|
||||
// Check entities interacting with spawn
|
||||
if (LocationUtil.isLocationAffectingLocation(block.getLocation(), islandLocation) &&
|
||||
if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world) &&
|
||||
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Spawn.Protection")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
@ -4,7 +4,9 @@ import me.goodandevil.skyblock.SkyBlock;
|
||||
import me.goodandevil.skyblock.config.FileManager;
|
||||
import me.goodandevil.skyblock.config.FileManager.Config;
|
||||
import me.goodandevil.skyblock.island.Island;
|
||||
import me.goodandevil.skyblock.island.IslandEnvironment;
|
||||
import me.goodandevil.skyblock.island.IslandManager;
|
||||
import me.goodandevil.skyblock.island.IslandWorld;
|
||||
import me.goodandevil.skyblock.utils.math.VectorUtil;
|
||||
import me.goodandevil.skyblock.utils.version.Materials;
|
||||
import me.goodandevil.skyblock.utils.world.block.BlockDegreesType;
|
||||
@ -32,7 +34,12 @@ public final class LocationUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isLocationAffectingLocation(Location location1, Location location2) {
|
||||
public static boolean isLocationAffectingIslandSpawn(Location location, Island island, IslandWorld world) {
|
||||
return isLocationAffectingLocation(location, island.getLocation(world, IslandEnvironment.Main))
|
||||
|| isLocationAffectingLocation(location, island.getLocation(world, IslandEnvironment.Visitor));
|
||||
}
|
||||
|
||||
private static boolean isLocationAffectingLocation(Location location1, Location location2) {
|
||||
Location headHeight = location2.clone().add(0, 1, 0);
|
||||
Location feetHeight = location2.clone();
|
||||
Location groundHeight = location2.clone().add(0, -1, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user