Java Code Examples for org.bukkit.command.CommandSender#hasPermission()

The following examples show how to use org.bukkit.command.CommandSender#hasPermission() . 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: VanillaCommandWrapper.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public static int dispatch(CommandSender sender, String commandLine)
{
    int pos = commandLine.indexOf( ' ' );
    if ( pos == -1 )
    {
        pos = commandLine.length();
    }
    String name = commandLine.substring( 0, pos );
    if ( !allowedCommands.contains( name ) )
    {
        return -1;
    }
    if ( !sender.hasPermission( "bukkit.command." + name ) )
    {
        sender.sendMessage( ChatColor.RED + "You do not have permission for this command" );
        return 0;
    }
    net.minecraft.command.ICommandSender listener = getListener( sender );
    if ( listener == null )
    {
        return -1;
    }
    return net.minecraft.server.MinecraftServer.getServer().getCommandManager().executeCommand( listener, commandLine );
}
 
Example 2
Source File: CommandHandler.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
	if (!sender.hasPermission("protocolsupport.admin")) {
		sender.sendMessage(ChatColor.DARK_RED + "You have no power here!");
		return true;
	}
	if (args.length == 0) {
		sender.sendMessage(ChatColor.DARK_PURPLE + "ProtocolSupportPocketStuff");
		sender.sendMessage(ChatColor.GRAY + "/psps reloadpacks");
		sender.sendMessage(ChatColor.GRAY + "/psps pocketinfo");
		sender.sendMessage(ChatColor.GRAY + "/psps skinz");
		return true;
	}
	SubCommand subcommand = subcommands.get(args[0]);
	if (subcommand == null) {
		return false;
	}
	String[] subcommandargs = Arrays.copyOfRange(args, 1, args.length);
	if (subcommandargs.length < subcommand.getMinArgs()) {
		sender.sendMessage(ChatColor.DARK_RED + "Not enough args");
		return true;
	}
	return subcommand.handle(sender, subcommandargs);
}
 
Example 3
Source File: InvalidateCommand.java    From ChangeSkin with MIT License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (plugin.isBungeeCord()) {
        onBungeeCord(sender, command.getName(), args);
        return true;
    }

    if (args.length > 0) {
        Player targetPlayer = Bukkit.getPlayerExact(args[0]);
        if (targetPlayer == null) {
            plugin.sendMessage(sender, "not-online");
            return true;
        }

        String permPrefix = plugin.getName().toLowerCase() + ".command.skinupdate.other.";
        if (!sender.hasPermission(permPrefix + targetPlayer.getUniqueId())
                && !sender.hasPermission(permPrefix + '*')) {
            plugin.sendMessage(sender, "no-permission-other");
            return true;
        }

        Runnable skinInvalidate = new SkinInvalidator(plugin, sender, targetPlayer);
        Bukkit.getScheduler().runTaskAsynchronously(plugin, skinInvalidate);
        return true;
    }

    if (!(sender instanceof Player)) {
        plugin.sendMessage(sender, "no-console");
        return true;
    }

    Player receiver = (Player) sender;
    Bukkit.getScheduler().runTaskAsynchronously(plugin, new SkinInvalidator(plugin, sender, receiver));
    return true;
}
 
Example 4
Source File: CommandCombatLogX.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private boolean checkNoPermission(CommandSender sender, String permission) {
    if(sender.hasPermission(permission)) return false;

    String message = this.plugin.getLanguageMessageColoredWithPrefix("errors.no-permission").replace("{permission}", permission);
    this.plugin.sendMessage(sender, message);
    return true;
}
 
