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

The following examples show how to use org.bukkit.entity.Player#hasMetadata() . 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: PrivateMessageCommands.java    From CardinalPGM with MIT License 6 votes vote down vote up
@Command(aliases = {"reply", "r"}, desc = "Reply to a private message", min = 1)
public static void reply(final CommandContext cmd, CommandSender sender) throws CommandException {
    if (!(sender instanceof Player)) {
        throw new CommandException(ChatConstant.ERROR_PLAYER_COMMAND.getMessage(ChatUtil.getLocale(sender)));
    }
    Player player = (Player) sender;
    if (!player.hasMetadata("reply")) {
        throw new CommandException(ChatConstant.ERROR_NO_MESSAGES.getMessage(ChatUtil.getLocale(sender)));
    }
    Player target = (Player) player.getMetadata("reply").get(0).value();
    if (target == null) {
        throw new CommandException(ChatConstant.ERROR_PLAYER_NOT_FOUND.getMessage(ChatUtil.getLocale(sender)));
    }
    if (Settings.getSettingByName("PrivateMessages") == null || Settings.getSettingByName("PrivateMessages").getValueByPlayer(target).getValue().equalsIgnoreCase("all")) {
        target.sendMessage(ChatColor.GRAY + "From " + Players.getName(sender) + ChatColor.GRAY + ": " + ChatColor.RESET + cmd.getJoinedStrings(0));
        sender.sendMessage(ChatColor.GRAY + "To " + Players.getName(target) + ChatColor.GRAY + ": " + ChatColor.RESET + cmd.getJoinedStrings(0));
        if (Settings.getSettingByName("PrivateMessageSounds") == null || Settings.getSettingByName("PrivateMessageSounds").getValueByPlayer(target).getValue().equalsIgnoreCase("on")) {
            target.playSound(target.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2F);
        }
        target.setMetadata("reply", new FixedMetadataValue(Cardinal.getInstance(), sender));
    } else {
        sender.sendMessage(new LocalizedChatMessage(ChatConstant.ERROR_PLAYER_DISABLED_PMS, Players.getName(target) + ChatColor.RED).getMessage(ChatUtil.getLocale(sender)));
    }
}
 
Example 2
Source File: Game.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
public void onPlayerTeleport(PlayerTeleportEvent event, SpleefPlayer player) {
	Player bukkitPlayer = player.getBukkitPlayer();
	
	if (bukkitPlayer.hasMetadata(SpleefPlayer.ALLOW_NEXT_TELEPORT_KEY)) {
		List<MetadataValue> values = bukkitPlayer.getMetadata(SpleefPlayer.ALLOW_NEXT_TELEPORT_KEY);
		
		for (MetadataValue value : values) {
			if (value.getOwningPlugin() != heavySpleef.getPlugin()) {
				continue;
			}
			
			if (value.asBoolean()) {
				return;
			}
		}
	}
	
	event.setCancelled(true);
}
 
Example 3
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gives temporary perms
 * Gives flymode if player has a specific permission and is on his island
 * @param e - event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerEnterOnIsland(final IslandEnterEvent e){
    Player player = plugin.getServer().getPlayer(e.getPlayer());
    if (player != null && !player.hasMetadata("NPC")) {
        if (DEBUG) {
            plugin.getLogger().info("DEBUG: player entered island");
            plugin.getLogger().info("DEBUG: island center is " + e.getIslandLocation());
            if (e.getIslandOwner() != null && plugin.getPlayers().isAKnownPlayer(e.getIslandOwner())) {
                plugin.getLogger().info("DEBUG: island owner is " + plugin.getPlayers().getName(e.getIslandOwner()));
            } else {
                plugin.getLogger().info("DEBUG: island is unowned or owner unknown");
            }
        }
        processPerms(player, e.getIsland());
    }
}
 
