commit 284b359006510c776ea83481526ae41e856502d7
Author: mfnalex <1122571+mfnalex@users.noreply.github.com>
Date: Mon May 24 13:46:25 2021 +0200
Initial commit
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..744289d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+# Project exclude paths
+/target/
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..3aacef9
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,122 @@
+
+ 4.0.0
+
+ de.jeff_media
+ NoTridentVoid
+ NoTridentVoid
+ 1.0.0
+
+
+ ${project.name}
+ ${project.groupId}.notridentvoid.Main
+
+ UTF-8
+ 1.8
+ yyyyMMddHHmm
+ ${maven.build.timestamp}
+
+
+
+
+
+
+ src/main/resources
+ true
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 3.1.0
+
+ ${project.name}
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.1.0
+
+
+ package
+
+ shade
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.0
+
+
+ compile
+ compile
+
+ compile
+
+
+
+ testCompile
+ test-compile
+
+ testCompile
+
+
+
+
+
+ ${java.version}
+
+
+
+
+
+
+ org.apache.maven.wagon
+ wagon-ftp
+ 3.4.1
+
+
+
+
+
+
+
+ spigot-repo
+ https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
+
+ jeff-media-gbr
+ https://repo.jeff-media.de/maven2
+
+
+
+
+
+
+ org.spigotmc
+ spigot
+ 1.16.5-R0.1-SNAPSHOT
+ provided
+
+
+ de.jeff_media
+ SpigotUpdateChecker
+ 1.2.1
+
+
+
+
+
+
+ jeff-ftp
+ ftps://ftp.jeff-media.de/maven2
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/de/jeff_media/notridentvoid/Main.java b/src/main/java/de/jeff_media/notridentvoid/Main.java
new file mode 100644
index 0000000..3700bcd
--- /dev/null
+++ b/src/main/java/de/jeff_media/notridentvoid/Main.java
@@ -0,0 +1,60 @@
+package de.jeff_media.notridentvoid;
+
+import de.jeff_media.notridentvoid.config.Config;
+import de.jeff_media.notridentvoid.listeners.ProjectileListener;
+import de.jeff_media.updatechecker.UpdateChecker;
+import de.jeff_media.updatechecker.UserAgentBuilder;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.NamespacedKey;
+import org.bukkit.entity.Trident;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.util.ArrayList;
+import java.util.UUID;
+
+public class Main extends JavaPlugin {
+
+ private static Main instance;
+ private final ArrayList tridents = new ArrayList<>();
+ public static final Material SAFETY_MATERIAL = Material.BARRIER;
+ public static NamespacedKey LOYALTY_TAG;
+
+ public static Main getInstance() {
+ return instance;
+ }
+
+ @Override
+ public void onEnable() {
+ instance = this;
+ LOYALTY_TAG = new NamespacedKey(this, "loyalty");
+ reload();
+ Bukkit.getPluginManager().registerEvents(new ProjectileListener(), this);
+ }
+
+ public void reload() {
+ new Config();
+ UpdateChecker.init(this, "https://api.jeff-media.de/notridentvoid/latest-version.txt")
+ .setDonationLink("https://paypal.me/mfnalex")
+ .setDownloadLink("https://www.spigotmc.org/resources/authors/mfnalex.175238/")
+ .setUserAgent(UserAgentBuilder.getDefaultUserAgent());
+ if(getConfig().getString(Config.CHECK_FOR_UPDATES).equalsIgnoreCase("true")) {
+ UpdateChecker.getInstance().checkEveryXHours(getConfig().getDouble(Config.UPDATE_CHECK_INTERVAL))
+ .checkNow();
+ } else if(getConfig().getString(Config.CHECK_FOR_UPDATES).equalsIgnoreCase("on-startup")) {
+ UpdateChecker.getInstance().checkNow();
+ }
+ }
+
+ public void register(Trident trident) {
+ tridents.add(trident.getUniqueId());
+ }
+
+ public boolean isRegistered(Trident trident) {
+ return tridents.contains(trident.getUniqueId());
+ }
+
+ public void unregister(Trident trident) {
+ tridents.remove(trident.getUniqueId());
+ }
+}
diff --git a/src/main/java/de/jeff_media/notridentvoid/config/Config.java b/src/main/java/de/jeff_media/notridentvoid/config/Config.java
new file mode 100644
index 0000000..18648fa
--- /dev/null
+++ b/src/main/java/de/jeff_media/notridentvoid/config/Config.java
@@ -0,0 +1,21 @@
+package de.jeff_media.notridentvoid.config;
+
+import de.jeff_media.notridentvoid.Main;
+
+public class Config {
+
+ private final Main main = Main.getInstance();
+
+ public static String VOID_SAVING = "void-saving";
+ public static String CHECK_FOR_UPDATES = "check-for-updates";
+ public static String UPDATE_CHECK_INTERVAL = "update-check-interval";
+
+ public Config() {
+ addDefault(VOID_SAVING, true);
+ }
+
+ private void addDefault(String node, Object value) {
+ main.getConfig().set(node, value);
+ }
+
+}
diff --git a/src/main/java/de/jeff_media/notridentvoid/config/Permissions.java b/src/main/java/de/jeff_media/notridentvoid/config/Permissions.java
new file mode 100644
index 0000000..9dd0abd
--- /dev/null
+++ b/src/main/java/de/jeff_media/notridentvoid/config/Permissions.java
@@ -0,0 +1,5 @@
+package de.jeff_media.notridentvoid.config;
+
+public class Permissions {
+ public static final String NOTRIDENTVOID_USE = "notridentvoid.use";
+}
diff --git a/src/main/java/de/jeff_media/notridentvoid/listeners/ProjectileListener.java b/src/main/java/de/jeff_media/notridentvoid/listeners/ProjectileListener.java
new file mode 100644
index 0000000..eaae15f
--- /dev/null
+++ b/src/main/java/de/jeff_media/notridentvoid/listeners/ProjectileListener.java
@@ -0,0 +1,66 @@
+package de.jeff_media.notridentvoid.listeners;
+
+import de.jeff_media.notridentvoid.Main;
+import de.jeff_media.notridentvoid.config.Config;
+import de.jeff_media.notridentvoid.tasks.WatchTrident;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
+import org.bukkit.entity.Trident;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.ProjectileLaunchEvent;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import org.bukkit.persistence.PersistentDataContainer;
+import org.bukkit.persistence.PersistentDataType;
+import org.bukkit.scheduler.BukkitRunnable;
+
+public class ProjectileListener implements Listener {
+
+ private final Main main = Main.getInstance();
+
+ /*private boolean hasLoyalty(Entity trident) {
+ return trident.getPersistentDataContainer().has(Main.LOYALTY_TAG, PersistentDataType.BYTE);
+ }
+
+ private void addLoyalty(Entity trident) {
+ trident.getPersistentDataContainer().set(Main.LOYALTY_TAG,PersistentDataType.BYTE, (byte) 1);
+ }*/
+
+ private boolean hasLoyalty(ItemStack item) {
+ if(!item.hasItemMeta()) return false;
+ ItemMeta meta = item.getItemMeta();
+ return meta.hasEnchant(Enchantment.LOYALTY);
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onShoot(ProjectileLaunchEvent event) {
+ if(event.getEntityType() != EntityType.TRIDENT) return;
+ Trident trident = (Trident) event.getEntity();
+ if(main.isRegistered(trident)) return;
+ //if(!hasLoyalty(trident)) return;
+ if(!(trident.getShooter() instanceof Player)) return;
+ Player player = (Player) trident.getShooter();
+ ItemStack tridentItem = null;
+ if(player.getInventory().getItemInMainHand() != null) {
+ if(player.getInventory().getItemInMainHand().getType() == Material.TRIDENT) {
+ tridentItem = player.getInventory().getItemInMainHand();
+ }
+ } else if(player.getInventory().getItemInOffHand() != null) {
+ if(player.getInventory().getItemInOffHand().getType() == Material.TRIDENT) {
+ tridentItem = player.getInventory().getItemInOffHand();
+ }
+ }
+ if(tridentItem == null) return;
+ if(!hasLoyalty(tridentItem)) return;
+ if(!main.getConfig().getBoolean(Config.VOID_SAVING)) return;
+ main.register(trident);
+ new WatchTrident(trident).runTaskTimer(main,1,1);
+ Bukkit.getScheduler().runTaskLater(main,() ->main.unregister(trident),20);
+ }
+}
diff --git a/src/main/java/de/jeff_media/notridentvoid/tasks/RemoveBarrier.java b/src/main/java/de/jeff_media/notridentvoid/tasks/RemoveBarrier.java
new file mode 100644
index 0000000..02c8a37
--- /dev/null
+++ b/src/main/java/de/jeff_media/notridentvoid/tasks/RemoveBarrier.java
@@ -0,0 +1,35 @@
+package de.jeff_media.notridentvoid.tasks;
+
+import de.jeff_media.notridentvoid.Main;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.entity.Trident;
+import org.bukkit.scheduler.BukkitRunnable;
+
+public class RemoveBarrier extends BukkitRunnable {
+
+ private static final int MAX_TICKS = 40;
+ private final Block block;
+ private final Trident trident;
+ private int ticks = 0;
+ private boolean landed = false;
+
+ public RemoveBarrier(Trident trident, Block block) {
+ this.block = block;
+ this.trident = trident;
+ }
+
+ @Override
+ public void run() {
+ ticks++;
+ if(ticks >= MAX_TICKS || (trident.getVelocity().length() > 0 && trident.getLocation().distanceSquared(block.getLocation())>2)) {
+ Bukkit.getScheduler().runTaskLater(Main.getInstance(), () ->{
+ if (block.getType() == Main.SAFETY_MATERIAL) {
+ block.setType(Material.AIR);
+ }
+ cancel();
+ },20);
+ }
+ }
+}
diff --git a/src/main/java/de/jeff_media/notridentvoid/tasks/WatchTrident.java b/src/main/java/de/jeff_media/notridentvoid/tasks/WatchTrident.java
new file mode 100644
index 0000000..6dcbfaa
--- /dev/null
+++ b/src/main/java/de/jeff_media/notridentvoid/tasks/WatchTrident.java
@@ -0,0 +1,45 @@
+package de.jeff_media.notridentvoid.tasks;
+
+import de.jeff_media.notridentvoid.Main;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.entity.Trident;
+import org.bukkit.scheduler.BukkitRunnable;
+import org.bukkit.util.Vector;
+
+public class WatchTrident extends BukkitRunnable {
+
+ private static final int MAX_TICKS = 1200;
+ private final Trident trident;
+ private int ticks = 0;
+
+ public WatchTrident(Trident trident) {
+ this.trident = trident;
+ }
+
+ @Override
+ public void run() {
+
+ ticks++;
+ if(ticks >= MAX_TICKS || trident == null || trident.isDead() || !trident.isValid() || trident.getVelocity().length() == 0) {
+ cancel();
+ return;
+ }
+
+ Location nextLocation = trident.getLocation().add(trident.getVelocity());
+
+ if(nextLocation.getBlockY() > 1) return;
+ if(!nextLocation.getBlock().getType().isAir()) return;
+
+ if(nextLocation.getBlockY() < 0) {
+ nextLocation.setY(0);
+ trident.teleport(nextLocation.clone().add(0,1,0));
+ trident.setVelocity(new Vector(0,-1,0));
+ }
+
+ nextLocation.getBlock().setType(Main.SAFETY_MATERIAL);
+
+ new RemoveBarrier(trident, nextLocation.getBlock()).runTaskTimer(Main.getInstance(), 1, 1);
+ cancel();
+ }
+}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
new file mode 100644
index 0000000..ae1c936
--- /dev/null
+++ b/src/main/resources/config.yml
@@ -0,0 +1,33 @@
+##################
+# BetterTridents #
+##################
+
+# by mfnalex (JEFF Media GbR)
+
+###############
+# Permissions #
+###############
+
+# notridentvoid.use
+# Allows to use the "void-saving" feature
+# Default: true
+
+# When enabled, tridents enchanted with loyalty will be returned to the player
+# instead of vanishing when falling into the void
+# This is currently the only function of this plugin :P
+void-saving: true
+
+# Should we check for updates?
+# When enabled, a message is printed in the console if a new version has
+# been found, and OPs will be notified when they join the server.
+# When set to true, we will check for updates on startup and every X hours
+# When set to on-startup, we will only check on startup
+# When set to false, don't check for updates
+check-for-updates: true
+
+# When check-for-updates is true, AngelChest will check every X hours
+update-check-interval: 4
+
+# NEVER CHANGE THE VALUES BELOW!
+plugin-version: ${project.version}
+config-version: ${config.version}
\ No newline at end of file
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
new file mode 100644
index 0000000..ed4c62e
--- /dev/null
+++ b/src/main/resources/plugin.yml
@@ -0,0 +1,16 @@
+name: ${project.name}
+main: ${spigot.main}
+version: ${project.version}
+prefix: ${spigot.prefix}
+api-version: "1.13"
+authors: [mfnalex, JEFF Media GbR]
+website: "https://www.mfnalex.de"
+database: false
+load: STARTUP
+awareness:
+ - !@UTF8
+commands:
+permissions:
+ notridentvoid.use:
+ description: Prevents tridents enchanted with loyalty to get lost in the void
+ default: true
\ No newline at end of file