Skip to content

Commit

Permalink
Add player_bucket_fill and player_bucket_empty events. (#1387)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lildirt authored Jul 19, 2024
1 parent 17906e0 commit af10139
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
import com.laytonsmith.abstraction.MCWorld;
import com.laytonsmith.abstraction.blocks.MCBlock;
import com.laytonsmith.abstraction.blocks.MCBlockFace;
import com.laytonsmith.abstraction.blocks.MCMaterial;
import com.laytonsmith.abstraction.bukkit.BukkitConvertor;
import com.laytonsmith.abstraction.bukkit.BukkitMCBookMeta;
import com.laytonsmith.abstraction.bukkit.BukkitMCItemStack;
import com.laytonsmith.abstraction.bukkit.BukkitMCLocation;
import com.laytonsmith.abstraction.bukkit.BukkitMCWorld;
import com.laytonsmith.abstraction.bukkit.blocks.BukkitMCBlock;
import com.laytonsmith.abstraction.bukkit.blocks.BukkitMCMaterial;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCFishHook;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCHumanEntity;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCPlayer;
Expand All @@ -38,6 +40,9 @@
import com.laytonsmith.abstraction.events.MCExpChangeEvent;
import com.laytonsmith.abstraction.events.MCFoodLevelChangeEvent;
import com.laytonsmith.abstraction.events.MCGamemodeChangeEvent;
import com.laytonsmith.abstraction.events.MCPlayerBucketEmptyEvent;
import com.laytonsmith.abstraction.events.MCPlayerBucketEvent;
import com.laytonsmith.abstraction.events.MCPlayerBucketFillEvent;
import com.laytonsmith.abstraction.events.MCPlayerEnterBedEvent;
import com.laytonsmith.abstraction.events.MCPlayerLeaveBedEvent;
import com.laytonsmith.abstraction.events.MCPlayerChatEvent;
Expand Down Expand Up @@ -75,6 +80,9 @@
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerEditBookEvent;
Expand Down Expand Up @@ -1072,4 +1080,71 @@ public void setCancelled(boolean bln) {
pme.setCancelled(bln);
}
}


@abstraction(type = Implementation.Type.BUKKIT)
public abstract static class BukkitMCPlayerBucketEvent extends BukkitMCPlayerEvent implements MCPlayerBucketEvent {

PlayerBucketEvent pbe;

public BukkitMCPlayerBucketEvent(PlayerBucketEvent event) {
super(event);
this.pbe = event;
}

@Override
public MCBlock getBlock() {
return new BukkitMCBlock(pbe.getBlock());
}

@Override
public MCBlock getBlockClicked() {
return new BukkitMCBlock(pbe.getBlockClicked());
}

@Override
public MCBlockFace getBlockFace() {
return MCBlockFace.valueOf(pbe.getBlockFace().name());
}

@Override
public MCMaterial getBucket() {
return new BukkitMCMaterial(pbe.getBucket());
}

@Override
public MCEquipmentSlot getHand() {
if(pbe.getHand() == EquipmentSlot.HAND) {
return MCEquipmentSlot.WEAPON;
}
return MCEquipmentSlot.OFF_HAND;
}

@Override
public MCItemStack getItemStack() {
return new BukkitMCItemStack(pbe.getItemStack());
}
}

@abstraction(type = Implementation.Type.BUKKIT)
public static class BukkitMCPlayerBucketFillEvent extends BukkitMCPlayerBucketEvent implements MCPlayerBucketFillEvent {

PlayerBucketFillEvent pbfe;

public BukkitMCPlayerBucketFillEvent(PlayerBucketFillEvent event) {
super(event);
this.pbfe = event;
}
}

@abstraction(type = Implementation.Type.BUKKIT)
public static class BukkitMCPlayerBucketEmptyEvent extends BukkitMCPlayerBucketEvent implements MCPlayerBucketEmptyEvent {

PlayerBucketEmptyEvent pbee;

public BukkitMCPlayerBucketEmptyEvent(PlayerBucketEmptyEvent event) {
super(event);
this.pbee = event;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.laytonsmith.abstraction.bukkit.events.BukkitPlayerEvents.BukkitMCExpChangeEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitPlayerEvents.BukkitMCFoodLevelChangeEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitPlayerEvents.BukkitMCGamemodeChangeEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitPlayerEvents.BukkitMCPlayerBucketEmptyEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitPlayerEvents.BukkitMCPlayerBucketFillEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitPlayerEvents.BukkitMCPlayerEnterBedEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitPlayerEvents.BukkitMCPlayerLeaveBedEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitPlayerEvents.BukkitMCPlayerChatEvent;
Expand Down Expand Up @@ -40,6 +42,8 @@
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerEditBookEvent;
import org.bukkit.event.player.PlayerExpChangeEvent;
Expand Down Expand Up @@ -369,4 +373,16 @@ public void onNewTeleportLocation(PlayerTeleportEvent event) {
}
}
}

@EventHandler(priority = EventPriority.LOWEST)
public void onBucketFill(PlayerBucketFillEvent event) {
BukkitMCPlayerBucketFillEvent pbfe = new BukkitMCPlayerBucketFillEvent(event);
EventUtils.TriggerListener(Driver.PLAYER_BUCKET_FILL, "player_bucket_fill", pbfe);
}