Example 5
Source File: NoDatabaseWorker.java    From MarriageMaster with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command cmd, @NotNull String s, String[] strings)
{
	if(strings.length != 1 || !strings[0].equalsIgnoreCase("reload"))
	{
		commandSender.sendMessage(MessageColor.RED + "Only \"/marry reload\" is available at the moment!");
	}
	else
	{
		if(commandSender.hasPermission(Permissions.RELOAD))
		{
			command.unregisterCommand();
			HandlerList.unregisterAll(this);
			try
			{
				plugin.getConfiguration().reload();
				Reflection.getMethod(plugin.getClass(), "load").invoke(plugin);
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
		else
		{
			commandSender.sendMessage(MessageColor.RED + "You don't have the permission to do that!");
		}
	}
	return true;
}
 
Example 6
Source File: RegionNameCommand.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, ArrayList<String> args) {
  if (!sender.hasPermission("bw." + this.getPermission())) {
    return false;
  }

  Player player = (Player) sender;

  Game game = this.getPlugin().getGameManager().getGame(args.get(0));
  String name = args.get(1).toString();

  if (game == null) {
    player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
        + BedwarsRel
        ._l(sender, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
    return false;
  }

  if (game.getState() == GameState.RUNNING) {
    sender.sendMessage(
        ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
            ._l(sender, "errors.notwhilegamerunning")));
    return false;
  }

  if (name.length() > 15) {
    player.sendMessage(
        ChatWriter
            .pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.toolongregionname")));
    return true;
  }

  game.setRegionName(name);
  player
      .sendMessage(
          ChatWriter
              .pluginMessage(ChatColor.GREEN + BedwarsRel._l(player, "success.regionnameset")));
  return true;
}
 
Example 7
Source File: CheatCommand.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onExecute(CommandSender sender, String[] args) {
    if (sender instanceof Player) {
        if (sender.hasPermission("slimefun.cheat.items")) {
            SlimefunGuide.openCheatMenu((Player) sender);
        }
        else {
            SlimefunPlugin.getLocalization().sendMessage(sender, "messages.no-permission", true);
        }
    }
    else {
        SlimefunPlugin.getLocalization().sendMessage(sender, "messages.only-players", true);
    }
}
 
Example 8
Source File: IslandLogic.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
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 9
Source File: RemoveGameCommand.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, ArrayList<String> args) {
  if (!sender.hasPermission("bw." + this.getPermission())) {
    return false;
  }

  Game game = this.getPlugin().getGameManager().getGame(args.get(0));

  if (game == null) {
    sender.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
        + BedwarsRel
        ._l(sender, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
    return false;
  }

  if (game.getState() == GameState.RUNNING) {
    sender.sendMessage(
        ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
            ._l(sender, "errors.notwhilegamerunning")));
    return false;
  }

  BedwarsRel.getInstance().getGameManager().unloadGame(game);
  BedwarsRel.getInstance().getGameManager().removeGame(game);
  sender.sendMessage(
      ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel._l(sender, "success.gameremoved")));
  return true;
}
 
Example 10
Source File: MailboxCommands.java    From NyaaUtils with MIT License 5 votes vote down vote up
@SubCommand(value = "create", permission = "nu.mailbox")
public void createMailbox(CommandSender sender, Arguments args) {
    Player p = asPlayer(sender);
    String tmp = args.top();
    if (tmp != null) {
        if (sender.hasPermission("nu.mailadmin")) {
            createMailbox(p, args.nextOfflinePlayer());
        } else {
            msg(sender, "user.mailbox.permission_required");
        }
        return;
    }
    if (plugin.cfg.mailbox.getMailboxLocation(p.getUniqueId()) != null) {
        msg(p, "user.mailbox.already_set");
        return;
    }
    plugin.mailboxListener.registerRightClickCallback(p, 100,
            (Location clickedBlock) -> {
                Block b = clickedBlock.getBlock();
                if (b.getState() instanceof Chest) {
                    plugin.cfg.mailbox.updateLocationMapping(p.getUniqueId(), b.getLocation());
                    msg(p, "user.mailbox.set_success");
                    return;
                }
                msg(p, "user.mailbox.set_fail");
            });
    msg(p, "user.mailbox.now_right_click");
}
 
Example 11
Source File: CommandWesv.java    From WorldEditSelectionVisualizer with MIT License 5 votes vote down vote up
private void sendUsage(CommandSender sender) {
    String version = plugin.getDescription().getVersion();
    sender.sendMessage(ChatUtils.color("&6WorldEditSelectionVisualizer v" + version + "&7 by &6MrMicky&7."));

    if (sender instanceof Player) {
        sender.sendMessage(ChatUtils.color("&7- /wesv toggle"));
        sender.sendMessage(ChatUtils.color("&7- /wesv toggle clipboard"));
    }

    if (sender.hasPermission("wesv.reload")) {
        sender.sendMessage(ChatUtils.color("&7- /wesv reload"));
    }
}
 
Example 12
Source File: GroupinfoCommand.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getHelp(CommandSender target) {
	if(target.hasPermission("areashop.groupinfo")) {
		return "help-groupinfo";
	}
	return null;
}
 
Example 13
Source File: SellCommand.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getHelp(CommandSender target) {
	if(target.hasPermission("areashop.sell") || target.hasPermission("areashop.sellown")) {
		return "help-sell";
	}
	return null;
}
 
Example 14
Source File: StopresellCommand.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getHelp(CommandSender target) {
	if(target.hasPermission("areashop.stopresellall") || target.hasPermission("areashop.stopresell")) {
		return "help-stopResell";
	}
	return null;
}
 
Example 15
Source File: OpenCommand.java    From Minepacks with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<String> tabComplete(@NotNull CommandSender commandSender, @NotNull String mainCommandAlias, @NotNull String alias, @NotNull String[] args)
{
	if(args.length > 0 && (!(commandSender instanceof Player) || commandSender.hasPermission(Permissions.OTHERS)))
	{
		return Utils.getPlayerNamesStartingWith(args[args.length - 1], commandSender);
	}
	return null;
}
 
Example 16
Source File: DestroyableCommands.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
private void assertEditPerms(CommandSender sender) throws CommandException {
    if(!sender.hasPermission("pgm.destroyable.edit")) {
        throw new CommandException("You don't have permission to do that");
    }
}
 
