Search in sources :

Example 1 with BukkitMCLocation

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;
                }
            });
        }
    }
}
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 BukkitMCLocation

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);
            }
        }
    }
}
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 BukkitMCLocation

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);
            }
        }
    }
}
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 BukkitMCLocation

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

Aggregations

MCLocation (com.laytonsmith.abstraction.MCLocation)4 BukkitMCLocation (com.laytonsmith.abstraction.bukkit.BukkitMCLocation)4 Location (org.bukkit.Location)3 EventHandler (org.bukkit.event.EventHandler)3 MCItemStack (com.laytonsmith.abstraction.MCItemStack)1 BukkitMCItemStack (com.laytonsmith.abstraction.bukkit.BukkitMCItemStack)1 MCParticle (com.laytonsmith.abstraction.enums.MCParticle)1 MCRedstoneChangedEvent (com.laytonsmith.abstraction.events.MCRedstoneChangedEvent)1 UUID (java.util.UUID)1 Particle (org.bukkit.Particle)1 Vector (org.bukkit.util.Vector)1