geforkt von Mirrors/Paper
5c7081fecc
* Updated Upstream (Bukkit/CraftBukkit) Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 45690fe9 SPIGOT-5047: Correct slot types for 1.14 inventories CraftBukkit Changes:4090d01f
SPIGOT-5047: Correct slot types for 1.14 inventoriese8c08362
SPIGOT-5046: World#getLoadedChunks returning inaccessible cached chunks.d445af3b
SPIGOT-5067: Add item meta for 1.14 spawn eggs * Bring Chunk load checks in-line with spigot As of the last upstream merge spigot now checks ticket level status when returning loaded chunks for a world from api. Now our checks will respect that decision. * Fix spawn ticket levels Vanilla would keep the inner chunks of spawn available for ticking, however my changes made all chunks non-ticking. Resolve by changing ticket levels for spawn chunks inside the border to respect this behavior. * Make World#getChunkIfLoadedImmediately return only entity ticking chunks Mojang appears to be using chunks with level > 33 (non-ticking chunks) as cached chunks and not actually loaded chunks. * Bring all loaded checks in line with spigot Loaded chunks must be at least border chunks, or level <= 33
164 Zeilen
4.5 KiB
Diff
164 Zeilen
4.5 KiB
Diff
From 088e922b17a679192e4544462812259a94e19640 Mon Sep 17 00:00:00 2001
|
|
From: BillyGalbreath <Blake.Galbreath@GMail.com>
|
|
Date: Fri, 20 Jul 2018 23:36:55 -0500
|
|
Subject: [PATCH] AnvilDamageEvent
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/event/block/AnvilDamagedEvent.java b/src/main/java/com/destroystokyo/paper/event/block/AnvilDamagedEvent.java
|
|
new file mode 100644
|
|
index 000000000..a83c286c1
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/event/block/AnvilDamagedEvent.java
|
|
@@ -0,0 +1,148 @@
|
|
+package com.destroystokyo.paper.event.block;
|
|
+
|
|
+import org.bukkit.Material;
|
|
+import org.bukkit.block.data.BlockData;
|
|
+import org.bukkit.event.Cancellable;
|
|
+import org.bukkit.event.HandlerList;
|
|
+import org.bukkit.event.inventory.InventoryEvent;
|
|
+import org.bukkit.inventory.AnvilInventory;
|
|
+import org.bukkit.inventory.InventoryView;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+import org.jetbrains.annotations.Nullable;
|
|
+
|
|
+/**
|
|
+ * Called when an anvil is damaged from being used
|
|
+ */
|
|
+public class AnvilDamagedEvent extends InventoryEvent implements Cancellable {
|
|
+ private static final HandlerList handlers = new HandlerList();
|
|
+ private boolean cancel;
|
|
+ private DamageState damageState;
|
|
+
|
|
+ public AnvilDamagedEvent(@NotNull InventoryView inventory, @NotNull BlockData blockData) {
|
|
+ super(inventory);
|
|
+ this.damageState = DamageState.getState(blockData);
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ @Override
|
|
+ public AnvilInventory getInventory() {
|
|
+ return (AnvilInventory) super.getInventory();
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Gets the new state of damage on the anvil
|
|
+ *
|
|
+ * @return Damage state
|
|
+ */
|
|
+ @NotNull
|
|
+ public DamageState getDamageState() {
|
|
+ return damageState;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Sets the new state of damage on the anvil
|
|
+ *
|
|
+ * @param damageState Damage state
|
|
+ */
|
|
+ public void setDamageState(@NotNull DamageState damageState) {
|
|
+ this.damageState = damageState;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Gets if anvil is breaking on this use
|
|
+ *
|
|
+ * @return True if breaking
|
|
+ */
|
|
+ public boolean isBreaking() {
|
|
+ return damageState == DamageState.BROKEN;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Sets if anvil is breaking on this use
|
|
+ *
|
|
+ * @param breaking True if breaking
|
|
+ */
|
|
+ public void setBreaking(boolean breaking) {
|
|
+ if (breaking) {
|
|
+ damageState = DamageState.BROKEN;
|
|
+ } else if (damageState == DamageState.BROKEN) {
|
|
+ damageState = DamageState.DAMAGED;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public boolean isCancelled() {
|
|
+ return cancel;
|
|
+ }
|
|
+
|
|
+ public void setCancelled(boolean cancel) {
|
|
+ this.cancel = cancel;
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ public HandlerList getHandlers() {
|
|
+ return handlers;
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ public static HandlerList getHandlerList() {
|
|
+ return handlers;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Represents the amount of damage on an anvil block
|
|
+ */
|
|
+ public enum DamageState {
|
|
+ FULL(Material.ANVIL),
|
|
+ CHIPPED(Material.CHIPPED_ANVIL),
|
|
+ DAMAGED(Material.DAMAGED_ANVIL),
|
|
+ BROKEN(Material.AIR);
|
|
+
|
|
+ private Material material;
|
|
+
|
|
+ DamageState(@NotNull Material material) {
|
|
+ this.material = material;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Get block material of this state
|
|
+ *
|
|
+ * @return Material
|
|
+ */
|
|
+ @NotNull
|
|
+ public Material getMaterial() {
|
|
+ return material;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Get damaged state by block data
|
|
+ *
|
|
+ * @param blockData Block data
|
|
+ * @return DamageState
|
|
+ * @throws IllegalArgumentException If non anvil block data is given
|
|
+ */
|
|
+ @NotNull
|
|
+ public static DamageState getState(@Nullable BlockData blockData) {
|
|
+ return blockData == null ? BROKEN : getState(blockData.getMaterial());
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Get damaged state by block material
|
|
+ *
|
|
+ * @param material Block material
|
|
+ * @return DamageState
|
|
+ * @throws IllegalArgumentException If non anvil material is given
|
|
+ */
|
|
+ @NotNull
|
|
+ public static DamageState getState(@Nullable Material material) {
|
|
+ if (material == null) {
|
|
+ return BROKEN;
|
|
+ }
|
|
+ for (DamageState state : values()) {
|
|
+ if (state.material == material) {
|
|
+ return state;
|
|
+ }
|
|
+ }
|
|
+ throw new IllegalArgumentException("Material not an anvil");
|
|
+ }
|
|
+ }
|
|
+}
|
|
--
|
|
2.21.0
|
|
|