Implement basic spawn command
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bea 2022-11-11 23:22:26 +01:00
parent 8bc992a707
commit 09396fa09a
5 changed files with 39 additions and 6 deletions

View File

@ -3,6 +3,7 @@ package wtf.beatrice.limbomanager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import wtf.beatrice.limbomanager.commands.Spawn;
import wtf.beatrice.limbomanager.listeners.CommandCanceller; import wtf.beatrice.limbomanager.listeners.CommandCanceller;
import wtf.beatrice.limbomanager.listeners.PlayerChecker; import wtf.beatrice.limbomanager.listeners.PlayerChecker;
import wtf.beatrice.limbomanager.listeners.PlayerTeleporter; import wtf.beatrice.limbomanager.listeners.PlayerTeleporter;
@ -23,6 +24,10 @@ public class LimboManager extends JavaPlugin {
instance = this; instance = this;
pluginManager = Bukkit.getServer().getPluginManager(); pluginManager = Bukkit.getServer().getPluginManager();
// register commands
getCommand("spawn").setExecutor(new Spawn());
// register listeners
pluginManager.registerEvents(new PlayerChecker(), this); pluginManager.registerEvents(new PlayerChecker(), this);
pluginManager.registerEvents(new PlayerTeleporter(), this); pluginManager.registerEvents(new PlayerTeleporter(), this);
pluginManager.registerEvents(new CommandCanceller(), this); pluginManager.registerEvents(new CommandCanceller(), this);

View File

@ -0,0 +1,27 @@
package wtf.beatrice.limbomanager.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import wtf.beatrice.limbomanager.Cache;
public class Spawn implements CommandExecutor
{
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args)
{
if(!(sender instanceof Player))
{
sender.sendMessage("Not a player");
return true;
}
Cache.teleportToOwnIsland((Player) sender);
sender.sendMessage("Teleported");
return true;
}
}

View File

@ -4,13 +4,10 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import java.util.ArrayList;
import java.util.List;
public class CommandCanceller implements Listener public class CommandCanceller implements Listener
{ {
private final static String allowedCmdsRegex = "\\/(login|register|changepassword|premium|cracked)\\b"; private final static String allowedCmdsRegex = "\\/(login|register|changepassword|premium|cracked|spawn)\\b";
/* /*
first "/" is the command prefix first "/" is the command prefix
(login|register|...) means either one or the other (login|register|...) means either one or the other

View File

@ -20,7 +20,6 @@ public class PlayerChecker implements Listener
// remove join msg // remove join msg
event.setJoinMessage(null); event.setJoinMessage(null);
LimboManager plugin = LimboManager.getInstance(); LimboManager plugin = LimboManager.getInstance();
Player joiner = event.getPlayer(); Player joiner = event.getPlayer();

View File

@ -6,3 +6,8 @@ api-version: 1.19
author: astro_bea author: astro_bea
depend: depend:
- WorldEdit - WorldEdit
commands:
spawn:
usage: /<command>
description: teleport to player island spawn