commit f46286ce360441b6d34b681db0e34bed8766eb71
parent f27bc0004520de20556377b4a7e967ed64bae1a7
Author: typable <contact@typable.dev>
Date: Sat, 7 Sep 2024 16:25:26 +0200
feat: Added fast-travel feature
Diffstat:
5 files changed, 85 insertions(+), 3 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,3 +1,5 @@
poppy.jar
+.project
.gradle/
-build/
-\ No newline at end of file
+build/
+.settings/
diff --git a/build.sh b/build.sh
@@ -6,7 +6,6 @@ else
cpdl=";"
fi
-
javac -cp "./libs/bungeecord-chat-1.20-R0.2.jar${cpdl}./libs/spigot-api-1.21.1-R0.1-20240831.215322-16.jar" src/poppy/*.java src/poppy/modules/*.java -d build
jar cvfm poppy.jar res/MANIFEST.MF -C res plugin.yml -C build poppy
rm -rf ./build
diff --git a/check.sh b/check.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+if [[ "$OSTYPE" == "linux-gnu" || "$OSTYPE" == "darwin" ]]; then
+ cpdl=":"
+else
+ cpdl=";"
+fi
+
+javac -cp "./libs/bungeecord-chat-1.20-R0.2.jar${cpdl}./libs/spigot-api-1.21.1-R0.1-20240831.215322-16.jar" src/poppy/*.java src/poppy/modules/*.java -d build 2>&1
+if [ $? -eq 0 ]; then
+ rm -rf ./build
+fi
+exit 0
diff --git a/src/poppy/Main.java b/src/poppy/Main.java
@@ -25,6 +25,7 @@ import poppy.modules.CommonModule;
import poppy.modules.LeavesDecayModule;
import poppy.modules.SpawnerModule;
import poppy.modules.PlayerMountModule;
+import poppy.modules.FastTravelModule;
public class Main extends JavaPlugin {
@@ -44,6 +45,7 @@ public class Main extends JavaPlugin {
private AutoBreakerModule autoBreakerModule;
private PlayerMountModule playerMountModule;
private BlockDetectorModule blockDetectorModule;
+ private FastTravelModule fastTravelModule;
@Override
public void onEnable() {
@@ -86,6 +88,9 @@ public class Main extends JavaPlugin {
blockDetectorModule = new BlockDetectorModule();
pluginManager.registerEvents(blockDetectorModule, this);
+
+ fastTravelModule = new FastTravelModule(this);
+ pluginManager.registerEvents(fastTravelModule, this);
}
@Override
diff --git a/src/poppy/modules/FastTravelModule.java b/src/poppy/modules/FastTravelModule.java
@@ -0,0 +1,64 @@
+package poppy.modules;
+
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.Sound;
+import org.bukkit.block.Block;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Listener;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.player.PlayerInteractEvent;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.EquipmentSlot;
+import org.bukkit.inventory.meta.CompassMeta;
+import org.bukkit.scheduler.BukkitRunnable;
+
+public class FastTravelModule implements Listener {
+
+ private Plugin plugin;
+
+ public FastTravelModule(final Plugin plugin) {
+ this.plugin = plugin;
+ }
+
+ @EventHandler
+ public void onPlayerInteract(final PlayerInteractEvent event) {
+ if (event.getHand() != EquipmentSlot.HAND) {
+ return;
+ }
+ final ItemStack item = event.getItem();
+ if (item == null || item.getType() != Material.COMPASS) {
+ return;
+ }
+ final Block block = event.getClickedBlock();
+ if (block != null && block.getType() == Material.LODESTONE) {
+ return;
+ }
+ final CompassMeta meta = (CompassMeta) item.getItemMeta();
+ if (!meta.hasLodestone()) {
+ return;
+ }
+ final Player player = event.getPlayer();
+ final Location location = meta.getLodestone();
+ new BukkitRunnable() {
+ int timer = 5;
+ @Override
+ public void run() {
+ final Location playerLocation = player.getLocation();
+ if ( timer > 0) {
+ player.playSound(playerLocation, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 100.0F, 1.0F);
+ }
+ if (timer == 0) {
+ this.cancel();
+ location.add(0.5, 1.0, 0.5);
+ location.setYaw(playerLocation.getYaw());
+ location.setPitch(playerLocation.getPitch());
+ player.teleport(location);
+ player.playSound(playerLocation, Sound.ENTITY_PLAYER_TELEPORT, 100.0F, 1.0F);
+ }
+ timer--;
+ }
+ }.runTaskTimer(this.plugin, 0L, 20L);
+ }
+}