3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-16 13:00:06 +01:00

SPIGOT-2787: Keep performing getter null conversion at call sites

Dieser Commit ist enthalten in:
md_5 2016-11-18 11:07:02 +11:00
Ursprung 0c3bb76487
Commit 93b8244115
6 geänderte Dateien mit 24 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -197,7 +197,7 @@ public class CraftEventFactory {
public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, BlockPosition position, EnumDirection direction, ItemStack itemstack, EnumHand hand) {
return callPlayerInteractEvent(who, action, position, direction, itemstack, false, hand);
}
public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, BlockPosition position, EnumDirection direction, ItemStack itemstack, boolean cancelledBlock, EnumHand hand) {
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
@ -220,6 +220,10 @@ public class CraftEventFactory {
}
BlockFace blockFace = CraftBlock.notchToBlockFace(direction);
if (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0) {
itemInHand = null;
}
PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace, (hand == null) ? null : ((hand == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND));
if (cancelledBlock) {
event.setUseInteractedBlock(Event.Result.DENY);
@ -992,7 +996,7 @@ public class CraftEventFactory {
}
public static PrepareAnvilEvent callPrepareAnvilEvent(InventoryView view, ItemStack item) {
PrepareAnvilEvent event = new PrepareAnvilEvent(view, CraftItemStack.asCraftMirror(item));
PrepareAnvilEvent event = new PrepareAnvilEvent(view, CraftItemStack.asCraftMirror(item).clone());
event.getView().getPlayer().getServer().getPluginManager().callEvent(event);
event.getInventory().setItem(2, event.getResult());
return event;
@ -1012,7 +1016,7 @@ public class CraftEventFactory {
public static EntityBreedEvent callEntityBreedEvent(EntityLiving child, EntityLiving mother, EntityLiving father, EntityLiving breeder, ItemStack bredWith, int experience) {
org.bukkit.entity.LivingEntity breederEntity = (LivingEntity)(breeder == null ? null : breeder.getBukkitEntity());
CraftItemStack bredWithStack = CraftItemStack.asCraftMirror(bredWith);
CraftItemStack bredWithStack = bredWith == null ? null : CraftItemStack.asCraftMirror(bredWith).clone();
EntityBreedEvent event = new EntityBreedEvent((LivingEntity) child.getBukkitEntity(), (LivingEntity) mother.getBukkitEntity(), (LivingEntity) father.getBukkitEntity(), breederEntity, bredWithStack, experience);
child.world.getServer().getPluginManager().callEvent(event);

Datei anzeigen

@ -46,7 +46,7 @@ public class CraftInventory implements Inventory {
public ItemStack getItem(int index) {
net.minecraft.server.ItemStack item = getInventory().getItem(index);
return CraftItemStack.asCraftMirror(item);
return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item);
}
@Override
@ -65,7 +65,7 @@ public class CraftInventory implements Inventory {
int size = Math.min(items.length, mcItems.size());
for (int i = 0; i < size; i++) {
items[i] = CraftItemStack.asCraftMirror(mcItems.get(i));
items[i] = (mcItems.get(i).isEmpty()) ? null : CraftItemStack.asCraftMirror(mcItems.get(i));
}
return items;
}

Datei anzeigen

@ -28,10 +28,10 @@ public class CraftInventoryAnvil extends CraftInventory implements AnvilInventor
public ItemStack getItem(int slot) {
if (slot < getIngredientsInventory().getSize()) {
net.minecraft.server.ItemStack item = getIngredientsInventory().getItem(slot);
return CraftItemStack.asCraftMirror(item);
return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item);
} else {
net.minecraft.server.ItemStack item = getResultInventory().getItem(slot - getIngredientsInventory().getSize());
return CraftItemStack.asCraftMirror(item);
return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item);
}
}

Datei anzeigen

@ -70,10 +70,10 @@ public class CraftInventoryCrafting extends CraftInventory implements CraftingIn
public CraftItemStack getItem(int index) {
if (index < getResultInventory().getSize()) {
net.minecraft.server.ItemStack item = getResultInventory().getItem(index);
return CraftItemStack.asCraftMirror(item);
return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item);
} else {
net.minecraft.server.ItemStack item = getMatrixInventory().getItem(index - getResultInventory().getSize());
return CraftItemStack.asCraftMirror(item);
return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item);
}
}
@ -99,7 +99,8 @@ public class CraftInventoryCrafting extends CraftInventory implements CraftingIn
public ItemStack getResult() {
net.minecraft.server.ItemStack item = getResultInventory().getItem(0);
return CraftItemStack.asCraftMirror(item);
if (!item.isEmpty()) return CraftItemStack.asCraftMirror(item);
return null;
}
public void setMatrix(ItemStack[] contents) {

Datei anzeigen

@ -68,7 +68,7 @@ public final class CraftItemStack extends ItemStack {
}
public static CraftItemStack asCraftMirror(net.minecraft.server.ItemStack original) {
return (original.isEmpty()) ? null : new CraftItemStack(original);
return new CraftItemStack(original);
}
public static CraftItemStack asCraftCopy(ItemStack original) {

Datei anzeigen

@ -25,4 +25,12 @@ public class NMSCraftItemStackTest extends AbstractTestingBase {
assertThat(clone.getData(), is(itemStack.getData()));
assertThat(clone, is(itemStack));
}
@Test
public void testCloneNullItem() throws Exception {
net.minecraft.server.ItemStack nmsItemStack = null;
ItemStack itemStack = CraftItemStack.asCraftMirror(nmsItemStack);
ItemStack clone = itemStack.clone();
assertThat(clone, is(itemStack));
}
}