@EventHandler(priority = EventPriority.LOWEST)
public void onBucketEmpty(PlayerBucketEmptyEvent event) {
BukkitMCPlayerBucketEmptyEvent pbee = new BukkitMCPlayerBucketEmptyEvent(event);
EventUtils.TriggerListener(Driver.PLAYER_BUCKET_EMPTY, "player_bucket_empty", pbee);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.laytonsmith.abstraction.events;

public interface MCPlayerBucketEmptyEvent extends MCPlayerEvent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.laytonsmith.abstraction.events;

import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.blocks.MCBlock;
import com.laytonsmith.abstraction.blocks.MCBlockFace;
import com.laytonsmith.abstraction.blocks.MCMaterial;
import com.laytonsmith.abstraction.enums.MCEquipmentSlot;

public interface MCPlayerBucketEvent extends MCPlayerEvent {
MCBlock getBlock();

MCBlock getBlockClicked();

MCBlockFace getBlockFace();

MCMaterial getBucket();

MCEquipmentSlot getHand();

MCItemStack getItemStack();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.laytonsmith.abstraction.events;

public interface MCPlayerBucketFillEvent extends MCPlayerEvent {
}
2 changes: 2 additions & 0 deletions src/main/java/com/laytonsmith/core/events/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public enum Driver {
GAMEMODE_CHANGE,
PLAYER_ENTER_BED,
PLAYER_LEAVE_BED,
PLAYER_BUCKET_FILL,
PLAYER_BUCKET_EMPTY,
PLAYER_CHAT,
PLAYER_COMMAND,
PLAYER_CONSUME,
Expand Down
110 changes: 110 additions & 0 deletions src/main/java/com/laytonsmith/core/events/drivers/PlayerEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.laytonsmith.abstraction.events.MCExpChangeEvent;
import com.laytonsmith.abstraction.events.MCFoodLevelChangeEvent;
import com.laytonsmith.abstraction.events.MCGamemodeChangeEvent;
import com.laytonsmith.abstraction.events.MCPlayerBucketEvent;
import com.laytonsmith.abstraction.events.MCPlayerEnterBedEvent;
import com.laytonsmith.abstraction.events.MCPlayerLeaveBedEvent;
import com.laytonsmith.abstraction.events.MCPlayerChatEvent;
Expand Down Expand Up @@ -2784,4 +2785,113 @@ public BindableEvent convert(CArray manualObject, Target t) {
return null;
}
}

public abstract static class player_bucket_event extends AbstractEvent {

@Override
public boolean matches(Map<String, Mixed> prefilter, BindableEvent e) throws PrefilterNonMatchException {
if(e instanceof MCPlayerBucketEvent) {
return true;
}
return false;
}

@Override
public BindableEvent convert(CArray manualObject, Target t) {
throw ConfigRuntimeException.CreateUncatchableException("Unsupported operation.", Target.UNKNOWN);
}

@Override
public boolean modifyEvent(String key, Mixed value, BindableEvent e) {
return false;
}

@Override
public Map<String, Mixed> evaluate(BindableEvent event) throws EventException {
if(event instanceof MCPlayerBucketEvent e) {
Map<String, Mixed> ret = evaluate_helper(e);
Target t = Target.UNKNOWN;

ret.put("player", new CString(e.getPlayer().getName(), t));
ret.put("location", ObjectGenerator.GetGenerator().location(e.getBlock().getLocation(), false));

if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_19_2)) {
if(e.getHand() == MCEquipmentSlot.WEAPON) {
ret.put("hand", new CString("main_hand", t));
} else {
ret.put("hand", new CString("off_hand", t));
}
}
ret.put("item", ObjectGenerator.GetGenerator().item(e.getItemStack(), t));

return ret;
} else {
throw new EventException("Event received was not an MCPlayerBucketEvent.");
}
}
}

@api
public static class player_bucket_fill extends player_bucket_event {

@Override
public String getName() {
return "player_bucket_fill";
}

@Override
public String docs() {
return "{} "
+ "Fired when a player fills a bucket in their hand from the world."
+ " { player: the player who used the bucket."
+ " | location: where the bucket was filled from."
+ " | hand: hand the player was holding the bucket in, either main_hand or off_hand (MC 1.19.2+)."
+ " | item: the bucket item the player ended up with. }"
+ "{} "
+ "{} "
+ "{}";
}

@Override
public Version since() {
return MSVersion.V3_3_5;
}

@Override
public Driver driver() {
return Driver.PLAYER_BUCKET_FILL;
}
}

@api
public static class player_bucket_empty extends player_bucket_event {

@Override
public String getName() {
return "player_bucket_empty";
}

@Override
public String docs() {
return "{} "
+ "Fired when a player empties a bucket in their hand into the world."
+ " { player: the player who used the bucket."
+ " | location: where the bucket was emptied to."
+ " | hand: hand the player was holding the bucket in, either main_hand or off_hand (MC 1.19.2+)."
+ " | item: the bucket item the player ended up with. }"
+ "{} "
+ "{} "
+ "{}";
}

@Override
public Version since() {
return MSVersion.V3_3_5;
}

@Override
public Driver driver() {
return Driver.PLAYER_BUCKET_EMPTY;
}
}
}

0 comments on commit af10139

Please sign in to comment.