mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-09 09:01:31 +01:00
Changed priorities of the listeners to not cancel events too soon.
- Add the MVPortal Adjust Listener (lowest) - Change the PlayerListener to (High) Remember that the priories are really just order, so if PlayerListener was set to lowest, and cancelled the event, no one else would see it. These changes are required for the fix that i'm finishing up for NPs and SPs
This commit is contained in:
parent
c0d029c71d
commit
e344b0860d
@ -137,6 +137,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
|
||||
// Setup the block/player/entity listener.
|
||||
private MVPlayerListener playerListener = new MVPlayerListener(this);
|
||||
private MVPortalAdjustListener portalAdjustListener = new MVPortalAdjustListener(this);
|
||||
|
||||
private MVEntityListener entityListener = new MVEntityListener(this);
|
||||
private MVPluginListener pluginListener = new MVPluginListener(this);
|
||||
@ -304,7 +305,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
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_LOGIN, 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); // To prepend the world name
|
||||
pm.registerEvent(Event.Type.PLAYER_PORTAL, this.playerListener, Priority.Lowest, this); // To switch gamemode
|
||||
pm.registerEvent(Event.Type.PLAYER_PORTAL, this.playerListener, Priority.High, this); // We want this high to have it go last, so it can cancel if needbe.
|
||||
pm.registerEvent(Event.Type.PLAYER_PORTAL, this.portalAdjustListener, Priority.Lowest, this); // To handle portal correction
|
||||
pm.registerEvent(Event.Type.PLAYER_CHANGED_WORLD, this.playerListener, Priority.Monitor, this); // To switch gamemode
|
||||
|
||||
pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this);
|
||||
|
@ -0,0 +1,46 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.event;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
/**
|
||||
* This event is thrown when a portal is touched.
|
||||
*/
|
||||
public class MVPlayerTouchedPortalEvent extends Event implements Cancellable {
|
||||
private Player p;
|
||||
private Location l;
|
||||
private boolean isCancelled;
|
||||
|
||||
public MVPlayerTouchedPortalEvent(Player p, Location l) {
|
||||
super("MVPlayerTouchedPortalEvent");
|
||||
this.p = p;
|
||||
this.l = l;
|
||||
}
|
||||
|
||||
public Location getBlockTouched() {
|
||||
return this.l;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.isCancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean b) {
|
||||
this.isCancelled = b;
|
||||
}
|
||||
}
|
@ -186,17 +186,7 @@ public class MVPlayerListener extends PlayerListener {
|
||||
if (event.isCancelled() || event.getFrom() == null) {
|
||||
return;
|
||||
}
|
||||
// REMEMBER! getTo MAY be NULL HERE!!!
|
||||
// If the player was actually outside of the portal, adjust the from location
|
||||
if (event.getFrom().getWorld().getBlockAt(event.getFrom()).getType() != Material.PORTAL) {
|
||||
Location newloc = SafeTTeleporter.findPortalBlockNextTo(event.getFrom());
|
||||
// TODO: Fix this. Currently, we only check for PORTAL blocks. I'll have to figure out what
|
||||
// TODO: we want to do here.
|
||||
if (newloc != null) {
|
||||
event.setFrom(newloc);
|
||||
}
|
||||
}
|
||||
// Wait for the adjust, then return!
|
||||
// The adjust should have happened much earlier.
|
||||
if (event.getTo() == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2012. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.utils.SafeTTeleporter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.player.PlayerPortalEvent;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class MVPortalAdjustListener extends PlayerListener {
|
||||
|
||||
private MultiverseCore plugin;
|
||||
|
||||
public MVPortalAdjustListener(MultiverseCore core) {
|
||||
this.plugin = core;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerPortal(PlayerPortalEvent event) {
|
||||
this.plugin.log(Level.FINE, "CALLING CORE-ADJUST!!!");
|
||||
if (event.isCancelled() || event.getFrom() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// REMEMBER! getTo MAY be NULL HERE!!!
|
||||
// If the player was actually outside of the portal, adjust the from location
|
||||
if (event.getFrom().getWorld().getBlockAt(event.getFrom()).getType() != Material.PORTAL) {
|
||||
Location newloc = SafeTTeleporter.findPortalBlockNextTo(event.getFrom());
|
||||
// TODO: Fix this. Currently, we only check for PORTAL blocks. I'll have to figure out what
|
||||
// TODO: we want to do here.
|
||||
if (newloc != null) {
|
||||
event.setFrom(newloc);
|
||||
}
|
||||
}
|
||||
// Wait for the adjust, then return!
|
||||
if (event.getTo() == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -55,6 +55,19 @@ public class LocationManipulation {
|
||||
return formatter.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method simply does some rounding, rather than forcing a call to the server to get the blockdata.
|
||||
*
|
||||
* @param l The location to round to the block location
|
||||
* @return A rounded location.
|
||||
*/
|
||||
public static Location getBlockLocation(Location l) {
|
||||
l.setX(l.getBlockX());
|
||||
l.setY(l.getBlockY());
|
||||
l.setZ(l.getBlockZ());
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new location from a given string. The format is as follows:
|
||||
* <p>
|
||||
@ -132,7 +145,7 @@ public class LocationManipulation {
|
||||
* @return The {@link String}
|
||||
*/
|
||||
public static String strCoordsRaw(Location l) {
|
||||
if(l == null) {
|
||||
if (l == null) {
|
||||
return "null";
|
||||
}
|
||||
String result = "";
|
||||
|
Loading…
Reference in New Issue
Block a user