Search in sources :

Example 1 with MCRedstoneChangedEvent

use of com.laytonsmith.abstraction.events.MCRedstoneChangedEvent 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)

Aggregations

MCLocation (com.laytonsmith.abstraction.MCLocation)1 BukkitMCLocation (com.laytonsmith.abstraction.bukkit.BukkitMCLocation)1 MCRedstoneChangedEvent (com.laytonsmith.abstraction.events.MCRedstoneChangedEvent)1 EventHandler (org.bukkit.event.EventHandler)1