org.bukkit.metadata.MetadataValue Java Examples

The following examples show how to use org.bukkit.metadata.MetadataValue. 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: CustomDropListener.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event) {
    int i = 0;
    while (event.getEntity().hasMetadata("betonquest-drops-" + i)) {
        try {
            List<MetadataValue> metadata = event.getEntity().getMetadata("betonquest-drops-" + i);
            for (MetadataValue m : metadata) {
                String item = m.asString();
                int index = item.indexOf(':');
                event.getDrops().add(new QuestItem(new ItemID(null, item.substring(0, index)))
                        .generate(Integer.valueOf(item.substring(index + 1))));
            }
        } catch (Exception e) {
            LogUtils.getLogger().log(Level.WARNING, "Error when dropping custom item from entity: " + e.getMessage());
            LogUtils.logThrowable(e);
        }
        i++;
    }
}
 
Example #2
Source File: FlagBowspleef.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
private void cancelBowSpleefEntityEvent(Entity entity, Cancellable cancellable) {
	boolean isBowspleefEntity = false;
	List<MetadataValue> metadatas = entity.getMetadata(BOWSPLEEF_METADATA_KEY);
	for (MetadataValue value : metadatas) {
		if (value.getOwningPlugin() != getHeavySpleef().getPlugin()) {
			continue;
		}
		
		isBowspleefEntity = value.asBoolean();
	}
	
	if (isBowspleefEntity) {
		entity.remove();
		cancellable.setCancelled(true);
	}
}
 
Example #3
Source File: ExprMetadata.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Nullable
protected T[] get(Event e) {
	List<Object> values = new ArrayList<>();
	for (String value : this.values.getArray(e)) {
		for (Metadatable holder : holders.getArray(e)) {
			List<MetadataValue> metadata = holder.getMetadata(value);
			if (!metadata.isEmpty())
				values.add(metadata.get(metadata.size() - 1).value()); // adds the most recent metadata value
		}
	}
	try {
		return Converters.convertStrictly(values.toArray(), superType);
	} catch (ClassCastException e1) {
		return (T[]) Array.newInstance(superType, 0);
	}
}
 
