Skip to content

Commit a26bad9

Browse files
authored
Merge pull request #22 from MrButtersDEV/v3_Pickup_System
V3 pickup system
2 parents 7af3656 + 9644361 commit a26bad9

File tree

11 files changed

+134
-7
lines changed

11 files changed

+134
-7
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-SNAPSHOT</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: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package us.thezircon.play.autopickup.listeners;
22

33
import me.crafter.mc.lockettepro.LocketteProAPI;
4+
import org.bukkit.ChatColor;
45
import org.bukkit.Location;
56
import org.bukkit.Material;
67
import org.bukkit.NamespacedKey;
@@ -20,10 +21,12 @@
2021
import org.bukkit.scheduler.BukkitRunnable;
2122
import us.thezircon.play.autopickup.AutoPickup;
2223
import us.thezircon.play.autopickup.utils.Mendable;
24+
import us.thezircon.play.autopickup.utils.PickupObjective;
2325
import us.thezircon.play.autopickup.utils.TallCrops;
2426
import world.bentobox.bentobox.BentoBox;
2527
import world.bentobox.bentobox.database.objects.Island;
2628

29+
import java.time.Instant;
2730
import java.util.ArrayList;
2831
import java.util.List;
2932

@@ -38,6 +41,7 @@ public void onBreak(BlockBreakEvent e) {
3841
Location loc = e.getBlock().getLocation();
3942
boolean doFullInvMSG = PLUGIN.getConfig().getBoolean("doFullInvMSG");
4043
boolean doBlacklist = PLUGIN.getBlacklistConf().getBoolean("doBlacklisted");
44+
4145
List<String> blacklist = PLUGIN.getBlacklistConf().getStringList("Blacklisted");
4246

4347
if (AutoPickup.worldsBlacklist!=null && AutoPickup.worldsBlacklist.contains(loc.getWorld().getName())) {
@@ -54,6 +58,19 @@ public void onBreak(BlockBreakEvent e) {
5458
return;
5559
}
5660

61+
// Check if inv is full title
62+
if (PLUGIN.getConfig().contains("titlebar")) {
63+
boolean doFullInvMSGTitleBar = PLUGIN.getConfig().getBoolean("titlebar.doTitleBar");
64+
String titleLine1 = ChatColor.translateAlternateColorCodes('&', PLUGIN.getConfig().getString("titlebar.line1"));
65+
String titleLine2 = ChatColor.translateAlternateColorCodes('&', PLUGIN.getConfig().getString("titlebar.line2"));
66+
if (player.getInventory().firstEmpty() == -1) { // Checks for inventory space
67+
//Player has no space
68+
if (doFullInvMSGTitleBar) {
69+
player.sendTitle(titleLine1, titleLine2, 1, 20, 1);
70+
}
71+
}
72+
}
73+
5774
// LockettePro Patch
5875
if (AutoPickup.usingLocketteProByBrunyman) {
5976
if (LocketteProAPI.isLocked(block)) {
@@ -106,6 +123,12 @@ public void run() {
106123
}
107124
e.setExpToDrop(0); // Remove default XP
108125

126+
///////////////////////////////////// Custom items \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
127+
String key = loc.getBlockX()+";"+loc.getBlockY()+";"+loc.getBlockZ()+";"+loc.getWorld();
128+
AutoPickup.customItemPatch.put(key, new PickupObjective(loc, player, Instant.now()));
129+
///////////////////////////////////////////////////////////////////////////////////////
130+
131+
109132
// Deal with Containers
110133
if (block.getState() instanceof Container) {
111134

@@ -115,7 +138,7 @@ public void run() {
115138

116139
// Upgradable Hoppers Patch
117140
if (block.getState() instanceof Hopper && AutoPickup.usingUpgradableHoppers) {
118-
NamespacedKey upgHoppers = new NamespacedKey(PLUGIN.getServer().getPluginManager().getPlugin("UpgradeableHoppers"), "upgradeablehoppers");
141+
NamespacedKey upgHoppers = new NamespacedKey(PLUGIN.getServer().getPluginManager().getPlugin("UpgradeableHoppers"), "upgradeablehoppers:o");
119142
Container con = (Container) block.getState();
120143
if (con.getPersistentDataContainer().getKeys().contains(upgHoppers)) {
121144
return;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.AutoSmelt;
11+
import us.thezircon.play.autopickup.utils.PickupObjective;
12+
13+
public class ItemSpawnEventListener implements Listener {
14+
15+
private static final AutoPickup PLUGIN = AutoPickup.getPlugin(AutoPickup.class);
16+
17+
///////////////////////////////////// Custom items \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
18+
19+
@EventHandler
20+
public void onSpawn(ItemSpawnEvent e) {
21+
Location loc = e.getLocation();
22+
String key = loc.getBlockX()+";"+loc.getBlockY()+";"+loc.getBlockZ()+";"+loc.getWorld();
23+
if (AutoPickup.customItemPatch.containsKey(key)) {
24+
PickupObjective po = AutoPickup.customItemPatch.get(key);
25+
ItemStack item = e.getEntity().getItemStack();
26+
Player player = po.getPlayer();
27+
boolean doSmelt = PLUGIN.auto_smelt_blocks.contains(player);
28+
if (player.getInventory().firstEmpty()!=-1) {
29+
e.getEntity().remove();
30+
if (doSmelt) {
31+
player.getInventory().addItem(AutoSmelt.smelt(item, player));
32+
} else {
33+
player.getInventory().addItem(item);
34+
}
35+
}
36+
}
37+
}
38+
39+
}
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+
}

src/main/resources/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ msgReload: "&cReloaded Config"
4040
#Fully Inventory Message
4141
msgFullInv: "&7Your inventory is full!"
4242
doFullInvMSG: true
43+
titlebar:
44+
doTitleBar: false
45+
line1: "&cWarning"
46+
line2: "&7Inventory is full!"
4347

4448
#This is most useful for prison servers! -- This setting is not normally recommended
4549
#This feature voids any extra blocks broken when /auto is enabled and the inventory is full!

target/classes/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ msgReload: "&cReloaded Config"
4040
#Fully Inventory Message
4141
msgFullInv: "&7Your inventory is full!"
4242
doFullInvMSG: true
43+
titlebar:
44+
doTitleBar: false
45+
line1: "&cWarning"
46+
line2: "&7Inventory is full!"
4347

4448
#This is most useful for prison servers! -- This setting is not normally recommended
4549
#This feature voids any extra blocks broken when /auto is enabled and the inventory is full!

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-SNAPSHOT
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.

0 commit comments

Comments
 (0)