Fixed up the safe teleporting, now checks Y Properly and no longer

prioritises a higher coordinate over lower.
This commit is contained in:
Simon Rigby 2011-03-09 08:11:35 +00:00
parent 764b050baa
commit 438aa472d6
5 changed files with 31 additions and 14 deletions

View File

@ -3,6 +3,7 @@ package com.onarandombox.MultiVerseCore;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockRightClickEvent;
@ -22,8 +23,18 @@ public class MVBlockListener extends BlockListener {
}
public void onBlockFlow(BlockFromToEvent event){
public void onBlockPhysics(BlockPhysicsEvent event) {
if(event.isCancelled())
{
return;
}
int id = event.getChangedTypeId();
if (id == 90) { // && config.getBoolean("portalanywhere", false)
event.setCancelled(true);
return;
}
}
public void onBlockPlaced(BlockPlaceEvent event){

View File

@ -34,7 +34,7 @@ public class MVEntityListener extends EntityListener {
}
public void onExplosionPrimed(ExplosionPrimedEvent event){
if(event.getEntity() instanceof Fireball){
MultiVerseCore.log.info("Fireball");
//MultiVerseCore.log.info();
// Fireballs on Explode trigger this, sadly we can't get the blocks it would destroy... thats onEntityExplode
// However can't figure out a way to check in onEntityExplode if it was a Fireball which caused it...
}
@ -80,6 +80,8 @@ public class MVEntityListener extends EntityListener {
if(event.isCancelled()) return;
if(!(plugin.worlds.containsKey(world.getName()))) return; // Check if it's a world which we are meant to be managing.
//event.getEntity().getWorld().spawnCreature(arg0, arg1);
MVWorld mvworld = plugin.worlds.get(world.getName());
// TODO: Look of this and see if there's a cleaner/better method of doing so...

View File

@ -28,7 +28,7 @@ public class MVTeleport {
*/
public Location getDestination(World world, Player player, Location location) {
MultiVerseCore.log.info(player.getName() + " wants to go to " + world.getName() + ". He's now at " + player.getLocation().toString());
//MultiVerseCore.log.info(player.getName() + " wants to go to " + world.getName() + ". He's now at " + player.getLocation().toString());
double x, y, z;
@ -37,8 +37,8 @@ public class MVTeleport {
double srcComp = plugin.worlds.get(player.getWorld().getName()).compression;
double trgComp = plugin.worlds.get(world.getName()).compression;
MultiVerseCore.log.info(player.getWorld().getName() + "(" + srcComp + ") -> " + world.getName() + "(" + trgComp + ")");
MultiVerseCore.log.info(player.getName() + " -> " + player.getWorld().getName() + "(" + srcComp + ") -> " + world.getName() + "(" + trgComp + ")");
//MultiVerseCore.log.info("Original location : " + x + ", " + aux + ", " + z);
// If the Targets Compression is 0 then we teleport them to the Spawn of the World.
if(trgComp==0.0){
x = world.getSpawnLocation().getX()+0.5;
@ -72,7 +72,10 @@ public class MVTeleport {
if (aux > -1) {z = i; break;}
}
if (aux == -1) return null;
if (aux == -1) {
MultiVerseCore.log.info("Uh oh, no safe location.");
return null;
}
MultiVerseCore.log.info("Target location (safe): " + x + ", " + aux + ", " + z);
@ -82,13 +85,11 @@ public class MVTeleport {
}
private double safeColumn(World world, double x, double y, double z) {
double ny; boolean res = false;
for (ny = y; ny < 120 && ny < y + 48; ny++)
if (!this.blockIsNotSafe(world, x, y, z)) {res = true; break;}
for (ny = y; ny > 1 && ny > y - 48; ny--)
if (!this.blockIsNotSafe(world, x, y, z)) {res = true; break;}
if (res) return y;
else return -1;
for (double ny=0; ny<48;ny++){
if ((y+ny<120) && !this.blockIsNotSafe(world, x, y+ny, z)) { return y+ny; }
if ((y-ny>4) && !this.blockIsNotSafe(world, x, y-ny, z)) { return y-ny; }
}
return -1;
}
/**

View File

@ -127,6 +127,7 @@ public class MultiVerseCore extends JavaPlugin {
pm.registerEvent(Event.Type.PLUGIN_ENABLE, pluginListener, Priority.Normal, this); // Monitor for Permissions Plugin etc.
pm.registerEvent(Event.Type.BLOCK_PHYSICS, blockListener, Priority.Normal, this);
// Call the Function to load all the Worlds and setup the HashMap
loadWorlds();
// Purge Worlds of old Monsters/Animals which don't adhere to the setup.

View File

@ -1,6 +1,7 @@
package com.onarandombox.MultiVerseCore.commands;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -27,6 +28,7 @@ public class MVCoord extends MVCommandHandler {
p.sendMessage(ChatColor.RED + "Compression: " + ChatColor.WHITE + plugin.worlds.get(p.getWorld().getName()).compression);
p.sendMessage(ChatColor.RED + "Coordinates: " + ChatColor.WHITE + locMan.strCoords(p.getLocation()));
p.sendMessage(ChatColor.RED + "Direction: " + ChatColor.WHITE + locMan.getDirection(p.getLocation()));
p.sendMessage(ChatColor.RED + "Block: " + ChatColor.WHITE + Material.getMaterial(p.getWorld().getBlockTypeIdAt(p.getLocation())));
}
return true;
}