Java Code Examples for org.bukkit.entity.Player#isOp()

The following examples show how to use org.bukkit.entity.Player#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: SpawnEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onSpawnEggEvent(PlayerInteractEvent event) {
    Player player = event != null ? event.getPlayer() : null;
    if (player == null || event.isCancelled() || !plugin.getWorldManager().isSkyWorld(player.getWorld())) {
        return; // Bail out, we don't care
    }
    if (player.hasPermission("usb.mod.bypassprotection") || player.isOp()) {
        return;
    }
    ItemStack item = event.getItem();
    if (RIGHT_CLICKS.contains(event.getAction()) && item != null && isSpawnEgg(item)) {
        if (!plugin.playerIsOnIsland(player)) {
            event.setCancelled(true);
            plugin.notifyPlayer(player, tr("\u00a7eYou can only use spawn-eggs on your own island."));
            return;
        }
        SpawnEgg spawnEgg = (SpawnEgg) item.getData();
        checkLimits(event, spawnEgg.getSpawnedType(), player.getLocation());
        if (event.isCancelled()) {
            plugin.notifyPlayer(player, tr("\u00a7cYou have reached your spawn-limit for your island."));
            event.setUseItemInHand(Event.Result.DENY);
            event.setUseInteractedBlock(Event.Result.DENY);
        }
    }
}
 
Example 2
Source File: EconCommand.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void showHelp() {
	Player player;
	try {
		player = getPlayer();
	} catch (CivException e) {
		e.printStackTrace();
		return;
	}
	
	if (!player.isOp() && !player.hasPermission(CivSettings.ECON)) {
		return;
	}
	
	showBasicHelp();
	
}
 
Example 3
Source File: UpdateManager.java    From UHC with MIT License 5 votes vote down vote up
@Override
public void run() {
    try {
        final UpdateResponse response = checker.checkForUpdate();

        if (!response.hasUpdate()) return;

        final Release update = response.getUpdateDetails();

        // update.getVersion() cannot be null here
        if (update.getVersion().equals(latestUpdate)) return;

        latestUpdate = update.getVersion();

        plugin.getLogger().info(templates.evalTemplate("console", response));

        chatMessage = templates.evalTemplate("player.notify line", response);

        infoMessage = new TextComponent(templates.evalTemplate("player.info line", response));
        infoMessage.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, update.getUrl()));

        for (final Player player : plugin.getServer().getOnlinePlayers()) {
            if (player.isOp()) {
                player.sendMessage(chatMessage);
                player.spigot().sendMessage(infoMessage);
            }
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
 
Example 4
Source File: Tools.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Inventory getItemMenu(Player p) {
    if (!p.isOp() && !p.hasPermission("ce.item.*")) {
        Inventory lInv = Main.CEItemMenu;
        Inventory items = Bukkit.createInventory(null, lInv.getSize(), lInv.getTitle());
        items.setContents(lInv.getContents());
        for (int i = 0; i < items.getSize() - 2; i++) {
            ItemStack item = items.getItem(i);
            if (item == null || item.getType().equals(Material.AIR))
                continue;
            ItemMeta im = item.getItemMeta();
            List<String> lore = new ArrayList<String>();
            if (im.hasLore())
                lore = im.getLore();
            for (CItem ci : Main.items)
                if (item.getItemMeta().getDisplayName().equals(ci.getDisplayName())) {
                    if (!checkPermission(ci, p)) {
                        lore.add(ChatColor.RED + "You are not permitted to use this");
                        break;
                    }
                }
            im.setLore(lore);
            item.setItemMeta(im);
        }
        return items;
    }

    return Main.CEItemMenu;
}
 
Example 5
Source File: IslandGuard1_9.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handles Frost Walking on visitor's islands
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onBlockForm(final EntityBlockFormEvent e) {
    if (e.getEntity() instanceof Player && e.getNewState().getType().equals(Material.FROSTED_ICE)) {
        Player player= (Player) e.getEntity();
        if (!IslandGuard.inWorld(player)) {
            return;
        }
        if (player.isOp()) {
            return;
        }
        // This permission bypasses protection
        if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")) {
            return;
        }
        // Check island
        Island island = plugin.getGrid().getIslandAt(player.getLocation());
        if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) {
            return;
        }
        if (island !=null) {
            if (island.getMembers().contains(player.getUniqueId()) || island.getIgsFlag(SettingsFlag.PLACE_BLOCKS)) {
                return;
            }
        }
        // Silently cancel the event
        e.setCancelled(true);
    }
}
 