Example #4
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 #5
Source File: MapBuilder.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH)
public void nexusHelperCheck(PlayerInteractEvent event)
{
	if(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK
			|| event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
	{
		final Player player = event.getPlayer();
		TeamBlock t = null;
		if(KitUtils.itemHasName(player.getItemInHand(), TeamBlock.Red.getName()))
			t = TeamBlock.Red;
		else if(KitUtils.itemHasName(player.getItemInHand(), TeamBlock.Blue.getName()))
			t = TeamBlock.Blue;
		else if(KitUtils.itemHasName(player.getItemInHand(), TeamBlock.Green.getName()))
			t = TeamBlock.Green;
		else if(KitUtils.itemHasName(player.getItemInHand(), TeamBlock.Yellow.getName()))
			t = TeamBlock.Yellow;
		if(t != null)
		{
			//They made a click with a team block
			event.setCancelled(true);
			List<MetadataValue> vals = player.getMetadata("TeamHandler");
			if(vals != null && vals.size() == 1)
			{
				Object obj = vals.get(0).value();
				if(obj != null && obj instanceof TeamBlockHandler)
				{
					((TeamBlockHandler)obj).onBlockClick(player, t.Team, event.getAction(), event.getClickedBlock(),event.getBlockFace());
				}
			}
		}
	}
}
 
Example #6
Source File: BlockMetadataStore.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets or overwrites a metadata value on a {@link Block} from a given {@link Plugin}, ensuring the target block belongs
 * to this BlockMetadataStore's owning world.
 *
 * @see MetadataStoreBase#setMetadata(Object, String, MetadataValue)
 */
@Override
public void setMetadata(Block block, String metadataKey, MetadataValue newMetadataValue) {
    if (block.getWorld() == owningWorld) {
        super.setMetadata(block, metadataKey, newMetadataValue);
    } else {
        throw new IllegalArgumentException("Block does not belong to world " + owningWorld.getName());
    }
}
 
Example #7
Source File: BlockMetadataStore.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Retrieves the metadata for a {@link Block}, ensuring the block being asked for actually belongs to this BlockMetadataStore's
 * owning world.
 *
 * @see MetadataStoreBase#getMetadata(Object, String)
 */
@Override
public List<MetadataValue> getMetadata(Block block, String metadataKey) {
    if (block.getWorld() == owningWorld) {
        return super.getMetadata(block, metadataKey);
    } else {
        throw new IllegalArgumentException("Block does not belong to world " + owningWorld.getName());
    }
}
 
Example #8
Source File: HealthUtil.java    From ActionHealth with MIT License 5 votes vote down vote up
public String getName(LivingEntity entity, Player receiver) {
    String name;

    // Supporting mcmmo health bar to get to display correct name.
    List<MetadataValue> metadataValues = entity.getMetadata("mcMMO_oldName");
    List<MetadataValue> metadataValuesOld = entity.getMetadata("mcMMO: Custom Name");

    String mcMMOName = null;
    if (plugin.mcMMOEnabled && entity.getCustomName() != null && (!metadataValues.isEmpty() || !metadataValuesOld.isEmpty())) {
        mcMMOName = new McMMOSupport().getName(metadataValues.isEmpty() ? metadataValuesOld.get(0) : metadataValues.get(0));
    }

    if (mcMMOName == null) {
        if (entity.getCustomName() != null) {
            name = entity.getCustomName();
        } else if (plugin.langUtilsEnabled && plugin.configStore.useClientLanguage && receiver != null) {
            name = new LangUtilsSupport().getName(entity, receiver);
        } else {
            name = getNameReflection(entity);
        }
    } else if (mcMMOName.equals("")) {
        name = getNameReflection(entity);
    } else {
        name = mcMMOName;
    }

    if (plugin.configStore.translate.containsKey(name))
        name = plugin.configStore.translate.get(name);

    return name;
}
 
Example #9
Source File: McMMOSupport.java    From ActionHealth with MIT License 5 votes vote down vote up
public String getName(MetadataValue metadataValue) {
    /*if (metadataValue instanceof OldName) {
        OldName oldName = (OldName) metadataValue;
        return oldName.asString();
    }*/

    FixedMetadataValue fixedMetadataValue = (FixedMetadataValue) metadataValue;
    return fixedMetadataValue.asString();
}
 
Example #10
Source File: PlayerServerChanger.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onQuit(PlayerQuitEvent event) {
    final MetadataValue future = event.getPlayer().getMetadata(METADATA_KEY, plugin);
    if(future != null) {
        ((SettableFuture) future.value()).set(null);
    }
}
 
Example #11
Source File: BukkitPartyPlayerImpl.java    From Parties with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean isVanished() {
	Player player = Bukkit.getPlayer(this.getPlayerUUID());
	if (player != null) {
		for (MetadataValue meta : player.getMetadata("vanished")) {
			if (meta.asBoolean()) return true;
		}
	}
	return false;
}
 
Example #12
Source File: ProjectileMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
public static @Nullable ProjectileDefinition getProjectileDefinition(Entity entity) {
  MetadataValue metadataValue = entity.getMetadata("projectileDefinition", PGM.get());

  if (metadataValue != null) {
    return (ProjectileDefinition) metadataValue.value();
  } else if (launchingDefinition.get() != null) {
    return launchingDefinition.get();
  } else {
    return null;
  }
}
 
Example #13
Source File: Transporter.java    From AnnihilationPro with MIT License 5 votes vote down vote up
public UUID getBlocksOwner(Block b)
{
	List<MetadataValue> list = b.getMetadata("Owner");
	if(list == null || list.isEmpty())
		return null;
	return UUID.fromString(list.get(0).asString());
}
 
Example #14
Source File: ListenerMobCombat.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private SpawnReason getSpawnReason(LivingEntity entity) {
    if(entity == null) return SpawnReason.DEFAULT;
    if(!entity.hasMetadata("combatlogx_spawn_reason")) return SpawnReason.DEFAULT;

    List<MetadataValue> spawnReasonValues = entity.getMetadata("combatlogx_spawn_reason");
    for(MetadataValue metadataValue : spawnReasonValues) {
        Object object = metadataValue.value();
        if(!(object instanceof SpawnReason)) continue;
        
        return (SpawnReason) object;
    }
    
    return SpawnReason.DEFAULT;
}
 
Example #15
Source File: MobKillObjective.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onMobKill(MobKilledEvent event) {
    // check if it's the right entity type
    if (!event.getEntity().getType().equals(mobType)) {
        return;
    }
    // if the entity should have a name and it does not match, return
    if (name != null && (event.getEntity().getCustomName() == null ||
            !event.getEntity().getCustomName().equals(name))) {
        return;
    }
    // check if the entity is correctly marked
    if (marked != null) {
        if (!event.getEntity().hasMetadata("betonquest-marked")) {
            return;
        }
        List<MetadataValue> meta = event.getEntity().getMetadata("betonquest-marked");
        for (MetadataValue m : meta) {
            if (!m.asString().equals(marked)) {
                return;
            }
        }
    }
    // check if the player has this objective
    String playerID = PlayerConverter.getID(event.getPlayer());
    if (containsPlayer(playerID) && checkConditions(playerID)) {
        // the right mob was killed, handle data update
        MobData playerData = (MobData) dataMap.get(playerID);
        playerData.subtract();
        if (playerData.isZero()) {
            completeObjective(playerID);
        } else if (notify && playerData.getAmount() % notifyInterval == 0) {
            // send a notification
            Config.sendNotify(playerID, "mobs_to_kill", new String[]{String.valueOf(playerData.getAmount())},
                    "mobs_to_kill,info");
        }
    }
}
 
Example #16
Source File: PatienceTester.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isRunning(Player player, String key) {
    if (player.hasMetadata(key)) {
        List<MetadataValue> metadata = player.getMetadata(key);
        MetadataValue metadataValue = metadata.size() > 0 ? metadata.get(0) : null;
        if (metadataValue == null || metadataValue.asLong() < System.currentTimeMillis()) {
            player.removeMetadata(key, uSkyBlock.getInstance());
            return false;
        }
        player.sendMessage(getMessage());
        return true;
    }
    return false;
}
 
Example #17
Source File: DeathStandsModule.java    From UHC with MIT License 5 votes vote down vote up
protected EnumMap<EquipmentSlot, ItemStack> getSavedSlots(Player player) {
    for (final MetadataValue value : player.getMetadata(StandItemsMetadata.KEY)) {
        if (!(value instanceof StandItemsMetadata)) continue;

        // remove the metadata
        player.removeMetadata(StandItemsMetadata.KEY, value.getOwningPlugin());

        // return the map
        return ((StandItemsMetadata) value).value();
    }

    return Maps.newEnumMap(EquipmentSlot.class);
}
 
Example #18
Source File: Main.java    From ArmorStandTools with MIT License 5 votes vote down vote up
void returnArmorStand(ArmorStand as) {
    if(as.hasMetadata("startLoc")) {
        for (MetadataValue value : as.getMetadata("startLoc")) {
            if (value.getOwningPlugin() == this) {
                as.teleport((Location) value.value());
                as.removeMetadata("startLoc", this);
                return;
            }
        }
    }
    as.remove();
}
 
Example #19
Source File: FlagSplegg.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
	Entity entity = event.getEntity();
	
	Game game = null;
	List<MetadataValue> metadatas = entity.getMetadata(TNT_METADATA_KEY);
	for (MetadataValue value : metadatas) {
		if (value.getOwningPlugin() != getHeavySpleef().getPlugin()) {
			continue;
		}
		
		game = (Game) value.value();
	}
	
	if (game != null) {
		List<Block> blocks = event.blockList();
		for (Block block : blocks) {
			if (!game.canSpleef(block)) {
				continue;
			}
			
			block.setType(Material.AIR);
		}
		
		blocks.clear();
	}
}
 
