diff --git a/pom.xml b/pom.xml
index 9a4f6b8..be85d6a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,143 +1,135 @@
- 4.0.0
-
- nl.rutgerkok
- blocklocker
- 1.12.1-SNAPSHOT
- jar
-
- BlockLocker
- https://github.com/rutgerkok/BlockLocker
-
-
- UTF-8
- 5.3.1
-
-
-
-
- spigot-repo
- https://hub.spigotmc.org/nexus/content/groups/public/
-
-
- rutger-repo
- https://rutgerkok.nl/repo
-
-
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
+ nl.rutgerkok
+ blocklocker
+ 1.12.1-SNAPSHOT
+ jar
+ BlockLocker
+ https://github.com/rutgerkok/BlockLocker
+
+ UTF-8
+ 5.3.1
+
+
+
+ papermc
+ https://repo.papermc.io/repository/maven-public/
+
+
+ rutger-repo
+ https://rutgerkok.nl/repo
+
+
codemc-repo
https://repo.codemc.org/repository/maven-public/
-
-
-
-
- org.spigotmc
- spigot-api
- 1.18-R0.1-SNAPSHOT
- provided
-
-
- junit
- junit
-
-
-
-
-
-
- com.palmergames
- towny
- 0.96.7.0
- provided
-
-
- com.massivecraft
- MassiveCore
- 2.7.5
- provided
-
-
- com.massivecraft
- Factions
- 2.7.5
- provided
-
-
- com.gmail.nossr50.mcMMO
- mcMMO
- 2.1.218
- provided
-
-
- me.glaremasters
- guilds
- 3.5.3.5-RELEASE
- provided
-
-
- net.sacredlabyrinth.phaed.simpleclans
- SimpleClans
- 2.15.1
- provided
-
-
-
-
- org.junit.jupiter
- junit-jupiter-api
- ${junit.jupiter.version}
- test
-
-
- org.junit.jupiter
- junit-jupiter-engine
- ${junit.jupiter.version}
- test
-
-
- org.mockito
- mockito-core
- 2.23.0
- test
-
-
-
-
-
+ junit
+ junit
+
+
+
+
+
+ com.palmergames
+ towny
+ 0.96.7.0
+ provided
+
+
+ com.massivecraft
+ MassiveCore
+ 2.7.5
+ provided
+
+
+ com.massivecraft
+ Factions
+ 2.7.5
+ provided
+
+
+ com.gmail.nossr50.mcMMO
+ mcMMO
+ 2.1.218
+ provided
+
+
+ me.glaremasters
+ guilds
+ 3.5.3.5-RELEASE
+ provided
+
+
+ net.sacredlabyrinth.phaed.simpleclans
+ SimpleClans
+ 2.15.1
+ provided
+
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ ${junit.jupiter.version}
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ ${junit.jupiter.version}
+ test
+
+
+ org.mockito
+ mockito-core
+ 2.23.0
+ test
+
+
+
+
-
-
- .
- true
- src/main/resources
-
- *
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.7.0
-
- 17
- 17
-
-
-
-
-
-
-
- codemc-releases
- https://repo.codemc.io/repository/maven-releases/
-
-
- codemc-snapshots
- https://repo.codemc.io/repository/maven-snapshots/
-
-
+
+
+ .
+ true
+ src/main/resources
+
+ *
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.7.0
+
+ 17
+ 17
+
+
+
+
+
+
+ codemc-releases
+ https://repo.codemc.io/repository/maven-releases/
+
+
+ codemc-snapshots
+ https://repo.codemc.io/repository/maven-snapshots/
+
+
diff --git a/src/main/java/nl/rutgerkok/blocklocker/BlockLockerAPIv2.java b/src/main/java/nl/rutgerkok/blocklocker/BlockLockerAPIv2.java
index 06e4138..0f9c57d 100644
--- a/src/main/java/nl/rutgerkok/blocklocker/BlockLockerAPIv2.java
+++ b/src/main/java/nl/rutgerkok/blocklocker/BlockLockerAPIv2.java
@@ -1,8 +1,8 @@
package nl.rutgerkok.blocklocker;
import java.util.Date;
-import java.util.UUID;
import java.util.Optional;
+import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
@@ -31,7 +31,6 @@ public final class BlockLockerAPIv2 {
* The block.
* @return The owner, or empty if the block is not protected.
*/
- @SuppressWarnings("deprecation")
public static Optional getOwner(Block block) {
Optional protection = getPlugin().getProtectionFinder().findProtection(block);
if (!protection.isPresent()) {
diff --git a/src/main/java/nl/rutgerkok/blocklocker/BlockLockerPlugin.java b/src/main/java/nl/rutgerkok/blocklocker/BlockLockerPlugin.java
index 4b65ef5..2d4a368 100644
--- a/src/main/java/nl/rutgerkok/blocklocker/BlockLockerPlugin.java
+++ b/src/main/java/nl/rutgerkok/blocklocker/BlockLockerPlugin.java
@@ -2,6 +2,7 @@
import java.util.logging.Logger;
+import org.bukkit.block.Block;
import org.bukkit.event.Event;
import nl.rutgerkok.blocklocker.group.CombinedGroupSystem;
@@ -103,18 +104,36 @@ public interface BlockLockerPlugin {
/**
* Runs a task the next tick on the server thread.
*
+ * @param block
+ * Used to run the task in the region of the block (when using the
+ * Folia server).
* @param runnable
* The task.
*/
- void runLater(Runnable runnable);
+ void runLater(Block block, Runnable runnable);
/**
* Runs a task in the given amount of ticks on the server thread.
*
+ * @param block
+ * Used to run the task in the region of the block (when using the
+ * Folia server).
* @param runnable
* The task.
* @param ticks
* In how many ticks the method needs to run.
*/
- void runLater(Runnable runnable, int ticks);
+ void runLater(Block block, Runnable runnable, int ticks);
+
+ /**
+ * Runs a task on the server thread. On Folia, this thread only controls things
+ * that don't belong to a specific region, like weather and time.
+ *
+ * @param runnable
+ * The task.
+ * @param ticks
+ * In how many ticks the method needs to run.
+ */
+ void runLaterGlobally(Runnable runnable, int ticks);
+
}
diff --git a/src/main/java/nl/rutgerkok/blocklocker/impl/BlockLockerPluginImpl.java b/src/main/java/nl/rutgerkok/blocklocker/impl/BlockLockerPluginImpl.java
index 171d962..3bc2577 100644
--- a/src/main/java/nl/rutgerkok/blocklocker/impl/BlockLockerPluginImpl.java
+++ b/src/main/java/nl/rutgerkok/blocklocker/impl/BlockLockerPluginImpl.java
@@ -8,14 +8,20 @@
import java.util.Collection;
import java.util.Locale;
import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
import java.util.logging.Level;
import org.bukkit.Bukkit;
+import org.bukkit.block.Block;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.Event;
+import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
+import org.bukkit.scheduler.BukkitTask;
+import org.jetbrains.annotations.NotNull;
import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
@@ -51,6 +57,7 @@
import nl.rutgerkok.blocklocker.location.LocationChecker;
public class BlockLockerPluginImpl extends JavaPlugin implements BlockLockerPlugin {
+
private ChestSettings chestSettings;
private CombinedGroupSystem combinedGroupSystem;
private Config config;
@@ -60,6 +67,7 @@ public class BlockLockerPluginImpl extends JavaPlugin implements BlockLockerPlug
private SignParser signParser;
private Translator translator;
private CombinedLocationChecker combinedLocationChecker;
+
private HopperCache redstoneProtectCache;
@Override
@@ -262,13 +270,73 @@ public void reload() {
}
@Override
- public void runLater(Runnable runnable) {
- getServer().getScheduler().runTask(this, runnable);
+ public void runLater(Block block, Runnable runnable) {
+ getServer().getRegionScheduler().run(this, block.getLocation(), task -> {
+ runnable.run();
+ });
+ // getServer().getScheduler().runTask(this, runnable);
+ }
+
+ @Override
+ public void runLater(Block block, Runnable runnable, int ticks) {
+ getServer().getRegionScheduler()
+ .runDelayed(this, block.getWorld(), block.getX() >> 4, block.getZ() >> 4, task -> {
+ runnable.run();
+ }, ticks);
+ // getServer().getScheduler().runTaskLater(this, runnable, ticks);
}
@Override
- public void runLater(Runnable runnable, int ticks) {
- getServer().getScheduler().runTaskLater(this, runnable, ticks);
+ public void runLaterGlobally(Runnable runnable, int ticks) {
+ getServer().getGlobalRegionScheduler().runDelayed(this, task -> {
+ runnable.run();
+ }, ticks);
+ }
+
+ /**
+ * Folia-compatible alternative for running a timer task asynchronously.
+ *
+ * @param task
+ * The task.
+ * @param checkInterval
+ * The check interval in ticks.
+ */
+ public void runTimerAsync(Consumer task, long checkInterval) {
+ getServer().getAsyncScheduler().runAtFixedRate(this, foliaTask -> {
+ task.accept(new BukkitTask() {
+
+ @Override
+ public void cancel() {
+ foliaTask.cancel();
+ }
+
+ @Override
+ public @NotNull Plugin getOwner() {
+ return foliaTask.getOwningPlugin();
+ }
+
+ @Override
+ public int getTaskId() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return foliaTask.isCancelled();
+ }
+
+ @Override
+ public boolean isSync() {
+ return false;
+ }
+ });
+ }, 1, checkInterval * 50, TimeUnit.MILLISECONDS);
+
+ /*
+ * BukkitTask[] bukkitTask = new BukkitTask[1]; bukkitTask[0] =
+ * getServer().getScheduler().runTaskTimerAsynchronously(this, () -> {
+ * task.accept(bukkitTask[0]::cancel); }, 1, checkInterval);
+ */
}
}
diff --git a/src/main/java/nl/rutgerkok/blocklocker/impl/CompleteDoor.java b/src/main/java/nl/rutgerkok/blocklocker/impl/CompleteDoor.java
index 9179eae..8aa6290 100644
--- a/src/main/java/nl/rutgerkok/blocklocker/impl/CompleteDoor.java
+++ b/src/main/java/nl/rutgerkok/blocklocker/impl/CompleteDoor.java
@@ -259,6 +259,27 @@ private BlockFace getFaceToLeftDoor() {
return getFaceToLeftDoorOrNull(bottomBlock);
}
+ /**
+ * Returns one of the two (or four) door blocks.
+ *
+ * @return One of the two (or four) blocks.
+ */
+ public Block getSomeDoorBlock() {
+ if (this.bottomLeftBlock != null) {
+ return this.bottomLeftBlock;
+ }
+ if (this.bottomRightBlock != null) {
+ return this.bottomRightBlock;
+ }
+ if (this.topLeftBlock != null) {
+ return this.topLeftBlock;
+ }
+ if (this.topRightBlock != null) {
+ return this.topRightBlock;
+ }
+ throw new IllegalStateException("All four door blocks where null, this should not be possible");
+ }
+
/**
* Gets whether the door is currently open. The result is undefined if the
* door is half-open, half-closed.
diff --git a/src/main/java/nl/rutgerkok/blocklocker/impl/SignParserImpl.java b/src/main/java/nl/rutgerkok/blocklocker/impl/SignParserImpl.java
index 48c03f5..ae676ba 100644
--- a/src/main/java/nl/rutgerkok/blocklocker/impl/SignParserImpl.java
+++ b/src/main/java/nl/rutgerkok/blocklocker/impl/SignParserImpl.java
@@ -53,10 +53,12 @@ public String[] getDisplayLines(ProtectionSign sign) {
@Override
public Optional getSignType(Sign sign) {
+ @SuppressWarnings("deprecation")
String header = sign.getLine(0);
return Optional.ofNullable(getSignTypeOrNull(header));
}
+ @SuppressWarnings("deprecation")
@Override
public Optional getSignType(SignChangeEvent event) {
return Optional.ofNullable(getSignTypeOrNull(event.getLine(0)));
@@ -78,6 +80,7 @@ public boolean hasValidHeader(Sign sign) {
}
private Optional parseAdvancedSign(Sign sign) {
+ @SuppressWarnings("deprecation")
String[] displayedText = sign.getLines();
PersistentDataContainer data = sign.getPersistentDataContainer();
@@ -95,6 +98,7 @@ private Optional parseAdvancedSign(Sign sign) {
}
// Check header
+ @SuppressWarnings("deprecation")
String header = sign.getLine(0);
boolean headerMismatch = !chestSettings.getFancyLocalizedHeader(type, header).equals(header);
@@ -135,6 +139,7 @@ public Optional parseSign(Block sign) {
}
// Try plain sign, written by the user
+ @SuppressWarnings("deprecation")
String[] lines = signState.getLines();
return parseSimpleSign(sign.getLocation(), lines);
}
@@ -166,6 +171,7 @@ private Optional parseSimpleSign(Location location, String[] lin
return Optional.of(protectionSignImpl);
}
+ @SuppressWarnings("deprecation")
@Override
public void saveSign(ProtectionSign sign) {
// Find sign
diff --git a/src/main/java/nl/rutgerkok/blocklocker/impl/event/BlockPlaceListener.java b/src/main/java/nl/rutgerkok/blocklocker/impl/event/BlockPlaceListener.java
index 7f7d221..208ce3e 100644
--- a/src/main/java/nl/rutgerkok/blocklocker/impl/event/BlockPlaceListener.java
+++ b/src/main/java/nl/rutgerkok/blocklocker/impl/event/BlockPlaceListener.java
@@ -1,12 +1,10 @@
package nl.rutgerkok.blocklocker.impl.event;
-import nl.rutgerkok.blocklocker.Permissions;
-import nl.rutgerkok.blocklocker.Translator.Translation;
-import nl.rutgerkok.blocklocker.impl.BlockLockerPluginImpl;
-import nl.rutgerkok.blocklocker.impl.blockfinder.BlockFinder;
-import nl.rutgerkok.blocklocker.location.IllegalLocationException;
-import nl.rutgerkok.blocklocker.profile.PlayerProfile;
-import nl.rutgerkok.blocklocker.protection.Protection;
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+import java.util.UUID;
+
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
@@ -19,10 +17,13 @@
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.InventoryHolder;
-import java.util.HashSet;
-import java.util.Optional;
-import java.util.Set;
-import java.util.UUID;
+import nl.rutgerkok.blocklocker.Permissions;
+import nl.rutgerkok.blocklocker.Translator.Translation;
+import nl.rutgerkok.blocklocker.impl.BlockLockerPluginImpl;
+import nl.rutgerkok.blocklocker.impl.blockfinder.BlockFinder;
+import nl.rutgerkok.blocklocker.location.IllegalLocationException;
+import nl.rutgerkok.blocklocker.profile.PlayerProfile;
+import nl.rutgerkok.blocklocker.protection.Protection;
public final class BlockPlaceListener extends EventListener {
@@ -102,18 +103,21 @@ public void onBlockPlace(BlockPlaceEvent event) {
*/
private void sendChestHint(Player player) {
UUID playerId = player.getUniqueId();
- if (this.doNotSendChestHintPlayerIds.contains(playerId)) {
- return;
- }
- plugin.getTranslator().sendMessage(player, Translation.PROTECTION_CHEST_HINT);
+ synchronized (this.doNotSendChestHintPlayerIds) {
+ if (this.doNotSendChestHintPlayerIds.contains(playerId)) {
+ return;
+ }
+ plugin.getTranslator().sendMessage(player, Translation.PROTECTION_CHEST_HINT);
- // Temporarily suppress chest hint (120 seconds)
- this.doNotSendChestHintPlayerIds.add(playerId);
- plugin.getServer().getScheduler().runTaskLater(plugin, () -> {
+ // Temporarily suppress chest hint (120 seconds)
+ this.doNotSendChestHintPlayerIds.add(playerId);
+ }
+ plugin.runLaterGlobally(() -> {
// Note: we only keep a reference to the player id, not the entire player
// object, which might be replaced
- this.doNotSendChestHintPlayerIds
- .remove(playerId);
+ synchronized (this.doNotSendChestHintPlayerIds) {
+ this.doNotSendChestHintPlayerIds.remove(playerId);
+ }
}, 20 * 120);
}
diff --git a/src/main/java/nl/rutgerkok/blocklocker/impl/event/InteractListener.java b/src/main/java/nl/rutgerkok/blocklocker/impl/event/InteractListener.java
index 36733b1..e064e8e 100644
--- a/src/main/java/nl/rutgerkok/blocklocker/impl/event/InteractListener.java
+++ b/src/main/java/nl/rutgerkok/blocklocker/impl/event/InteractListener.java
@@ -403,13 +403,15 @@ private void scheduleClose(final Protection protection) {
if (openSeconds <= 0) {
return;
}
- plugin.runLater(() -> protection.setOpen(false, SoundCondition.ALWAYS), openSeconds * 20);
+ plugin.runLater(protection
+ .getSomeProtectedBlock(), () -> protection.setOpen(false, SoundCondition.ALWAYS), openSeconds * 20);
}
private Material toWallSign(Material signMaterial) {
return Material.valueOf(signMaterial.name().replace("_SIGN", "_WALL_SIGN"));
}
+ @SuppressWarnings("deprecation")
private boolean tryPlaceSign(Player player, Block block, BlockFace clickedSide, EquipmentSlot hand,
SignType signType) {
if (player.isSneaking() || !canBuildInMode(player.getGameMode())) {
diff --git a/src/main/java/nl/rutgerkok/blocklocker/impl/event/SignChangeListener.java b/src/main/java/nl/rutgerkok/blocklocker/impl/event/SignChangeListener.java
index eed5483..3a739a9 100644
--- a/src/main/java/nl/rutgerkok/blocklocker/impl/event/SignChangeListener.java
+++ b/src/main/java/nl/rutgerkok/blocklocker/impl/event/SignChangeListener.java
@@ -36,6 +36,7 @@ private Optional getExistingSignType(Block block) {
return Optional.empty();
}
+ @SuppressWarnings("deprecation")
private void handleSignNearbyProtection(SignChangeEvent event, Protection protection) {
Block block = event.getBlock();
Player player = event.getPlayer();
@@ -93,6 +94,7 @@ private void handleSignNearbyProtection(SignChangeEvent event, Protection protec
updateBlockForUniqueIdsSoon(block);
}
+ @SuppressWarnings("deprecation")
private void handleSignNotNearbyProtection(SignChangeEvent event) {
Optional parsedSign = plugin.getSignParser().getSignType(event);
if (!parsedSign.isPresent()) {
@@ -175,7 +177,7 @@ public void onSignChange(SignChangeEvent event) {
* The block that will be part of the protection.
*/
private void updateBlockForUniqueIdsSoon(final Block block) {
- plugin.runLater(new Runnable() {
+ plugin.runLater(block, new Runnable() {
@Override
public void run() {
Optional protection = plugin.getProtectionFinder().findProtection(block);
diff --git a/src/main/java/nl/rutgerkok/blocklocker/impl/profile/PlayerProfileImpl.java b/src/main/java/nl/rutgerkok/blocklocker/impl/profile/PlayerProfileImpl.java
index 12b3984..fce4c6b 100644
--- a/src/main/java/nl/rutgerkok/blocklocker/impl/profile/PlayerProfileImpl.java
+++ b/src/main/java/nl/rutgerkok/blocklocker/impl/profile/PlayerProfileImpl.java
@@ -92,6 +92,7 @@ public boolean includes(Profile other) {
return displayName.equalsIgnoreCase(otherProfile.getDisplayName());
}
+ @SuppressWarnings("deprecation")
@Override
public boolean isExpired(Date cutoffDate) {
diff --git a/src/main/java/nl/rutgerkok/blocklocker/impl/protection/AttachedProtectionImpl.java b/src/main/java/nl/rutgerkok/blocklocker/impl/protection/AttachedProtectionImpl.java
index 39654f6..a5f1022 100644
--- a/src/main/java/nl/rutgerkok/blocklocker/impl/protection/AttachedProtectionImpl.java
+++ b/src/main/java/nl/rutgerkok/blocklocker/impl/protection/AttachedProtectionImpl.java
@@ -93,6 +93,11 @@ protected Collection fetchSigns() {
return blockFinder.findAttachedSigns(Arrays.asList(protectionBlock, supportingBlock));
}
+ @Override
+ public Block getSomeProtectedBlock() {
+ return protectionBlock;
+ }
+
@Override
public boolean isOpen() {
BlockData materialData = protectionBlock.getBlockData();
diff --git a/src/main/java/nl/rutgerkok/blocklocker/impl/protection/ContainerProtectionImpl.java b/src/main/java/nl/rutgerkok/blocklocker/impl/protection/ContainerProtectionImpl.java
index 01f5f4c..1dcaa79 100644
--- a/src/main/java/nl/rutgerkok/blocklocker/impl/protection/ContainerProtectionImpl.java
+++ b/src/main/java/nl/rutgerkok/blocklocker/impl/protection/ContainerProtectionImpl.java
@@ -69,6 +69,10 @@ private ContainerProtectionImpl(ProtectionSign mainSign, Collection block
super(mainSign);
this.blocks = blocks;
this.blockFinder = blockFinder;
+
+ if (this.blocks.isEmpty()) {
+ throw new IllegalArgumentException("Blocks list is empty");
+ }
}
@Override
@@ -88,6 +92,14 @@ protected Collection fetchSigns() {
return blockFinder.findAttachedSigns(blocks);
}
+ @Override
+ public Block getSomeProtectedBlock() {
+ for (Block block : this.blocks) {
+ return block;
+ }
+ throw new AssertionError("Block list was empty, this should have been checked in the constructor");
+ }
+
@Override
public boolean isOpen() {
for (Block block : blocks) {
@@ -99,7 +111,6 @@ public boolean isOpen() {
return false;
}
-
private boolean setBlockOpen(Block block, boolean open) {
BlockData materialData = block.getBlockData();
if (!isFunctionalOpenable(materialData)) {
diff --git a/src/main/java/nl/rutgerkok/blocklocker/impl/protection/DoorProtectionImpl.java b/src/main/java/nl/rutgerkok/blocklocker/impl/protection/DoorProtectionImpl.java
index 9fef7d9..b7cbc2d 100644
--- a/src/main/java/nl/rutgerkok/blocklocker/impl/protection/DoorProtectionImpl.java
+++ b/src/main/java/nl/rutgerkok/blocklocker/impl/protection/DoorProtectionImpl.java
@@ -2,6 +2,8 @@
import java.util.Collection;
+import org.bukkit.block.Block;
+
import nl.rutgerkok.blocklocker.ProtectionSign;
import nl.rutgerkok.blocklocker.impl.CompleteDoor;
import nl.rutgerkok.blocklocker.impl.blockfinder.BlockFinder;
@@ -24,7 +26,7 @@ public final class DoorProtectionImpl extends AbstractProtection implements Door
* The block finder.
* @param door
* The door.
- *
+ *
* @return The door protection object.
*/
public static Protection fromDoorWithSign(ProtectionSign sign, BlockFinder blockFinder, CompleteDoor door) {
@@ -71,6 +73,11 @@ protected Collection fetchSigns() {
return blockFinder.findAttachedSigns(door.getBlocksForSigns());
}
+ @Override
+ public Block getSomeProtectedBlock() {
+ return this.door.getSomeDoorBlock();
+ }
+
@Override
public boolean isOpen() {
return door.isOpen();
diff --git a/src/main/java/nl/rutgerkok/blocklocker/impl/updater/UpdateChecker.java b/src/main/java/nl/rutgerkok/blocklocker/impl/updater/UpdateChecker.java
index 9a81f0c..e60c4b0 100644
--- a/src/main/java/nl/rutgerkok/blocklocker/impl/updater/UpdateChecker.java
+++ b/src/main/java/nl/rutgerkok/blocklocker/impl/updater/UpdateChecker.java
@@ -31,6 +31,7 @@ final class UpdateChecker {
* If an IO error occurs.
*/
public UpdateCheckResult checkForUpdatesSync(Plugin plugin) throws IOException {
+ @SuppressWarnings("deprecation")
String currentVersionEncoded = URLEncoder.encode(plugin.getDescription().getVersion(), "UTF-8");
URL url = new URL(UPDATE_URL + "?version=" + currentVersionEncoded);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
diff --git a/src/main/java/nl/rutgerkok/blocklocker/impl/updater/Updater.java b/src/main/java/nl/rutgerkok/blocklocker/impl/updater/Updater.java
index 5e716dc..93fcabb 100644
--- a/src/main/java/nl/rutgerkok/blocklocker/impl/updater/Updater.java
+++ b/src/main/java/nl/rutgerkok/blocklocker/impl/updater/Updater.java
@@ -9,10 +9,8 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
-import org.bukkit.plugin.Plugin;
-import org.bukkit.scheduler.BukkitRunnable;
-
import nl.rutgerkok.blocklocker.Translator;
+import nl.rutgerkok.blocklocker.impl.BlockLockerPluginImpl;
import nl.rutgerkok.blocklocker.impl.updater.UpdateResult.Status;
/**
@@ -26,21 +24,11 @@ public final class Updater {
*/
private static final long CHECK_INTERVAL = 20 * 60 * 60 * 12;
- private final Plugin plugin;
+ private final BlockLockerPluginImpl plugin;
private volatile UpdatePreference preference;
- private final BukkitRunnable task = new BukkitRunnable() {
- @Override
- public void run() {
- if (preference.checkForUpdates()) {
- updateSync();
- } else {
- this.cancel();
- }
- }
- };
private final Translator translator;
- public Updater(UpdatePreference preference, Translator translator, Plugin plugin) {
+ public Updater(UpdatePreference preference, Translator translator, BlockLockerPluginImpl plugin) {
this.preference = Preconditions.checkNotNull(preference);
this.translator = Preconditions.checkNotNull(translator);
this.plugin = Preconditions.checkNotNull(plugin);
@@ -77,12 +65,12 @@ private void notifyServer(final UpdateResult result) {
if (plugin.getServer().isPrimaryThread()) {
notifyServerFromServerThread(result);
} else {
- plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
+ plugin.runLaterGlobally(new Runnable() {
@Override
public void run() {
notifyServerFromServerThread(result);
}
- });
+ }, 1);
}
}
@@ -109,7 +97,13 @@ public void startUpdater() {
if (!preference.checkForUpdates()) {
return;
}
- task.runTaskTimerAsynchronously(plugin, 1, CHECK_INTERVAL);
+ plugin.runTimerAsync(task -> {
+ if (preference.checkForUpdates()) {
+ updateSync();
+ } else {
+ task.cancel();
+ }
+ }, CHECK_INTERVAL);
}
private void updateInstallSync(UpdateCheckResult result) throws IOException {
diff --git a/src/main/java/nl/rutgerkok/blocklocker/impl/updater/UserAgent.java b/src/main/java/nl/rutgerkok/blocklocker/impl/updater/UserAgent.java
index 526a71c..bc0d04f 100644
--- a/src/main/java/nl/rutgerkok/blocklocker/impl/updater/UserAgent.java
+++ b/src/main/java/nl/rutgerkok/blocklocker/impl/updater/UserAgent.java
@@ -10,10 +10,6 @@
*/
final class UserAgent {
- private UserAgent() {
-
- }
-
/**
* Sets the correct user agent as used by this plugin on the request.
*
@@ -23,7 +19,12 @@ private UserAgent() {
* The request to set the user agent on.
*/
static void setFor(Plugin plugin, URLConnection connection) {
+ @SuppressWarnings("deprecation")
String agent = "Mozilla/5.0 (" + plugin.getName() + "/" + plugin.getDescription().getVersion() + ")";
connection.setRequestProperty("User-Agent", agent);
}
+
+ private UserAgent() {
+
+ }
}
diff --git a/src/main/java/nl/rutgerkok/blocklocker/protection/Protection.java b/src/main/java/nl/rutgerkok/blocklocker/protection/Protection.java
index 93a43df..2b13963 100644
--- a/src/main/java/nl/rutgerkok/blocklocker/protection/Protection.java
+++ b/src/main/java/nl/rutgerkok/blocklocker/protection/Protection.java
@@ -4,6 +4,8 @@
import java.util.Date;
import java.util.Optional;
+import org.bukkit.block.Block;
+
import nl.rutgerkok.blocklocker.ProtectionSign;
import nl.rutgerkok.blocklocker.profile.Profile;
@@ -49,6 +51,14 @@ enum SoundCondition {
*/
Collection getAllowed();
+ /**
+ * Gets the location of the protection. Returns one of the blocks in the
+ * protection (if there are multiple blocks), and not one of the signs.
+ *
+ * @return The location.
+ */
+ Block getSomeProtectedBlock();
+
/**
* Gets the amount of seconds the door should stay open, before closing
* automatically. If no amount of seconds was specified on the door, -1 is
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 964794f..bb67907 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -5,6 +5,7 @@ author: Rutger Kok
load: startup
api-version: 1.18
softdepend: [Guilds, Factions, mcMMO, Towny]
+folia-supported: true
permissions:
blocklocker.protect:
description: "Protect containers and doors."