Example 6
Source File: Permission.java    From StaffPlus with GNU General Public License v3.0 5 votes vote down vote up
public boolean hasOnly(Player player, String permission)
{
	boolean hasPermission = false;
	
	if(player != null)
	{
		hasPermission = player.hasPermission(permission) && !player.isOp();
	}
	
	return hasPermission;
}
 
Example 7
Source File: EntityLimits.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks if action is allowed for player in location for flag
 * @param player
 * @param location
 * @param flag
 * @return true if allowed
 */
private boolean actionAllowed(Player player, Location location, SettingsFlag flag) {
    if (player == null) {
        return actionAllowed(location, flag);
    }
    // This permission bypasses protection
    if (player.isOp() || VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")) {
        return true;
    }
    Island island = plugin.getGrid().getProtectedIslandAt(location);
    if (island != null && (island.getIgsFlag(flag) || island.getMembers().contains(player.getUniqueId()))){
        return true;
    }
    return island == null && Settings.defaultWorldSettings.get(flag);
}
 
Example 8
Source File: AdminCmd.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkAdminPerms(Player player2, String[] split) {
    // Check perms quickly for this command
    if (player2.isOp()) {
        return true;
    }
    String check = split[0];
    if (check.equalsIgnoreCase("confirm"))
        check = "purge";
    if (VaultHelper.checkPerm(player2, Settings.PERMPREFIX + "admin." + check.toLowerCase())) {
        return true;
    }
    return false;
}
 
Example 9
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks if action is allowed for player in location for flag
 * @param player
 * @param location
 * @param flag
 * @return true if allowed
 */
private boolean actionAllowed(Player player, Location location, SettingsFlag flag) {
    if (player == null) {
        return actionAllowed(location, flag);
    }
    // This permission bypasses protection
    if (player.isOp() || VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")) {
        return true;
    }
    Island island = plugin.getGrid().getProtectedIslandAt(location);
    if (island != null && (island.getIgsFlag(flag) || island.getMembers().contains(player.getUniqueId()))){
        return true;
    }
    return island == null && Settings.defaultWorldSettings.get(flag);
}
 
Example 10
Source File: CreateArena.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
public boolean onCommand(Player player, String[] args) {
    if(!player.hasPermission(permission()) && !player.isOp()){
        MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "error.nopermission", player);
        return true;
    }
    GameManager.getInstance().createArenaFromSelection(player);
    return true;
}
 
Example 11
Source File: MobLibCommand.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
	
	if (sender instanceof Player) {

		Player player = (Player)sender;
		if (player.isOp()) {
			player.sendMessage("Spawning test yobo");
			MobLib.spawnCustom(args[0], player.getLocation());
		}
	}
	
	return false;
}
 
Example 12
Source File: LWC.java    From Modern-LWC with MIT License 5 votes vote down vote up
/**
 * Check if a player can do admin functions on LWC
 *
 * @param player the player to check
 * @return true if the player is an LWC admin
 */
public boolean isAdmin(Player player) {
    if (player.isOp()) {
        if (configuration.getBoolean("core.opIsLWCAdmin", true)) {
            return true;
        }
    }

    return hasPermission(player, "lwc.admin");
}
 
Example 13
Source File: DebugFishListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onDebug(PlayerInteractEvent e) {
    if (e.getAction() == Action.PHYSICAL || e.getHand() != EquipmentSlot.HAND) {
        return;
    }

    Player p = e.getPlayer();

    if (p.isOp() && SlimefunUtils.isItemSimilar(e.getItem(), SlimefunItems.DEBUG_FISH, true)) {
        e.setCancelled(true);

        if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
            if (p.isSneaking()) {
                if (BlockStorage.hasBlockInfo(e.getClickedBlock())) {
                    BlockStorage.clearBlockInfo(e.getClickedBlock());
                }
            }
            else {
                e.setCancelled(false);
            }
        }
        else if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
            if (p.isSneaking()) {
                Block b = e.getClickedBlock().getRelative(e.getBlockFace());
                b.setType(Material.PLAYER_HEAD);
                SkullBlock.setFromHash(b, HeadTexture.MISSING_TEXTURE.getTexture());
            }
            else if (BlockStorage.hasBlockInfo(e.getClickedBlock())) {
                sendInfo(p, e.getClickedBlock());
            }
        }
    }
}
 
