mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 05:06:45 +01:00
Avoid picking up items to the hotbar while using unarmed. Fixes #939
This commit is contained in:
parent
532c2e7450
commit
7fe8122499
@ -15,6 +15,7 @@ Version 1.4.06-dev
|
||||
= Fixed wolves from Call of the Wild only having 8 health
|
||||
= Fixed bug where /party chat was not working
|
||||
! Changed Chimaera Wing's recipe result to use the ingredient Material
|
||||
! Players will no longer pickup items to their hotbar while using Unarmed
|
||||
|
||||
Version 1.4.05
|
||||
+ Added option to allow refreshing of chunks after block-breaking abilities. (Disabled by default)
|
||||
|
@ -85,6 +85,8 @@ public class McMMOPlayer {
|
||||
private int recentlyHurt;
|
||||
private int respawnATS;
|
||||
|
||||
private SkillType lastGained;
|
||||
|
||||
public McMMOPlayer(Player player) {
|
||||
String playerName = player.getName();
|
||||
|
||||
@ -491,6 +493,7 @@ public class McMMOPlayer {
|
||||
spoutHud.setLastGained(skillType);
|
||||
}
|
||||
|
||||
lastGained = skillType;
|
||||
SkillUtils.xpCheckSkill(skillType, player, profile);
|
||||
}
|
||||
|
||||
@ -642,6 +645,14 @@ public class McMMOPlayer {
|
||||
partyChatMode = !partyChatMode;
|
||||
}
|
||||
|
||||
public SkillType getLastGained() {
|
||||
return lastGained;
|
||||
}
|
||||
|
||||
public void setLastGained(SkillType type) {
|
||||
this.lastGained = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies an experience gain using skill modifiers, global rate and perks
|
||||
*
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.gmail.nossr50.listeners;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -25,6 +27,7 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.chat.ChatManager;
|
||||
@ -200,7 +203,8 @@ public class PlayerListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Item item = event.getItem();
|
||||
Item drop = event.getItem();
|
||||
ItemStack dropStack = drop.getItemStack();
|
||||
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
@ -208,8 +212,32 @@ public class PlayerListener implements Listener {
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
if (mcMMOPlayer.inParty() && ItemUtils.isShareable(item.getItemStack())) {
|
||||
ShareHandler.handleItemShare(event, mcMMOPlayer);
|
||||
if (mcMMOPlayer.inParty() && ItemUtils.isShareable(dropStack)) {
|
||||
event.setCancelled(ShareHandler.handleItemShare(drop, mcMMOPlayer));
|
||||
}
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
int firstEmpty = inventory.firstEmpty();
|
||||
|
||||
if (mcMMOPlayer.getLastGained() == SkillType.UNARMED && ItemUtils.isShareable(dropStack) && firstEmpty == inventory.getHeldItemSlot()) {
|
||||
int nextSlot = firstEmpty + 1;
|
||||
|
||||
for (Iterator<ItemStack> iterator = inventory.iterator(nextSlot); iterator.hasNext();) {
|
||||
ItemStack itemstack = iterator.next();
|
||||
|
||||
if (itemstack == null) {
|
||||
inventory.setItem(nextSlot, dropStack);
|
||||
player.updateInventory();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
nextSlot++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,9 +91,8 @@ public final class ShareHandler {
|
||||
* @param mcMMOPlayer Player who picked up the item
|
||||
* @return True if the item has been shared
|
||||
*/
|
||||
public static boolean handleItemShare(PlayerPickupItemEvent event, McMMOPlayer mcMMOPlayer) {
|
||||
Item item = event.getItem();
|
||||
ItemStack itemStack = item.getItemStack();
|
||||
public static boolean handleItemShare(Item drop, McMMOPlayer mcMMOPlayer) {
|
||||
ItemStack itemStack = drop.getItemStack();
|
||||
Party party = mcMMOPlayer.getParty();
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
Player winningPlayer = null;
|
||||
@ -126,8 +125,7 @@ public final class ShareHandler {
|
||||
nearMembers.add(player);
|
||||
partySize = nearMembers.size();
|
||||
|
||||
event.setCancelled(true);
|
||||
item.remove();
|
||||
drop.remove();
|
||||
int itemWeight = ItemWeightConfig.getInstance().getItemWeight(itemStack.getType());
|
||||
|
||||
for (int i = 0; i < itemStack.getAmount(); i++) {
|
||||
@ -172,8 +170,7 @@ public final class ShareHandler {
|
||||
|
||||
partySize = nearMembers.size() + 1;
|
||||
|
||||
event.setCancelled(true);
|
||||
item.remove();
|
||||
drop.remove();
|
||||
|
||||
for (int i = 0; i < itemStack.getAmount(); i++) {
|
||||
int randomMember = Misc.getRandom().nextInt(partySize);
|
||||
|
Loading…
Reference in New Issue
Block a user