use of com.laytonsmith.abstraction.MCLocation 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.MCLocation 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.MCLocation 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.MCLocation in project CommandHelper by EngineHub.
the class BukkitMCWorld 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) {
w.spawnParticle(type, loc, count, offsetX, offsetY, offsetZ, velocity, ((MCItemStack) data).getHandle());
} else {
w.spawnParticle(type, loc, count, offsetX, offsetY, offsetZ, velocity);
}
} catch (NoClassDefFoundError ex) {
// probably prior to 1.9
}
}
use of com.laytonsmith.abstraction.MCLocation in project CommandHelper by EngineHub.
the class PlayerManangementTest method testPloc.
// @Test(timeout = 10000)
// public void testAllPlayers() throws Exception {
// String script = "all_players()";
// String done = SRun(script, fakePlayer);
// //This output is too long to test with msg()
// assertEquals("{player1, player2, player3, player}", done);
// }
@Test
public void testPloc() throws Exception, Exception {
String script = "msg(ploc())";
BukkitMCWorld w = GetWorld("world");
MCLocation loc = StaticLayer.GetLocation(w, 0, 1, 0);
when(fakePlayer.getLocation()).thenReturn(loc);
when(fakePlayer.getWorld()).thenReturn(w);
SRun(script, fakePlayer);
verify(fakePlayer).sendMessage("{0: 0.0, 1: 1.0, 2: 0.0, 3: world, 4: 0.0, 5: 0.0, pitch: 0.0, world: world, x: 0.0, y: 1.0, yaw: 0.0, z: 0.0}");
}
Aggregations