Example 14
Source File: Vote.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
public boolean onCommand(Player player, String[] args) {
    if (!player.hasPermission(permission()) && !player.isOp()) {
        MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "error.nopermission", player);
        return false;
    }
    int game = GameManager.getInstance().getPlayerGameId(player);
    if(game == -1){
        MessageManager.getInstance().sendMessage(MessageManager.PrefixType.ERROR, "error.notinarena", player);
        return true;
    }

    GameManager.getInstance().getGame(GameManager.getInstance().getPlayerGameId(player)).vote(player);

    return true;
}
 
Example 15
Source File: CivInfoCommand.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
public static void show(CommandSender sender, Resident resident, Civilization civ) {
	
	boolean isOP = false;
	if (sender instanceof Player) {
		Player player;
		try {
			player = CivGlobal.getPlayer(resident);
			if (player.isOp()) {
				isOP = true;
			}
		} catch (CivException e) {
			/* Allow console to display. */
		}
	}	else {
		/* We're the console. */
		isOP = true;
	}
	
	
	CivMessage.sendHeading(sender, "Civilization of "+civ.getName());
	
	CivMessage.send(sender, CivColor.Green+"Score: "+CivColor.LightGreen+civ.getScore()+
			CivColor.Green+" Towns: "+CivColor.LightGreen+civ.getTownCount());
	if (civ.getLeaderGroup() == null) {
		CivMessage.send(sender, CivColor.Green+"Leaders: "+CivColor.Rose+"NONE");
	} else {
		CivMessage.send(sender, CivColor.Green+"Leaders: "+CivColor.LightGreen+civ.getLeaderGroup().getMembersString());
	}
	
	if (civ.getAdviserGroup() == null) {
		CivMessage.send(sender, CivColor.Green+"Advisers: "+CivColor.Rose+"NONE");
	} else {
		CivMessage.send(sender, CivColor.Green+"Advisers: "+CivColor.LightGreen+civ.getAdviserGroup().getMembersString());
	}
    
    if (resident == null || civ.hasResident(resident)) {
    	CivMessage.send(sender, CivColor.Green+"Income Tax Rate: "+CivColor.LightGreen+civ.getIncomeTaxRateString()+
				CivColor.Green+" Science Percentage: "+CivColor.LightGreen+DecimalHelper.formatPercentage(civ.getSciencePercentage()));
		CivMessage.send(sender ,CivColor.Green+"Beakers: "+CivColor.LightGreen+civ.getBeakers()+
				CivColor.Green+" Online: "+CivColor.LightGreen+civ.getOnlineResidents().size());
    }
	
	if (resident == null || civ.getLeaderGroup().hasMember(resident) || civ.getAdviserGroup().hasMember(resident) || isOP) {
		CivMessage.send(sender, CivColor.Green+"Treasury: "+CivColor.LightGreen+civ.getTreasury().getBalance()+CivColor.Green+" coins.");
	}
	
	if (civ.getTreasury().inDebt()) {
		CivMessage.send(sender, CivColor.Yellow+"In Debt: "+civ.getTreasury().getDebt()+" coins.");	
		CivMessage.send(sender, CivColor.Yellow+civ.getDaysLeftWarning());
	}
	
	for (EndGameCondition endCond : EndGameCondition.endConditions) {
		ArrayList<SessionEntry> entries = CivGlobal.getSessionDB().lookup(endCond.getSessionKey());
		if (entries.size() == 0) {
			continue;
		}
		
		for (SessionEntry entry : entries) {
			if (civ == EndGameCondition.getCivFromSessionData(entry.value)) {
				Integer daysLeft = endCond.getDaysToHold() - endCond.getDaysHeldFromSessionData(entry.value);
				CivMessage.send(sender, CivColor.LightBlue+CivColor.BOLD+civ.getName()+CivColor.White+" is "+
				CivColor.Yellow+CivColor.BOLD+daysLeft+CivColor.White+" days away from a "+CivColor.LightPurple+CivColor.BOLD+endCond.getVictoryName()+
				CivColor.White+" victory!");
				break;
			}
		}
	}
	
	Integer votes = EndConditionDiplomacy.getVotesFor(civ);
	if (votes > 0) {
		CivMessage.send(sender, CivColor.LightBlue+CivColor.BOLD+civ.getName()+CivColor.White+" has "+
				CivColor.LightPurple+CivColor.BOLD+votes+CivColor.White+" diplomatic votes");
	}
	
	Double beakers = EndConditionScience.getBeakersFor(civ);
	if (beakers > 0) {
		DecimalFormat df = new DecimalFormat("#.#");
		CivMessage.send(sender, CivColor.LightBlue+CivColor.BOLD+civ.getName()+CivColor.White+" has "+
				CivColor.LightPurple+CivColor.BOLD+df.format(beakers)+CivColor.White+" beakers on The Enlightenment.");			
	}
	
	String out = CivColor.Green+"Towns: ";
	for (Town town : civ.getTowns()) {
		if (town.isCapitol()) {
			out += CivColor.Gold+town.getName();
		} else if (town.getMotherCiv() != null) {
			out += CivColor.Yellow+town.getName();
		} else {
			out += CivColor.White+town.getName();
		}
		out += ", ";
	}
	
	CivMessage.send(sender, out);
}
 
