Repackage patches

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2021-03-16 09:00:00 +11:00
parent 2777f7b780
commit 18496e998f
433 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
--- a/net/minecraft/server/TileEntity.java
+++ b/net/minecraft/server/TileEntity.java
@@ -5,8 +5,18 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.util.Supplier;
+// CraftBukkit start
+import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
+import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry;
+import org.bukkit.inventory.InventoryHolder;
+// CraftBukkit end
+
public abstract class TileEntity {
+ // CraftBukkit start - data containers
+ private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry();
+ public CraftPersistentDataContainer persistentDataContainer;
+ // CraftBukkit end
private static final Logger LOGGER = LogManager.getLogger();
private final TileEntityTypes<?> tileType;
@Nullable
@@ -38,6 +48,14 @@
public void load(IBlockData iblockdata, NBTTagCompound nbttagcompound) {
this.position = new BlockPosition(nbttagcompound.getInt("x"), nbttagcompound.getInt("y"), nbttagcompound.getInt("z"));
+ // CraftBukkit start - read container
+ this.persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY);
+
+ NBTBase persistentDataTag = nbttagcompound.get("PublicBukkitValues");
+ if (persistentDataTag instanceof NBTTagCompound) {
+ this.persistentDataContainer.putAll((NBTTagCompound) persistentDataTag);
+ }
+ // CraftBukkit end
}
public NBTTagCompound save(NBTTagCompound nbttagcompound) {
@@ -54,6 +72,11 @@
nbttagcompound.setInt("x", this.position.getX());
nbttagcompound.setInt("y", this.position.getY());
nbttagcompound.setInt("z", this.position.getZ());
+ // CraftBukkit start - store container
+ if (this.persistentDataContainer != null && !this.persistentDataContainer.isEmpty()) {
+ nbttagcompound.set("PublicBukkitValues", this.persistentDataContainer.toTagCompound());
+ }
+ // CraftBukkit end
return nbttagcompound;
}
}
@@ -169,4 +192,13 @@
}, this::getPosition});
}
}
+
+ // CraftBukkit start - add method
+ public InventoryHolder getOwner() {
+ if (world == null) return null;
+ org.bukkit.block.BlockState state = world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()).getState();
+ if (state instanceof InventoryHolder) return (InventoryHolder) state;
+ return null;
+ }
+ // CraftBukkit end
}

View File

@@ -0,0 +1,14 @@
--- a/net/minecraft/server/TileEntityBanner.java
+++ b/net/minecraft/server/TileEntityBanner.java
@@ -70,6 +70,11 @@
}
this.patterns = nbttagcompound.getList("Patterns", 10);
+ // CraftBukkit start
+ while (this.patterns.size() > 20) {
+ this.patterns.remove(20);
+ }
+ // CraftBukkit end
this.h = null;
this.g = true;
}

View File

