Java Code Examples for org.bukkit.entity.Player#performCommand()
The following examples show how to use
org.bukkit.entity.Player#performCommand() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpSudoEvent.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@Override protected Void execute(String playerID) { Player player = PlayerConverter.getPlayer(playerID); boolean previousOp = player.isOp(); try { player.setOp(true); for (String command : commands) player.performCommand(command.replace("%player%", player.getName())); } catch (Exception e) { LogUtils.getLogger().log(Level.WARNING, "Couldn't run OpSudoEvent.", e); LogUtils.logThrowable(e); } finally { player.setOp(previousOp); } return null; }
Example 2
Source File: SignEvents.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onBlockHit(PlayerInteractEvent e) { Player player = e.getPlayer(); if (e.getPlayer() == null || e.getClickedBlock() == null || e.getAction() != Action.RIGHT_CLICK_BLOCK || e.getPlayer().getGameMode() != GameMode.SURVIVAL || !isSign(e.getClickedBlock().getType()) || !player.hasPermission("usb.island.signs.use") || !plugin.getWorldManager().isSkyAssociatedWorld(player.getWorld())) { return; } if (e.getClickedBlock().getState() instanceof Sign) { Sign sign = (Sign) e.getClickedBlock().getState(); String firstLine = FormatUtil.stripFormatting(sign.getLine(0)).trim(); if (firstLine.startsWith("/")) { e.setCancelled(true); player.performCommand(firstLine.substring(1)); } } }
Example 3
Source File: uSkyBlock.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
private void doExecCommand(Player player, String command) { if (command.startsWith("op:")) { if (player.isOp()) { player.performCommand(command.substring(3).trim()); } else { player.setOp(true); // Prevent privilege escalation if called command throws unhandled exception try { player.performCommand(command.substring(3).trim()); } finally { player.setOp(false); } } } else if (command.startsWith("console:")) { getServer().dispatchCommand(getServer().getConsoleSender(), command.substring(8).trim()); } else { player.performCommand(command); } }
Example 4
Source File: CommandTouchAction.java From HoloAPI with GNU General Public License v3.0 | 6 votes |
@Override public void onTouch(Player who, Action action) { String command = this.command.replace("%name%", who.getName()); command = command.replace("%world%", who.getWorld().getName()); if (command.startsWith("server ")) { String serverName = StringUtil.combineSplit(1, command.split(" "), " "); ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(byteOutput); try { out.writeUTF("Connect"); out.writeUTF(serverName); who.sendPluginMessage(HoloAPI.getCore(), "BungeeCord", byteOutput.toByteArray()); return; } catch (IOException ignored) { } } if (this.shouldPerformAsConsole()) { HoloAPI.getCore().getServer().dispatchCommand(HoloAPI.getCore().getServer().getConsoleSender(), command); } else { who.performCommand(command); } }
Example 5
Source File: SkyBlockMenu.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
private void onClickCreateMenu(InventoryClickEvent event, Player p, ItemMeta meta, int slotIndex, int menuSize) { event.setCancelled(true); if (slotIndex == 0) { p.closeInventory(); p.performCommand("island create"); } else if (slotIndex == menuSize-2) { p.closeInventory(); p.performCommand("island spawn"); } else if (slotIndex == menuSize-1) { p.closeInventory(); p.performCommand("island accept"); } else if (meta != null && meta.getDisplayName() != null) { String schemeName = stripFormatting(meta.getDisplayName()); if (plugin.getPerkLogic().getSchemes(p).contains(schemeName)) { p.closeInventory(); p.performCommand("island create " + schemeName); } else { p.sendMessage(tr("\u00a7eYou do not have access to that island-schematic!")); } } }
Example 6
Source File: GridManager.java From askyblock with GNU General Public License v2.0 | 5 votes |
/** * This removes players from an island overworld and nether - used when reseting or deleting an island * Mobs are killed when the chunks are refreshed. * @param island to remove players from * @param uuid - uuid to ignore */ public void removePlayersFromIsland(final Island island, UUID uuid) { // Teleport players away for (Player player : plugin.getServer().getOnlinePlayers()) { if (island.inIslandSpace(player.getLocation())) { //plugin.getLogger().info("DEBUG: in island space"); // Teleport island players to their island home if (!player.getUniqueId().equals(uuid) && (plugin.getPlayers().hasIsland(player.getUniqueId()) || plugin.getPlayers().inTeam(player.getUniqueId()))) { //plugin.getLogger().info("DEBUG: home teleport"); homeTeleport(player); } else { //plugin.getLogger().info("DEBUG: move player to spawn"); // Move player to spawn Island spawn = getSpawn(); if (spawn != null) { // go to island spawn player.teleport(ASkyBlock.getIslandWorld().getSpawnLocation()); //plugin.getLogger().warning("During island deletion player " + player.getName() + " sent to spawn."); } else { if (!player.performCommand(Settings.SPAWNCOMMAND)) { plugin.getLogger().warning( "During island deletion player " + player.getName() + " could not be sent to spawn so was dropped, sorry."); } } } } } }
Example 7
Source File: SudoEvent.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
@Override protected Void execute(String playerID) { Player player = PlayerConverter.getPlayer(playerID); for (String command : commands) { player.performCommand(command.replace("%player%", player.getName())); } return null; }
Example 8
Source File: SkyBlockMenu.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
private void onClickPartyMenu(InventoryClickEvent event, ItemStack currentItem, Player p, ItemMeta meta, SkullMeta skull, int slotIndex) { event.setCancelled(true); if (slotIndex < 0 || slotIndex > 35) { return; } if (meta == null || currentItem.getType() == SIGN_MATERIAL) { p.closeInventory(); p.performCommand("island"); } else if (skull != null && plugin.getIslandInfo(p).isLeader(p)) { p.closeInventory(); p.openInventory(displayPartyPlayerGUI(p, skull.getOwner())); } }
Example 9
Source File: Util.java From askyblock with GNU General Public License v2.0 | 5 votes |
public static void runCommand(final Player player, final String string) { if (plugin.getServer().isPrimaryThread()) { player.performCommand(string); } else { plugin.getServer().getScheduler().runTask(plugin, () -> player.performCommand(string)); } }
Example 10
Source File: SkyBlockMenu.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
private void onClickLogMenu(InventoryClickEvent event, Player p, int slotIndex) { event.setCancelled(true); if (slotIndex < 0 || slotIndex > 35) { return; } p.closeInventory(); p.performCommand("island"); }
Example 11
Source File: ArmorStandCmd.java From ArmorStandTools with MIT License | 5 votes |
boolean execute(Player p) { if(command == null) return true; if(isOnCooldown()) { p.sendMessage(ChatColor.RED + Config.cmdOnCooldown); return true; } setOnCooldown(); String cmd = command.contains("%player%") ? command.replaceAll("%player%", p.getName()) : command; if(console) { return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd); } else { return p.performCommand(cmd); } }
Example 12
Source File: SelectorIcon.java From SonarPet with GNU General Public License v3.0 | 5 votes |
@Override public void onClick(final Player viewer) { viewer.closeInventory(); if (this.command.equalsIgnoreCase(EchoPet.getPlugin().getCommandString() + " menu")) { new BukkitRunnable() { @Override public void run() { viewer.performCommand(getCommand()); } }.runTaskLater(EchoPet.getPlugin(), 5L); } else { viewer.performCommand(this.getCommand()); } }
Example 13
Source File: CombatManager.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
private void runAsPlayer(Player player, String command) { try { player.performCommand(command); } catch(Throwable ex) { Logger logger = this.plugin.getLogger(); logger.log(Level.SEVERE, "An error occurred while executing a command as a player:", ex); } }
Example 14
Source File: Signs.java From AnnihilationPro with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void signClickCheck(PlayerInteractEvent event) { if(event.getAction() == Action.RIGHT_CLICK_BLOCK) { Block b = event.getClickedBlock(); if(b != null) { if(b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) { final Location loc = b.getLocation(); final Player p = event.getPlayer(); AnniSign sign = this.signs.get(MapKey.getKey(loc)); if(sign != null) { event.setCancelled(true); if(sign.getType().equals(SignType.Team)) { AnniTeam team = sign.getType().getTeam(); if(team != null) { p.performCommand("team "+team.getName()); } } else if(sign.getType().equals(SignType.Brewing)) { ShopMenu.openBrewingShop(p); } else if(sign.getType().equals(SignType.Weapon)) { ShopMenu.openWeaponShop(p); } } } } } }
Example 15
Source File: SelectorIcon.java From EchoPet with GNU General Public License v3.0 | 5 votes |
@Override public void onClick(final Player viewer) { viewer.closeInventory(); if (this.command.equalsIgnoreCase(EchoPet.getPlugin().getCommandString() + " menu")) { new BukkitRunnable() { @Override public void run() { viewer.performCommand(getCommand()); } }.runTaskLater(EchoPet.getPlugin(), 5L); } else { viewer.performCommand(this.getCommand()); } }
Example 16
Source File: CommandUtil.java From Civs with GNU General Public License v3.0 | 5 votes |
public static void performCommand(OfflinePlayer offlinePlayer, String command) { String finalCommand = command; boolean runAsOp = false; boolean runFromConsole = false; for (;;) { if (finalCommand.startsWith("^")) { runAsOp = true; finalCommand = finalCommand.substring(1); } else if (finalCommand.startsWith("!")) { runFromConsole = true; finalCommand = finalCommand.substring(1); } else { break; } } if (offlinePlayer.isOnline()) { finalCommand = finalCommand.replace("$name$", ((Player) offlinePlayer).getName()); } else { Player player1 = offlinePlayer.getPlayer(); if (player1 != null && player1.isValid()) { finalCommand = finalCommand.replace("$name$", player1.getName()); } } if (runFromConsole) { Bukkit.dispatchCommand(Bukkit.getConsoleSender(), finalCommand); } else if (offlinePlayer.isOnline()) { Player player = (Player) offlinePlayer; boolean setOp = runAsOp && !player.isOp(); if (setOp) { player.setOp(true); } player.performCommand(finalCommand); if (setOp) { player.setOp(false); } } }
Example 17
Source File: ItemShortcut.java From Minepacks with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onItemClick(InventoryClickEvent event) { if(event.getWhoClicked() instanceof Player) { final Player player = (Player) event.getWhoClicked(); if(isItemShortcut(event.getCurrentItem())) { if(event.getAction() == InventoryAction.SWAP_WITH_CURSOR) { if(plugin.isDisabled(player) != WorldBlacklistMode.None || !player.hasPermission(Permissions.USE) || !plugin.isPlayerGameModeAllowed(player)) return; Backpack backpack = plugin.getBackpackCachedOnly(player); if(backpack != null) { //TODO right click should place only one final ItemStack stack = event.getCursor(); if(plugin.getItemFilter() == null || !plugin.getItemFilter().isItemBlocked(stack)) { ItemStack full = backpack.addItem(stack); stack.setAmount((full == null) ? 0 : full.getAmount()); event.setCursor(full); event.setCancelled(true); } else { plugin.getItemFilter().messageNotAllowedInBackpack.send(player, plugin.getItemFilter().itemNameResolver.getName(stack)); } } } else if(event.getClick() == ClickType.RIGHT || event.getClick() == ClickType.SHIFT_RIGHT) { player.performCommand(openCommand); event.setCancelled(true); } else if(event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) { event.setCancelled(true); messageDoNotRemoveItem.send(player); } if(blockItemFromMoving) event.setCancelled(true); } else if((event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD || event.getAction() == InventoryAction.HOTBAR_SWAP) && event.getHotbarButton() != -1) { ItemStack item = player.getInventory().getItem(event.getHotbarButton()); if(isItemShortcut(item)) { event.setCancelled(true); messageDoNotRemoveItem.send(player); } } else if(isItemShortcut(event.getCursor())) { if(!player.getInventory().equals(event.getClickedInventory())) { event.setCancelled(true); messageDoNotRemoveItem.send(player); } else if(event.getSlotType() == InventoryType.SlotType.ARMOR && blockAsHat) { event.setCancelled(true); } } } }
Example 18
Source File: PlayerEvents.java From askyblock with GNU General Public License v2.0 | 4 votes |
/** * Prevents visitors from getting damage if invinciblevisitors option is set to TRUE * @param e - event */ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onVisitorGetDamage(EntityDamageEvent e){ if(!Settings.invincibleVisitors || !(e.getEntity() instanceof Player) || e.getCause().equals(DamageCause.ENTITY_ATTACK)) { return; } Player p = (Player) e.getEntity(); if (!IslandGuard.inWorld(p) || plugin.getGrid().locationIsOnIsland(p, p.getLocation())) return; if (Settings.visitorDamagePrevention.contains(e.getCause())) e.setCancelled(true); if(e.getCause().equals(DamageCause.VOID)) { if (plugin.getPlayers().hasIsland(p.getUniqueId()) || plugin.getPlayers().inTeam(p.getUniqueId())) { Location safePlace = plugin.getGrid().getSafeHomeLocation(p.getUniqueId(), 1); if (safePlace != null) { unsetFalling(p.getUniqueId()); p.teleport(safePlace); // Set their fall distance to zero otherwise they crash onto their island and die p.setFallDistance(0); e.setCancelled(true); return; } } if (plugin.getGrid().getSpawn() != null) { p.teleport(plugin.getGrid().getSpawnPoint()); // Set their fall distance to zero otherwise they crash onto their island and die p.setFallDistance(0); e.setCancelled(true); return; } else if (!p.performCommand("spawn")) { // If this command doesn't work, let them die otherwise they may get trapped in the void forever return; } else { // Set their fall distance to zero otherwise they crash onto their island and die p.setFallDistance(0); e.setCancelled(true); } } }
Example 19
Source File: SkyBlockMenu.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
private void onClickChallengeMenu(InventoryClickEvent event, ItemStack currentItem, Player p, String inventoryName) { int slotIndex = event.getRawSlot(); event.setCancelled(true); Matcher m = CHALLENGE_PAGE_HEADER.matcher(inventoryName); int page = 1; int max = challengeLogic.getTotalPages(); if (m.find()) { page = Integer.parseInt(m.group("p")); max = Integer.parseInt(m.group("max")); } ItemStack item = event.getInventory().getItem(event.getInventory().getSize() - 9); String playerName = item != null && item.hasItemMeta() && item.getItemMeta().getLore() != null && item.getItemMeta().getLore().size() > 0 ? item.getItemMeta().getLore().get(0) : null; if (playerName != null && playerName.trim().isEmpty()) { playerName = null; } // Last row is pagination if (slotIndex >= CHALLENGE_PAGESIZE && slotIndex < CHALLENGE_PAGESIZE + COLS_PER_ROW && currentItem != null && currentItem.getType() != Material.AIR) { // Pagination p.closeInventory(); p.openInventory(displayChallengeGUI(p, currentItem.getAmount(), playerName)); return; } // If in action bar or anywhere else, just bail out if (slotIndex < 0 || slotIndex > CHALLENGE_PAGESIZE || isAirOrLocked(currentItem)) { return; } if ((slotIndex % 9) > 0) { // 0,9... are the rank-headers... p.closeInventory(); if (currentItem.getItemMeta() != null) { String challenge = currentItem.getItemMeta().getDisplayName(); String challengeName = stripFormatting(challenge); p.performCommand("c c " + challengeName); } p.openInventory(displayChallengeGUI(p, page, playerName)); } else { p.closeInventory(); if (slotIndex < (CHALLENGE_PAGESIZE/2)) { // Upper half if (page > 1) { p.openInventory(displayChallengeGUI(p, page - 1, playerName)); } else { p.performCommand("island"); } } else if (page < max) { p.openInventory(displayChallengeGUI(p, page + 1, playerName)); } else { p.performCommand("island"); } } }
Example 20
Source File: SkyBlockMenu.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
private void onClickMainMenu(InventoryClickEvent event, ItemStack currentItem, Player p, int slotIndex) { event.setCancelled(true); if (slotIndex < 0 || slotIndex > 35) { return; } PlayerInfo playerInfo = plugin.getPlayerInfo(p); IslandInfo islandInfo = plugin.getIslandInfo(playerInfo); if (currentItem.getType() == Material.JUNGLE_SAPLING) { p.closeInventory(); p.performCommand("island biome"); } else if (currentItem.getType() == Material.PLAYER_HEAD) { p.closeInventory(); p.performCommand("island party"); } else if (currentItem.getType() == Material.RED_BED) { p.closeInventory(); p.performCommand("island sethome"); p.performCommand("island"); } else if (currentItem.getType() == Material.GRASS) { p.closeInventory(); p.performCommand("island spawn"); } else if (currentItem.getType() == Material.HOPPER) { p.closeInventory(); p.performCommand("island setwarp"); p.performCommand("island"); } else if (currentItem.getType() == Material.WRITABLE_BOOK) { p.closeInventory(); p.performCommand("island log"); } else if (currentItem.getType() == Material.OAK_DOOR) { p.closeInventory(); p.performCommand("island home"); } else if (currentItem.getType() == Material.EXPERIENCE_BOTTLE) { p.closeInventory(); p.performCommand("island level"); } else if (currentItem.getType() == Material.DIAMOND_ORE) { p.closeInventory(); p.performCommand("c"); } else if (currentItem.getType() == Material.END_STONE || currentItem.getType() == Material.END_PORTAL_FRAME) { p.closeInventory(); p.performCommand("island togglewarp"); p.performCommand("island"); } else if (currentItem.getType() == Material.IRON_BARS && islandInfo.isLocked()) { p.closeInventory(); p.performCommand("island unlock"); p.performCommand("island"); } else if (currentItem.getType() == Material.IRON_BARS && !islandInfo.isLocked()) { p.closeInventory(); p.performCommand("island lock"); p.performCommand("island"); } else if (slotIndex == 17) { if (islandInfo.isLeader(p) && plugin.getConfig().getBoolean("island-schemes-enabled", true)) { p.closeInventory(); p.openInventory(createRestartGUI(p)); } else { if (plugin.getConfirmHandler().millisLeft(p, "/is leave") > 0) { p.closeInventory(); p.performCommand("island leave"); } else { p.performCommand("island leave"); updateLeaveMenuItemTimer(p, event.getInventory(), currentItem); } } } else { if (!isExtraMenuAction(p, currentItem)) { p.closeInventory(); p.performCommand("island"); } } }