Skip to content

Commit

Permalink
4.7.0: Neutral teleporting
Browse files Browse the repository at this point in the history
home command configuration and fixes
creation gui improvements
queue bug fix
fixed island generation bug (generation was totally  screwed, how no one noticed this before me lol)
  • Loading branch information
aleksilassila committed Oct 31, 2020
1 parent 59eb451 commit 454e495
Showing 11 changed files with 125 additions and 57 deletions.
6 changes: 6 additions & 0 deletions src/config.yml
Original file line number Diff line number Diff line change
@@ -33,6 +33,8 @@ generation:
generationDelayInTicks: 0.3 # 2 Will generate 1 row per 2 ticks, 0.5 will generate 2 rows per 1 tick.
maxVariationsPerBiome: 5 # Max locations generated for each biome, lower the value to speed up server startup.
clearSpeedMultiplier: 3 # Removing blocks should be faster than placing them, so you might swant to speed up clearing.
maxBiomeSize: 80 # Minimum width of biome block so that it gets picked up by the generator and added as available variation.
# Should be the same as the biggest island size being generated.

biomeBlacklist: # These biomes do not get picked up by island generator.
- DEEP_OCEAN # Ocean biomes work poorly with islands.
@@ -55,4 +57,8 @@ voidTeleport: true # If enabled, void kills again in island
islandDamage: false # Enable / disable damage on islands
restrictIslandBlockFlows: true # Let water / lava only flow inside a sphere containing island
disableWilderness: false # Disable wilderness, do not touch unless you know what you are doing
allowHomeOnlyFromOverworld: true # Disable /home in nether and end
disableNeutralTeleports: false # Disable teleporting neutrals to islands with /home command
neutralTeleportRange: 2 # How far neutrals are being teleported around the player
unfinishedIslandTeleports: true # Deny teleports to island that are still being generated.
locale: en
2 changes: 1 addition & 1 deletion src/me/aleksilassila/islands/GUIs/CreateGUI.java
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ private List<StaticPane> availableIslandPanes() {
BiomeMaterials.valueOf(biome.name()).getMaterial(),
Messages.get("gui.create.BIOME_NAME", biome.name()),
false,
Messages.get("gui.create.BIOME_LORE")
Messages.get("gui.create.BIOME_LORE", availableLocations.get(biome).size())
),
event -> {
getSizeGui(biome).show(event.getWhoClicked());
10 changes: 4 additions & 6 deletions src/me/aleksilassila/islands/Islands.java
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;
import me.aleksilassila.islands.commands.IslandCommands;
import me.aleksilassila.islands.commands.TeleportCommands;
import me.aleksilassila.islands.commands.IslandManagmentCommands;
import me.aleksilassila.islands.commands.TrustCommands;
import me.aleksilassila.islands.generation.IslandGeneration;
@@ -105,7 +105,7 @@ public void onEnable() {

new IslandManagmentCommands(this);

IslandCommands islandCommands = new IslandCommands(this);
TeleportCommands islandCommands = new TeleportCommands(this);

islandCommands.new HomeCommand();
islandCommands.new VisitCommand();
@@ -151,8 +151,7 @@ public String createNewIsland(Biome biome, int islandSize, Player player) throws
getIslandsConfig().getInt(islandId + ".z")
),
false,
0,
0,
islandId,
shape
);

