Skip to content

Commit

Permalink
push upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Galajus committed Jul 22, 2024
1 parent 993107f commit 82e5481
Show file tree
Hide file tree
Showing 24 changed files with 195 additions and 89 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<url>https://github.com/espidev/ProtectionStones</url>

<properties>
<java.version>1.21</java.version>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -205,15 +205,15 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<groupId>dev.folia</groupId>
<artifactId>folia-api</artifactId>
<version>1.20.6-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.9-SNAPSHOT</version>
<version>7.0.10</version>
<scope>provided</scope>
<exclusions>
<exclusion>
Expand All @@ -231,7 +231,7 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.2.6-SNAPSHOT</version>
<version>7.3.3</version>
<scope>provided</scope>
<exclusions>
<exclusion>
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/dev/espi/protectionstones/BlockHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
import dev.espi.protectionstones.utils.WGUtils;
import net.md_5.bungee.api.chat.TextComponent;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockPlaceEvent;
Expand Down Expand Up @@ -275,7 +279,7 @@ public static boolean createActualRegion(Player p, Location l, PSProtectBlock bl
if (blockOptions.autoHide) {
PSL.msg(p, PSL.REGION_HIDDEN.msg());
// run on next tick so placing tile entities don't complain
Bukkit.getScheduler().runTask(ProtectionStones.getInstance(), () -> l.getBlock().setType(Material.AIR));
Bukkit.getGlobalRegionScheduler().run(ProtectionStones.getInstance(), (task) -> l.getBlock().setType(Material.AIR));
}

if (blockOptions.startWithTaxAutopay) {
Expand Down Expand Up @@ -312,7 +316,8 @@ private static void playerMergeTask(Player p, PSRegion r) {
// actually do auto merge
if (!showGUI) {
PSRegion finalMergeTo = mergeTo;
Bukkit.getScheduler().runTaskAsynchronously(ProtectionStones.getInstance(), () -> {

Bukkit.getAsyncScheduler().runNow(ProtectionStones.getInstance(), (task) -> {
try {
WGMerge.mergeRealRegions(p.getWorld(), r.getWGRegionManager(), finalMergeTo, Arrays.asList(finalMergeTo, r));
PSL.msg(p, PSL.MERGE_AUTO_MERGED.msg().replace("%region%", finalMergeTo.getId()));
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/dev/espi/protectionstones/ListenerClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import dev.espi.protectionstones.event.PSBreakProtectBlockEvent;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import dev.espi.protectionstones.event.PSCreateEvent;
import dev.espi.protectionstones.event.PSRemoveEvent;
import dev.espi.protectionstones.utils.RecipeUtil;
Expand Down Expand Up @@ -53,6 +55,7 @@
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.GrindstoneInventory;
import org.bukkit.inventory.ItemStack;

import java.util.List;
Expand All @@ -69,7 +72,7 @@ public void onPlayerJoin(PlayerJoinEvent e) {
UUIDCache.storeUUIDNamePair(p.getUniqueId(), p.getName());

// allow worldguard to resolve all UUIDs to names
Bukkit.getScheduler().runTaskAsynchronously(ProtectionStones.getInstance(), () -> UUIDCache.storeWGProfile(p.getUniqueId(), p.getName()));
Bukkit.getAsyncScheduler().runNow(ProtectionStones.getInstance(), (task) -> UUIDCache.storeWGProfile(p.getUniqueId(), p.getName()));

// add recipes to player's recipe book
p.discoverRecipes(RecipeUtil.getRecipeKeys());
Expand All @@ -83,7 +86,7 @@ public void onPlayerJoin(PlayerJoinEvent e) {

// tax join message
if (ProtectionStones.getInstance().getConfigOptions().taxEnabled && ProtectionStones.getInstance().getConfigOptions().taxMessageOnJoin) {
Bukkit.getScheduler().runTaskAsynchronously(ProtectionStones.getInstance(), () -> {
Bukkit.getAsyncScheduler().runNow(ProtectionStones.getInstance(), (task) -> {
int amount = 0;
for (PSRegion psr : psp.getTaxEligibleRegions()) {
for (PSRegion.TaxPayment tp : psr.getTaxPaymentsDue()) {
Expand Down Expand Up @@ -564,7 +567,7 @@ public void onPSCreate(PSCreateEvent event) {
if (!event.getRegion().getTypeOptions().eventsEnabled) return;

// run on next tick (after the region is created to allow for edits to the region)
Bukkit.getServer().getScheduler().runTask(ProtectionStones.getInstance(), () -> {
Bukkit.getGlobalRegionScheduler().run(ProtectionStones.getInstance(), (task) -> {
// run custom commands (in config)
for (String action : event.getRegion().getTypeOptions().regionCreateCommands) {
execEvent(action, event.getPlayer(), event.getPlayer().getName(), event.getRegion());
Expand Down
25 changes: 14 additions & 11 deletions src/main/java/dev/espi/protectionstones/PSEconomy.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import dev.espi.protectionstones.utils.MiscUtil;
import dev.espi.protectionstones.utils.WGUtils;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.Bukkit;
import org.bukkit.World;
Expand All @@ -30,6 +31,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
Expand All @@ -38,7 +40,8 @@

public class PSEconomy {
private List<PSRegion> rentedList = new CopyOnWriteArrayList<>();
private static int rentRunner = -1, taxRunner = -1;
private static ScheduledTask RENT_RUNNER = null;
private static ScheduledTask TAX_RUNNER = null;

public PSEconomy() {
if (!ProtectionStones.getInstance().isVaultSupportEnabled()) {
Expand All @@ -49,11 +52,11 @@ public PSEconomy() {
loadRentList();

// start rent
rentRunner = Bukkit.getScheduler().runTaskTimerAsynchronously(ProtectionStones.getInstance(), this::updateRents, 0, 200).getTaskId();
RENT_RUNNER = Bukkit.getAsyncScheduler().runAtFixedRate(ProtectionStones.getInstance(), (task) -> this.updateRents(), 0, 200* 50, TimeUnit.MILLISECONDS);

// start taxes
if (ProtectionStones.getInstance().getConfigOptions().taxEnabled)
taxRunner = Bukkit.getScheduler().runTaskTimerAsynchronously(ProtectionStones.getInstance(), this::updateTaxes, 0, 200).getTaskId();
TAX_RUNNER = Bukkit.getAsyncScheduler().runAtFixedRate(ProtectionStones.getInstance(), (task) -> this.updateTaxes(), 0, 200 * 50, TimeUnit.MILLISECONDS);
}

private synchronized void updateRents() {
Expand Down Expand Up @@ -89,13 +92,13 @@ private void updateTaxes() {
* Stops the economy cycle. Used for reloads when creating a new PSEconomy.
*/
public void stop() {
if (rentRunner != -1) {
Bukkit.getScheduler().cancelTask(rentRunner);
rentRunner = -1;
if (RENT_RUNNER != null) {
RENT_RUNNER.cancel();
RENT_RUNNER = null;
}
if (taxRunner != -1) {
Bukkit.getScheduler().cancelTask(taxRunner);
taxRunner = -1;
if (TAX_RUNNER != null) {
TAX_RUNNER.cancel();
TAX_RUNNER = null;
}
}

Expand Down Expand Up @@ -126,7 +129,7 @@ public void loadRentList() {
public static void processTaxes(PSRegion r) {
// if taxes are enabled for this regions
if (r.getTypeOptions() != null && r.getTypeOptions().taxPeriod != -1) {
Bukkit.getScheduler().runTask(ProtectionStones.getInstance(), () -> {
Bukkit.getGlobalRegionScheduler().run(ProtectionStones.getInstance(), (task) -> {
// update tax payments due
r.updateTaxPayments();

Expand Down Expand Up @@ -191,7 +194,7 @@ public static void doRentPayment(PSRegion r) {
}

// update money must be run in main thread
Bukkit.getScheduler().runTask(ProtectionStones.getInstance(), () -> tenant.pay(landlord, r.getPrice()));
Bukkit.getGlobalRegionScheduler().run(ProtectionStones.getInstance(), (task) -> tenant.pay(landlord, r.getPrice()));
r.setRentLastPaid(Instant.now().getEpochSecond());
try { // must save region to persist last paid
r.getWGRegionManager().saveChanges();
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/dev/espi/protectionstones/ProtectionStones.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@
import dev.espi.protectionstones.placeholders.PSPlaceholderExpansion;
import dev.espi.protectionstones.utils.BlockUtil;
import dev.espi.protectionstones.utils.RecipeUtil;
import dev.espi.protectionstones.utils.upgrade.LegacyUpgrade;
import dev.espi.protectionstones.utils.UUIDCache;
import dev.espi.protectionstones.utils.WGUtils;
import dev.espi.protectionstones.utils.upgrade.LegacyUpgrade;
import net.luckperms.api.LuckPerms;
import net.milkbowl.vault.economy.Economy;
import org.bstats.bukkit.Metrics;
import org.bukkit.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.CommandMap;
import org.bukkit.enchantments.Enchantment;
Expand All @@ -43,11 +49,16 @@
import org.bukkit.inventory.meta.tags.ItemTagType;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import net.luckperms.api.LuckPerms;

import java.io.File;
import java.lang.reflect.Field;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Logger;

import static com.google.common.base.Preconditions.checkNotNull;
Expand Down Expand Up @@ -637,7 +648,7 @@ public void onEnable() {
// uuid cache
getLogger().info("Building UUID cache... (if slow change async-load-uuid-cache in the config to true)");
if (configOptions.asyncLoadUUIDCache) { // async load
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
Bukkit.getAsyncScheduler().runNow(plugin, (task) -> {
for (OfflinePlayer op : Bukkit.getOfflinePlayers()) {
UUIDCache.storeUUIDNamePair(op.getUniqueId(), op.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public boolean executeArgument(CommandSender s, String[] args, HashMap<String, S
String addPlayerName = UUIDCache.getNameFromUUID(addPlayerUuid);

// getting player regions is slow, so run it async
Bukkit.getServer().getScheduler().runTaskAsynchronously(ProtectionStones.getInstance(), () -> {
Bukkit.getAsyncScheduler().runNow(ProtectionStones.getInstance(), (task) -> {
List<PSRegion> regions;

// obtain region list that player is being added to or removed from
Expand Down Expand Up @@ -160,7 +160,7 @@ public boolean executeArgument(CommandSender s, String[] args, HashMap<String, S
}

// add to WorldGuard profile cache
Bukkit.getScheduler().runTaskAsynchronously(ProtectionStones.getInstance(), () -> UUIDCache.storeWGProfile(addPlayerUuid, addPlayerName));
Bukkit.getAsyncScheduler().runNow(ProtectionStones.getInstance(), (task2) -> UUIDCache.storeWGProfile(addPlayerUuid, addPlayerName));

} else if ((operationType.equals("remove") && r.isMember(addPlayerUuid))
|| (operationType.equals("removeowner") && r.isOwner(addPlayerUuid))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
import dev.espi.protectionstones.PSRegion;
import dev.espi.protectionstones.ProtectionStones;
import dev.espi.protectionstones.utils.WGUtils;
import org.bukkit.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

Expand All @@ -30,7 +33,13 @@
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;

class ArgAdminCleanup {

Expand Down Expand Up @@ -91,7 +100,7 @@ static boolean argumentAdminCleanup(CommandSender p, String[] preParseArgs) {

// async cleanup task
String finalAlias = alias;
Bukkit.getScheduler().runTaskAsynchronously(ProtectionStones.getInstance(), () -> {
Bukkit.getAsyncScheduler().runNow(ProtectionStones.getInstance(), (task) -> {
int days = (args.size() > 0) ? Integer.parseInt(args.get(0)) : 30; // 30 days is default if days aren't specified

PSL.msg(p, PSL.ADMIN_CLEANUP_HEADER.msg()
Expand Down Expand Up @@ -146,7 +155,7 @@ static boolean argumentAdminCleanup(CommandSender p, String[] preParseArgs) {

static private void regionLoop(Iterator<PSRegion> deleteRegionsIterator, CommandSender p, boolean isRemoveOperation) {
if (deleteRegionsIterator.hasNext()) {
Bukkit.getScheduler().runTaskLater(ProtectionStones.getInstance(), () ->
Bukkit.getGlobalRegionScheduler().runDelayed(ProtectionStones.getInstance(), (task) ->
processRegion(deleteRegionsIterator, p, isRemoveOperation), 1);
} else { // finished region iteration
PSL.msg(p, PSL.ADMIN_CLEANUP_FOOTER.msg()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ static boolean argumentAdminHide(CommandSender p, String[] args) {
mgr = WGUtils.getRegionManagerWithWorld(w);
}

Bukkit.getScheduler().runTaskAsynchronously(ProtectionStones.getInstance(), () -> {
Bukkit.getAsyncScheduler().runNow(ProtectionStones.getInstance(), (task) -> {
// loop through regions that are protection stones and hide or unhide the block
for (ProtectedRegion r : mgr.getRegions().values()) {
if (ProtectionStones.isPSRegion(r)) {
PSRegion region = PSRegion.fromWGRegion(w, r);
if (args[1].equalsIgnoreCase("hide")) {
Bukkit.getScheduler().runTask(ProtectionStones.getInstance(), region::hide);
Bukkit.getGlobalRegionScheduler().run(ProtectionStones.getInstance(), (task1) -> region.hide());
} else if (args[1].equalsIgnoreCase("unhide")){
Bukkit.getScheduler().runTask(ProtectionStones.getInstance(), region::unhide);
Bukkit.getGlobalRegionScheduler().run(ProtectionStones.getInstance(), (task1) -> region.unhide());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static boolean argumentAdminSetTaxAutopayers(CommandSender s, String[] args) {

PSL.msg(s, ChatColor.GRAY + "Scanning through regions, and setting tax autopayers for regions that don't have one...");

Bukkit.getScheduler().runTaskAsynchronously(ProtectionStones.getInstance(), () -> {
Bukkit.getAsyncScheduler().runNow(ProtectionStones.getInstance(), (task) -> {
WGUtils.getAllRegionManagers().forEach((w, rgm) -> {
for (ProtectedRegion r : rgm.getRegions().values()) {
PSRegion psr = PSRegion.fromWGRegion(w, r);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public boolean executeArgument(CommandSender s, String[] args, HashMap<String, S
r.setSellable(false, null, 0);
PSL.msg(p, PSL.BUY_STOP_SELL.msg());
} else {
if (!NumberUtils.isNumber(args[1]))
if (!NumberUtils.isCreatable(args[1]))
return PSL.msg(p, PSL.SELL_HELP.msg());

PSL.msg(p, PSL.SELL_FOR_SALE.msg().replace("%price%", String.format("%.2f", Double.parseDouble(args[1]))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

public class ArgCount implements PSCommandArg {

Expand Down Expand Up @@ -68,7 +72,7 @@ public HashMap<String, Boolean> getRegisteredFlags() {
@Override
public boolean executeArgument(CommandSender s, String[] args, HashMap<String, String> flags) {
Player p = (Player) s;
Bukkit.getScheduler().runTaskAsynchronously(ProtectionStones.getInstance(), () -> {
Bukkit.getAsyncScheduler().runNow(ProtectionStones.getInstance(), (task) -> {
int[] count;

if (args.length == 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dev/espi/protectionstones/commands/ArgFlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
import dev.espi.protectionstones.utils.WGUtils;
import net.md_5.bungee.api.chat.*;
import org.apache.commons.lang3.StringUtils;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
Expand Down
Loading

0 comments on commit 82e5481

Please sign in to comment.