Fix border off by 1 issues. Fix island create with menu disabled.

This commit is contained in:
Esophose 2019-05-24 10:24:13 -06:00
parent ac6c3c8719
commit 1bc5e1fb6f
7 changed files with 104 additions and 90 deletions

View File

@ -12,7 +12,7 @@ public class IslandCreateEvent extends IslandEvent {
private final Player player; private final Player player;
public IslandCreateEvent(Island island, Player player) { public IslandCreateEvent(Island island, Player player) {
super(island); super(island, true);
this.player = player; this.player = player;
} }

View File

@ -12,6 +12,7 @@ import me.goodandevil.skyblock.sound.SoundManager;
import me.goodandevil.skyblock.upgrade.Upgrade; import me.goodandevil.skyblock.upgrade.Upgrade;
import me.goodandevil.skyblock.utils.NumberUtil; import me.goodandevil.skyblock.utils.NumberUtil;
import me.goodandevil.skyblock.utils.version.Sounds; import me.goodandevil.skyblock.utils.version.Sounds;
import me.goodandevil.skyblock.utils.world.LocationUtil;
import me.goodandevil.skyblock.utils.world.WorldBorder; import me.goodandevil.skyblock.utils.world.WorldBorder;
import me.goodandevil.skyblock.visit.Visit; import me.goodandevil.skyblock.visit.Visit;
import org.apache.commons.lang.WordUtils; import org.apache.commons.lang.WordUtils;
@ -823,6 +824,14 @@ public class Island {
return unlocked; return unlocked;
} }
public boolean isLocationWithinIsland(IslandWorld world, Location location) {
Location islandLocation = this.getLocation(world, IslandEnvironment.Island).clone().add(0.5, 0, 0.5);
double size = this.getRadius();
size += size % 2 == 0 ? 1 : 0;
return LocationUtil.isLocationAtLocationRadius(location, islandLocation, size);
}
public me.goodandevil.skyblock.api.island.Island getAPIWrapper() { public me.goodandevil.skyblock.api.island.Island getAPIWrapper() {
return apiWrapper; return apiWrapper;
} }

View File

@ -214,7 +214,8 @@ public class IslandManager {
} }
} }
Bukkit.getServer().getPluginManager().callEvent(new IslandCreateEvent(island.getAPIWrapper(), player)); Bukkit.getScheduler().runTaskAsynchronously(skyblock, () ->
Bukkit.getServer().getPluginManager().callEvent(new IslandCreateEvent(island.getAPIWrapper(), player)));
skyblock.getPlayerDataManager().getPlayerData(player).setIsland(player.getUniqueId()); skyblock.getPlayerDataManager().getPlayerData(player).setIsland(player.getUniqueId());

View File