Example 4
Source File: ListenerMenuClose.java    From TrMenu with MIT License 6 votes vote down vote up
@EventHandler
public void onClose(InventoryCloseEvent e) {
    if (!(e.getInventory().getHolder() instanceof MenuHolder)) {
        return;
    }

    Player p = (Player) e.getPlayer();
    Menu menu = ((MenuHolder) e.getInventory().getHolder()).getMenu();

    if (!Strings.isBlank(menu.getCloseRequirement()) && !Boolean.parseBoolean(String.valueOf(JavaScript.run(p, menu.getCloseRequirement())))) {
        TrAction.runActions(menu.getCloseDenyActions(), p);
        return;
    }
    if (menu.getCloseActions() != null && !p.hasMetadata("TrMenu.Force-Close")) {
        menu.getCloseActions().forEach(action -> action.run(p));
    }
    if (ArgsCache.getHeldSlot().containsKey(p.getUniqueId())) {
        p.getInventory().setHeldItemSlot(ArgsCache.getHeldSlot().get(p.getUniqueId()));
        ArgsCache.getHeldSlot().remove(p.getUniqueId());
    }
    menu.getButtons().keySet().forEach(b -> {
        b.getDefIcon().getItem().resetIndex(p);
        b.getIcons().forEach(i -> i.getItem().resetIndex(p));
    });
}
 
Example 5
Source File: GameCreator.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
private String addTeamJoinEntity(final Player player, String name) {
    for (Team t : game.getTeams()) {
        if (t.name.equals(name)) {
            if (player.hasMetadata(BEDWARS_TEAM_JOIN_METADATA)) {
                player.removeMetadata(BEDWARS_TEAM_JOIN_METADATA, Main.getInstance());
            }
            player.setMetadata(BEDWARS_TEAM_JOIN_METADATA, new TeamJoinMetaDataValue(t));

            new BukkitRunnable() {
                public void run() {
                    if (!player.hasMetadata(BEDWARS_TEAM_JOIN_METADATA)) {
                        return;
                    }

                    player.removeMetadata(BEDWARS_TEAM_JOIN_METADATA, Main.getInstance());
                }
            }.runTaskLater(Main.getInstance(), 200L);
            return i18n("admin_command_click_right_on_entity_to_set_join").replace("%team%", t.name);
        }
    }
    return i18n("admin_command_team_is_not_exists");
}
 
Example 6
Source File: RecipeBuilder.java    From ProRecipes with GNU General Public License v2.0 6 votes vote down vote up
public void saveFurnace(ItemStack source, Player p){
	p.removeMetadata("recipeBuilder", ProRecipes.getPlugin());
	if(source.getType() != Material.AIR){
		ItemStack ib = null;
		ib = storedItems.get(p.getName()).clone();
		storedItems.remove(p.getName());
		RecipeFurnace rec = new RecipeFurnace(ib, source);
		if(p.hasMetadata("recPermission")){
			rec.setPermission(p.getMetadata("recPermission").get(0).asString());
			p.removeMetadata("recPermission", ProRecipes.getPlugin());
		}
		rec.register();
		ItemBuilder.sendMessage(p, m.getMessage("Recipe_Builder_Title", ChatColor.GOLD + "Recipe Builder") ,  m.getMessage("Furnace_Saved", ChatColor.DARK_GREEN + "Your furnace recipe has been saved!"));
		ProRecipes.getPlugin().getRecipes().saveRecipes(false);
	}else{
		ItemBuilder.sendMessage(p, m.getMessage("Recipe_Builder_Title", ChatColor.GOLD + "Recipe Builder") ,  m.getMessage("Recipe_Builder_Empty", ChatColor.DARK_RED + "You cannot save an empty recipe"));
		//return;
	}
}
 
Example 7
Source File: ProRecipes.java    From ProRecipes with GNU General Public License v2.0 5 votes vote down vote up
public void removeMeta(Player p){
	String[] s = {"recipeBuilder","recipeViewer","itemViewer","itemBuilder"};
	for(String t : s){
		if(p.hasMetadata(t)){
			p.removeMetadata(t, this);
		}
	}
}
 
Example 8
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gives temporary perms to players who are online when the server is reloaded or the plugin reloaded.
 */
public void giveAllTempPerms() {
    if (plugin.getGrid() == null) {
        return;
    }
    if (DEBUG)
        plugin.getLogger().info("DEBUG: Giving all temp perms");
    for (Player player : plugin.getServer().getOnlinePlayers()) {
        if(player != null && !player.hasMetadata("NPC") && plugin.getGrid().playerIsOnIsland(player)){
            if(VaultHelper.checkPerm(player, Settings.PERMPREFIX + "islandfly")){
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: Fly enable");
                player.setAllowFlight(true);
                player.setFlying(true);
            }

            for(String perm : Settings.temporaryPermissions){
                if(!VaultHelper.checkPerm(player, perm)){
                    VaultHelper.addPerm(player, perm, ASkyBlock.getIslandWorld());
                    if (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
                        VaultHelper.addPerm(player, perm, ASkyBlock.getNetherWorld());
                    }
                    List<String> perms = new ArrayList<String>();
                    if(temporaryPerms.containsKey(player.getUniqueId())) perms = temporaryPerms.get(player.getUniqueId());
                    perms.add(perm);
                    temporaryPerms.put(player.getUniqueId(), perms);
                }
            }
        }
    }
}
 
Example 9
Source File: PatienceTester.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isRunning(Player player, String key) {
    if (player.hasMetadata(key)) {
        List<MetadataValue> metadata = player.getMetadata(key);
        MetadataValue metadataValue = metadata.size() > 0 ? metadata.get(0) : null;
        if (metadataValue == null || metadataValue.asLong() < System.currentTimeMillis()) {
            player.removeMetadata(key, uSkyBlock.getInstance());
            return false;
        }
        player.sendMessage(getMessage());
        return true;
    }
    return false;
}
 
Example 10
Source File: Statz.java    From Statz with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method does a general check for all events.
 * <br>
 * Currently, it checks if a player is in creative mode and if we should
 * ignore creative mode
 *
 * @param player Player to check
 * @param stat   Stat to check
 * @return true if we should track the stat, false otherwise.
 */
public boolean doGeneralCheck(Player player, PlayerStat stat) {
    // Check if player is NPC.
    if (player.hasMetadata("NPC")) {
        return false;
    }

    // Check if we should register players in CREATIVE
    if (this.getConfigHandler().shouldIgnoreCreative() && player.getGameMode() == GameMode.CREATIVE) {
        return false;
    }

    // Check if we should track in the player's current position.
    return !this.getDisableManager().isStatDisabledLocation(player.getLocation(), stat);
}
 
Example 11
Source File: WorldGuardUtils.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
public static boolean hasBypass(Player player, World world, ProtectedRegion region, Flag<?> flag)
{
	if (player.hasMetadata("NPC"))
	{
		return true;
	}
	
	//Permission system that supports wildcars is really helpful here :)
	if (player.hasPermission("worldguard.region.bypass." + world.getName() + "." + region.getId() + "." + flag.getName()))
	{
		return true;
	}
	
	return false;
}
 
Example 12
Source File: AssassinsBlade.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean effect(Event event, final Player player) {
	if(event instanceof PlayerInteractEvent) {
		if(!player.hasMetadata("ce.assassin"))
			if(player.isSneaking())
					  player.setMetadata("ce.assassin", new FixedMetadataValue(main, null));
					  player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, InvisibilityDuration, 0, true), true);
					  player.sendMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + "You hide in the shadows.");
					  new BukkitRunnable() {
						  @Override
						  public void run() {
							  if(player.hasMetadata("ce.assassin")) {
								  player.removeMetadata("ce.assassin", main);
								  player.sendMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + "You are no longer hidden!");
							  }
						  }
					  }.runTaskLater(main, InvisibilityDuration);
					  return true;
				  }
	if(event instanceof EntityDamageByEntityEvent) {
		EntityDamageByEntityEvent e = ((EntityDamageByEntityEvent) event);
		if(e.getDamager() == player && player.hasMetadata("ce.assassin")) {
			  e.setDamage(e.getDamage() * AmbushDmgMultiplier);
			  player.removeMetadata("ce.assassin", main);
			  player.removePotionEffect(PotionEffectType.INVISIBILITY);
			  EffectManager.playSound(e.getEntity().getLocation(), "BLOCK_PISTON_EXTEND", 0.4f, 0.1f);
			  player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, WeaknessLength, WeaknessLevel, false), true);
			  player.sendMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + "You are no longer hidden!");
	   }
	}
	 return false;
}
 
Example 13
Source File: QuitEvent.java    From StackMob-3 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onQuit(PlayerQuitEvent event){
    Player player = event.getPlayer();
    if(player.hasMetadata(GlobalValues.STICK_MODE)){
        player.removeMetadata(GlobalValues.STICK_MODE, sm);
        player.removeMetadata(GlobalValues.SELECTED_ENTITY, sm);
        player.removeMetadata(GlobalValues.WAITING_FOR_INPUT, sm);
    }
}
 
Example 14
Source File: Deepwounds.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void effect(Event e, ItemStack item, int level) {
	EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
	final Player damaged = (Player) event.getEntity();
	final Player damager = (Player) event.getDamager();
	if(!getHasCooldown(damager) && !damaged.hasMetadata("ce.bleed")) {

	Random random = new Random();
	if(random.nextInt(100) < rand) {
		generateCooldown(damager, 140);
		Tools.applyBleed(damaged, duration*level);
	}
	}
}
 
Example 15
Source File: BungeeListener.java    From FastLogin with MIT License 5 votes vote down vote up
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
    ByteArrayDataInput dataInput = ByteStreams.newDataInput(message);

    LoginActionMessage loginMessage = new LoginActionMessage();
    loginMessage.readFrom(dataInput);

    plugin.getLog().debug("Received plugin message {}", loginMessage);

    Player targetPlayer = player;
    if (!loginMessage.getPlayerName().equals(player.getName())) {
        targetPlayer = Bukkit.getPlayerExact(loginMessage.getPlayerName());;
    }

    if (targetPlayer == null) {
        plugin.getLog().warn("Force action player {} not found", loginMessage.getPlayerName());
        return;
    }

    // fail if target player is blacklisted because already authenticated or wrong bungeecord id
    if (targetPlayer.hasMetadata(plugin.getName())) {
        plugin.getLog().warn("Received message {} from a blacklisted player {}", loginMessage, targetPlayer);
    } else {
        UUID sourceId = loginMessage.getProxyId();
        if (plugin.getBungeeManager().isProxyAllowed(sourceId)) {
            readMessage(targetPlayer, loginMessage);
        } else {
            plugin.getLog().warn("Received proxy id: {} that doesn't exist in the proxy whitelist file", sourceId);
        }
    }
}
 
Example 16
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Revoke temporary perms
 * Removes flymode with a delay if player leave his island.
 * @param e - event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerLeaveIsland(final IslandExitEvent e) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: island exit event");
    final Player player = plugin.getServer().getPlayer(e.getPlayer());
    if (player != null && !player.hasMetadata("NPC")) {
        if (DEBUG) {
            plugin.getLogger().info("DEBUG: player left island. e.getLocation = " + e.getLocation());
            plugin.getLogger().info("DEBUG: player location = " + player.getLocation());
        }
        removeTempPerms(player, e.getIsland(), plugin.getGrid().getIslandAt(e.getLocation()));
    }
}
 
Example 17
Source File: NaturalMobSpawnEventHandler.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
private static int getHuntingGearBonus(Entity entity) {

        int huntingGearChanceAdder = 0;

        for (Player player : Bukkit.getOnlinePlayers()) {

            if (player.getWorld().equals(entity.getWorld()) &&
                    (!player.hasMetadata(MetadataHandler.VANISH_NO_PACKET) ||
                            player.hasMetadata(MetadataHandler.VANISH_NO_PACKET) && !player.getMetadata(MetadataHandler.VANISH_NO_PACKET).get(0).asBoolean())) {

                if (player.getLocation().distance(entity.getLocation()) < range) {

                    ItemStack helmet = player.getInventory().getHelmet();
                    ItemStack chestplate = player.getInventory().getChestplate();
                    ItemStack leggings = player.getInventory().getLeggings();
                    ItemStack boots = player.getInventory().getBoots();
                    ItemStack heldItem = player.getInventory().getItemInMainHand();
                    ItemStack offHandItem = player.getInventory().getItemInOffHand();

                    if (CustomEnchantmentCache.hunterEnchantment.hasCustomEnchantment(helmet))
                        huntingGearChanceAdder += CustomEnchantmentCache.hunterEnchantment.getCustomEnchantmentLevel(helmet);
                    if (CustomEnchantmentCache.hunterEnchantment.hasCustomEnchantment(chestplate))
                        huntingGearChanceAdder += CustomEnchantmentCache.hunterEnchantment.getCustomEnchantmentLevel(chestplate);
                    if (CustomEnchantmentCache.hunterEnchantment.hasCustomEnchantment(leggings))
                        huntingGearChanceAdder += CustomEnchantmentCache.hunterEnchantment.getCustomEnchantmentLevel(leggings);
                    if (CustomEnchantmentCache.hunterEnchantment.hasCustomEnchantment(boots))
                        huntingGearChanceAdder += CustomEnchantmentCache.hunterEnchantment.getCustomEnchantmentLevel(boots);
                    if (CustomEnchantmentCache.hunterEnchantment.hasCustomEnchantment(heldItem))
                        huntingGearChanceAdder += CustomEnchantmentCache.hunterEnchantment.getCustomEnchantmentLevel(heldItem);
                    if (CustomEnchantmentCache.hunterEnchantment.hasCustomEnchantment(offHandItem))
                        huntingGearChanceAdder += CustomEnchantmentCache.hunterEnchantment.getCustomEnchantmentLevel(offHandItem);

                }

            }

        }

        huntingGearChanceAdder = huntingGearChanceAdder * ConfigValues.customEnchantmentsConfig.getInt(CustomEnchantmentsConfig.HUNTER_SPAWN_BONUS);

        return huntingGearChanceAdder;

    }
 
Example 18
Source File: Powergloves.java    From ce with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean effect(Event event, final Player player) {
	if(event instanceof PlayerInteractEntityEvent) {
		PlayerInteractEntityEvent e = (PlayerInteractEntityEvent) event;
		e.setCancelled(true);
		final Entity clicked = e.getRightClicked();
		if(!player.hasMetadata("ce." + getOriginalName()))
			if(!clicked.getType().equals(EntityType.PAINTING) && !clicked.getType().equals(EntityType.ITEM_FRAME) && clicked.getPassenger() != player && player.getPassenger() == null) {
				player.setMetadata("ce." + getOriginalName(), new FixedMetadataValue(main, false));

				player.setPassenger(clicked);

				player.getWorld().playEffect(player.getLocation(), Effect.ZOMBIE_CHEW_IRON_DOOR, 10);

				new BukkitRunnable() {

					@Override
					public void run() {
						player.getWorld().playEffect(player.getLocation(), Effect.CLICK2, 10);
						player.setMetadata("ce." + getOriginalName(), new FixedMetadataValue(main, true));
						this.cancel();
					}
				}.runTaskLater(main, ThrowDelayAfterGrab);

				new BukkitRunnable() {

					int			GrabTime	= MaxGrabtime;
					ItemStack	current		= player.getItemInHand();

					@Override
					public void run() {
						if(current.equals(player.getItemInHand())) {
							current = player.getItemInHand();
						if(GrabTime > 0) {
							if(!player.hasMetadata("ce." + getOriginalName())) {
								this.cancel();
							}
							GrabTime--;
						} else if(GrabTime <= 0) {
							if(player.hasMetadata("ce." + getOriginalName())) {
								player.getWorld().playEffect(player.getLocation(), Effect.CLICK1, 10);
								player.removeMetadata("ce." + getOriginalName(), main);
								generateCooldown(player, getCooldown());
							}
							clicked.leaveVehicle();
							this.cancel();
						}
					  } else {
						  player.removeMetadata("ce." + getOriginalName(), main);
						  generateCooldown(player, getCooldown());
						  this.cancel();
					  }
					}
				}.runTaskTimer(main, 0l, 10l);
			}
	} else if(event instanceof PlayerInteractEvent) {
		if(player.hasMetadata("ce." + getOriginalName()) && player.getMetadata("ce." + getOriginalName()).get(0).asBoolean())
				if(player.getPassenger() != null) {
					Entity passenger = player.getPassenger();
					player.getPassenger().leaveVehicle();
					passenger.setVelocity(player.getLocation().getDirection().multiply(ThrowSpeedMultiplier));
					player.getWorld().playEffect(player.getLocation(), Effect.ZOMBIE_DESTROY_DOOR, 10);
					player.removeMetadata("ce." + getOriginalName(), main);
					return true;
				}
	}
	return false;
}
 
Example 19
Source File: AddTeamJoinCommand.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, ArrayList<String> args) {
  if (!super.hasPermission(sender)) {
    return false;
  }

  Player player = (Player) sender;
  String team = args.get(1);

  Game game = this.getPlugin().getGameManager().getGame(args.get(0));
  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;
  }

  Team gameTeam = game.getTeam(team);

  if (gameTeam == null) {
    player.sendMessage(
        ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.teamnotfound")));
    return false;
  }

  // only in lobby
  if (game.getLobby() == null || !player.getWorld().equals(game.getLobby().getWorld())) {
    player.sendMessage(
        ChatWriter
            .pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.mustbeinlobbyworld")));
    return false;
  }

  if (player.hasMetadata("bw-addteamjoin")) {
    player.removeMetadata("bw-addteamjoin", BedwarsRel.getInstance());
  }

  player.setMetadata("bw-addteamjoin", new TeamJoinMetaDataValue(gameTeam));
  final Player runnablePlayer = player;

  new BukkitRunnable() {

    @Override
    public void run() {
      try {
        if (!runnablePlayer.hasMetadata("bw-addteamjoin")) {
          return;
        }

        runnablePlayer.removeMetadata("bw-addteamjoin", BedwarsRel.getInstance());
      } catch (Exception ex) {
        BedwarsRel.getInstance().getBugsnag().notify(ex);
        // just ignore
      }
    }
  }.runTaskLater(BedwarsRel.getInstance(), 20L * 10L);

  player.sendMessage(
      ChatWriter
          .pluginMessage(
              ChatColor.GREEN + BedwarsRel._l(player, "success.selectteamjoinentity")));
  return true;
}
 
Example 20
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Removes perms for a player who was on one island and is now elsewhere
 * If fromIsland and toIsland are the same, then the player is just out of their protection zone
 * and if timing is allowed, they will keep their fly capability
 * @param player
 * @param fromIsland
 * @param toIsland
 */
public void removeTempPerms(final Player player, Island fromIsland, Island toIsland) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: Removing temp perms");
    if (player == null || player.hasMetadata("NPC")) {
        return;
    }
    // Check if the player has left the island completely
    if(VaultHelper.checkPerm(player, Settings.PERMPREFIX + "islandfly")) {
        // If the player has teleported to another world or island
        if (fromIsland.equals(toIsland)) {
            if (player.isFlying() && player.getGameMode().equals(GameMode.SURVIVAL)) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: player is flying timer is " + Settings.flyTimeOutside + "s");
                if (Settings.flyTimeOutside == 0) {
                    player.setAllowFlight(false);
                    player.setFlying(false);
                    if (DEBUG)
                        plugin.getLogger().info("DEBUG: removed fly");
                } else {
                    plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

                        @Override
                        public void run() {
                            if(!plugin.getGrid().playerIsOnIsland(player) && player.isFlying()){
                                // Check they didn't enable creative
                                if (player.getGameMode().equals(GameMode.SURVIVAL)) {
                                    player.setAllowFlight(false);
                                    player.setFlying(false);
                                    if (DEBUG)
                                        plugin.getLogger().info("DEBUG: removed fly");
                                }
                            }

                        }
                    }, 20L*Settings.flyTimeOutside);
                }
            }
        } else {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: Removing flight immediately");
            if (player.getGameMode().equals(GameMode.SURVIVAL)) {
                // Remove fly immediately
                player.setAllowFlight(false);
                player.setFlying(false);
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: removed fly");
            }
        }
    }


    for(String perm : Settings.temporaryPermissions){
        if(temporaryPerms.containsKey(player.getUniqueId()) && VaultHelper.checkPerm(player, perm)){
            VaultHelper.removePerm(player, perm, ASkyBlock.getIslandWorld());
            if (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
                VaultHelper.removePerm(player, perm, ASkyBlock.getNetherWorld());
            }
            if (DEBUG)
                plugin.getLogger().info("DEBUG: removed temp perm " + perm);
            List<String> perms = temporaryPerms.get(player.getUniqueId());
            perms.remove(perm);
            if(perms.isEmpty()) temporaryPerms.remove(player.getUniqueId());
            else temporaryPerms.put(player.getUniqueId(), perms);
        }
    }
}