public void shoot(Player player){ setAttackTimer(getAttackTimer() + System.currentTimeMillis() - getLastAttackTimer()); setLastAttackTimer(System.currentTimeMillis()); if(getAttackTimer() < getShootCooldown()) return; /*if (hasBullets()) { System.out.println("Tiene balas: " + Integer.parseInt(lore.get(lore.size() - 1).split(" ")[1])); youShotM8(); }*/ Snowball snowball = player.getWorld().spawn(player.getEyeLocation(), Snowball.class); snowball.setVelocity(player.getLocation().getDirection().multiply(distance())); snowball.setShooter(player); snowball.setMetadata("twd", new FixedMetadataValue(WCTWD.getInstance(), "weapon_" + getId())); // player.playSound(player.getLocation(), sound, 1, 1); particle.display(particleData, 0, 0, 0, 1, 3, player.getLocation(), 20); }
public GameSign(Hub hub, AbstractGame game, String map, ChatColor color, String template, RestrictedVersion restrictedVersion, Sign sign) { this.hub = hub; this.game = game; this.map = map; this.color = color; this.template = template; this.restrictedVersion = restrictedVersion; this.sign = sign; this.sign.setMetadata("game", new FixedMetadataValue(hub, game.getCodeName())); this.sign.setMetadata("map", new FixedMetadataValue(hub, map)); hub.getScheduledExecutorService().scheduleAtFixedRate(this::scrollMapName, 500, 500, TimeUnit.MILLISECONDS); this.updateTask = hub.getServer().getScheduler().runTaskTimerAsynchronously(hub, this::update, 20L, 20L); }
/** * Cancel damages if the game doesn't activate them * Also set last damage cause of the damaged player * * @param event Event */ @EventHandler public void onEntityDamage(EntityDamageEvent event) { if (event.getEntity() instanceof Player) { if (!this.game.isDamagesActivated()) { event.setCancelled(true); return; } if (event.getCause() != EntityDamageEvent.DamageCause.ENTITY_ATTACK && event.getCause() != EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) { while (event.getEntity().hasMetadata("lastDamager")) event.getEntity().removeMetadata("lastDamager", this.game.getPlugin()); event.getEntity().setMetadata("lastDamager", new FixedMetadataValue(this.game.getPlugin(), event.getCause())); } } }
/** * Launch 2 more arrows when one is launched * * @param event Event */ @EventHandler public void onProjectileLaunch(ProjectileLaunchEvent event) { if (event.getEntity().getType() != EntityType.ARROW || !(event.getEntity().getShooter() instanceof Player) || event.getEntity().hasMetadata("TAM")) return; final Vector velocity = event.getEntity().getVelocity(); for(int i = 0; i < 2; i++) { this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () -> { EntityArrow entityArrow = new EntityArrow(((CraftWorld)event.getEntity().getWorld()).getHandle(), ((CraftLivingEntity)event.getEntity().getShooter()).getHandle(), 1F); entityArrow.shoot(((CraftLivingEntity)event.getEntity().getShooter()).getHandle().pitch, ((CraftLivingEntity)event.getEntity().getShooter()).getHandle().yaw, 0.0F, 3.0F, 1.0F); entityArrow.getBukkitEntity().setMetadata("TAM", new FixedMetadataValue(this.plugin, true)); entityArrow.getBukkitEntity().setVelocity(velocity); ((CraftWorld)event.getEntity().getWorld()).getHandle().addEntity(entityArrow); }, 5L * (i + 1)); } }
@EventHandler public void handleInteract(@Nonnull PlayerInteractEvent event) { if (event.getAction() == org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null) { if (event.getClickedBlock().getState() instanceof Sign) { Sign sign = (Sign) event.getClickedBlock().getState(); if (sign.hasMetadata("UpdateCooldown")) { long cooldown = sign.getMetadata("UpdateCooldown").get(0).asLong(); if (cooldown > System.currentTimeMillis() - 1 * 1000) { return; } } sign.update(); sign.setMetadata("UpdateCooldown", new FixedMetadataValue(voxelGamesLib, System.currentTimeMillis())); } } }
@EventHandler public void onPlayerMoveEvent(PlayerMoveEvent event){ Player p = event.getPlayer(); //p.sendMessage(""+p.getFallDistance()); //p.sendMessage(""+p.getVelocity().getY()); if(playerCanFall(p)){ //fix NCP false alarm //Utility.ncpFix(p); p.setGliding(true); FixedMetadataValue m = new FixedMetadataValue(plugin, null); p.setMetadata("falling", m); }else if(p.hasMetadata("falling")){ p.removeMetadata("falling", plugin); } }
@EventHandler public void onInteract(PlayerInteractEvent e) { if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { if (e.getClickedBlock().getType() == Material.CAULDRON) { if (e.getClickedBlock().getLocation().add(0, -1, 0).getBlock().getType() == Material.DIAMOND_BLOCK) { Item item = e.getPlayer().getWorld().dropItem(e.getClickedBlock().getLocation().add(0.5, 2, 0.5), e.getPlayer().getEquipment().getItemInMainHand()); item.setMetadata("item-owner", new FixedMetadataValue(NationZ.plugin, e.getPlayer().getUniqueId().toString())); item.setVelocity(new Vector(0, 0, 0)); item.setCustomName(item.getName()); item.setCustomNameVisible(true); e.getPlayer().getEquipment().setItemInMainHand(null); e.setCancelled(true); } } } }
@EventHandler public void onEntityExplode(EntityExplodeEvent event) { if (event.getEntity() != null) { if (event.getEntity().getType() == EntityType.PRIMED_TNT) { for (Block block : event.blockList()) { if (block.getType() == Material.TNT && getWhoPlaced(event.getEntity()) != null) { Location location = block.getLocation(); tntPlaced.put(location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ(), getWhoPlaced(event.getEntity())); } } for (Entity entity : event.getEntity().getNearbyEntities(8, 8, 8)) { // F.debug("Found tnt"); if (entity instanceof TNTPrimed) { UUID playerUUID = getWhoPlaced(event.getEntity()); if(playerUUID != null) { Dispenser dispenser; // F.debug("found placer: " + Bukkit.getServer().getPlayer(playerUUID)); entity.setMetadata("source", new FixedMetadataValue(GamePlate.getInstance(), playerUUID)); } } } } } }
@SuppressWarnings("deprecation") @Override public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType) { if (!WorldGuardUtils.hasBypass(player)) { if (!player.hasMetadata("WGEFP-TPOEF")) { com.sk89q.worldedit.Location location = toSet.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.TELEPORT_ON_ENTRY); if (location != null) { player.setMetadata("WGEFP-TPOEF", new FixedMetadataValue(WorldGuardExtraFlagsPlugin.getPlugin(), null)); player.teleport(BukkitUtil.toLocation(location)); } } } return true; }
@SuppressWarnings("deprecation") @Override public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType) { if (!WorldGuardUtils.hasBypass(player)) { if (!player.hasMetadata("WGEFP-TPOEF")) { for (ProtectedRegion exitd : exited) { com.sk89q.worldedit.Location location = exitd.getFlag(FlagUtils.TELEPORT_ON_EXIT); if (location != null) { player.setMetadata("WGEFP-TPOEF", new FixedMetadataValue(WorldGuardExtraFlagsPlugin.getPlugin(), null)); player.teleport(BukkitUtil.toLocation(location)); break; } } } } return true; }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onEntitySpawn(CreatureSpawnEvent event) { LivingEntity entity = event.getEntity(); if(!this.isMonster(entity)) return; SpawnReason reason = event.getSpawnReason(); if(reason == SpawnReason.SPAWNER || reason == SpawnReason.SPAWNER_EGG) { entity.setMetadata(this.ALLOW_TARGET_TAG, new FixedMetadataValue(GPFlags.instance, new Boolean(true))); return; } Flag flag = this.GetFlagInstanceAtLocation(event.getLocation(), null); if(flag == null) return; event.setCancelled(true); }
@Override public void showInFrame(Player player, int entityId, String debugInfo) { if (!isViewing(player)) { return; } //Create the ItemStack with the player's map ID ItemStack itemStack = new ItemStack(Material.MAP, 1, getMapId(player)); if (debugInfo != null) { //Add the debug info to the display ItemMeta itemMeta = itemStack.getItemMeta(); itemMeta.setDisplayName(debugInfo); itemStack.setItemMeta(itemMeta); } ItemFrame itemFrame = MapManagerPlugin.getItemFrameById(player.getWorld(), entityId); if (itemFrame != null) { //Add a reference to this MapWrapper (can be used in MapWrapper#getWrapperForId) itemFrame.removeMetadata("MAP_WRAPPER_REF", MapManagerPlugin.instance); itemFrame.setMetadata("MAP_WRAPPER_REF", new FixedMetadataValue(MapManagerPlugin.instance, DefaultMapWrapper.this)); } sendItemFramePacket(player, entityId, itemStack); }
@Override public void change(Event e, Object[] delta, Changer.ChangeMode mode){ if (object.getSingle(e) instanceof Metadatable) { Metadatable metadata = (Metadatable)object.getSingle(e); if (mode == ChangeMode.SET) { if (metadata.hasMetadata(string.getSingle(e))) { metadata.removeMetadata(string.getSingle(e), Skellett.plugin); } metadata.setMetadata(string.getSingle(e), (MetadataValue)new FixedMetadataValue(Skellett.plugin, (Object)(delta[0]))); } else if (mode == ChangeMode.RESET || mode == ChangeMode.DELETE) { if (metadata.hasMetadata(string.getSingle(e))) { metadata.removeMetadata(string.getSingle(e), Skellett.plugin); } } } }
@Command(aliases = {"msg", "message", "pm", "privatemessage", "whisper", "tell"}, desc = "Send a private message to a player.", usage = "<player> <message>", min = 2) public static void pm(final CommandContext cmd, CommandSender sender) throws CommandException { if (!(sender instanceof Player)) throw new CommandException(ChatConstant.ERROR_PLAYER_COMMAND.getMessage(Locale.getDefault().toString())); Player target = Bukkit.getPlayer(cmd.getString(0), sender); if (target == null) { throw new CommandException(ChatConstant.ERROR_PLAYER_NOT_FOUND.getMessage(((Player) sender).getLocale())); } if (Settings.getSettingByName("PrivateMessages") == null || Settings.getSettingByName("PrivateMessages").getValueByPlayer(target).getValue().equalsIgnoreCase("all")) { target.sendMessage(ChatColor.GRAY + "(From " + TeamUtils.getTeamColorByPlayer((Player) sender) + ((Player) sender).getDisplayName() + ChatColor.GRAY + "): " + ChatColor.RESET + cmd.getJoinedStrings(1)); sender.sendMessage(ChatColor.GRAY + "(To " + TeamUtils.getTeamColorByPlayer(target) + target.getDisplayName() + ChatColor.GRAY + "): " + ChatColor.RESET + cmd.getJoinedStrings(1)); target.setMetadata("reply", new FixedMetadataValue(Cardinal.getInstance(), sender)); } else { sender.sendMessage(new LocalizedChatMessage(ChatConstant.ERROR_PLAYER_DISABLED_PMS, target.getDisplayName()).getMessage(((Player) sender).getLocale())); } }
@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(new LocalizedChatMessage(ChatConstant.ERROR_PLAYER_COMMAND).getMessage(ChatUtils.getLocale(sender))); } if (!((Player) sender).hasMetadata("reply")) { throw new CommandException(new LocalizedChatMessage(ChatConstant.ERROR_NO_MESSAGES).getMessage(ChatUtils.getLocale(sender))); } Player target = (Player) ((Player) sender).getMetadata("reply").get(0).value(); if (target == null) { throw new CommandException(ChatConstant.ERROR_PLAYER_NOT_FOUND.getMessage(((Player) sender).getLocale())); } if (Settings.getSettingByName("PrivateMessages") == null || Settings.getSettingByName("PrivateMessages").getValueByPlayer(target).getValue().equalsIgnoreCase("all")) { target.sendMessage(ChatColor.GRAY + "(From " + TeamUtils.getTeamColorByPlayer((Player) sender) + ((Player) sender).getDisplayName() + ChatColor.GRAY + "): " + ChatColor.RESET + cmd.getJoinedStrings(0)); sender.sendMessage(ChatColor.GRAY + "(To " + TeamUtils.getTeamColorByPlayer(target) + target.getDisplayName() + ChatColor.GRAY + "): " + ChatColor.RESET + cmd.getJoinedStrings(0)); target.setMetadata("reply", new FixedMetadataValue(Cardinal.getInstance(), sender)); } else { sender.sendMessage(new LocalizedChatMessage(ChatConstant.ERROR_PLAYER_DISABLED_PMS, target.getDisplayName()).getMessage(((Player) sender).getLocale())); } }
@Nullable public Entity spawn(NPCData npcData, Location location) { Preconditions.checkNotNull(npcData, "npc data cannot be null."); Preconditions.checkNotNull(location, "location cannot be null."); World world = location.getWorld(); // temporary fix for EntitySpawnEvent being cancelled... spawning = true; Entity entity = world.spawnEntity(location, npcData.getType()); spawning = false; NPCSpawnEvent event = new NPCSpawnEvent(entity, npcData); owner.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { entity.remove(); return null; } entity.setMetadata(METADATA_KEY, new FixedMetadataValue(this.owner, npcData.getId())); this.npcs.add(entity); return entity; }
@EventHandler(ignoreCancelled = true) public void onNPCSpawn(NPCSpawnEvent event) { String name = getData(event.getData(), NPCProperties.NAME, String.class); if (name == null) { return; } Preconditions.checkArgument(!name.isEmpty(), "name cannot be empty."); Entity npc = event.getNpc(); ArmorStand armorStand = (ArmorStand) npcManager.spawn(this.blankNametag, npc.getLocation()); if (armorStand == null) { warn("ArmorStand for %s could not be spawned.", event.getData().getId()); return; } armorStand.setCustomName(name); armorStand.setMetadata(nametagMetadata, new FixedMetadataValue(this.npcManager.getOwner(), npc.getEntityId())); this.datas.put(npc, new NameData(npc, armorStand)); if (this.task == null) { this.task = new ArmorStandTask(); } }
@Override public void onItemClick(ItemClickEvent event) { if(t == 0) { player.setMetadata("titleEdit", new FixedMetadataValue(Bukkit.getPluginManager().getPlugin("SteakGUI"), menu.getName())); new MessageHandler().sendMessage(player, "&b제목을 입력해 주세요.(16자 이하) 취소하시려면 'cancel' 혹은 '취소' 를 입력하세요."); event.setWillClose(true); } else if(t == 1) { new LineSetting().show(menu, player); } else if(t == 2) { if(!event.getClick().isShiftClick()) { player.setMetadata("importChest", new FixedMetadataValue(Bukkit.getPluginManager().getPlugin("SteakGUI"), menu.getName())); new MessageHandler().sendMessage(player, "&b가져올 체스트를 선택해 주세요."); event.setWillClose(true); } else { player.setMetadata("importChestForce", new FixedMetadataValue(Bukkit.getPluginManager().getPlugin("SteakGUI"), menu.getName())); new MessageHandler().sendMessage(player, "&c가져올 체스트를 선택해 주세요.(덮어쓰기 모드)"); event.setWillClose(true); } } else if(t == 3) { new EditorMain().show(menu, player); } }
@Override public void onItemClick(ItemClickEvent event) { ItemTask editTask = menu.getItemArray().get(slot).getTask(task); if(t == 0) { new MessageHandler().sendMessage(event.getPlayer(), "&a메시지를 입력하세요."); player.setMetadata("messageSet", new FixedMetadataValue(Bukkit.getPluginManager().getPlugin("SteakGUI"), new Object[]{menu.getName(), slot, task})); event.setWillClose(true); } else if(t == 1) { new NewTaskSelector().show(menu, player, slot, task); } else if(t == 2) { menu.getItemArray().get(slot).delTask(task); MenuFileHandler.saveMenu(menu); new ItemTaskEditor().show(MenuFileHandler.loadMenu(menu.getName()), player, slot); } else if(t == 3) { new TaskClickTypeEditor().show(menu, player, slot, task); } else { new ItemTaskEditor().show(menu, player, slot); } }
@Override public void onItemClick(ItemClickEvent event) { ItemTask editTask = menu.getItemArray().get(slot).getTask(task); if(t == 0) { new MessageHandler().sendMessage(event.getPlayer(), "&a매뉴 이름을 입력하세요."); player.setMetadata("menuSet", new FixedMetadataValue(Bukkit.getPluginManager().getPlugin("SteakGUI"), new Object[]{menu.getName(), slot, task})); event.setWillClose(true); } else if(t == 1) { new NewTaskSelector().show(menu, player, slot, task); } else if(t == 2) { menu.getItemArray().get(slot).delTask(task); MenuFileHandler.saveMenu(menu); new ItemTaskEditor().show(MenuFileHandler.loadMenu(menu.getName()), player, slot); } else if(t == 3) { new TaskClickTypeEditor().show(menu, player, slot, task); } else { new ItemTaskEditor().show(menu, player, slot); } }
@Override public void onItemClick(ItemClickEvent event) { ItemTask editTask = menu.getItemArray().get(slot).getTask(task); if(t == 0) { new MessageHandler().sendMessage(event.getPlayer(), "&a메시지를 입력하세요."); player.setMetadata("messageSet", new FixedMetadataValue(Bukkit.getPluginManager().getPlugin("SteakGUI"), new Object[]{menu.getName(), slot, task})); event.setWillClose(true); } else if(t == 1) { new NewTaskSelector().show(menu, player, slot, task); } else if(t == 2) { menu.getItemArray().get(slot).delTask(task); MenuFileHandler.saveMenu(menu); new ItemTaskEditor().show(MenuFileHandler.loadMenu(menu.getName()), player, slot); } else if(t == 3) { menu.getItemArray().get(slot).delTask(task); new TaskClickTypeEditor().show(menu, player, slot, task); } else { new ItemTaskEditor().show(menu, player, slot); } }
@EventHandler public void onCreatureSpawn(CreatureSpawnEvent event) { if (event == null || event.isCancelled() || event.getLocation() == null || !plugin.isSkyWorld(event.getLocation().getWorld())) { return; // Bail out, we don't care } if (!event.isCancelled() && ADMIN_INITIATED.contains(event.getSpawnReason())) { return; // Allow it, the above method would have blocked it if it should be blocked. } checkLimits(event, event.getEntity().getType(), event.getLocation()); if (!event.isCancelled() && event.getEntity() instanceof Squid) { Location loc = event.getLocation(); int z = loc.getBlockZ(); int x = loc.getBlockX(); if (loc.getWorld().getBiome(x, z) == Biome.DEEP_OCEAN && LocationUtil.findRoofBlock(loc).getType() == Material.PRISMARINE) { loc.getWorld().spawnEntity(loc, EntityType.GUARDIAN); event.setCancelled(true); } } if (!event.isCancelled() && event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.BUILD_WITHER && event.getEntity() instanceof Wither) { IslandInfo islandInfo = plugin.getIslandInfo(event.getLocation()); if (islandInfo != null && islandInfo.getLeader() != null) { event.getEntity().setCustomName(I18nUtil.tr("{0}''s Wither", islandInfo.getLeader())); event.getEntity().setMetadata("fromIsland", new FixedMetadataValue(plugin, islandInfo.getName())); } } }
@Override @SuppressWarnings("unchecked") public void register() { if (block == null) { Map<String, Object> dataMap = (Map<String, Object>) new Yaml().load(model.getData()); World world = Bukkit.getWorld((String) dataMap.get("w")); Location loc = new Location(world, (Integer) dataMap.get("x"), (Integer) dataMap.get("y"), (Integer) dataMap.get("z")); block = loc.getBlock(); if (block == null) { throw new RuntimeException("Couldn't find block at pos" + loc.toString()); } } MetadataValue meta = new FixedMetadataValue(plugin, this); block.setMetadata(META_KEY, meta); super.register(); }
@Override public CastResult onCast(User user, int power, String[] args) { final Player player = user.getPlayer(); final int amount = this.amount * power; Bukkit.getScheduler().runTaskTimer(Zephyrus.getPlugin(), new Runnable() { int shots = amount; @Override public void run() { if (shots > 0 && player.isOnline()) { player.launchProjectile(Arrow.class) .setMetadata("ignore_pickup", new FixedMetadataValue(Zephyrus.getPlugin(), true)); shots--; } } }, 1, 1); return CastResult.SUCCESS; }
/** * Adds a player to the arena and calls an ArenaJoinEvent. * * @param player * Player to add */ public final synchronized void addPlayer(Player player) { // Check if player is already in arena if (player.hasMetadata(META_IDENTIFIER)) { // Get Metdata for the identifier List<MetadataValue> values = player.getMetadata(META_IDENTIFIER); // Cycle through values for (MetadataValue value : values) // Check if value is instance of Arena if (value.value() instanceof Arena) // Remove player from arena ((Arena) value.value()).removePlayer(player); } // Add player to this arena players.add(player); // Update Metadata of player player.setMetadata(META_IDENTIFIER, new FixedMetadataValue(plugin, this)); // Call the ArenaJoinEvent Bukkit.getPluginManager().callEvent(new ArenaJoinEvent(player, this)); }
@EventHandler(ignoreCancelled = true) public void onSandCannon(EntityChangeBlockEvent event) { BukkitEntity entity = new BukkitEntity(event.getEntity()); if (manager.isPlotWorld(entity) && event.getEntityType().equals(EntityType.FALLING_BLOCK)) { if (event.getTo().equals(Material.AIR)) { entity.setMetadata("plotFallBlock", new FixedMetadataValue(plugin, event.getBlock().getLocation())); } else { List<MetadataValue> values = entity.getMetadata("plotFallBlock"); if (!values.isEmpty()) { org.bukkit.Location spawn = (org.bukkit.Location) (values.get(0).value()); org.bukkit.Location createdNew = event.getBlock().getLocation(); if (spawn.getBlockX() != createdNew.getBlockX() || spawn.getBlockZ() != createdNew.getBlockZ()) { event.setCancelled(true); } } } } }
protected InvisibleBlock() { Bukkit.getScheduler().runTask(GameHandler.getGameHandler().getPlugin(), new Runnable() { @Override public void run() { for (Chunk chunk : GameHandler.getGameHandler().getMatchWorld().getLoadedChunks()) { for (Block block36 : chunk.getBlocks(Material.getMaterial(36))) { block36.setType(Material.AIR); block36.setMetadata("block36", new FixedMetadataValue(GameHandler.getGameHandler().getPlugin(), true)); } for (Block door : chunk.getBlocks(Material.IRON_DOOR_BLOCK)) { if (door.getRelative(BlockFace.DOWN).getType() != Material.IRON_DOOR_BLOCK && door.getRelative(BlockFace.UP).getType() != Material.IRON_DOOR_BLOCK) door.setType(Material.BARRIER); } } } }); }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onVehicleCreate(VehicleCreateEvent event) { Vehicle entity = event.getVehicle(); Location location = BukkitUtil.getLocation(entity); PlotArea area = location.getPlotArea(); if (area == null) { return; } Plot plot = area.getOwnedPlotAbs(location); if (plot == null || checkEntity(entity, plot)) { entity.remove(); return; } if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) { entity.setMetadata("plot", new FixedMetadataValue((Plugin) PS.get().IMP, plot)); } }
@EventHandler public void onInteract(PlayerInteractEvent e) { if(e.isCancelled()) { return; } if(e.getAction() == Action.RIGHT_CLICK_BLOCK) { if(e.getClickedBlock().getType() == Material.CHEST) { Chest chest = (Chest) e.getClickedBlock().getState(); if(chest.hasMetadata("crate_owner")) { String owner = ((FixedMetadataValue)chest.getMetadata("crate_owner").get(0)).asString(); if(!e.getPlayer().getName().equalsIgnoreCase(owner)) { e.getPlayer().sendMessage(ChatColor.RED + "this crate does not belongs to you!."); e.setCancelled(true); } } } } }
@Override public boolean use(Player player) { boolean containsBow = false; for (ItemStack item : player.getInventory().getContents()) { if (item != null) { if (item.getType() == Material.BOW) { containsBow = true; break; } } } if (containsBow) { if (player.getInventory().containsAtLeast(new ItemStack(Material.ARROW), 1)) { Arrow arrow = player.launchProjectile(Arrow.class); arrow.setMetadata("isRazorShot", new FixedMetadataValue(plugin, true)); player.getInventory().removeItem(new ItemStack(Material.ARROW)); return true; } else { player.sendMessage(ChatColor.RED + "You require an arrow."); } } else { player.sendMessage(ChatColor.RED + "You require a bow."); } return false; }
private void display(CommandSender sender, String playerName) { if (sender instanceof Player) { McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName()); long cooldownMillis = Math.max(Config.getInstance().getDatabasePlayerCooldown(), 1750); if (mcMMOPlayer.getDatabaseATS() + cooldownMillis > System.currentTimeMillis()) { sender.sendMessage(LocaleLoader.getString("Commands.Database.Cooldown")); return; } if (((Player) sender).hasMetadata(mcMMO.databaseCommandKey)) { sender.sendMessage(LocaleLoader.getString("Commands.Database.Processing")); return; } else { ((Player) sender).setMetadata(mcMMO.databaseCommandKey, new FixedMetadataValue(mcMMO.p, null)); } mcMMOPlayer.actualizeDatabaseATS(); } boolean useBoard = (sender instanceof Player) && (Config.getInstance().getRankUseBoard()); boolean useChat = !useBoard || Config.getInstance().getRankUseChat(); new McrankCommandAsyncTask(playerName, sender, useBoard, useChat).runTaskAsynchronously(mcMMO.p); }
@EventHandler public void onChunkLoad(ChunkLoadEvent event) { final Chunk chunk = event.getChunk(); Bukkit.getScheduler().runTask(GameHandler.getGameHandler().getPlugin(), new Runnable() { @Override public void run() { for (Block block36 : chunk.getBlocks(Material.getMaterial(36))) { block36.setType(Material.AIR); block36.setMetadata("block36", new FixedMetadataValue(GameHandler.getGameHandler().getPlugin(), true)); } for (Block door : chunk.getBlocks(Material.IRON_DOOR_BLOCK)) { if (door.getRelative(BlockFace.DOWN).getType() != Material.IRON_DOOR_BLOCK && door.getRelative(BlockFace.UP).getType() != Material.IRON_DOOR_BLOCK) door.setType(Material.BARRIER); } } }); }
@Override public boolean use(Player player) { boolean containsBow = false; for (ItemStack item : player.getInventory().getContents()) { if (item != null) { if (item.getType() == Material.BOW) { containsBow = true; break; } } } if (containsBow) { if (player.getInventory().containsAtLeast(new ItemStack(Material.ARROW), 1) && player.getInventory().containsAtLeast(new ItemStack(Material.STRING), 1)) { Plugin plugin = Bukkit.getServer().getServicesManager().getRegistration(SkillsPlugin.class).getProvider(); final Arrow arrow = player.launchProjectile(Arrow.class); arrow.setMetadata("isSnareShot", new FixedMetadataValue(plugin, true)); player.getInventory().removeItem(new ItemStack(Material.ARROW), new ItemStack(Material.STRING)); return true; } else { player.sendMessage(ChatColor.RED + "You require some string and an arrow to create a snare shot."); } } else { player.sendMessage(ChatColor.RED + "You require a bow to launch a snare shot."); } return false; }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityShootBow(EntityShootBowEvent event) { Entity projectile = event.getProjectile(); if (!(projectile instanceof Arrow)) { return; } ItemStack bow = event.getBow(); if (bow != null && bow.containsEnchantment(Enchantment.ARROW_INFINITE)) { projectile.setMetadata(mcMMO.infiniteArrowKey, mcMMO.metadataValue); } projectile.setMetadata(mcMMO.bowForceKey, new FixedMetadataValue(plugin, Math.min(event.getForce() * AdvancedConfig.getInstance().getForceMultiplier(), 1.0))); projectile.setMetadata(mcMMO.arrowDistanceKey, new FixedMetadataValue(plugin, projectile.getLocation())); }
@EventHandler public void onPlayerJoin(PlayerJoinEvent event) { List<String> channelList; if (!event.getPlayer().hasMetadata(MetaKeys.CHANNEL_LIST)) { event.getPlayer().setMetadata(MetaKeys.CHANNEL_LIST, new FixedMetadataValue(this, new LinkedList<String>())); ConfigurationSection cfg = this.getPlayerData(event.getPlayer()); List<String> channels; if (!cfg.contains(MetaKeys.CHANNEL_LIST)) { channels = new ArrayList<String>(); channels.add("G"); cfg.set(MetaKeys.CHANNEL_LIST, channels); } channels = cfg.getStringList(MetaKeys.CHANNEL_LIST); channelList = new ArrayList<String>(channels); } else { channelList = new ArrayList<String>((Collection<? extends String>) event.getPlayer().getMetadata(MetaKeys.CHANNEL_LIST).get(0).value()); } Collections.reverse(channelList); for (String c: channelList) { if (channelManager.channelExists(c)) { channelManager.joinChannel(event.getPlayer(), channelManager.getChannel(c), null); } } }
@Override public void onExecute(Player p, LinkedList<String> args) throws CommandError { Sound snd = null; if (args.size() > 0) { snd = Sound.valueOf(args.peek().toUpperCase()); if (snd == null) { throw new CommandError("Unknown Sound: " + args.peek()); } } ConfigurationSection cfg = plugin.getPlayerData(p); cfg.set(MetaKeys.PM_NOTIFICATION, snd == null ? "" : snd.name()); p.setMetadata(MetaKeys.PM_NOTIFICATION, new FixedMetadataValue(plugin, snd)); String info = "cleared."; if (snd != null) { info = "set to " + snd.name() + "."; p.playSound(p.getLocation(), snd, 10, 1); } plugin.send(p, "Your incoming private messages notification has been " + info); }
@Override public boolean use(Player player) { boolean containsBow = false; for (ItemStack item : player.getInventory().getContents()) { if (item != null) { if (item.getType() == Material.BOW) { containsBow = true; break; } } } if (containsBow) { if (player.getInventory().containsAtLeast(new ItemStack(Material.ARROW), 1) && player.getInventory().containsAtLeast(new ItemStack(Material.FERMENTED_SPIDER_EYE), 1)) { Plugin plugin = Bukkit.getServer().getServicesManager().getRegistration(SkillsPlugin.class).getProvider(); final Arrow arrow = player.launchProjectile(Arrow.class); arrow.setMetadata("isPoisonArrow", new FixedMetadataValue(plugin, true)); player.getInventory().removeItem(new ItemStack(Material.ARROW), new ItemStack(Material.FERMENTED_SPIDER_EYE)); return true; } else { player.sendMessage(ChatColor.RED + "You require a fermented spider eye and an arrow to create a poisoned arrow."); } } else { player.sendMessage(ChatColor.RED + "You require a bow to launch a poisoned arrow."); } return false; }
protected boolean onPortal(Entity entity) { // Mob arenas eventually! if (!(entity instanceof Player)) { return false; } Player player = ((Player)entity).getPlayer(); Arena arena = controller.getArena(player); if (arena != null && arena.getPortalDamage() > 0) { String portalDeathMessage = arena.getPortalDeathMessage(); if (portalDeathMessage != null && !portalDeathMessage.isEmpty()) { player.setMetadata("death_message", new FixedMetadataValue(controller.getPlugin(), portalDeathMessage)); } player.damage(arena.getPortalDamage()); if (portalDeathMessage != null && !portalDeathMessage.isEmpty()) { player.removeMetadata("death_message", controller.getPlugin()); } return true; } return false; }
@EventHandler public void onItemDrop(PlayerDropItemEvent event) { RacerHandler racerHandler = plugin.getRacerHandler(); Racer racer = racerHandler.getRacer(event.getPlayer()); for (Powerup powerup : plugin.getPowerupsRegistry().getPowerups()) { if (powerup.getItem().getType() == event.getItemDrop().getItemStack().getType() && powerup.getItem().getDurability() == event.getItemDrop().getItemStack().getDurability() && !racer.inventoryIsSpinning()) { powerup.doOnDrop(racerHandler.getRacer(event.getPlayer()), event.getItemDrop()); if (powerup.cancelledEvents().contains(Powerup.ActionType.DROP) || powerup.cancelledEvents().contains(Powerup.ActionType.ALL)) { event.setCancelled(true); } else { event.getItemDrop().setMetadata("whoDropped", new FixedMetadataValue(plugin, event.getPlayer().getUniqueId().toString())); } return; } else if (racer.inventoryIsSpinning()) { event.setCancelled(true); } } }
public void died(Player player) { ArenaPlayer arenaPlayer = new ArenaPlayer(this, player); if (isStarted()) { if (players.contains(arenaPlayer)) { deadPlayers.add(arenaPlayer); players.remove(arenaPlayer); Location specroom = getLoseLocation(); player.setMetadata("respawnLocation", new FixedMetadataValue(controller.getPlugin(), specroom)); player.sendMessage(ChatColor.AQUA + "You have lost - Better luck next time!"); } } else { if (queue.contains(arenaPlayer)) { player.sendMessage(ChatColor.RED + "You died before the match even started!"); } queue.remove(arenaPlayer); } player.removeMetadata("arena", controller.getPlugin()); check(); }