Fixed bug involving consuming of soup stacks in off-hand.
This commit is contained in:
parent
6ba5c21dfd
commit
55b6d99e91
Binary file not shown.
@ -12,6 +12,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Effect;
|
import org.bukkit.Effect;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -2797,7 +2798,7 @@ public class GenericFunctions {
|
|||||||
for (ItemStack item : p.getEquipment().getArmorContents()) {
|
for (ItemStack item : p.getEquipment().getArmorContents()) {
|
||||||
if (isArtifactEquip(item) &&
|
if (isArtifactEquip(item) &&
|
||||||
ArtifactAbility.containsEnchantment(ArtifactAbility.GREED, item)) {
|
ArtifactAbility.containsEnchantment(ArtifactAbility.GREED, item)) {
|
||||||
TwosideKeeper.log("Found one.",5);
|
//TwosideKeeper.log("Found one. "+item,0);
|
||||||
int tier = ArtifactUtils.getArtifactTier(item);
|
int tier = ArtifactUtils.getArtifactTier(item);
|
||||||
if (Math.random()<=(8-(tier/2d))/100d) {
|
if (Math.random()<=(8-(tier/2d))/100d) {
|
||||||
item = ArtifactAbility.downgradeEnchantment(p, item, ArtifactAbility.GREED);
|
item = ArtifactAbility.downgradeEnchantment(p, item, ArtifactAbility.GREED);
|
||||||
@ -2817,6 +2818,7 @@ public class GenericFunctions {
|
|||||||
ArtifactAbility.containsEnchantment(ArtifactAbility.GREED, item)) {
|
ArtifactAbility.containsEnchantment(ArtifactAbility.GREED, item)) {
|
||||||
int tier = ArtifactUtils.getArtifactTier(item);
|
int tier = ArtifactUtils.getArtifactTier(item);
|
||||||
//TwosideKeeper.log("Chance is "+((8-(tier/2d))/100d), 0);
|
//TwosideKeeper.log("Chance is "+((8-(tier/2d))/100d), 0);
|
||||||
|
//TwosideKeeper.log("Found one. "+item,0);
|
||||||
if (Math.random()<=(8-(tier/2d))/100d) {
|
if (Math.random()<=(8-(tier/2d))/100d) {
|
||||||
item = ArtifactAbility.downgradeEnchantment(p, item, ArtifactAbility.GREED);
|
item = ArtifactAbility.downgradeEnchantment(p, item, ArtifactAbility.GREED);
|
||||||
//AwakenedArtifact.setLV(item, AwakenedArtifact.getLV(item)-1, p);
|
//AwakenedArtifact.setLV(item, AwakenedArtifact.getLV(item)-1, p);
|
||||||
@ -5233,4 +5235,17 @@ public class GenericFunctions {
|
|||||||
pd.lastusedbeastwithin=TwosideKeeper.getServerTickTime();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,6 +133,7 @@ import org.bukkit.event.player.PlayerFishEvent.State;
|
|||||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerItemBreakEvent;
|
import org.bukkit.event.player.PlayerItemBreakEvent;
|
||||||
|
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
||||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerKickEvent;
|
import org.bukkit.event.player.PlayerKickEvent;
|
||||||
@ -7795,6 +7796,42 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority=EventPriority.LOW,ignoreCancelled = true)
|
@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) {
|
public void onBlockBreak(BlockBreakEvent ev) {
|
||||||
|
|
||||||
TwosideSpleefGames.PassEvent(ev);
|
TwosideSpleefGames.PassEvent(ev);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user