mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 22:56: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 wolves from Call of the Wild only having 8 health
|
||||||
= Fixed bug where /party chat was not working
|
= Fixed bug where /party chat was not working
|
||||||
! Changed Chimaera Wing's recipe result to use the ingredient Material
|
! 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
|
Version 1.4.05
|
||||||
+ Added option to allow refreshing of chunks after block-breaking abilities. (Disabled by default)
|
+ 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 recentlyHurt;
|
||||||
private int respawnATS;
|
private int respawnATS;
|
||||||
|
|
||||||
|
private SkillType lastGained;
|
||||||
|
|
||||||
public McMMOPlayer(Player player) {
|
public McMMOPlayer(Player player) {
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
|
|
||||||
@ -491,6 +493,7 @@ public class McMMOPlayer {
|
|||||||
spoutHud.setLastGained(skillType);
|
spoutHud.setLastGained(skillType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastGained = skillType;
|
||||||
SkillUtils.xpCheckSkill(skillType, player, profile);
|
SkillUtils.xpCheckSkill(skillType, player, profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -642,6 +645,14 @@ public class McMMOPlayer {
|
|||||||
partyChatMode = !partyChatMode;
|
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
|
* Modifies an experience gain using skill modifiers, global rate and perks
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.gmail.nossr50.listeners;
|
package com.gmail.nossr50.listeners;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
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.PlayerQuitEvent;
|
||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.chat.ChatManager;
|
import com.gmail.nossr50.chat.ChatManager;
|
||||||
@ -200,7 +203,8 @@ public class PlayerListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
Item item = event.getItem();
|
Item drop = event.getItem();
|
||||||
|
ItemStack dropStack = drop.getItemStack();
|
||||||
|
|
||||||
if (Misc.isNPCEntity(player)) {
|
if (Misc.isNPCEntity(player)) {
|
||||||
return;
|
return;
|
||||||
@ -208,8 +212,32 @@ public class PlayerListener implements Listener {
|
|||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
if (mcMMOPlayer.inParty() && ItemUtils.isShareable(item.getItemStack())) {
|
if (mcMMOPlayer.inParty() && ItemUtils.isShareable(dropStack)) {
|
||||||
ShareHandler.handleItemShare(event, mcMMOPlayer);
|
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
|
* @param mcMMOPlayer Player who picked up the item
|
||||||
* @return True if the item has been shared
|
* @return True if the item has been shared
|
||||||
*/
|
*/
|
||||||
public static boolean handleItemShare(PlayerPickupItemEvent event, McMMOPlayer mcMMOPlayer) {
|
public static boolean handleItemShare(Item drop, McMMOPlayer mcMMOPlayer) {
|
||||||
Item item = event.getItem();
|
ItemStack itemStack = drop.getItemStack();
|
||||||
ItemStack itemStack = item.getItemStack();
|
|
||||||
Party party = mcMMOPlayer.getParty();
|
Party party = mcMMOPlayer.getParty();
|
||||||
Player player = mcMMOPlayer.getPlayer();
|
Player player = mcMMOPlayer.getPlayer();
|
||||||
Player winningPlayer = null;
|
Player winningPlayer = null;
|
||||||
@ -126,8 +125,7 @@ public final class ShareHandler {
|
|||||||
nearMembers.add(player);
|
nearMembers.add(player);
|
||||||
partySize = nearMembers.size();
|
partySize = nearMembers.size();
|
||||||
|
|
||||||
event.setCancelled(true);
|
drop.remove();
|
||||||
item.remove();
|
|
||||||
int itemWeight = ItemWeightConfig.getInstance().getItemWeight(itemStack.getType());
|
int itemWeight = ItemWeightConfig.getInstance().getItemWeight(itemStack.getType());
|
||||||
|
|
||||||
for (int i = 0; i < itemStack.getAmount(); i++) {
|
for (int i = 0; i < itemStack.getAmount(); i++) {
|
||||||
@ -172,8 +170,7 @@ public final class ShareHandler {
|
|||||||
|
|
||||||
partySize = nearMembers.size() + 1;
|
partySize = nearMembers.size() + 1;
|
||||||
|
|
||||||
event.setCancelled(true);
|
drop.remove();
|
||||||
item.remove();
|
|
||||||
|
|
||||||
for (int i = 0; i < itemStack.getAmount(); i++) {
|
for (int i = 0; i < itemStack.getAmount(); i++) {
|
||||||
int randomMember = Misc.getRandom().nextInt(partySize);
|
int randomMember = Misc.getRandom().nextInt(partySize);
|
||||||
|
Loading…
Reference in New Issue
Block a user