コード例 #1
0
ファイル: TabAPI.java プロジェクト: dentmaged/TabAPI
  public void onEnable() {
    plugin = this;

    FileConfiguration config = getConfig();
    config.options().copyDefaults(true);

    MemoryConfiguration defaultConfig = new MemoryConfiguration();
    defaultConfig.set("flickerPrevention", Long.valueOf(flickerPrevention));
    config.setDefaults(defaultConfig);
    saveConfig();

    reloadConfiguration();
    getCommand("tabapi").setExecutor(this);
    try {
      new Metrics(this).start();
    } catch (IOException e) {
      e.printStackTrace();
    }
    protocolManager = ProtocolLibrary.getProtocolManager();
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
    for (Player p : Bukkit.getOnlinePlayers()) {
      Plugin plugin = Bukkit.getPluginManager().getPlugin("TabAPI");
      setPriority(plugin, p, 2);
      resetTabList(p);
      setPriority(plugin, p, -2);
    }
    protocolManager.addPacketListener(
        new PacketAdapter(
            this, ListenerPriority.NORMAL, new PacketType[] {PacketType.Play.Server.PLAYER_INFO}) {
          public void onPacketSending(PacketEvent event) {
            PacketContainer p = event.getPacket();
            List<PlayerInfoData> pinfodata =
                (List<PlayerInfoData>) p.getPlayerInfoDataLists().read(0);
            String s = ((PlayerInfoData) pinfodata.get(0)).getProfile().getName();
            if (s.startsWith("$")) {
              List<PlayerInfoData> pinfodataReSend = new ArrayList<PlayerInfoData>();
              PlayerInfoData pinfod = (PlayerInfoData) pinfodata.get(0);
              pinfodataReSend.add(
                  new PlayerInfoData(
                      pinfod.getProfile().withName(s.substring(1)),
                      pinfod.getPing(),
                      pinfod.getGameMode(),
                      WrappedChatComponent.fromText(pinfod.getProfile().getName().substring(1))));

              p.getPlayerInfoDataLists().write(0, pinfodataReSend);
              event.setPacket(p);
            } else if (TabAPI.protocolManager.getProtocolVersion(event.getPlayer()) < 47) {
              event.setCancelled(true);
            }
          }
        });
  }
コード例 #2
0
ファイル: RPGItem.java プロジェクト: OsipXD/RPG-Items
  public void save(ConfigurationSection s) {
    s.set("name", name);
    s.set("id", id);
    s.set("display", displayName.replaceAll("" + ChatColor.COLOR_CHAR, "&"));
    s.set("quality", quality.toString());
    s.set("damageMin", damageMin);
    s.set("damageMax", damageMax);
    s.set("armour", armour);
    s.set("type", type.replaceAll("" + ChatColor.COLOR_CHAR, "&"));
    s.set("hand", hand.replaceAll("" + ChatColor.COLOR_CHAR, "&"));
    s.set("lore", loreText.replaceAll("" + ChatColor.COLOR_CHAR, "&"));
    ArrayList<String> descriptionConv = new ArrayList<String>(description);
    for (int i = 0; i < descriptionConv.size(); i++) {
      descriptionConv.set(i, descriptionConv.get(i).replaceAll("" + ChatColor.COLOR_CHAR, "&"));
    }
    s.set("description", descriptionConv);
    s.set("item", item.getType().toString());
    s.set("ignoreWorldGuard", ignoreWorldGuard);

    ItemMeta meta = localeMeta.get("en_GB");
    if (meta instanceof LeatherArmorMeta) {
      s.set("item_colour", ((LeatherArmorMeta) meta).getColor().asRGB());
    } else {
      s.set("item_data", item.getDurability());
    }
    ConfigurationSection powerConfigs = s.createSection("powers");
    int i = 0;
    for (Power p : powers) {
      MemoryConfiguration pConfig = new MemoryConfiguration();
      pConfig.set("powerName", p.getName());
      p.save(pConfig);
      powerConfigs.set(Integer.toString(i), pConfig);
      i++;
    }

    // Recipes
    s.set("hasRecipe", hasRecipe);
    if (hasRecipe) {
      s.set("recipe", recipe);
    }

    ConfigurationSection drops = s.createSection("dropChances");
    for (String key : dropChances.keySet()) {
      drops.set(key, dropChances.get(key));
    }

    s.set("maxDurability", maxDurability);
    s.set("forceBar", forceBar);
  }