Example #20
Source File: AsyncWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setMetadata(final String key, final MetadataValue meta) {
    TaskManager.IMP.sync(new RunnableVal<Object>() {
        @Override
        public void run(Object value) {
            parent.setMetadata(key, meta);
        }
    });
}
 
Example #21
Source File: BlockMetadataStore.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets or overwrites a metadata value on a {@link Block} from a given {@link Plugin}, ensuring the target block belongs
 * to this BlockMetadataStore's owning world.
 * @see MetadataStoreBase#setMetadata(Object, String, org.bukkit.metadata.MetadataValue)
 */
@Override
public void setMetadata(Block block, String metadataKey, MetadataValue newMetadataValue) {
    if(block.getWorld() == owningWorld) {
        super.setMetadata(block, metadataKey, newMetadataValue);
    } else {
        throw new IllegalArgumentException("Block does not belong to world " + owningWorld.getName());
    }
}
 
Example #22
Source File: BlockMetadataStore.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Retrieves the metadata for a {@link Block}, ensuring the block being asked for actually belongs to this BlockMetadataStore's
 * owning world.
 * @see MetadataStoreBase#getMetadata(Object, String)
 */
@Override
public List<MetadataValue> getMetadata(Block block, String metadataKey) {
    if(block.getWorld() == owningWorld) {
        return super.getMetadata(block, metadataKey);
    } else {
        throw new IllegalArgumentException("Block does not belong to world " + owningWorld.getName());
    }
}
 
