Skip to content

Commit 82c2a8b

Browse files
authored
Merge pull request #77 from MrButtersDEV/master
Merge pull requests to dev build
2 parents ff234eb + 284baa3 commit 82c2a8b

18 files changed

+480
-23
lines changed

pom.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
<id>spigotmc-repo</id>
6161
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
6262
</repository>
63+
<repository>
64+
<id>papermc</id>
65+
<url>https://repo.papermc.io/repository/maven-public/</url>
66+
</repository>
6367
<repository>
6468
<id>sonatype</id>
6569
<url>https://oss.sonatype.org/content/groups/public/</url>
@@ -77,7 +81,6 @@
7781
<name>Lumine Releases</name>
7882
<url>https://mvn.lumine.io/repository/maven-public/</url>
7983
</repository>
80-
8184
</repositories>
8285

8386
<dependencies>
@@ -87,6 +90,12 @@
8790
<version>1.21.1-R0.1-SNAPSHOT</version>
8891
<scope>provided</scope>
8992
</dependency>
93+
<dependency>
94+
<groupId>dev.folia</groupId>
95+
<artifactId>folia-api</artifactId>
96+
<version>1.21.4-R0.1-SNAPSHOT</version>
97+
<scope>provided</scope>
98+
</dependency>
9099
<dependency>
91100
<groupId>world.bentobox</groupId>
92101
<artifactId>bentobox</artifactId>

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.bukkit.plugin.java.JavaPlugin;
1212
import org.bukkit.scheduler.BukkitRunnable;
1313
import us.thezircon.play.autopickup.commands.AutoDrops;
14+
import us.thezircon.play.autopickup.commands.AutoFishingDrops;
1415
import us.thezircon.play.autopickup.commands.AutoPickup.Auto;
1516
import us.thezircon.play.autopickup.commands.AutoSmelt;
1617
import us.thezircon.play.autopickup.listeners.*;
@@ -28,11 +29,13 @@ public final class AutoPickup extends JavaPlugin {
2829

2930
public HashSet<Player> autopickup_list = new HashSet<>(); // Blocks
3031
public HashSet<Player> autopickup_list_mobs = new HashSet<>(); // Mobs
32+
public HashSet<Player> autopickup_list_fishing = new HashSet<>(); // Fish
3133
public HashSet<Player> auto_smelt_blocks = new HashSet<>(); // AutoSmelt - Blocks
3234
public Messages messages = null;
3335
public boolean UP2Date = true;
3436
public TallCrops crops;
3537

38+
public static boolean usingFolia = false; // Folia Support
3639
public static boolean usingUpgradableHoppers = false; // UpgradableHoppers Patch
3740
public static boolean usingLocketteProByBrunyman = false; // LockettePro Patch
3841
public static boolean usingBentoBox = false; // BentoBox - AOneBlock Patch
@@ -60,6 +63,16 @@ public final class AutoPickup extends JavaPlugin {
6063

6164
private static AutoPickup instance;
6265

66+
@Override
67+
public void onLoad() {
68+
try {
69+
Class.forName("io.papermc.paper.threadedregions.scheduler.RegionScheduler");
70+
usingFolia = true;
71+
} catch (ClassNotFoundException e) {
72+
usingFolia = false;
73+
}
74+
}
75+
6376
@Override
6477
public void onEnable() {
6578
// Plugin startup logic
@@ -133,6 +146,7 @@ public void onEnable() {
133146
getServer().getPluginManager().registerEvents(new EntityDeathEventListener(), this);
134147
getServer().getPluginManager().registerEvents(new PlayerInteractEventListener(), this);
135148
getServer().getPluginManager().registerEvents(new PlayerDropItemEventListener(), this);
149+
getServer().getPluginManager().registerEvents(new PlayerFishEventListener(), this);
136150
getServer().getPluginManager().registerEvents(new ItemSpawnEventListener(), this);
137151
getServer().getPluginManager().registerEvents(new EntityDropItemEventListener(), this);
138152

@@ -144,6 +158,7 @@ public void onEnable() {
144158
// Commands
145159
getCommand("autopickup").setExecutor(new Auto());
146160
getCommand("autodrops").setExecutor(new AutoDrops());
161+
getCommand("autofishingdrops").setExecutor(new AutoFishingDrops());
147162
getCommand("autosmelt").setExecutor(new AutoSmelt());
148163

149164
// Crops by version
@@ -173,15 +188,15 @@ public void run() {
173188
}
174189

175190
// Pickup Objective Cleaner
176-
new BukkitRunnable() {
191+
SchedulerUtils.runTaskTimerAsynchronously(new FoliaRunnable() {
177192
@Override
178193
public void run() {
179194
customItemPatch.keySet().removeIf(key -> (Duration.between(Instant.now(), customItemPatch.get(key).getCreatedAt()).getSeconds() < -15));
180195
}
181-
}.runTaskTimerAsynchronously(this, 300L, 300L); // 15 sec
196+
}, 300L, 300L); // 15 sec
182197

183198
// Dropped items cleaner ****
184-
new BukkitRunnable() {
199+
SchedulerUtils.runTaskTimer(null, new FoliaRunnable() {
185200
@Override
186201
public void run() {
187202
try {
@@ -191,7 +206,7 @@ public void run() {
191206
});
192207
} catch (NullPointerException ignored) {}
193208
}
194-
}.runTaskTimer(this, 6000L, 6000L); // 5 min
209+
}, 6000L, 6000L); // 5 min
195210

196211
// Load auto smelt cache
197212
AutoSmeltUtils.loadFurnaceRecipes(smeltRecipeCache);
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+
}

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
import org.bukkit.inventory.meta.ItemMeta;
2020
import org.bukkit.scheduler.BukkitRunnable;
2121
import us.thezircon.play.autopickup.AutoPickup;
22-
import us.thezircon.play.autopickup.utils.HexFormat;
23-
import us.thezircon.play.autopickup.utils.Mendable;
24-
import us.thezircon.play.autopickup.utils.PickupObjective;
25-
import us.thezircon.play.autopickup.utils.TallCrops;
22+
import us.thezircon.play.autopickup.utils.*;
2623
import world.bentobox.bentobox.BentoBox;
2724
import world.bentobox.bentobox.database.objects.Island;
2825

@@ -44,7 +41,7 @@ public void onBreak(BlockBreakEvent e) {
4441
return;
4542
}
4643

47-
Bukkit.getScheduler().runTaskAsynchronously(PLUGIN, new Runnable() {
44+
SchedulerUtils.runTaskAsynchronously(new Runnable() {
4845
@Override
4946
public void run() {
5047
boolean requirePermsAUTO = PLUGIN.getConfig().getBoolean("requirePerms.autopickup");
@@ -92,7 +89,7 @@ public void run() {
9289
// }
9390

9491
// AOneBlock Patch
95-
new BukkitRunnable() {
92+
SchedulerUtils.runTaskLater(player.getLocation(), new FoliaRunnable() {
9693
@Override
9794
public void run() {
9895
if (AutoPickup.usingBentoBox) {
@@ -143,7 +140,7 @@ public void run() {
143140
}
144141
}
145142
}
146-
}.runTaskLater(PLUGIN, 1);
143+
}, 1);
147144

148145
// Mend Items & Give Player XP
149146
boolean usingSilkSpawner = PLUGIN.getConfig().getBoolean("usingSilkSpawnerPlugin");
@@ -494,15 +491,15 @@ public static int mend(ItemStack item, int xp) {
494491
}
495492

496493
private static void fix(ItemStack item) {
497-
new BukkitRunnable() {
494+
SchedulerUtils.runTaskLater(null, new FoliaRunnable() {
498495
@Override
499496
public void run() {
500497
ItemMeta meta = item.getItemMeta();
501498
Damageable damage = (Damageable) meta;
502499
damage.setDamage(0);
503500
item.setItemMeta(meta);
504501
}
505-
}.runTaskLater(PLUGIN, 1);
502+
}, 1);
506503
}
507504

508505
private static int amt = 1;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.bukkit.event.entity.EntityDeathEvent;
1111
import org.bukkit.inventory.ItemStack;
1212
import us.thezircon.play.autopickup.AutoPickup;
13+
import us.thezircon.play.autopickup.utils.SchedulerUtils;
1314

1415
import java.util.HashMap;
1516
import java.util.Iterator;
@@ -33,7 +34,7 @@ public void onDeath(EntityDeathEvent e) {
3334

3435
if (!PLUGIN.autopickup_list_mobs.contains(player)) return;
3536

36-
Bukkit.getScheduler().runTaskAsynchronously(PLUGIN, new Runnable() {
37+
SchedulerUtils.runTaskAsynchronously(new Runnable() {
3738
@Override
3839
public void run() {
3940
boolean requirePermsAUTO = PLUGIN.getConfig().getBoolean("requirePerms.autopickup");

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.bukkit.event.player.PlayerShearEntityEvent;
99
import org.bukkit.inventory.ItemStack;
1010
import us.thezircon.play.autopickup.AutoPickup;
11+
import us.thezircon.play.autopickup.utils.SchedulerUtils;
1112

1213
import java.util.HashMap;
1314
import java.util.Iterator;
@@ -67,7 +68,7 @@ public void onDrop(EntityDropItemEvent e) {
6768
}
6869
}
6970

70-
Bukkit.getScheduler().runTaskAsynchronously(PLUGIN, new Runnable() {
71+
SchedulerUtils.runTaskAsynchronously(new Runnable() {
7172
@Override
7273
public void run() {
7374
if (!player.hasPermission("autopickup.pickup.mined")) {

0 commit comments

Comments
 (0)