Removing obsolete Nether portal code.

If you want more control over the worlds, I recommend using Multiverse.
/world command still exists, it can be used to switch between worlds. The default ratio of 8 is used for nether.
This commit is contained in:
snowleo 2011-10-04 21:58:47 +02:00
parent 65a78a6ea9
commit 11d22f95cc
8 changed files with 23 additions and 400 deletions

View File

@ -201,11 +201,6 @@ public class Essentials extends JavaPlugin implements IEssentials
pm.registerEvent(Type.PLAYER_TELEPORT, jailPlayerListener, Priority.High, this);
pm.registerEvent(Type.PLAYER_JOIN, jailPlayerListener, Priority.High, this);
if (settings.isNetherEnabled() && getServer().getWorlds().size() < 2)
{
getServer().createWorld(settings.getNetherName(), World.Environment.NETHER);
}
pm.registerEvent(Type.ENTITY_EXPLODE, tntListener, Priority.High, this);
final EssentialsTimer timer = new EssentialsTimer(this);

View File

@ -100,114 +100,11 @@ public class EssentialsPlayerListener extends PlayerListener
return;
}
Location afk = user.getAfkPosition();
final Location afk = user.getAfkPosition();
if (afk == null || !event.getTo().getWorld().equals(afk.getWorld()) || afk.distanceSquared(event.getTo()) > 9)
{
user.updateActivity(true);
}
if (!ess.getSettings().getNetherPortalsEnabled())
{
return;
}
final Block block = event.getPlayer().getWorld().getBlockAt(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
final List<World> worlds = server.getWorlds();
if (block.getType() == Material.PORTAL && worlds.size() > 1 && user.isAuthorized("essentials.portal"))
{
if (user.getJustPortaled())
{
return;
}
World nether = server.getWorld(ess.getSettings().getNetherName());
if (nether == null)
{
for (World world : worlds)
{
if (world.getEnvironment() == World.Environment.NETHER)
{
nether = world;
break;
}
}
if (nether == null)
{
return;
}
}
final World world = user.getWorld() == nether ? worlds.get(0) : nether;
double factor;
if (user.getWorld().getEnvironment() == World.Environment.NETHER && world.getEnvironment() == World.Environment.NORMAL)
{
factor = ess.getSettings().getNetherRatio();
}
else if (user.getWorld().getEnvironment() == World.Environment.NORMAL && world.getEnvironment() == World.Environment.NETHER)
{
factor = 1.0 / ess.getSettings().getNetherRatio();
}
else
{
factor = 1.0;
}
Location loc = event.getTo();
int x = loc.getBlockX();
int y = loc.getBlockY();
int z = loc.getBlockZ();
if (user.getWorld().getBlockAt(x, y, z - 1).getType() == Material.PORTAL)
{
z--;
}
if (user.getWorld().getBlockAt(x - 1, y, z).getType() == Material.PORTAL)
{
x--;
}
x = (int)(x * factor);
z = (int)(z * factor);
loc = new Location(world, x + .5, y, z + .5);
Block dest = world.getBlockAt(x, y, z);
NetherPortal portal = NetherPortal.findPortal(dest);
if (portal == null)
{
if (world.getEnvironment() == World.Environment.NETHER || ess.getSettings().getGenerateExitPortals())
{
portal = NetherPortal.createPortal(dest);
LOGGER.info(Util.format("userCreatedPortal", event.getPlayer().getName()));
user.sendMessage(Util.i18n("generatingPortal"));
loc = portal.getSpawn();
}
}
else
{
LOGGER.info(Util.format("userUsedPortal", event.getPlayer().getName()));
user.sendMessage(Util.i18n("usingPortal"));
loc = portal.getSpawn();
}
event.setFrom(loc);
event.setTo(loc);
try
{
user.getTeleport().now(loc, new Trade("portal", ess));
}
catch (Exception ex)
{
user.sendMessage(ex.getMessage());
}
user.setJustPortaled(true);
user.sendMessage(Util.i18n("teleportingPortal"));
event.setCancelled(true);
return;
}
user.setJustPortaled(false);
}
@Override

View File

@ -35,8 +35,6 @@ public interface ISettings extends IConf
int getDefaultStackSize();
boolean getGenerateExitPortals();
double getHealCooldown();
Object getKit(String name);
@ -45,12 +43,6 @@ public interface ISettings extends IConf
String getLocale();
String getNetherName();
boolean getNetherPortalsEnabled();
double getNetherRatio();
String getNewbieSpawn();
String getNicknamePrefix();
@ -105,8 +97,6 @@ public interface ISettings extends IConf
boolean isEcoDisabled();
boolean isNetherEnabled();
boolean isTradeInStacks(int id);
List<Integer> itemSpawnBlacklist();
@ -117,8 +107,6 @@ public interface ISettings extends IConf
boolean spawnIfNoHome();
boolean use1to1RatioInNether();
boolean warnOnBuildDisallow();
boolean warnOnSmite();

