// TODO: make sure this is threadsafe @EventHandler(priority = EventPriority.LOWEST) public void onPlayerChat(final AsyncPlayerChatEvent event) { if (event.getPlayer() == currentPlayer) { final StateMachine.MachineResult result = stateMachine.reactOnMessage(event.getMessage()); if (result == StateMachine.MachineResult.ABORT) { currentPlayer.sendMessage( "Installation wizard aborted. You can restart it using /essentialsupdate."); currentPlayer = null; } if (result == StateMachine.MachineResult.DONE) { startWork(); } event.setCancelled(true); } }
@EventHandler public void onPlayerJoin(final PlayerJoinEvent event) { final Player player = event.getPlayer(); if (currentPlayer != null && currentPlayer.getName().equals(player.getName())) { currentPlayer = player; player.sendMessage("You quit the game, while the installation wizard was running."); player.sendMessage("The installation wizard will now resume."); player.sendMessage("You can exit the wizard by typing quit into the chat."); stateMachine.resumeInstallation(player); } if (player.hasPermission("essentials.update") && !updateCheck.isEssentialsInstalled()) { player.sendMessage("Hello " + player.getDisplayName()); player.sendMessage( "Please type /essentialsupdate into the chat to start the installation of Essentials."); } if (player.hasPermission("essentials.update")) { final UpdateCheck.CheckResult result = updateCheck.getResult(); switch (result) { case NEW_ESS: player.sendMessage( "The new version " + updateCheck.getNewVersion().toString() + " for Essentials is available. Please type /essentialsupdate to update."); break; case NEW_BUKKIT: player.sendMessage( "Your bukkit version is not the recommended build for Essentials, please update to version " + updateCheck.getNewBukkitVersion() + "."); break; case NEW_ESS_BUKKIT: player.sendMessage( "There is a new version " + updateCheck.getNewVersion().toString() + " of Essentials for Bukkit " + updateCheck.getNewBukkitVersion()); break; default: } } }
public void onCommand(final CommandSender sender) { if (sender instanceof Player && sender.hasPermission("essentials.update")) { if (currentPlayer == null) { currentPlayer = (Player) sender; if (selfUpdate()) { return; } stateMachine = new StateMachine(plugin, currentPlayer, updateCheck); final StateMachine.MachineResult result = stateMachine.askQuestion(); if (result == StateMachine.MachineResult.DONE) { startWork(); } } if (!currentPlayer.equals(sender)) { sender.sendMessage( "The player " + currentPlayer.getDisplayName() + " is already using the wizard."); } } else { sender.sendMessage("Please run the command as op from in game."); } }