Java Code Examples for org.bukkit.entity.Player#setMetadata()
The following examples show how to use
org.bukkit.entity.Player#setMetadata() .
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: GameCreator.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
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 2
Source File: GameCreator.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
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 3
Source File: ControllablePlayerBase.java From EntityAPI with GNU Lesser General Public License v3.0 | 6 votes |
@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; }
Example 4
Source File: Tools.java From ce with GNU Lesser General Public License v3.0 | 6 votes |
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); }
Example 5
Source File: StickInteractEvent.java From StackMob-3 with GNU General Public License v3.0 | 6 votes |
@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); } } }
Example 6
Source File: RecipeBuilder.java From ProRecipes with GNU General Public License v2.0 | 6 votes |
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); }
Example 7
Source File: RemoveholoCommand.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@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; }
Example 8
Source File: Blitz.java From CardinalPGM with MIT License | 5 votes |
@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()); } } }
Example 9
Source File: AreaCommand.java From AnnihilationPro with MIT License | 5 votes |
@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."); } } } }
Example 10
Source File: ItemBuilder.java From ProRecipes with GNU General Public License v2.0 | 5 votes |
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")); }
Example 11
Source File: MainListener.java From ArmorStandTools with MIT License | 5 votes |
@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); }
Example 12
Source File: AssassinsBlade.java From ce with GNU Lesser General Public License v3.0 | 5 votes |
@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: ActionSetShape.java From TrMenu with MIT License | 5 votes |
@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()); } }
Example 14
Source File: JoinEvent.java From SuperVanish with Mozilla Public License 2.0 | 4 votes |
@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); } }
Example 15
Source File: PatienceTester.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
public static void startRunning(Player player, String key) { player.setMetadata(key, new FixedMetadataValue(uSkyBlock.getInstance(), System.currentTimeMillis() + maxRunning)); }
Example 16
Source File: Powergloves.java From ce with GNU Lesser General Public License v3.0 | 4 votes |
@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 17
Source File: RemoveHoloCommand.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
@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; }
Example 18
Source File: AddTeamJoinCommand.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
@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 19
Source File: RecipeManager.java From ProRecipes with GNU General Public License v2.0 | 3 votes |
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)); }
Example 20
Source File: RecipeBuilder.java From ProRecipes with GNU General Public License v2.0 | 3 votes |
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")); }