Example 16
Source File: CivCommand.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
public void time_cmd() throws CivException {
	CivMessage.sendHeading(sender, "CivCraft Timers");
	Resident resident = getResident();
	ArrayList<String> out = new ArrayList<String>();
	SimpleDateFormat sdf = new SimpleDateFormat("M/dd h:mm:ss a z");
	
	Calendar cal = Calendar.getInstance();
	cal.setTimeZone(TimeZone.getTimeZone(resident.getTimezone()));
	sdf.setTimeZone(cal.getTimeZone());
	
	
	out.add(CivColor.Green+"Current Server Time: "+CivColor.LightGreen+sdf.format(cal.getTime()));
	
	cal.setTime(CivGlobal.getNextUpkeepDate());
	out.add(CivColor.Green+"Next Upkeep: "+CivColor.LightGreen+sdf.format(cal.getTime()));
	
	cal.setTime(CivGlobal.getNextHourlyTickDate());
	out.add(CivColor.Green+"Next Hourly Tick: "+CivColor.LightGreen+sdf.format(cal.getTime()));
	
	cal.setTime(CivGlobal.getNextRepoTime());
	out.add(CivColor.Green+"Next Trade Good Repo: "+CivColor.LightGreen+sdf.format(cal.getTime()));
	
	if (War.isWarTime()) {
		out.add(CivColor.Yellow+"WarTime is now!");
		cal.setTime(War.getStart());
		out.add(CivColor.Yellow+"    Started: "+CivColor.LightGreen+sdf.format(cal.getTime()));
		
		cal.setTime(War.getEnd());
		out.add(CivColor.Yellow+"    Ends: "+CivColor.LightGreen+sdf.format(cal.getTime()));
	} else {
		cal.setTime(War.getNextWarTime());
		out.add(CivColor.Green+"Next WarTime: "+CivColor.LightGreen+sdf.format(cal.getTime()));
	}
	
	Player player = null;
	try {
		player = getPlayer();
	} catch (CivException e) {
	}

	if (player == null || player.hasPermission(CivSettings.MINI_ADMIN) || player.isOp()) {
		cal.setTime(CivGlobal.getTodaysSpawnRegenDate());
		out.add(CivColor.LightPurple+"Next Spawn Regen: "+CivColor.LightGreen+sdf.format(cal.getTime()));
		
		cal.setTime(CivGlobal.getNextRandomEventTime());
		out.add(CivColor.LightPurple+"Next Random Event: "+CivColor.LightGreen+sdf.format(cal.getTime()));
	}
	
	CivMessage.send(sender, out);
}
 
Example 17
Source File: ASkyBlock.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resets a player's inventory, armor slots, equipment, enderchest and
 * potion effects
 *
 * @param player - player
 */
@SuppressWarnings("deprecation")
public void resetPlayer(Player player) {
    // getLogger().info("DEBUG: clear inventory = " +
    // Settings.clearInventory);
    if (Settings.clearInventory
            && (player.getWorld().getName().equalsIgnoreCase(Settings.worldName) || player.getWorld().getName()
                    .equalsIgnoreCase(Settings.worldName + "_nether"))) {
        // Clear their inventory and equipment and set them as survival
        player.getInventory().clear(); // Javadocs are wrong - this does not
        // clear armor slots! So...
        player.getInventory().setArmorContents(null);
        player.getInventory().setHelmet(null);
        player.getInventory().setChestplate(null);
        player.getInventory().setLeggings(null);
        player.getInventory().setBoots(null);
        player.getEquipment().clear();
    }
    if (!player.isOp()) {
        player.setGameMode(GameMode.SURVIVAL);
    }
    if (Settings.resetChallenges) {
        // Reset the player's challenge status
        players.resetAllChallenges(player.getUniqueId(), false);
    }
    // Reset the island level
    players.setIslandLevel(player.getUniqueId(), 0);
    // Clear the starter island
    players.clearStartIslandRating(player.getUniqueId());
    // Save the player
    players.save(player.getUniqueId());
    topTen.topTenAddEntry(player.getUniqueId(), 0);
    // Update the inventory
    player.updateInventory();
    if (Settings.resetEnderChest) {
        // Clear any Enderchest contents
        final ItemStack[] items = new ItemStack[player.getEnderChest().getContents().length];
        player.getEnderChest().setContents(items);
    }
    // Clear any potion effects
    for (PotionEffect effect : player.getActivePotionEffects())
        player.removePotionEffect(effect.getType());
}
 
