@EventHandler public void onButtonClick(ButtonClickEvent event) { TreeTabButton button = (TreeTabButton) event.getButton(); SpoutPlayer sPlayer = event.getPlayer(); sPlayer.sendMessage("Button " + button.getSkillSet().toString() + " clicked"); gui.switchSkillTreeTab(button, sPlayer); }
@Override public void keyPressed(KeyBindingEvent keyBindingEvent) { Keyboard key = keyBindingEvent.getBinding().getDefaultKey(); switch (key) { case KEY_1: case KEY_2: case KEY_3: case KEY_4: case KEY_5: case KEY_6: case KEY_7: case KEY_8: case KEY_9: SpoutPlayer p = keyBindingEvent.getPlayer(); if (holdingCtrl.contains(p)) { int numKey = (int) key.toString().charAt(4) - 49; p.sendMessage(numKey + " pressed"); // p.setItemInHand( lastWep.get( p ) ); // This is wrong. This puts the pressed keys // item in the current hand. It doesn't change the #slot that's active.. SkillsPlayer mmoPlayer = MMOSkillTree.mmoPlayerManager.get(p); mmoPlayer.activateSkill(numKey); } break; } if (key == Keyboard.KEY_LCONTROL) { SpoutPlayer p = keyBindingEvent.getPlayer(); holdingCtrl.add(p); lastWep.put(p, p.getItemInHand()); } }
@Override public void playMusic(String url, Location location, SpoutPlayer player) { /** get players in radius of the jukebox and start it for only those players * */ for (Player p : location.getWorld().getPlayers()) { double distance = location.toVector().distance(p.getLocation().toVector()); if (distance <= (double) range) { SpoutPlayer sp = SpoutManager.getPlayer(p); if (sp.isSpoutCraftEnabled()) { try { SpoutManager.getSoundManager().playCustomMusic(plugin, sp, url, true, location, range); } catch (Exception e) { // the disc has an error. player.sendMessage(e.getMessage()); SpoutManager.getSoundManager() .playGlobalCustomSoundEffect( plugin, CustomsManager.SF_JUKEBOX_ERROR, false, location, 3); } } } } }
public boolean onCommand(CommandSender sender, Command cmd, String label, String args[]) { if (sender instanceof SpoutPlayer) { SpoutPlayer player = (SpoutPlayer) sender; if (cmd.getName().equals("toomanybuckets") && args.length == 0) { plugin.openOverlay(player); return true; } else { if (args.length == 1 && args[0].equalsIgnoreCase("rml")) { player.sendMessage(ChatColor.RED + "rml can only be issued from the console!"); return true; } else { return false; } } } else { if (args.length != 1 || !args[0].equalsIgnoreCase("rml")) { sender.sendMessage("You need to be player to invoke the GUI interface!"); return true; } else { plugin.load(true); return true; } } }
@Override public void onKeyPressedEvent(KeyPressedEvent event) { if (event.getScreenType() != ScreenType.GAME_SCREEN) { return; } SpoutPlayer player = event.getPlayer(); PlayerOptions po = PlayerOptions.getPlayer(player); String msg = ""; if (Utils.isValidModifier(event.getKey())) { PlayerOptions.addPressed(player.getName(), event.getKey()); return; } ChooseMode mode = PlayerOptions.getMode(player); boolean valid = Utils.isValidKey(player, event.getKey()); if (!valid) { switch (mode) { case SET: case GSET: player.sendMessage(ChatColor.RED + "That key combination is not valid."); } return; } LinkedHashSet<Keyboard> allPressed = PlayerOptions.getPressed(player.getName()); allPressed.add(event.getKey()); if (mode == ChooseMode.NONE) { if (!Permission.check(player, "SpoutKeyCommands.use")) { return; } PlayerCmd pc = PlayerCmd.get(player, allPressed); GlobalCmd gc = GlobalCmd.get(allPressed); if (pc == null && gc == null) { return; } String perf = po.getPreferred(); if (perf.equalsIgnoreCase("global") && gc != null || pc == null) { player.performCommand(gc.getCommand()); } else if (perf.equalsIgnoreCase("personal") && pc != null || pc != null) { player.performCommand(pc.getCommand()); } return; } String cmd = PlayerOptions.getCmd(player); PluginManager pm = Bukkit.getServer().getPluginManager(); String pluginName = SpoutKeyCommands.getInstance().getDescription().getName(); PlayerCmd pc = null; GlobalCmd gc = null; switch (mode) { case SET: if (cmd.equals("")) { return; } msg = ChatColor.DARK_AQUA + "Command set to: " + ChatColor.GREEN + Utils.getKeyString(allPressed); pc = PlayerCmd.get(player, allPressed); if (pc != null) { if (!pluginName.equals(pc.getPlugin())) { Plugin p = pm.getPlugin(pc.getPlugin()); if (p != null && p.isEnabled()) { msg = ChatColor.RED + "That key is already set by " + pc.getPlugin(); break; } } pc.setCommand(cmd); pc.setPlugin(pluginName); SpoutKeyCommands.getInstance().getDatabase().update(pc); break; } pc = new PlayerCmd(allPressed, cmd, player, SpoutKeyCommands.getInstance()); SpoutKeyCommands.getInstance().getDatabase().save(pc); break; case GSET: if (cmd.equals("")) { return; } msg = ChatColor.DARK_AQUA + "Global command set to: " + ChatColor.GREEN + Utils.getKeyString(allPressed); gc = GlobalCmd.get(allPressed); if (gc != null) { if (!pluginName.equals(gc.getPlugin())) { Plugin p = pm.getPlugin(gc.getPlugin()); if (p != null && p.isEnabled()) { msg = ChatColor.RED + "That key is already set by " + gc.getPlugin(); break; } } gc.setCommand(cmd); gc.setPlugin(pluginName); SpoutKeyCommands.getInstance().getDatabase().update(gc); break; } gc = new GlobalCmd(allPressed, cmd, SpoutKeyCommands.getInstance()); SpoutKeyCommands.getInstance().getDatabase().save(gc); break; case UNSET: pc = PlayerCmd.get(player, allPressed); if (pc == null) { msg = ChatColor.RED + "No command on this combination"; break; } if (!pluginName.equals(pc.getPlugin())) { Plugin p = pm.getPlugin(pc.getPlugin()); if (p != null && p.isEnabled()) { msg = ChatColor.RED + "That key is set by " + pc.getPlugin(); break; } } SpoutKeyCommands.getInstance().getDatabase().delete(pc); msg = ChatColor.DARK_AQUA + "Command unset from: " + ChatColor.GREEN + Utils.getKeyString(allPressed); break; case GUNSET: gc = GlobalCmd.get(allPressed); if (gc == null) { msg = ChatColor.RED + "No global command on this combination"; break; } if (!pluginName.equals(gc.getPlugin())) { Plugin p = pm.getPlugin(gc.getPlugin()); if (p != null && p.isEnabled()) { msg = ChatColor.RED + "That key is already set by " + gc.getPlugin(); break; } } SpoutKeyCommands.getInstance().getDatabase().delete(gc); msg = ChatColor.DARK_AQUA + "Global command unset from: " + ChatColor.GREEN + Utils.getKeyString(allPressed); break; } player.sendMessage(msg); }
public void onCustomEvent(Event event) { if (event instanceof ButtonClickEvent) { Button button = ((ButtonClickEvent) event).getButton(); UUID uuid = button.getId(); SpoutPlayer sPlayer = ((ButtonClickEvent) event).getPlayer(); ItemStack itemInHand = sPlayer.getInventory().getItemInHand(); int id = sPlayer.getEntityId(); if (BITBook.BITButtons.get(uuid) == "saveBookButton") { BITBook.popupScreen.get(id).close(); BITBook.cleanupPopupScreen(sPlayer); BITBook.BITButtons.remove(uuid); int i = BITBook.currentPageNo.get(id); BITBook.bodytextGUI2.get(id)[i] = BITBook.bodytextGUI.get(id).getText(); BITBook.saveBook(sPlayer, BITBook.currentBookId.get(id)); itemInHand.setDurability(BITBook.currentBookId.get(id)); sPlayer.closeActiveWindow(); BITBook.hasOpenedBook.put(id, false); } else if (BITBook.BITButtons.get(uuid) == "cancelBookButton" || BITBook.BITButtons.get(uuid) == "returnBookButton") { BITBook.popupScreen.get(id).close(); BITBook.cleanupPopupScreen(sPlayer); BITBook.BITButtons.remove(uuid); BITBook.bitBooks.remove(BITBook.currentBookId.get(id)); BITBook.currentBookId.put(id, (short) 1000); sPlayer.closeActiveWindow(); BITBook.hasOpenedBook.put(id, false); } else if ((BITBook.BITButtons.get(uuid) == "nextPageButton")) { if (validateFields(sPlayer)) { BITBook.showNextPage(sPlayer); } } else if ((BITBook.BITButtons.get(uuid) == "previousPageButton")) { if (validateFields(sPlayer)) { BITBook.showPreviousPage(sPlayer); } } else if ((BITBook.BITButtons.get(uuid) == "masterCopyButton")) { if (validateFields(sPlayer)) { if (BITBook.masterCopyGUI.get(id)) { BITBook.masterCopyGUI.put(id, false); } else { BITBook.masterCopyGUI.put(id, true); } BITBook.masterCopyButtonGUI.get(id).setText("Master:" + BITBook.masterCopyGUI.get(id)); BITBook.masterCopyButtonGUI.get(id).setDirty(true); } } else if ((BITBook.BITButtons.get(uuid) == "forceBookToPlayerInventoryButton")) { if (validateFields(sPlayer)) { if (BITBook.forceBookToPlayerInventoryGUI.get(id)) { BITBook.forceBookToPlayerInventoryGUI.put(id, false); } else { BITBook.forceBookToPlayerInventoryGUI.put(id, true); } BITBook.forceBookToPlayerInventoryButtonGUI .get(id) .setText("Force:" + BITBook.forceBookToPlayerInventoryGUI.get(id)); BITBook.forceBookToPlayerInventoryButtonGUI.get(id).setDirty(true); } } else if ((BITBook.BITButtons.get(uuid) == "canBeMovedFromInventoryButton")) { if (validateFields(sPlayer)) { if (BITBook.canBeMovedFromInventoryGUI.get(id)) { BITBook.canBeMovedFromInventoryGUI.put(id, false); } else { BITBook.canBeMovedFromInventoryGUI.put(id, true); } BITBook.canBeMovedFromInventoryButtonGUI .get(id) .setText("Moved:" + BITBook.canBeMovedFromInventoryGUI.get(id)); BITBook.canBeMovedFromInventoryButtonGUI.get(id).setDirty(true); } } else if ((BITBook.BITButtons.get(uuid) == "copyTheBookWhenMovedButton")) { if (validateFields(sPlayer)) { if (BITBook.copyTheBookWhenMovedGUI.get(id)) { BITBook.copyTheBookWhenMovedGUI.put(id, false); } else { BITBook.copyTheBookWhenMovedGUI.put(id, true); } BITBook.copyTheBookWhenMovedButtonGUI .get(id) .setText("Copy:" + BITBook.copyTheBookWhenMovedGUI.get(id)); BITBook.copyTheBookWhenMovedButtonGUI.get(id).setDirty(true); } } // ************************************ // This only happens if I have forgot to handle a button // ************************************ else { if (BITConfig.DEBUG_GUI) sPlayer.sendMessage( "BITBookSpoutListener: Unknow button:" + BITBook.BITButtons.get(uuid)); } } }