コード例 #1
0
ファイル: AccountsPlugin.java プロジェクト: EthilVan/Plugins
  @Override
  public void onEnable() {
    PluginManager pm = Bukkit.getPluginManager();

    AccountsConfig config;
    try {
      config = getLoader().loadOrCreate("config.json", AccountsConfig.class);
    } catch (GsonLoadException exc) {
      getLogger().log(Level.SEVERE, "Unable to load config.json", exc);
      config = new AccountsConfig();
    }

    Accounts accounts = new EVAccounts(this, config);
    EthilVan.registerAccounts(accounts);

    Listener accountsListener = new AccountsListener(this);
    pm.registerEvents(accountsListener, this);

    ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
    protocolManager.addPacketListener(new NamePlatePacketListener(this));

    CommandsRegistration registration = new CommandsRegistration(this, Locale.FRANCE);
    registration.register(new AccountsCommands());

    Bukkit.getScheduler().runTaskTimer(this, this, 6000, 6000);
  }
コード例 #2
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);
            }
          }
        });
  }
コード例 #3
0
  public void addListener(final ProtocolManager protocolManager, final JavaPlugin myPlugin) {

    protocolManager.addPacketListener(
        new PacketAdapter(myPlugin, ConnectionSide.SERVER_SIDE, 0x05, 0x18) {
          @Override
          public void onPacketSending(PacketEvent event) {
            PacketContainer packet = event.getPacket();
            Random rand = new Random();
            double num = rand.nextDouble();
            double rate = 0.05;
            rate = plugin.getConfig().getDouble("rate");

            try {
              switch (event.getPacketID()) {
                case 0x18:
                  if (num >= rate) {
                    return;
                  }
                  if (packet.getSpecificModifier(int.class).size() >= 2
                      && (packet.getSpecificModifier(int.class).read(1) == 54)) {
                    server
                        .getScheduler()
                        .scheduleSyncDelayedTask(
                            myPlugin,
                            new FakePacketEntityEquipment(
                                myPlugin,
                                protocolManager,
                                event.getPlayer(),
                                packet.getSpecificModifier(int.class).read(0)));
                  }
                  break;
              }

            } catch (FieldAccessException e) {
              logger.log(Level.SEVERE, "Couldn't access field.", e);
            }
          }
        });
  }
コード例 #4
0
  public void onEnable() {
    version = getDescription().getVersion();
    name = getDescription().getName();
    final List<String> hiddenCommands = new ArrayList<String>();
    hiddenCommands.add("all");

    try {
      Metrics metrics = new Metrics(this);
      metrics.start();
      Logger.getLogger("Minecraft")
          .info(
              "["
                  + name
                  + "] Version: "
                  + version
                  + " Metrics started: http://mcstats.org/plugin/HideAndCustomPlugins");

    } catch (IOException e) {
      System.out.println("Error Submitting stats!");
    }
    loadConfig();
    Bukkit.getServer().getPluginManager().registerEvents(this, this);

    if (getConfig().getBoolean("update-notification")) {
      try {
        new Updater(
                this,
                80016,
                "http://dev.bukkit.org/bukkit-plugins/hideandcustomplugins/",
                "SearchForUpdates")
            .search();
      } catch (MalformedURLException e1) {
        e1.printStackTrace();
      }
    }

    final ProtocolManager manager = ProtocolLibrary.getProtocolManager();
    manager.addPacketListener(
        new PacketAdapter(this, new PacketType[] {PacketType.Play.Client.TAB_COMPLETE}) {
          @SuppressWarnings("rawtypes")
          public void onPacketReceiving(PacketEvent event) {
            if ((event.getPacketType() == PacketType.Play.Client.TAB_COMPLETE)
                && (!event.getPlayer().hasPermission("hideandcustomplugins.bypass"))
                && (((String) event.getPacket().getStrings().read(0)).startsWith("/"))
                && (((String) event.getPacket().getStrings().read(0)).split(" ").length == 1)) {

              event.setCancelled(true);

              List<?> list = new ArrayList();
              List<?> extra = new ArrayList();

              String[] tabList = new String[list.size() + extra.size()];

              for (int index = 0; index < list.size(); index++) {
                tabList[index] = ((String) list.get(index));
              }

              for (int index = 0; index < extra.size(); index++) {
                tabList[(index + list.size())] = ('/' + (String) extra.get(index));
              }
              PacketContainer tabComplete =
                  manager.createPacket(PacketType.Play.Server.TAB_COMPLETE);
              tabComplete.getStringArrays().write(0, tabList);

              try {
                manager.sendServerPacket(event.getPlayer(), tabComplete);
              } catch (InvocationTargetException e) {
                e.printStackTrace();
              }
            }
          }
        });

    for (String s : getConfig().getString("plugins").split(", ")) {
      this.plugins.add(s);
    }
    Logger.getLogger("Minecraft")
        .info("[" + name + "] Version: " + version + " Plugin has been activated successfully.");
  }