diff --git a/TwosideKeeper.jar b/TwosideKeeper.jar index 5ec708c..1f1925e 100644 Binary files a/TwosideKeeper.jar and b/TwosideKeeper.jar differ diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java index f51320b..b206920 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java @@ -12,6 +12,7 @@ import java.util.Set; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Chunk; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; @@ -2797,7 +2798,7 @@ public class GenericFunctions { for (ItemStack item : p.getEquipment().getArmorContents()) { if (isArtifactEquip(item) && ArtifactAbility.containsEnchantment(ArtifactAbility.GREED, item)) { - TwosideKeeper.log("Found one.",5); + //TwosideKeeper.log("Found one. "+item,0); int tier = ArtifactUtils.getArtifactTier(item); if (Math.random()<=(8-(tier/2d))/100d) { item = ArtifactAbility.downgradeEnchantment(p, item, ArtifactAbility.GREED); @@ -2817,6 +2818,7 @@ public class GenericFunctions { ArtifactAbility.containsEnchantment(ArtifactAbility.GREED, item)) { int tier = ArtifactUtils.getArtifactTier(item); //TwosideKeeper.log("Chance is "+((8-(tier/2d))/100d), 0); + //TwosideKeeper.log("Found one. "+item,0); if (Math.random()<=(8-(tier/2d))/100d) { item = ArtifactAbility.downgradeEnchantment(p, item, ArtifactAbility.GREED); //AwakenedArtifact.setLV(item, AwakenedArtifact.getLV(item)-1, p); @@ -5233,4 +5235,17 @@ public class GenericFunctions { pd.lastusedbeastwithin=TwosideKeeper.getServerTickTime(); } } + + public static void dropItem(ItemStack oldMainHand, Location l) { + Chunk c = l.getChunk(); + TwosideKeeper.temporary_chunks.add(c); + Item it = null; + do { + c.load(); + it = l.getWorld().dropItemNaturally(l, oldMainHand); + it.setInvulnerable(true); + } while (it==null || !it.isValid()); + TwosideKeeper.temporary_chunks.remove(c); + c.unload(); + } } diff --git a/src/sig/plugin/TwosideKeeper/TwosideKeeper.java b/src/sig/plugin/TwosideKeeper/TwosideKeeper.java index 0a5ed69..d1890ca 100644 --- a/src/sig/plugin/TwosideKeeper/TwosideKeeper.java +++ b/src/sig/plugin/TwosideKeeper/TwosideKeeper.java @@ -133,6 +133,7 @@ import org.bukkit.event.player.PlayerFishEvent.State; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemBreakEvent; +import org.bukkit.event.player.PlayerItemConsumeEvent; import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerKickEvent; @@ -7793,8 +7794,44 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } } } - + @EventHandler(priority=EventPriority.LOW,ignoreCancelled = true) + public void onItemConsume(PlayerItemConsumeEvent ev) { + //TwosideKeeper.log("Player is holding "+ev.getPlayer().getEquipment().getItemInMainHand(), 0); + if (EatingSoupFromOffHand(ev.getPlayer())) { + //TwosideKeeper.log("Eating soup from OffHand.", 0); + //We know vanilla minecraft will bug this out. Replace the bowl in the off-hand with the consumed item (with 1 smaller stack size) + //Replace our main hand with the item we were holding in our main hand. + final ItemStack oldMainHand = ev.getPlayer().getEquipment().getItemInMainHand().clone(); + final ItemStack oldOffHand = ev.getItem(); + final Player p = ev.getPlayer(); + final Location l = ev.getPlayer().getLocation().clone(); + final int slot = ev.getPlayer().getInventory().getHeldItemSlot(); + Bukkit.getScheduler().runTaskLater(TwosideKeeper.plugin, ()->{ + if (p!=null && p.isValid()) { + //TwosideKeeper.log("Resetting items... Slot: "+slot+", Main Hand: "+oldMainHand+", Off Hand: "+oldOffHand, 0); + aPlugin.API.setSlot(p, slot); + p.getEquipment().setItemInMainHand(oldMainHand); + oldOffHand.setAmount(oldOffHand.getAmount()-1); + p.getEquipment().setItemInOffHand(oldOffHand); + } else { + TwosideKeeper.log("WARNING!! Could not give recovered item for eating soup from off-hand back! Dropping "+oldMainHand+" at Location "+l, 1); + GenericFunctions.dropItem(oldMainHand, l); + } + }, 1); + } + } + + private boolean EatingSoupFromOffHand(Player p) { + return isSoup(p.getEquipment().getItemInOffHand()) && + p.getEquipment().getItemInOffHand().getAmount()>1 && + !isSoup(p.getEquipment().getItemInMainHand()); + } + private boolean isSoup(ItemStack item) { + return item.getType()==Material.MUSHROOM_SOUP || + item.getType()==Material.BEETROOT_SOUP; + } + @EventHandler(priority=EventPriority.LOW,ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent ev) { TwosideSpleefGames.PassEvent(ev);