@@ -0,0 +1,61 @@
--- a/net/minecraft/server/TileEntityBarrel.java
+++ b/net/minecraft/server/TileEntityBarrel.java
@@ -1,7 +1,49 @@
package net.minecraft.server;
+// CraftBukkit start
+import java.util.ArrayList;
+import java.util.List;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
public class TileEntityBarrel extends TileEntityLootable {
+ // CraftBukkit start - add fields and methods
+ public List<HumanEntity> transaction = new ArrayList<>();
+ private int maxStack = MAX_STACK;
+ public boolean opened;
+
+ @Override
+ public List<ItemStack> getContents() {
+ return this.items;
+ }
+
+ @Override
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ @Override
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ @Override
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ @Override
+ public int getMaxStackSize() {
+ return maxStack;
+ }
+
+ @Override
+ public void setMaxStackSize(int i) {
+ maxStack = i;
+ }
+ // CraftBukkit end
private NonNullList<ItemStack> items;
private int b;
@@ -100,7 +142,7 @@
return;
}
- boolean flag = (Boolean) iblockdata.get(BlockBarrel.OPEN);
+ boolean flag = (Boolean) iblockdata.get(BlockBarrel.OPEN) && !opened; // CraftBukkit - only set flag if Barrel isn't set open by API.
if (flag) {
this.playOpenSound(iblockdata, SoundEffects.BLOCK_BARREL_CLOSE);

View File

@@ -0,0 +1,133 @@
--- a/net/minecraft/server/TileEntityBeacon.java
+++ b/net/minecraft/server/TileEntityBeacon.java
@@ -8,6 +8,11 @@
import java.util.stream.Collectors;
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.potion.CraftPotionUtil;
+import org.bukkit.potion.PotionEffect;
+// CraftBukkit end
+
public class TileEntityBeacon extends TileEntity implements ITileInventory, ITickable {
public static final MobEffectList[][] a = new MobEffectList[][]{{MobEffects.FASTER_MOVEMENT, MobEffects.FASTER_DIG}, {MobEffects.RESISTANCE, MobEffects.JUMP}, {MobEffects.INCREASE_DAMAGE}, {MobEffects.REGENERATION}};
@@ -24,6 +29,15 @@
public IChatBaseComponent customName;
public ChestLock chestLock;
private final IContainerProperties containerProperties;
+ // CraftBukkit start - add fields and methods
+ public PotionEffect getPrimaryEffect() {
+ return (this.primaryEffect != null) ? CraftPotionUtil.toBukkit(new MobEffect(this.primaryEffect, getLevel(), getAmplification(), true, true)) : null;
+ }
+
+ public PotionEffect getSecondaryEffect() {
+ return (hasSecondaryEffect()) ? CraftPotionUtil.toBukkit(new MobEffect(this.secondaryEffect, getLevel(), getAmplification(), true, true)) : null;
+ }
+ // CraftBukkit end
public TileEntityBeacon() {
super(TileEntityTypes.BEACON);
@@ -192,39 +206,78 @@
super.al_();
}
- private void applyEffects() {
- if (!this.world.isClientSide && this.primaryEffect != null) {
- double d0 = (double) (this.levels * 10 + 10);
+ // CraftBukkit start - split into components
+ private byte getAmplification() {
+ {
byte b0 = 0;
if (this.levels >= 4 && this.primaryEffect == this.secondaryEffect) {
b0 = 1;
}
+ return b0;
+ }
+ }
+
+ private int getLevel() {
+ {
int i = (9 + this.levels * 2) * 20;
+ return i;
+ }
+ }
+
+ public List getHumansInRange() {
+ {
+ double d0 = (double) (this.levels * 10 + 10);
+
AxisAlignedBB axisalignedbb = (new AxisAlignedBB(this.position)).g(d0).b(0.0D, (double) this.world.getBuildHeight(), 0.0D);
List<EntityHuman> list = this.world.a(EntityHuman.class, axisalignedbb);
+
+ return list;
+ }
+ }
+
+ private void applyEffect(List list, MobEffectList effects, int i, int b0) {
+ {
Iterator iterator = list.iterator();
EntityHuman entityhuman;
while (iterator.hasNext()) {
entityhuman = (EntityHuman) iterator.next();
- entityhuman.addEffect(new MobEffect(this.primaryEffect, i, b0, true, true));
+ entityhuman.addEffect(new MobEffect(effects, i, b0, true, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.BEACON);
}
+ }
+ }
+ private boolean hasSecondaryEffect() {
+ {
if (this.levels >= 4 && this.primaryEffect != this.secondaryEffect && this.secondaryEffect != null) {
- iterator = list.iterator();
-
- while (iterator.hasNext()) {
- entityhuman = (EntityHuman) iterator.next();
- entityhuman.addEffect(new MobEffect(this.secondaryEffect, i, 0, true, true));
- }
+ return true;
}
+ return false;
}
}
+ private void applyEffects() {
+ if (!this.world.isClientSide && this.primaryEffect != null) {
+ double d0 = (double) (this.levels * 10 + 10);
+ byte b0 = getAmplification();
+
+ int i = getLevel();
+ List list = getHumansInRange();
+
+ applyEffect(list, this.primaryEffect, i, b0);
+
+ if (hasSecondaryEffect()) {
+ applyEffect(list, this.secondaryEffect, i, 0);
+ }
+ }
+
+ }
+ // CraftBukkit end
+
public void a(SoundEffect soundeffect) {
this.world.playSound((EntityHuman) null, this.position, soundeffect, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
@@ -254,8 +307,11 @@
@Override
public void load(IBlockData iblockdata, NBTTagCompound nbttagcompound) {
super.load(iblockdata, nbttagcompound);
- this.primaryEffect = b(nbttagcompound.getInt("Primary"));
- this.secondaryEffect = b(nbttagcompound.getInt("Secondary"));
+ // CraftBukkit start - persist manually set non-default beacon effects (SPIGOT-3598)
+ this.primaryEffect = MobEffectList.fromId(nbttagcompound.getInt("Primary"));
+ this.secondaryEffect = MobEffectList.fromId(nbttagcompound.getInt("Secondary"));
+ this.levels = nbttagcompound.getInt("Levels"); // SPIGOT-5053, use where available
+ // CraftBukkit end
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
this.customName = IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName"));
}

View File

@@ -0,0 +1,153 @@
--- a/net/minecraft/server/TileEntityBeehive.java
+++ b/net/minecraft/server/TileEntityBeehive.java
@@ -10,6 +10,7 @@
private final List<TileEntityBeehive.HiveBee> bees = Lists.newArrayList();
@Nullable
public BlockPosition flowerPos = null;
+ public int maxBees = 3; // CraftBukkit - allow setting max amount of bees a hive can hold
public TileEntityBeehive() {
super(TileEntityTypes.BEEHIVE);
@@ -49,7 +50,7 @@
}
public boolean isFull() {
- return this.bees.size() == 3;
+ return this.bees.size() == this.maxBees; // CraftBukkit
}
public void a(@Nullable EntityHuman entityhuman, IBlockData iblockdata, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus) {
@@ -66,7 +67,7 @@
if (entityhuman.getPositionVector().distanceSquared(entity.getPositionVector()) <= 16.0D) {
if (!this.isSedated()) {
- entitybee.setGoalTarget(entityhuman);
+ entitybee.setGoalTarget(entityhuman, org.bukkit.event.entity.EntityTargetEvent.TargetReason.CLOSEST_PLAYER, true); // CraftBukkit
} else {
entitybee.setCannotEnterHiveTicks(400);
}
@@ -78,10 +79,16 @@
}
private List<Entity> releaseBees(IBlockData iblockdata, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus) {
+ // CraftBukkit start - This allows us to bypass the night/rain/emergency check
+ return releaseBees(iblockdata, tileentitybeehive_releasestatus, false);
+ }
+
+ public List<Entity> releaseBees(IBlockData iblockdata, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus, boolean force) {
List<Entity> list = Lists.newArrayList();
this.bees.removeIf((tileentitybeehive_hivebee) -> {
- return this.releaseBee(iblockdata, tileentitybeehive_hivebee, list, tileentitybeehive_releasestatus);
+ return this.releaseBee(iblockdata, tileentitybeehive_hivebee, list, tileentitybeehive_releasestatus, force);
+ // CraftBukkit end
});
return list;
}
@@ -107,7 +114,19 @@
}
public void a(Entity entity, boolean flag, int i) {
- if (this.bees.size() < 3) {
+ if (this.bees.size() < this.maxBees) { // CraftBukkit
+ // CraftBukkit start
+ if (this.world != null) {
+ org.bukkit.event.entity.EntityEnterBlockEvent event = new org.bukkit.event.entity.EntityEnterBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, getPosition()));
+ org.bukkit.Bukkit.getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ if (entity instanceof EntityBee) {
+ ((EntityBee) entity).setCannotEnterHiveTicks(400);
+ }
+ return;
+ }
+ }
+ // CraftBukkit end
entity.stopRiding();
entity.ejectPassengers();
NBTTagCompound nbttagcompound = new NBTTagCompound();
@@ -133,7 +152,13 @@
}
private boolean releaseBee(IBlockData iblockdata, TileEntityBeehive.HiveBee tileentitybeehive_hivebee, @Nullable List<Entity> list, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus) {
- if ((this.world.isNight() || this.world.isRaining()) && tileentitybeehive_releasestatus != TileEntityBeehive.ReleaseStatus.EMERGENCY) {
+ // CraftBukkit start - This allows us to bypass the night/rain/emergency check
+ return releaseBee(iblockdata, tileentitybeehive_hivebee, list, tileentitybeehive_releasestatus, false);
+ }
+
+ private boolean releaseBee(IBlockData iblockdata, TileEntityBeehive.HiveBee tileentitybeehive_hivebee, @Nullable List<Entity> list, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus, boolean force) {
+ if (!force && (this.world.isNight() || this.world.isRaining()) && tileentitybeehive_releasestatus != TileEntityBeehive.ReleaseStatus.EMERGENCY) {
+ // CraftBukkit end
return false;
} else {
BlockPosition blockposition = this.getPosition();
@@ -157,6 +182,18 @@
if (!entity.getEntityType().a((Tag) TagsEntity.BEEHIVE_INHABITORS)) {
return false;
} else {
+ // CraftBukkit start
+ if (entity instanceof EntityBee) {
+ float f = entity.getWidth();
+ double d0 = flag ? 0.0D : 0.55D + (double) (f / 2.0F);
+ double d1 = (double) blockposition.getX() + 0.5D + d0 * (double) enumdirection.getAdjacentX();
+ double d2 = (double) blockposition.getY() + 0.5D - (double) (entity.getHeight() / 2.0F);
+ double d3 = (double) blockposition.getZ() + 0.5D + d0 * (double) enumdirection.getAdjacentZ();
+
+ entity.setPositionRotation(d1, d2, d3, entity.yaw, entity.pitch);
+ }
+ if (!this.world.addEntity(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BEEHIVE)) return false; // CraftBukkit - SpawnReason, moved from below
+ // CraftBukkit end
if (entity instanceof EntityBee) {
EntityBee entitybee = (EntityBee) entity;
@@ -186,6 +223,7 @@
list.add(entitybee);
}
+ /* // CraftBukkit start
float f = entity.getWidth();
double d0 = flag ? 0.0D : 0.55D + (double) (f / 2.0F);
double d1 = (double) blockposition.getX() + 0.5D + d0 * (double) enumdirection.getAdjacentX();
@@ -193,10 +231,11 @@
double d3 = (double) blockposition.getZ() + 0.5D + d0 * (double) enumdirection.getAdjacentZ();
entity.setPositionRotation(d1, d2, d3, entity.yaw, entity.pitch);
+ */ // CraftBukkit end
}
this.world.playSound((EntityHuman) null, blockposition, SoundEffects.BLOCK_BEEHIVE_EXIT, SoundCategory.BLOCKS, 1.0F, 1.0F);
- return this.world.addEntity(entity);
+ return true; // return this.world.addEntity(entity); // CraftBukkit - moved up
}
} else {
return false;
@@ -234,6 +273,10 @@
if (this.releaseBee(iblockdata, tileentitybeehive_hivebee, (List) null, tileentitybeehive_releasestatus)) {
iterator.remove();
+ // CraftBukkit start
+ } else {
+ tileentitybeehive_hivebee.ticksInHive = tileentitybeehive_hivebee.minOccupationTicks / 2; // Not strictly Vanilla behaviour in cases where bees cannot spawn but still reasonable
+ // CraftBukkit end
}
}
}
@@ -276,6 +319,11 @@
this.flowerPos = GameProfileSerializer.b(nbttagcompound.getCompound("FlowerPos"));
}
+ // CraftBukkit start
+ if (nbttagcompound.hasKey("Bukkit.MaxEntities")) {
+ this.maxBees = nbttagcompound.getInt("Bukkit.MaxEntities");
+ }
+ // CraftBukkit end
}
@Override
@@ -285,6 +333,7 @@
if (this.x()) {
nbttagcompound.set("FlowerPos", GameProfileSerializer.a(this.flowerPos));
}
+ nbttagcompound.setInt("Bukkit.MaxEntities", this.maxBees); // CraftBukkit
return nbttagcompound;
}

View File

@@ -0,0 +1,112 @@
--- a/net/minecraft/server/TileEntityBrewingStand.java
+++ b/net/minecraft/server/TileEntityBrewingStand.java
@@ -4,6 +4,16 @@
import java.util.Iterator;
import javax.annotation.Nullable;
+// CraftBukkit start
+import java.util.List;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.event.inventory.BrewEvent;
+import org.bukkit.event.inventory.BrewingStandFuelEvent;
+import org.bukkit.inventory.InventoryHolder;
+// CraftBukkit end
+
public class TileEntityBrewingStand extends TileEntityContainer implements IWorldInventory, ITickable {
private static final int[] b = new int[]{3};
@@ -15,6 +25,36 @@
private Item k;
public int fuelLevel;
protected final IContainerProperties a;
+ // CraftBukkit start - add fields and methods
+ private int lastTick = MinecraftServer.currentTick;
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+ private int maxStack = 64;
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ public List<ItemStack> getContents() {
+ return this.items;
+ }
+
+ @Override
+ public int getMaxStackSize() {
+ return maxStack;
+ }
+
+ public void setMaxStackSize(int size) {
+ maxStack = size;
+ }
+ // CraftBukkit end
public TileEntityBrewingStand() {
super(TileEntityTypes.BREWING_STAND);
@@ -83,8 +123,19 @@
ItemStack itemstack = (ItemStack) this.items.get(4);
if (this.fuelLevel <= 0 && itemstack.getItem() == Items.BLAZE_POWDER) {
- this.fuelLevel = 20;
- itemstack.subtract(1);
+ // CraftBukkit start
+ BrewingStandFuelEvent event = new BrewingStandFuelEvent(world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()), CraftItemStack.asCraftMirror(itemstack), 20);
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+
+ this.fuelLevel = event.getFuelPower();
+ if (this.fuelLevel > 0 && event.isConsuming()) {
+ itemstack.subtract(1);
+ }
+ // CraftBukkit end
this.update();
}
@@ -92,9 +143,14 @@
boolean flag1 = this.brewTime > 0;
ItemStack itemstack1 = (ItemStack) this.items.get(3);
+ // CraftBukkit start - Use wall time instead of ticks for brewing
+ int elapsedTicks = MinecraftServer.currentTick - this.lastTick;
+ this.lastTick = MinecraftServer.currentTick;
+
if (flag1) {
- --this.brewTime;
- boolean flag2 = this.brewTime == 0;
+ this.brewTime -= elapsedTicks;
+ boolean flag2 = this.brewTime <= 0; // == -> <=
+ // CraftBukkit end
if (flag2 && flag) {
this.j();
@@ -168,6 +224,16 @@
private void j() {
ItemStack itemstack = (ItemStack) this.items.get(3);
+ // CraftBukkit start
+ InventoryHolder owner = this.getOwner();
+ if (owner != null) {
+ BrewEvent event = new BrewEvent(world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()), (org.bukkit.inventory.BrewerInventory) owner.getInventory(), this.fuelLevel);
+ org.bukkit.Bukkit.getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+ }
+ // CraftBukkit end
for (int i = 0; i < 3; ++i) {
this.items.set(i, PotionBrewer.d(itemstack, (ItemStack) this.items.get(i)));

View File

@@ -0,0 +1,36 @@
--- a/net/minecraft/server/TileEntityCampfire.java
+++ b/net/minecraft/server/TileEntityCampfire.java
@@ -4,6 +4,12 @@
import java.util.Random;
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.block.BlockCookEvent;
+// CraftBukkit end
+
public class TileEntityCampfire extends TileEntity implements Clearable, ITickable {
private final NonNullList<ItemStack> items;
@@ -55,6 +61,20 @@
}).orElse(itemstack);
BlockPosition blockposition = this.getPosition();
+ // CraftBukkit start - fire BlockCookEvent
+ CraftItemStack source = CraftItemStack.asCraftMirror(itemstack);
+ org.bukkit.inventory.ItemStack result = CraftItemStack.asBukkitCopy(itemstack1);
+
+ BlockCookEvent blockCookEvent = new BlockCookEvent(CraftBlock.at(this.world, this.position), source, result);
+ this.world.getServer().getPluginManager().callEvent(blockCookEvent);
+
+ if (blockCookEvent.isCancelled()) {
+ return;
+ }
+
+ result = blockCookEvent.getResult();
+ itemstack1 = CraftItemStack.asNMSCopy(result);
+ // CraftBukkit end
InventoryUtils.dropItem(this.world, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), itemstack1);
this.items.set(i, ItemStack.b);
this.k();

View File

@@ -0,0 +1,127 @@
--- a/net/minecraft/server/TileEntityChest.java
+++ b/net/minecraft/server/TileEntityChest.java
@@ -3,6 +3,11 @@
import java.util.Iterator;
import java.util.List;
+// CraftBukkit start
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
public class TileEntityChest extends TileEntityLootable implements ITickable {
private NonNullList<ItemStack> items;
@@ -11,6 +16,37 @@
public int viewingCount;
private int j;
+ // CraftBukkit start - add fields and methods
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+ private int maxStack = MAX_STACK;
+ public boolean opened;
+
+ public List<ItemStack> getContents() {
+ return this.items;
+ }
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ @Override
+ public int getMaxStackSize() {
+ return maxStack;
+ }
+
+ public void setMaxStackSize(int size) {
+ maxStack = size;
+ }
+ // CraftBukkit end
+
protected TileEntityChest(TileEntityTypes<?> tileentitytypes) {
super(tileentitytypes);
this.items = NonNullList.a(27, ItemStack.b);
@@ -61,6 +97,13 @@
this.b = this.a;
float f = 0.1F;
+ // CraftBukkit start - If chest is forced open by API, remove a viewer due to playBlockAction() call and don't tick to prevent sound effects.
+ if (opened) {
+ this.viewingCount--;
+ return;
+ }
+ // CraftBukkit end
+
if (this.viewingCount > 0 && this.a == 0.0F) {
this.playOpenSound(SoundEffects.BLOCK_CHEST_OPEN);
}
@@ -155,8 +198,20 @@
if (this.viewingCount < 0) {
this.viewingCount = 0;
}
+ int oldPower = Math.max(0, Math.min(15, this.viewingCount)); // CraftBukkit - Get power before new viewer is added
++this.viewingCount;
+ if (this.world == null) return; // CraftBukkit
+
+ // CraftBukkit start - Call redstone event
+ if (this.getBlock().getBlock() == Blocks.TRAPPED_CHEST) {
+ int newPower = Math.max(0, Math.min(15, this.viewingCount));
+
+ if (oldPower != newPower) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRedstoneChange(world, position, oldPower, newPower);
+ }
+ }
+ // CraftBukkit end
this.onOpen();
}
@@ -165,7 +220,18 @@
@Override
public void closeContainer(EntityHuman entityhuman) {
if (!entityhuman.isSpectator()) {
+ int oldPower = Math.max(0, Math.min(15, this.viewingCount)); // CraftBukkit - Get power before new viewer is added
--this.viewingCount;
+
+ // CraftBukkit start - Call redstone event
+ if (this.getBlock().getBlock() == Blocks.TRAPPED_CHEST) {
+ int newPower = Math.max(0, Math.min(15, this.viewingCount));
+
+ if (oldPower != newPower) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRedstoneChange(world, position, oldPower, newPower);
+ }
+ }
+ // CraftBukkit end
this.onOpen();
}
@@ -175,7 +241,7 @@
Block block = this.getBlock().getBlock();
if (block instanceof BlockChest) {
- this.world.playBlockAction(this.position, block, 1, this.viewingCount);
+ if (!opened) this.world.playBlockAction(this.position, block, 1, this.viewingCount); // CraftBukkit
this.world.applyPhysics(this.position, block);
}
@@ -216,4 +282,11 @@
protected Container createContainer(int i, PlayerInventory playerinventory) {
return ContainerChest.a(i, playerinventory, this);
}
+
+ // CraftBukkit start
+ @Override
+ public boolean isFilteredNBT() {
+ return true;
+ }
+ // CraftBukkit end
}

View File

@@ -0,0 +1,16 @@
--- a/net/minecraft/server/TileEntityCommand.java
+++ b/net/minecraft/server/TileEntityCommand.java
@@ -9,6 +9,13 @@
private boolean c;
private boolean g;
private final CommandBlockListenerAbstract h = new CommandBlockListenerAbstract() {
+ // CraftBukkit start
+ @Override
+ public org.bukkit.command.CommandSender getBukkitSender(CommandListenerWrapper wrapper) {
+ return new org.bukkit.craftbukkit.command.CraftBlockCommandSender(wrapper, TileEntityCommand.this);
+ }
+ // CraftBukkit end
+
@Override
public void setCommand(String s) {
super.setCommand(s);

View File

@@ -0,0 +1,57 @@
--- a/net/minecraft/server/TileEntityConduit.java
+++ b/net/minecraft/server/TileEntityConduit.java
@@ -7,6 +7,11 @@
import java.util.UUID;
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+// CraftBukkit end
+
public class TileEntityConduit extends TileEntity implements ITickable {
private static final Block[] b = new Block[]{Blocks.PRISMARINE, Blocks.PRISMARINE_BRICKS, Blocks.SEA_LANTERN, Blocks.DARK_PRISMARINE};
@@ -158,7 +163,7 @@
EntityHuman entityhuman = (EntityHuman) iterator.next();
if (this.position.a((BaseBlockPosition) entityhuman.getChunkCoordinates(), (double) j) && entityhuman.isInWaterOrRain()) {
- entityhuman.addEffect(new MobEffect(MobEffects.CONDUIT_POWER, 260, 0, true, true));
+ entityhuman.addEffect(new MobEffect(MobEffects.CONDUIT_POWER, 260, 0, true, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.CONDUIT); // CraftBukkit
}
}
@@ -175,7 +180,7 @@
this.target = this.x();
this.k = null;
} else if (this.target == null) {
- List<EntityLiving> list = this.world.a(EntityLiving.class, this.m(), (entityliving1) -> {
+ List<EntityLiving> list = this.world.a(EntityLiving.class, this.m(), (java.util.function.Predicate<EntityLiving>) (entityliving1) -> { // CraftBukkit - decompile error
return entityliving1 instanceof IMonster && entityliving1.isInWaterOrRain();
});
@@ -187,8 +192,13 @@
}
if (this.target != null) {
- this.world.playSound((EntityHuman) null, this.target.locX(), this.target.locY(), this.target.locZ(), SoundEffects.BLOCK_CONDUIT_ATTACK_TARGET, SoundCategory.BLOCKS, 1.0F, 1.0F);
- this.target.damageEntity(DamageSource.MAGIC, 4.0F);
+ // CraftBukkit start
+ CraftEventFactory.blockDamage = CraftBlock.at(this.world, this.position);
+ if (this.target.damageEntity(DamageSource.MAGIC, 4.0F)) {
+ this.world.playSound((EntityHuman) null, this.target.locX(), this.target.locY(), this.target.locZ(), SoundEffects.BLOCK_CONDUIT_ATTACK_TARGET, SoundCategory.BLOCKS, 1.0F, 1.0F);
+ }
+ CraftEventFactory.blockDamage = null;
+ // CraftBukkit end
}
if (entityliving != this.target) {
@@ -221,7 +231,7 @@
@Nullable
private EntityLiving x() {
- List<EntityLiving> list = this.world.a(EntityLiving.class, this.m(), (entityliving) -> {
+ List<EntityLiving> list = this.world.a(EntityLiving.class, this.m(), (java.util.function.Predicate<EntityLiving>) (entityliving) -> { // CraftBukkit - decompile error
return entityliving.getUniqueID().equals(this.k);
});

View File

@@ -0,0 +1,15 @@
--- a/net/minecraft/server/TileEntityContainer.java
+++ b/net/minecraft/server/TileEntityContainer.java
@@ -76,4 +76,12 @@
}
protected abstract Container createContainer(int i, PlayerInventory playerinventory);
+
+ // CraftBukkit start
+ @Override
+ public org.bukkit.Location getLocation() {
+ if (world == null) return null;
+ return new org.bukkit.Location(world.getWorld(), position.getX(), position.getY(), position.getZ());
+ }
+ // CraftBukkit end
}

View File

@@ -0,0 +1,51 @@
--- a/net/minecraft/server/TileEntityDispenser.java
+++ b/net/minecraft/server/TileEntityDispenser.java
@@ -2,11 +2,48 @@
import java.util.Random;
+// CraftBukkit start
+import java.util.List;
+
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
public class TileEntityDispenser extends TileEntityLootable {
private static final Random a = new Random();
private NonNullList<ItemStack> items;
+ // CraftBukkit start - add fields and methods
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+ private int maxStack = MAX_STACK;
+
+ public List<ItemStack> getContents() {
+ return this.items;
+ }
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ @Override
+ public int getMaxStackSize() {
+ return maxStack;
+ }
+
+ public void setMaxStackSize(int size) {
+ maxStack = size;
+ }
+ // CraftBukkit end
+
protected TileEntityDispenser(TileEntityTypes<?> tileentitytypes) {
super(tileentitytypes);
this.items = NonNullList.a(9, ItemStack.b);

View File

@@ -0,0 +1,62 @@
--- a/net/minecraft/server/TileEntityEndGateway.java
+++ b/net/minecraft/server/TileEntityEndGateway.java
@@ -7,6 +7,13 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.bukkit.event.player.PlayerTeleportEvent;
+// CraftBukkit end
+
public class TileEntityEndGateway extends TileEntityEnderPortal implements ITickable {
private static final Logger LOGGER = LogManager.getLogger();
@@ -117,7 +124,7 @@
public void b(Entity entity) {
if (this.world instanceof WorldServer && !this.f()) {
this.c = 100;
- if (this.exitPortal == null && this.world.getDimensionKey() == World.THE_END) {
+ if (this.exitPortal == null && this.world.getTypeKey() == DimensionManager.THE_END) { // CraftBukkit - work in alternate worlds
this.a((WorldServer) this.world);
}
@@ -142,6 +149,27 @@
entity1 = entity.getRootVehicle();
}
+ // CraftBukkit start - Fire PlayerTeleportEvent
+ if (entity1 instanceof EntityPlayer) {
+ org.bukkit.craftbukkit.entity.CraftPlayer player = (CraftPlayer) entity1.getBukkitEntity();
+ org.bukkit.Location location = new Location(world.getWorld(), (double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D);
+ location.setPitch(player.getLocation().getPitch());
+ location.setYaw(player.getLocation().getYaw());
+
+ PlayerTeleportEvent teleEvent = new PlayerTeleportEvent(player, player.getLocation(), location, PlayerTeleportEvent.TeleportCause.END_GATEWAY);
+ Bukkit.getPluginManager().callEvent(teleEvent);
+ if (teleEvent.isCancelled()) {
+ return;
+ }
+
+ entity1.resetPortalCooldown();
+ ((EntityPlayer) entity1).playerConnection.teleport(teleEvent.getTo());
+ this.h(); // CraftBukkit - call at end of method
+ return;
+
+ }
+ // CraftBukkit end
+
entity1.resetPortalCooldown();
entity1.enderTeleportAndLoad((double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D);
}
@@ -246,7 +274,7 @@
}
private void a(WorldServer worldserver, BlockPosition blockposition) {
- WorldGenerator.END_GATEWAY.b((WorldGenFeatureConfiguration) WorldGenEndGatewayConfiguration.a(this.getPosition(), false)).a(worldserver, worldserver.getChunkProvider().getChunkGenerator(), new Random(), blockposition);
+ WorldGenerator.END_GATEWAY.b(WorldGenEndGatewayConfiguration.a(this.getPosition(), false)).a(worldserver, worldserver.getChunkProvider().getChunkGenerator(), new Random(), blockposition); // CraftBukkit - decompile error
}
public void a(BlockPosition blockposition, boolean flag) {

View File

@@ -0,0 +1,187 @@
--- a/net/minecraft/server/TileEntityFurnace.java
+++ b/net/minecraft/server/TileEntityFurnace.java
@@ -10,6 +10,17 @@
import java.util.Map;
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.inventory.FurnaceBurnEvent;
+import org.bukkit.event.inventory.FurnaceExtractEvent;
+import org.bukkit.event.inventory.FurnaceSmeltEvent;
+// CraftBukkit end
+
public abstract class TileEntityFurnace extends TileEntityContainer implements IWorldInventory, RecipeHolder, AutoRecipeOutput, ITickable {
private static final int[] g = new int[]{0};
@@ -137,6 +148,36 @@
return map;
}
+ // CraftBukkit start - add fields and methods
+ private int maxStack = MAX_STACK;
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+
+ public List<ItemStack> getContents() {
+ return this.items;
+ }
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ @Override
+ public int getMaxStackSize() {
+ return maxStack;
+ }
+
+ public void setMaxStackSize(int size) {
+ maxStack = size;
+ }
+ // CraftBukkit end
+
private static boolean b(Item item) {
return TagsItem.NON_FLAMMABLE_WOOD.isTagged(item);
}
@@ -223,12 +264,23 @@
this.cookTime = MathHelper.clamp(this.cookTime - 2, 0, this.cookTimeTotal);
}
} else {
- IRecipe<?> irecipe = (IRecipe) this.world.getCraftingManager().craft(this.c, this, this.world).orElse((Object) null);
+ IRecipe irecipe = this.world.getCraftingManager().craft((Recipes<RecipeCooking>) this.c, this, this.world).orElse(null); // Eclipse fail
if (!this.isBurning() && this.canBurn(irecipe)) {
- this.burnTime = this.fuelTime(itemstack);
+ // CraftBukkit start
+ CraftItemStack fuel = CraftItemStack.asCraftMirror(itemstack);
+
+ FurnaceBurnEvent furnaceBurnEvent = new FurnaceBurnEvent(CraftBlock.at(this.world, this.position), fuel, fuelTime(itemstack));
+ this.world.getServer().getPluginManager().callEvent(furnaceBurnEvent);
+
+ if (furnaceBurnEvent.isCancelled()) {
+ return;
+ }
+
+ this.burnTime = furnaceBurnEvent.getBurnTime();
this.ticksForCurrentFuel = this.burnTime;
- if (this.isBurning()) {
+ if (this.isBurning() && furnaceBurnEvent.isBurning()) {
+ // CraftBukkit end
flag1 = true;
if (!itemstack.isEmpty()) {
Item item = itemstack.getItem();
@@ -290,11 +342,38 @@
ItemStack itemstack1 = irecipe.getResult();
ItemStack itemstack2 = (ItemStack) this.items.get(2);
+ // CraftBukkit start - fire FurnaceSmeltEvent
+ CraftItemStack source = CraftItemStack.asCraftMirror(itemstack);
+ org.bukkit.inventory.ItemStack result = CraftItemStack.asBukkitCopy(itemstack1);
+
+ FurnaceSmeltEvent furnaceSmeltEvent = new FurnaceSmeltEvent(this.world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()), source, result);
+ this.world.getServer().getPluginManager().callEvent(furnaceSmeltEvent);
+
+ if (furnaceSmeltEvent.isCancelled()) {
+ return;
+ }
+
+ result = furnaceSmeltEvent.getResult();
+ itemstack1 = CraftItemStack.asNMSCopy(result);
+
+ if (!itemstack1.isEmpty()) {
+ if (itemstack2.isEmpty()) {
+ this.items.set(2, itemstack1.cloneItemStack());
+ } else if (CraftItemStack.asCraftMirror(itemstack2).isSimilar(result)) {
+ itemstack2.add(itemstack1.getCount());
+ } else {
+ return;
+ }
+ }
+
+ /*
if (itemstack2.isEmpty()) {
this.items.set(2, itemstack1.cloneItemStack());
} else if (itemstack2.getItem() == itemstack1.getItem()) {
itemstack2.add(1);
}
+ */
+ // CraftBukkit end
if (!this.world.isClientSide) {
this.a(irecipe);
@@ -319,7 +398,7 @@
}
protected int getRecipeCookingTime() {
- return (Integer) this.world.getCraftingManager().craft(this.c, this, this.world).map(RecipeCooking::getCookingTime).orElse(200);
+ return (this.hasWorld()) ? (Integer) this.world.getCraftingManager().craft((Recipes<RecipeCooking>) this.c, this, this.world).map(RecipeCooking::getCookingTime).orElse(200) : 200; // CraftBukkit - SPIGOT-4302 // Eclipse fail
}
public static boolean isFuel(ItemStack itemstack) {
@@ -446,14 +525,20 @@
@Override
public void b(EntityHuman entityhuman) {}
- public void d(EntityHuman entityhuman) {
- List<IRecipe<?>> list = this.a(entityhuman.world, entityhuman.getPositionVector());
+ public void d(EntityHuman entityhuman, ItemStack itemstack, int amount) { // CraftBukkit
+ List<IRecipe<?>> list = this.a(entityhuman.world, entityhuman.getPositionVector(), entityhuman, itemstack, amount); // CraftBukkit
entityhuman.discoverRecipes(list);
this.n.clear();
}
public List<IRecipe<?>> a(World world, Vec3D vec3d) {
+ // CraftBukkit start
+ return this.a(world, vec3d, null, null, 0);
+ }
+
+ public List<IRecipe<?>> a(World world, Vec3D vec3d, EntityHuman entityhuman, ItemStack itemstack, int amount) {
+ // CraftBukkit end
List<IRecipe<?>> list = Lists.newArrayList();
ObjectIterator objectiterator = this.n.object2IntEntrySet().iterator();
@@ -462,14 +547,14 @@
world.getCraftingManager().getRecipe((MinecraftKey) entry.getKey()).ifPresent((irecipe) -> {
list.add(irecipe);
- a(world, vec3d, entry.getIntValue(), ((RecipeCooking) irecipe).getExperience());
+ a(world, vec3d, entry.getIntValue(), ((RecipeCooking) irecipe).getExperience(), entityhuman, itemstack, amount); // CraftBukkit
});
}
return list;
}
- private static void a(World world, Vec3D vec3d, int i, float f) {
+ private void a(World world, Vec3D vec3d, int i, float f, EntityHuman entityhuman, ItemStack itemstack, int amount) { // CraftBukkit
int j = MathHelper.d((float) i * f);
float f1 = MathHelper.h((float) i * f);
@@ -477,6 +562,14 @@
++j;
}
+ // CraftBukkit start - fire FurnaceExtractEvent
+ if (amount != 0) {
+ FurnaceExtractEvent event = new FurnaceExtractEvent((Player) entityhuman.getBukkitEntity(), CraftBlock.at(world, position), org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(itemstack.getItem()), amount, j);
+ world.getServer().getPluginManager().callEvent(event);
+ j = event.getExpToDrop();
+ }
+ // CraftBukkit end
+
while (j > 0) {
int k = EntityExperienceOrb.getOrbValue(j);

View File

@@ -0,0 +1,134 @@
--- a/net/minecraft/server/TileEntityHopper.java
+++ b/net/minecraft/server/TileEntityHopper.java
@@ -7,12 +7,51 @@
import java.util.stream.IntStream;
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.event.inventory.InventoryMoveItemEvent;
+import org.bukkit.event.inventory.InventoryPickupItemEvent;
+import org.bukkit.inventory.Inventory;
+// CraftBukkit end
+
public class TileEntityHopper extends TileEntityLootable implements IHopper, ITickable {
private NonNullList<ItemStack> items;
private int j;
private long k;
+ // CraftBukkit start - add fields and methods
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+ private int maxStack = MAX_STACK;
+
+ public List<ItemStack> getContents() {
+ return this.items;
+ }
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ @Override
+ public int getMaxStackSize() {
+ return maxStack;
+ }
+
+ public void setMaxStackSize(int size) {
+ maxStack = size;
+ }
+ // CraftBukkit end
+
public TileEntityHopper() {
super(TileEntityTypes.HOPPER);
this.items = NonNullList.a(5, ItemStack.b);
@@ -138,7 +177,28 @@
for (int i = 0; i < this.getSize(); ++i) {
if (!this.getItem(i).isEmpty()) {
ItemStack itemstack = this.getItem(i).cloneItemStack();
- ItemStack itemstack1 = addItem(this, iinventory, this.splitStack(i, 1), enumdirection);
+ // ItemStack itemstack1 = addItem(this, iinventory, this.splitStack(i, 1), enumdirection);
+
+ // CraftBukkit start - Call event when pushing items into other inventories
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(this.splitStack(i, 1));
+
+ Inventory destinationInventory;
+ // Have to special case large chests as they work oddly
+ if (iinventory instanceof InventoryLargeChest) {
+ destinationInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((InventoryLargeChest) iinventory);
+ } else {
+ destinationInventory = iinventory.getOwner().getInventory();
+ }
+
+ InventoryMoveItemEvent event = new InventoryMoveItemEvent(this.getOwner().getInventory(), oitemstack.clone(), destinationInventory, true);
+ this.getWorld().getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ this.setItem(i, itemstack);
+ this.setCooldown(8); // Delay hopper checks
+ return false;
+ }
+ ItemStack itemstack1 = addItem(this, iinventory, CraftItemStack.asNMSCopy(event.getItem()), enumdirection);
+ // CraftBukkit end
if (itemstack1.isEmpty()) {
iinventory.update();
@@ -203,7 +263,34 @@
if (!itemstack.isEmpty() && b(iinventory, itemstack, i, enumdirection)) {
ItemStack itemstack1 = itemstack.cloneItemStack();
- ItemStack itemstack2 = addItem(iinventory, ihopper, iinventory.splitStack(i, 1), (EnumDirection) null);
+ // ItemStack itemstack2 = addItem(iinventory, ihopper, iinventory.splitStack(i, 1), (EnumDirection) null);
+ // CraftBukkit start - Call event on collection of items from inventories into the hopper
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(iinventory.splitStack(i, 1));
+
+ Inventory sourceInventory;
+ // Have to special case large chests as they work oddly
+ if (iinventory instanceof InventoryLargeChest) {
+ sourceInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((InventoryLargeChest) iinventory);
+ } else {
+ sourceInventory = iinventory.getOwner().getInventory();
+ }
+
+ InventoryMoveItemEvent event = new InventoryMoveItemEvent(sourceInventory, oitemstack.clone(), ihopper.getOwner().getInventory(), false);
+
+ ihopper.getWorld().getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ iinventory.setItem(i, itemstack1);
+
+ if (ihopper instanceof TileEntityHopper) {
+ ((TileEntityHopper) ihopper).setCooldown(8); // Delay hopper checks
+ } else if (ihopper instanceof EntityMinecartHopper) {
+ ((EntityMinecartHopper) ihopper).setCooldown(4); // Delay hopper minecart checks
+ }
+
+ return false;
+ }
+ ItemStack itemstack2 = addItem(iinventory, ihopper, CraftItemStack.asNMSCopy(event.getItem()), null);
+ // CraftBukkit end
if (itemstack2.isEmpty()) {
iinventory.update();
@@ -218,6 +305,13 @@
public static boolean a(IInventory iinventory, EntityItem entityitem) {
boolean flag = false;
+ // CraftBukkit start
+ InventoryPickupItemEvent event = new InventoryPickupItemEvent(iinventory.getOwner().getInventory(), (org.bukkit.entity.Item) entityitem.getBukkitEntity());
+ entityitem.world.getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return false;
+ }
+ // CraftBukkit end
ItemStack itemstack = entityitem.getItemStack().cloneItemStack();
ItemStack itemstack1 = addItem((IInventory) null, iinventory, itemstack, (EnumDirection) null);

View File

@@ -0,0 +1,152 @@
--- a/net/minecraft/server/TileEntityLectern.java
+++ b/net/minecraft/server/TileEntityLectern.java
@@ -2,9 +2,63 @@
import javax.annotation.Nullable;
-public class TileEntityLectern extends TileEntity implements Clearable, ITileInventory {
+// CraftBukkit start
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+import org.bukkit.Location;
+import org.bukkit.block.Lectern;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.inventory.InventoryHolder;
+// CraftBukkit end
+
+public class TileEntityLectern extends TileEntity implements Clearable, ITileInventory, ICommandListener { // CraftBukkit - ICommandListener
+
+ // CraftBukkit start - add fields and methods
+ public final IInventory inventory = new LecternInventory();
+ public class LecternInventory implements IInventory {
+
+ public List<HumanEntity> transaction = new ArrayList<>();
+ private int maxStack = 1;
+
+ @Override
+ public List<ItemStack> getContents() {
+ return Arrays.asList(book);
+ }
+
+ @Override
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ @Override
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ @Override
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ @Override
+ public void setMaxStackSize(int i) {
+ maxStack = i;
+ }
+
+ @Override
+ public Location getLocation() {
+ return new Location(world.getWorld(), position.getX(), position.getY(), position.getZ());
+ }
+
+ @Override
+ public InventoryHolder getOwner() {
+ return (Lectern) TileEntityLectern.this.getOwner();
+ }
+ // CraftBukkit end
- public final IInventory inventory = new IInventory() {
@Override
public int getSize() {
return 1;
@@ -49,11 +103,20 @@
}
@Override
- public void setItem(int i, ItemStack itemstack) {}
+ // CraftBukkit start
+ public void setItem(int i, ItemStack itemstack) {
+ if (i == 0) {
+ TileEntityLectern.this.setBook(itemstack);
+ if (TileEntityLectern.this.getWorld() != null) {
+ BlockLectern.setHasBook(TileEntityLectern.this.getWorld(), TileEntityLectern.this.getPosition(), TileEntityLectern.this.getBlock(), TileEntityLectern.this.hasBook());
+ }
+ }
+ }
+ // CraftBukkit end
@Override
public int getMaxStackSize() {
- return 1;
+ return maxStack; // CraftBukkit
}
@Override
@@ -135,7 +198,7 @@
if (j != this.page) {
this.page = j;
this.update();
- BlockLectern.a(this.getWorld(), this.getPosition(), this.getBlock());
+ if (this.world != null) BlockLectern.a(this.getWorld(), this.getPosition(), this.getBlock()); // CraftBukkit
}
}
@@ -158,6 +221,32 @@
return itemstack;
}
+ // CraftBukkit start
+ @Override
+ public void sendMessage(IChatBaseComponent ichatbasecomponent, UUID uuid) {
+ }
+
+ @Override
+ public org.bukkit.command.CommandSender getBukkitSender(CommandListenerWrapper wrapper) {
+ return wrapper.getEntity() != null ? wrapper.getEntity().getBukkitSender(wrapper) : new org.bukkit.craftbukkit.command.CraftBlockCommandSender(wrapper, this);
+ }
+
+ @Override
+ public boolean shouldSendSuccess() {
+ return false;
+ }
+
+ @Override
+ public boolean shouldSendFailure() {
+ return false;
+ }
+
+ @Override
+ public boolean shouldBroadcastCommands() {
+ return false;
+ }
+
+ // CraftBukkit end
private CommandListenerWrapper a(@Nullable EntityHuman entityhuman) {
String s;
Object object;
@@ -172,7 +261,8 @@
Vec3D vec3d = Vec3D.a((BaseBlockPosition) this.position);
- return new CommandListenerWrapper(ICommandListener.DUMMY, vec3d, Vec2F.a, (WorldServer) this.world, 2, s, (IChatBaseComponent) object, this.world.getMinecraftServer(), entityhuman);
+ // CraftBukkit - this
+ return new CommandListenerWrapper(this, vec3d, Vec2F.a, (WorldServer) this.world, 2, s, (IChatBaseComponent) object, this.world.getMinecraftServer(), entityhuman);
}
@Override
@@ -211,7 +301,7 @@
@Override
public Container createMenu(int i, PlayerInventory playerinventory, EntityHuman entityhuman) {
- return new ContainerLectern(i, this.inventory, this.containerProperties);
+ return new ContainerLectern(i, this.inventory, this.containerProperties, playerinventory); // CraftBukkit
}
@Override

View File

@@ -0,0 +1,68 @@
--- a/net/minecraft/server/TileEntityShulkerBox.java
+++ b/net/minecraft/server/TileEntityShulkerBox.java
@@ -4,6 +4,11 @@
import java.util.stream.IntStream;
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
public class TileEntityShulkerBox extends TileEntityLootable implements IWorldInventory, ITickable {
private static final int[] a = IntStream.range(0, 27).toArray();
@@ -16,6 +21,37 @@
private EnumColor l;
private boolean m;
+ // CraftBukkit start - add fields and methods
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+ private int maxStack = MAX_STACK;
+ public boolean opened;
+
+ public List<ItemStack> getContents() {
+ return this.contents;
+ }
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ @Override
+ public int getMaxStackSize() {
+ return maxStack;
+ }
+
+ public void setMaxStackSize(int size) {
+ maxStack = size;
+ }
+ // CraftBukkit end
+
public TileEntityShulkerBox(@Nullable EnumColor enumcolor) {
super(TileEntityTypes.SHULKER_BOX);
this.contents = NonNullList.a(27, ItemStack.b);
@@ -178,6 +214,7 @@
}
++this.viewingCount;
+ if (opened) return; // CraftBukkit - only animate if the ShulkerBox hasn't been forced open already by an API call.
this.world.playBlockAction(this.position, this.getBlock().getBlock(), 1, this.viewingCount);
if (this.viewingCount == 1) {
this.world.playSound((EntityHuman) null, this.position, SoundEffects.BLOCK_SHULKER_BOX_OPEN, SoundCategory.BLOCKS, 0.5F, this.world.random.nextFloat() * 0.1F + 0.9F);
@@ -190,6 +227,7 @@
public void closeContainer(EntityHuman entityhuman) {
if (!entityhuman.isSpectator()) {
--this.viewingCount;
+ if (opened) return; // CraftBukkit - only animate if the ShulkerBox hasn't been forced open already by an API call.
this.world.playBlockAction(this.position, this.getBlock().getBlock(), 1, this.viewingCount);
if (this.viewingCount <= 0) {
this.world.playSound((EntityHuman) null, this.position, SoundEffects.BLOCK_SHULKER_BOX_CLOSE, SoundCategory.BLOCKS, 0.5F, this.world.random.nextFloat() * 0.1F + 0.9F);

View File

@@ -0,0 +1,118 @@
--- a/net/minecraft/server/TileEntitySign.java
+++ b/net/minecraft/server/TileEntitySign.java
@@ -3,7 +3,7 @@
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import javax.annotation.Nullable;
-public class TileEntitySign extends TileEntity {
+public class TileEntitySign extends TileEntity implements ICommandListener { // CraftBukkit - implements
public final IChatBaseComponent[] lines;
public boolean isEditable;
@@ -29,6 +29,12 @@
nbttagcompound.setString("Text" + (i + 1), s);
}
+ // CraftBukkit start
+ if (Boolean.getBoolean("convertLegacySigns")) {
+ nbttagcompound.setBoolean("Bukkit.isConverted", true);
+ }
+ // CraftBukkit end
+
nbttagcompound.setString("Color", this.color.c());
return nbttagcompound;
}
@@ -39,18 +45,38 @@
super.load(iblockdata, nbttagcompound);
this.color = EnumColor.a(nbttagcompound.getString("Color"), EnumColor.BLACK);
+ // CraftBukkit start - Add an option to convert signs correctly
+ // This is done with a flag instead of all the time because
+ // we have no way to tell whether a sign is from 1.7.10 or 1.8
+
+ boolean oldSign = Boolean.getBoolean("convertLegacySigns") && !nbttagcompound.getBoolean("Bukkit.isConverted");
+
for (int i = 0; i < 4; ++i) {
String s = nbttagcompound.getString("Text" + (i + 1));
- IChatMutableComponent ichatmutablecomponent = IChatBaseComponent.ChatSerializer.a(s.isEmpty() ? "\"\"" : s);
+ if (s != null && s.length() > 2048) {
+ s = "\"\"";
+ }
+
+ try {
+ IChatMutableComponent ichatmutablecomponent = IChatBaseComponent.ChatSerializer.a(s.isEmpty() ? "\"\"" : s);
- if (this.world instanceof WorldServer) {
- try {
- this.lines[i] = ChatComponentUtils.filterForDisplay(this.a((EntityPlayer) null), ichatmutablecomponent, (Entity) null, 0);
- } catch (CommandSyntaxException commandsyntaxexception) {
+ if (oldSign) {
+ lines[i] = org.bukkit.craftbukkit.util.CraftChatMessage.fromString(s)[0];
+ continue;
+ }
+ // CraftBukkit end
+
+ if (this.world instanceof WorldServer) {
+ try {
+ this.lines[i] = ChatComponentUtils.filterForDisplay(this.a((EntityPlayer) null), ichatmutablecomponent, (Entity) null, 0);
+ } catch (CommandSyntaxException commandsyntaxexception) {
+ this.lines[i] = ichatmutablecomponent;
+ }
+ } else {
this.lines[i] = ichatmutablecomponent;
}
- } else {
- this.lines[i] = ichatmutablecomponent;
+ } catch (com.google.gson.JsonParseException jsonparseexception) {
+ this.lines[i] = new ChatComponentText(s);
}
this.g[i] = null;
@@ -111,11 +137,37 @@
return true;
}
+ // CraftBukkit start
+ @Override
+ public void sendMessage(IChatBaseComponent ichatbasecomponent, java.util.UUID uuid) {}
+
+ @Override
+ public org.bukkit.command.CommandSender getBukkitSender(CommandListenerWrapper wrapper) {
+ return wrapper.getEntity() != null ? wrapper.getEntity().getBukkitSender(wrapper) : new org.bukkit.craftbukkit.command.CraftBlockCommandSender(wrapper, this);
+ }
+
+ @Override
+ public boolean shouldSendSuccess() {
+ return false;
+ }
+
+ @Override
+ public boolean shouldSendFailure() {
+ return false;
+ }
+
+ @Override
+ public boolean shouldBroadcastCommands() {
+ return false;
+ }
+ // CraftBukkit end
+
public CommandListenerWrapper a(@Nullable EntityPlayer entityplayer) {
String s = entityplayer == null ? "Sign" : entityplayer.getDisplayName().getString();
Object object = entityplayer == null ? new ChatComponentText("Sign") : entityplayer.getScoreboardDisplayName();
- return new CommandListenerWrapper(ICommandListener.DUMMY, Vec3D.a((BaseBlockPosition) this.position), Vec2F.a, (WorldServer) this.world, 2, s, (IChatBaseComponent) object, this.world.getMinecraftServer(), entityplayer);
+ // CraftBukkit - this
+ return new CommandListenerWrapper(this, Vec3D.a((BaseBlockPosition) this.position), Vec2F.a, (WorldServer) this.world, 2, s, (IChatBaseComponent) object, this.world.getMinecraftServer(), entityplayer);
}
public EnumColor getColor() {
@@ -126,7 +178,7 @@
if (enumcolor != this.getColor()) {
this.color = enumcolor;
this.update();
- this.world.notify(this.getPosition(), this.getBlock(), this.getBlock(), 3);
+ if (this.world != null) this.world.notify(this.getPosition(), this.getBlock(), this.getBlock(), 3); // CraftBukkit - skip notify if world is null (SPIGOT-5122)
return true;
} else {
return false;