Skip to content

Commit 5f0e3de

Browse files
committed
Feature requests
1 parent 576c747 commit 5f0e3de

File tree

12 files changed

+135
-6
lines changed

12 files changed

+135
-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.4.2-SNAPSHOT</version>
9+
<version>1.4.3-SNAPSHOT</version>
1010
<packaging>jar</packaging>
1111

1212
<name>AutoPickup</name>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void onEnable() {
128128
getServer().getPluginManager().registerEvents(new PlayerInteractEventListener(), this);
129129
getServer().getPluginManager().registerEvents(new PlayerDropItemEventListener(), this);
130130
getServer().getPluginManager().registerEvents(new ItemSpawnEventListener(), this);
131-
131+
getServer().getPluginManager().registerEvents(new EntityDropItemEventListener(), this);
132132

133133

134134
if (usingMythicMobs) {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ public void onBreak(BlockBreakEvent e) {
4444
return;
4545
}
4646

47+
Bukkit.getScheduler().runTaskAsynchronously(PLUGIN, new Runnable() {
48+
@Override
49+
public void run() {
50+
if (!player.hasPermission("autopickup.pickup.mined")) {
51+
PLUGIN.autopickup_list.remove(player);
52+
}
53+
if (!player.hasPermission("autopickup.pickup.mined.autosmelt")) {
54+
PLUGIN.auto_smelt_blocks.remove(player);
55+
}
56+
}
57+
});
58+
4759
Block block = e.getBlock();
4860
Location loc = e.getBlock().getLocation();
4961
boolean doFullInvMSG = PLUGIN.getConfig().getBoolean("doFullInvMSG");

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

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

3+
import org.bukkit.Bukkit;
34
import org.bukkit.Location;
45
import org.bukkit.entity.EntityType;
56
import org.bukkit.entity.Player;
@@ -31,7 +32,16 @@ public void onDeath(EntityDeathEvent e) {
3132
Player player = e.getEntity().getKiller();
3233

3334
if (!PLUGIN.autopickup_list_mobs.contains(player)) return;
34-
35+
36+
Bukkit.getScheduler().runTaskAsynchronously(PLUGIN, new Runnable() {
37+
@Override
38+
public void run() {
39+
if (!player.hasPermission("autopickup.pickup.entities")) {
40+
PLUGIN.autopickup_list_mobs.remove(player);
41+
}
42+
}
43+
});
44+
3545
boolean doFullInvMSG = PLUGIN.getConfig().getBoolean("doFullInvMSG");
3646

3747
Location loc = e.getEntity().getKiller().getLocation();
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package us.thezircon.play.autopickup.listeners;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.entity.Player;
5+
import org.bukkit.event.EventHandler;
6+
import org.bukkit.event.Listener;
7+
import org.bukkit.event.entity.EntityDropItemEvent;
8+
import org.bukkit.event.player.PlayerShearEntityEvent;
9+
import org.bukkit.inventory.ItemStack;
10+
import us.thezircon.play.autopickup.AutoPickup;
11+
12+
import java.util.HashMap;
13+
import java.util.Iterator;
14+
import java.util.UUID;
15+
16+
public class EntityDropItemEventListener implements Listener {
17+
18+
private static final AutoPickup PLUGIN = AutoPickup.getPlugin(AutoPickup.class);
19+
20+
private static HashMap<UUID, UUID> player_sheep_map = new HashMap<>();
21+
22+
@EventHandler
23+
public void onSheer(PlayerShearEntityEvent e) {
24+
player_sheep_map.put(e.getEntity().getUniqueId(), e.getPlayer().getUniqueId());
25+
}
26+
27+
@EventHandler
28+
public void onDrop(EntityDropItemEvent e) {
29+
30+
boolean doFullInvMSG = PLUGIN.getConfig().getBoolean("doFullInvMSG");
31+
32+
if (AutoPickup.worldsBlacklist!=null && AutoPickup.worldsBlacklist.contains(e.getEntity().getWorld().getName())) {
33+
return;
34+
}
35+
36+
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+
}
42+
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);
50+
}
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+
}
64+
}
65+
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+
}
72+
}
73+
});
74+
}
75+
}
76+
77+
}

src/main/java/us/thezircon/play/autopickup/utils/AutoSmelt.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
import org.bukkit.Tag;
66
import org.bukkit.entity.Player;
77
import org.bukkit.inventory.*;
8+
import us.thezircon.play.autopickup.AutoPickup;
89

910
import java.util.*;
1011

1112
public class AutoSmelt {
1213

14+
private static final AutoPickup PLUGIN = AutoPickup.getPlugin(AutoPickup.class);
15+
1316
public boolean isAutoSmeltEnabled = false;
1417
public static Material[] ignore = {Material.COAL_ORE, Material.REDSTONE_ORE, Material.DIAMOND_ORE, Material.EMERALD_ORE, Material.LAPIS_ORE, Material.NETHER_QUARTZ_ORE};
1518
public static List<Material> ignoreMaterials = Arrays.asList(ignore);
@@ -19,11 +22,16 @@ public boolean isEnabled() {
1922
}
2023

2124
public static ItemStack smelt(ItemStack itemStack, Player player) {
25+
List<String> blacklist = PLUGIN.getBlacklistConf().getStringList("AutoSmeltBlacklist");
2226

2327
if (ignoreMaterials.contains(itemStack.getType())) {
2428
return itemStack;
2529
}
2630

31+
if (blacklist.contains(itemStack.getType().toString())) {
32+
return itemStack;
33+
}
34+
2735
ItemStack result = itemStack;
2836
Iterator<Recipe> iter = Bukkit.recipeIterator();
2937
while (iter.hasNext()) {

src/main/java/us/thezircon/play/autopickup/utils/VersionChk.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import us.thezircon.play.autopickup.AutoPickup;
66

77
import java.io.BufferedReader;
8+
import java.io.File;
89
import java.io.InputStreamReader;
910
import java.net.HttpURLConnection;
1011
import java.net.URL;
12+
import java.util.Arrays;
1113
import java.util.logging.Logger;
1214

1315
import static com.google.common.net.HttpHeaders.USER_AGENT;
@@ -58,7 +60,17 @@ public static void checkVersion(String name, int id) throws Exception { //https:
5860

5961
// Config Version:
6062
double configVersion = PLUGIN.getConfig().getDouble("ConfigVersion");
63+
if (configVersion<=1.2) {
64+
PLUGIN.getConfig().set("ConfigVersion", 1.3);
65+
PLUGIN.getBlacklistConf().set("doAutoSmeltBlacklist", false);
66+
PLUGIN.getBlacklistConf().set("AutoSmeltBlacklist", Arrays.asList("OAK_LOG"));
6167

68+
File conf = new File(PLUGIN.getDataFolder(), "config.yml");
69+
File fileBlacklist = new File(PLUGIN.getDataFolder(), "blacklist.yml");
70+
71+
PLUGIN.getConfig().save(conf);
72+
PLUGIN.getBlacklistConf().save(fileBlacklist);
73+
}
6274

6375

6476
}

src/main/resources/blacklist.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#Set to "true" if you would like to enable the blacklist
1818
doBlacklisted: false
1919
doBlacklistedEntities: true
20+
doAutoSmeltBlacklist: false
2021

2122
#By listing blocks below you are adding them to the blacklist therefore causing them to drop to the ground.
2223
Blacklisted:
@@ -28,3 +29,7 @@ BlacklistedEntities:
2829

2930
BlacklistedWorlds:
3031
- example
32+
33+
#These materials will be ignored when auto smelt is enabled. Only items that can be smelted should be added.
34+
AutoSmeltBlacklist:
35+
- OAK_LOG

src/main/resources/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ConfigVersion: 1.2
1+
ConfigVersion: 1.3
22
#############################################################################################################
33
# _ _____ _ _ #
44
# /\ | | | __ \ (_) | | #

target/classes/blacklist.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#Set to "true" if you would like to enable the blacklist
1818
doBlacklisted: false
1919
doBlacklistedEntities: true
20+
doAutoSmeltBlacklist: false
2021

2122
#By listing blocks below you are adding them to the blacklist therefore causing them to drop to the ground.
2223
Blacklisted:
@@ -28,3 +29,7 @@ BlacklistedEntities:
2829

2930
BlacklistedWorlds:
3031
- example
32+
33+
#These materials will be ignored when auto smelt is enabled. Only items that can be smelted should be added.
34+
AutoSmeltBlacklist:
35+
- OAK_LOG

0 commit comments

Comments
 (0)