Skip to content

Commit 5ed870e

Browse files
committed
Add auto fishingdrops
1 parent 5fa5f4f commit 5ed870e

File tree

11 files changed

+254
-0
lines changed

11 files changed

+254
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.bukkit.plugin.java.JavaPlugin;
99
import org.bukkit.scheduler.BukkitRunnable;
1010
import us.thezircon.play.autopickup.commands.AutoDrops;
11+
import us.thezircon.play.autopickup.commands.AutoFishingDrops;
1112
import us.thezircon.play.autopickup.commands.AutoPickup.Auto;
1213
import us.thezircon.play.autopickup.commands.AutoSmelt;
1314
import us.thezircon.play.autopickup.listeners.*;
@@ -25,6 +26,7 @@ public final class AutoPickup extends JavaPlugin {
2526

2627
public HashSet<Player> autopickup_list = new HashSet<>(); // Blocks
2728
public HashSet<Player> autopickup_list_mobs = new HashSet<>(); // Mobs
29+
public HashSet<Player> autopickup_list_fishing = new HashSet<>(); // Fish
2830
public HashSet<Player> auto_smelt_blocks = new HashSet<>(); // AutoSmelt - Blocks
2931
public Messages messages = null;
3032
public boolean UP2Date = true;
@@ -127,6 +129,7 @@ public void onEnable() {
127129
getServer().getPluginManager().registerEvents(new EntityDeathEventListener(), this);
128130
getServer().getPluginManager().registerEvents(new PlayerInteractEventListener(), this);
129131
getServer().getPluginManager().registerEvents(new PlayerDropItemEventListener(), this);
132+
getServer().getPluginManager().registerEvents(new PlayerFishEventListener(), this);
130133
getServer().getPluginManager().registerEvents(new ItemSpawnEventListener(), this);
131134
getServer().getPluginManager().registerEvents(new EntityDropItemEventListener(), this);
132135

@@ -138,6 +141,7 @@ public void onEnable() {
138141
// Commands
139142
getCommand("autopickup").setExecutor(new Auto());
140143
getCommand("autodrops").setExecutor(new AutoDrops());
144+
getCommand("autofishingdrops").setExecutor(new AutoFishingDrops());
141145
getCommand("autosmelt").setExecutor(new AutoSmelt());
142146

143147
// Crops by version
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package us.thezircon.play.autopickup.commands;
2+
3+
import org.bukkit.command.Command;
4+
import org.bukkit.command.CommandExecutor;
5+
import org.bukkit.command.CommandSender;
6+
import org.bukkit.entity.Player;
7+
import us.thezircon.play.autopickup.AutoPickup;
8+
import us.thezircon.play.autopickup.utils.PickupPlayer;
9+
10+
public class AutoFishingDrops implements CommandExecutor {
11+
12+
private static final AutoPickup PLUGIN = AutoPickup.getPlugin(AutoPickup.class);
13+
14+
@Override
15+
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
16+
boolean requirePermsAUTO = PLUGIN.getConfig().getBoolean("requirePerms.autopickup");
17+
18+
if (sender instanceof Player) {
19+
Player player = (Player) sender;
20+
if (player.hasPermission("autopickup.pickup.fishing") || (!requirePermsAUTO)) {
21+
toggle(player);
22+
} else {
23+
player.sendMessage(PLUGIN.getMsg().getPrefix() + " " + PLUGIN.getMsg().getNoPerms());
24+
}
25+
}
26+
27+
return false;
28+
29+
}
30+
31+
public static void toggle(Player player) {
32+
PickupPlayer PP = new PickupPlayer(player);
33+
if (PLUGIN.autopickup_list_fishing.contains(player)) {
34+
PLUGIN.autopickup_list_fishing.remove(player);
35+
player.sendMessage(PLUGIN.getMsg().getPrefix() + " " + PLUGIN.getMsg().getMsgAutoFishingdropsDisable());
36+
PP.setEnabledFishing(false);
37+
} else if (!PLUGIN.autopickup_list_fishing.contains(player)) {
38+
PLUGIN.autopickup_list_fishing.add(player);
39+
player.sendMessage(PLUGIN.getMsg().getPrefix() + " " + PLUGIN.getMsg().getMsgAutoFishingdropsEnable());
40+
PP.setEnabledFishing(true);
41+
}
42+
}
43+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.bukkit.entity.Player;
88
import us.thezircon.play.autopickup.AutoPickup;
99
import us.thezircon.play.autopickup.commands.AutoPickup.subcommands.drops;
10+
import us.thezircon.play.autopickup.commands.AutoPickup.subcommands.fishingdrops;
1011
import us.thezircon.play.autopickup.commands.AutoPickup.subcommands.reload;
1112
import us.thezircon.play.autopickup.commands.AutoPickup.subcommands.smelt;
1213
import us.thezircon.play.autopickup.commands.CMDManager;
@@ -24,6 +25,7 @@ public class Auto implements TabExecutor{
2425
public Auto(){
2526
subcommands.add(new reload());
2627
subcommands.add(new drops());
28+
subcommands.add(new fishingdrops());
2729
subcommands.add(new smelt());
2830
}
2931

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package us.thezircon.play.autopickup.commands.AutoPickup.subcommands;
2+
3+
import org.bukkit.command.CommandSender;
4+
import org.bukkit.entity.Player;
5+
import us.thezircon.play.autopickup.AutoPickup;
6+
import us.thezircon.play.autopickup.commands.AutoFishingDrops;
7+
import us.thezircon.play.autopickup.commands.CMDManager;
8+
9+
import java.util.List;
10+
11+
public class fishingdrops extends CMDManager {
12+
13+
private static final AutoPickup PLUGIN = AutoPickup.getPlugin(AutoPickup.class);
14+
15+
@Override
16+
public String getName() {
17+
return "fishingdrops";
18+
}
19+
20+
@Override
21+
public String getDescription() {
22+
return "Picks up fishing drops";
23+
}
24+
25+
@Override
26+
public String getSyntax() {
27+
return "/auto fishingdrops";
28+
}
29+
30+
@Override
31+
public void perform(CommandSender sender, String[] args) {
32+
boolean requirePermsAUTO = PLUGIN.getConfig().getBoolean("requirePerms.autopickup");
33+
34+
if (sender instanceof Player) {
35+
Player player = (Player) sender;
36+
if (player.hasPermission("autopickup.pickup.fishing") || !requirePermsAUTO) {
37+
AutoFishingDrops.toggle(player);
38+
} else {
39+
sender.sendMessage(PLUGIN.getMsg().getPrefix() + " " + PLUGIN.getMsg().getNoPerms());
40+
}
41+
}
42+
}
43+
44+
@Override
45+
public List<String> arg1(Player player, String[] args) {
46+
return null;
47+
}
48+
49+
@Override
50+
public List<String> arg2(Player player, String[] args) {
51+
return null;
52+
}
53+
54+
@Override
55+
public List<String> arg3(Player player, String[] args) {
56+
return null;
57+
}
58+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package us.thezircon.play.autopickup.listeners;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.Location;
5+
import org.bukkit.Material;
6+
import org.bukkit.entity.Item;
7+
import org.bukkit.entity.Player;
8+
import org.bukkit.event.EventHandler;
9+
import org.bukkit.event.Listener;
10+
import org.bukkit.event.player.PlayerFishEvent;
11+
import org.bukkit.inventory.ItemStack;
12+
import us.thezircon.play.autopickup.AutoPickup;
13+
14+
import java.util.HashMap;
15+
import java.util.List;
16+
17+
public class PlayerFishEventListener implements Listener {
18+
19+
private static final AutoPickup PLUGIN = AutoPickup.getPlugin(AutoPickup.class);
20+
21+
@EventHandler
22+
public void onFish(PlayerFishEvent e) {
23+
Player player = e.getPlayer();
24+
25+
if(!(e.getState().equals(PlayerFishEvent.State.CAUGHT_FISH))) return;
26+
if(!(e.getCaught() instanceof Item)) return;
27+
28+
if (!PLUGIN.autopickup_list_fishing.contains(player)) return;
29+
30+
Bukkit.getScheduler().runTaskAsynchronously(PLUGIN, new Runnable() {
31+
@Override
32+
public void run() {
33+
boolean requirePermsAUTO = PLUGIN.getConfig().getBoolean("requirePerms.autopickup");
34+
if (!requirePermsAUTO) {
35+
return;
36+
}
37+
if (!player.hasPermission("autopickup.pickup.fishing") && !player.hasPermission("autopickup.pickup.fishing.autoenabled")) {
38+
PLUGIN.autopickup_list_fishing.remove(player);
39+
}
40+
}
41+
});
42+
43+
boolean doFullInvMSG = PLUGIN.getConfig().getBoolean("doFullInvMSG");
44+
45+
Location loc = e.getPlayer().getLocation();
46+
if (AutoPickup.worldsBlacklist!=null && AutoPickup.worldsBlacklist.contains(loc.getWorld().getName())) {
47+
return;
48+
}
49+
50+
Item caught = (Item) e.getCaught();
51+
52+
if (PLUGIN.getBlacklistConf().contains("BlacklistedFishing", true)) {
53+
boolean doBlacklist = PLUGIN.getBlacklistConf().getBoolean("BlacklistedFishing");
54+
List<String> blacklist = PLUGIN.getBlacklistConf().getStringList("BlacklistedFishing");
55+
56+
if (doBlacklist && blacklist.contains(caught.getItemStack().getType().toString())) {
57+
return;
58+
}
59+
}
60+
61+
HashMap<Integer, ItemStack> leftOver = player.getInventory().addItem(caught.getItemStack());
62+
caught.setItemStack(new ItemStack(Material.AIR));
63+
if (!leftOver.isEmpty()) {
64+
for (ItemStack item : leftOver.values()) {
65+
player.getWorld().dropItemNaturally(loc, item);
66+
}
67+
if (doFullInvMSG) {
68+
long secondsLeft;
69+
long cooldown = 15000; // 15 sec
70+
if (AutoPickup.lastInvFullNotification.containsKey(player.getUniqueId())) {
71+
secondsLeft = (AutoPickup.lastInvFullNotification.get(player.getUniqueId())/1000)+ cooldown/1000 - (System.currentTimeMillis()/1000);
72+
} else {
73+
secondsLeft = 0;
74+
}
75+
if (secondsLeft<=0) {
76+
player.sendMessage(PLUGIN.getMsg().getPrefix() + " " + PLUGIN.getMsg().getFullInventory());
77+
AutoPickup.lastInvFullNotification.put(player.getUniqueId(), System.currentTimeMillis());
78+
}
79+
}
80+
}
81+
}
82+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ public void onJoin(PlayerJoinEvent e) {
5858
}
5959
}
6060

61+
if (player.hasPermission("autopickup.pickup.fishing.autoenabled")) {
62+
if (!PLUGIN.autopickup_list_fishing.contains(player)) {
63+
PLUGIN.autopickup_list_fishing.add(player);
64+
//if (doAutoEnableMSG) {player.sendMessage(PLUGIN.getMsg().getPrefix() + " " + PLUGIN.getMsg().getAutoEnabled());}
65+
}
66+
}
67+
6168
if (player.hasPermission("autopickup.pickup.mined.autosmelt.autoenabled")) {
6269
if (!PLUGIN.auto_smelt_blocks.contains(player)) {
6370
PLUGIN.auto_smelt_blocks.add(player);
@@ -82,6 +89,11 @@ public void onJoin(PlayerJoinEvent e) {
8289
PLUGIN.autopickup_list_mobs.add(player);
8390
}
8491
}
92+
if (PP.getFishDropsToggle() && player.hasPermission("autopickup.pickup.fishing")) {
93+
if (!PLUGIN.autopickup_list_fishing.contains(player)) {
94+
PLUGIN.autopickup_list_fishing.add(player);
95+
}
96+
}
8597
}
8698

8799
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ public String getMsgAutoDropsDisable() {
2323
return msgAutoDropsDisable;
2424
}
2525

26+
public String getMsgAutoFishingdropsEnable() {
27+
return msgAutoFishingDropsEnable;
28+
}
29+
30+
public String getMsgAutoFishingdropsDisable() {
31+
return msgAutoFishingDropsDisable;
32+
}
33+
2634
public String getMsgAutoSmeltEnable() {
2735
return msgAutoSmeltEnable;
2836
}
@@ -33,6 +41,8 @@ public String getMsgAutoSmeltDisable() {
3341

3442
private String msgAutoDropsEnable;
3543
private String msgAutoDropsDisable;
44+
private String msgAutoFishingDropsEnable;
45+
private String msgAutoFishingDropsDisable;
3646
private String msgAutoSmeltEnable;
3747
private String msgAutoSmeltDisable;
3848

@@ -81,6 +91,8 @@ public Messages() {
8191
try {
8292
this.msgAutoDropsEnable = HexFormat.format(PLUGIN.getConfig().getString("msgAutoMobDropsEnable"));
8393
this.msgAutoDropsDisable = HexFormat.format(PLUGIN.getConfig().getString("msgAutoMobDropsDisable"));
94+
this.msgAutoFishingDropsEnable = HexFormat.format(PLUGIN.getConfig().getString("msgAutoFishingDropsEnable"));
95+
this.msgAutoFishingDropsDisable = HexFormat.format(PLUGIN.getConfig().getString("msgAutoFishingDropsDisable"));
8496
this.msgAutoSmeltEnable = HexFormat.format(PLUGIN.getConfig().getString("msgAutoSmeltEnable"));
8597
this.msgAutoSmeltDisable = HexFormat.format(PLUGIN.getConfig().getString("msgAutoSmeltDisable"));
8698
} catch (NullPointerException e) {

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ public void run() {
9090
}.runTaskLater(plugin, 1);
9191
}
9292

93+
public void setEnabledFishing(boolean e) {
94+
new BukkitRunnable() {
95+
@Override
96+
public void run() {
97+
if (!fileExists()) {createFile();}
98+
99+
File playerFile = new File(plugin.getDataFolder()+File.separator+"PlayerData"+File.separator+uuid+".yml");
100+
FileConfiguration data = YamlConfiguration.loadConfiguration(playerFile);
101+
102+
data.set("enabled_fishing_drops", e);
103+
104+
try {
105+
data.save(playerFile);
106+
} catch (IOException err){
107+
log.warning("[AutoPickup] Unable to update "+uuid+"'s data file.");
108+
}
109+
}
110+
}.runTaskLater(plugin, 1);
111+
}
112+
93113
public void setEnabledAutoSmelt(boolean e) {
94114
new BukkitRunnable() {
95115
@Override
@@ -126,6 +146,16 @@ public boolean getMobDropsToggle(){
126146
}
127147
}
128148

149+
public boolean getFishDropsToggle(){
150+
if (!fileExists()) {createFile();}
151+
FileConfiguration data = YamlConfiguration.loadConfiguration(playerData);
152+
try {
153+
return data.getBoolean("enabled_fishing_drops");
154+
} catch (NullPointerException e) {
155+
return false;
156+
}
157+
}
158+
129159
public boolean getAutoSmeltToggle(){
130160
if (!fileExists()) {createFile();}
131161
FileConfiguration data = YamlConfiguration.loadConfiguration(playerData);

src/main/resources/blacklist.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Blacklisted:
2727
BlacklistedEntities:
2828
- PLAYER
2929

30+
BlacklistedFishing: []
31+
3032
BlacklistedWorlds:
3133
- example
3234

src/main/resources/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ msgAutoSmeltDisable: "&7You have&c disabled &7auto smelt."
2828
msgAutoMobDropsEnable: "&7You have&a enabled &7auto drops."
2929
msgAutoMobDropsDisable: "&7You have&c disabled &7auto drops."
3030

31+
#Toggle Message - /fishingdrops
32+
msgAutoFishingDropsEnable: "&7You have&a enabled &7auto fishing drops."
33+
msgAutoFishingDropsDisable: "&7You have&c disabled &7auto fishing drops."
34+
3135
#Aditional toggling messages
3236
msgAutoEnable: "&7Auto pickup has been automatically&a enabled&7."
3337
doAutoEnableMSG: true

0 commit comments

Comments
 (0)