Skip to content

Commit 8bd80ee

Browse files
authored
Merge pull request #73 from MrButtersDEV/master
Update
2 parents eb35926 + 442dace commit 8bd80ee

File tree

14 files changed

+314
-151
lines changed

14 files changed

+314
-151
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
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.5-SNAPSHOT</version>
9+
<version>1.4.7-DEVBUILD.4</version>
1010
<packaging>jar</packaging>
1111

1212
<name>AutoPickup</name>
@@ -83,7 +83,7 @@
8383
<dependency>
8484
<groupId>org.spigotmc</groupId>
8585
<artifactId>spigot-api</artifactId>
86-
<version>1.20-R0.1-SNAPSHOT</version>
86+
<version>1.21.1-R0.1-SNAPSHOT</version>
8787
<scope>provided</scope>
8888
</dependency>
8989
<dependency>
@@ -111,4 +111,4 @@
111111
<scope>provided</scope>
112112
</dependency>
113113
</dependencies>
114-
</project>
114+
</project>

src/main/java/us/thezircon/play/autopickup/AutoPickup.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package us.thezircon.play.autopickup;
22

33
import org.bukkit.Bukkit;
4+
import org.bukkit.Material;
45
import org.bukkit.configuration.InvalidConfigurationException;
56
import org.bukkit.configuration.file.FileConfiguration;
67
import org.bukkit.configuration.file.YamlConfiguration;
8+
import org.bukkit.entity.Entity;
79
import org.bukkit.entity.Player;
10+
import org.bukkit.inventory.FurnaceRecipe;
811
import org.bukkit.plugin.java.JavaPlugin;
912
import org.bukkit.scheduler.BukkitRunnable;
1013
import us.thezircon.play.autopickup.commands.AutoDrops;
@@ -49,8 +52,11 @@ public final class AutoPickup extends JavaPlugin {
4952
public static HashMap<String, PickupObjective> customItemPatch = new HashMap<>();
5053
public static HashSet<UUID> droppedItems = new HashSet<>();
5154

55+
// Cache smeling recipie list
56+
public static final Map<Material, FurnaceRecipe> smeltRecipeCache = new HashMap<>();
57+
5258
// Notification Cooldown
53-
public static HashMap<UUID, Long> lastInvFullNotification = new HashMap<>();
59+
public static WeakHashMap<UUID, Long> lastInvFullNotification = new WeakHashMap<>();
5460

5561
private static AutoPickup instance;
5662

@@ -179,12 +185,17 @@ public void run() {
179185
@Override
180186
public void run() {
181187
try {
182-
droppedItems.removeIf(uuid -> (Bukkit.getEntity(uuid))==null);
183-
droppedItems.removeIf(uuid -> (Bukkit.getEntity(uuid)).isDead()); ///////
188+
droppedItems.removeIf(uuid -> {
189+
Entity entity = Bukkit.getEntity(uuid);
190+
return entity == null || entity.isDead();
191+
});
184192
} catch (NullPointerException ignored) {}
185193
}
186194
}.runTaskTimer(this, 6000L, 6000L); // 5 min
187195

196+
// Load auto smelt cache
197+
AutoSmeltUtils.loadFurnaceRecipes(smeltRecipeCache);
198+
188199
}
189200

190201

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,43 @@
11
package us.thezircon.play.autopickup.api;
22

3+
import org.bukkit.Location;
34
import org.bukkit.entity.Item;
5+
import org.bukkit.entity.Player;
46
import us.thezircon.play.autopickup.AutoPickup;
7+
import us.thezircon.play.autopickup.utils.PickupObjective;
58

9+
import java.time.Instant;
610
import java.util.UUID;
711

812
public class AutoAPI {
913

14+
/**
15+
* @deprecated Experimental API; This api has not been tested & officially supported / may be removed.
16+
* @param itemEntity The Item Entity that should be ignored by AutoPickup
17+
*/
1018
public static void addIgnoredDrop(Item itemEntity) {
1119
UUID uuid = itemEntity.getUniqueId();
1220
addIgnoredDrop(uuid);
1321
}
1422

23+
/**
24+
* @deprecated Experimental API; This api has not been tested & officially supported / may be removed.
25+
* @param itemEntityUUID UUID of an item entity that should be ignored by AutoPickup
26+
*/
1527
public static void addIgnoredDrop(UUID itemEntityUUID) {
1628
AutoPickup.droppedItems.add(itemEntityUUID);
1729
}
1830

31+
/**
32+
* @param location The location that should be watched for possible custom drops.
33+
* @param player The player who broke said block.
34+
* @deprecated Experimental API; This api has not been tested & officially supported / may be removed.
35+
*
36+
* Blocks broken by players are already tagged for custom drops; this should be used for adjacent blocks that should be watched for additional custom drops.
37+
*/
38+
public static void tagCustomDropLocation(Location location, Player player) {
39+
String key = location.getBlockX()+";"+location.getBlockY()+";"+location.getBlockZ()+";"+location.getWorld();
40+
AutoPickup.customItemPatch.put(key, new PickupObjective(location, player, Instant.now()));
41+
}
42+
1943
}

