Commit 87ec95fe authored by Adam Blank's avatar Adam Blank
Browse files

move things around, rename a bit

parent f7944286
Showing with 76 additions and 11 deletions
+76 -11
...@@ -2,22 +2,40 @@ package edu.caltech.cs001; ...@@ -2,22 +2,40 @@ package edu.caltech.cs001;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public abstract class CaltechMinecraftEvent implements Listener { public class CaltechMinecraftMod implements Listener {
private final JavaPlugin plugin; private final JavaPlugin plugin;
public CaltechMinecraftEvent(JavaPlugin plugin) { public CaltechMinecraftMod(JavaPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
private abstract void onBucketEmpty(PlayerBucketEmptyEvent event); protected void onDropItem(PlayerDropItemEvent event) {}
protected void onBucketEmpty(PlayerBucketEmptyEvent event) {}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
player.setOp(true);
}
@EventHandler // tagging with @EventHandler will make Minecraft listen to this method
public void onDropItemSynced(PlayerDropItemEvent event) {
// We are just making sure all the code in onDropItem() happens at the same time.
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, () -> this.onDropItem(event), 1);
}
@EventHandler // tagging with @EventHandler will make Minecraft listen to this method @EventHandler // tagging with @EventHandler will make Minecraft listen to this method
public void onBucketEmptySynced(PlayerBucketEmptyEvent event) { public void onBucketEmptySynced(PlayerBucketEmptyEvent event) {
......
...@@ -3,19 +3,19 @@ package edu.caltech.cs001; ...@@ -3,19 +3,19 @@ package edu.caltech.cs001;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public class SparklerEvent extends CaltechMinecraftEvent { public class IDidntNeedThatAnywayMod extends CaltechMinecraftMod {
private void onBucketEmpty(PlayerBucketEmptyEvent event) { public IDidntNeedThatAnywayMod(JavaPlugin plugin) { super(plugin); }
Block block = event.getBlock();
if (isPond(block)) { protected void onDropItem(PlayerDropItemEvent event) {
destroyPond(block); Item item = event.getItemDrop();
spawnTurtle(block.getWorld(), block.getLocation()); item.remove();
}
} }
} }
...@@ -15,6 +15,6 @@ public class MainPlugin extends JavaPlugin { ...@@ -15,6 +15,6 @@ public class MainPlugin extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
this.manager.registerEvents(new SparklerEvent(this), this); this.manager.registerEvents(new IDidntNeedThatAnywayMod(this), this);
} }
} }
...@@ -10,7 +10,9 @@ import org.bukkit.event.Listener; ...@@ -10,7 +10,9 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public class TurtleSpawnerEvent extends CaltechMinecraftEvent { public class TurtlePondMod extends CaltechMinecraftMod {
public TurtlePondMod(JavaPlugin plugin) { super(plugin); }
/** /**
* Checks if the block `centerBlock` is a water block in the middle of a pond of Material.STONE. * Checks if the block `centerBlock` is a water block in the middle of a pond of Material.STONE.
* *
...@@ -29,16 +31,13 @@ public class TurtleSpawnerEvent extends CaltechMinecraftEvent { ...@@ -29,16 +31,13 @@ public class TurtleSpawnerEvent extends CaltechMinecraftEvent {
} }
/** /**
* Spawns a turtle in `world` at `location`. * When a player empties a bucket (in this case, a water bucket) into the middle of
**/ * a pond, this method (1) deletes the pond, and (2) spawns an EntityType.TURTLE where
private void spawnTurtle(World world, Location loc) { * the pond was.
// TODO: Implement me! *
} * Hint: This method should use the other two methods you wrote above!
/**
* TODO put docs here
**/ **/
private void onBucketEmpty(PlayerBucketEmptyEvent event) { protected void onBucketEmpty(PlayerBucketEmptyEvent event) {
// TODO: Implement me! // TODO: Implement me!
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment