org.bukkit.metadata.FixedMetadataValue Java Examples

The following examples show how to use org.bukkit.metadata.FixedMetadataValue. 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: RecipeBuilder.java    From ProRecipes with GNU General Public License v2.0 6 votes vote down vote up
public void openRecipeBuilder(final Player p, final String type){
	ItemBuilder.close(p);
	ItemBuilder.sendMessage(p, m.getMessage("Recipe_Builder_Title", ChatColor.GOLD + "Recipe Builder") , m.getMessage("Recipe_Builder_Insert", ChatColor.DARK_GREEN + "Insert the desired result"));
	
	ProRecipes.getPlugin().getServer().getScheduler().runTaskLater(ProRecipes.getPlugin(), new Runnable(){

		@Override
		public void run() {
			p.setMetadata("recipeBuilder", new FixedMetadataValue(ProRecipes.getPlugin(), "itemRequest" + type));
			p.openWorkbench(null, true);
			//Inventory i = RPGRecipes.getPlugin().getServer().createInventory(p, InventoryType.WORKBENCH, "ItemBuilder");
			//p.openInventory(i);
		}
		
	}, ProRecipes.getPlugin().wait);
	
}
 
Example #2
Source File: SkullPlaceHolders.java    From VoxelGamesLibv2 with MIT License 6 votes vote down vote up
@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 Skull) {
            Skull skull = (Skull) event.getClickedBlock().getState();
            if (skull.hasMetadata("UpdateCooldown")) {
                long cooldown = skull.getMetadata("UpdateCooldown").get(0).asLong();
                if (cooldown > System.currentTimeMillis() - 1 * 1000) {
                    return;
                }
            }
            skull.update();
            skull.setMetadata("UpdateCooldown", new FixedMetadataValue(voxelGamesLib, System.currentTimeMillis()));
        }
    }
}
 
Example #3
Source File: SignPlaceholders.java    From VoxelGamesLibv2 with MIT License 6 votes vote down vote up
@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()));
        }
    }
}
 
Example #4
Source File: StickInteractEvent.java    From StackMob-3 with GNU General Public License v3.0 6 votes vote down vote up
@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 #5
Source File: ReceivedDamageEvent.java    From StackMob-3 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onDamageReceived(EntityDamageEvent event) {
    if(event.getEntity() instanceof LivingEntity){
        if(StackTools.hasValidStackData(event.getEntity())){
            LivingEntity entity = (LivingEntity) event.getEntity();
            if(sm.getCustomConfig().getBoolean("kill-step-damage.enabled")){
                double healthAfter = entity.getHealth() - event.getFinalDamage();
                if(healthAfter <= 0){
                    entity.setMetadata(GlobalValues.LEFTOVER_DAMAGE, new FixedMetadataValue(sm, Math.abs(healthAfter)));
                }
            }

            if(!sm.getCustomConfig().getStringList("multiply-damage-received.cause-blacklist")
                    .contains(event.getCause().toString())) {
                if(event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK){
                    return;
                }
                int stackSize = StackTools.getSize(entity);
                double extraDamage = event.getDamage() + ((event.getDamage() * (stackSize - 1) * 0.25));
                event.setDamage(extraDamage);
            }
        }
    }
}
 
Example #6
Source File: SpawnEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent event) {
    if (event == null || !plugin.getWorldManager().isSkyAssociatedWorld(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.getEntity() instanceof WaterMob) {
        Location loc = event.getLocation();
        if (isDeepOceanBiome(loc) && isPrismarineRoof(loc)) {
            loc.getWorld().spawnEntity(loc, EntityType.GUARDIAN);
            event.setCancelled(true);
        }
    }
    if (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()));
        }
    }
}
 
Example #7
Source File: RecipeBuilder.java    From ProRecipes with GNU General Public License v2.0 6 votes vote down vote up
private void openMutliCraft(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("Recipe_Builder_MultiCraft_Title", "Multi-Craft"),  
			m.getMessage("Recipe_Builder_MultiCraft_Add", ChatColor.DARK_GREEN + "Add ingredients on left, results on right"));
	
	ProRecipes.getPlugin().getServer().getScheduler().runTaskLater(ProRecipes.getPlugin(), new Runnable(){

		@Override
		public void run() {
			p.setMetadata("recipeBuilder", new FixedMetadataValue(ProRecipes.getPlugin(), "craftRecipeChest"));
			p.openInventory(ProRecipes.getPlugin().getRecipes().createMultiTable(p, 0));
			
		}
		
	}, ProRecipes.getPlugin().wait);
}
 
Example #8
Source File: PrivateMessageCommands.java    From CardinalPGM with MIT License 6 votes vote down vote up
@Command(aliases = {"reply", "r"}, desc = "Reply to a private message", min = 1)
public static void reply(final CommandContext cmd, CommandSender sender) throws CommandException {
    if (!(sender instanceof Player)) {
        throw new CommandException(ChatConstant.ERROR_PLAYER_COMMAND.getMessage(ChatUtil.getLocale(sender)));
    }
    Player player = (Player) sender;
    if (!player.hasMetadata("reply")) {
        throw new CommandException(ChatConstant.ERROR_NO_MESSAGES.getMessage(ChatUtil.getLocale(sender)));
    }
    Player target = (Player) player.getMetadata("reply").get(0).value();
    if (target == null) {
        throw new CommandException(ChatConstant.ERROR_PLAYER_NOT_FOUND.getMessage(ChatUtil.getLocale(sender)));
    }
    if (Settings.getSettingByName("PrivateMessages") == null || Settings.getSettingByName("PrivateMessages").getValueByPlayer(target).getValue().equalsIgnoreCase("all")) {
        target.sendMessage(ChatColor.GRAY + "From " + Players.getName(sender) + ChatColor.GRAY + ": " + ChatColor.RESET + cmd.getJoinedStrings(0));
        sender.sendMessage(ChatColor.GRAY + "To " + Players.getName(target) + ChatColor.GRAY + ": " + ChatColor.RESET + cmd.getJoinedStrings(0));
        if (Settings.getSettingByName("PrivateMessageSounds") == null || Settings.getSettingByName("PrivateMessageSounds").getValueByPlayer(target).getValue().equalsIgnoreCase("on")) {
            target.playSound(target.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2F);
        }
        target.setMetadata("reply", new FixedMetadataValue(Cardinal.getInstance(), sender));
    } else {
        sender.sendMessage(new LocalizedChatMessage(ChatConstant.ERROR_PLAYER_DISABLED_PMS, Players.getName(target) + ChatColor.RED).getMessage(ChatUtil.getLocale(sender)));
    }
}
 
Example #9
Source File: RecipeBuilder.java    From ProRecipes with GNU General Public License v2.0 6 votes vote down vote up
private void openFurnace(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_Furnace", ChatColor.DARK_GREEN + "Add your source! Close to save recipe."));
	ProRecipes.getPlugin().getServer().getScheduler().runTaskLater(ProRecipes.getPlugin(), new Runnable(){

		@Override
		public void run() {
			p.setMetadata("recipeBuilder", new FixedMetadataValue(ProRecipes.getPlugin(), "craftRecipeFurnace"));
			p.openWorkbench(null, true);
			p.getOpenInventory().setItem(0, i);
		}
		
	}, ProRecipes.getPlugin().wait);
}
 
Example #10
Source File: RecipeBuilder.java    From ProRecipes with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler
public void onTalk(AsyncPlayerChatEvent event){
	if(event.getPlayer().hasMetadata("recipeBuilder")){
		String step = event.getPlayer().getMetadata("recipeBuilder").get(0).asString();
		if(step.equalsIgnoreCase("choosePermission")){
			if(event.getMessage().equalsIgnoreCase("no")){
				event.setCancelled(true);
				openChoice(event.getPlayer());
				return;
			}
			event.getPlayer().setMetadata("recPermission", new FixedMetadataValue(ProRecipes.getPlugin(), ChatColor.stripColor(event.getMessage())));
			event.setCancelled(true);
			openChoice(event.getPlayer());
		}
	}
}
 
Example #11
Source File: RecipeBuilder.java    From ProRecipes with GNU General Public License v2.0 6 votes vote down vote up
private void openShaped(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(), "craftRecipeShaped"));
			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 #12
Source File: BukkitPlotListener.java    From PlotMe-Core with GNU General Public License v3.0 6 votes vote down vote up
@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);
                }
            }
        }
    }
}
 
Example #13
Source File: InvisibleBlock.java    From CardinalPGM with MIT License 6 votes vote down vote up
@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);
            }
        }
    });
}
 
Example #14
Source File: PricklyBlock.java    From ce with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean effect(Event event, Player player) {
	if(event instanceof BlockPlaceEvent) {
		BlockPlaceEvent e = (BlockPlaceEvent) event;
		Block b = e.getBlock();
		b.setMetadata("ce.mine", new FixedMetadataValue(main, getOriginalName()));
		String coord = b.getX() + " " + b.getY() + " " + b.getZ();
		b.getRelative(0,1,0).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord));
		b.getRelative(0,-1,0).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord));
		b.getRelative(1,0,0).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord));
		b.getRelative(0,0,1).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord));
		b.getRelative(0,0,-1).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord));
		b.getRelative(-1,0,0).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord));
	} else if(event instanceof PlayerMoveEvent) {
		if(!player.getGameMode().equals(GameMode.CREATIVE) && !player.hasPotionEffect(PotionEffectType.CONFUSION)) {
			player.damage(Damage);
			player.sendMessage(ChatColor.DARK_GREEN + "A nearbly Block is hurting you!");
			player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, NauseaDuration, NauseaLevel));
		}
	}
	return false;
}
 
Example #15
Source File: Bandage.java    From ce with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void heal(final Player p) {
	p.sendMessage(ChatColor.GREEN + "The bandage covers your wounds.");
	p.setMetadata("ce." + getOriginalName(), new FixedMetadataValue(main, ChatColor.RED + "You are already using a bandage!"));
	if(p.hasMetadata("ce.bleed")) 
		p.removeMetadata("ce.bleed", main);
	new BukkitRunnable() {
		int localCounter = TotalHealTime;
		@Override
		public void run() {
			if(!p.isDead() && localCounter != 0) {
				if(((Damageable) p).getHealth() == ((Damageable) p).getMaxHealth() && StopAtFullHealth) {
					p.sendMessage(ChatColor.GREEN + "Your wounds have fully recovered.");
					this.cancel();
				}
				if(((Damageable) p).getHealth() + healBursts <= ((Damageable) p).getMaxHealth())
					p.setHealth(((Damageable) p).getHealth() + healBursts);
				else
					p.setHealth(((Damageable) p).getMaxHealth());
			localCounter--;
			} else {
				p.sendMessage(ChatColor.GREEN + "The bandage has recovered some of your wounds.");
				this.cancel();
			}
		}
	}.runTaskTimer(main, 0l, 20l);
}
 
Example #16
Source File: ItemBuilder.java    From ProRecipes with GNU General Public License v2.0 6 votes vote down vote up
public void openItemBuilder(final Player p){
	sendMessage(p,  m.getMessage("Item_Builder_Title", ChatColor.GOLD + "Item Builder"),  m.getMessage("Item_Builder_Insert", ChatColor.DARK_GREEN + "Insert a desired itemstack to modify."));
	
	ProRecipes.getPlugin().getServer().getScheduler().runTaskLater(ProRecipes.getPlugin(), new Runnable(){

		@Override
		public void run() {
			p.closeInventory();
			p.setMetadata("itemBuilder", new FixedMetadataValue(ProRecipes.getPlugin(), "itemRequest"));
			p.openWorkbench(null, true);
			//Inventory i = RPGRecipes.getPlugin().getServer().createInventory(p, InventoryType.WORKBENCH, "ItemBuilder");
			//p.openInventory(i);
		}
		
	}, ProRecipes.getPlugin().wait);
	
}
 
Example #17
Source File: IceAspect.java    From ce with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private HashMap<Block, String> getIgloo(Location start, int size, Player p) {
    HashMap<Block, String> list = new HashMap<Block, String>();
    int bx = start.getBlockX();
    int by = start.getBlockY();
    int bz = start.getBlockZ();

    for (int x = bx - size; x <= bx + size; x++)
        for (int y = by - 1; y <= by + size; y++)
            for (int z = bz - size; z <= bz + size; z++) {
                double distancesquared = (bx - x) * (bx - x) + ((bz - z) * (bz - z)) + ((by - y) * (by - y));
                if (distancesquared < (size * size) && distancesquared >= ((size - 1) * (size - 1))) {
                    org.bukkit.block.Block b = new Location(start.getWorld(), x, y, z).getBlock();
                    if ((b.getType() == Material.AIR || (!b.getType().equals(Material.CARROT) && !b.getType().equals(Material.POTATO) && !b.getType().equals(Material.CROPS)
                            && !b.getType().toString().contains("SIGN") && !b.getType().isSolid())) && Tools.checkWorldGuard(b.getLocation(), p, "PVP", false)) {
                        list.put(b, b.getType().toString() + " " + b.getData());
                        b.setType(Material.ICE);
                        b.setMetadata("ce.Ice", new FixedMetadataValue(getPlugin(), null));
                    }
                }
            }
    return list;
}
 
Example #18
Source File: RecipeBuilder.java    From ProRecipes with GNU General Public License v2.0 6 votes vote down vote up
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 #19
Source File: DefaultMapWrapper.java    From MapManager with MIT License 6 votes vote down vote up
@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(MAP_MATERIAL, 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);
}
 
Example #20
Source File: CommandDebug.java    From TrMenu with MIT License 6 votes vote down vote up
@Override
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (player.hasMetadata("TrMenu-Debug")) {
            player.removeMetadata("TrMenu-Debug", TrMenu.getPlugin());
            sender.sendMessage("§7Canceled...");
        } else {
            player.setMetadata("TrMenu-Debug", new FixedMetadataValue(TrMenu.getPlugin(), ""));
            sender.sendMessage("§aEnabled...");
        }
        return;
    }

    sender.sendMessage("§3--------------------------------------------------");
    sender.sendMessage("");
    sender.sendMessage("§2Total Menus: §6" + TrMenuAPI.getMenus().size());
    sender.sendMessage("§2Cached Skulls: §6" + Skulls.getSkulls().size());
    sender.sendMessage("§2Running Tasks: §6" + Bukkit.getScheduler().getActiveWorkers().stream().filter(t -> t.getOwner() == TrMenu.getPlugin()).count() + Bukkit.getScheduler().getPendingTasks().stream().filter(t -> t.getOwner() == TrMenu.getPlugin()).count());
    sender.sendMessage("§2Metrics: §6" + MetricsHandler.getMetrics().isEnabled());
    sender.sendMessage("§2TabooLib: §f" + Plugin.getVersion());
    sender.sendMessage("");
    sender.sendMessage("§2TrMenu Built-Time: §b" + YamlConfiguration.loadConfiguration(new InputStreamReader(Files.getResource(TrMenu.getPlugin(), "plugin.yml"))).getString("built-time", "Null"));
    sender.sendMessage("");
    sender.sendMessage("§3--------------------------------------------------");
}
 
Example #21
Source File: Tools.java    From ce with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #22
Source File: SelfDestruct.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void effect(Event e, ItemStack item, int level) {
	PlayerDeathEvent event = (PlayerDeathEvent) e;
	for(int i = level; i >= 0; i--) {
	TNTPrimed tnt = (TNTPrimed) event.getEntity().getWorld().spawnEntity(event.getEntity().getLocation(), EntityType.PRIMED_TNT);
	tnt.setFuseTicks(delay);
	tnt.setVelocity(new Vector(Tools.random.nextDouble()*1.5 - 1, Tools.random.nextDouble() * 1.5, Tools.random.nextDouble()*1.5 - 1));
	if(!Main.createExplosions)
		tnt.setMetadata("ce.explosive", new FixedMetadataValue(getPlugin(), null));
	}
}
 
Example #23
Source File: Projectiles.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onEntityShootBowEvent(EntityShootBowEvent event) {
    if (!projectile.equals(EntityType.ARROW) || velocityMod != 1.0) {
        Vector vector = event.getProjectile().getVelocity();
        event.setProjectile(GameHandler.getGameHandler().getMatchWorld().spawnEntity(event.getProjectile().getLocation(), projectile));
        ((Projectile) event.getProjectile()).setShooter(event.getEntity());
        event.getProjectile().setVelocity(vector.multiply(velocityMod));
        event.getProjectile().setMetadata("custom", new FixedMetadataValue(GameHandler.getGameHandler().getPlugin(), true));
    }
}
 
Example #24
Source File: RemoveholoCommand.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #25
Source File: Main.java    From ArmorStandTools with MIT License 5 votes vote down vote up
void setPlayerSkull(Player p, ArmorStand as) {
    Block b = Utils.findAnAirBlock(p.getLocation());
    if(b == null) {
        p.sendMessage(ChatColor.RED + Config.noAirError);
        return;
    }
    b.setType(Material.SIGN);
    nms.openSign(p, b);
    b.setMetadata("armorStand", new FixedMetadataValue(this, as.getUniqueId()));
    b.setMetadata("setSkull", new FixedMetadataValue(this, true));
}
 
Example #26
Source File: Main.java    From ArmorStandTools with MIT License 5 votes vote down vote up
void setName(Player p, ArmorStand as) {
    Block b = Utils.findAnAirBlock(p.getLocation());
    if(b == null) {
        p.sendMessage(ChatColor.RED + Config.noAirError);
        return;
    }
    b.setType(Material.SIGN);
    nms.openSign(p, b);
    b.setMetadata("armorStand", new FixedMetadataValue(this, as.getUniqueId()));
    b.setMetadata("setName", new FixedMetadataValue(this, true));
}
 
Example #27
Source File: MainListener.java    From ArmorStandTools with MIT License 5 votes vote down vote up
@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 #28
Source File: ListenerMobCombat.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onSpawn(CreatureSpawnEvent e) {
    LivingEntity entity = e.getEntity();
    SpawnReason spawnReason = e.getSpawnReason();

    FixedMetadataValue fixedValue = new FixedMetadataValue(this.expansion.getPlugin().getPlugin(), spawnReason);
    entity.setMetadata("combatlogx_spawn_reason", fixedValue);
}
 
Example #29
Source File: ExpCapListener.java    From NyaaUtils with MIT License 5 votes vote down vote up
@EventHandler
public void onExpCapThrown(ProjectileLaunchEvent event) {
    if (!cfg.expcap_thron_enabled) return;
    if (event.getEntity() instanceof ThrownExpBottle) {
        ProjectileSource shooter = event.getEntity().getShooter();
        if (shooter instanceof Player) {
            event.getEntity().setMetadata("nu_expcap_exp",
                    new FixedMetadataValue(plugin,
                            thrownExpMap.computeIfAbsent(((Player) shooter).getUniqueId(), uuid -> 0)
                    )
            );
        }
    }
}
 
Example #30
Source File: EntityTracker.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Registers an Entity as an elite mob. Can be cancelled by third party plugins as it calls the EliteMobSpawnEvent
 * which is cancellable. Cancelling that event will cancel the spawn of the Elite Mob.
 *
 * @param eliteMobEntity registers entity as elite mob
 */
public static boolean registerEliteMob(EliteMobEntity eliteMobEntity) {
    EliteMobSpawnEvent eliteMobSpawnEvent = new EliteMobSpawnEvent(eliteMobEntity.getLivingEntity(), eliteMobEntity, eliteMobEntity.getSpawnReason());
    if (eliteMobSpawnEvent.isCancelled()) return false;
    eliteMobs.add(eliteMobEntity);
    eliteMobsLivingEntities.add(eliteMobEntity.getLivingEntity());
    registerCullableEntity(eliteMobEntity.getLivingEntity());
    eliteMobEntity.getLivingEntity().setMetadata(MetadataHandler.ELITE_MOB_METADATA, new FixedMetadataValue(MetadataHandler.PLUGIN, eliteMobEntity.getLevel()));
    return true;
}