reorganize engine bits into engine package, same with commands, reimplement player state as FSM
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package gg.malloc.defense.commands;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import gg.malloc.defense.engine.GameRunner;
|
||||
|
||||
import gg.malloc.defense.Plugin;
|
||||
|
||||
public class AddPlayerCommand implements CommandExecutor {
|
||||
Plugin m_plugin;
|
||||
|
||||
public AddPlayerCommand(Plugin plugin) {
|
||||
m_plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
||||
String worldName = args[0];
|
||||
GameRunner runner = m_plugin.getRunnerForWorld(m_plugin.getServer().getWorld(worldName));
|
||||
Player player = m_plugin.getServer().getPlayer(args[1]);
|
||||
runner.addPlayer(player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package gg.malloc.defense.commands;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.World;
|
||||
|
||||
import gg.malloc.defense.engine.GameRunner;
|
||||
|
||||
import gg.malloc.defense.Plugin;
|
||||
|
||||
public class SetStageCommand implements CommandExecutor {
|
||||
Plugin m_plugin;
|
||||
|
||||
public SetStageCommand(Plugin plugin) {
|
||||
m_plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
||||
World world = m_plugin.getServer().getWorld(args[1]);
|
||||
GameRunner runner = m_plugin.getRunnerForWorld(world);
|
||||
String stateName = args[0].toLowerCase();
|
||||
boolean ret = false;
|
||||
if (stateName.equals("idle")) {
|
||||
ret = runner.requestTransition(GameRunner.Stage.Idle);
|
||||
} else if (stateName.equals("warmup")) {
|
||||
ret = runner.requestTransition(GameRunner.Stage.Warmup);
|
||||
} else if (stateName.equals("playing")) {
|
||||
ret = runner.requestTransition(GameRunner.Stage.Playing);
|
||||
} else if (stateName.equals("gameover")) {
|
||||
ret = runner.requestTransition(GameRunner.Stage.GameOver);
|
||||
} else {
|
||||
sender.sendMessage("Unknown state " + stateName);
|
||||
return false;
|
||||
}
|
||||
if (!ret) {
|
||||
sender.sendMessage("Could not set state to " + stateName);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user