# HG changeset patch # User jrvanwhy # Date 1316904330 25200 # Node ID f159d9d175899e5f5f5ac45af87412c2d9cdfffc If I'm doing this right, then this is committing the project to BukkitDev. diff -r 000000000000 -r f159d9d17589 build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/build.xml Sat Sep 24 15:45:30 2011 -0700 @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project WaterMonster. + + + diff -r 000000000000 -r f159d9d17589 manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/manifest.mf Sat Sep 24 15:45:30 2011 -0700 @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff -r 000000000000 -r f159d9d17589 nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nbproject/build-impl.xml Sat Sep 24 15:45:30 2011 -0700 @@ -0,0 +1,883 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 000000000000 -r f159d9d17589 nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nbproject/genfiles.properties Sat Sep 24 15:45:30 2011 -0700 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=aa5bb499 +build.xml.script.CRC32=dff47a48 +build.xml.stylesheet.CRC32=28e38971@1.38.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=aa5bb499 +nbproject/build-impl.xml.script.CRC32=25a3bc88 +nbproject/build-impl.xml.stylesheet.CRC32=78c6a6ee@1.38.1.45 diff -r 000000000000 -r f159d9d17589 nbproject/private/private.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nbproject/private/private.properties Sat Sep 24 15:45:30 2011 -0700 @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=/home/ryan/.netbeans/6.9/build.properties diff -r 000000000000 -r f159d9d17589 nbproject/private/private.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nbproject/private/private.xml Sat Sep 24 15:45:30 2011 -0700 @@ -0,0 +1,4 @@ + + + + diff -r 000000000000 -r f159d9d17589 nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nbproject/project.properties Sat Sep 24 15:45:30 2011 -0700 @@ -0,0 +1,75 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=WaterMonster +application.vendor=ryan +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/WaterMonster.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +file.reference.bukkit-0.0.1-SNAPSHOT.jar=/home/ryan/bukkitdev/bukkit-0.0.1-SNAPSHOT.jar +includes=** +jar.compress=true +javac.classpath=\ + ${file.reference.bukkit-0.0.1-SNAPSHOT.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class= +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff -r 000000000000 -r f159d9d17589 nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nbproject/project.xml Sat Sep 24 15:45:30 2011 -0700 @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + WaterMonster + + + + + + + + + diff -r 000000000000 -r f159d9d17589 src/net/jrvanwhy/watermonster/WaterEntity.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/jrvanwhy/watermonster/WaterEntity.java Sat Sep 24 15:45:30 2011 -0700 @@ -0,0 +1,184 @@ +package net.jrvanwhy.watermonster; + +import java.util.List; +import org.bukkit.Bukkit; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Animals; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; + +public class WaterEntity implements Runnable { + WaterMonster plugin; + boolean active = false; + Location position = null; + double soundTimer = 1.0; + LivingEntity target = null; + + static final int MonsterDamage = 1; + + public WaterEntity(WaterMonster instance) { + plugin = instance; + } + + public Player findNearestPlayer(Location location) { + Player[] players = Bukkit.getServer().getOnlinePlayers(); + Player closestPlayer = null; + double closestDist = -1.0; + + for (int i = 0; i < players.length; i++) { + if (closestDist < 0.0 || + players[i].getLocation().distance(location) < closestDist) { + closestPlayer = players[i]; + closestDist = closestPlayer.getLocation().distance(location); + } + } + return closestPlayer; + } + + public LivingEntity findNearestEntityInWater(Location location) { + List entities = location.getWorld().getLivingEntities(); + LivingEntity closestEntity = null; + double closestDist = -1.0; + + for (int i = 0; i < entities.size(); i++) { + if (entities.get(i).getLocation().getBlockY() == 63 && + entities.get(i).getLocation().getBlock().getType() + .equals(Material.STATIONARY_WATER) && + (closestDist < 0.0 || + entities.get(i).getLocation() + .distance(location) < closestDist)/* && + !(entities.get(i) instanceof Animals)*/) { + + closestEntity = entities.get(i); + closestDist = entities.get(i).getLocation().distance(location); + } + } + return closestEntity; + } + + public void activate(Player player) { + int relx = (int) Math.round(Math.random()*20.0-10.0); + int relz = 10 - Math.abs(relx); + relz *= Math.signum(Math.random()-0.5); + Location location = player.getLocation().clone().add(relx, 0, relz); + location.setY(63.0); + if (location.getBlock().getType().equals(Material.STATIONARY_WATER)) { + soundTimer = 1.0; + placeMonster(location); + target = player; + registerTimer(); + active = true; + } + } + + private void registerTimer() { + plugin.getServer().getScheduler().scheduleSyncRepeatingTask + (plugin, this, 40, 20); + } + + private Location dirTo(Location a, Location b) { + Location result = b.clone().subtract(a); + result.setY(0.0); + if (Math.abs(result.getX()) > Math.abs(result.getZ())) { + result.setZ(0); + result.setX(Math.signum(result.getX())); + } else { + result.setX(0); + result.setZ(Math.signum(result.getZ())); + } + return result; + } + + private Location dirTo2(Location a, Location b) { + Location result = b.clone().subtract(a); + result.setY(0.0); + if (Math.abs(result.getX()) < Math.abs(result.getZ())) { + result.setZ(0); + result.setX(Math.signum(result.getX())); + } else { + result.setX(0); + result.setZ(Math.signum(result.getZ())); + } + return result; + } + + public void run() { + if (!active) return; + Player closestPlayer = findNearestPlayer(position); + if (closestPlayer == null || + closestPlayer.getLocation().distance(position) > 100) { + kill(); + return; + } + if (target.getLocation().distance(position) > 5.0 || + target.getLocation().getY() > 65.0) { + target = null; + } + + if (target == null || target.isDead()) { + target = findNearestEntityInWater(position); + } + + if (target == null || + target.getLocation().distance(position) > 100.0) { + + target = closestPlayer; + } + if (target.getLocation().distance(position) < 1.0) { + target.damage(MonsterDamage); + return; + } + double moveDist = 0.0; + int tries = 10; + for (int i = 0; i < 4; i++) { + moveDist += Math.random(); + } + Location loc = position.clone(); + while (tries > 0 && loc.distance(position) < moveDist) { + tries--; + Location newLoc = loc.clone().add(dirTo(loc, target.getLocation())); + if (newLoc.getBlock().getType().equals(Material.STATIONARY_WATER)) { + loc = newLoc; + } else { + newLoc = loc.clone().add( + dirTo2(loc, target.getLocation())); + if (newLoc.getBlock().getType(). + equals(Material.STATIONARY_WATER)) { + loc = newLoc; + } + } + } + if (!loc.equals(position)) moveMonster(loc); + if (target.getLocation().distance(position) < 1.0) { + target.damage(MonsterDamage); + } + } + + private void placeMonster(Location location) { + position = location; + position.getBlock().setType(Material.AIR); + } + + private void removeMonster() { + position.getBlock().setType(Material.STATIONARY_WATER); + } + + private void moveMonster(Location location) { + removeMonster(); + placeMonster(location); + soundTimer += Math.random(); + if (soundTimer >= 1.0) { + soundTimer -= 1.0; + position.getWorld().playEffect(position, Effect.STEP_SOUND, 8); + } + } + + public void kill() { + plugin.getServer().getScheduler().cancelTasks(plugin); + if (position != null) removeMonster(); + active = false; + position = null; + } +} \ No newline at end of file diff -r 000000000000 -r f159d9d17589 src/net/jrvanwhy/watermonster/WaterMonster.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/jrvanwhy/watermonster/WaterMonster.java Sat Sep 24 15:45:30 2011 -0700 @@ -0,0 +1,33 @@ +package net.jrvanwhy.watermonster; + +import java.util.logging.Logger; +import org.bukkit.event.Event; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +public class WaterMonster extends JavaPlugin { + static final Logger log = Logger.getLogger("Minecraft"); + + private final WaterMonsterPlayerListener playerListener = + new WaterMonsterPlayerListener(this); + + private final WaterMonsterWaterListener waterListener = + new WaterMonsterWaterListener(this); + + WaterEntity monster; + + public void onEnable() { + PluginManager pm = this.getServer().getPluginManager(); + pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, + Event.Priority.Normal, this); + pm.registerEvent(Event.Type.BLOCK_FROMTO, waterListener, + Event.Priority.Normal, this); + monster = new WaterEntity(this); + log.info("WaterMonster enabled"); + } + + public void onDisable() { + monster.kill(); + log.info("WaterMonster disabled"); + } +} \ No newline at end of file diff -r 000000000000 -r f159d9d17589 src/net/jrvanwhy/watermonster/WaterMonsterPlayerListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/jrvanwhy/watermonster/WaterMonsterPlayerListener.java Sat Sep 24 15:45:30 2011 -0700 @@ -0,0 +1,22 @@ +package net.jrvanwhy.watermonster; + +import org.bukkit.Material; +import org.bukkit.event.player.PlayerListener; +import org.bukkit.event.player.PlayerMoveEvent; + +public class WaterMonsterPlayerListener extends PlayerListener { + public static WaterMonster plugin; + + public WaterMonsterPlayerListener(WaterMonster instance) { + plugin = instance; + } + + @Override + public void onPlayerMove(PlayerMoveEvent event) { + if (!plugin.monster.active && + event.getTo().getBlockY() == 63 && + event.getTo().getBlock().getType().equals(Material.STATIONARY_WATER)) { + plugin.monster.activate(event.getPlayer()); + } + } +} \ No newline at end of file diff -r 000000000000 -r f159d9d17589 src/net/jrvanwhy/watermonster/WaterMonsterWaterListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/jrvanwhy/watermonster/WaterMonsterWaterListener.java Sat Sep 24 15:45:30 2011 -0700 @@ -0,0 +1,26 @@ +package net.jrvanwhy.watermonster; + +import org.bukkit.event.block.BlockFromToEvent; +import org.bukkit.event.block.BlockListener; + +public class WaterMonsterWaterListener extends BlockListener { + WaterMonster plugin; + + public WaterMonsterWaterListener(WaterMonster instance) { + plugin = instance; + } + + @Override + public void onBlockFromTo(BlockFromToEvent event) { + if (plugin.monster.position != null && + plugin.monster.position.getWorld().equals( + event.getToBlock().getWorld()) && + event.getToBlock().getLocation(). + distance(plugin.monster.position) < 1.5) { + + event.setCancelled(true); + return; + } + event.setCancelled(false); + } +} \ No newline at end of file diff -r 000000000000 -r f159d9d17589 src/plugin.yml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/plugin.yml Sat Sep 24 15:45:30 2011 -0700 @@ -0,0 +1,3 @@ +name: WaterMonster +main: net.jrvanwhy.watermonster.WaterMonster +version: 1.0 \ No newline at end of file