Example 17
Source File: SetdurationCommand.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void execute(CommandSender sender, String[] args) {
	if(!sender.hasPermission("areashop.setduration") && (!sender.hasPermission("areashop.setduration.landlord") && sender instanceof Player)) {
		plugin.message(sender, "setduration-noPermission");
		return;
	}
	if(args.length < 3 || args[1] == null || args[2] == null) {
		plugin.message(sender, "setduration-help");
		return;
	}
	int regionArgument = 3;
	if(args.length >= 2 && ("default".equalsIgnoreCase(args[1]) || "reset".equalsIgnoreCase(args[1]))) {
		regionArgument = 2;
	}
	RentRegion rent;
	if(args.length <= regionArgument) {
		if(sender instanceof Player) {
			// get the region by location
			List<RentRegion> regions = Utils.getImportantRentRegions(((Player)sender).getLocation());
			if(regions.isEmpty()) {
				plugin.message(sender, "cmd-noRegionsAtLocation");
				return;
			} else if(regions.size() > 1) {
				plugin.message(sender, "cmd-moreRegionsAtLocation");
				return;
			} else {
				rent = regions.get(0);
			}
		} else {
			plugin.message(sender, "cmd-automaticRegionOnlyByPlayer");
			return;
		}
	} else {
		rent = plugin.getFileManager().getRent(args[regionArgument]);
	}
	if(rent == null) {
		plugin.message(sender, "setduration-notRegistered", args[regionArgument]);
		return;
	}
	if(!sender.hasPermission("areashop.setduration") && !(sender instanceof Player && rent.isLandlord(((Player)sender).getUniqueId()))) {
		plugin.message(sender, "setduration-noLandlord", rent);
		return;
	}
	if("default".equalsIgnoreCase(args[1]) || "reset".equalsIgnoreCase(args[1])) {
		rent.setDuration(null);
		rent.update();
		plugin.message(sender, "setduration-successRemoved", rent);
		return;
	}
	try {
		Integer.parseInt(args[1]);
	} catch(NumberFormatException e) {
		plugin.message(sender, "setduration-wrongAmount", args[1], rent);
		return;
	}
	if(!Utils.checkTimeFormat(args[1] + " " + args[2])) {
		plugin.message(sender, "setduration-wrongFormat", args[1] + " " + args[2], rent);
		return;
	}
	rent.setDuration(args[1] + " " + args[2]);
	rent.update();
	plugin.message(sender, "setduration-success", rent);
}
 
Example 18
Source File: BaseSubCommand.java    From TabooLib with MIT License 4 votes vote down vote up
public boolean hasPermission(CommandSender sender) {
    return Strings.isBlank(getPermission()) || sender.hasPermission(getPermission());
}
 
Example 19
Source File: HologramSubCommand.java    From HolographicDisplays with GNU General Public License v3.0 4 votes vote down vote up
public final boolean hasPermission(CommandSender sender) {
	if (permission == null) return true;
	return sender.hasPermission(permission);
}
 
Example 20
Source File: ClassCommands.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Command(
    aliases = { "class", "selectclass", "c", "cl" },
    desc = "Selects or views the player class",
    min = 0,
    max = -1
)
@CommandPermissions("pgm.class")
public void selectclass(CommandContext args, CommandSender sender) throws CommandException {
    ClassMatchModule classModule = getClassModule(sender);

    MatchPlayer player = CommandUtils.senderToMatchPlayer(sender);
    final User user = userStore.getUser(player.getBukkit());
    PlayerClass cls = classModule.selectedClass(user);

    if(args.argsLength() == 0) {
        // show current class
        sender.sendMessage(ChatColor.GREEN + PGMTranslations.t("command.class.view.currentClass", player) + " " + ChatColor.GOLD + ChatColor.UNDERLINE + cls.getName());
        sender.sendMessage(ChatColor.DARK_PURPLE + PGMTranslations.t("command.class.view.list", player).replace("'/classes'", ChatColor.GOLD + "'/classes'" + ChatColor.DARK_PURPLE));
    } else {
        if(!sender.hasPermission("pgm.class.select")) {
            throw new CommandPermissionsException();
        }

        String search = args.getJoinedStrings(0);
        PlayerClass result = StringUtils.bestFuzzyMatch(search, classModule.getClasses(), 0.9);
        if(result == null) {
            throw new CommandException(PGMTranslations.t("command.class.select.classNotFound", player));
        }

        if(!cls.canUse(player.getBukkit())) {
            throw new CommandException(PGMTranslations.t("command.class.restricted", player, ChatColor.GOLD, result.getName(), ChatColor.RED));
        }

        try {
            classModule.setPlayerClass(user, result);
        } catch (IllegalStateException e) {
            throw new CommandException(PGMTranslations.t("command.class.stickyClass", player));
        }

        sender.sendMessage(ChatColor.GREEN + PGMTranslations.t("command.class.select.confirm", player, ChatColor.GOLD.toString() + ChatColor.UNDERLINE + result.getName() + ChatColor.GREEN));
        if(player.isParticipating()) {
            sender.sendMessage(ChatColor.GREEN + PGMTranslations.t("command.class.select.nextSpawn", player));
        }
    }
}