I'm sorry Kainzo. Now Core does NOT use PLAYER_MOVE.

This commit is contained in:
Eric Stokes 2011-07-17 15:45:17 -06:00
parent 5aa91c67f5
commit bdefb38f3c
4 changed files with 52 additions and 103 deletions

View File

@ -23,57 +23,31 @@ public class MVPlayerListener extends PlayerListener {
this.plugin = plugin;
}
@Override
public void onPlayerMove(PlayerMoveEvent event) {
Player p = event.getPlayer(); // Grab Player
Location loc = p.getLocation(); // Grab Location
/**
* Check the Player has actually moved a block to prevent unneeded calculations... This is to prevent huge performance drops on high player count servers.
*/
MVPlayerSession ps = this.plugin.getPlayerSession(p);
if (ps.getLocation().getBlockX() == loc.getBlockX() && ps.getLocation().getBlockY() == loc.getBlockY() && ps.getLocation().getBlockZ() == loc.getBlockZ()) {
ps.setStaleLocation(true);
return;
} else {
ps.setLocation(loc); // Update the Players Session to the new Location.
ps.setStaleLocation(false);
}
}
@Override
public void onPlayerBedLeave(PlayerBedLeaveEvent event) {
Location bedLoc = event.getBed().getLocation();
bedLoc = this.plugin.getTeleporter().getSafeBedDestination(bedLoc);
this.plugin.getPlayerSession(event.getPlayer()).setRespawnLocation(bedLoc);
event.getPlayer().sendMessage("You should come back here when you type '/mv sleep'!");
}
// Taken out until we do persistance.
// @Override
// public void onPlayerBedLeave(PlayerBedLeaveEvent event) {
// Location bedLoc = event.getBed().getLocation();
// bedLoc = this.plugin.getTeleporter().getSafeBedDestination(bedLoc);
// this.plugin.getPlayerSession(event.getPlayer()).setRespawnLocation(bedLoc);
// event.getPlayer().sendMessage("You should come back here when you type '/mv sleep'!");
// }
@Override
public void onPlayerChat(PlayerChatEvent event) {
// Not sure if this should be a separate plugin... in here for now!!!
// FernFerret
if (event.isCancelled()) {
return;
}
/**
* Check whether the Server is set to prefix the chat with the World name. If not we do nothing, if so we need to check if the World has an Alias.
*/
// Check whether the Server is set to prefix the chat with the World name. If not we do nothing, if so we need to check if the World has an Alias.
if (this.plugin.configMV.getBoolean("worldnameprefix", true)) {
String world = event.getPlayer().getWorld().getName();
String prefix = "";
// If we're not a MV world, don't do anything
if (!this.plugin.isMVWorld(world)) {
return;
}
MVWorld mvworld = this.plugin.getMVWorld(world);
prefix = mvworld.getColoredWorldString();
String format = event.getFormat();
event.setFormat("[" + prefix + "]" + format);
}
}
@ -118,10 +92,10 @@ public class MVPlayerListener extends PlayerListener {
event.getPlayer().sendMessage("If you just wanna see all of the Multiverse Help, type: " + ChatColor.GREEN + "/mv");
}
}
@Override
public void onPlayerQuit(PlayerQuitEvent event) {
this.plugin.removePlayerSession(event.getPlayer());
}
@Override

View File