Example #23
Source File: Database.java    From ScoreboardStats with MIT License 5 votes vote down vote up
public Optional<PlayerStats> getStats(Player request) {
    if (request != null) {
        for (MetadataValue metadata : request.getMetadata(METAKEY)) {
            if (metadata.value() instanceof PlayerStats) {
                return Optional.of((PlayerStats) metadata.value());
            }
        }
    }

    return Optional.empty();
}
 
Example #24
Source File: HookBukkitVanish.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isVanished(Player player) {
    if(player == null) return false;

    List<MetadataValue> metaList = player.getMetadata("vanished");
    for(MetadataValue meta : metaList) {
        boolean value = meta.asBoolean();
        if(value) return true;
    }

    return false;
}
 
Example #25
Source File: CraftBlock.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public List<MetadataValue> getMetadata(String metadataKey) {
    return chunk.getCraftWorld().getBlockMetadata().getMetadata(this, metadataKey);
}
 
Example #26
Source File: CraftBlockState.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
    requirePlaced();
    chunk.getCraftWorld().getBlockMetadata().setMetadata(getBlock(), metadataKey, newMetadataValue);
}
 
Example #27
Source File: AsyncBlock.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<MetadataValue> getMetadata(String metadataKey) {
    return null;
}
 
Example #28
Source File: AsyncWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<MetadataValue> getMetadata(String key) {
    return parent.getMetadata(key);
}
 
Example #29
Source File: CraftBlock.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
    chunk.getCraftWorld().getBlockMetadata().setMetadata(this, metadataKey, newMetadataValue);
}
 
Example #30
Source File: EntityListener.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onInteractEntity(PlayerInteractAtEntityEvent event) {
  if (event.getRightClicked() == null) {
    return;
  }

  Entity entity = event.getRightClicked();
  Player player = event.getPlayer();
  if (!player.hasMetadata("bw-addteamjoin")) {
    if (!(entity instanceof LivingEntity)) {
      return;
    }

    LivingEntity livEntity = (LivingEntity) entity;
    Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);
    if (game == null) {
      return;
    }

    if (game.getState() != GameState.WAITING) {
      return;
    }

    Team team = game.getTeam(ChatColor.stripColor(livEntity.getCustomName()));
    if (team == null) {
      return;
    }

    game.playerJoinTeam(player, team);
    event.setCancelled(true);
    return;
  }

  List<MetadataValue> values = player.getMetadata("bw-addteamjoin");
  if (values == null || values.size() == 0) {
    return;
  }

  event.setCancelled(true);
  TeamJoinMetaDataValue value = (TeamJoinMetaDataValue) values.get(0);
  if (!((boolean) value.value())) {
    return;
  }

  if (!(entity instanceof LivingEntity)) {
    player.sendMessage(
        ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
            ._l(player, "errors.entitynotcompatible")));
    return;
  }

  LivingEntity living = (LivingEntity) entity;
  living.setRemoveWhenFarAway(false);
  living.setCanPickupItems(false);
  living.setCustomName(value.getTeam().getChatColor() + value.getTeam().getDisplayName());
  living.setCustomNameVisible(
      BedwarsRel.getInstance().getBooleanConfig("jointeam-entity.show-name", true));

  if (living.getType().equals(EntityType.valueOf("ARMOR_STAND"))) {
    Utils.equipArmorStand(living, value.getTeam());
  }

  player.removeMetadata("bw-addteamjoin", BedwarsRel.getInstance());
  player.sendMessage(ChatWriter
      .pluginMessage(
          ChatColor.GREEN + BedwarsRel._l(player, "success.teamjoinadded", ImmutableMap.of("team",
              value.getTeam().getChatColor() + value.getTeam().getDisplayName()
                  + ChatColor.GREEN))));
}