Skip to content

Commit 2ae65f1

Browse files
committed
Added full inventory cooldown timer
1 parent 585ad82 commit 2ae65f1

5 files changed

Lines changed: 54 additions & 10 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public final class AutoPickup extends JavaPlugin {
4949
public static HashMap<String, PickupObjective> customItemPatch = new HashMap<>();
5050
public static HashSet<UUID> droppedItems = new HashSet<>();
5151

52+
// Notification Cooldown
53+
public static HashMap<UUID, Long> lastInvFullNotification = new HashMap<>();
54+
5255
private static AutoPickup instance;
5356

5457
@Override
@@ -120,11 +123,11 @@ public void onEnable() {
120123
// Listeners
121124
getServer().getPluginManager().registerEvents(new BlockDropItemEventListener(), this);
122125
getServer().getPluginManager().registerEvents(new PlayerJoinEventListener(), this);
123-
getServer().getPluginManager().registerEvents(new BlockBreakEventListener(), this);
126+
// getServer().getPluginManager().registerEvents(new BlockBreakEventListener(), this);
124127
getServer().getPluginManager().registerEvents(new EntityDeathEventListener(), this);
125128
getServer().getPluginManager().registerEvents(new PlayerInteractEventListener(), this);
126129
getServer().getPluginManager().registerEvents(new PlayerDropItemEventListener(), this);
127-
getServer().getPluginManager().registerEvents(new ItemSpawnEventListener(), this);
130+
// getServer().getPluginManager().registerEvents(new ItemSpawnEventListener(), this);
128131

129132
if (usingMythicMobs) {
130133
getServer().getPluginManager().registerEvents(new MythicMobListener(), this);

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

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

33
import me.crafter.mc.lockettepro.LocketteProAPI;
4-
import org.bukkit.Bukkit;
5-
import org.bukkit.Location;
6-
import org.bukkit.Material;
7-
import org.bukkit.NamespacedKey;
4+
import net.md_5.bungee.api.ChatMessageType;
5+
import net.md_5.bungee.api.chat.TextComponent;
6+
import org.bukkit.*;
87
import org.bukkit.block.*;
98
import org.bukkit.enchantments.Enchantment;
109
import org.bukkit.entity.Entity;
@@ -111,7 +110,17 @@ public void run() {
111110
player.getWorld().dropItemNaturally(loc, item);
112111
}
113112
if (doFullInvMSG) {
114-
player.sendMessage(PLUGIN.getMsg().getPrefix() + " " + PLUGIN.getMsg().getFullInventory());
113+
long secondsLeft;
114+
long cooldown = 15000; // 15 sec
115+
if (AutoPickup.lastInvFullNotification.containsKey(player.getUniqueId())) {
116+
secondsLeft = (AutoPickup.lastInvFullNotification.get(player.getUniqueId())/1000)+ cooldown/1000 - (System.currentTimeMillis()/1000);
117+
} else {
118+
secondsLeft = 0;
119+
}
120+
if (secondsLeft<=0) {
121+
player.sendMessage(PLUGIN.getMsg().getPrefix() + " " + PLUGIN.getMsg().getFullInventory());
122+
AutoPickup.lastInvFullNotification.put(player.getUniqueId(), System.currentTimeMillis());
123+
}
115124
}
116125
}
117126

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,19 @@ public void onDrop(BlockDropItemEvent e) {
6161

6262
if (player.getInventory().firstEmpty() == -1) { // Checks for inventory space
6363
//Player has no space
64-
if (doFullInvMSG) {player.sendMessage(PLUGIN.getMsg().getPrefix() + " " + PLUGIN.getMsg().getFullInventory());}
64+
if (doFullInvMSG) {
65+
long secondsLeft;
66+
long cooldown = 15000; // 15 sec
67+
if (AutoPickup.lastInvFullNotification.containsKey(player.getUniqueId())) {
68+
secondsLeft = (AutoPickup.lastInvFullNotification.get(player.getUniqueId())/1000)+ cooldown/1000 - (System.currentTimeMillis()/1000);
69+
} else {
70+
secondsLeft = 0;
71+
}
72+
if (secondsLeft<=0) {
73+
player.sendMessage(PLUGIN.getMsg().getPrefix() + " " + PLUGIN.getMsg().getFullInventory());
74+
AutoPickup.lastInvFullNotification.put(player.getUniqueId(), System.currentTimeMillis());
75+
}
76+
}
6577

6678
if (voidOnFullInv) {
6779
i.remove();

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,17 @@ public void onDeath(EntityDeathEvent e) {
7878
player.getWorld().dropItemNaturally(loc, item);
7979
}
8080
if (doFullInvMSG) {
81-
player.sendMessage(PLUGIN.getMsg().getPrefix() + " " + PLUGIN.getMsg().getFullInventory());
81+
long secondsLeft;
82+
long cooldown = 15000; // 15 sec
83+
if (AutoPickup.lastInvFullNotification.containsKey(player.getUniqueId())) {
84+
secondsLeft = (AutoPickup.lastInvFullNotification.get(player.getUniqueId())/1000)+ cooldown/1000 - (System.currentTimeMillis()/1000);
85+
} else {
86+
secondsLeft = 0;
87+
}
88+
if (secondsLeft<=0) {
89+
player.sendMessage(PLUGIN.getMsg().getPrefix() + " " + PLUGIN.getMsg().getFullInventory());
90+
AutoPickup.lastInvFullNotification.put(player.getUniqueId(), System.currentTimeMillis());
91+
}
8292
}
8393
}
8494

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,17 @@ public void onDeath(MythicMobDeathEvent e) {
6464
player.getWorld().dropItemNaturally(loc, item);
6565
}
6666
if (doFullInvMSG) {
67-
player.sendMessage(PLUGIN.getMsg().getPrefix() + " " + PLUGIN.getMsg().getFullInventory());
67+
long secondsLeft;
68+
long cooldown = 15000; // 15 sec
69+
if (AutoPickup.lastInvFullNotification.containsKey(player.getUniqueId())) {
70+
secondsLeft = (AutoPickup.lastInvFullNotification.get(player.getUniqueId())/1000)+ cooldown/1000 - (System.currentTimeMillis()/1000);
71+
} else {
72+
secondsLeft = 0;
73+
}
74+
if (secondsLeft<=0) {
75+
player.sendMessage(PLUGIN.getMsg().getPrefix() + " " + PLUGIN.getMsg().getFullInventory());
76+
AutoPickup.lastInvFullNotification.put(player.getUniqueId(), System.currentTimeMillis());
77+
}
6878
}
6979
}
7080
}

0 commit comments

Comments
 (0)