Skip to content

Instantly share code, notes, and snippets.

@TwoSquirrels
Last active January 29, 2023 15:33
Show Gist options
  • Save TwoSquirrels/a8bcb81c18ea9fda636417f39c97ae09 to your computer and use it in GitHub Desktop.
Save TwoSquirrels/a8bcb81c18ea9fda636417f39c97ae09 to your computer and use it in GitHub Desktop.
Simple Grappling Hook Spigot Plugin
// SPDX-License-Identifier: CC0
package io.github.twosquirrels.simplegrapplinghook;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
public final class SimpleGrapplingHook extends JavaPlugin implements Listener {
final double LATERAL = 0.7;
final double VERTICAL = 1.2;
@Override
public void onEnable() {
// Plugin startup logic
super.getServer().getPluginManager().registerEvents(this, this);
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
return true;
}
@EventHandler
public void onFish(PlayerFishEvent event) {
Player player = event.getPlayer();
FishHook fishHook = event.getHook();
PlayerFishEvent.State state = event.getState();
if (
state.equals(PlayerFishEvent.State.REEL_IN) ||
state.equals(PlayerFishEvent.State.IN_GROUND) ||
state.equals(PlayerFishEvent.State.CAUGHT_ENTITY) ||
state.equals(PlayerFishEvent.State.CAUGHT_FISH)
) {
Location playerLoc = player.getLocation();
Location hookLoc = fishHook.getLocation();
double dir = Math.atan2(hookLoc.getZ() - playerLoc.getZ(), hookLoc.getX() - playerLoc.getX());
player.setVelocity(new Vector()
.setX((hookLoc.getX() - playerLoc.getX()) * this.LATERAL)
.setY(this.VERTICAL)
.setZ((hookLoc.getZ() - playerLoc.getZ()) * this.LATERAL)
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment