Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrote "on vehicle collides with entity" event in new ScriptEvent fo…
…rmat. Rewrote "on vehicle collides with block" event in new ScriptEvent format. Split file into two separate events. Existing issue where event doesn't handle when vehicle collides with NPC. It is reporting as a block collision with the block under the NPC.
- Loading branch information
Showing
4 changed files
with
233 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 0 additions & 153 deletions
153
src/main/java/net/aufdemrand/denizen/events/core/VehicleCollisionSmartEvent.java
This file was deleted.
Oops, something went wrong.
111 changes: 111 additions & 0 deletions
111
...main/java/net/aufdemrand/denizen/events/scriptevents/VehicleCollidesBlockScriptEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package net.aufdemrand.denizen.events.scriptevents; | ||
|
||
import net.aufdemrand.denizen.objects.dEntity; | ||
import net.aufdemrand.denizen.objects.dLocation; | ||
import net.aufdemrand.denizen.objects.dMaterial; | ||
import net.aufdemrand.denizen.utilities.DenizenAPI; | ||
import net.aufdemrand.denizencore.events.ScriptEvent; | ||
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.vehicle.VehicleBlockCollisionEvent; | ||
|
||
import java.util.HashMap; | ||
|
||
public class VehicleCollidesBlockScriptEvent extends ScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// vehicle collides with block | ||
// vehicle collides with <material> | ||
// <vehicle> collides with block | ||
// <vehicle> collides with <material> | ||
// | ||
// @Triggers when a vehicle collides with a block. | ||
// | ||
// @Context | ||
// <context.vehicle> returns the dEntity of the vehicle. | ||
// <context.location> returns the dLocation of the block. | ||
// | ||
// --> | ||
|
||
public VehicleCollidesBlockScriptEvent() { | ||
instance = this; | ||
} | ||
public static VehicleCollidesBlockScriptEvent instance; | ||
public dEntity vehicle; | ||
public dLocation location; | ||
public VehicleBlockCollisionEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptContainer scriptContainer, String s) { | ||
String lower = CoreUtilities.toLowerCase(s); | ||
String arg = lower.substring(lower.lastIndexOf("with ") + 5); | ||
return lower.contains(" collides with ") | ||
&& (arg.equals("block") || dMaterial.matches(arg)); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptContainer scriptContainer, String s) { | ||
String lower = CoreUtilities.toLowerCase(s); | ||
|
||
String block = lower.substring(lower.lastIndexOf(" ") + 1); | ||
String mat = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData()).identifyNoIdentifier(); | ||
|
||
if (mat.equals("m@air") || (mat.equals("air"))) { | ||
return false; | ||
} | ||
if (!block.equals("block") | ||
&& !block.equals(mat)) { | ||
return false; | ||
} | ||
|
||
String v_test = lower.substring(0,lower.indexOf(" ")); | ||
if (!v_test.equals("vehicle") | ||
&& !v_test.equals(vehicle.identifySimpleType())) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "VehicleCollidesBlock"; | ||
} | ||
|
||
@Override | ||
public void init() { | ||
Bukkit.getServer().getPluginManager().registerEvents(this, DenizenAPI.getCurrentInstance()); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
VehicleBlockCollisionEvent.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("vehicle", vehicle); | ||
context.put("location", location); | ||
return context; | ||
} | ||
|
||
@EventHandler | ||
public void onVehicleCollidesBlock(VehicleBlockCollisionEvent event) { | ||
vehicle= new dEntity(event.getVehicle()); | ||
location = new dLocation(event.getBlock().getLocation()); | ||
this.event = event; | ||
fire(); | ||
} | ||
} |
Oops, something went wrong.