mirror of
https://github.com/JEFF-Media-GbR/BetterTridents.git
synced 2025-01-14 11:31:18 +01:00
Initial commit
This commit is contained in:
commit
284b359006
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# Project exclude paths
|
||||
/target/
|
122
pom.xml
Normal file
122
pom.xml
Normal file
@ -0,0 +1,122 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>de.jeff_media</groupId>
|
||||
<name>NoTridentVoid</name>
|
||||
<artifactId>NoTridentVoid</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<properties>
|
||||
<spigot.prefix>${project.name}</spigot.prefix>
|
||||
<spigot.main>${project.groupId}.notridentvoid.Main</spigot.main>
|
||||
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.build.timestamp.format>yyyyMMddHHmm</maven.build.timestamp.format>
|
||||
<config.version>${maven.build.timestamp}</config.version>
|
||||
</properties>
|
||||
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<configuration>
|
||||
<finalName>${project.name}</finalName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>testCompile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>org.apache.maven.wagon</groupId>
|
||||
<artifactId>wagon-ftp</artifactId>
|
||||
<version>3.4.1</version>
|
||||
</extension>
|
||||
</extensions>
|
||||
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jeff-media-gbr</id>
|
||||
<url>https://repo.jeff-media.de/maven2</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spigot and PaperLib -->
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.16.5-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.jeff_media</groupId>
|
||||
<artifactId>SpigotUpdateChecker</artifactId>
|
||||
<version>1.2.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>jeff-ftp</id>
|
||||
<url>ftps://ftp.jeff-media.de/maven2</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
</project>
|
60
src/main/java/de/jeff_media/notridentvoid/Main.java
Normal file
60
src/main/java/de/jeff_media/notridentvoid/Main.java
Normal file
@ -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<UUID> 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());
|
||||
}
|
||||
}
|
21
src/main/java/de/jeff_media/notridentvoid/config/Config.java
Normal file
21
src/main/java/de/jeff_media/notridentvoid/config/Config.java
Normal file
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package de.jeff_media.notridentvoid.config;
|
||||
|
||||
public class Permissions {
|
||||
public static final String NOTRIDENTVOID_USE = "notridentvoid.use";
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
33
src/main/resources/config.yml
Normal file
33
src/main/resources/config.yml
Normal file
@ -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}
|
16
src/main/resources/plugin.yml
Normal file
16
src/main/resources/plugin.yml
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user