Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs1-24fa
final
Commits
87ec95fe
Commit
87ec95fe
authored
6 months ago
by
Adam Blank
Browse files
Options
Download
Email Patches
Plain Diff
move things around, rename a bit
parent
f7944286
master
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/main/java/edu/caltech/cs001/CaltechMinecraftMod.java
+45
-0
src/main/java/edu/caltech/cs001/CaltechMinecraftMod.java
src/main/java/edu/caltech/cs001/IDidntNeedThatAnywayMod.java
+21
-0
src/main/java/edu/caltech/cs001/IDidntNeedThatAnywayMod.java
src/main/java/edu/caltech/cs001/MainPlugin.java
+1
-1
src/main/java/edu/caltech/cs001/MainPlugin.java
src/main/java/edu/caltech/cs001/TurtlePondMod.java
+9
-10
src/main/java/edu/caltech/cs001/TurtlePondMod.java
with
76 additions
and
11 deletions
+76
-11
src/main/java/edu/caltech/cs001/CaltechMinecraft
Event
.java
→
src/main/java/edu/caltech/cs001/CaltechMinecraft
Mod
.java
View file @
87ec95fe
...
...
@@ -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
CaltechMinecraft
Event
implements
Listener
{
public
class
CaltechMinecraft
Mod
implements
Listener
{
private
final
JavaPlugin
plugin
;
public
CaltechMinecraft
Event
(
JavaPlugin
plugin
)
{
public
CaltechMinecraft
Mod
(
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
)
{
...
...
This diff is collapsed.
Click to expand it.
src/main/java/edu/caltech/cs001/
SparklerEvent
.java
→
src/main/java/edu/caltech/cs001/
IDidntNeedThatAnywayMod
.java
View file @
87ec95fe
...
...
@@ -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.Player
BucketEmpty
Event
;
import
org.bukkit.event.player.Player
DropItem
Event
;
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
();
}
}
This diff is collapsed.
Click to expand it.
src/main/java/edu/caltech/cs001/MainPlugin.java
View file @
87ec95fe
...
...
@@ -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
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/edu/caltech/cs001/Turtle
SpawnerEvent
.java
→
src/main/java/edu/caltech/cs001/Turtle
PondMod
.java
View file @
87ec95fe
...
...
@@ -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!
**/
pr
ivate
void
onBucketEmpty
(
PlayerBucketEmptyEvent
event
)
{
pr
otected
void
onBucketEmpty
(
PlayerBucketEmptyEvent
event
)
{
// TODO: Implement me!
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help