@@ -191,8 +190,7 @@ public boolean recreateIsland(String islandId, Biome biome, int islandSize, Play
getIslandsConfig().getInt(islandId + ".z")
),
true,
getIslandsConfig().getInt(islandId + ".xIndex"),
getIslandsConfig().getInt(islandId + ".zIndex"),
islandId,
shape
);
} catch (IllegalArgumentException e) {
Original file line number Diff line number Diff line change
@@ -7,19 +7,24 @@
import me.aleksilassila.islands.utils.Permissions;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;

import java.util.Date;
import java.util.List;
import java.util.Optional;

public class IslandCommands {
public class TeleportCommands {
private final Islands plugin;
private final IslandLayout layout;

public IslandCommands(Islands plugin) {
public TeleportCommands(Islands plugin) {
this.plugin = plugin;
this.layout = plugin.layout;
}
@@ -70,9 +75,19 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

public class HomeCommand implements CommandExecutor {
private final boolean allowHomeOnlyFromOverworld;
private final boolean disableNeutralTeleports;
private final int neutralTeleportRange;
private final boolean unfinishedIslandTeleports;

public HomeCommand() {
plugin.getCommand("home").setExecutor(this);
plugin.getCommand("homes").setExecutor(this);

this.allowHomeOnlyFromOverworld = plugin.getConfig().getBoolean("allowHomeOnlyFromOverworld");
this.disableNeutralTeleports = plugin.getConfig().getBoolean("disableNeutralTeleports");
this.neutralTeleportRange = plugin.getConfig().getInt("neutralTeleportRange");
this.unfinishedIslandTeleports = plugin.getConfig().getBoolean("unfinishedIslandTeleports");
}

@Override
@@ -102,33 +117,34 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

return true;
} else {
if (!player.hasPermission(Permissions.command.home)) {
player.sendMessage(Messages.get("error.NO_PERMISSION"));
return true;
}
}

if (!canTeleport(player) && !player.hasPermission(Permissions.bypass.home)) {
player.sendMessage(Messages.get("error.COOLDOWN", teleportCooldown(player)));
return true;
}
if (!player.hasPermission(Permissions.command.home)) {
player.sendMessage(Messages.get("error.NO_PERMISSION"));
return true;
}

try {
if (args.length != 0) {
Integer.parseInt(args[0]);
}
} catch (NumberFormatException e) {
player.sendMessage(Messages.help.HOME);
return true;
if (!canTeleport(player) && !player.hasPermission(Permissions.bypass.home)) {
player.sendMessage(Messages.get("error.COOLDOWN", teleportCooldown(player)));
return true;
}

try {
if (args.length != 0) {
Integer.parseInt(args[0]);
}
} catch (NumberFormatException e) {
player.sendMessage(Messages.help.HOME);
return true;
}

if (player.getWorld().getName().equals("world_nether") && !player.hasPermission(Permissions.bypass.home)) {
if (allowHomeOnlyFromOverworld && !player.getWorld().getEnvironment().equals(World.Environment.NORMAL)
&& !player.hasPermission(Permissions.bypass.home)) {
player.sendMessage(Messages.get("info.IN_OVERWORLD"));
return true;
}

if (player.getWorld().getName().equals("world") && !player.hasPermission(Permissions.bypass.home)) {
if (!player.hasPermission(Permissions.bypass.home)) {
// Check if is on surface
Location playerLocation = player.getLocation();

@@ -149,9 +165,33 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
homeId = 1;
}

Location location = layout.getIslandSpawn(layout.getHomeIsland(player.getUniqueId(), homeId));
String islandId = layout.getHomeIsland(player.getUniqueId(), homeId);

if (plugin.islandGeneration.queue.size() > 0
&& plugin.islandGeneration.queue.get(0).getIslandId().equals(islandId)
&& !unfinishedIslandTeleports) {
Messages.send(player, "error.ISLAND_UNFINISHED");
return true;
}

if (plugin.islandGeneration.queue.size() != 0)
System.out.println("IslanId " + islandId + " and " + plugin.islandGeneration.queue.get(0).getIslandId());

Location location = layout.getIslandSpawn(islandId);

if (location != null) {
if (!disableNeutralTeleports && player.hasPermission(Permissions.bypass.neutralTeleport)) {
List<Entity> entities = player.getNearbyEntities(neutralTeleportRange, neutralTeleportRange, neutralTeleportRange);
entities.removeIf(entity -> entity instanceof Monster || !entity.getType().isAlive());

Location animalLocation = location.clone();
animalLocation.setY(plugin.islandsWorld.getHighestBlockYAt(location) + 1);

for (Entity entity : entities) {
entity.teleport(animalLocation);
}
}

player.teleport(location);
} else {
player.sendMessage(Messages.get("error.HOME_NOT_FOUND"));
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ public void onCommand(Player player, String[] args, boolean confirmed) {
return;
}

if (!plugin.islandGeneration.clearIsland(player, Integer.parseInt(islandId.split("x")[0]), Integer.parseInt(islandId.split("x")[1]))) {
if (!plugin.islandGeneration.clearIsland(player, islandId)) {
player.sendMessage(Messages.get("error.ONGOING_QUEUE_EVENT"));
return;
}
18 changes: 9 additions & 9 deletions src/me/aleksilassila/islands/generation/Biomes.java
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ public class Biomes {

public Biomes(Islands plugin, World world) {
this.world = world;
this.biggestIslandSize = plugin.getConfig().getInt("island.BIG");
this.biggestIslandSize = plugin.getConfig().getInt("generation.maxBiomeSize");
this.plugin = plugin;

this.biomeSearchJumpBlocks = plugin.getConfig().getInt("generation.searchJump");
@@ -72,7 +72,7 @@ private void loadBiomesFromConfig() {

private void generateAndSaveBiomes() {
plugin.clearBiomesCache();
this.availableLocations = generateIslandLocations(biggestIslandSize);
this.availableLocations = generateIslandLocations();

plugin.getBiomesCache().set("seed", String.valueOf(plugin.islandsSourceWorld.getSeed()));

@@ -118,17 +118,17 @@ private boolean isBlacklisted(Biome biome) {
}

@NotNull
public HashMap<Biome, List<Location>> generateIslandLocations(int maxIslandSize) {
public HashMap<Biome, List<Location>> generateIslandLocations() {
HashMap<Biome, List<Location>> locations = new HashMap<>();
List<int[]> usedPositions = new ArrayList<int[]>();

plugin.getLogger().info("Generating biomes...");

for (int x = 0; x < biomeSearchSize - maxIslandSize; x += biomeSearchJumpBlocks) {
zLoop: for (int z = 0; z < biomeSearchSize - maxIslandSize; z += biomeSearchJumpBlocks) {
for (int x = 0; x < biomeSearchSize - biggestIslandSize; x += biomeSearchJumpBlocks) {
zLoop: for (int z = 0; z < biomeSearchSize - biggestIslandSize; z += biomeSearchJumpBlocks) {
for (int[] pos : usedPositions) {
if (pos[0] <= x && x <= pos[0] + maxIslandSize && pos[1] <= z && z <= pos[1] + maxIslandSize) {
z += maxIslandSize;
if (pos[0] <= x && x <= pos[0] + biggestIslandSize && pos[1] <= z && z <= pos[1] + biggestIslandSize) {
z += biggestIslandSize;
continue zLoop;
}
}
@@ -140,7 +140,7 @@ public HashMap<Biome, List<Location>> generateIslandLocations(int maxIslandSize)
continue;
}

if (isSuitableLocation(x, z, maxIslandSize, biome)) {
if (isSuitableLocation(x, z, biggestIslandSize, biome)) {
Location location = new Location(world, x, 0, z);

if (locations.containsKey(biome)) {
@@ -152,7 +152,7 @@ public HashMap<Biome, List<Location>> generateIslandLocations(int maxIslandSize)
}

usedPositions.add(new int[]{x, z});
z += maxIslandSize;
z += biggestIslandSize;
}

}
Loading
Oops, something went wrong.

0 comments on commit 454e495

Please sign in to comment.