Skip to content
Permalink
Browse files

Fixed PASSIVE command items. This broke due to running an IntelliJ in…

…spection, that had a bug in logical equivalency calculations
  • Loading branch information
me4502 committed Jan 26, 2020
1 parent 0188261 commit 579bf37079fe1600e9cc29c6af3f6472bd8905f3
@@ -184,13 +184,13 @@ public boolean flipState(Block trigger, CraftBookPlayer player) throws InvalidMe

ChangedSign sign = CraftBookBukkitUtil.toChangedSign(trigger);

// Attempt to detect whether the bridge is above or below the sign,
// Attempt to detect whether the door is above or below the sign,
// first assuming that the bridge is above
Block proximalBaseCenter = getBlockBase(trigger);

BlockData doorType = getBlockType(trigger);
if (!BlockUtil.areBlocksIdentical(proximalBaseCenter, doorType)) {
throw new InvalidMechanismException("mech.bridge.material");
throw new InvalidMechanismException("mech.door.material");
}

// Find the other side
@@ -157,7 +157,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {

CraftBookPlayer player = CraftBookPlugin.inst().wrapPlayer(event.getPlayer());

if(showNameClick && MobSkullType.getEntityType(skull.getOwner()) == null) {
if(showNameClick && MobSkullType.getEntityType(skull.getOwner()) == null && skull.getOwner() != null) {
player.printRaw(ChatColor.YELLOW + player.translate("mech.headdrops.click-message") + ' ' + skull.getOwner());
} else if (MobSkullType.getEntityType(skull.getOwner()) != null) {
skull.setOwner(MobSkullType.getFromEntityType(MobSkullType.getEntityType(skull.getOwner())).getPlayerName());
@@ -14,6 +14,7 @@
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.Cancellable;
@@ -127,12 +128,12 @@ public boolean enable() {
}, 0, 20);
Bukkit.getScheduler().runTaskTimer(CraftBookPlugin.inst(), () -> {
for(Player player : Bukkit.getOnlinePlayers()) {
if(player.getInventory().getItemInMainHand() != null)
if(player.getInventory().getItemInMainHand().getType() != Material.AIR)
performCommandItems(player.getInventory().getItemInMainHand(), player, null);
if(player.getInventory().getItemInOffHand() != null)
if(player.getInventory().getItemInOffHand().getType() != Material.AIR)
performCommandItems(player.getInventory().getItemInOffHand(), player, null);
for(ItemStack stack : player.getInventory().getArmorContents())
if(stack != null)
if(stack != null && stack.getType() != Material.AIR)
performCommandItems(stack, player, null);
}
}, 10, 10);
@@ -193,10 +194,10 @@ public void onPlayerInteract(final PlayerInteractEvent event) {
@EventHandler(priority=EventPriority.HIGH)
public void onPlayerHitEntity(final PlayerInteractEntityEvent event) {

if(event.getPlayer().getItemInHand() == null)
if(event.getPlayer().getInventory().getItemInMainHand().getType() == Material.AIR)
return;

performCommandItems(event.getPlayer().getItemInHand(), event.getPlayer(), event);
performCommandItems(event.getPlayer().getInventory().getItemInMainHand(), event.getPlayer(), event);
}

@EventHandler(priority=EventPriority.HIGH)
@@ -304,7 +305,6 @@ public void onItemPickup(final EntityPickupItemEvent event) {
}
}

@SuppressWarnings("unchecked")
@EventHandler(priority=EventPriority.HIGH)
public void onPlayerDeath(PlayerDeathEvent event) {

@@ -346,7 +346,6 @@ public void onPlayerChat(AsyncPlayerChatEvent event) {
performCommandItems(event.getPlayer().getItemInHand(), event.getPlayer(), event);
}

@SuppressWarnings("unchecked")
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerRespawn(PlayerRespawnEvent event) {

@@ -361,9 +360,8 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
deathPersistItems.remove(event.getPlayer().getUniqueId());
}

@SuppressWarnings("deprecation")
public void performCommandItems(ItemStack item, final Player player, final Event event) {
if (event == null || !EventUtil.passesFilter(event))
if (event != null && !EventUtil.passesFilter(event))
return;

CraftBookPlayer lplayer = CraftBookPlugin.inst().wrapPlayer(player);
@@ -466,9 +464,9 @@ public void performCommandItems(ItemStack item, final Player player, final Event
player.getInventory().getItemInOffHand().setAmount(player.getInventory().getItemInOffHand().getAmount() - 1);
else
player.getInventory().setItemInOffHand(null);
} else if (event instanceof PlayerPickupItemEvent) {
((PlayerPickupItemEvent) event).getItem().remove();
((PlayerPickupItemEvent) event).setCancelled(true);
} else if (event instanceof EntityPickupItemEvent) {
((EntityPickupItemEvent) event).getItem().remove();
((EntityPickupItemEvent) event).setCancelled(true);
} else {
if (player.getInventory().getItemInMainHand().getAmount() > 1)
player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1);

0 comments on commit 579bf37

Please sign in to comment.
You can’t perform that action at this time.