Permalink
Browse files

Improve a couple event handlers

  • Loading branch information...
PseudoKnight committed Oct 24, 2017
1 parent b62f293 commit d09df7bbb8c40fed0e761e71a5c4adf99f5b9a83
@@ -2,11 +2,8 @@
import com.laytonsmith.abstraction.MCLocation;
import com.laytonsmith.abstraction.bukkit.BukkitMCLocation;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCPlayer;
import com.laytonsmith.abstraction.bukkit.events.BukkitPlayerEvents.*;
import com.laytonsmith.commandhelper.CommandHelperPlugin;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.events.Driver;
import com.laytonsmith.core.events.EventUtils;
import com.laytonsmith.core.events.drivers.PlayerEvents;
@@ -15,6 +12,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.player.*;
@@ -76,8 +74,11 @@ public void onPlayerJoin(PlayerJoinEvent e) {
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent e) {
BukkitMCPlayerInteractEvent pie = new BukkitMCPlayerInteractEvent(e);
EventUtils.TriggerListener(Driver.PLAYER_INTERACT, "player_interact", pie);
EventUtils.TriggerListener(Driver.PLAYER_INTERACT, "pressure_plate_activated", pie);
if(e.getAction().equals(Action.PHYSICAL)){
EventUtils.TriggerListener(Driver.PLAYER_INTERACT, "pressure_plate_activated", pie);
} else {
EventUtils.TriggerListener(Driver.PLAYER_INTERACT, "player_interact", pie);
}
}
@EventHandler(priority = EventPriority.LOWEST)
@@ -202,12 +203,12 @@ public void onPlayerQuit(PlayerQuitEvent event) {
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
BukkitMCPlayer currentPlayer = (BukkitMCPlayer) Static.GetPlayer(event.getPlayer().getName(), Target.UNKNOWN);
//Apparently this happens sometimes, so prevent it
if (!event.getFrom().equals(currentPlayer._Player().getWorld())) {
BukkitMCWorldChangedEvent wce = new BukkitMCWorldChangedEvent(event);
EventUtils.TriggerListener(Driver.WORLD_CHANGED, "world_changed", wce);
if (event.getFrom().equals(event.getPlayer().getWorld())) {
return;
}
BukkitMCWorldChangedEvent wce = new BukkitMCWorldChangedEvent(event);
EventUtils.TriggerListener(Driver.WORLD_CHANGED, "world_changed", wce);
}
@EventHandler(priority = EventPriority.LOWEST)
@@ -855,10 +855,6 @@ public boolean matches(Map<String, Construct> prefilter, BindableEvent e) throws
if(e instanceof MCPlayerInteractEvent){
MCPlayerInteractEvent pie = (MCPlayerInteractEvent)e;
if(pie.getAction().equals(MCAction.PHYSICAL)){
return false;
}
if(prefilter.containsKey("button")){
if(pie.getAction().equals(MCAction.LEFT_CLICK_AIR) || pie.getAction().equals(MCAction.LEFT_CLICK_BLOCK)){
if(!prefilter.get("button").val().toLowerCase().equals("left")){
@@ -1072,9 +1068,6 @@ public String docs() {
public boolean matches(Map<String, Construct> prefilter, BindableEvent e) throws PrefilterNonMatchException {
if(e instanceof MCPlayerInteractEvent){
MCPlayerInteractEvent pie = (MCPlayerInteractEvent)e;
if(!((MCPlayerInteractEvent)e).getAction().equals(MCAction.PHYSICAL)){
return false;
}
Prefilters.match(prefilter, "location", pie.getClickedBlock().getLocation(), PrefilterType.LOCATION_MATCH);
if(prefilter.containsKey("activated")){
//TODO: Once activation is supported, check for that here

0 comments on commit d09df7b

Please sign in to comment.