Skip to content

Commit 3b0d3e8

Browse files
committed
Attempt to fix #66
This tries to make the sheep shearing logic more stable.
1 parent 3ce903e commit 3b0d3e8

File tree

2 files changed

+38
-34
lines changed

2 files changed

+38
-34
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>us.thezircon.play</groupId>
88
<artifactId>AutoPickup</artifactId>
9-
<version>1.4.7-DEVBUILD.2</version>
9+
<version>1.4.7-DEVBUILD.3</version>
1010
<packaging>jar</packaging>
1111

1212
<name>AutoPickup</name>

src/main/java/us/thezircon/play/autopickup/listeners/EntityDropItemEventListener.java

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,44 +34,48 @@ public void onDrop(EntityDropItemEvent e) {
3434
}
3535

3636
UUID sheep = e.getEntity().getUniqueId();
37-
if (player_sheep_map.containsKey(sheep)) {
38-
Player player = Bukkit.getPlayer(player_sheep_map.get(sheep));
39-
if (!PLUGIN.autopickup_list.contains(player)) {
40-
return;
41-
}
37+
UUID playerUUID = player_sheep_map.remove(sheep); // Avoid duplicate lookups
38+
if (playerUUID == null) return;
39+
40+
Player player = Bukkit.getPlayer(playerUUID);
41+
if (player == null) return;
42+
43+
if (!PLUGIN.autopickup_list.contains(player)) {
44+
return;
45+
}
4246

43-
// Drops
44-
ItemStack drops = e.getItemDrop().getItemStack();
45-
e.getItemDrop().remove();
46-
HashMap<Integer, ItemStack> leftOver = player.getInventory().addItem(drops);
47-
if (leftOver.keySet().size()>0) {
48-
for (ItemStack item : leftOver.values()) {
49-
player.getWorld().dropItemNaturally(e.getItemDrop().getLocation(), item);
47+
// Drops
48+
ItemStack drops = e.getItemDrop().getItemStack();
49+
e.getItemDrop().remove();
50+
HashMap<Integer, ItemStack> leftOver = player.getInventory().addItem(drops);
51+
if (leftOver.keySet().size()>0) {
52+
for (ItemStack item : leftOver.values()) {
53+
player.getWorld().dropItemNaturally(e.getItemDrop().getLocation(), item);
54+
}
55+
if (doFullInvMSG) {
56+
long secondsLeft;
57+
long cooldown = 15000; // 15 sec
58+
if (AutoPickup.lastInvFullNotification.containsKey(player.getUniqueId())) {
59+
secondsLeft = (AutoPickup.lastInvFullNotification.get(player.getUniqueId())/1000)+ cooldown/1000 - (System.currentTimeMillis()/1000);
60+
} else {
61+
secondsLeft = 0;
5062
}
51-
if (doFullInvMSG) {
52-
long secondsLeft;
53-
long cooldown = 15000; // 15 sec
54-
if (AutoPickup.lastInvFullNotification.containsKey(player.getUniqueId())) {
55-
secondsLeft = (AutoPickup.lastInvFullNotification.get(player.getUniqueId())/1000)+ cooldown/1000 - (System.currentTimeMillis()/1000);
56-
} else {
57-
secondsLeft = 0;
58-
}
59-
if (secondsLeft<=0) {
60-
player.sendMessage(PLUGIN.getMsg().getPrefix() + " " + PLUGIN.getMsg().getFullInventory());
61-
AutoPickup.lastInvFullNotification.put(player.getUniqueId(), System.currentTimeMillis());
62-
}
63+
if (secondsLeft<=0) {
64+
player.sendMessage(PLUGIN.getMsg().getPrefix() + " " + PLUGIN.getMsg().getFullInventory());
65+
AutoPickup.lastInvFullNotification.put(player.getUniqueId(), System.currentTimeMillis());
6366
}
6467
}
68+
}
6569

66-
Bukkit.getScheduler().runTaskAsynchronously(PLUGIN, new Runnable() {
67-
@Override
68-
public void run() {
69-
if (!player.hasPermission("autopickup.pickup.mined")) {
70-
PLUGIN.autopickup_list.remove(player);
71-
}
70+
Bukkit.getScheduler().runTaskAsynchronously(PLUGIN, new Runnable() {
71+
@Override
72+
public void run() {
73+
if (!player.hasPermission("autopickup.pickup.mined")) {
74+
PLUGIN.autopickup_list.remove(player);
7275
}
73-
});
74-
}
76+
}
77+
});
7578
}
76-
7779
}
80+
81+

0 commit comments

Comments
 (0)