当前位置: 首页>>代码示例>>Java>>正文


Java Enchantment类代码示例

本文整理汇总了Java中org.bukkit.enchantments.Enchantment的典型用法代码示例。如果您正苦于以下问题:Java Enchantment类的具体用法?Java Enchantment怎么用?Java Enchantment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Enchantment类属于org.bukkit.enchantments包,在下文中一共展示了Enchantment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onEnchantItem

import org.bukkit.enchantments.Enchantment; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onEnchantItem(EnchantItemEvent event) {
    Map<Enchantment, Integer> adding = event.getEnchantsToAdd();
    Iterator<Map.Entry<Enchantment, Integer>> iterator = adding.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<Enchantment, Integer> entry = iterator.next();
        Enchantment enchantment = entry.getKey();
        int maxLevel = getMaxLevel(enchantment);
        if (entry.getValue() > maxLevel) {
            if (maxLevel > 0) {
                adding.put(enchantment, maxLevel);
            } else {
                iterator.remove();
            }
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:18,代码来源:EnchantLimitListener.java

示例2: setVale

import org.bukkit.enchantments.Enchantment; //导入依赖的package包/类
public static void setVale(Player player, int amount) throws SQLException {
    UUID uuid = player.getUniqueId();
    PreparedStatement stmt = plugin.getDb().getConnection().prepareStatement("UPDATE vale_eco SET amount = "+amount+" WHERE uuid = '"+uuid.toString()+"'");
    stmt.executeUpdate();

    ItemStack item = new ItemStack(Material.EMERALD, 1);
    ItemMeta meta = item.getItemMeta();
    meta.setDisplayName(ChatColor.GREEN.toString() + getVale(player) + (getVale(player)==1?" Vale":" Vales"));
    meta.addEnchant(Enchantment.LUCK, 1, true);
    meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
    item.setItemMeta(meta);
    if(plugin.getConfig().getString("valeitemininv").equals("true")){
        player.getInventory().setItem(8, item);
    }

}
 
开发者ID:Warvale,项目名称:NetworkCore,代码行数:17,代码来源:ValeUtil.java

示例3: openFakeInv

import org.bukkit.enchantments.Enchantment; //导入依赖的package包/类
/**
 * Copy an inventory and open it for player
 *
 * @param i Inventory to open
 * @param p Player that needs the inventory
 */
public static void openFakeInv(Inventory i, OMGPlayer p) {
    Inventory fake = Bukkit.createInventory(p.bukkit, i.getSize(), i.getTitle());
    for (int slot = 0; slot < i.getContents().length; slot++) {
        ItemStack e = i.getContents()[slot];
        if (e != null) {
            e = e.clone();
            ItemMeta im = e.getItemMeta();
            im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
            im.addItemFlags(ItemFlag.HIDE_ENCHANTS);
            if ((NBTParser.getTagCompound(e).hasKey("kitid") && NBTParser.getTagCompound(e).getString("kitid").equals(p.kit.name)) || (NBTParser.getTagCompound(e).hasKey("teamid") && NBTParser.getTagCompound(e).getString("teamid").equals(p.requestedTeam.id)))
                im.addEnchant(Enchantment.DURABILITY, 1, true);
            if (NBTParser.getTagCompound(e).hasKey("kitid")) {
                ItemStack finalE = e;
                OMGKit.kits.stream().filter(k -> k.getName().equals(NBTParser.getTagCompound(finalE).getString("kitid"))).forEach(k -> {
                    List<String> ss = im.hasLore() ? im.getLore() : new ArrayList<>();
                    ss.add(ChatColor.GREEN + "Can use: " + (OMGPI.g.player_hasKit(p, k) ? (ChatColor.GREEN + "YES") : (ChatColor.RED + "NO")));
                    im.setLore(ss);
                });
            }
            e.setItemMeta(im);
            fake.setItem(slot, e);
        }
    }
    p.bukkit.openInventory(fake);
}
 
开发者ID:BurnyDaKath,项目名称:OMGPI,代码行数:32,代码来源:Inventories.java

示例4: EnchantedBookCustomItem

import org.bukkit.enchantments.Enchantment; //导入依赖的package包/类
public EnchantedBookCustomItem(Material material, Config config, PlaceholderRegistry placeholders) {
    super(material, config, placeholders);
    storedEnchantments = new HashMap<>();

    if (config.has("stored-enchantments")) {
        Map<String, Object> stEnch = config.getMap("stored-enchantments");

        for(Map.Entry<String, Object> e : stEnch.entrySet()) {
            Enchantment ench = Enchantment.getByName(e.getKey().replace(' ', '_').toUpperCase(Locale.ENGLISH));
            if (ench == null)
                Uppercore.logger().severe("Cannot find enchantment: " + e.getKey());
            else
                storedEnchantments.put(ench, PlaceholderValue.intValue(e.getValue().toString()));
        }
    }
}
 
开发者ID:upperlevel,项目名称:uppercore,代码行数:17,代码来源:EnchantedBookCustomItem.java

示例5: getGlow

import org.bukkit.enchantments.Enchantment; //导入依赖的package包/类
public static Enchantment getGlow() {
    if (glow != null)
        return glow;

    try {
        Field f = Enchantment.class.getDeclaredField("acceptingNew");
        f.setAccessible(true);
        f.set(null, true);
    } catch (Exception e) {
        e.printStackTrace();
    }

    glow = new EnchantGlow(255);
    Enchantment.registerEnchantment(glow);
    return glow;
}
 
开发者ID:WarzoneMC,项目名称:Warzone,代码行数:17,代码来源:EnchantGlow.java

示例6: onQuit

import org.bukkit.enchantments.Enchantment; //导入依赖的package包/类
@EventHandler
public void onQuit(PlayerQuitEvent event) {
	// Removing Speed Miner effect
	if(speedMiner.get(event.getPlayer().getName()) != null) {
		speedMiner.get(event.getPlayer().getName()).removeEnchantment(Enchantment.DIG_SPEED);
		event.getPlayer().removePotionEffect(PotionEffectType.FAST_DIGGING);
		event.getPlayer().removePotionEffect(PotionEffectType.SPEED);
		speedMiner.remove(event.getPlayer().getName());
	}
	// Removing Rainbow Miner effect
	if(rainbowMiner.get(event.getPlayer().getName()) != null) {
		rainbowMiner.get(event.getPlayer().getName()).removeEnchantment(Enchantment.LOOT_BONUS_BLOCKS);
		event.getPlayer().removePotionEffect(PotionEffectType.FAST_DIGGING);
		rainbowMiner.remove(event.getPlayer().getName());
	}
	// Removing Diamond Miner effect
	if(diamondMiner.get(event.getPlayer().getName()) != null) {
		diamondMiner.remove(event.getPlayer().getName());
	}
	// Quiting challenge in case player is doing it
	if(plugin.getChallenges().getChallenge(event.getPlayer()) > 0){
		plugin.getChallenges().quitChallenge(event.getPlayer());
	}
	plugin.getPlayerManager().saveData(event.getPlayer());
}
 
开发者ID:benNek,项目名称:AsgardAscension,代码行数:26,代码来源:PlayerListener.java

示例7: build

import org.bukkit.enchantments.Enchantment; //导入依赖的package包/类
/**
 * Get the final {@link ItemStack} with all the attributes you have been adding
 *
 * @return the {@link ItemStack} of this {@link ItemBuilder}
 */
@Override
public ItemStack build() {
    ItemStack s = new ItemStack(this.getMaterial());
    s.setAmount(this.getAmount());
    s.setDurability(this.getDamage());
    LeatherArmorMeta m = (LeatherArmorMeta) s.getItemMeta();

    for (ItemFlag iflag : this.getAllItemflags()) {
        m.addItemFlags(iflag);
    }
    m.setDisplayName(this.getName());
    m.setLore(this.getLore());
    m.setColor(color);
    s.setItemMeta(m);
    for (Map.Entry<Enchantment, Integer> temp : this.getAllEnchantments().entrySet()) {
        s.addUnsafeEnchantment(temp.getKey(), temp.getValue());
    }
    return s;
}
 
开发者ID:AlphaHelixDev,项目名称:AlphaLibary,代码行数:25,代码来源:LeatherItemBuilder.java

示例8: CraftMetaItem

import org.bukkit.enchantments.Enchantment; //导入依赖的package包/类
CraftMetaItem(CraftMetaItem meta) {
    if (meta == null) {
        attributes = null;
        return;
    }

    this.displayName = meta.displayName;

    if (meta.hasLore()) {
        this.lore = new ArrayList<String>(meta.lore);
    }

    if (meta.hasEnchants()) {
        this.enchantments = new HashMap<Enchantment, Integer>(meta.enchantments);
    }

    this.repairCost = meta.repairCost;
    this.attributes = meta.attributes;
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:20,代码来源:CraftMetaItem.java

示例9: registerEnchants

import org.bukkit.enchantments.Enchantment; //导入依赖的package包/类
/**
 * Register all of our custom enchants.
 */
private static void registerEnchants() {

    // Tell bukkit it's ok to register new enchants.
    try {
        Field f = Enchantment.class.getDeclaredField("acceptingNew");
        f.setAccessible(true);
        f.set(null, true);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Register each enchant.
    for (CustomEnchant ce : CustomEnchant.values())
        Enchantment.registerEnchantment(ce.getEnchant());
}
 
开发者ID:Kneesnap,项目名称:Kineticraft,代码行数:19,代码来源:Enchants.java

示例10: onPlayerInteract

import org.bukkit.enchantments.Enchantment; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.getAction() == Action.LEFT_CLICK_BLOCK && event.hasItem()) {
        // The player didn't click an enchantment table, Creative players will instantly destroy.
        Player player = event.getPlayer();
        if (event.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE && player.getGameMode() != GameMode.CREATIVE) {

            // The player didn't click with an enchanted book.
            ItemStack stack = event.getItem();
            if (stack != null && stack.getType() == Material.ENCHANTED_BOOK) {
                ItemMeta meta = stack.getItemMeta();
                if (meta instanceof EnchantmentStorageMeta) {
                    EnchantmentStorageMeta enchantmentStorageMeta = (EnchantmentStorageMeta) meta;
                    for (Enchantment enchantment : enchantmentStorageMeta.getStoredEnchants().keySet()) {
                        enchantmentStorageMeta.removeStoredEnchant(enchantment);
                    }

                    event.setCancelled(true);
                    player.setItemInHand(EMPTY_BOOK);
                    player.sendMessage(ChatColor.GREEN + "You reverted this item to its original form.");
                }
            }
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:26,代码来源:BookDeenchantListener.java

示例11: run

import org.bukkit.enchantments.Enchantment; //导入依赖的package包/类
public void run(PAUser user, String label, String[] args) {
    if (args.length == 2) {
        ItemStack i = user.getPlayer().getInventory().getItemInHand();

        Enchantment enchantment;
        int level;

        if (!Utils.isInt(args[1])) return;
        enchantment = getEnchantment(args[0]);
        level = Integer.parseInt(args[1]);

        if (enchantment == null) return;

        i.addUnsafeEnchantment(enchantment, level);
    }
}
 
开发者ID:cadox8,项目名称:PA,代码行数:17,代码来源:EnchantCMD.java

示例12: serialize

import org.bukkit.enchantments.Enchantment; //导入依赖的package包/类
public static String serialize(ItemStack item) {
	String name = item.getType().name().toLowerCase();
	String data = "";
	if (item.getDurability() != (short) 0)
		data = ":" + item.getDurability();
	
	String amount = "";
	if (item.getAmount() > 1)
		amount = "," + item.getAmount();
	
	String ench = "";
	if (item.getEnchantments().size() > 0) {
		for (Entry<Enchantment, Integer> e : item.getEnchantments().entrySet()) {
			ench += e.getKey().getName().toLowerCase() + ":" + e.getValue() + ",";
		}
		ench = ench.substring(ench.length() - 1);
	}
	
	return name + data + amount + ench;		
}
 
开发者ID:thekeenant,项目名称:mczone,代码行数:21,代码来源:ItemUtil.java

示例13: start

import org.bukkit.enchantments.Enchantment; //导入依赖的package包/类
@Override
public void start() {
    if (!kitsDir.exists()) {
        log.info("Kits dir doesn't exist, creating....");
        kitsDir.mkdirs();
    }

    File[] files = kitsDir.listFiles();
    if (files != null) {
        for (File file : files) {
            if (file.getName().endsWith(".json")) {
                availableKits.add(file.getName().replace(".json", ""));
            }
        }
    }
    log.info("There are " + availableKits.size() + " kits available.");

    // test stuff
    Kit kit = new Kit("DefaultKit");
    kit.addItem(0, new ItemBuilder(Material.STONE).name("Test Stone").build());
    kit.addItem(1, new ItemBuilder(Material.DIAMOND_SWORD).enchantment(Enchantment.DAMAGE_ALL, 5).name(ChatColor.RED + "Cool sword").amount(2).build());
    kit.addItem(2, new ItemBuilder(Material.LEATHER_BOOTS).enchantment(Enchantment.PROTECTION_EXPLOSIONS, 2).enchantment(Enchantment.PROTECTION_FALL, 5).name("Cool bots").amount(3).color(Color.RED).durability(10).lore("test").lore("Lore").build());
    createKit(kit);
    kit = loadKit("DefaultKit", new File(kitsDir, kit.getName() + ".json"));
    System.out.println(kit);
}
 
开发者ID:VoxelGamesLib,项目名称:VoxelGamesLibv2,代码行数:27,代码来源:KitHandler.java

示例14: getRandomEnchant

import org.bukkit.enchantments.Enchantment; //导入依赖的package包/类
public static ItemStack getRandomEnchant(List<Enchantment>enchants, int amount){
	ItemStack result = new ItemStack(Material.ENCHANTED_BOOK);
	List<Enchantment>left = new ArrayList<Enchantment>(enchants);
	EnchantmentStorageMeta meta = (EnchantmentStorageMeta) result.getItemMeta();
	if(amount > left.size())
		amount = left.size();
	for(int i = 0 ; i < amount && !left.isEmpty() ; i++){
		Enchantment e = VanillaPlusCore.getRandom(left);
		left.remove(e);
		int level = VanillaPlusCore.getRandom().nextInt(100);
		level = level % (e.getMaxLevel()+1-e.getStartLevel())+e.getStartLevel();
		meta.addStoredEnchant(e, level, false);
	}
	result.setItemMeta(meta);
	return result;
}
 
开发者ID:dracnis,项目名称:VanillaPlus,代码行数:17,代码来源:MinecraftUtils.java

示例15: updateVoting

import org.bukkit.enchantments.Enchantment; //导入依赖的package包/类
private void updateVoting(int slot) {
    Bukkit.getOnlinePlayers().forEach(player -> {
        ItemStack itemStack = player.getInventory().getItem(slot);
        itemStack.setAmount(getVotes(slot));
        if(votes.containsKey(player)) {
            for(int i=2; i<7; i++) {
                ItemStack temp = player.getInventory().getItem(i);
                if(temp != null) {
                    if(temp.getType() != Material.AIR) {
                        if(slots.get(i) != votes.get(player)) {
                            if(temp.getEnchantments().containsKey(Enchantment.DURABILITY)) {
                                temp.removeEnchantment(Enchantment.DURABILITY);
                            }
                            player.getInventory().setItem(i, temp);
                        } else {
                            temp.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
                            player.getInventory().setItem(i, temp);
                        }
                    }
                }
            }
        }
    });
}
 
开发者ID:ArcadiaPlugins,项目名称:Arcadia-Spigot,代码行数:25,代码来源:GameVotingRunnable.java


注:本文中的org.bukkit.enchantments.Enchantment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。