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

move things around, rename a bit

parent f7944286
No related merge requests found
Showing with 76 additions and 11 deletions
+76 -11
......@@ -2,22 +2,40 @@ package edu.caltech.cs001;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.entity.EntityType;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.plugin.java.JavaPlugin;
public abstract class CaltechMinecraftEvent implements Listener {
public class CaltechMinecraftMod implements Listener {
private final JavaPlugin plugin;
public CaltechMinecraftEvent(JavaPlugin plugin) {
public CaltechMinecraftMod(JavaPlugin 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
public void onBucketEmptySynced(PlayerBucketEmptyEvent event) {
......
......@@ -3,19 +3,19 @@ package edu.caltech.cs001;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class SparklerEvent extends CaltechMinecraftEvent {
private void onBucketEmpty(PlayerBucketEmptyEvent event) {
Block block = event.getBlock();
if (isPond(block)) {
destroyPond(block);
spawnTurtle(block.getWorld(), block.getLocation());
}
public class IDidntNeedThatAnywayMod extends CaltechMinecraftMod {
public IDidntNeedThatAnywayMod(JavaPlugin plugin) { super(plugin); }
protected void onDropItem(PlayerDropItemEvent event) {
Item item = event.getItemDrop();
item.remove();
}
}
......@@ -15,6 +15,6 @@ public class MainPlugin extends JavaPlugin {
@Override
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;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
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.
*
......@@ -29,16 +31,13 @@ public class TurtleSpawnerEvent extends CaltechMinecraftEvent {
}
/**
* Spawns a turtle in `world` at `location`.
**/
private void spawnTurtle(World world, Location loc) {
// TODO: Implement me!
}
/**
* TODO put docs here
* 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
* the pond was.
*
* Hint: This method should use the other two methods you wrote above!
**/
private void onBucketEmpty(PlayerBucketEmptyEvent event) {
protected void onBucketEmpty(PlayerBucketEmptyEvent event) {
// 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