View File

@ -1,167 +0,0 @@
/**
* @author SpaceManiac
* @licent MIT
* @origin https://github.com/SpaceManiac/Nether/blob/master/org/innectis/Nether/NetherPortal.java
*/
package com.earth2me.essentials;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.Location;
import org.bukkit.Material;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
public class NetherPortal
{
private Block block;
public NetherPortal(Block b)
{
block = b;
}
public Block getBlock()
{
return block;
}
public void setBlock(Block b)
{
block = b;
}
// Return a random spawnable location
public Location getSpawn()
{
if (block.getWorld().getBlockAt(block.getX() + 1, block.getY(), block.getZ()).getType().equals(Material.PORTAL)
|| block.getWorld().getBlockAt(block.getX() - 1, block.getY(), block.getZ()).getType().equals(Material.PORTAL))
{
// portal is in X direction
return new Location(block.getWorld(), block.getX() + 1,
block.getY(), block.getZ() + 1 - 2 * Math.round(Math.random()));
}
else
{
// portal is in Z direction
return new Location(block.getWorld(), block.getX() + 1 - 2 * Math.round(Math.random()),
block.getY(), block.getZ() + 1);
}
}
// ==============================
// Find a nearby portal within 16 blocks of the given block
// Not guaranteed to be the nearest
public static NetherPortal findPortal(Block dest)
{
World world = dest.getWorld();
// Get list of columns in a circle around the block
ArrayList<Block> columns = new ArrayList<Block>();
for (int x = dest.getX() - 16; x <= dest.getX() + 16; ++x)
{
for (int z = dest.getZ() - 16; z <= dest.getZ() + 16; ++z)
{
int dx = dest.getX() - x, dz = dest.getZ() - z;
if (dx * dx + dz * dz <= 256)
{
columns.add(world.getBlockAt(x, 0, z));
}
}
}
// For each column try to find a portal block
for (Block col : columns)
{
for (int y = 127; y >= 0; --y)
{
Block b = world.getBlockAt(col.getX(), y, col.getZ());
if (b.getType().equals(Material.PORTAL) && Math.abs(dest.getY() - y) <= 16)
{
// Huzzah!
return new NetherPortal(b);
}
}
}
// Nope!
return null;
}
// Create a new portal at the specified block, fudging position if needed
// Will occasionally end up making portals in bad places, but let's hope not
public static NetherPortal createPortal(Block dest)
{
World world = dest.getWorld();
// Try not to spawn within water or lava
Material m = dest.getType();
while (((m.equals(Material.LAVA) || m.equals(Material.WATER) || m.equals(Material.STATIONARY_LAVA)
|| m.equals(Material.STATIONARY_WATER) || m.equals(Material.SAND) || m.equals(Material.GRAVEL))) &&
dest.getY() < 120)
{
dest = world.getBlockAt(dest.getX(), dest.getY() + 4, dest.getZ());
m = dest.getType();
}
// Not too high or too low overall
if (dest.getY() > 120)
{
dest = world.getBlockAt(dest.getX(), 120, dest.getZ());
}
else if (dest.getY() < 8)
{
dest = world.getBlockAt(dest.getX(), 8, dest.getZ());
}
// Create the physical portal
// For now, don't worry about direction
int x = dest.getX(), y = dest.getY(), z = dest.getZ();
Logger.getLogger("Minecraft").log(Level.INFO, Util.format("creatingPortal", x, y, z));
// Clear area around portal
ArrayList<Block> columns = new ArrayList<Block>();
for (int x2 = x - 4; x2 <= x + 4; ++x2)
{
for (int z2 = z - 4; z2 <= z + 4; ++z2)
{
double dx = x + 0.5f - x2, dz = z - z2;
if (dx * dx + dz * dz <= 13)
{
columns.add(world.getBlockAt(x2, 0, z2));
}
}
}
// Clear area around portal
for (Block col : columns)
{
// Stone platform
world.getBlockAt(col.getX(), y - 1, col.getZ()).setType(Material.STONE);
for (int yd = 0; yd < 4; ++yd)
{
world.getBlockAt(col.getX(), y + yd, col.getZ()).setType(Material.AIR);
}
}
// Build obsidian frame
for (int xd = -1; xd < 3; ++xd)
{
for (int yd = -1; yd < 4; ++yd)
{
if (xd == -1 || yd == -1 || xd == 2 || yd == 3)
{
world.getBlockAt(x + xd, y + yd, z).setType(Material.OBSIDIAN);
}
}
}
// Set it alight!
dest.setType(Material.FIRE);
return new NetherPortal(dest);
}
}

View File