@ -13,7 +13,6 @@ import com.onarandombox.utils.BlockSafety;
public class MVPlayerSession {
private Player player; // Player holder, may be unnecessary.
private Location loc = new Location(null, 0, 0, 0); // Contain the Players Location so on player move we can compare this and check if they've moved a block.
private BlockSafety bs = new BlockSafety();
private Long teleportLast = 0L; // Timestamp for the Players last Portal Teleportation.
@ -26,11 +25,9 @@ public class MVPlayerSession {
private Location bedB;
private Configuration config; // Configuration file to find out Cooldown Timers.
private boolean staleLocation;
public MVPlayerSession(Player player, Configuration config, MultiverseCore multiVerseCore) {
this.player = player;
this.setLocation(player.getLocation());
this.config = config;
this.bedSpawn = null;
}
@ -73,49 +70,30 @@ public class MVPlayerSession {
this.bedSpawn = location;
}
// This one simply spawns the player closer to the bed.
public Location getBedRespawnLocation() {
// There is a bedrespawn set
if (this.bedSpawn != null) {
if (!this.bs.playerCanSpawnHereSafely(this.bedSpawn) || !bedStillExists(this.bedSpawn)) {
this.bedSpawn = null;
return this.bedSpawn;
}
Location actualRespawn = this.bedSpawn;
Location bedRespawn = new Location(actualRespawn.getWorld(), actualRespawn.getX(), actualRespawn.getY(), actualRespawn.getZ());
bedRespawn.setY(bedRespawn.getY() - .25);
return bedRespawn;
}
return null;
}
private boolean bedStillExists(Location bedSpawn) {
//System.out.print("Dangers:");
//this.bs.showDangers(bedSpawn);
Location locationDown = new Location(bedSpawn.getWorld(), bedSpawn.getX(), bedSpawn.getY(), bedSpawn.getZ());
locationDown.setY(locationDown.getY() - 1);
if (locationDown.getBlock().getType() != Material.BED_BLOCK) {
return false;
}
return true;
}
public void setStaleLocation(boolean active) {
this.staleLocation = active;
}
public boolean isStaleLocation() {
return this.staleLocation;
}
public void setLocation(Location loc) {
// Perform rounding to always have integer values
this.loc = loc;
}
public Location getLocation() {
return this.loc;
}
// // This one simply spawns the player closer to the bed.
// public Location getBedRespawnLocation() {
// // There is a bedrespawn set
// if (this.bedSpawn != null) {
// if (!this.bs.playerCanSpawnHereSafely(this.bedSpawn) || !bedStillExists(this.bedSpawn)) {
// this.bedSpawn = null;
// return this.bedSpawn;
// }
// Location actualRespawn = this.bedSpawn;
// Location bedRespawn = new Location(actualRespawn.getWorld(), actualRespawn.getX(), actualRespawn.getY(), actualRespawn.getZ());
// bedRespawn.setY(bedRespawn.getY() - .25);
// return bedRespawn;
// }
// return null;
// }
//
// private boolean bedStillExists(Location bedSpawn) {
// //System.out.print("Dangers:");
// //this.bs.showDangers(bedSpawn);
// Location locationDown = new Location(bedSpawn.getWorld(), bedSpawn.getX(), bedSpawn.getY(), bedSpawn.getZ());
// locationDown.setY(locationDown.getY() - 1);
// if (locationDown.getBlock().getType() != Material.BED_BLOCK) {
// return false;
// }
// return true;
// }
}

View File

@ -56,7 +56,6 @@ public class MultiverseCore extends JavaPlugin {
// Setup the block/player/entity listener.
private MVPlayerListener playerListener = new MVPlayerListener(this);;
private MVBlockListener blockListener = new MVBlockListener(this);
private MVEntityListener entityListener = new MVEntityListener(this);
private MVPluginListener pluginListener = new MVPluginListener(this);
@ -126,11 +125,8 @@ public class MultiverseCore extends JavaPlugin {
pm.registerEvent(Event.Type.PLAYER_TELEPORT, this.playerListener, Priority.Highest, this); // Cancel Teleports if needed.
pm.registerEvent(Event.Type.PLAYER_JOIN, this.playerListener, Priority.Normal, this); // To create the Player Session
pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Priority.Normal, this); // To remove Player Sessions
pm.registerEvent(Event.Type.PLAYER_KICK, this.playerListener, Priority.Highest, this);
pm.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Priority.Low, this); // Let plugins which specialize in (re)spawning carry more weight.
pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Priority.Low, this);
pm.registerEvent(Event.Type.PLAYER_BED_LEAVE, this.playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Priority.Normal, this); // To prepend the world name
pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.Normal, this); // To Allow/Disallow fake PVP
@ -138,11 +134,6 @@ public class MultiverseCore extends JavaPlugin {
pm.registerEvent(Event.Type.PLUGIN_ENABLE, this.pluginListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.PLUGIN_DISABLE, this.pluginListener, Priority.Monitor, this);
// pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Normal, this); // To prevent Blocks being destroyed.
// pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this); // To prevent Blocks being placed.
// pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Normal, this); // Try to prevent Ghasts from blowing up structures.
// pm.registerEvent(Event.Type.EXPLOSION_PRIMED, entityListener, Priority.Normal, this); // Try to prevent Ghasts from blowing up structures.
}
/**
@ -594,4 +585,10 @@ public class MultiverseCore extends JavaPlugin {
sender.sendMessage("Multiverse doesn't know about " + ChatColor.DARK_AQUA + worldName + ChatColor.WHITE + " yet.");
sender.sendMessage("Type " + ChatColor.DARK_AQUA + "/mv import ?" + ChatColor.WHITE + " for help!");
}
public void removePlayerSession(Player player) {
if(this.playerSessions.containsKey(player.getName())) {
this.playerSessions.remove(player.getName());
}
}
}

View File

@ -30,13 +30,13 @@ public class SleepCommand extends MultiverseCommand {
if (p == null) {
return;
}
MVPlayerSession session = this.plugin.getPlayerSession(p);
if (session.getBedRespawnLocation() != null) {
p.teleport(session.getBedRespawnLocation());
} else {
sender.sendMessage("Hmm this is awkward...");
sender.sendMessage("Something is wrong with your bed.");
sender.sendMessage("It has either been destroyed or obstructed.");
}
// MVPlayerSession session = this.plugin.getPlayerSession(p);
// if (session.getBedRespawnLocation() != null) {
// p.teleport(session.getBedRespawnLocation());
// } else {
// sender.sendMessage("Hmm this is awkward...");
// sender.sendMessage("Something is wrong with your bed.");
// sender.sendMessage("It has either been destroyed or obstructed.");
// }
}
}