mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-22 18:26:08 +01:00
Fix issues with island size and worldborder
This commit is contained in:
parent
ed6a16e65f
commit
28a6bbe7ef
@ -66,10 +66,6 @@ public class Island {
|
||||
if (this.size > 1000) {
|
||||
this.size = 50;
|
||||
}
|
||||
|
||||
if(this.size % 2 != 0) {
|
||||
this.size += 1;
|
||||
}
|
||||
|
||||
if (player.isOnline()) {
|
||||
int customSize = PlayerUtils.getNumberFromPermission(player.getPlayer(), "fabledskyblock.size", 0);
|
||||
@ -336,7 +332,7 @@ public class Island {
|
||||
if (size > 1000 || size < 0) {
|
||||
size = 50;
|
||||
}
|
||||
|
||||
|
||||
this.size = size;
|
||||
plugin.getFileManager().getConfig(
|
||||
new File(new File(plugin.getDataFolder().toString() + "/island-data"), ownerUUID.toString() + ".yml"))
|
||||
@ -344,7 +340,7 @@ public class Island {
|
||||
}
|
||||
|
||||
public double getRadius() {
|
||||
return (size / 2d) + 0.5d;
|
||||
return (((size%2==0) ? size : (size-1d)) / 2d);
|
||||
}
|
||||
|
||||
public boolean hasPassword() {
|
||||
@ -457,15 +453,11 @@ public class Island {
|
||||
|
||||
Location islandLocation = getLocation(worldManager.getIslandWorld(blockLocation.getWorld()), IslandEnvironment.Island);
|
||||
double halfSize = Math.floor(getRadius());
|
||||
|
||||
if (blockLocation.getBlockX() > (islandLocation.getBlockX() + halfSize)
|
||||
|| blockLocation.getBlockX() < (islandLocation.getBlockX() - halfSize - 1)
|
||||
|| blockLocation.getBlockZ() > (islandLocation.getBlockZ() + halfSize)
|
||||
|| blockLocation.getBlockZ() < (islandLocation.getBlockZ() - halfSize - 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
return !(blockLocation.getBlockX() > (islandLocation.getBlockX() + halfSize))
|
||||
&& !(blockLocation.getBlockX() < (islandLocation.getBlockX() - halfSize - 1))
|
||||
&& !(blockLocation.getBlockZ() > (islandLocation.getBlockZ() + halfSize))
|
||||
&& !(blockLocation.getBlockZ() < (islandLocation.getBlockZ() - halfSize - 1));
|
||||
}
|
||||
|
||||
public Biome getBiome() {
|
||||
|
@ -7,6 +7,7 @@ import com.google.common.base.Preconditions;
|
||||
import com.songoda.core.compatibility.CompatibleBiome;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.skyblock.SkyBlock;
|
||||
import com.songoda.skyblock.api.event.island.*;
|
||||
import com.songoda.skyblock.ban.BanManager;
|
||||
@ -63,10 +64,10 @@ public class IslandManager {
|
||||
|
||||
private final SkyBlock plugin;
|
||||
|
||||
private List<IslandPosition> islandPositions = new ArrayList<>();
|
||||
private Map<UUID, UUID> islandProxies = new HashMap<>();
|
||||
private Map<UUID, Island> islandStorage = new HashMap<>();
|
||||
private int offset;
|
||||
private final List<IslandPosition> islandPositions = new ArrayList<>();
|
||||
private final Map<UUID, UUID> islandProxies = new HashMap<>();
|
||||
private final Map<UUID, Island> islandStorage = new HashMap<>();
|
||||
private final int offset;
|
||||
|
||||
private HashMap<IslandWorld, Integer> oldSystemIslands;
|
||||
|
||||
@ -813,7 +814,7 @@ public class IslandManager {
|
||||
|
||||
Location islandLocation = fileManager.getLocation(config, "Location.Normal.Island", false);
|
||||
|
||||
if (LocationUtil.isLocationAtLocationRadius(location, islandLocation, size)) {
|
||||
if (LocationUtil.isLocationInLocationRadius(location, islandLocation, size)) {
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -1395,9 +1396,13 @@ public class IslandManager {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double increment = island.getSize() % 2 != 0 ? 0.5d : 0.0d;
|
||||
|
||||
if (configLoad.getBoolean("Island.WorldBorder.Enable") && island.isBorder()) {
|
||||
WorldBorder.send(player, island.getBorderColor(), island.getSize(), island.getLocation(worldManager.getIslandWorld(player.getWorld()), IslandEnvironment.Island));
|
||||
WorldBorder.send(player, island.getBorderColor(), island.getSize(),
|
||||
island.getLocation(worldManager.getIslandWorld(player.getWorld()),
|
||||
IslandEnvironment.Island).clone().add(increment, 0, increment));
|
||||
} else {
|
||||
WorldBorder.send(player, null, 1.4999992E7D, new org.bukkit.Location(player.getWorld(), 0, 0, 0));
|
||||
}
|
||||
@ -1534,29 +1539,25 @@ public class IslandManager {
|
||||
|
||||
if (island.isBorder()) {
|
||||
if (plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.WorldBorder.Enable")) {
|
||||
double increment = island.getSize() % 2 != 0 ? 0.5d : 0.0d;
|
||||
|
||||
for (IslandWorld worldList : IslandWorld.getIslandWorlds()) {
|
||||
if (worldList == IslandWorld.Nether) {
|
||||
if (NMSUtil.getVersionNumber() < 13) {
|
||||
continue;
|
||||
if (worldList != IslandWorld.Nether || ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
||||
for (Player all : getPlayersAtIsland(island)) {
|
||||
WorldBorder.send(all, island.getBorderColor(), island.getSize(), island.getLocation(worldManager.getIslandWorld(all.getWorld()), IslandEnvironment.Island).clone().add(increment, 0, increment));
|
||||
}
|
||||
}
|
||||
|
||||
for (Player all : getPlayersAtIsland(island)) {
|
||||
WorldBorder.send(all, island.getBorderColor(), island.getSize(), island.getLocation(worldManager.getIslandWorld(all.getWorld()), IslandEnvironment.Island));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (IslandWorld worldList : IslandWorld.getIslandWorlds()) {
|
||||
if (worldList == IslandWorld.Nether) {
|
||||
if (NMSUtil.getVersionNumber() < 13) {
|
||||
continue;
|
||||
if (worldList != IslandWorld.Nether || ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
||||
for (Player all : getPlayersAtIsland(island)) {
|
||||
WorldBorder.send(all, null, 1.4999992E7D, new Location(all.getWorld(), 0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
for (Player all : getPlayersAtIsland(island)) {
|
||||
WorldBorder.send(all, null, 1.4999992E7D, new org.bukkit.Location(all.getWorld(), 0, 0, 0));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1623,9 +1624,14 @@ public class IslandManager {
|
||||
|
||||
public boolean isLocationAtIsland(Island island, org.bukkit.Location location, IslandWorld world) {
|
||||
Location islandLocation = island.getLocation(world, IslandEnvironment.Island);
|
||||
if (islandLocation == null) return false;
|
||||
|
||||
return LocationUtil.isLocationAtLocationRadius(location.clone().add(0.5, 0, 0.5), islandLocation, island.getRadius() + 1);
|
||||
if (islandLocation != null && location.getWorld().equals(islandLocation.getWorld())) {
|
||||
double locIncrement = island.getSize() % 2d != 0d ? 0.50d + Double.MIN_VALUE : -Double.MIN_VALUE;
|
||||
return LocationUtil.isLocationInLocationRadius(
|
||||
islandLocation.clone().add(locIncrement, 0d, locIncrement),
|
||||
location.toCenterLocation(),
|
||||
island.getRadius() + Math.round(locIncrement));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Island getIslandByPlayer(org.bukkit.OfflinePlayer player) {
|
||||
|
@ -145,7 +145,9 @@ public class Interact implements Listener {
|
||||
StackableManager stackableManager = plugin.getStackableManager();
|
||||
IslandLevelManager levellingManager = plugin.getLevellingManager();
|
||||
|
||||
Island island = islandManager.getIslandAtLocation(player.getLocation());
|
||||
Island island = (block != null) ?
|
||||
islandManager.getIslandAtLocation(block.getLocation()) :
|
||||
islandManager.getIslandAtLocation(player.getLocation());
|
||||
if (island == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
@ -149,7 +149,7 @@ public class Move implements Listener {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!LocationUtil.isLocationAtLocationRadius(island.getLocation(world, IslandEnvironment.Island), to, island.getRadius())) {
|
||||
if(!islandManager.isLocationAtIsland(island, to)) {
|
||||
teleportPlayerToIslandSpawn(player, world, island);
|
||||
Config config = fileManager.getConfig(new File(plugin.getDataFolder(), "config.yml"));
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
|
@ -232,7 +232,7 @@ public class PlayerDataManager {
|
||||
Visit visit = visitIslands.get(visitIslandList);
|
||||
IslandLocation location = visit.getLocation(world);
|
||||
|
||||
if (location != null && LocationUtil.isLocationAtLocationRadius(player.getLocation(), location.getLocation(), visit.getRadius())) {
|
||||
if (location != null && LocationUtil.isLocationInLocationRadius(player.getLocation(), location.getLocation(), visit.getRadius())) {
|
||||
Player targetPlayer = Bukkit.getServer().getPlayer(visitIslandList);
|
||||
String targetPlayerName;
|
||||
|
||||
|
@ -148,16 +148,15 @@ public final class LocationUtil {
|
||||
|| isLocationLocation(location2.subtract(0, 1, 0), location1);
|
||||
}
|
||||
|
||||
public static boolean isLocationAtLocationRadius(Location location1, Location location2, double radius) {
|
||||
public static boolean isLocationInLocationRadius(Location location1, Location location2, double radius) {
|
||||
if (location1 == null || location2 == null || location1.getWorld() == null || location2.getWorld() == null
|
||||
|| !location1.getWorld().getName().equals(location2.getWorld().getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -10,39 +10,38 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class WorldBorder {
|
||||
|
||||
private static Class<?> packetPlayOutWorldBorder, packetPlayOutWorldBorderEnumClass, worldBorderClass,
|
||||
craftWorldClass;
|
||||
|
||||
private static Class<?> packetPlayOutWorldBorderEnumClass;
|
||||
private static Class<?> worldBorderClass;
|
||||
private static Class<?> craftWorldClass;
|
||||
private static Constructor<?> packetPlayOutWorldBorderConstructor;
|
||||
|
||||
static {
|
||||
try {
|
||||
packetPlayOutWorldBorder = NMSUtil.getNMSClass("PacketPlayOutWorldBorder");
|
||||
Class<?> packetPlayOutWorldBorder = NMSUtil.getNMSClass("PacketPlayOutWorldBorder");
|
||||
|
||||
if (NMSUtil.getVersionNumber() > 10) {
|
||||
packetPlayOutWorldBorderEnumClass = packetPlayOutWorldBorder.getDeclaredClasses()[0];
|
||||
} else {
|
||||
packetPlayOutWorldBorderEnumClass = packetPlayOutWorldBorder.getDeclaredClasses()[1];
|
||||
if(packetPlayOutWorldBorder != null) {
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) {
|
||||
packetPlayOutWorldBorderEnumClass = packetPlayOutWorldBorder.getDeclaredClasses()[0];
|
||||
} else {
|
||||
packetPlayOutWorldBorderEnumClass = packetPlayOutWorldBorder.getDeclaredClasses()[1];
|
||||
}
|
||||
|
||||
worldBorderClass = NMSUtil.getNMSClass("WorldBorder");
|
||||
craftWorldClass = NMSUtil.getCraftClass("CraftWorld");
|
||||
|
||||
packetPlayOutWorldBorderConstructor = packetPlayOutWorldBorder.getConstructor(worldBorderClass,
|
||||
packetPlayOutWorldBorderEnumClass);
|
||||
}
|
||||
|
||||
worldBorderClass = NMSUtil.getNMSClass("WorldBorder");
|
||||
craftWorldClass = NMSUtil.getCraftClass("CraftWorld");
|
||||
|
||||
packetPlayOutWorldBorderConstructor = packetPlayOutWorldBorder.getConstructor(worldBorderClass,
|
||||
packetPlayOutWorldBorderEnumClass);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void send(Player player, Color color, double size, Location centerLocation) {
|
||||
size +=2;
|
||||
try {
|
||||
if (centerLocation == null || centerLocation.getWorld() == null)
|
||||
return;
|
||||
|
||||
if (size % 2 == 1)
|
||||
size++;
|
||||
|
||||
Object worldBorder = worldBorderClass.getConstructor().newInstance();
|
||||
|
||||
@ -54,13 +53,16 @@ public final class WorldBorder {
|
||||
}
|
||||
|
||||
Method setCenter = worldBorder.getClass().getMethod("setCenter", double.class, double.class);
|
||||
setCenter.invoke(worldBorder, centerLocation.getBlockX(), centerLocation.getBlockZ());
|
||||
setCenter.invoke(worldBorder, centerLocation.getX(), centerLocation.getZ());
|
||||
|
||||
Method setSize = worldBorder.getClass().getMethod("setSize", double.class);
|
||||
setSize.invoke(worldBorder, size);
|
||||
|
||||
Method setWarningTime = worldBorder.getClass().getMethod("setWarningTime", int.class);
|
||||
setWarningTime.invoke(worldBorder, 0);
|
||||
|
||||
Method setWarningDistance = worldBorder.getClass().getMethod("setWarningDistance", int.class);
|
||||
setWarningDistance.invoke(worldBorder, 0);
|
||||
|
||||
Method transitionSizeBetween = worldBorder.getClass().getMethod("transitionSizeBetween", double.class,
|
||||
double.class, long.class);
|
||||
|
@ -19,12 +19,11 @@ Island:
|
||||
ChunkPerTick: 15
|
||||
Size:
|
||||
# Warning: The maximum is capped at 1000
|
||||
# Warning: Only even numbers are accepted
|
||||
# Warning: Do not go over the maximum
|
||||
# The size of an Island when created
|
||||
Minimum: 100
|
||||
Minimum: 51
|
||||
# The maximum size of an Island based on the permission node 'fabledskyblock.size.<size>'.
|
||||
Maximum: 200
|
||||
Maximum: 1000
|
||||
Creation:
|
||||
# Rather than opening the 'Island Creator' menu. Create an island
|
||||
# as soon as a player performs the '/island' or '/island create'
|
||||
|
Loading…
Reference in New Issue
Block a user