Implemented command argument handling
This commit is contained in:
parent
808ff6c84e
commit
d452f76007
@ -3,16 +3,36 @@ package dev.kske.spawnfly;
|
|||||||
import org.bukkit.command.*;
|
import org.bukkit.command.*;
|
||||||
|
|
||||||
public class SpawnCommand implements CommandExecutor {
|
public class SpawnCommand implements CommandExecutor {
|
||||||
public SpawnCommand() {}
|
SpawnFly spawnFly;
|
||||||
|
|
||||||
|
public SpawnCommand(SpawnFly spawnFly) { this.spawnFly = spawnFly;}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label,
|
public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label,
|
||||||
String[] args) {
|
String[] args) {
|
||||||
if(command.getName().equals("setspawnflyarea")) {
|
if(command.getName().equals("setspawnflyarea")) {
|
||||||
sender.sendMessage("Hello this works!");
|
if(args.length == 6) {
|
||||||
return true;
|
int[] cords = new int[6];
|
||||||
|
int cnt = 0;
|
||||||
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
try {
|
||||||
|
int value = Integer.parseInt(args[i]);
|
||||||
|
cords[i] = value;
|
||||||
|
//sender.sendMessage("Argument " +(i + 1) + " is " + value);
|
||||||
|
cnt++;
|
||||||
|
} catch (Exception e) {
|
||||||
|
//sender.sendMessage("Argument " + (i + 1) + " is not valid as a coordinate!");
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
|
if(cnt == 6) {
|
||||||
|
spawnFly.setCoordinates(cords[0], cords[1], cords[2], cords[3], cords[4], cords[5]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sender.sendMessage("Please use valid coordinates!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,16 +4,21 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public final class SpawnFly extends JavaPlugin {
|
public final class SpawnFly extends JavaPlugin {
|
||||||
|
SpawnListener spawnListener = new SpawnListener();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
getLogger().info("onEnable has been invoked!");
|
getLogger().info("onEnable has been invoked!");
|
||||||
Bukkit.getPluginManager().registerEvents(new SpawnListener(), this);
|
Bukkit.getPluginManager().registerEvents(spawnListener, this);
|
||||||
getCommand("setspawnflyarea").setExecutor(new SpawnCommand());
|
getCommand("setspawnflyarea").setExecutor(new SpawnCommand(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
getLogger().info("onDisable has been invoked!");
|
getLogger().info("onDisable has been invoked!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCoordinates(int x1, int y1, int z1, int x2, int y2, int z2) {
|
||||||
|
spawnListener.setCoordinates(x1, y1, z1, x2, y2, z2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import org.bukkit.event.entity.EntityToggleGlideEvent;
|
|||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
|
|
||||||
public class SpawnListener implements Listener {
|
public class SpawnListener implements Listener {
|
||||||
|
int x1, y1, z1, x2, y2, z2;
|
||||||
|
|
||||||
Map<String, Boolean> canceledEvents = new HashMap<>();
|
Map<String, Boolean> canceledEvents = new HashMap<>();
|
||||||
|
|
||||||
@ -47,4 +48,13 @@ public class SpawnListener implements Listener {
|
|||||||
canceledEvents.put(e.getEntity().getName(), false);
|
canceledEvents.put(e.getEntity().getName(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCoordinates(int x1, int y1, int z1, int x2, int y2, int z2) {
|
||||||
|
this.x1 = x1;
|
||||||
|
this.y1 = y1;
|
||||||
|
this.z1 = z1;
|
||||||
|
this.x2 = x2;
|
||||||
|
this.y2 = y2;
|
||||||
|
this.z2 = z2;
|
||||||
|
}
|
||||||
}
|
}
|
@ -3,4 +3,4 @@ main: dev.kske.spawnfly.SpawnFly
|
|||||||
version: 0.0.1
|
version: 0.0.1
|
||||||
commands:
|
commands:
|
||||||
setspawnflyarea:
|
setspawnflyarea:
|
||||||
usage: /setspawnflyarea
|
usage: /setspawnflyarea x1 y1 z1 x2 y2 z2
|
||||||
|
Loading…
Reference in New Issue
Block a user