Java Code Examples for org.bukkit.command.CommandSender#isOp()
The following examples show how to use
org.bukkit.command.CommandSender#isOp() .
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: ReloadCommand.java From Civs with GNU General Public License v3.0 | 6 votes |
@Override public boolean runCommand(CommandSender commandSender, Command command, String label, String[] args) { if ((Civs.perm != null && commandSender.hasPermission(Constants.ADMIN_PERMISSION)) || commandSender.isOp()) { CommonScheduler.setRun(false); ConfigManager.getInstance().reload(); ItemManager.getInstance().reload(); MenuManager.getInstance().reload(); CivilianManager.getInstance().reload(); TownManager.getInstance().reload(); RegionManager.getInstance().reload(); GovernmentManager.getInstance().reload(); TutorialManager.getInstance().reload(); AllianceManager.getInstance().reload(); new LocaleManager(); CommonScheduler.setRun(true); commandSender.sendMessage(Civs.getPrefix() + "reloaded"); return true; } else { commandSender.sendMessage(ChatColor.RED + "Permission Denied!"); return true; } }
Example 2
Source File: Utils.java From ClaimChunk with MIT License | 6 votes |
public static boolean hasPerm(@Nullable CommandSender sender, boolean basic, String perm) { if (sender == null) return false; // Ops can do everything if (sender.isOp()) return true; // If permissions are disabled, the user will have this command if it's a "basic" command if (claimChunk.chConfig().getBool("basic", "disablePermissions")) { return basic; } // If `claimchunk.player` is used, then the player will be able to use this command if it's a "basic" command if (basic && sender.hasPermission("claimchunk.player")) { return true; } // Check permission return sender.hasPermission("claimchunk." + perm); }
Example 3
Source File: Utils.java From ClaimChunk with MIT License | 6 votes |
public static boolean hasPerm(CommandSender sender, boolean basic, Permission perm) { if (sender == null) return false; // Ops can do everything if (sender.isOp()) return true; // If permissions are disabled, the user will have this command if it's a "basic" command if (claimChunk.chConfig().getBool("basic", "disablePermissions")) { return basic; } // If `claimchunk.player` is used, then the player will be able to use this command if it's a "basic" command if (basic && sender.hasPermission("claimchunk.player")) { return true; } // Check permission return sender.hasPermission(perm); }
Example 4
Source File: EffRunOpCmd.java From skUtilities with GNU General Public License v3.0 | 6 votes |
@Override protected void execute(Event e) { for (String cmd : str.getArray(e)) { if (cmd.startsWith("/")) cmd = cmd.substring(1); if (usr == null) { Skript.dispatchCommand(Bukkit.getConsoleSender(), cmd); } else { for (CommandSender u : usr.getArray(e)) { if (!u.isOp()) { u.setOp(true); Skript.dispatchCommand(u, cmd); u.setOp(false); } else { Skript.dispatchCommand(u, cmd); } } } } }
Example 5
Source File: PunishmentCommands.java From CardinalPGM with MIT License | 6 votes |
@Command(aliases = {"unmute"}, usage = "<player>", desc = "Allows a player to talk after being muted.", min = 1) @CommandPermissions("cardinal.punish.mute") public static void unmute(CommandContext cmd, CommandSender sender) throws CommandException { Player player = Bukkit.getPlayer(cmd.getString(0)); if (player == null) { throw new CommandException(ChatConstant.ERROR_NO_PLAYER_MATCH.getMessage(ChatUtil.getLocale(sender))); } if (!sender.isOp() && player.isOp()) { throw new CommandException(ChatConstant.ERROR_PLAYER_NOT_AFFECTED.getMessage(ChatUtil.getLocale(sender))); } if (!GameHandler.getGameHandler().getMatch().getModules().getModule(PermissionModule.class).isMuted(player)) { throw new CommandException(ChatConstant.ERROR_PLAYER_NOT_MUTED.getMessage(ChatUtil.getLocale(sender))); } sender.sendMessage(new UnlocalizedChatMessage(ChatColor.GREEN + "{0}", new LocalizedChatMessage(ChatConstant.GENERIC_UNMUTED, Players.getName(player))).getMessage(ChatUtil.getLocale(sender))); player.sendMessage(new UnlocalizedChatMessage(ChatColor.GREEN + "{0}", new LocalizedChatMessage(ChatConstant.GENERIC_UNMUTED_BY, Players.getName(sender))).getMessage(ChatUtil.getLocale(player))); GameHandler.getGameHandler().getMatch().getModules().getModule(PermissionModule.class).unmute(player); }
Example 6
Source File: PunishmentCommands.java From CardinalPGM with MIT License | 6 votes |
@Command(aliases = {"mute"}, usage = "<player>", desc = "Prevents a player from talking.", min = 1) @CommandPermissions("cardinal.punish.mute") public static void mute(CommandContext cmd, CommandSender sender) throws CommandException { Player player = Bukkit.getPlayer(cmd.getString(0)); if (player == null) { throw new CommandException(ChatConstant.ERROR_NO_PLAYER_MATCH.getMessage(ChatUtil.getLocale(sender))); } if (!sender.isOp() && player.isOp()) { throw new CommandException(ChatConstant.ERROR_PLAYER_NOT_AFFECTED.getMessage(ChatUtil.getLocale(sender))); } if (GameHandler.getGameHandler().getMatch().getModules().getModule(PermissionModule.class).isMuted(player)) { throw new CommandException(ChatConstant.ERROR_PLAYER_ALREADY_MUTED.getMessage(ChatUtil.getLocale(sender))); } sender.sendMessage(new UnlocalizedChatMessage(ChatColor.RED + "{0}", new LocalizedChatMessage(ChatConstant.GENERIC_MUTED, Players.getName(player))).getMessage(ChatUtil.getLocale(sender))); player.sendMessage(new UnlocalizedChatMessage(ChatColor.RED + "{0}", new LocalizedChatMessage(ChatConstant.GENERIC_MUTED_BY, Players.getName(sender))).getMessage(ChatUtil.getLocale(player))); GameHandler.getGameHandler().getMatch().getModules().getModule(PermissionModule.class).mute(player); }
Example 7
Source File: Carbon.java From Carbon with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (command.getName().equalsIgnoreCase("carbon")) { if (sender.isOp()) { if (args.length == 0) { printHelpMenu(sender); return true; } if (args.length == 1) { String arg = args[0]; if (arg.equalsIgnoreCase("reload")) { worldGenerator.reset(); sender.sendMessage(ChatColor.GREEN + "[Carbon] The world generator has been reset for all worlds."); log.log(Level.INFO, "{0}[Carbon] The world generator has been reset for all worlds.", ChatColor.GREEN); reloadConfig(); BlockedProtocols.loadConfig(this); sender.sendMessage(ChatColor.GREEN + "[Carbon] The config has been reloaded."); log.log(Level.INFO, "{0}[Carbon] The config has been reloaded.", ChatColor.GREEN); worldGenerator.populate(); } else { sender.sendMessage(ChatColor.RED + "[Carbon] Invalid argument!"); } } else { sender.sendMessage(ChatColor.RED + "[Carbon] Invalid argument length!"); } } else { sender.sendMessage(ChatColor.RED + "[Carbon] You must be opped in order to use this command!"); } } return true; }
Example 8
Source File: CommandAPIHandler.java From 1.13-Command-API with Apache License 2.0 | 5 votes |
/** * Checks if a sender has a given permission. * @param sender the sender to check permissions of * @param permission the CommandAPI CommandPermission permission to check * @return true if the sender satisfies the provided permission */ private boolean permissionCheck(CommandSender sender, CommandPermission permission) { if (sender == null) { return true; } if (permission.equals(CommandPermission.NONE)) { return true; } else if (permission.equals(CommandPermission.OP)) { return sender.isOp(); } else { return sender.hasPermission(permission.getPermission()); } }
Example 9
Source File: DebugFishCommand.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@Override public void onExecute(CommandSender sender, String[] args) { if (sender instanceof Player && sender.isOp()) { ((Player) sender).getInventory().addItem(SlimefunItems.DEBUG_FISH); } else { SlimefunPlugin.getLocalization().sendMessage(sender, "messages.no-permission", true); } }
Example 10
Source File: ResidentCommand.java From civcraft with GNU General Public License v2.0 | 5 votes |
public static void show(CommandSender sender, Resident resident) { CivMessage.sendHeading(sender, "Resident "+resident.getName()); Date lastOnline = new Date(resident.getLastOnline()); SimpleDateFormat sdf = new SimpleDateFormat("M/dd/yy h:mm:ss a z"); CivMessage.send(sender, CivColor.Green+"Last Online:"+CivColor.LightGreen+sdf.format(lastOnline)); CivMessage.send(sender, CivColor.Green+"Town: "+CivColor.LightGreen+resident.getTownString()); CivMessage.send(sender, CivColor.Green+"Camp: "+CivColor.LightGreen+resident.getCampString()); if (sender.getName().equalsIgnoreCase(resident.getName()) || sender.isOp()) { CivMessage.send(sender, CivColor.Green+"Personal Treasury: "+CivColor.LightGreen+resident.getTreasury().getBalance()+" "+ CivColor.Green+"Taxes Owed: "+CivColor.LightGreen+(resident.getPropertyTaxOwed()+resident.getFlatTaxOwed())); if (resident.hasTown()) { if (resident.getSelectedTown() != null) { CivMessage.send(sender, CivColor.Green+"Selected Town: "+CivColor.LightGreen+resident.getSelectedTown().getName()); } else { CivMessage.send(sender, CivColor.Green+"Selected Town: "+CivColor.LightGreen+resident.getTown().getName()); } } } if (resident.getTreasury().inDebt()) { CivMessage.send(resident, CivColor.Yellow+"In Debt "+resident.getTreasury().getDebt()+" coins!"); } if (resident.getDaysTilEvict() > 0) { CivMessage.send(resident, CivColor.Yellow+"Eviction in "+resident.getDaysTilEvict()+" days."); } CivMessage.send(sender, CivColor.Green+"Groups: "+resident.getGroupsString()); try { if (resident.isUsesAntiCheat()) { CivMessage.send(sender, CivColor.LightGreen+"Online and currently using CivCraft's Anti-Cheat"); } else { CivMessage.send(sender, CivColor.Rose+"Online but NOT validated by CivCraft's Anti-Cheat"); } } catch (CivException e) { CivMessage.send(sender, CivColor.LightGray+"Resident is not currently online."); } }
Example 11
Source File: IslandLogic.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
public void showTopTen(final CommandSender sender, final int page) { long t = System.currentTimeMillis(); if (t > (lastGenerate + (Settings.island_topTenTimeout*60000)) || (sender.hasPermission("usb.admin.topten") || sender.isOp())) { lastGenerate = t; plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> { generateTopTen(sender); displayTopTen(sender, page); }); } else { displayTopTen(sender, page); } }
Example 12
Source File: BukkitCommand.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { final FawePlayer plr = Fawe.imp().wrap(sender); if (!sender.hasPermission(this.cmd.getPerm()) && !sender.isOp()) { BBC.NO_PERM.send(plr, this.cmd.getPerm()); return true; } this.cmd.executeSafe(plr, args); return true; }
Example 13
Source File: CommandHandler.java From NyaaUtils with MIT License | 5 votes |
@SubCommand(value = "vote", permission = "nu.vote") public void vote(CommandSender sender, Arguments args) { if (!plugin.cfg.vote_enable) { return; } if (plugin.voteTask != null && plugin.voteTask.ticks < plugin.voteTask.timeout) { if (args.length() == 2) { if (sender.isOp() && "STOP".equalsIgnoreCase(args.top())) { plugin.voteTask.ticks = plugin.voteTask.timeout + 1; plugin.voteTask.cancel(); return; } plugin.voteTask.vote(asPlayer(sender), args.nextInt()); } } else { if (args.length() < 4) { throw new BadCommandException("user.vote.need_options"); } String subject = args.nextString(); Set<String> options = new HashSet<>(); for (int i = 0; i < plugin.cfg.vote_max_options; i++) { String option = args.top(); if (option != null && option.length() > 0) { options.add(args.nextString()); } else { break; } } plugin.voteTask = new VoteTask(subject, plugin.cfg.vote_timeout, plugin.cfg.vote_broadcast_interval, options); plugin.voteTask.runTaskTimer(plugin, 1, 1); } }
Example 14
Source File: DelArena.java From Survival-Games with GNU General Public License v3.0 | 5 votes |
public boolean onCommand(CommandSender sender, String[] args) { if (!sender.hasPermission(permission()) && !sender.isOp()){ MessageManager.getInstance().sendFMessage(PrefixType.ERROR, "error.nopermission", sender); return true; } if(args.length != 1){ MessageManager.getInstance().sendFMessage(PrefixType.ERROR, "error.notspecified", sender, "input-Arena"); return true; } FileConfiguration s = SettingsManager.getInstance().getSystemConfig(); //FileConfiguration spawn = SettingsManager.getInstance().getSpawns(); int arena = Integer.parseInt(args[0]); Game g = GameManager.getInstance().getGame(arena); if(g == null){ MessageManager.getInstance().sendFMessage(PrefixType.ERROR, "error.gamedoesntexist", sender, "arena-" + arena); return true; } g.disable(); s.set("sg-system.arenas."+arena+".enabled", false); s.set("sg-system.arenano", s.getInt("sg-system.arenano") - 1); //spawn.set("spawns."+arena, null); MessageManager.getInstance().sendFMessage(PrefixType.INFO, "info.deleted", sender, "input-Arena"); SettingsManager.getInstance().saveSystemConfig(); GameManager.getInstance().hotRemoveArena(arena); //LobbyManager.getInstance().clearAllSigns(); LobbyManager.getInstance().removeSignsForArena(arena); return true; }
Example 15
Source File: PunishmentCommands.java From CardinalPGM with MIT License | 5 votes |
@Command(aliases = {"kick", "k"}, desc = "Kick a player.", usage = "<player> [reason]", min = 1) @CommandPermissions("cardinal.punish.kick") public static void kick(CommandContext cmd, CommandSender sender) throws CommandException { Player kicked = Bukkit.getPlayer(cmd.getString(0)); if (kicked == null) { throw new CommandException(ChatConstant.ERROR_PLAYER_NOT_FOUND.getMessage(ChatUtil.getLocale(sender))); } if (!sender.isOp() && kicked.isOp()) { throw new CommandException(ChatConstant.ERROR_PLAYER_NOT_AFFECTED.getMessage(ChatUtil.getLocale(sender))); } String reason = cmd.argsLength() > 1 ? cmd.getJoinedStrings(1) : "You have been kicked!"; Bukkit.broadcastMessage(Players.getName(sender) + ChatColor.GOLD + " \u00BB Kicked \u00BB " + Players.getName(kicked) + ChatColor.GOLD + " \u00BB " + reason); kicked.kickPlayer(ChatColor.RED + "Kicked" + ChatColor.GOLD + " \u00BB " + ChatColor.AQUA + reason); }
Example 16
Source File: ItemsPasteCommand.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
@Override public boolean execute(final CommandSender sender, ArrayList<String> args) { if (!super.hasPermission(sender) && !sender.isOp()) { return false; } if (!(sender instanceof Player)) { return false; } final Player player = (Player) sender; BedwarsRel.getInstance().getServer().getScheduler() .runTaskAsynchronously(BedwarsRel.getInstance(), new Runnable() { @Override public void run() { try { ItemStack[] playerItems = player.getInventory().getContents(); String uploadConfigFile; ArrayList<Map<String, Object>> itemsList = new ArrayList<>(); for (ItemStack item : playerItems) { if (item == null) { continue; } itemsList.add(item.serialize()); } YamlConfiguration uploadConfig = new YamlConfiguration(); uploadConfig.set("sampleItems", itemsList); StringBuilder b = new StringBuilder(); b.append( "# Welcome to this paste\n# This might help you to better add your custom items to BedwarsRel's shop.yml\n\n"); b.append(uploadConfig.saveToString()); b.append("\n"); b.append( "\n# This is not a working shop - it's just a list of items you can add to your shop!"); String link = HastebinUtility.upload(b.toString()); sender.sendMessage(ChatWriter .pluginMessage(ChatColor.GREEN + "Success! Items pasted on " + link)); } catch (IOException e) { e.printStackTrace(); } } }); return true; }
Example 17
Source File: DefaultUpdateCallback.java From Thermos with GNU General Public License v3.0 | 4 votes |
private boolean hasPermission(CommandSender player) { return player.hasPermission(ThermosCommand.UPDATE) || player.isOp(); }
Example 18
Source File: HelpCommand.java From Statz with GNU General Public License v3.0 | 4 votes |
private void showHelpPages(final CommandSender sender, int page) { List<StatzCommand> commands = new ArrayList<StatzCommand>( plugin.getCommandsManager().getRegisteredCommands().values()); // Create a new list that will be new commands list. This is done so statz automatically adjusts help pages. // If sender is OP then all commands are available, no need to refactor. if (!sender.isOp()) { final List<StatzCommand> newList = new ArrayList<StatzCommand>(); for (final StatzCommand cmd : commands) { // Check if player has permission to do this, before presenting this command if (cmd.getPermission() != null && sender.hasPermission(cmd.getPermission())) { newList.add(cmd); } } commands = newList; } final int listSize = commands.size(); // Don't show more than 6 commands per page // (Does she want the D?) final int maxPages = (int) Math.ceil(listSize / 6D); if (page > maxPages || page == 0) page = maxPages; int start = 0; int end = 6; if (page != 1) { final int pageDifference = page - 1; // Because we need 7, not 6. start += 1; start += (6 * pageDifference); end = start + 6; } sender.sendMessage(ChatColor.GREEN + "-- Statz Commands --"); for (int i = start; i < end; i++) { // Can't go any further if (i >= listSize) break; final StatzCommand command = commands.get(i); sender.sendMessage(ChatColor.AQUA + command.getUsage() + ChatColor.GRAY + " - " + command.getDescription()); } sender.sendMessage(Lang.PAGE_INDEX.getConfigValue(page, maxPages)); }
Example 19
Source File: CommandParticle.java From Carbon with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { Location location = null; boolean color = false; if (sender instanceof Player) { if (!sender.isOp()) { return false; } location = ((Player) sender).getLocation(); color = true; } else if (sender instanceof BlockCommandSender) { location = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5D, 0.5D, 0.5D); } else { sender.sendMessage("This command needs to be sent by an ingame command executor."); return true; } if (args.length >= 8) { String name = args[0]; String x = args[1]; String y = args[2]; String z = args[3]; Location finalLocation = getLocation(sender, color, location, x, y, z); String xd = args[4]; String yd = args[5]; String zd = args[6]; String speed = args[7]; String amount = args.length > 8 ? args[8] : "1"; float fXd = parseFloat(sender, color, xd); float fYd = parseFloat(sender, color, yd); float fZd = parseFloat(sender, color, zd); float fSpeed = parseFloat(sender, color, speed); int iAmount = parseInt(sender, color, amount); if (fXd != -1.0F && fYd != -1.0F && fZd != -1.0F && iAmount != -1) { try { ParticleEffect.fromName(name).display(fXd, fYd, fZd, fSpeed, iAmount, finalLocation, 32.0D); return true; } catch (Exception ex) { if (color) { sender.sendMessage("" + ChatColor.RED + "An internal error occurred while attempting to perform this command"); } else { sender.sendMessage("An internal error occurred while attempting to perform this command"); } } } } return false; }
Example 20
Source File: CommandTitle.java From Carbon with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { if (sender instanceof Player) { if (!sender.isOp()) { return false; } } if (args.length < 1) { sender.sendMessage(ChatColor.RED + "Usage: /title <player> <title|subtitle|clear|reset|times> ..."); return true; } ArrayList<Player> targets = new ArrayList<Player>(); if (args[0].equalsIgnoreCase("@a")) { targets.addAll(Bukkit.getOnlinePlayers()); } Player player = getOnlinePlayer(args[0]); if (player == null && targets.isEmpty()) { sender.sendMessage(ChatColor.RED + args[0] + " is not a valid player or is offline."); return true; } targets.add(player); for (Player target : targets) { if (args[1].equalsIgnoreCase("times")) { int fadeIn, stay, fadeOut; if (args.length < 5) { sender.sendMessage(ChatColor.RED + "Usage: /title <player> times <fadeIn> <stay> <fadeOut>"); return true; } if (isInteger(args[2])) { fadeIn = Integer.parseInt(args[2]); } else { sender.sendMessage(ChatColor.RED + args[2] + " is not a valid number"); return true; } if (isInteger(args[3])) { stay = Integer.parseInt(args[3]); } else { sender.sendMessage(ChatColor.RED + args[3] + " is not a valid number"); return true; } if (isInteger(args[4])) { fadeOut = Integer.parseInt(args[4]); } else { sender.sendMessage(ChatColor.RED + args[4] + " is not a valid number"); return true; } sendTimes(fadeIn, stay, fadeOut, target); sender.sendMessage(ChatColor.GREEN + "Title command successfully executed"); } else if (args[1].equalsIgnoreCase("title")) { if (args.length < 3) { sender.sendMessage(ChatColor.RED + "Usage: /title <player> title <raw json title|text>"); return true; } sendTitle(args, 2, target); sender.sendMessage(ChatColor.GREEN + "Title command successfully executed"); } else if (args[1].equalsIgnoreCase("subtitle")) { if (args.length < 3) { sender.sendMessage(ChatColor.RED + "Usage: /title <player> subtitle <raw json title|text>"); return true; } sendSubtitle(args, 2, target); sender.sendMessage(ChatColor.GREEN + "Title command successfully executed"); } else if (args[1].equalsIgnoreCase("clear")) { //sendTimes(0,0,0,player); sendClear(target); sender.sendMessage(ChatColor.GREEN + "Title command successfully executed"); } else if (args[1].equalsIgnoreCase("reset")) { sendReset(target); sender.sendMessage(ChatColor.GREEN + "Title command successfully executed"); } } return true; }