Skip to content

Commit 4467bde

Browse files
committed
Custom Drop Support Dev.1
1 parent 7af3656 commit 4467bde

File tree

9 files changed

+102
-6
lines changed

9 files changed

+102
-6
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.2.2-SNAPSHOT</version>
9+
<version>1.3.0-DEVBUILD.1</version>
1010
<packaging>jar</packaging>
1111

1212
<name>AutoPickup</name>

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

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

3+
import org.bukkit.Bukkit;
4+
import org.bukkit.Location;
35
import org.bukkit.configuration.InvalidConfigurationException;
46
import org.bukkit.configuration.file.FileConfiguration;
57
import org.bukkit.configuration.file.YamlConfiguration;
@@ -10,15 +12,16 @@
1012
import us.thezircon.play.autopickup.commands.AutoPickup.Auto;
1113
import us.thezircon.play.autopickup.commands.AutoSmelt;
1214
import us.thezircon.play.autopickup.listeners.*;
13-
import us.thezircon.play.autopickup.utils.Messages;
14-
import us.thezircon.play.autopickup.utils.Metrics;
15-
import us.thezircon.play.autopickup.utils.TallCrops;
16-
import us.thezircon.play.autopickup.utils.VersionChk;
15+
import us.thezircon.play.autopickup.utils.*;
1716

1817
import java.io.File;
1918
import java.io.IOException;
2019
import java.net.UnknownHostException;
20+
import java.time.Duration;
21+
import java.time.Instant;
2122
import java.util.ArrayList;
23+
import java.util.HashMap;
24+
import java.util.Map;
2225
import java.util.UUID;
2326

2427
public final class AutoPickup extends JavaPlugin {
@@ -35,6 +38,10 @@ public final class AutoPickup extends JavaPlugin {
3538
public static boolean usingBentoBox = false; // BentoBox - AOneBlock Patch
3639
public static ArrayList<String> worldsBlacklist = null;
3740

41+
// Custom Items Patch
42+
public static HashMap<String, PickupObjective> customItemPatch = new HashMap<>();
43+
public static ArrayList<String> customItemPatchKeys = new ArrayList<>();
44+
3845
@Override
3946
public void onEnable() {
4047
// Plugin startup logic
@@ -66,6 +73,7 @@ public void onEnable() {
6673
getServer().getPluginManager().registerEvents(new BlockBreakEventListener(), this);
6774
getServer().getPluginManager().registerEvents(new EntityDeathEventListener(), this);
6875
getServer().getPluginManager().registerEvents(new PlayerInteractEventListener(), this);
76+
getServer().getPluginManager().registerEvents(new ItemSpawnEventListener(), this);
6977

7078
// Commands
7179
getCommand("autopickup").setExecutor(new Auto());
@@ -97,6 +105,24 @@ public void run() {
97105
if (getBlacklistConf().contains("BlacklistedWorlds")) {
98106
worldsBlacklist = (ArrayList<String>) getBlacklistConf().getList("BlacklistedWorlds");
99107
}
108+
109+
// Pickup Objective Cleaner
110+
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
111+
@Override
112+
public void run() {
113+
114+
for (String key : customItemPatchKeys) {
115+
if (customItemPatch.containsKey(key)) {
116+
PickupObjective po = customItemPatch.get(key);
117+
if (Duration.between(Instant.now(), po.getCreatedAt()).getSeconds() < -15) {
118+
customItemPatch.remove(key);
119+
customItemPatchKeys.remove(key);
120+
}
121+
}
122+
}
123+
124+
}
125+
}, 0L, 300L); // 15 sec
100126
}
101127

102128
@Override

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
import org.bukkit.scheduler.BukkitRunnable;
2121
import us.thezircon.play.autopickup.AutoPickup;
2222
import us.thezircon.play.autopickup.utils.Mendable;
23+
import us.thezircon.play.autopickup.utils.PickupObjective;
2324
import us.thezircon.play.autopickup.utils.TallCrops;
2425
import world.bentobox.bentobox.BentoBox;
2526
import world.bentobox.bentobox.database.objects.Island;
2627

28+
import java.time.Instant;
2729
import java.util.ArrayList;
2830
import java.util.List;
2931

@@ -106,6 +108,12 @@ public void run() {
106108
}
107109
e.setExpToDrop(0); // Remove default XP
108110

111+
///////////////////////////////////// Custom items \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
112+
String key = loc.getBlockX()+";"+loc.getBlockY()+";"+loc.getBlockZ()+";"+loc.getWorld();
113+
AutoPickup.customItemPatch.put(key, new PickupObjective(loc, player, Instant.now()));
114+
///////////////////////////////////////////////////////////////////////////////////////
115+
116+
109117
// Deal with Containers
110118
if (block.getState() instanceof Container) {
111119

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package us.thezircon.play.autopickup.listeners;
2+
3+
import org.bukkit.Location;
4+
import org.bukkit.entity.Player;
5+
import org.bukkit.event.EventHandler;
6+
import org.bukkit.event.Listener;
7+
import org.bukkit.event.entity.ItemSpawnEvent;
8+
import org.bukkit.inventory.ItemStack;
9+
import us.thezircon.play.autopickup.AutoPickup;
10+
import us.thezircon.play.autopickup.utils.PickupObjective;
11+
12+
public class ItemSpawnEventListener implements Listener {
13+
14+
///////////////////////////////////// Custom items \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
15+
16+
@EventHandler
17+
public void onSpawn(ItemSpawnEvent e) {
18+
Location loc = e.getLocation();
19+
String key = loc.getBlockX()+";"+loc.getBlockY()+";"+loc.getBlockZ()+";"+loc.getWorld();
20+
if (AutoPickup.customItemPatch.containsKey(key)) {
21+
PickupObjective po = AutoPickup.customItemPatch.get(key);
22+
ItemStack item = e.getEntity().getItemStack();
23+
Player player = po.getPlayer();
24+
if (player.getInventory().firstEmpty()!=-1) {
25+
e.getEntity().remove();
26+
player.getInventory().addItem(item);
27+
}
28+
}
29+
}
30+
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package us.thezircon.play.autopickup.utils;
2+
3+
import org.bukkit.Location;
4+
import org.bukkit.entity.Player;
5+
6+
import java.time.Instant;
7+
8+
public class PickupObjective {
9+
10+
private Location location;
11+
private Player player;
12+
private Instant createdAt;
13+
14+
public PickupObjective(Location location, Player player, Instant instant) {
15+
this.location = location;
16+
this.player = player;
17+
this.createdAt = instant;
18+
}
19+
20+
public Location getLocation() {
21+
return location;
22+
}
23+
24+
public Player getPlayer() {
25+
return player;
26+
}
27+
28+
public Instant getCreatedAt() {
29+
return createdAt;
30+
}
31+
}

target/classes/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: AutoPickup
2-
version: 1.2.2-SNAPSHOT
2+
version: 1.3.0-DEVBUILD.1
33
main: us.thezircon.play.autopickup.AutoPickup
44
prefix: AutoPickup
55
authors: [BUTTERFIELD8]
0 Bytes
Binary file not shown.
734 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)