Skip to content

Commit

Permalink
Changed deleteIsland algorithm to work better with large island
Browse files Browse the repository at this point in the history
distances.
  • Loading branch information
tastybento committed Oct 1, 2014
1 parent bc8a734 commit 01a5496
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 24 deletions.
23 changes: 23 additions & 0 deletions acidIsland/src/com/wasteofplastic/askyblock/ASkyBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,16 @@ public Location getSafeHomeLocation(final UUID p) {
// Try the default location
Location dl = new Location(l.getWorld(), l.getX() + 0.5D, l.getY() + 5D, l.getZ() + 2.5D, 0F, 30F);
if (isSafeLocation(dl)) {
players.setHomeLocation(p, dl);
return dl;
}
// Try just above the bedrock
dl = new Location(l.getWorld(), l.getX(), l.getY() + 5D, l.getZ(), 0F, 30F);
if (isSafeLocation(dl)) {
players.setHomeLocation(p, dl);
return dl;
}

// Try higher up - 25 blocks high and then move down
for (int y = l.getBlockY() + 25; y > 0; y--) {
final Location n = new Location(l.getWorld(), l.getBlockX(), y, l.getBlockZ());
Expand All @@ -338,6 +346,21 @@ public Location getSafeHomeLocation(final UUID p) {
return n;
}
}
// Try anywhere in the island area
// Start from up above and work down
for (int y = l.getWorld().getMaxHeight(); y>0; y--) {
for (int x = l.getBlockX() - Settings.islandDistance/2; x < l.getBlockX() + Settings.islandDistance/2; x++) {
for (int z = l.getBlockZ() - Settings.islandDistance/2; z < l.getBlockZ() + Settings.islandDistance/2; z++) {
Location ultimate = new Location(l.getWorld(),x,y,z);
if (!ultimate.getBlock().equals(Material.AIR)) {
if (isSafeLocation(ultimate)) {
players.setHomeLocation(p, ultimate);
return ultimate;
}
}
}
}
}
// Nothing worked
return null;
}
Expand Down
51 changes: 31 additions & 20 deletions acidIsland/src/com/wasteofplastic/askyblock/DeleteIsland.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ public DeleteIsland(ASkyBlock plugin, Location loc) {
private int checkVersion() throws ClassNotFoundException, IllegalArgumentException,
SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException,
NoSuchMethodException {
int slice = 255;
// Calculate how many slices we should take without killing the server
int slice = (int)Math.floor(255D * ((double)10000/(Settings.islandDistance*Settings.islandDistance)));
if (slice < 10) {
slice = 10;
}
String serverPackageName = plugin.getServer().getClass().getPackage().getName();
String pluginPackageName = plugin.getClass().getPackage().getName();
String version = serverPackageName.substring(serverPackageName.lastIndexOf('.') + 1);
Expand All @@ -86,10 +90,14 @@ private int checkVersion() throws ClassNotFoundException, IllegalArgumentExcepti
} catch (Exception e) {
plugin.getLogger().info("No NMS Handler found, falling back to slow island delete.");
clazz = Class.forName(pluginPackageName + ".fallback.NMSHandler");
slice = 51;
slice = (int)Math.floor(51D * ((double)10000/(Settings.islandDistance*Settings.islandDistance)));
if (slice < 10) {
slice = 10;
}
}
//plugin.getLogger().info(serverPackageName);
//plugin.getLogger().info(pluginPackageName);
//plugin.getLogger().info("Slice is = " + slice);
plugin.getLogger().info(serverPackageName);
plugin.getLogger().info(pluginPackageName);
// Check if we have a NMSAbstraction implementing class at that location.
if (NMSAbstraction.class.isAssignableFrom(clazz)) {
nms = (NMSAbstraction) clazz.getConstructor().newInstance();
Expand Down Expand Up @@ -142,6 +150,11 @@ void removeSlice(int top, int bottom) {
chunks.add(chunkCoords);
}
final Material bt = b.getType();
Material setTo = Material.AIR;
// Split depending on below or above water line
if (y < Settings.sea_level) {
setTo = Material.STATIONARY_WATER;
}
// Grab anything out of containers (do that it is
// destroyed)
switch (bt) {
Expand All @@ -152,46 +165,44 @@ void removeSlice(int top, int bottom) {
final Chest c = (Chest) b.getState();
final ItemStack[] items = new ItemStack[c.getInventory().getContents().length];
c.getInventory().setContents(items);
b.setType(Material.AIR);
b.setType(setTo);
break;
case FURNACE:
final Furnace f = (Furnace) b.getState();
final ItemStack[] i2 = new ItemStack[f.getInventory().getContents().length];
f.getInventory().setContents(i2);
b.setType(Material.AIR);
b.setType(setTo);
break;
case DISPENSER:
final Dispenser d = (Dispenser) b.getState();
final ItemStack[] i3 = new ItemStack[d.getInventory().getContents().length];
d.getInventory().setContents(i3);
b.setType(Material.AIR);
b.setType(setTo);
break;
case HOPPER:
final Hopper h = (Hopper) b.getState();
final ItemStack[] i4 = new ItemStack[h.getInventory().getContents().length];
h.getInventory().setContents(i4);
b.setType(Material.AIR);
b.setType(setTo);
break;
case SIGN_POST:
case WALL_SIGN:
case SIGN:
//getLogger().info("DEBUG: Sign");
b.setType(Material.AIR);
b.setType(setTo);
break;
case AIR:
if (setTo.equals(Material.STATIONARY_WATER)) {
nms.setBlockSuperFast(b, setTo);
}
case STATIONARY_WATER:
if (setTo.equals(Material.AIR)) {
nms.setBlockSuperFast(b, setTo);
}
default:
nms.setBlockSuperFast(b, setTo);
break;
}
// Split depending on below or above water line
if (y < Settings.sea_level) {
if (!bt.equals(Material.STATIONARY_WATER))
nms.setBlockSuperFast(b, Material.STATIONARY_WATER);
//b.setType(Material.STATIONARY_WATER);
} else {
if (!bt.equals(Material.AIR))
nms.setBlockSuperFast(b, Material.AIR);
//b.setType(Material.AIR);
}

}
}
}
Expand Down
5 changes: 2 additions & 3 deletions acidIsland/src/com/wasteofplastic/askyblock/IslandCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Calendar;
Expand All @@ -45,7 +44,6 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
Expand Down Expand Up @@ -755,6 +753,7 @@ public void run() {
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable () {
@Override
public void run() {
//plugin.homeTeleport(player);
player.getWorld().spawnEntity(cowSpot, EntityType.COW);

}
Expand All @@ -765,7 +764,7 @@ public void run() {
if (oldIsland != null) {
plugin.removeIsland(oldIsland);
DeleteIsland deleteIsland = new DeleteIsland(plugin,oldIsland);
deleteIsland.runTaskTimer(plugin, 40L, 40L);
deleteIsland.runTaskTimer(plugin, 80L, 40L);
}
plugin.restartEvents();
} else {
Expand Down
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ commands:
asadmin:
description: Admin commands
usage: |
/acid
/asadmin
asc:
description: Game challenges
aliases: [c, challenge, aschallenge]
Expand Down

0 comments on commit 01a5496

Please sign in to comment.