@ -95,12 +95,6 @@ public class Settings implements ISettings
return config.getInt("starting-balance", 0);
}
@Override
public boolean getNetherPortalsEnabled()
{
return isNetherEnabled() && config.getBoolean("nether.portals-enabled", false);
}
@Override
public boolean isCommandDisabled(final IEssentialsCommand cmd)
{
@ -257,18 +251,6 @@ public class Settings implements ISettings
return config.getBoolean("reclaim-onlogout", true);
}
@Override
public String getNetherName()
{
return config.getString("nether.folder", "nether");
}
@Override
public boolean isNetherEnabled()
{
return config.getBoolean("nether.enabled", false);
}
@Override
public int getSpawnMobLimit()
{
@ -318,12 +300,6 @@ public class Settings implements ISettings
config.getString("chat.format", "&7[{GROUP}]&f {DISPLAYNAME}&7:&f {MESSAGE}"));
}
@Override
public boolean getGenerateExitPortals()
{
return config.getBoolean("nether.generate-exit-portals", true);
}
@Override
public boolean getAnnounceNewPlayers()
{
@ -403,22 +379,6 @@ public class Settings implements ISettings
return config.getBoolean("protect.disable.warn-on-build-disallow", false);
}
@Override
public boolean use1to1RatioInNether()
{
return config.getBoolean("nether.use-1to1-ratio", false);
}
@Override
public double getNetherRatio()
{
if (config.getBoolean("nether.use-1to1-ratio", false))
{
return 1.0;
}
return config.getDouble("nether.ratio", 8.0);
}
@Override
public boolean isDebug()
{

View File

@ -17,26 +17,28 @@ public class Commandworld extends EssentialsCommand
}
@Override
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
World world;
List<World> worlds = server.getWorlds();
if (args.length < 1)
{
World nether = server.getWorld(ess.getSettings().getNetherName());
if (nether == null) {
for (World world2 : worlds)
World nether = null;
final List<World> worlds = server.getWorlds();
for (World world2 : worlds)
{
if (world2.getEnvironment() == World.Environment.NETHER)
{
if (world2.getEnvironment() == World.Environment.NETHER) {
nether = world2;
break;
}
}
if (nether == null) {
return;
nether = world2;
break;
}
}
if (nether == null)
{
return;
}
world = user.getWorld() == nether ? worlds.get(0) : nether;
}
else
@ -54,23 +56,22 @@ public class Commandworld extends EssentialsCommand
double factor;
if (user.getWorld().getEnvironment() == World.Environment.NETHER && world.getEnvironment() == World.Environment.NORMAL)
{
factor = ess.getSettings().getNetherRatio();
factor = 8.0;
}
else if (user.getWorld().getEnvironment() != world.getEnvironment())
else if (user.getWorld().getEnvironment() == World.Environment.NORMAL && world.getEnvironment() == World.Environment.NETHER)
{
factor = 1.0 / ess.getSettings().getNetherRatio();
factor = 1.0 / 8.0;
}
else
{
else {
factor = 1.0;
}
Location loc = user.getLocation();
loc = new Location(world, loc.getBlockX() * factor + .5, loc.getBlockY(), loc.getBlockZ() * factor + .5);
final Location loc = user.getLocation();
final Location target = new Location(world, loc.getBlockX() * factor + .5, loc.getBlockY(), loc.getBlockZ() * factor + .5);
Trade charge = new Trade(this.getName(), ess);
final Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user);
user.getTeleport().teleport(loc, charge);
user.getTeleport().teleport(target, charge);
throw new NoChargeException();
}
}

View File

@ -79,12 +79,6 @@ reclaim-onlogout: false
# Should primitive spawn protection be enabled? For most servers, this should be flase; it is better to use a third-party plugin to protect it.
spawn-protection: false
# Nether settings
# Sets wether you want to change the default behaviour of the nether portals.
nether:
portals-enabled: false
generate-exit-portals: false
# Mob limit on spawnmob
spawnmob-limit: 10

View File

@ -1,45 +0,0 @@
package com.earth2me.essentials;
import junit.framework.TestCase;
public class EssentialsTest extends TestCase
{
public EssentialsTest(String testName)
{
super(testName);
}
private static void should(String what)
{
System.out.println("Essentials should " + what);
}
public void testLoadClasses()
{
should("make all classes accessible");
try
{
ItemDb itemDb = null;
Mob mob = null;
NetherPortal netherPortal = null;
OfflinePlayer offlinePlayer = null;
Settings settings = null;
Spawn spawn = null;
TargetBlock targetBlock = null;
User user = null;
assertNull(itemDb);
assertNull(mob);
assertNull(netherPortal);
assertNull(offlinePlayer);
assertNull(settings);
assertNull(spawn);
assertNull(targetBlock);
assertNull(user);
}
catch (Throwable ex)
{
fail(ex.toString());
}
}
}