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;
public IslandCreateEvent(Island island, Player player) {
super(island);
super(island, true);
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.utils.NumberUtil;
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.visit.Visit;
import org.apache.commons.lang.WordUtils;
@ -823,6 +824,14 @@ public class Island {
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() {
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());

View File

@ -188,12 +188,9 @@ public class Block implements Listener {
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml"));
FileConfiguration configLoad = config.getFileConfiguration();
if (configLoad.getBoolean("Island.WorldBorder.Block")) {
if (block.getType() == Material.DISPENSER) {
if (!LocationUtil.isLocationAtLocationRadius(block.getLocation(),
island.getLocation(world, IslandEnvironment.Island), island.getRadius() - 2.0D)) {
event.setCancelled(true);
}
if (configLoad.getBoolean("Island.WorldBorder.Block") && block.getType() == Material.DISPENSER) {
if (!island.isLocationWithinIsland(world, block.getLocation())) {
event.setCancelled(true);
}
}
@ -272,11 +269,14 @@ public class Block implements Listener {
org.bukkit.block.Block block = event.getToBlock();
// Protect spawn location and outside of border
if (!LocationUtil.isLocationAtLocationRadius(block.getLocation(), island.getLocation(world, IslandEnvironment.Island), island.getRadius() - 1.0D)) {
// Protect outside of border
if (!island.isLocationWithinIsland(world, block.getLocation())) {
event.setCancelled(true);
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);
return;
}
@ -293,7 +293,7 @@ public class Block implements Listener {
island.hasRole(IslandRole.Member, p.getUniqueId()) ||
island.hasRole(IslandRole.Coop, 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);
}
}
@ -336,7 +336,7 @@ public class Block implements Listener {
FileConfiguration configLoad = config.getFileConfiguration();
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);
return;
}
@ -392,7 +392,7 @@ public class Block implements Listener {
FileConfiguration configLoad = config.getFileConfiguration();
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);
return;
}
@ -468,7 +468,7 @@ public class Block implements Listener {
island.hasRole(IslandRole.Member, player.getUniqueId()) ||
island.hasRole(IslandRole.Coop, 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);
}
}

View File

@ -36,93 +36,97 @@ public class Quit implements Listener {
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
Bukkit.getScheduler().runTaskAsynchronously(skyblock, () -> {
Player player = event.getPlayer();
PlayerDataManager playerDataManager = skyblock.getPlayerDataManager();
CooldownManager cooldownManager = skyblock.getCooldownManager();
MessageManager messageManager = skyblock.getMessageManager();
InviteManager inviteManager = skyblock.getInviteManager();
IslandManager islandManager = skyblock.getIslandManager();
PlayerDataManager playerDataManager = skyblock.getPlayerDataManager();
CooldownManager cooldownManager = skyblock.getCooldownManager();
MessageManager messageManager = skyblock.getMessageManager();
InviteManager inviteManager = skyblock.getInviteManager();
IslandManager islandManager = skyblock.getIslandManager();
PlayerData playerData = playerDataManager.getPlayerData(player);
PlayerData playerData = playerDataManager.getPlayerData(player);
try {
playerData.setLastOnline(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date()));
} catch (Exception e) {
}
try {
playerData.setLastOnline(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date()));
} catch (Exception ignored) {
}
Island island = islandManager.getIsland(player);
Island island = islandManager.getIsland(player);
if (island != null) {
Set<UUID> islandMembersOnline = islandManager.getMembersOnline(island);
if (island != null) {
Set<UUID> islandMembersOnline = islandManager.getMembersOnline(island);
if (islandMembersOnline.size() == 1) {
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(island.getOwnerUUID());
cooldownManager.setCooldownPlayer(CooldownType.Levelling, offlinePlayer);
cooldownManager.removeCooldownPlayer(CooldownType.Levelling, offlinePlayer);
if (islandMembersOnline.size() == 1) {
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(island.getOwnerUUID());
cooldownManager.setCooldownPlayer(CooldownType.Levelling, offlinePlayer);
cooldownManager.removeCooldownPlayer(CooldownType.Levelling, offlinePlayer);
cooldownManager.setCooldownPlayer(CooldownType.Ownership, offlinePlayer);
cooldownManager.removeCooldownPlayer(CooldownType.Ownership, offlinePlayer);
} else if (islandMembersOnline.size() == 2) {
for (UUID islandMembersOnlineList : islandMembersOnline) {
if (!islandMembersOnlineList.equals(player.getUniqueId())) {
Player targetPlayer = Bukkit.getServer().getPlayer(islandMembersOnlineList);
PlayerData targetPlayerData = playerDataManager.getPlayerData(targetPlayer);
cooldownManager.setCooldownPlayer(CooldownType.Ownership, offlinePlayer);
cooldownManager.removeCooldownPlayer(CooldownType.Ownership, offlinePlayer);
} else if (islandMembersOnline.size() == 2) {
for (UUID islandMembersOnlineList : islandMembersOnline) {
if (!islandMembersOnlineList.equals(player.getUniqueId())) {
Player targetPlayer = Bukkit.getServer().getPlayer(islandMembersOnlineList);
PlayerData targetPlayerData = playerDataManager.getPlayerData(targetPlayer);
if (targetPlayerData.isChat()) {
targetPlayerData.setChat(false);
messageManager.sendMessage(targetPlayer,
skyblock.getFileManager()
.getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Chat.Untoggled.Message"));
if (targetPlayerData.isChat()) {
targetPlayerData.setChat(false);
messageManager.sendMessage(targetPlayer,
skyblock.getFileManager()
.getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Chat.Untoggled.Message"));
}
}
}
}
final Island is = island;
Bukkit.getScheduler().scheduleSyncDelayedTask(skyblock, () -> islandManager.unloadIsland(is, player));
}
islandManager.unloadIsland(island, player);
}
cooldownManager.setCooldownPlayer(CooldownType.Biome, player);
cooldownManager.removeCooldownPlayer(CooldownType.Biome, player);
cooldownManager.setCooldownPlayer(CooldownType.Biome, player);
cooldownManager.removeCooldownPlayer(CooldownType.Biome, player);
cooldownManager.setCooldownPlayer(CooldownType.Creation, player);
cooldownManager.removeCooldownPlayer(CooldownType.Creation, player);
cooldownManager.setCooldownPlayer(CooldownType.Creation, player);
cooldownManager.removeCooldownPlayer(CooldownType.Creation, player);
playerDataManager.savePlayerData(player);
playerDataManager.unloadPlayerData(player);
playerDataManager.savePlayerData(player);
playerDataManager.unloadPlayerData(player);
if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
.getBoolean("Island.Coop.Unload")) {
for (Island islandList : islandManager.getCoopIslands(player)) {
islandList.removeCoopPlayer(player.getUniqueId());
}
}
if (playerData != null && playerData.getIsland() != null && islandManager.containsIsland(playerData.getIsland())) {
island = islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(playerData.getIsland()));
if (!island.hasRole(IslandRole.Member, player.getUniqueId())
&& !island.hasRole(IslandRole.Operator, player.getUniqueId())
&& !island.hasRole(IslandRole.Owner, player.getUniqueId())) {
islandManager.unloadIsland(island, null);
}
}
if (inviteManager.hasInvite(player.getUniqueId())) {
Invite invite = inviteManager.getInvite(player.getUniqueId());
Player targetPlayer = Bukkit.getServer().getPlayer(invite.getOwnerUUID());
if (targetPlayer != null) {
messageManager.sendMessage(targetPlayer,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration()
.getString("Command.Island.Invite.Invited.Sender.Disconnected.Message")
.replace("%player", player.getName()));
skyblock.getSoundManager().playSound(targetPlayer, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
.getBoolean("Island.Coop.Unload")) {
for (Island islandList : islandManager.getCoopIslands(player)) {
islandList.removeCoopPlayer(player.getUniqueId());
}
}
inviteManager.removeInvite(player.getUniqueId());
}
if (playerData != null && playerData.getIsland() != null && islandManager.containsIsland(playerData.getIsland())) {
island = islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(playerData.getIsland()));
if (!island.hasRole(IslandRole.Member, player.getUniqueId())
&& !island.hasRole(IslandRole.Operator, player.getUniqueId())
&& !island.hasRole(IslandRole.Owner, player.getUniqueId())) {
final Island is = island;
Bukkit.getScheduler().scheduleSyncDelayedTask(skyblock, () -> islandManager.unloadIsland(is, null));
}
}
if (inviteManager.hasInvite(player.getUniqueId())) {
Invite invite = inviteManager.getInvite(player.getUniqueId());
Player targetPlayer = Bukkit.getServer().getPlayer(invite.getOwnerUUID());
if (targetPlayer != null) {
messageManager.sendMessage(targetPlayer,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration()
.getString("Command.Island.Invite.Invited.Sender.Disconnected.Message")
.replace("%player", player.getName()));
skyblock.getSoundManager().playSound(targetPlayer, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
}
inviteManager.removeInvite(player.getUniqueId());
}
});
}
}

View File

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

View File

@ -48,10 +48,10 @@ public final class LocationUtil {
return false;
}
double x = Math.abs(location1.getX() - location2.getX()) - 1;
double z = Math.abs(location1.getZ() - location2.getZ()) - 1;
double x = Math.abs(location1.getX() - location2.getX());
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) {