Java Code Examples for org.bukkit.entity.Player#hasPermission()
The following examples show how to use
org.bukkit.entity.Player#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: Refill.java From Survival-Games with GNU General Public License v3.0 | 6 votes |
public boolean onCommand(Player player, String[] args) { if (!player.hasPermission(permission()) && !player.isOp()) { MessageManager.getInstance().sendFMessage(PrefixType.ERROR, "error.nopermission", player); return true; } int game = -1; if(args.length >= 1){ game = Integer.parseInt(args[0]); } else game = GameManager.getInstance().getPlayerGameId(player); if(game == -1){ MessageManager.getInstance().sendFMessage(PrefixType.ERROR, "error.notingame", player); return true; } QueueManager.getInstance().restockChests(game); msgmgr.sendFMessage(PrefixType.INFO, "game.refill", player, "arena-" + game); return true; }
Example 2
Source File: UpdateChecker.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); if (player.hasPermission(BaseCommand.ADMIN_PERMISSION)) { if (Main.getConfigurator().config.getBoolean("update-checker.zero.admins") && result.isUpdateAvailable) { mpr("update_checker_zero").replace("version", result.currentZeroVersion).send(player); mpr("update_checker_zero_second").replace("url", result.download).send(player); } if (Main.getConfigurator().config.getBoolean("update-checker.one.admins") && result.isOneAvailable) { mpr("update_checker_one").replace("url", result.oneWebsite).send(player); if (javaVer < 55.0F) { mpr("update_checker_one_second_bad").send(player); } else { mpr("update_checker_one_second_good").send(player); } } } }
Example 3
Source File: InventoryBlock.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
default void createPreset(SlimefunItem item, String title, Consumer<BlockMenuPreset> setup) { new BlockMenuPreset(item.getID(), title) { @Override public void init() { setup.accept(this); } @Override public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) { if (flow == ItemTransportFlow.INSERT) return getInputSlots(); else return getOutputSlots(); } @Override public boolean canOpen(Block b, Player p) { return p.hasPermission("slimefun.inventory.bypass") || (SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES) && Slimefun.hasUnlocked(p, item, false)); } }; }
Example 4
Source File: GroupManager.java From NovaGuilds with GNU General Public License v3.0 | 6 votes |
/** * Gets the group of a player * * @param player player * @return the group */ public static NovaGroup getGroup(Player player) { Map<String, NovaGroup> groups = plugin.getGroupManager().getGroups(); String groupName = "default"; if(player == null) { return getGroup(groupName); } if(player.hasPermission("novaguilds.group.admin")) { return getGroup("admin"); } for(String name : groups.keySet()) { if(player.hasPermission("novaguilds.group." + name) && !name.equalsIgnoreCase("default")) { groupName = name; break; } } return getGroup(groupName); }
Example 5
Source File: Utils.java From ShopChest with MIT License | 5 votes |
private static boolean hasPermissionToCreateShop(Player player, ItemStack item, String... permissions) { for (String permission : permissions) { boolean b1 = false; boolean b2 = false; boolean b3 = false; if (player.hasPermission(permission)) { b1 = true; } if (item != null) { if (item.getDurability() == 0) { String perm1 = permission + "." + item.getType().toString(); String perm2 = permission + "." + item.getType().toString() + ".0"; if (player.hasPermission(perm1) || player.hasPermission(perm2)) { b2 = true; } } if (player.hasPermission(permission + "." + item.getType().toString() + "." + item.getDurability())) { b3 = true; } } if (!(b1 || b2 || b3)) { return false; } } return true; }
Example 6
Source File: PermissionHandler.java From StaffPlus with GNU General Public License v3.0 | 5 votes |
public boolean has(Player player, String permission) { boolean hasPermission = false; if(player != null) { hasPermission = player.hasPermission(permission) || isOp(player); } return hasPermission; }
Example 7
Source File: WorldGuard7FAWEHook.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean canBuild_i(final Player p, final Location l) { if (p.hasPermission("worldguard.region.bypass." + l.getWorld().getName())) return true; RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery(); LocalPlayer player = WorldGuardPlugin.inst().wrapPlayer(p); return query.testState(BukkitAdapter.adapt(l), player, Flags.BUILD); }
Example 8
Source File: GriefEvents.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onShearEvent(PlayerShearEntityEvent event) { Player player = event.getPlayer(); if (!shearingEnabled || !plugin.getWorldManager().isSkyAssociatedWorld(player.getWorld())) { return; // Not our concern } if (player.hasPermission("usb.mod.bypassprotection")) { return; } if (!plugin.playerIsOnIsland(player)) { event.setCancelled(true); } }
Example 9
Source File: QPlayer.java From Quests with MIT License | 5 votes |
/** * @return 0 if success, 1 if no permission, 2 is only data loaded, 3 if player not found */ public int openCategory(Category category, QMenuCategory superMenu, boolean backButton) { if (onlyDataLoaded) { return 2; } Player player = Bukkit.getPlayer(this.uuid); if (player == null) { return 3; } if (category.isPermissionRequired() && !player.hasPermission("quests.category." + category.getId())) { return 1; } // Using `this` instead of searching again for this QPlayer QMenuQuest qMenuQuest = new QMenuQuest(this, category.getId(), superMenu); List<Quest> quests = new ArrayList<>(); for (String questid : category.getRegisteredQuestIds()) { Quest quest = plugin.getQuestManager().getQuestById(questid); if (quest != null) { quests.add(quest); } } qMenuQuest.populate(quests); qMenuQuest.setBackButtonEnabled(backButton); return openCategory(category, qMenuQuest); }
Example 10
Source File: XPMain.java From AnnihilationPro with MIT License | 5 votes |
public static int checkMultipliers(Player player, int initialXP) { if(perms.size() > 0) { for(Perm p : perms) { if(player.hasPermission(p.perm)) { initialXP = (int)Math.ceil(((double)initialXP)*p.multiplier); break; } } } return initialXP; }
Example 11
Source File: LevelCommand.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
public boolean getIslandLevel(final Player player, final String islandPlayer, final String cmd) { final PlayerInfo info = plugin.getPlayerInfo(islandPlayer); if (info == null || !info.getHasIsland()) { player.sendMessage(tr("\u00a74That player is invalid or does not have an island!")); return false; } final us.talabrek.ultimateskyblock.api.IslandInfo islandInfo = plugin.getIslandInfo(info); if (islandInfo == null || islandInfo.getIslandLocation() == null) { player.sendMessage(tr("\u00a74That player is invalid or does not have an island!")); return false; } final boolean shouldRecalculate = player.getName().equals(info.getPlayerName()) || player.hasPermission("usb.admin.island"); final Runnable showInfo = () -> { if (player != null && player.isOnline() && info != null) { player.sendMessage(tr("\u00a7eInformation about {0}''s Island:", islandPlayer)); if (cmd.equalsIgnoreCase("level")) { IslandRank rank = plugin.getIslandLogic().getRank(info.locationForParty()); if (rank != null) { player.sendMessage(new String[]{ tr("\u00a7aIsland level is {0,number,###.##}", rank.getScore()), tr("\u00a79Rank is {0}", rank.getRank()) }); } else { player.sendMessage(tr("\u00a74Could not locate rank of {0}", islandPlayer)); } } } }; if (shouldRecalculate) { plugin.getServer().getScheduler().runTaskLater(plugin, () -> plugin.calculateScoreAsync(player, info.locationForParty(), new Callback<us.talabrek.ultimateskyblock.api.model.IslandScore>() { @Override public void run() { plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, showInfo, 10L); } }), 1L); } else { showInfo.run(); } return true; }
Example 12
Source File: GUIManager.java From Hawk with GNU General Public License v3.0 | 5 votes |
@EventHandler public void clickEvent(InventoryClickEvent e) { if (!(e.getWhoClicked() instanceof Player)) return; Player p = (Player) e.getWhoClicked(); if (!activeWindows.containsKey(p.getUniqueId()) || activeWindows.get(p.getUniqueId()) == null) return; if (!activeWindows.get(p.getUniqueId()).getInventory().equals(e.getClickedInventory())) return; e.setCancelled(true); String perm = Hawk.BASE_PERMISSION + ".gui"; if (!p.hasPermission(perm)) { p.sendMessage(String.format(Hawk.NO_PERMISSION, perm)); p.closeInventory(); return; } Window window = activeWindows.get(p.getUniqueId()); int clickedLoc = e.getRawSlot(); for (int i = 0; i < window.getElements().length; i++) { if (i == clickedLoc) { Element element = window.getElements()[i]; if(element == null) break; element.doAction(p, hawk); break; } } }
Example 13
Source File: Prize.java From Crazy-Crates with MIT License | 5 votes |
/** * @return Returns true if they prize has blacklist permissions and false if not. */ public boolean hasBlacklistPermission(Player player) { if (!player.isOp()) { for (String blackListPermission : blackListPermissions) { if (player.hasPermission(blackListPermission)) { return true; } } } return false; }
Example 14
Source File: PlayerChatListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority=EventPriority.HIGH) public void onPlayerChat(AsyncPlayerChatEvent e){ Player player = e.getPlayer(); GameManager gm = GameManager.getGameManager(); MainConfiguration cfg = gm.getConfiguration(); if (e.isCancelled()){ return; } UhcPlayer uhcPlayer = gm.getPlayersManager().getUhcPlayer(player); // Spec chat if(!cfg.getCanSendMessagesAfterDeath() && uhcPlayer.getState() == PlayerState.DEAD){ // check if has override permissions if (player.hasPermission("uhc-core.chat.override")) return; // Send message in spec chat. String message = Lang.DISPLAY_SPECTATOR_CHAT .replace("%player%", player.getDisplayName()) .replace("%message%", e.getMessage()); gm.getPlayersManager().getOnlineSpectatingPlayers().forEach(p -> p.sendMessage(message)); e.setCancelled(true); return; } // Team chat if ( uhcPlayer.getState() == PlayerState.PLAYING && isTeamMessage(cfg, e, uhcPlayer) ){ e.setCancelled(true); uhcPlayer.getTeam().sendChatMessageToTeamMembers(uhcPlayer, e.getMessage()); } }
Example 15
Source File: HelpCommand.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
@Override public void execute(CommandSender cs, String[] args) { Player p = (Player) cs; int page = 1; if (args.length == 2) { try { page = Integer.parseInt(args[1]); } catch (NumberFormatException e) { return; } } int maxpage = (int) Math.ceil(IridiumSkyblock.getCommandManager().commands.size() / 18.00); int current = 0; p.sendMessage(Utils.color(IridiumSkyblock.getMessages().helpHeader)); for (com.iridium.iridiumskyblock.commands.Command command : IridiumSkyblock.getCommandManager().commands) { if ((p.hasPermission(command.getPermission()) || command.getPermission().equalsIgnoreCase("") || command.getPermission().equalsIgnoreCase("iridiumskyblock.")) && command.isEnabled()) { if (current >= (page - 1) * 18 && current < page * 18) p.sendMessage(Utils.color(IridiumSkyblock.getMessages().helpMessage.replace("%command%", command.getAliases().get(0)).replace("%description%", command.getDescription()))); current++; } } BaseComponent[] components = TextComponent.fromLegacyText(Utils.color(IridiumSkyblock.getMessages().helpfooter.replace("%maxpage%", maxpage + "").replace("%page%", page + ""))); for (BaseComponent component : components) { if (ChatColor.stripColor(component.toLegacyText()).contains(IridiumSkyblock.getMessages().nextPage)) { if (page < maxpage) { component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/is help " + (page + 1))); component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to go to page " + (page + 1)).create())); } } else if (ChatColor.stripColor(component.toLegacyText()).contains(IridiumSkyblock.getMessages().previousPage)) { if (page > 1) { component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/is help " + (page - 1))); component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to go to page " + (page - 1)).create())); } } } p.getPlayer().spigot().sendMessage(components); }
Example 16
Source File: KitLoading.java From AnnihilationPro with MIT License | 5 votes |
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(sender instanceof Player) { Player player = (Player)sender; if(player.hasPermission("Anni.ChangeKit")) { this.openKitMap(player); return true; } } return false; }
Example 17
Source File: ConfigManager.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public boolean needClaimToInteract(Player p, Block b) { if (p.hasPermission("redprotect.need-claim-to-build.bypass")) return false; if (root.needed_claim_to_build.worlds.contains(p.getWorld().getName()) && b != null && root.needed_claim_to_build.allow_interact_blocks.stream().noneMatch(str -> str.equalsIgnoreCase(b.getType().name())) && root.needed_claim_to_build.allow_break_blocks.stream().noneMatch(str -> str.equalsIgnoreCase(b.getType().name())) && !b.getType().name().contains(root.region_settings.block_id.toUpperCase()) && !b.getType().name().contains("SIGN")) { RedProtect.get().lang.sendMessage(p, "need.claim.tobuild"); return true; } return false; }
Example 18
Source File: ParticleCommands.java From NyaaUtils with MIT License | 4 votes |
public boolean isAdminOrAuthor(Player p, ParticleSet set) { return p.hasPermission("nu.particles.admin") || p.getUniqueId().equals(set.getAuthor()); }
Example 19
Source File: ScriptCommand.java From Skript with GNU General Public License v3.0 | 4 votes |
public boolean execute(final CommandSender sender, final String commandLabel, final String rest) { if (sender instanceof Player) { if ((executableBy & PLAYERS) == 0) { sender.sendMessage("" + m_executable_by_console); return false; } } else { if ((executableBy & CONSOLE) == 0) { sender.sendMessage("" + m_executable_by_players); return false; } } final ScriptCommandEvent event = new ScriptCommandEvent(ScriptCommand.this, sender); if (!permission.isEmpty() && !sender.hasPermission(permission)) { if (sender instanceof Player) { List<MessageComponent> components = permissionMessage.getMessageComponents(event); ((Player) sender).spigot().sendMessage(BungeeConverter.convert(components)); } else { sender.sendMessage(permissionMessage.getSingle(event)); } return false; } cooldownCheck : { if (sender instanceof Player && cooldown != null) { Player player = ((Player) sender); UUID uuid = player.getUniqueId(); // Cooldown bypass if (!cooldownBypass.isEmpty() && player.hasPermission(cooldownBypass)) { setLastUsage(uuid, event, null); break cooldownCheck; } if (getLastUsage(uuid, event) != null) { if (getRemainingMilliseconds(uuid, event) <= 0) { if (!SkriptConfig.keepLastUsageDates.value()) setLastUsage(uuid, event, null); } else { String msg = cooldownMessage.getSingle(event); if (msg != null) sender.sendMessage(msg); return false; } } } } if (Bukkit.isPrimaryThread()) { execute2(event, sender, commandLabel, rest); if (sender instanceof Player && !event.isCooldownCancelled()) setLastUsage(((Player) sender).getUniqueId(), event, new Date()); } else { // must not wait for the command to complete as some plugins call commands in such a way that the server will deadlock Bukkit.getScheduler().scheduleSyncDelayedTask(Skript.getInstance(), new Runnable() { @Override public void run() { execute2(event, sender, commandLabel, rest); if (sender instanceof Player && !event.isCooldownCancelled()) setLastUsage(((Player) sender).getUniqueId(), event, new Date()); } }); } return true; // Skript prints its own error message anyway }
Example 20
Source File: ShopInteractListener.java From ShopChest with MIT License | 3 votes |
@EventHandler(priority = EventPriority.HIGH) public void onPlayerInteractCreate(PlayerInteractEvent e) { Player p = e.getPlayer(); Block b = e.getClickedBlock(); if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (!(ClickType.getPlayerClickType(p) instanceof CreateClickType)) return; if (b.getType() != Material.CHEST && b.getType() != Material.TRAPPED_CHEST) return; if (ClickType.getPlayerClickType(p).getClickType() != ClickType.EnumClickType.CREATE) return; if (Config.enableAuthMeIntegration && plugin.hasAuthMe() && !AuthMeApi.getInstance().isAuthenticated(p)) return; if (e.isCancelled() && !p.hasPermission(Permissions.CREATE_PROTECTED)) { p.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_CREATE_PROTECTED)); plugin.debug(p.getName() + " is not allowed to create a shop on the selected chest"); } else if (shopUtils.isShop(b.getLocation())) { p.sendMessage(LanguageUtils.getMessage(Message.CHEST_ALREADY_SHOP)); plugin.debug("Chest is already a shop"); } else if (!ItemUtils.isAir(b.getRelative(BlockFace.UP).getType())) { p.sendMessage(LanguageUtils.getMessage(Message.CHEST_BLOCKED)); plugin.debug("Chest is blocked"); } else { CreateClickType clickType = (CreateClickType) ClickType.getPlayerClickType(p); ShopProduct product = clickType.getProduct(); double buyPrice = clickType.getBuyPrice(); double sellPrice = clickType.getSellPrice(); ShopType shopType = clickType.getShopType(); create(p, b.getLocation(), product, buyPrice, sellPrice, shopType); } e.setCancelled(true); ClickType.removePlayerClickType(p); }