Skip to content

Commit

Permalink
Merge pull request #97 from mergu/master
Browse files Browse the repository at this point in the history
stop_sound mec, track vehicle enter/exit event
  • Loading branch information
mcmonkey4eva committed Aug 6, 2017
2 parents 1c8a5f7 + 23be090 commit 4b5dcbe
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.aufdemrand.denizen.events.core;

import net.aufdemrand.denizen.nms.NMSHandler;
import net.aufdemrand.denizen.nms.NMSVersion;
import net.aufdemrand.denizen.objects.dCuboid;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dLocation;
Expand All @@ -12,9 +14,12 @@
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.*;
import org.bukkit.event.vehicle.VehicleMoveEvent;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -106,7 +111,7 @@ public void breakDown() {
// <context.from> returns the block location moved from.
// <context.to> returns the block location moved to.
// <context.cuboids> returns a list of cuboids entered/exited (when no cuboid is specified in the event name).
// <context.cause> returns the cause of the event. Can be: WALK, WORLD_CHANGE, JOIN, LEAVE, TELEPORT
// <context.cause> returns the cause of the event. Can be: WALK, WORLD_CHANGE, JOIN, LEAVE, TELEPORT, VEHICLE
//
// @Determine
// "CANCELLED" to stop the player from moving, if cause is WALK or TELEPORT.
Expand Down Expand Up @@ -158,6 +163,23 @@ public void onWorldChange(PlayerChangedWorldEvent event) {
internalRun(evt, "world_change");
}

@EventHandler
public void vehicleMoveEvent(VehicleMoveEvent event) {
List<Entity> passengers = new ArrayList<Entity>();
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_11_R1)) {
passengers.addAll(event.getVehicle().getPassengers());
}
else {
passengers.add(event.getVehicle().getPassenger());
}
for (Entity entity : passengers) {
if (dEntity.isPlayer(entity)) {
PlayerMoveEvent evt = new PlayerMoveEvent((Player) entity, event.getFrom(), event.getTo());
internalRun(evt, "vehicle");
}
}
}

@EventHandler
public void playerMoveEvent(PlayerMoveEvent event) {
internalRun(event, "walk");
Expand Down
25 changes: 25 additions & 0 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3043,6 +3043,31 @@ else if (split.length > 1) {
}
}

// <--[mechanism]
// @object dPlayer
// @name stop_sound
// @input Element
// @description
// Stops all sounds of the specified type for the player.
// Valid types are AMBIENT, BLOCKS, HOSTILE, MASTER, MUSIC,
// NEUTRAL, PLAYERS, RECORDS, VOICE, and WEATHER
// If no sound type is specified, all types will be stopped.
// -->
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_11_R1)
&& mechanism.matches("stop_sound")) {
if (!mechanism.hasValue()) {
getPlayerEntity().stopSound("");
}
else {
try {
getPlayerEntity().stopSound("", SoundCategory.valueOf(value.asString().toUpperCase()));
}
catch (Exception e) {
dB.echoError("Invalid SoundCategory. Must specify a valid name.");
}
}
}

// <--[mechanism]
// @object dPlayer
// @name action_bar
Expand Down

0 comments on commit 4b5dcbe

Please sign in to comment.