use of org.bukkit.Material in project EliteMobs by MagmaGuy.
the class AttackWeb method attackWeb.
@EventHandler
public void attackWeb(EntityDamageByEntityEvent event) {
Entity damager = event.getDamager();
Entity damagee = event.getEntity();
Block block = damagee.getLocation().getBlock();
Material originalMaterial = block.getType();
if (!originalMaterial.equals(Material.AIR)) {
return;
}
if (damager.hasMetadata(MetadataHandler.ATTACK_FREEZE_MD) || damager instanceof Projectile && ProjectileMetadataDetector.projectileMetadataDetector((Projectile) damager, MetadataHandler.ATTACK_FREEZE_MD)) {
return;
}
if (damagee.hasMetadata("WebCooldown")) {
return;
}
if (damager.hasMetadata(powerMetadata)) {
//if a block spawned by the plugin is already in place, skip effect
if (block.hasMetadata("TemporaryBlock")) {
return;
}
processID = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
int counter = 0;
@Override
public void run() {
webEffectApplier(counter, damagee, block);
counter++;
}
}, 2, 1);
}
if (damager instanceof Projectile) {
if (ProjectileMetadataDetector.projectileMetadataDetector((Projectile) damager, powerMetadata)) {
processID = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
int counter = 0;
@Override
public void run() {
webEffectApplier(counter, damagee, block);
counter++;
}
}, 1, 1);
}
}
}
use of org.bukkit.Material in project Essentials by drtshock.
the class Commandrecipe method shapedRecipe.
public void shapedRecipe(final CommandSource sender, final ShapedRecipe recipe, final boolean showWindow) {
final Map<Character, ItemStack> recipeMap = recipe.getIngredientMap();
if (showWindow) {
final User user = ess.getUser(sender.getPlayer());
user.getBase().closeInventory();
user.setRecipeSee(true);
final InventoryView view = user.getBase().openWorkbench(null, true);
final String[] recipeShape = recipe.getShape();
final Map<Character, ItemStack> ingredientMap = recipe.getIngredientMap();
for (int j = 0; j < recipeShape.length; j++) {
for (int k = 0; k < recipeShape[j].length(); k++) {
final ItemStack item = ingredientMap.get(recipeShape[j].toCharArray()[k]);
if (item == null) {
continue;
}
if (item.getDurability() == Short.MAX_VALUE) {
item.setDurability((short) 0);
}
view.getTopInventory().setItem(j * 3 + k + 1, item);
}
}
} else {
final HashMap<Material, String> colorMap = new HashMap<>();
int i = 1;
for (Character c : "abcdefghi".toCharArray()) {
ItemStack item = recipeMap.get(c);
if (!colorMap.containsKey(item == null ? null : item.getType())) {
colorMap.put(item == null ? null : item.getType(), String.valueOf(i++));
}
}
final Material[][] materials = new Material[3][3];
for (int j = 0; j < recipe.getShape().length; j++) {
for (int k = 0; k < recipe.getShape()[j].length(); k++) {
ItemStack item = recipe.getIngredientMap().get(recipe.getShape()[j].toCharArray()[k]);
materials[j][k] = item == null ? null : item.getType();
}
}
sender.sendMessage(tl("recipeGrid", colorMap.get(materials[0][0]), colorMap.get(materials[0][1]), colorMap.get(materials[0][2])));
sender.sendMessage(tl("recipeGrid", colorMap.get(materials[1][0]), colorMap.get(materials[1][1]), colorMap.get(materials[1][2])));
sender.sendMessage(tl("recipeGrid", colorMap.get(materials[2][0]), colorMap.get(materials[2][1]), colorMap.get(materials[2][2])));
StringBuilder s = new StringBuilder();
for (Material items : colorMap.keySet().toArray(new Material[colorMap.size()])) {
s.append(tl("recipeGridItem", colorMap.get(items), getMaterialName(items)));
}
sender.sendMessage(tl("recipeWhere", s.toString()));
}
}
use of org.bukkit.Material in project BKCommonLib by bergerhealer.
the class ParseUtil method parseMaterial.
/**
* Tries to parse the text to one of the values in the Material class
*
* @param text to parse
* @param def to return on failure
* @return Parsed or default value
*/
@SuppressWarnings("deprecation")
public static Material parseMaterial(String text, Material def) {
if (LogicUtil.nullOrEmpty(text)) {
return def;
}
// From ID
try {
return LogicUtil.fixNull(MaterialUtil.getType(Integer.parseInt(text)), def);
} catch (Exception ex) {
}
// Replace aliases and find the corresponding Material
String matName = MAT_ALIASES.replace(text.trim().toUpperCase(Locale.ENGLISH));
Material mat;
while (true) {
// First consult the name mapping (faster)
mat = MAT_NAME_MAP.get(matName);
if (mat != null) {
return mat;
}
// Parse it (slower)
mat = parseEnum(Material.class, matName, null);
if (mat != null) {
return mat;
}
// Handle a 'multiple' in the name (sadly, no ES)
if (matName.endsWith("S")) {
matName = matName.substring(0, matName.length() - 1);
} else {
return def;
}
}
}
use of org.bukkit.Material in project acidisland by tastybento.
the class EntityLimits method onAnimalSpawn.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onAnimalSpawn(final CreatureSpawnEvent e) {
// If not in the right world, return
if (!IslandGuard.inWorld(e.getEntity())) {
return;
}
// If not an animal
if (!(e.getEntity() instanceof Animals) && !e.getEntityType().equals(EntityType.SQUID)) {
return;
}
if (DEBUG2) {
plugin.getLogger().info("Animal spawn event! " + e.getEventName());
plugin.getLogger().info(e.getSpawnReason().toString());
plugin.getLogger().info(e.getEntityType().toString());
}
// If there's no limit - leave it
if (Settings.breedingLimit <= 0) {
if (DEBUG2)
plugin.getLogger().info("No limit on breeding or spawning");
return;
}
// We only care about spawning and breeding
if (e.getSpawnReason() != SpawnReason.SPAWNER && e.getSpawnReason() != SpawnReason.BREEDING && e.getSpawnReason() != SpawnReason.EGG && e.getSpawnReason() != SpawnReason.DISPENSE_EGG && e.getSpawnReason() != SpawnReason.SPAWNER_EGG && !e.getSpawnReason().name().contains("BABY")) {
if (DEBUG2)
plugin.getLogger().info("Not Spawner or breeding");
return;
}
LivingEntity animal = e.getEntity();
Island island = plugin.getGrid().getProtectedIslandAt(animal.getLocation());
if (island == null) {
// Animal is spawning outside of an island so ignore
if (DEBUG2)
plugin.getLogger().info("Outside island, so spawning is okay");
return;
}
// Count how many animals are there and who is the most likely spawner if it was a player
// This had to be reworked because the previous snowball approach doesn't work for large volumes
List<Player> culprits = new ArrayList<Player>();
boolean overLimit = false;
int animals = 0;
for (int x = island.getMinProtectedX() / 16; x <= (island.getMinProtectedX() + island.getProtectionSize() - 1) / 16; x++) {
for (int z = island.getMinProtectedZ() / 16; z <= (island.getMinProtectedZ() + island.getProtectionSize() - 1) / 16; z++) {
for (Entity entity : ASkyBlock.getIslandWorld().getChunkAt(x, z).getEntities()) {
if (entity instanceof Animals || entity.getType().equals(EntityType.SQUID)) {
if (DEBUG2)
plugin.getLogger().info("DEBUG: Animal count is " + animals);
animals++;
if (animals >= Settings.breedingLimit) {
// Delete any extra animals
overLimit = true;
animal.remove();
if (DEBUG2)
plugin.getLogger().info("Over limit! >=" + Settings.breedingLimit);
e.setCancelled(true);
}
} else if (entity instanceof Player && e.getSpawnReason() != SpawnReason.SPAWNER && e.getSpawnReason() != SpawnReason.DISPENSE_EGG) {
for (ItemStack itemInHand : Util.getPlayerInHandItems((Player) entity)) {
if (itemInHand != null) {
Material type = itemInHand.getType();
if (type == Material.EGG || type == Material.MONSTER_EGG || type == Material.WHEAT || type == Material.CARROT_ITEM || type == Material.SEEDS) {
if (DEBUG2)
plugin.getLogger().info("Player used egg or did breeding ");
if (!culprits.contains((Player) entity)) {
culprits.add(((Player) entity));
}
}
}
}
}
}
}
}
if (DEBUG2)
plugin.getLogger().info("Counting nether");
// Nether check
if (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
for (int x = island.getMinProtectedX() / 16; x <= (island.getMinProtectedX() + island.getProtectionSize() - 1) / 16; x++) {
for (int z = island.getMinProtectedZ() / 16; z <= (island.getMinProtectedZ() + island.getProtectionSize() - 1) / 16; z++) {
for (Entity entity : ASkyBlock.getNetherWorld().getChunkAt(x, z).getEntities()) {
if (entity instanceof Animals || entity.getType().equals(EntityType.SQUID)) {
if (DEBUG2)
plugin.getLogger().info("DEBUG: Animal count is " + animals);
animals++;
if (animals >= Settings.breedingLimit) {
// Delete any extra animals
if (DEBUG2)
plugin.getLogger().info("Over limit! >=" + Settings.breedingLimit);
overLimit = true;
animal.remove();
e.setCancelled(true);
}
} else if (entity instanceof Player && e.getSpawnReason() != SpawnReason.SPAWNER && e.getSpawnReason() != SpawnReason.DISPENSE_EGG) {
for (ItemStack itemInHand : Util.getPlayerInHandItems(((Player) entity))) {
Material type = itemInHand.getType();
if (type == Material.EGG || type == Material.MONSTER_EGG || type == Material.WHEAT || type == Material.CARROT_ITEM || type == Material.SEEDS) {
if (!culprits.contains((Player) entity)) {
culprits.add(((Player) entity));
}
}
}
}
}
}
}
}
if (overLimit) {
if (e.getSpawnReason() != SpawnReason.SPAWNER) {
plugin.getLogger().warning("Island at " + island.getCenter().getBlockX() + "," + island.getCenter().getBlockZ() + " hit the island animal breeding limit of " + Settings.breedingLimit);
for (Player player : culprits) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).moblimitsError.replace("[number]", String.valueOf(Settings.breedingLimit)));
plugin.getLogger().warning(player.getName() + " was trying to use " + Util.getPlayerInHandItems(player).toString());
}
}
}
// plugin.getLogger().info("DEBUG: Animal count is " + animals);
}
use of org.bukkit.Material in project acidisland by tastybento.
the class IslandGuard method onBlockIgnite.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockIgnite(final BlockIgniteEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
plugin.getLogger().info(e.getCause().name());
}
if (!inWorld(e.getBlock())) {
// plugin.getLogger().info("DEBUG: Not in world");
return;
}
// Check if this is a portal lighting
if (e.getBlock() != null && e.getBlock().getType().equals(Material.OBSIDIAN)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: portal lighting");
return;
}
if (e.getCause() != null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: ignite cause = " + e.getCause());
switch(e.getCause()) {
case ENDER_CRYSTAL:
case EXPLOSION:
case FIREBALL:
case LIGHTNING:
if (!actionAllowed(e.getBlock().getLocation(), SettingsFlag.FIRE)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: canceling fire");
e.setCancelled(true);
}
break;
case FLINT_AND_STEEL:
Set<Material> transparent = new HashSet<Material>();
transparent.add(Material.AIR);
if (DEBUG) {
plugin.getLogger().info("DEBUG: block = " + e.getBlock());
// plugin.getLogger().info("DEBUG: target block = " + e.getPlayer().getTargetBlock(transparent, 10));
}
// Check if this is allowed
if (e.getPlayer() != null && (e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypass"))) {
return;
}
if (!actionAllowed(e.getBlock().getLocation(), SettingsFlag.FIRE)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: canceling fire");
// If this was not a player, just stop it
if (e.getPlayer() == null) {
e.setCancelled(true);
break;
}
// Get target block
Block targetBlock = e.getPlayer().getTargetBlock(transparent, 10);
if (targetBlock.getType().equals(Material.OBSIDIAN)) {
final MaterialData md = new MaterialData(e.getBlock().getType(), e.getBlock().getData());
new BukkitRunnable() {
@Override
public void run() {
if (e.getBlock().getType().equals(Material.FIRE)) {
e.getBlock().setType(md.getItemType());
e.getBlock().setData(md.getData());
}
}
}.runTask(plugin);
} else {
e.setCancelled(true);
}
}
break;
case LAVA:
case SPREAD:
// Check if this is a portal lighting
if (e.getBlock() != null && e.getBlock().getType().equals(Material.OBSIDIAN)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: obsidian lighting");
return;
}
if (!actionAllowed(e.getBlock().getLocation(), SettingsFlag.FIRE_SPREAD)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: canceling fire spread");
e.setCancelled(true);
}
break;
default:
break;
}
}
}
Aggregations