下面列出了org.bukkit.entity.Player#hasMetadata ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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");
}
@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)));
}
}
/**
* 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());
}
}
@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));
});
}
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;
}
}
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);
}
/**
* 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()));
}
}
@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);
}
}
}
@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);
}
}
}
@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);
}
}
public void removeMeta(Player p){
String[] s = {"recipeBuilder","recipeViewer","itemViewer","itemBuilder"};
for(String t : s){
if(p.hasMetadata(t)){
p.removeMetadata(t, this);
}
}
}
@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;
}
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;
}
/**
* 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);
}
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;
}
/**
* 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);
}
}
}
}
}
/**
* 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);
}
}
}
@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;
}
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;
}
@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;
}