use of com.laytonsmith.abstraction.bukkit.BukkitMCLocation in project CommandHelper by EngineHub.
the class BukkitServerListener method onBlockPhysics.
@EventHandler(priority = EventPriority.LOWEST)
public void onBlockPhysics(BlockPhysicsEvent event) {
Map<MCLocation, Boolean> locations = ServerEvents.getRedstoneMonitors();
if (locations.isEmpty()) {
// Bail as quickly as we can if this isn't being used.
return;
}
final MCLocation blockLocation = new BukkitMCLocation(event.getBlock().getLocation());
if (locations.containsKey(blockLocation)) {
// This is a monitored location, so we will be triggering the event.
boolean wasPowered = locations.get(blockLocation);
final boolean isPowered = blockLocation.getBlock().isBlockPowered();
if (wasPowered != isPowered) {
// It was changed, so set the state appropriately now.
locations.put(blockLocation, isPowered);
EventUtils.TriggerListener(Driver.REDSTONE_CHANGED, "redstone_changed", new MCRedstoneChangedEvent() {
@Override
public boolean isActive() {
return isPowered;
}
@Override
public MCLocation getLocation() {
return blockLocation;
}
@Override
public Object _GetObject() {
return null;
}
});
}
}
}
use of com.laytonsmith.abstraction.bukkit.BukkitMCLocation in project CommandHelper by EngineHub.
the class BukkitPlayerListener method onPlayerMove.
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerMove(PlayerMoveEvent event) {
Location from = event.getFrom();
Location to = event.getTo();
if (from.getX() == to.getX() && from.getY() == to.getY() && from.getZ() == to.getZ()) {
return;
}
String p = event.getPlayer().getName();
for (Integer threshold : PlayerEvents.GetThresholdList()) {
Map<String, MCLocation> lastLocations = PlayerEvents.GetLastLocations(threshold);
MCLocation last;
if (!lastLocations.containsKey(p)) {
last = new BukkitMCLocation(from);
lastLocations.put(p, last);
} else {
last = lastLocations.get(p);
}
MCLocation movedTo = new BukkitMCLocation(to);
if (!movedTo.getWorld().getName().equals(last.getWorld().getName())) {
lastLocations.put(p, movedTo);
continue;
}
if (last.distance(movedTo) > threshold) {
BukkitMCPlayerMoveEvent pme = new BukkitMCPlayerMoveEvent(event, threshold, last);
EventUtils.TriggerListener(Driver.PLAYER_MOVE, "player_move", pme);
if (!pme.isCancelled()) {
lastLocations.put(p, movedTo);
}
}
}
}
use of com.laytonsmith.abstraction.bukkit.BukkitMCLocation in project CommandHelper by EngineHub.
the class BukkitVehicleListener method onVehicleMove.
@EventHandler(priority = EventPriority.LOWEST)
public void onVehicleMove(VehicleMoveEvent event) {
Location from = event.getFrom();
Location to = event.getTo();
UUID id = event.getVehicle().getUniqueId();
for (Integer threshold : VehicleEvents.GetThresholdList()) {
Map<UUID, MCLocation> lastLocations = VehicleEvents.GetLastLocations(threshold);
if (!lastLocations.containsKey(id)) {
lastLocations.put(id, new BukkitMCLocation(from));
continue;
}
MCLocation last = lastLocations.get(id);
if (!to.getWorld().getName().equals(last.getWorld().getName())) {
lastLocations.put(id, new BukkitMCLocation(to));
continue;
}
BukkitMCLocation movedTo = new BukkitMCLocation(to);
if (last.distance(movedTo) > threshold) {
BukkitMCVehicleMoveEvent vme = new BukkitMCVehicleMoveEvent(event, threshold, last);
EventUtils.TriggerListener(Driver.VEHICLE_MOVE, "vehicle_move", vme);
if (!vme.isCancelled()) {
lastLocations.put(id, movedTo);
} else {
event.getVehicle().setVelocity(new Vector(0, 0, 0));
event.getVehicle().teleport(from);
}
}
}
}
use of com.laytonsmith.abstraction.bukkit.BukkitMCLocation in project CommandHelper by EngineHub.
the class BukkitMCPlayer method spawnParticle.
@Override
public void spawnParticle(MCLocation l, MCParticle pa, int count, double offsetX, double offsetY, double offsetZ, double velocity, Object data) {
try {
Particle type = Particle.valueOf(pa.name());
Location loc = ((BukkitMCLocation) l).asLocation();
if (data != null && type.getDataType().equals(ItemStack.class) && data instanceof MCItemStack) {
p.spawnParticle(type, loc, count, offsetX, offsetY, offsetZ, velocity, ((MCItemStack) data).getHandle());
} else {
p.spawnParticle(type, loc, count, offsetX, offsetY, offsetZ, velocity);
}
} catch (NoClassDefFoundError ex) {
// probably prior to 1.9
}
}
Aggregations