Skip to content

Commit

Permalink
Converted "on player steps on block" from SmartEvent.
Browse files Browse the repository at this point in the history
  • Loading branch information
Talamar1 committed Jun 14, 2015
1 parent 98c3727 commit b411170
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 129 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -573,7 +573,6 @@ public void onEnable() {
OldEventManager.registerSmartEvent(new FlagSmartEvent());
OldEventManager.registerSmartEvent(new NPCNavigationSmartEvent());
OldEventManager.registerSmartEvent(new PlayerEquipsArmorSmartEvent());
OldEventManager.registerSmartEvent(new PlayerStepsOnSmartEvent());
eventManager().registerCoreMembers();

ScriptEvent.registerScriptEvent(new BiomeEnterExitScriptEvent());
Expand Down Expand Up @@ -616,6 +615,7 @@ public void onEnable() {
ScriptEvent.registerScriptEvent(new PlayerDamagesBlockScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerJumpScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerPlacesBlockScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerStepsOnScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerTakesFromFurnaceScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerWalkScriptEvent());
ScriptEvent.registerScriptEvent(new RedstoneScriptEvent());
Expand Down

This file was deleted.

@@ -0,0 +1,143 @@
package net.aufdemrand.denizen.events.scriptevents;

import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.events.ScriptEvent;
import net.aufdemrand.denizencore.objects.dList;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer;
import net.aufdemrand.denizencore.utilities.CoreUtilities;

import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;

import java.util.HashMap;

public class PlayerStepsOnScriptEvent extends ScriptEvent implements Listener {

// <--[event]
// @Events
// player steps on block (in <notable cuboid>)
// player steps on <material> (in <notable cuboid>)
//
// @Warning This event may fire very rapidly.
//
// @Cancellable true
//
// @Triggers when a player steps onto a material.
//
// @Context
// <context.location> returns a dLocation of the block the player is stepping on.
// <context.cuboids> returns a dList of all cuboids the player is inside.
// <context.previous_location> returns a dLocation of where the player was before stepping onto the block.
// <context.new_location> returns a dLocation of where the player is now.
//
// -->

public PlayerStepsOnScriptEvent() {
instance = this;
}
public static PlayerStepsOnScriptEvent instance;
public dLocation location;
public dLocation previous_location;
public dLocation new_location;
public dList cuboids;
public PlayerMoveEvent event;

@Override
public boolean couldMatch(ScriptContainer scriptContainer, String s) {
return s.toLowerCase().startsWith("player steps on");
}

@Override
public boolean matches(ScriptContainer scriptContainer, String s) {
String lower = CoreUtilities.toLowerCase(s);

String mat = CoreUtilities.getXthArg(3, lower);
dMaterial material = dMaterial.getMaterialFrom(location.getBlock().getType(), location.getBlock().getData());
if (!mat.equals("block") && !mat.equals(material.identifyNoIdentifier())) {
return false;
}
if (CoreUtilities.xthArgEquals(4, lower, "in")) {
String it = CoreUtilities.getXthArg(5, lower);
if (dCuboid.matches(it)) {
dCuboid cuboid = dCuboid.valueOf(it);
if (!cuboid.isInsideCuboid(location)) {
return false;
}
}
else if (dEllipsoid.matches(it)) {
dEllipsoid ellipsoid = dEllipsoid.valueOf(it);
if (!ellipsoid.contains(location)) {
return false;
}
}
else {
dB.echoError("Invalid event 'IN ...' check [" + getName() + "]: '" + s + "' for " + scriptContainer.getName());
return false;
}
}

return true;
}

@Override
public String getName() {
return "PlayerStepsOn";
}

@Override
public void init() {
Bukkit.getServer().getPluginManager().registerEvents(this, DenizenAPI.getCurrentInstance());
}

@Override
public void destroy() {
PlayerMoveEvent.getHandlerList().unregister(this);
}

@Override
public boolean applyDetermination(ScriptContainer container, String determination) {
return super.applyDetermination(container, determination);
}

@Override
public HashMap<String, dObject> getContext() {
HashMap<String, dObject> context = super.getContext();
context.put("location", location);
context.put("previous_location", previous_location);
context.put("new_location", new_location);
context.put("cuboids", cuboids);
return context;
}

@EventHandler
public void onPlayerStepsOn(PlayerMoveEvent event) {
location = new dLocation(event.getTo().clone().subtract(0, 1, 0));
previous_location = new dLocation(event.getFrom());
new_location = new dLocation(event.getTo());
cuboids = new dList();
for (dCuboid cuboid: dCuboid.getNotableCuboidsContaining(location)) {
cuboids.add(cuboid.identifySimple());
}
cancelled = event.isCancelled();
this.event = event;
fire();
event.setCancelled(cancelled);
}

@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent event) {
if (dEntity.isNPC(event.getPlayer())) {
return;
}
PlayerMoveEvent evt = new PlayerMoveEvent(event.getPlayer(), event.getFrom(), event.getTo());
onPlayerStepsOn(evt);
event.setCancelled(evt.isCancelled());
}

}

0 comments on commit b411170

Please sign in to comment.