Skip to content

Commit

Permalink
Merge pull request #110 from AleksandarHaralanov/master
Browse files Browse the repository at this point in the history
Add chest open event
  • Loading branch information
moderatorman authored Nov 1, 2024
2 parents a6f0278 + 6969b27 commit eca365a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/main/java/net/minecraft/server/EntityPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import org.bukkit.craftbukkit.ChunkCompressionThread;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.inventory.ChestOpenedEvent;

import java.util.*;

Expand Down Expand Up @@ -456,6 +456,12 @@ public void b(int i, int j, int k) {
public void a(IInventory iinventory) {
this.ai();

// Poseidon start
ChestOpenedEvent event = new ChestOpenedEvent((org.bukkit.entity.Player) this.getBukkitEntity(), iinventory.getContents());
this.world.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return;
// Poseidon end

this.netServerHandler.sendPacket(new Packet100OpenWindow(this.bO, 0, iinventory.getName(), iinventory.getSize()));
this.activeContainer = new ContainerChest(this.inventory, iinventory);
this.activeContainer.windowId = this.bO;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/minecraft/server/IInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ public interface IInventory {

boolean a_(EntityHuman entityhuman);

public abstract ItemStack[] getContents(); // CraftBukkit
ItemStack[] getContents(); // CraftBukkit
}
3 changes: 2 additions & 1 deletion src/main/java/org/bukkit/event/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public enum Category {
/**
* Provides a lookup for all core events
*
* @see org.bukkit.event.
* @see org.bukkit.event
*/
public enum Type {

Expand All @@ -154,6 +154,7 @@ public enum Type {

PACKET_RECEIVED(Category.PACKET),

CHEST_OPENED(Category.BLOCK),

/**
* Called when a player first starts their connection. Called before UUID is known.
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/org/bukkit/event/inventory/ChestOpenedEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.bukkit.event.inventory;

import net.minecraft.server.ItemStack;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;

public class ChestOpenedEvent extends Event implements Cancellable {
private boolean cancelled;
private Player player;
private ItemStack[] contents;

public ChestOpenedEvent(Player player, ItemStack[] contents) {
super(Type.CHEST_OPENED);
this.player = player;
this.contents = contents;
}

public Player getPlayer() {
return player;
}

public ItemStack[] getContents() {
return contents;
}

public boolean isCancelled() {
return cancelled;
}

public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
}

0 comments on commit eca365a

Please sign in to comment.