src/main/java/us/thezircon/play/autopickup/commands/AutoPickup/Auto.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public Auto(){
3030
public ArrayList<CMDManager> getSubCommands(){
3131
return subcommands;
3232
}
33-
3433
@Override
3534
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
3635
boolean requirePermsAUTO = PLUGIN.getConfig().getBoolean("requirePerms.autopickup");

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

Lines changed: 127 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package us.thezircon.play.autopickup.listeners;
22

3-
import me.crafter.mc.lockettepro.LocketteProAPI;
3+
//import me.crafter.mc.lockettepro.LocketteProAPI;
44
import net.md_5.bungee.api.ChatMessageType;
55
import net.md_5.bungee.api.chat.TextComponent;
66
import org.bukkit.*;
@@ -85,11 +85,11 @@ public void run() {
8585
}
8686

8787
// LockettePro Patch
88-
if (AutoPickup.usingLocketteProByBrunyman) {
89-
if (LocketteProAPI.isLocked(block)) {
90-
return;
91-
}
92-
}
88+
// if (AutoPickup.usingLocketteProByBrunyman) {
89+
// if (LocketteProAPI.isLocked(block)) {
90+
// return;
91+
// }
92+
// }
9393

9494
// AOneBlock Patch
9595
new BukkitRunnable() {
@@ -324,7 +324,7 @@ public void run() {
324324
}
325325

326326
//deal with sugarcane
327-
if (e.getBlock().getType() == Material.SUGAR_CANE || e.getBlock().getType() == Material.GRASS || e.getBlock().getType() == Material.SAND) {
327+
if (e.getBlock().getType() == Material.SUGAR_CANE || e.getBlock().getType() == Material.GRASS_BLOCK || e.getBlock().getType() == Material.SAND) {
328328
Location lnew = l.clone();
329329
do {
330330
lnew.setY(lnew.getY() + 1);
@@ -337,6 +337,126 @@ public void run() {
337337
addLocation(lnew, e.getPlayer());
338338
}
339339

340+
if (
341+
Bukkit.getVersion().contains("1.16") ||
342+
Bukkit.getVersion().contains("1.17") ||
343+
Bukkit.getVersion().contains("1.18") ||
344+
Bukkit.getVersion().contains("1.19") ||
345+
Bukkit.getVersion().contains("1.20") ||
346+
Bukkit.getVersion().contains("1.21")
347+
) {
348+
//deal with weeping vines
349+
if (e.getBlock().getType() == Material.WEEPING_VINES_PLANT || e.getBlock().getRelative(BlockFace.DOWN).getType() == Material.WEEPING_VINES_PLANT) {
350+
Location lnew = l.clone();
351+
do {
352+
lnew.setY(lnew.getY() - 1);
353+
if (lnew.getBlock().getType() == Material.WEEPING_VINES_PLANT) {
354+
addLocation(lnew, e.getPlayer());
355+
} else {
356+
break;
357+
}
358+
} while (true);
359+
addLocation(lnew, e.getPlayer());
360+
} else if (e.getBlock().getType() == Material.WEEPING_VINES || e.getBlock().getRelative(BlockFace.DOWN).getType() == Material.WEEPING_VINES) {
361+
Location lnew = l.clone();
362+
do {
363+
lnew.setY(lnew.getY() - 1);
364+
if (lnew.getBlock().getType() == Material.WEEPING_VINES) {
365+
addLocation(lnew, e.getPlayer());
366+
} else {
367+
break;
368+
}
369+
} while (true);
370+
addLocation(lnew, e.getPlayer());
371+
}
372+
373+
//deal with twisting vines
374+
if (e.getBlock().getType() == Material.TWISTING_VINES_PLANT || e.getBlock().getRelative(BlockFace.UP).getType() == Material.TWISTING_VINES_PLANT) {
375+
Location lnew = l.clone();
376+
do {
377+
lnew.setY(lnew.getY() + 1);
378+
if (lnew.getBlock().getType() == Material.TWISTING_VINES_PLANT) {
379+
addLocation(lnew, e.getPlayer());
380+
} else {
381+
break;
382+
}
383+
} while (true);
384+
addLocation(lnew, e.getPlayer());
385+
} else if (e.getBlock().getType() == Material.TWISTING_VINES || e.getBlock().getRelative(BlockFace.UP).getType() == Material.TWISTING_VINES) {
386+
Location lnew = l.clone();
387+
do {
388+
lnew.setY(lnew.getY() + 1);
389+
if (lnew.getBlock().getType() == Material.TWISTING_VINES) {
390+
addLocation(lnew, e.getPlayer());
391+
} else {
392+
break;
393+
}
394+
} while (true);
395+
addLocation(lnew, e.getPlayer());
396+
}
397+
398+
if(!Bukkit.getVersion().contains("1.16")) {
399+
//deal with glow berries
400+
if (e.getBlock().getType() == Material.CAVE_VINES_PLANT || e.getBlock().getRelative(BlockFace.DOWN).getType() == Material.CAVE_VINES_PLANT) {
401+
Location lnew = l.clone();
402+
do {
403+
lnew.setY(lnew.getY() - 1);
404+
if (lnew.getBlock().getType() == Material.CAVE_VINES_PLANT) {
405+
addLocation(lnew, e.getPlayer());
406+
} else {
407+
break;
408+
}
409+
} while (true);
410+
addLocation(lnew, e.getPlayer());
411+
} else if (e.getBlock().getType() == Material.CAVE_VINES || e.getBlock().getRelative(BlockFace.DOWN).getType() == Material.CAVE_VINES) {
412+
Location lnew = l.clone();
413+
do {
414+
lnew.setY(lnew.getY() - 1);
415+
if (lnew.getBlock().getType() == Material.CAVE_VINES) {
416+
addLocation(lnew, e.getPlayer());
417+
} else {
418+
break;
419+
}
420+
} while (true);
421+
addLocation(lnew, e.getPlayer());
422+
}
423+
424+
//deal with dripleafs
425+
if (e.getBlock().getType() == Material.BIG_DRIPLEAF_STEM || e.getBlock().getRelative(BlockFace.UP).getType() == Material.BIG_DRIPLEAF_STEM) {
426+
Location lnew = l.clone();
427+
double y = lnew.getY();
428+
do {
429+
lnew.setY(lnew.getY() + 1);
430+
if (lnew.getBlock().getType() == Material.BIG_DRIPLEAF_STEM) {
431+
addLocation(lnew, e.getPlayer());
432+
} else if (lnew.getBlock().getType() == Material.BIG_DRIPLEAF) {
433+
addLocation(lnew, e.getPlayer());
434+
} else {
435+
y--;
436+
lnew.setY(y);
437+
if (lnew.getBlock().getType() == Material.BIG_DRIPLEAF_STEM) {
438+
addLocation(lnew, e.getPlayer());
439+
} else {
440+
break;
441+
}
442+
}
443+
} while (true);
444+
addLocation(lnew, e.getPlayer());
445+
} else if (e.getBlock().getType() == Material.BIG_DRIPLEAF || e.getBlock().getRelative(BlockFace.UP).getType() == Material.BIG_DRIPLEAF) {
446+
Location lnew = l.clone();
447+
do {
448+
lnew.setY(lnew.getY() - 1);
449+
if (lnew.getBlock().getType() == Material.BIG_DRIPLEAF) {
450+
addLocation(lnew, e.getPlayer());
451+
} else {
452+
break;
453+
}
454+
} while (true);
455+
addLocation(lnew, e.getPlayer());
456+
}
457+
}
458+
}
459+
340460
// TEST END
341461

342462
if (verticalReq.contains(e.getBlock().getType()) || verticalReqDown.contains(e.getBlock().getType())) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.bukkit.event.block.BlockDropItemEvent;
1111
import org.bukkit.inventory.ItemStack;
1212
import us.thezircon.play.autopickup.AutoPickup;
13-
import us.thezircon.play.autopickup.utils.AutoSmelt;
13+
import us.thezircon.play.autopickup.utils.AutoSmeltUtils;
1414
import us.thezircon.play.autopickup.utils.HexFormat;
1515

1616
import java.util.HashMap;
@@ -64,7 +64,7 @@ public void onDrop(BlockDropItemEvent e) {
6464
}
6565

6666
if (doSmelt) {
67-
drop = AutoSmelt.smelt(drop, player);
67+
drop = AutoSmeltUtils.smelt(drop, player);
6868
}
6969

7070
HashMap<Integer, ItemStack> leftOver = player.getInventory().addItem(drop);

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+

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void onClick(PlayerInteractEvent e) {
4444
@Override
4545
public void run() {
4646
for (Entity entity : loc.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
47-
if (entity.getType().equals(EntityType.DROPPED_ITEM)) {
47+
if (entity.getType().equals(EntityType.ITEM)) {
4848
Item item = (Item) entity;
4949
ItemStack items = item.getItemStack();
5050
if (items.getType().equals(Material.SWEET_BERRIES)) {

0 commit comments

Comments
 (0)