@ -188,14 +188,11 @@ public class Block implements Listener {
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")); Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml"));
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
if (configLoad.getBoolean("Island.WorldBorder.Block")) { if (configLoad.getBoolean("Island.WorldBorder.Block") && block.getType() == Material.DISPENSER) {
if (block.getType() == Material.DISPENSER) { if (!island.isLocationWithinIsland(world, block.getLocation())) {
if (!LocationUtil.isLocationAtLocationRadius(block.getLocation(),
island.getLocation(world, IslandEnvironment.Island), island.getRadius() - 2.0D)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
}
// Check spawn protection // Check spawn protection
if (configLoad.getBoolean("Island.Spawn.Protection")) { if (configLoad.getBoolean("Island.Spawn.Protection")) {
@ -272,11 +269,14 @@ public class Block implements Listener {
org.bukkit.block.Block block = event.getToBlock(); org.bukkit.block.Block block = event.getToBlock();
// Protect spawn location and outside of border // Protect outside of border
if (!LocationUtil.isLocationAtLocationRadius(block.getLocation(), island.getLocation(world, IslandEnvironment.Island), island.getRadius() - 1.0D)) { if (!island.isLocationWithinIsland(world, block.getLocation())) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} else if (LocationUtil.isLocationAffectingLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Main)) && configLoad.getBoolean("Island.Spawn.Protection")) { }
// Protect spawn
if (LocationUtil.isLocationAffectingLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Main)) && configLoad.getBoolean("Island.Spawn.Protection")) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -293,7 +293,7 @@ public class Block implements Listener {
island.hasRole(IslandRole.Member, p.getUniqueId()) || island.hasRole(IslandRole.Member, p.getUniqueId()) ||
island.hasRole(IslandRole.Coop, p.getUniqueId()) || island.hasRole(IslandRole.Coop, p.getUniqueId()) ||
island.hasRole(IslandRole.Operator, p.getUniqueId()); island.hasRole(IslandRole.Operator, p.getUniqueId());
if (isMember && LocationUtil.isLocationAtLocationRadius(p.getLocation(), island.getLocation(world, IslandEnvironment.Island), island.getRadius())) { if (isMember && island.isLocationWithinIsland(world, p.getLocation())) {
possiblePlayers.add(p); possiblePlayers.add(p);
} }
} }
@ -336,7 +336,7 @@ public class Block implements Listener {
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
for (org.bukkit.block.Block block : event.getBlocks()) { for (org.bukkit.block.Block block : event.getBlocks()) {
if (!LocationUtil.isLocationAtLocationRadius(block.getLocation(), island.getLocation(world, IslandEnvironment.Island), island.getRadius() - 2.0D)) { if (!island.isLocationWithinIsland(world, block.getLocation())) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -392,7 +392,7 @@ public class Block implements Listener {
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
for (org.bukkit.block.Block block : event.getBlocks()) { for (org.bukkit.block.Block block : event.getBlocks()) {
if (!LocationUtil.isLocationAtLocationRadius(block.getLocation(), island.getLocation(world, IslandEnvironment.Island), island.getRadius() - 2.0D)) { if (!island.isLocationWithinIsland(world, block.getLocation())) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -468,7 +468,7 @@ public class Block implements Listener {
island.hasRole(IslandRole.Member, player.getUniqueId()) || island.hasRole(IslandRole.Member, player.getUniqueId()) ||
island.hasRole(IslandRole.Coop, player.getUniqueId()) || island.hasRole(IslandRole.Coop, player.getUniqueId()) ||
island.hasRole(IslandRole.Operator, player.getUniqueId()); island.hasRole(IslandRole.Operator, player.getUniqueId());
if (isMember && LocationUtil.isLocationAtLocationRadius(player.getLocation(), island.getLocation(world, IslandEnvironment.Island), island.getRadius())) { if (isMember && island.isLocationWithinIsland(world, player.getLocation())) {
possiblePlayers.add(player); possiblePlayers.add(player);
} }
} }

View File

@ -36,6 +36,7 @@ public class Quit implements Listener {
@EventHandler @EventHandler
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
Bukkit.getScheduler().runTaskAsynchronously(skyblock, () -> {
Player player = event.getPlayer(); Player player = event.getPlayer();
PlayerDataManager playerDataManager = skyblock.getPlayerDataManager(); PlayerDataManager playerDataManager = skyblock.getPlayerDataManager();
@ -48,7 +49,7 @@ public class Quit implements Listener {
try { try {
playerData.setLastOnline(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date())); playerData.setLastOnline(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date()));
} catch (Exception e) { } catch (Exception ignored) {
} }
Island island = islandManager.getIsland(player); Island island = islandManager.getIsland(player);
@ -80,7 +81,8 @@ public class Quit implements Listener {
} }
} }
islandManager.unloadIsland(island, player); final Island is = island;
Bukkit.getScheduler().scheduleSyncDelayedTask(skyblock, () -> islandManager.unloadIsland(is, player));
} }
cooldownManager.setCooldownPlayer(CooldownType.Biome, player); cooldownManager.setCooldownPlayer(CooldownType.Biome, player);
@ -105,7 +107,8 @@ public class Quit implements Listener {
if (!island.hasRole(IslandRole.Member, player.getUniqueId()) if (!island.hasRole(IslandRole.Member, player.getUniqueId())
&& !island.hasRole(IslandRole.Operator, player.getUniqueId()) && !island.hasRole(IslandRole.Operator, player.getUniqueId())
&& !island.hasRole(IslandRole.Owner, player.getUniqueId())) { && !island.hasRole(IslandRole.Owner, player.getUniqueId())) {
islandManager.unloadIsland(island, null); final Island is = island;
Bukkit.getScheduler().scheduleSyncDelayedTask(skyblock, () -> islandManager.unloadIsland(is, null));
} }
} }
@ -124,5 +127,6 @@ public class Quit implements Listener {
inviteManager.removeInvite(player.getUniqueId()); inviteManager.removeInvite(player.getUniqueId());
} }
});
} }
} }

View File

@ -1130,7 +1130,7 @@ public enum Materials {
Materials pmat = null; Materials pmat = null;
for (Materials mat : Materials.values()) { for (Materials mat : Materials.values()) {
if (name.toUpperCase().equals(mat.old12Mat)) { if (name.equalsIgnoreCase(mat.old12Mat)) {
if (pmat == null) { if (pmat == null) {
pmat = mat; pmat = mat;
} }
@ -1179,7 +1179,7 @@ public enum Materials {
return Materials.valueOf(mat.toString()); return Materials.valueOf(mat.toString());
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
for (Materials xmat : Materials.values()) { for (Materials xmat : Materials.values()) {
if (xmat.old12Mat.equals(mat.toString())) { if (xmat.old12Mat.equalsIgnoreCase(mat.toString())) {
return xmat; return xmat;
} }
} }

View File

@ -48,10 +48,10 @@ public final class LocationUtil {
return false; return false;
} }
double x = Math.abs(location1.getX() - location2.getX()) - 1; double x = Math.abs(location1.getX() - location2.getX());
double z = Math.abs(location1.getZ() - location2.getZ()) - 1; double z = Math.abs(location1.getZ() - location2.getZ());
return x < radius && z < radius; return x <= radius && z <= radius;
} }
public static List<Location> getLocations(Location minLocation, Location maxLocation) { public static List<Location> getLocations(Location minLocation, Location maxLocation) {