Skip to content

Instantly share code, notes, and snippets.

@WouterG
Last active February 8, 2020 17:16
Show Gist options
  • Save WouterG/238d617cdee804f7fdf4cd08b834b90f to your computer and use it in GitHub Desktop.
Save WouterG/238d617cdee804f7fdf4cd08b834b90f to your computer and use it in GitHub Desktop.
import net.menoni.rd.RuntimeDebugger;
import net.menoni.rd.model.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
public class exampletimer implements Debugger, Debugger.Stoppable, Runnable {
private BukkitTask timerTask;
private Player invoker;
public void debug(RuntimeDebugger plugin, CommandSender cs) {
if (!(cs instanceof Player)) {
cs.sendMessage("Command can only be used by a player");
return;
}
this.invoker = (Player) cs;
timerTask = Bukkit.getScheduler().runTaskTimer(plugin, this, 2L, 2L);
cs.sendMessage(ChatColor.YELLOW + "Up up and away! Crouch to stop going up!");
}
public void run() {
if (this.invoker == null || !this.invoker.isOnline()) {
// make sure the script doesn't crash if the player disconnects
this.stop();
}
// if the player is sneaking, don't change their velocity
if (this.invoker.isSneaking()) {
return;
}
// otherwise, make them go up up up!
this.invoker.setVelocity(this.invoker.getVelocity().clone().add(new Vector(0d, 1d, 0d)));
}
public void stop() {
if (this.timerTask != null) {
this.timerTask.cancel();
this.timerTask = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment