org.bukkit.entity.Player#setMetadata ( )源码实例Demo

下面列出了org.bukkit.entity.Player#setMetadata ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: BedWars   文件: GameCreator.java
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");
}
 
源代码2 项目: BedWars   文件: GameCreator.java
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");
}
 
源代码3 项目: ce   文件: Tools.java
public static void applyBleed(final Player target, final int bleedDuration) {
    target.sendMessage(ChatColor.RED + "You are Bleeding!");
    target.setMetadata("ce.bleed", new FixedMetadataValue(Main.plugin, null));
    new BukkitRunnable() {

        int seconds = bleedDuration;

        @Override
        public void run() {
            if (seconds >= 0) {
                if (!target.isDead() && target.hasMetadata("ce.bleed")) {
                    target.damage(1 + (((Damageable) target).getHealth() / 15));
                    seconds--;
                } else {
                    target.removeMetadata("ce.bleed", Main.plugin);
                    this.cancel();
                }
            } else {
                target.removeMetadata("ce.bleed", Main.plugin);
                target.sendMessage(ChatColor.GREEN + "You have stopped Bleeding!");
                this.cancel();
            }
        }
    }.runTaskTimer(Main.plugin, 0l, 20l);

}
 
源代码4 项目: StackMob-3   文件: StickInteractEvent.java
@EventHandler
public void onStickInteract(PlayerInteractEntityEvent event){
    Player player = event.getPlayer();
    Entity entity = event.getRightClicked();
    if(!(entity instanceof Mob)){
        return;
    }
    if(event.getHand() != EquipmentSlot.HAND) {
        return;
    }
    if (sm.getStickTools().isStackingStick(player.getInventory().getItemInMainHand())) {
        if (player.isSneaking()) {
            sm.getStickTools().toggleMode(player);
        } else {
            if(!(StackTools.hasValidMetadata(player, GlobalValues.STICK_MODE))){
                player.setMetadata(GlobalValues.STICK_MODE, new FixedMetadataValue(sm, 1));
            }
            sm.getStickTools().performAction(player, entity);
        }
    }
}
 
源代码5 项目: ProRecipes   文件: RecipeBuilder.java
private void openShapeless(final Player p) {
	final ItemStack i = p.getOpenInventory().getItem(0).clone();
	ItemBuilder.close(p);
	p.setMetadata("closed", new FixedMetadataValue(ProRecipes.getPlugin(), ""));
	ItemBuilder.sendMessage(p, m.getMessage("Recipe_Builder_Title", ChatColor.GOLD + "Recipe Builder") ,  m.getMessage("Recipe_Builder_Add", ChatColor.DARK_GREEN + "Add your ingredients! Close to save recipe."));
	ProRecipes.getPlugin().getServer().getScheduler().runTaskLater(ProRecipes.getPlugin(), new Runnable(){
		
		@Override
		public void run() {
			p.setMetadata("recipeBuilder", new FixedMetadataValue(ProRecipes.getPlugin(), "craftRecipeShapeless"));
			p.openWorkbench(null, true);
			//p.removeMetadata("closed", RPGRecipes.getPlugin());
			p.getOpenInventory().setItem(0, i);
			//Inventory i = RPGRecipes.getPlugin().getServer().createInventory(p, InventoryType.WORKBENCH, "ItemBuilder");
			//p.openInventory(i);
		}
		
	}, ProRecipes.getPlugin().wait);
	
}
 
源代码6 项目: EntityAPI   文件: ControllablePlayerBase.java
@Override
public SpawnResult spawn(Location location) {
    if (isSpawned()) {
        return SpawnResult.ALREADY_SPAWNED;
    }

    this.handle = GameRegistry.get(IEntitySpawnHandler.class).createPlayerHandle(this, location, this.name, UUID.nameUUIDFromBytes(("EntityAPI-NPC:" + this.getId() + this.name).getBytes()));

    Player entity = this.getBukkitEntity();
    if (entity != null) {
        entity.setMetadata(EntityAPI.ENTITY_METADATA_MARKER, new FixedMetadataValue(EntityAPI.getCore(), true)); // Perhaps make this a key somewhere
        entity.teleport(location);
        entity.setSleepingIgnored(true);
    }

    // Send the Packet
    handle.updateSpawn();

    //return spawned;
    return isSpawned() ? SpawnResult.SUCCESS : SpawnResult.FAILED;
}
 
源代码7 项目: BedWars   文件: RemoveholoCommand.java
@Override
public boolean execute(CommandSender sender, List<String> args) {
    Player player = (Player) sender;
    if (!Main.isHologramsEnabled()) {
        player.sendMessage(i18n("holo_not_enabled"));
    } else {
        player.setMetadata("bw-remove-holo", new FixedMetadataValue(Main.getInstance(), true));
        player.sendMessage(i18n("click_to_holo_for_remove"));
    }
    return true;
}
 
源代码8 项目: TrMenu   文件: ActionSetShape.java
@Override
public void onExecute(Player player) {
    Menu menu = TrMenuAPI.getMenu(player);
    int shapeIndex = NumberUtils.toInt(getContent(player), -1);
    if (menu != null && menu.getRows().size() > 1 && shapeIndex != menu.getShape(player)) {
        player.setMetadata("TrMenu.Force-Close", new FixedMetadataValue(TrMenu.getPlugin(), "Close"));
        menu.open(player, shapeIndex, true, ArgsCache.getPlayerArgs(player));
        player.removeMetadata("TrMenu.Force-Close", TrMenu.getPlugin());
    }
}
 
源代码9 项目: ce   文件: AssassinsBlade.java
@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;
}
 
源代码10 项目: ArmorStandTools   文件: MainListener.java
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    final Player p = event.getPlayer();
    if(plugin.carryingArmorStand.containsKey(p.getUniqueId())) {
        if (plugin.playerHasPermission(p, plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), null)) {
            plugin.carryingArmorStand.remove(p.getUniqueId());
            Utils.actionBarMsg(p, Config.asDropped);
            p.setMetadata("lastDrop", new FixedMetadataValue(plugin, System.currentTimeMillis()));
            event.setCancelled(true);
        } else {
            p.sendMessage(ChatColor.RED + Config.wgNoPerm);
        }
        return;
    }
    ArmorStandTool tool = ArmorStandTool.get(event.getItem());
    if(tool == null) return;
    event.setCancelled(true);
    Action action = event.getAction();
    if(action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) {
        Utils.cycleInventory(p);
    } else if((action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) && tool == ArmorStandTool.SUMMON) {
        if (!plugin.playerHasPermission(p, event.getClickedBlock(), tool)) {
            p.sendMessage(ChatColor.RED + Config.generalNoPerm);
            return;
        }
        Location l = Utils.getLocationFacing(p.getLocation());
        plugin.pickUpArmorStand(spawnArmorStand(l), p, true);
        Utils.actionBarMsg(p, Config.carrying);
    }
    new BukkitRunnable() {
        @Override
        public void run() {
            //noinspection deprecation
            p.updateInventory();
        }
    }.runTaskLater(plugin, 1L);
}
 
源代码11 项目: ProRecipes   文件: ItemBuilder.java
public void openAddLore(Player p){
	storedItems.put(p.getName(), p.getOpenInventory().getItem(0).clone());
	close(p);
	p.getInventory().remove(storedItems.get(p.getName()));
	p.setMetadata("closed", new FixedMetadataValue(ProRecipes.getPlugin(), ""));
	p.setMetadata("itemBuilder", new FixedMetadataValue(ProRecipes.getPlugin(), "addLore"));
	sendMessage(p, m.getMessage("Item_Builder_Title", ChatColor.GOLD + "Item Builder"),  m.getMessage("Item_Builder_Lore", ChatColor.DARK_GREEN + "Type desired lore to add in chat"));
}
 
源代码12 项目: AnnihilationPro   文件: AreaCommand.java
@EventHandler(priority = EventPriority.LOW,ignoreCancelled = true)
public void playerCheck(PlayerInteractEvent event)
{
    if(event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)
    {
        final Player player = event.getPlayer();
        if(KitUtils.itemHasName(player.getItemInHand(), CustomItem.AREAWAND.getName()))
        {
            event.setCancelled(true);
            final Loc loc = new Loc(event.getClickedBlock().getLocation(),false);
            Callable<Object> b = new Callable<Object>(){
                @Override
                public Object call() throws Exception
                {
                    return loc;
                }};

            if(event.getAction() == Action.LEFT_CLICK_BLOCK)
            {
                player.setMetadata("A.Loc1", new LazyMetadataValue(AnnihilationMain.getInstance(),b));
                player.sendMessage(ChatColor.LIGHT_PURPLE+"Corner "+ChatColor.GOLD+"1 "+ChatColor.LIGHT_PURPLE+"set.");
            }
            else
            {
                player.setMetadata("A.Loc2", new LazyMetadataValue(AnnihilationMain.getInstance(),b));
                player.sendMessage(ChatColor.LIGHT_PURPLE+"Corner "+ChatColor.GOLD+"2 "+ChatColor.LIGHT_PURPLE+"set.");
            }
        }
    }
}
 
源代码13 项目: CardinalPGM   文件: Blitz.java
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
    Player player = event.getEntity();
    Optional<TeamModule> team = Teams.getTeamByPlayer(player);
    if (team.isPresent() && !team.get().isObserver()) {
        int oldMeta = this.getLives(player);
        player.removeMetadata("lives", Cardinal.getInstance());
        player.setMetadata("lives", new LazyMetadataValue(Cardinal.getInstance(), LazyMetadataValue.CacheStrategy.NEVER_CACHE, new BlitzLives(oldMeta - 1)));
        if (this.getLives(player) == 0) {
            Teams.getTeamById("observers").get().add(player, true, false);
            player.removeMetadata("lives", Cardinal.getInstance());
        }
    }
}
 
源代码14 项目: BedwarsRel   文件: AddTeamJoinCommand.java
@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;
}
 
源代码15 项目: ce   文件: Powergloves.java
@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;
}
 
源代码16 项目: SuperVanish   文件: JoinEvent.java
@Override
public void execute(Listener l, Event event) {
    try {
        if (event instanceof PlayerJoinEvent) {
            PlayerJoinEvent e = (PlayerJoinEvent) event;
            final Player p = e.getPlayer();
            // vanished:
            if (plugin.getVanishStateMgr().isVanished(p.getUniqueId())) {
                // Join message
                if (plugin.getSettings().getBoolean("MessageOptions.HideRealJoinQuitMessages")) {
                    e.setJoinMessage(null);
                    Broadcast.announceSilentJoin(p, plugin);
                }
                // collision
                try {
                    //noinspection deprecation
                    p.spigot().setCollidesWithEntities(false);
                } catch (NoClassDefFoundError | NoSuchMethodError ignored) {
                }
                // reminding message
                if (plugin.getSettings().getBoolean("MessageOptions.RemindVanishedOnJoin")) {
                    plugin.sendMessage(p, "RemindingMessage", p);
                }
                // re-add action bar
                if (plugin.getActionBarMgr() != null && plugin.getSettings().getBoolean(
                        "MessageOptions.DisplayActionBar")) {
                    plugin.getActionBarMgr().addActionBar(p);
                }
                // sleep state
                p.setSleepingIgnored(true);
                // adjust fly
                if (plugin.getSettings().getBoolean("InvisibilityFeatures.Fly.Enable")) {
                    p.setAllowFlight(true);
                }
                // metadata
                p.setMetadata("vanished", new FixedMetadataValue(plugin, true));
            } else {
                // not vanished:
                // metadata
                p.removeMetadata("vanished", plugin);
            }
            // not necessarily vanished:
            // recreate files msg
            if ((p.hasPermission("sv.recreatecfg") || p.hasPermission("sv.recreatefiles"))
                    && (plugin.getConfigMgr().isSettingsUpdateRequired()
                    || plugin.getConfigMgr().isMessagesUpdateRequired())) {
                String currentVersion = plugin.getDescription().getVersion();
                boolean isDismissed =
                        plugin.getPlayerData().getBoolean("PlayerData." + p.getUniqueId() + ".dismissed."
                                + currentVersion.replace(".", "_"), false);
                if (!isDismissed)
                    new BukkitRunnable() {
                        @Override
                        public void run() {
                            plugin.sendMessage(p, "RecreationRequiredMsg", p);
                        }
                    }.runTaskLater(plugin, 1);
            }
        }
    } catch (Exception er) {
        plugin.logException(er);
    }
}
 
源代码17 项目: uSkyBlock   文件: PatienceTester.java
public static void startRunning(Player player, String key) {
    player.setMetadata(key, new FixedMetadataValue(uSkyBlock.getInstance(), System.currentTimeMillis() + maxRunning));
}
 
源代码18 项目: BedwarsRel   文件: RemoveHoloCommand.java
@Override
public boolean execute(CommandSender sender, ArrayList<String> args) {
  if (!super.hasPermission(sender)) {
    return false;
  }

  final Player player = (Player) sender;
  player.setMetadata("bw-remove-holo", new FixedMetadataValue(BedwarsRel.getInstance(), true));
  if (BedwarsRel.getInstance().getHolographicInteractor().getType()
      .equalsIgnoreCase("HolographicDisplays")) {
    player.sendMessage(
        ChatWriter
            .pluginMessage(
                ChatColor.GREEN + BedwarsRel._l(player, "commands.removeholo.explain")));

  } else if (BedwarsRel.getInstance().getHolographicInteractor().getType()
      .equalsIgnoreCase("HologramAPI")) {

    for (Location location : BedwarsRel.getInstance().getHolographicInteractor()
        .getHologramLocations()) {
      if (player.getEyeLocation().getBlockX() == location.getBlockX()
          && player.getEyeLocation().getBlockY() == location.getBlockY()
          && player.getEyeLocation().getBlockZ() == location.getBlockZ()) {
        BedwarsRel.getInstance().getHolographicInteractor().onHologramTouch(player, location);
      }
    }
    BedwarsRel.getInstance().getServer().getScheduler().runTaskLater(BedwarsRel.getInstance(),
        new Runnable() {

          @Override
          public void run() {
            if (player.hasMetadata("bw-remove-holo")) {
              player.removeMetadata("bw-remove-holo", BedwarsRel.getInstance());
            }
          }

        }, 10L * 20L);

  }
  return true;
}
 
源代码19 项目: ProRecipes   文件: RecipeManager.java
public void askPermission(final Player p, String type){
	
	
	ItemBuilder.close(p);
	p.setMetadata("closed", new FixedMetadataValue(ProRecipes.getPlugin(), ""));
	ItemBuilder.sendMessage(p, m.getMessage("Recipe_Viewer_Title", ChatColor.GOLD + "Recipe Manager"),  m.getMessage("Choose_Permission", ChatColor.DARK_GREEN + "Type a permission. Type 'no' for no permission"));
	
	p.setMetadata("recipeViewer", new FixedMetadataValue(ProRecipes.getPlugin(), "choosePermission" + type));

}
 
源代码20 项目: ProRecipes   文件: RecipeBuilder.java
public void askPermission(final Player p){
	
	
	ItemBuilder.close(p);
	p.setMetadata("closed", new FixedMetadataValue(ProRecipes.getPlugin(), ""));
	ItemBuilder.sendMessage(p, m.getMessage("Recipe_Builder_Title", ChatColor.GOLD + "Recipe Builder") , m.getMessage("Choose_Permission", ChatColor.DARK_GREEN + "Type a permission. Type 'no' for no permission"));
	
	p.setMetadata("recipeBuilder", new FixedMetadataValue(ProRecipes.getPlugin(), "choosePermission"));

}