diff --git a/README.md b/README.md index 2c4aec2..896d30c 100755 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ a [RedstoneChips](http://eisental.github.com/RedstoneChips) circuit library cont - rangefinder - An ultrasonic transceiver for detecting the exact distance between the chip and anything. - beacon - Can force map chunks to stay loaded and monitors whether chunks in a region are loaded or not. - slotinput - Input decimal numbers by choosing an inventory slot and clicking an interface block. -- vehicleid - Track a vehicle entity id number as it passes over the chip interface blocks. +- vehicleid - Track a vehicle entity id number as it passes by the chip interface blocks. - playerid - Track a player entity id. - spark - Strike thunders on command. @@ -19,10 +19,14 @@ __For much more information, see the [circuitdocs](http://eisental.github.com/Re Installation ------------- * Download the latest RedstoneChips bundle [RedstoneChips](http://eisental.github.com/RedstoneChips). -* Copy all jar files into the plugins folder of your craftbukkit installation. +* Copy all jar files into the plugins folder of your spigot installation. Changelog --------- +#### SensorLibrary 0.4 +- Updated for RC1.0 +__playerid__: Added sign arguments for sphere and axis type detection and distance of detection +__vehicleid__: Added sign arguments for sphere and axis type detection and distance of detection #### SensorLibrary 0.34 - __daytime__: Fixed daytime offset bug. diff --git a/src/main/resources/plugin.yml b/plugin.yml similarity index 87% rename from src/main/resources/plugin.yml rename to plugin.yml index f7be7e8..69c7240 100755 --- a/src/main/resources/plugin.yml +++ b/plugin.yml @@ -1,6 +1,7 @@ name: SensorLibrary main: org.redstonechips.sensorlibrary.SensorLibrary -version: 0.34 +version: 0.40 +api-version: 1.15 author: eisental description: Sensor library for RedstoneChips integrated circuits plugin. website: eisental.github.com/RedstoneChips diff --git a/pom.xml b/pom.xml index 150913e..c871ea8 100755 --- a/pom.xml +++ b/pom.xml @@ -22,10 +22,17 @@ + + org.bukkit + bukkit + 1.15.2-R0.1-SNAPSHOT + jar + provided + org.redstonechips RedstoneChips - 1.0-SNAPSHOT + 1.1-SNAPSHOT diff --git a/src/main/java/org/redstonechips/sensorlibrary/SensorLibrary.java b/src/main/java/org/redstonechips/sensorlibrary/SensorLibrary.java index d617e0a..d29eb4b 100755 --- a/src/main/java/org/redstonechips/sensorlibrary/SensorLibrary.java +++ b/src/main/java/org/redstonechips/sensorlibrary/SensorLibrary.java @@ -14,7 +14,7 @@ public class SensorLibrary extends CircuitLibrary { @Override public Class[] getCircuitClasses() { return new Class[] {photocell.class, pirsensor.class, rangefinder.class, daytime.class, slotinput.class, - beacon.class, spark.class, liquidlevel.class}; + beacon.class, spark.class, liquidlevel.class, playerid.class, vehicleid.class}; } @Override diff --git a/src/main/java/org/redstonechips/sensorlibrary/beacon.java b/src/main/java/org/redstonechips/sensorlibrary/beacon.java index 0177382..50b6c9f 100755 --- a/src/main/java/org/redstonechips/sensorlibrary/beacon.java +++ b/src/main/java/org/redstonechips/sensorlibrary/beacon.java @@ -70,6 +70,16 @@ public void shutdown() { SensorLibrary.eventDispatcher.unregisterListener(chunkLoadListener); SensorLibrary.eventDispatcher.unregisterListener(chunkUnloadListener); } + @Override + public void destroyed() { + SensorLibrary.eventDispatcher.unregisterListener(chunkLoadListener); + SensorLibrary.eventDispatcher.unregisterListener(chunkUnloadListener); + } + @Override + public void disable() { + SensorLibrary.eventDispatcher.unregisterListener(chunkLoadListener); + SensorLibrary.eventDispatcher.unregisterListener(chunkUnloadListener); + } private final EventListener chunkLoadListener = new EventListener() { @Override @@ -91,7 +101,7 @@ public void onEvent(Event e) { Chunk chunk = event.getChunk(); if (keepalive) { if (chip.hasListeners()) debug("Chunk (" + chunk.getX() + ", " + chunk.getZ() + ") in " + chip.world.getName()+ " is kept alive."); - event.setCancelled(true); + chunk.setForceLoaded(true); } else { loadCount--; sendBit(); diff --git a/src/main/java/org/redstonechips/sensorlibrary/liquidlevel.java b/src/main/java/org/redstonechips/sensorlibrary/liquidlevel.java index 4bca762..8dfae08 100644 --- a/src/main/java/org/redstonechips/sensorlibrary/liquidlevel.java +++ b/src/main/java/org/redstonechips/sensorlibrary/liquidlevel.java @@ -8,7 +8,8 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.block.BlockState; +import org.bukkit.block.data.Levelled; +import org.bukkit.block.data.BlockData; import org.bukkit.event.Event; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockEvent; @@ -32,9 +33,9 @@ public class liquidlevel extends Circuit { private static final Set liquids = new HashSet<>(); static { liquids.add(Material.WATER); - liquids.add(Material.STATIONARY_WATER); + //liquids.add(Material.FLOWING_WATER); liquids.add(Material.LAVA); - liquids.add(Material.STATIONARY_LAVA); + //liquids.add(Material.STATIONARY_LAVA); } Map sides = new HashMap<>(); @@ -152,13 +153,17 @@ private void updateSide(Location side) { } private byte findWaterLevel(Location l) { - BlockState b = l.getBlock().getState(); + Block b = l.getBlock(); + BlockData bd = b.getBlockData(); + if (liquids.contains(b.getType())) { - byte data = b.getData().getData(); - if (data>7) // falling liquid. full water block. + Levelled data = (Levelled)bd; + System.out.println("old = " + b); + //System.out.println("new = " + b.getBlockData().getLevel()); + if (data.getLevel()>7) // falling liquid. full water block. return 8; else - return (byte)(8-b.getData().getData()); + return (byte)(8-data.getLevel()); } else { return 0; } diff --git a/src/main/java/org/redstonechips/sensorlibrary/pirsensor.java b/src/main/java/org/redstonechips/sensorlibrary/pirsensor.java index 92cbfc7..32e3f74 100755 --- a/src/main/java/org/redstonechips/sensorlibrary/pirsensor.java +++ b/src/main/java/org/redstonechips/sensorlibrary/pirsensor.java @@ -26,7 +26,7 @@ public void input(boolean state, int inIdx) { // clock pin triggered boolean alarm = false; - for (Object o : chip.world.getEntitiesByClass(checkedEntities)) { + for (Object o : chip.world.getEntitiesByClasses(checkedEntities)) { Entity e = (Entity)o; Location l = e.getLocation(); diff --git a/src/main/java/org/redstonechips/sensorlibrary/playerid.java b/src/main/java/org/redstonechips/sensorlibrary/playerid.java index a32c1a8..c52a079 100755 --- a/src/main/java/org/redstonechips/sensorlibrary/playerid.java +++ b/src/main/java/org/redstonechips/sensorlibrary/playerid.java @@ -1,79 +1,222 @@ -/* + package org.redstonechips.sensorlibrary; import org.bukkit.Location; +import org.bukkit.event.Event; import org.bukkit.event.player.PlayerMoveEvent; +import org.redstonechips.RCPrefs; import org.redstonechips.circuit.Circuit; +import org.redstonechips.event.EventListener; -/** +/* * * @author Tal Eisenberg - *//* + */ public class playerid extends Circuit { private final int resetPin = 1; private final int disablePin = 0; private boolean pinDisabled = false; private int lastInterface = -1; - + private byte distance = 1; + private boolean sphere = false; + + private Boolean[] directionAim = new Boolean[] { + false, + false, + false, + false, + false, + false, + }; + + private static final String[] directionText = new String[] { + "EAST", + "WEST", + "NORTH", + "SOUTH", + "ABOVE", + "BELOW", + }; + @Override public void input(boolean state, int inIdx) { if (inIdx==resetPin && state) { for (int i=0; i0) { + for (byte i=0; imaxIdDistance) return error("Maximum distance exceeded: " + args[i] + ". The maximum distance is " + maxIdDistance + ". Set playerid.maxdistance in preferences.yml to extend the maximum distance."); + + } catch (NumberFormatException ne2) { + return error("Bad distance argument: " + args[i] + ". Expecting a number between 1 and " + maxIdDistance); + } + } + else if (args[i].toUpperCase().equals("SPHERE")) sphere = true; //check if sphere or axis is on sign. No arg defaults to axis + else if (args[i].toUpperCase().equals("AXIS")) sphere = false; + for (byte j=0; j<=5; j++) { + if (args[i].toUpperCase().equals(directionText[j])) { // if sign arg is a direction, mark that direction as true + directionAim[j] = true; + } + } + } + } } + SensorLibrary.eventDispatcher.registerListener(PlayerMoveEvent.class, moveListener); + return this; } + + private final EventListener moveListener = new EventListener() { - void onPlayerMove(PlayerMoveEvent event) { - if (pinDisabled) return; + @Override + public void onEvent(Event e) { + if (pinDisabled) return; + PlayerMoveEvent p = (PlayerMoveEvent)e; + Location to = p.getTo(); + boolean found = false; - Location to = event.getTo(); - boolean found = false; + for (int i=0; i0 && + Math.abs(too.getBlockY()-inn.getBlockY())<=distance && + Math.abs(too.getBlockZ()-inn.getBlockZ())<=distance); + boolean distanceSphereEast = (too.getBlockX()-inn.getBlockX()<=distance && + too.getBlockX()-inn.getBlockX()>0 && + Math.abs(too.getBlockY()-inn.getBlockY())<=distance && + Math.abs(too.getBlockZ()-inn.getBlockZ())<=distance); + boolean distanceSphereNorth = (inn.getBlockZ()-too.getBlockZ()<=distance && + inn.getBlockZ()-too.getBlockZ()>0 && + Math.abs(too.getBlockY()-inn.getBlockY())<=distance && + Math.abs(too.getBlockX()-inn.getBlockX())<=distance); + boolean distanceSphereSouth = (too.getBlockZ()-inn.getBlockZ()<=distance && + too.getBlockZ()-inn.getBlockZ()>0 && + Math.abs(too.getBlockY()-inn.getBlockY())<=distance && + Math.abs(too.getBlockX()-inn.getBlockX())<=distance); + boolean distanceSphereAbove = (too.getBlockY()-inn.getBlockY()<=distance && + too.getBlockY()-inn.getBlockY()>0 && + Math.abs(too.getBlockZ()-inn.getBlockZ())<=distance && + Math.abs(too.getBlockX()-inn.getBlockX())<=distance); + boolean distanceSphereBelow = (inn.getBlockY()-too.getBlockY()<=distance && + inn.getBlockY()-too.getBlockY()>0 && + Math.abs(too.getBlockZ()-inn.getBlockZ())<=distance && + Math.abs(too.getBlockX()-inn.getBlockX())<=distance); + boolean distanceSphere = (distanceSphereEast&&!directionAim[1]&&!directionAim[2]&&!directionAim[3]&&!directionAim[4]&&!directionAim[5]) + || (distanceSphereWest&&!directionAim[0]&&!directionAim[2]&&!directionAim[3]&&!directionAim[4]&&!directionAim[5]) + || (distanceSphereNorth&&!directionAim[1]&&!directionAim[0]&&!directionAim[3]&&!directionAim[4]&&!directionAim[5]) + || (distanceSphereSouth&&!directionAim[1]&&!directionAim[2]&&!directionAim[0]&&!directionAim[4]&&!directionAim[5]) + || (distanceSphereAbove&&!directionAim[1]&&!directionAim[2]&&!directionAim[3]&&!directionAim[0]&&!directionAim[5]) + || (distanceSphereBelow&&!directionAim[1]&&!directionAim[2]&&!directionAim[3]&&!directionAim[4]&&!directionAim[0]); + if (distanceSphere) return true; + } + else { + boolean distanceCheckEast= (too.getBlockX()-inn.getBlockX()<=distance && + too.getBlockX()-inn.getBlockX()>0 && + too.getBlockY()-inn.getBlockY()==0 && + too.getBlockZ()-inn.getBlockZ()==0); // can not use ABS as it will flag opposing sides as true instead of just one side + + boolean distanceCheckWest= (inn.getBlockX()-too.getBlockX()<=distance && + inn.getBlockX()-too.getBlockX()>0 && + too.getBlockY()-inn.getBlockY()==0 && + too.getBlockZ()-inn.getBlockZ()==0); + + boolean distanceCheckNorth=(inn.getBlockZ()-too.getBlockZ()<=distance && + inn.getBlockZ()-too.getBlockZ()>0 && + too.getBlockY()-inn.getBlockY()==0 && + too.getBlockX()-inn.getBlockX()==0); + + boolean distanceCheckSouth=(too.getBlockZ()-inn.getBlockZ()<=distance && + too.getBlockZ()-inn.getBlockZ()>0 && + too.getBlockY()-inn.getBlockY()==0 && + too.getBlockX()-inn.getBlockX()==0); + + boolean distanceCheckAbove=(too.getBlockY()-inn.getBlockY()<=distance && + too.getBlockY()-inn.getBlockY()>0 && + too.getBlockX()-inn.getBlockX()==0 && + too.getBlockZ()-inn.getBlockZ()==0); + + boolean distanceCheckBelow=(inn.getBlockY()-too.getBlockY()<=distance && + inn.getBlockY()-too.getBlockY()>0 && + too.getBlockX()-inn.getBlockX()==0 && + too.getBlockZ()-inn.getBlockZ()==0); + + boolean axisDistance = (distanceCheckEast&&!directionAim[1]&&!directionAim[2]&&!directionAim[3]&&!directionAim[4]&&!directionAim[5]) + || (distanceCheckWest&&!directionAim[0]&&!directionAim[2]&&!directionAim[3]&&!directionAim[4]&&!directionAim[5]) + || (distanceCheckNorth&&!directionAim[1]&&!directionAim[0]&&!directionAim[3]&&!directionAim[4]&&!directionAim[5]) + || (distanceCheckSouth&&!directionAim[1]&&!directionAim[2]&&!directionAim[0]&&!directionAim[4]&&!directionAim[5]) + || (distanceCheckAbove&&!directionAim[1]&&!directionAim[2]&&!directionAim[3]&&!directionAim[0]&&!directionAim[5]) + || (distanceCheckBelow&&!directionAim[1]&&!directionAim[2]&&!directionAim[3]&&!directionAim[4]&&!directionAim[0]); + if (axisDistance) return true; + } + return false; + } - + private int getMaxIdDistance() { + Object oMaxDist = RCPrefs.getPref("playerid.maxDistance"); + if (oMaxDist != null && oMaxDist instanceof Integer) return (Integer)oMaxDist; + else return -1; + } + @Override public void shutdown() { - SensorLibrary.deregisterPlayeridCircuit(this); + SensorLibrary.eventDispatcher.unregisterListener(moveListener); + } + @Override + public void disable() { + SensorLibrary.eventDispatcher.unregisterListener(moveListener); + } + @Override + public void destroyed(){ + SensorLibrary.eventDispatcher.unregisterListener(moveListener); } } -*/ \ No newline at end of file diff --git a/src/main/java/org/redstonechips/sensorlibrary/rangefinder.java b/src/main/java/org/redstonechips/sensorlibrary/rangefinder.java index 5c7805c..7af3e85 100755 --- a/src/main/java/org/redstonechips/sensorlibrary/rangefinder.java +++ b/src/main/java/org/redstonechips/sensorlibrary/rangefinder.java @@ -167,7 +167,7 @@ private void trigger() { for (int z = corner1.getBlockZ(); z<=corner2.getBlockZ(); z++) { Material type = chip.world.getBlockAt(x, y, z).getType(); - if (type!=Material.AIR && type!=Material.WATER && type!=Material.STATIONARY_WATER) { + if (type!=Material.AIR && type!=Material.WATER) { objectsInRange.add(Locations.getFaceCenter(chip.world, x,y,z, oppositeFace)); } @@ -199,6 +199,10 @@ private void trigger() { case NORTH: lp.add(0,0,-0.2); break; + default: + break; + + } objectsInRange.add(lp); } else { diff --git a/src/main/java/org/redstonechips/sensorlibrary/vehicleid.java b/src/main/java/org/redstonechips/sensorlibrary/vehicleid.java index f8ce05b..2abe456 100755 --- a/src/main/java/org/redstonechips/sensorlibrary/vehicleid.java +++ b/src/main/java/org/redstonechips/sensorlibrary/vehicleid.java @@ -1,78 +1,222 @@ -/* + package org.redstonechips.sensorlibrary; import org.bukkit.Location; +import org.bukkit.event.Event; import org.bukkit.event.vehicle.VehicleMoveEvent; +import org.redstonechips.RCPrefs; import org.redstonechips.circuit.Circuit; +import org.redstonechips.event.EventListener; -/** +/* * * @author Tal Eisenberg - *//* + */ public class vehicleid extends Circuit { private final int resetPin = 1; private final int disablePin = 0; private boolean pinDisabled = false; private int lastInterface = -1; + private byte distance = 1; + private boolean sphere = false; + + private Boolean[] directionAim = new Boolean[] { + false, + false, + false, + false, + false, + false, + }; + + private static final String[] directionText = new String[] { + "EAST", + "WEST", + "NORTH", + "SOUTH", + "ABOVE", + "BELOW", + }; @Override public void input(boolean state, int inIdx) { if (inIdx==resetPin && state) { for (int i=0; i0) { + for (byte i=0; imaxIdDistance) return error("Maximum distance exceeded: " + args[i] + ". The maximum distance is " + maxIdDistance + ". Set vehicleid.maxdistance in preferences.yml to extend the maximum distance."); + + } catch (NumberFormatException ne2) { + return error("Bad distance argument: " + args[i] + ". Expecting a number between 1 and " + maxIdDistance); + } + } + else if (args[i].toUpperCase().equals("SPHERE")) sphere = true; + else if (args[i].toUpperCase().equals("AXIS")) sphere = false; + for (byte j=0; j<=5; j++) { + if (args[i].toUpperCase().equals(directionText[j])) { // if sign arg is a direction, mark that direction as true + directionAim[j] = true; + } + } + } + } + } + SensorLibrary.eventDispatcher.registerListener(VehicleMoveEvent.class, moveListener); return this; } - void onVehicleMove(VehicleMoveEvent event) { - if (pinDisabled) return; - - Location to = event.getTo(); - boolean found = false; - - for (int i=0; i0 && + Math.abs(too.getBlockY()-inn.getBlockY())<=distance && + Math.abs(too.getBlockZ()-inn.getBlockZ())<=distance); + boolean distanceSphereEast = (too.getBlockX()-inn.getBlockX()<=distance && + too.getBlockX()-inn.getBlockX()>0 && + Math.abs(too.getBlockY()-inn.getBlockY())<=distance && + Math.abs(too.getBlockZ()-inn.getBlockZ())<=distance); + boolean distanceSphereNorth = (inn.getBlockZ()-too.getBlockZ()<=distance && + inn.getBlockZ()-too.getBlockZ()>0 && + Math.abs(too.getBlockY()-inn.getBlockY())<=distance && + Math.abs(too.getBlockX()-inn.getBlockX())<=distance); + boolean distanceSphereSouth = (too.getBlockZ()-inn.getBlockZ()<=distance && + too.getBlockZ()-inn.getBlockZ()>0 && + Math.abs(too.getBlockY()-inn.getBlockY())<=distance && + Math.abs(too.getBlockX()-inn.getBlockX())<=distance); + boolean distanceSphereAbove = (too.getBlockY()-inn.getBlockY()<=distance && + too.getBlockY()-inn.getBlockY()>0 && + Math.abs(too.getBlockZ()-inn.getBlockZ())<=distance && + Math.abs(too.getBlockX()-inn.getBlockX())<=distance); + boolean distanceSphereBelow = (inn.getBlockY()-too.getBlockY()<=distance && + inn.getBlockY()-too.getBlockY()>0 && + Math.abs(too.getBlockZ()-inn.getBlockZ())<=distance && + Math.abs(too.getBlockX()-inn.getBlockX())<=distance); + boolean distanceSphere = (distanceSphereEast&&!directionAim[1]&&!directionAim[2]&&!directionAim[3]&&!directionAim[4]&&!directionAim[5]) + || (distanceSphereWest&&!directionAim[0]&&!directionAim[2]&&!directionAim[3]&&!directionAim[4]&&!directionAim[5]) + || (distanceSphereNorth&&!directionAim[1]&&!directionAim[0]&&!directionAim[3]&&!directionAim[4]&&!directionAim[5]) + || (distanceSphereSouth&&!directionAim[1]&&!directionAim[2]&&!directionAim[0]&&!directionAim[4]&&!directionAim[5]) + || (distanceSphereAbove&&!directionAim[1]&&!directionAim[2]&&!directionAim[3]&&!directionAim[0]&&!directionAim[5]) + || (distanceSphereBelow&&!directionAim[1]&&!directionAim[2]&&!directionAim[3]&&!directionAim[4]&&!directionAim[0]); + if (distanceSphere) return true; + } + else { + boolean distanceCheckEast= (too.getBlockX()-inn.getBlockX()<=distance && + too.getBlockX()-inn.getBlockX()>0 && + too.getBlockY()-inn.getBlockY()==0 && + too.getBlockZ()-inn.getBlockZ()==0); // can not use ABS as it will flag opposing sides as true instead of just one side + + boolean distanceCheckWest= (inn.getBlockX()-too.getBlockX()<=distance && + inn.getBlockX()-too.getBlockX()>0 && + too.getBlockY()-inn.getBlockY()==0 && + too.getBlockZ()-inn.getBlockZ()==0); + + boolean distanceCheckNorth=(inn.getBlockZ()-too.getBlockZ()<=distance && + inn.getBlockZ()-too.getBlockZ()>0 && + too.getBlockY()-inn.getBlockY()==0 && + too.getBlockX()-inn.getBlockX()==0); + + boolean distanceCheckSouth=(too.getBlockZ()-inn.getBlockZ()<=distance && + too.getBlockZ()-inn.getBlockZ()>0 && + too.getBlockY()-inn.getBlockY()==0 && + too.getBlockX()-inn.getBlockX()==0); + + boolean distanceCheckAbove=(too.getBlockY()-inn.getBlockY()<=distance && + too.getBlockY()-inn.getBlockY()>0 && + too.getBlockX()-inn.getBlockX()==0 && + too.getBlockZ()-inn.getBlockZ()==0); + + boolean distanceCheckBelow=(inn.getBlockY()-too.getBlockY()<=distance && + inn.getBlockY()-too.getBlockY()>0 && + too.getBlockX()-inn.getBlockX()==0 && + too.getBlockZ()-inn.getBlockZ()==0); + + boolean axisDistance = (distanceCheckEast&&!directionAim[1]&&!directionAim[2]&&!directionAim[3]&&!directionAim[4]&&!directionAim[5]) + || (distanceCheckWest&&!directionAim[0]&&!directionAim[2]&&!directionAim[3]&&!directionAim[4]&&!directionAim[5]) + || (distanceCheckNorth&&!directionAim[1]&&!directionAim[0]&&!directionAim[3]&&!directionAim[4]&&!directionAim[5]) + || (distanceCheckSouth&&!directionAim[1]&&!directionAim[2]&&!directionAim[0]&&!directionAim[4]&&!directionAim[5]) + || (distanceCheckAbove&&!directionAim[1]&&!directionAim[2]&&!directionAim[3]&&!directionAim[0]&&!directionAim[5]) + || (distanceCheckBelow&&!directionAim[1]&&!directionAim[2]&&!directionAim[3]&&!directionAim[4]&&!directionAim[0]); + if (axisDistance) return true; + } + return false; + + } + private int getMaxIdDistance() { + Object oMaxDist = RCPrefs.getPref("vehicleid.maxDistance"); + if (oMaxDist != null && oMaxDist instanceof Integer) return (Integer)oMaxDist; + else return -1; } @Override public void shutdown() { - SensorLibrary.deregisterVehicleidCircuit(this); + SensorLibrary.eventDispatcher.unregisterListener(moveListener); + } + @Override + public void disable() { + SensorLibrary.eventDispatcher.unregisterListener(moveListener); + } + @Override + public void destroyed(){ + SensorLibrary.eventDispatcher.unregisterListener(moveListener); } } -*/ \ No newline at end of file