Search in sources :

Example 1 with MCLocation

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;
                }
            });
        }
    }
}
Also used : MCLocation(com.laytonsmith.abstraction.MCLocation) BukkitMCLocation(com.laytonsmith.abstraction.bukkit.BukkitMCLocation) BukkitMCLocation(com.laytonsmith.abstraction.bukkit.BukkitMCLocation) MCRedstoneChangedEvent(com.laytonsmith.abstraction.events.MCRedstoneChangedEvent) EventHandler(org.bukkit.event.EventHandler)

Example 2 with MCLocation

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);
            }
        }
    }
}
Also used : MCLocation(com.laytonsmith.abstraction.MCLocation) BukkitMCLocation(com.laytonsmith.abstraction.bukkit.BukkitMCLocation) BukkitMCLocation(com.laytonsmith.abstraction.bukkit.BukkitMCLocation) MCLocation(com.laytonsmith.abstraction.MCLocation) Location(org.bukkit.Location) BukkitMCLocation(com.laytonsmith.abstraction.bukkit.BukkitMCLocation) EventHandler(org.bukkit.event.EventHandler)

Example 3 with MCLocation

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);
            }
        }
    }
}
Also used : MCLocation(com.laytonsmith.abstraction.MCLocation) BukkitMCLocation(com.laytonsmith.abstraction.bukkit.BukkitMCLocation) BukkitMCLocation(com.laytonsmith.abstraction.bukkit.BukkitMCLocation) UUID(java.util.UUID) Vector(org.bukkit.util.Vector) MCLocation(com.laytonsmith.abstraction.MCLocation) Location(org.bukkit.Location) BukkitMCLocation(com.laytonsmith.abstraction.bukkit.BukkitMCLocation) EventHandler(org.bukkit.event.EventHandler)

Example 4 with MCLocation

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
    }
}
Also used : Particle(org.bukkit.Particle) MCItemStack(com.laytonsmith.abstraction.MCItemStack) Location(org.bukkit.Location) MCLocation(com.laytonsmith.abstraction.MCLocation)

Example 5 with MCLocation

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}");
}
Also used : MCLocation(com.laytonsmith.abstraction.MCLocation) BukkitMCWorld(com.laytonsmith.abstraction.bukkit.BukkitMCWorld) Test(org.junit.Test) StaticTest(com.laytonsmith.testing.StaticTest)

Aggregations

MCLocation (com.laytonsmith.abstraction.MCLocation)15 BukkitMCLocation (com.laytonsmith.abstraction.bukkit.BukkitMCLocation)6 Location (org.bukkit.Location)6 MCWorld (com.laytonsmith.abstraction.MCWorld)4 BukkitMCWorld (com.laytonsmith.abstraction.bukkit.BukkitMCWorld)4 MCEntity (com.laytonsmith.abstraction.MCEntity)3 MCItemStack (com.laytonsmith.abstraction.MCItemStack)3 CArray (com.laytonsmith.core.constructs.CArray)3 EventHandler (org.bukkit.event.EventHandler)3 BukkitMCEntity (com.laytonsmith.abstraction.bukkit.entities.BukkitMCEntity)2 BukkitMCLivingEntity (com.laytonsmith.abstraction.bukkit.entities.BukkitMCLivingEntity)2 CREFormatException (com.laytonsmith.core.exceptions.CRE.CREFormatException)2 StaticTest (com.laytonsmith.testing.StaticTest)2 Particle (org.bukkit.Particle)2 Test (org.junit.Test)2 MCInventory (com.laytonsmith.abstraction.MCInventory)1 MCLivingEntity (com.laytonsmith.abstraction.MCLivingEntity)1 MCPlayer (com.laytonsmith.abstraction.MCPlayer)1 MCServer (com.laytonsmith.abstraction.MCServer)1 MCBlock (com.laytonsmith.abstraction.blocks.MCBlock)1