From 1e1a13e7a14bcac243b277a066d4ba0356dcb2c9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20=C5=A0mahel?=
<48548230+ceskyDJ@users.noreply.github.com>
Date: Tue, 21 Dec 2021 19:12:32 +0100
Subject: [PATCH] Add support for Spigot 1.13+ and some refactoring #25
---
pom.xml | 4 ++--
.../exceptions/MissingArgumentException.java | 22 -------------------
.../MissingPermissionException.java | 6 ++---
.../exceptions/PluginNotFoundException.java | 1 +
.../listeners/BlockBreakListener.java | 3 ---
.../listeners/MobMoveListener.java | 8 -------
.../listeners/WaterCreateListener.java | 3 ---
.../listeners/WaterDispenseListener.java | 11 ++++------
.../listeners/WaterPlaceListener.java | 1 -
.../listeners/WaterReplaceListener.java | 4 ----
.../listeners/WaterScoopListener.java | 10 +++++----
.../netherwater/managers/ConfigManager.java | 2 +-
.../managers/ConfigManipulator.java | 8 +------
.../netherwater/managers/MessageManager.java | 2 +-
.../tasks/WaterAnimationAgent.java | 1 -
.../tasks/WaterDisappearingAgent.java | 1 -
src/main/resources/plugin.yml | 3 ++-
17 files changed, 20 insertions(+), 70 deletions(-)
delete mode 100644 src/main/java/cz/ceskydj/netherwater/exceptions/MissingArgumentException.java
diff --git a/pom.xml b/pom.xml
index 4fe493c..a626d33 100644
--- a/pom.xml
+++ b/pom.xml
@@ -78,7 +78,7 @@
org.spigotmc
spigot-api
- 1.15.2-R0.1-SNAPSHOT
+ 1.13.2-R0.1-SNAPSHOT
provided
@@ -92,7 +92,7 @@
com.sk89q.worldguard
worldguard-bukkit
- 7.0.2
+ 7.0.0
provided
diff --git a/src/main/java/cz/ceskydj/netherwater/exceptions/MissingArgumentException.java b/src/main/java/cz/ceskydj/netherwater/exceptions/MissingArgumentException.java
deleted file mode 100644
index 56d25bc..0000000
--- a/src/main/java/cz/ceskydj/netherwater/exceptions/MissingArgumentException.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package cz.ceskydj.netherwater.exceptions;
-
-public class MissingArgumentException extends Exception {
- public MissingArgumentException() {
- }
-
- public MissingArgumentException(String message) {
- super(message);
- }
-
- public MissingArgumentException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public MissingArgumentException(Throwable cause) {
- super(cause);
- }
-
- public MissingArgumentException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
- }
-}
diff --git a/src/main/java/cz/ceskydj/netherwater/exceptions/MissingPermissionException.java b/src/main/java/cz/ceskydj/netherwater/exceptions/MissingPermissionException.java
index 821b9b1..d3830a4 100644
--- a/src/main/java/cz/ceskydj/netherwater/exceptions/MissingPermissionException.java
+++ b/src/main/java/cz/ceskydj/netherwater/exceptions/MissingPermissionException.java
@@ -1,10 +1,8 @@
package cz.ceskydj.netherwater.exceptions;
-import java.security.PrivilegedActionException;
-
+@SuppressWarnings("unused")
public class MissingPermissionException extends Exception {
- public MissingPermissionException() {
- }
+ public MissingPermissionException() {}
public MissingPermissionException(String message) {
super(message);
diff --git a/src/main/java/cz/ceskydj/netherwater/exceptions/PluginNotFoundException.java b/src/main/java/cz/ceskydj/netherwater/exceptions/PluginNotFoundException.java
index a5cd992..a1e413d 100644
--- a/src/main/java/cz/ceskydj/netherwater/exceptions/PluginNotFoundException.java
+++ b/src/main/java/cz/ceskydj/netherwater/exceptions/PluginNotFoundException.java
@@ -1,5 +1,6 @@
package cz.ceskydj.netherwater.exceptions;
+@SuppressWarnings("unused")
public class PluginNotFoundException extends Exception {
public PluginNotFoundException() {
super();
diff --git a/src/main/java/cz/ceskydj/netherwater/listeners/BlockBreakListener.java b/src/main/java/cz/ceskydj/netherwater/listeners/BlockBreakListener.java
index 403f495..4c13725 100644
--- a/src/main/java/cz/ceskydj/netherwater/listeners/BlockBreakListener.java
+++ b/src/main/java/cz/ceskydj/netherwater/listeners/BlockBreakListener.java
@@ -18,14 +18,11 @@
import java.util.Objects;
public class BlockBreakListener implements Listener {
- private final NetherWater plugin;
private final MessageManager messageManager;
private final DB db;
private final PermissionManager permissionManager;
public BlockBreakListener(NetherWater plugin) {
- this.plugin = plugin;
-
this.messageManager = plugin.getMessageManager();
this.db = plugin.getDatabaseWrapper();
this.permissionManager = plugin.getPermissionManager();
diff --git a/src/main/java/cz/ceskydj/netherwater/listeners/MobMoveListener.java b/src/main/java/cz/ceskydj/netherwater/listeners/MobMoveListener.java
index 641a2aa..db9a77a 100644
--- a/src/main/java/cz/ceskydj/netherwater/listeners/MobMoveListener.java
+++ b/src/main/java/cz/ceskydj/netherwater/listeners/MobMoveListener.java
@@ -5,26 +5,18 @@
import cz.ceskydj.netherwater.database.EntityStorage;
import cz.ceskydj.netherwater.managers.ConfigManager;
import cz.ceskydj.netherwater.managers.MessageManager;
-import org.bouncycastle.util.Arrays;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.data.Levelled;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
-import org.bukkit.entity.Fish;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
-import org.bukkit.event.entity.EntityDamageByBlockEvent;
-import org.bukkit.event.entity.EntityDamageEvent;
-import org.bukkit.event.entity.EntityEnterBlockEvent;
-import org.bukkit.event.entity.EntityToggleSwimEvent;
import org.bukkit.event.player.PlayerMoveEvent;
-import java.util.Objects;
-
public class MobMoveListener implements Listener {
private final MessageManager messageManager;
private final ConfigManager configManager;
diff --git a/src/main/java/cz/ceskydj/netherwater/listeners/WaterCreateListener.java b/src/main/java/cz/ceskydj/netherwater/listeners/WaterCreateListener.java
index 5b03489..d997b3d 100644
--- a/src/main/java/cz/ceskydj/netherwater/listeners/WaterCreateListener.java
+++ b/src/main/java/cz/ceskydj/netherwater/listeners/WaterCreateListener.java
@@ -15,13 +15,10 @@
import org.bukkit.event.block.FluidLevelChangeEvent;
public class WaterCreateListener implements Listener {
- private final NetherWater plugin;
private final ConfigManager configManager;
private final MessageManager messageManager;
public WaterCreateListener(NetherWater plugin) {
- this.plugin = plugin;
-
this.configManager = plugin.getConfigManager();
this.messageManager = plugin.getMessageManager();
}
diff --git a/src/main/java/cz/ceskydj/netherwater/listeners/WaterDispenseListener.java b/src/main/java/cz/ceskydj/netherwater/listeners/WaterDispenseListener.java
index f9bfb90..f519bf2 100644
--- a/src/main/java/cz/ceskydj/netherwater/listeners/WaterDispenseListener.java
+++ b/src/main/java/cz/ceskydj/netherwater/listeners/WaterDispenseListener.java
@@ -46,7 +46,7 @@ public void onBlockDispense(BlockDispenseEvent event) {
this.messageManager.dump("- Block: " + block.getType().name());
this.messageManager.dump("- Block's metadata: " + block.getBlockData().getAsString(true));
this.messageManager.dump("- Item: " + item.getType().name());
- this.messageManager.dump("- Item's metadata: " + item.getItemMeta().toString());
+ this.messageManager.dump("- Item's metadata: " + item.getItemMeta());
if (block.getType() != Material.DISPENSER) {
return;
@@ -75,12 +75,9 @@ public void onBlockDispense(BlockDispenseEvent event) {
Dispenser dispenser = (Dispenser) block.getState();
Inventory inventory = dispenser.getInventory();
- Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() {
- @Override
- public void run() {
- int bucketPosition = inventory.first(Material.WATER_BUCKET);
- inventory.setItem(bucketPosition, new ItemStack(Material.BUCKET));
- }
+ Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, () -> {
+ int bucketPosition = inventory.first(Material.WATER_BUCKET);
+ inventory.setItem(bucketPosition, new ItemStack(Material.BUCKET));
});
// If the player has bypass permission, the water block won't disappear
diff --git a/src/main/java/cz/ceskydj/netherwater/listeners/WaterPlaceListener.java b/src/main/java/cz/ceskydj/netherwater/listeners/WaterPlaceListener.java
index c2bed40..84514fd 100644
--- a/src/main/java/cz/ceskydj/netherwater/listeners/WaterPlaceListener.java
+++ b/src/main/java/cz/ceskydj/netherwater/listeners/WaterPlaceListener.java
@@ -21,7 +21,6 @@
import org.bukkit.potion.PotionType;
import java.util.Objects;
-import java.util.logging.Level;
public class WaterPlaceListener implements Listener {
private final MessageManager messageManager;
diff --git a/src/main/java/cz/ceskydj/netherwater/listeners/WaterReplaceListener.java b/src/main/java/cz/ceskydj/netherwater/listeners/WaterReplaceListener.java
index dc4da34..7611e63 100644
--- a/src/main/java/cz/ceskydj/netherwater/listeners/WaterReplaceListener.java
+++ b/src/main/java/cz/ceskydj/netherwater/listeners/WaterReplaceListener.java
@@ -11,16 +11,12 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
-import org.bukkit.inventory.ItemStack;
public class WaterReplaceListener implements Listener {
- private final NetherWater plugin;
private final DB db;
private final PermissionManager permissionManager;
public WaterReplaceListener(NetherWater plugin) {
- this.plugin = plugin;
-
this.db = plugin.getDatabaseWrapper();
this.permissionManager = plugin.getPermissionManager();
}
diff --git a/src/main/java/cz/ceskydj/netherwater/listeners/WaterScoopListener.java b/src/main/java/cz/ceskydj/netherwater/listeners/WaterScoopListener.java
index 7bbebc9..2bfa5e8 100644
--- a/src/main/java/cz/ceskydj/netherwater/listeners/WaterScoopListener.java
+++ b/src/main/java/cz/ceskydj/netherwater/listeners/WaterScoopListener.java
@@ -16,15 +16,12 @@
import org.bukkit.event.player.PlayerInteractEvent;
public class WaterScoopListener implements Listener {
- private final NetherWater plugin;
private final ConfigManager configManager;
private final MessageManager messageManager;
private final DB db;
private final PermissionManager permissionManager;
public WaterScoopListener(NetherWater plugin) {
- this.plugin = plugin;
-
this.configManager = plugin.getConfigManager();
this.messageManager = plugin.getMessageManager();
this.db = plugin.getDatabaseWrapper();
@@ -42,7 +39,12 @@ public void onPlayerInteract(PlayerInteractEvent event) {
}
Player player = event.getPlayer();
- Block selectedBlock = event.getClickedBlock().getRelative(event.getBlockFace());
+ Block selectedBlock;
+ if (event.getClickedBlock() != null) {
+ selectedBlock = event.getClickedBlock().getRelative(event.getBlockFace());
+ } else {
+ return;
+ }
if (selectedBlock.getType() != Material.WATER) {
return;
diff --git a/src/main/java/cz/ceskydj/netherwater/managers/ConfigManager.java b/src/main/java/cz/ceskydj/netherwater/managers/ConfigManager.java
index e6c1db9..4e9f08b 100644
--- a/src/main/java/cz/ceskydj/netherwater/managers/ConfigManager.java
+++ b/src/main/java/cz/ceskydj/netherwater/managers/ConfigManager.java
@@ -3,7 +3,7 @@
import java.util.List;
public class ConfigManager {
- private ConfigManipulator configManipulator;
+ private final ConfigManipulator configManipulator;
public ConfigManager(ConfigManipulator configManipulator) {
this.configManipulator = configManipulator;
diff --git a/src/main/java/cz/ceskydj/netherwater/managers/ConfigManipulator.java b/src/main/java/cz/ceskydj/netherwater/managers/ConfigManipulator.java
index 04d01c0..015db2b 100644
--- a/src/main/java/cz/ceskydj/netherwater/managers/ConfigManipulator.java
+++ b/src/main/java/cz/ceskydj/netherwater/managers/ConfigManipulator.java
@@ -4,7 +4,6 @@
import de.leonhard.storage.Config;
import org.bukkit.ChatColor;
import org.bukkit.Color;
-import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
@@ -18,6 +17,7 @@
import java.util.Map;
import java.util.Objects;
+@SuppressWarnings("unused")
public class ConfigManipulator {
private final NetherWater plugin;
private final MessageManager messageManager;
@@ -164,12 +164,6 @@ public ItemStack getItemStack(String key) {
return this.configData.getOrDefault(key, defaultValue);
}
- public Location getLocation(String key) {
- Location defaultValue = this.defaultConfig.getLocation(key);
-
- return this.configData.getOrDefault(key, defaultValue);
- }
-
public OfflinePlayer getOfflinePlayer(String key) {
OfflinePlayer defaultValue = this.defaultConfig.getOfflinePlayer(key);
diff --git a/src/main/java/cz/ceskydj/netherwater/managers/MessageManager.java b/src/main/java/cz/ceskydj/netherwater/managers/MessageManager.java
index d8c849a..75a698d 100644
--- a/src/main/java/cz/ceskydj/netherwater/managers/MessageManager.java
+++ b/src/main/java/cz/ceskydj/netherwater/managers/MessageManager.java
@@ -52,7 +52,7 @@ public void sendMessage(ConsoleCommandSender console, String messageName) {
this.sendMessage(console, messageName, null);
}
- public void sendMessage(ConsoleCommandSender console, String messageName, Map variables) {
+ public void sendMessage(ConsoleCommandSender ignoredConsole, String messageName, Map variables) {
this.consoleMessage(this.prepareMessage(messageName, variables));
}
diff --git a/src/main/java/cz/ceskydj/netherwater/tasks/WaterAnimationAgent.java b/src/main/java/cz/ceskydj/netherwater/tasks/WaterAnimationAgent.java
index a599b8d..80a150d 100644
--- a/src/main/java/cz/ceskydj/netherwater/tasks/WaterAnimationAgent.java
+++ b/src/main/java/cz/ceskydj/netherwater/tasks/WaterAnimationAgent.java
@@ -8,7 +8,6 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Levelled;
-import org.bukkit.material.Cauldron;
import java.util.LinkedHashSet;
import java.util.List;
diff --git a/src/main/java/cz/ceskydj/netherwater/tasks/WaterDisappearingAgent.java b/src/main/java/cz/ceskydj/netherwater/tasks/WaterDisappearingAgent.java
index 6adc6e9..bd0a12d 100644
--- a/src/main/java/cz/ceskydj/netherwater/tasks/WaterDisappearingAgent.java
+++ b/src/main/java/cz/ceskydj/netherwater/tasks/WaterDisappearingAgent.java
@@ -74,7 +74,6 @@ public void run() {
if (blockType.contains("CAULDRON") && block.getBlockData() instanceof Levelled) {
Levelled water_level = (Levelled) block.getBlockData();
-
if (water_level.getLevel() == 1) {
// There is the last bit of water --> empty cauldron completely
block.setType(Material.CAULDRON);
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index d63b4f1..1f4dbaf 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -5,7 +5,7 @@ author: ceskyDJ
main: cz.ceskydj.netherwater.NetherWater
database: true
-api-version: "1.15"
+api-version: "1.13"
softdepend:
- WorldEdit
- WorldGuard
@@ -44,6 +44,7 @@ permissions:
netherwater.spread.bypass: true
netherwater.scooping.bypass: true
netherwater.disappearing.bypass: true
+ netherwater.drying.bypass: true
netherwater.world.bypass:
description: Allows players to bypass the disabled worlds and place water
default: op