Example 18
Source File: PlayerData.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean init(final @Nullable Class<? extends Player> c, final @Nullable Player e) {
	op = e == null ? 0 : e.isOp() ? 1 : -1;
	return true;
}
 
Example 19
Source File: SecuritySystem.java    From FunnyGuilds with Apache License 2.0 4 votes vote down vote up
public boolean checkPlayer(Player player, SecurityType type, Object... values) {
    if (! FunnyGuilds.getInstance().getPluginConfiguration().regionsEnabled) {
        return false;
    }
    
    if (isBanned(User.get(player))) {
        return true;
    }
    
    switch (type) {
        case FREECAM:
            Guild guild = null;

            for (Object value : values) {
                if (value instanceof Guild) {
                    guild = (Guild) value;
                }
            }

            if (guild == null) {
                return false;
            }

            Region region = guild.getRegion();

            if (region == null) {
                return false;
            }

            int dis = (int) region.getCenter().distance(player.getLocation());

            if (dis < 6) {
                return false;
            }
            
            for (Player w : Bukkit.getOnlinePlayers()) {
                if (w.isOp()) {
                    w.sendMessage(SecurityUtils.getBustedMessage(player.getName(), "FreeCam"));
                    w.sendMessage(SecurityUtils.getNoteMessage("Zaatakowal krysztal z odleglosci &c" + dis + " kratek"));
                }
            }
            
            blocked.add(User.get(player));
            return true;
        case EVERYTHING:
            break;
        default:
            break;
    }
    
    return false;
}
 
Example 20
Source File: IslandGuard1_8.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled=true)
void placeArmorStandEvent(PlayerInteractEvent e) {
    Player p = e.getPlayer();
    if (DEBUG) {
        plugin.getLogger().info("1.8 " + "Armor stand place " + e.getEventName());
    }
    if (!IslandGuard.inWorld(p)) {
        return;
    }
    if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
        // You can do anything if you are Op
        return;
    }

    // Check if they are holding armor stand
    for (ItemStack inHand : Util.getPlayerInHandItems(e.getPlayer())) {
        if (inHand.getType().equals(Material.ARMOR_STAND)) {
            // Check island
            Island island = plugin.getGrid().getIslandAt(e.getPlayer().getLocation());
            if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) {
                return;
            }
            if (island !=null && (island.getMembers().contains(p.getUniqueId()) || island.getIgsFlag(SettingsFlag.PLACE_BLOCKS))) {
                //plugin.getLogger().info("1.8 " + "DEBUG: armor stand place check");
                if (Settings.limitedBlocks.containsKey("ARMOR_STAND") && Settings.limitedBlocks.get("ARMOR_STAND") > -1) {
                    //plugin.getLogger().info("1.8 " + "DEBUG: count armor stands");
                    int count = island.getTileEntityCount(Material.ARMOR_STAND,e.getPlayer().getWorld());
                    //plugin.getLogger().info("1.8 " + "DEBUG: count is " + count + " limit is " + Settings.limitedBlocks.get("ARMOR_STAND"));
                    if (Settings.limitedBlocks.get("ARMOR_STAND") <= count) {
                        Util.sendMessage(e.getPlayer(), ChatColor.RED + (plugin.myLocale(e.getPlayer().getUniqueId()).entityLimitReached.replace("[entity]",
                                Util.prettifyText(Material.ARMOR_STAND.toString()))).replace("[number]", String.valueOf(Settings.limitedBlocks.get("ARMOR_STAND"))));
                        e.setCancelled(true);
                        return;
                    }
                }
                return;
            }
            // plugin.getLogger().info("1.8 " + "DEBUG: stand place cancelled");
            e.setCancelled(true);
            Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
            e.getPlayer().updateInventory();
        }
    }
}