@Override
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof Player) {
      Player player = (Player) sender;
      if (label.equalsIgnoreCase("explosion")) {
        PacketContainer fakeExplosion =
            protocolManager.createPacket(PacketType.Play.Server.EXPLOSION);

        // Set the coordinates
        try {
          fakeExplosion
              .getSpecificModifier(double.class)
              .write(0, player.getLocation().getX())
              .write(1, player.getLocation().getY())
              .write(2, player.getLocation().getZ());
          fakeExplosion.getSpecificModifier(float.class).write(0, 3.0F);

          protocolManager.sendServerPacket(player, fakeExplosion);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }

      return true;
    }

    return false;
  }
Exemple #2
1
 public static void clearTab(Player p) {
   if (!p.isOnline()) return;
   int a;
   String msg;
   WrappedGameProfile gameProfile;
   if (protocolManager.getProtocolVersion(p) >= 47) {
     TabHolder47 tabold = (TabHolder47) playerTabLast47.get(p.getName());
     if (tabold != null) {
       for (int b = 0; b < tabold.maxv; b++) {
         for (a = 0; a < tabold.maxh; a++) {
           msg = tabold.tabs[a][b];
           gameProfile = tabold.tabGameProfiles[a][b];
           addPacket(
               p,
               msg.substring(0, Math.min(msg.length(), 16)),
               getSlotId(b, a),
               gameProfile,
               false,
               0);
         }
       }
     }
   } else {
     TabHolder tabold = (TabHolder) playerTabLast.get(p.getName());
     if (tabold != null) {
       for (String[] s : tabold.tabs) {
         for (String message : s) {
           if (message != null) {
             addPacket(p, message.substring(0, Math.min(message.length(), 16)), 0, null, false, 0);
           }
         }
       }
     }
   }
 }
Exemple #3
0
  @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);
  }
Exemple #4
0
  private static void addPacket(
      Player p, String msg, int slotId, WrappedGameProfile gameProfile, boolean b, int ping) {
    PacketContainer message = protocolManager.createPacket(PacketType.Play.Server.PLAYER_INFO);
    String nameToShow = (!shuttingdown ? "$" : "") + msg;
    if (protocolManager.getProtocolVersion(p) >= 47) {
      nameToShow =
          (!shuttingdown ? "$" : "")
              + ChatColor.DARK_GRAY
              + slotId
              + ": "
              + msg.substring(0, Math.min(msg.length(), 10));
    }
    EnumWrappers.PlayerInfoAction action;
    if (b) {
      action = EnumWrappers.PlayerInfoAction.ADD_PLAYER;
    } else {
      action = EnumWrappers.PlayerInfoAction.REMOVE_PLAYER;
    }
    message.getPlayerInfoAction().write(0, action);
    List<PlayerInfoData> pInfoData = new ArrayList<PlayerInfoData>();
    if (gameProfile != null) {
      pInfoData.add(
          new PlayerInfoData(
              gameProfile
                  .withName(nameToShow.substring(1))
                  .withId(
                      UUID.nameUUIDFromBytes(
                              ("OfflinePlayer:" + nameToShow.substring(1)).getBytes(Charsets.UTF_8))
                          .toString()),
              ping,
              EnumWrappers.NativeGameMode.SURVIVAL,
              WrappedChatComponent.fromText(nameToShow)));
    } else {
      pInfoData.add(
          new PlayerInfoData(
              new WrappedGameProfile(
                  UUID.nameUUIDFromBytes(
                      ("OfflinePlayer:" + nameToShow.substring(1)).getBytes(Charsets.UTF_8)),
                  nameToShow.substring(1)),
              ping,
              EnumWrappers.NativeGameMode.SURVIVAL,
              WrappedChatComponent.fromText(nameToShow)));
    }

    message.getPlayerInfoDataLists().write(0, pInfoData);
    List<PacketContainer> packetList = cachedPackets.get(p);
    if (packetList == null) {
      packetList = new ArrayList<PacketContainer>();
      cachedPackets.put(p, packetList);
    }
    packetList.add(message);
  }
Exemple #5
0
  public static void updatePlayer(Player p) {
    if (!p.isOnline()) {
      return;
    }
    r = 0;
    e = 0;
    if (protocolManager.getProtocolVersion(p) >= 47) {
      TabObject47 tabo = (TabObject47) playerTab47.get(p.getName());
      TabHolder47 tab = tabo.getTab();
      if (tab == null) {
        return;
      }

      clearTab(p);
      for (int b = 0; b < tab.maxv; b++) {
        for (int a = 0; a < tab.maxh; a++) {
          if (tab.tabs[a][b] == null) {
            tab.tabs[a][b] = nextNull();
          }
          String msg = tab.tabs[a][b];
          int ping = tab.tabPings[a][b];
          WrappedGameProfile gameProfile = tab.tabGameProfiles[a][b];
          addPacket(
              p,
              msg == null ? " " : msg.substring(0, Math.min(msg.length(), 16)),
              getSlotId(b, a),
              gameProfile,
              true,
              ping);
        }
      }
      flushPackets(p, tab.getCopy());
    } else {
      TabObject tabo = (TabObject) playerTab.get(p.getName());
      TabHolder tab = tabo.getTab();
      if (tab == null) {
        return;
      }

      clearTab(p);
      for (int b = 0; b < tab.maxv; b++) {
        for (int a = 0; a < tab.maxh; a++) {
          if (tab.tabs[a][b] == null) {
            tab.tabs[a][b] = nextNull();
          }
          String msg = tab.tabs[a][b];
          int ping = tab.tabPings[a][b];
          addPacket(
              p,
              msg == null ? " " : msg.substring(0, Math.min(msg.length(), 16)),
              0,
              null,
              true,
              ping);
        }
      }
      flushPackets(p, tab.getCopy());
    }
  }
 @Override
 public void playSound(Location location, String sound, float volume, float pitch) {
   PacketContainer packet = protocolManager.createPacket(62);
   packet.getStrings().write(0, sound);
   int p = (int) (pitch * 63D);
   if (p < 0) p = 0;
   if (p > 255) p = 255;
   packet
       .getIntegers()
       .write(0, (int) (location.getX() * 8D))
       .write(1, (int) (location.getY() * 8D))
       .write(2, (int) (location.getZ() * 8D))
       .write(3, p);
   packet.getFloat().write(0, volume);
   protocolManager.broadcastServerPacket(
       packet, location, volume > 1.0 ? (int) (16 * volume) : 16);
 }
Exemple #7
0
 public static void resetTabList(Player p) {
   int a = 0;
   int b = 0;
   for (Player pl : Bukkit.getOnlinePlayers()) {
     setTabString(Bukkit.getPluginManager().getPlugin("TabAPI"), p, a, b, pl.getPlayerListName());
     b++;
     if (b > getHorizSize(protocolManager.getProtocolVersion(pl))) {
       b = 0;
       a++;
     }
   }
 }
 @Override
 public void playSound(Player player, String sound, float volume, float pitch) {
   Location loc = player.getLocation();
   PacketContainer packet = protocolManager.createPacket(62);
   packet.getStrings().write(0, sound);
   int p = (int) (pitch * 63D);
   if (p < 0) p = 0;
   if (p > 255) p = 255;
   packet
       .getIntegers()
       .write(0, (int) (loc.getX() * 8D))
       .write(1, (int) (loc.getY() * 8D))
       .write(2, (int) (loc.getZ() * 8D))
       .write(3, p);
   packet.getFloat().write(0, volume);
   try {
     protocolManager.sendServerPacket(player, packet);
   } catch (InvocationTargetException e) {
     e.printStackTrace();
   }
 }
Exemple #9
0
  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);
            }
          }
        });
  }
 @Override
 public void playParticleEffect(
     Location location,
     String name,
     float spreadHoriz,
     float spreadVert,
     float speed,
     int count,
     int radius,
     float yOffset) {
   PacketContainer packet = protocolManager.createPacket(63);
   packet.getStrings().write(0, name);
   packet
       .getFloat()
       .write(0, (float) location.getX())
       .write(1, (float) location.getY() + yOffset)
       .write(2, (float) location.getZ())
       .write(3, spreadHoriz)
       .write(4, spreadVert)
       .write(5, spreadHoriz)
       .write(6, speed);
   packet.getIntegers().write(0, count);
   protocolManager.broadcastServerPacket(packet, location, radius);
 }
Exemple #11
0
 public static void setTabString(
     Plugin plugin, Player p, int x, int y, String msg, int ping, WrappedGameProfile gameProfile) {
   try {
     if (protocolManager.getProtocolVersion(p) >= 47) {
       TabObject47 tabo = getTab47(p);
       tabo.setTab(plugin, x, y, msg, ping, gameProfile);
       playerTab47.put(p.getName(), tabo);
     } else {
       TabObject tabo = getTab(p);
       tabo.setTab(plugin, x, y, msg, ping);
       playerTab.put(p.getName(), tabo);
     }
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
  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);
            }
          }
        });
  }
  /** Sends the self disguise to the player */
  public static void sendSelfDisguise(final Player player, final TargetedDisguise disguise) {
    try {
      if (!disguise.isDisguiseInUse()
          || !player.isValid()
          || !player.isOnline()
          || !disguise.isSelfDisguiseVisible()
          || !disguise.canSee(player)) {
        return;
      }
      Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(player);
      if (entityTrackerEntry == null) {
        // A check incase the tracker is null.
        // If it is, then this method will be run again in one tick. Which is when it should be
        // constructed.
        // Else its going to run in a infinite loop hue hue hue..
        // At least until this disguise is discarded
        Bukkit.getScheduler()
            .runTask(
                libsDisguises,
                new Runnable() {
                  public void run() {
                    if (DisguiseAPI.getDisguise(player, player) == disguise) {
                      sendSelfDisguise(player, disguise);
                    }
                  }
                });
        return;
      }
      // Add himself to his own entity tracker
      ((HashSet<Object>)
              ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
                  .get(entityTrackerEntry))
          .add(ReflectionManager.getNmsEntity(player));
      ProtocolManager manager = ProtocolLibrary.getProtocolManager();
      // Send the player a packet with himself being spawned
      manager.sendServerPacket(
          player,
          manager
              .createPacketConstructor(PacketType.Play.Server.NAMED_ENTITY_SPAWN, player)
              .createPacket(player));
      WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(player);
      sendSelfPacket(
          player,
          manager
              .createPacketConstructor(
                  PacketType.Play.Server.ENTITY_METADATA, player.getEntityId(), dataWatcher, true)
              .createPacket(player.getEntityId(), dataWatcher, true));

      boolean isMoving = false;
      try {
        Field field =
            ReflectionManager.getNmsClass("EntityTrackerEntry").getDeclaredField("isMoving");
        field.setAccessible(true);
        isMoving = field.getBoolean(entityTrackerEntry);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
      // Send the velocity packets
      if (isMoving) {
        Vector velocity = player.getVelocity();
        sendSelfPacket(
            player,
            manager
                .createPacketConstructor(
                    PacketType.Play.Server.ENTITY_VELOCITY,
                    player.getEntityId(),
                    velocity.getX(),
                    velocity.getY(),
                    velocity.getZ())
                .createPacket(
                    player.getEntityId(), velocity.getX(), velocity.getY(), velocity.getZ()));
      }

      // Why the hell would he even need this. Meh.
      if (player.getVehicle() != null && player.getEntityId() > player.getVehicle().getEntityId()) {
        sendSelfPacket(
            player,
            manager
                .createPacketConstructor(
                    PacketType.Play.Server.ATTACH_ENTITY, 0, player, player.getVehicle())
                .createPacket(0, player, player.getVehicle()));
      } else if (player.getPassenger() != null
          && player.getEntityId() > player.getPassenger().getEntityId()) {
        sendSelfPacket(
            player,
            manager
                .createPacketConstructor(
                    PacketType.Play.Server.ATTACH_ENTITY, 0, player.getPassenger(), player)
                .createPacket(0, player.getPassenger(), player));
      }

      // Resend the armor
      for (int i = 0; i < 5; i++) {
        ItemStack item;
        if (i == 0) {
          item = player.getItemInHand();
        } else {
          item = player.getInventory().getArmorContents()[i - 1];
        }

        if (item != null && item.getType() != Material.AIR) {
          sendSelfPacket(
              player,
              manager
                  .createPacketConstructor(
                      PacketType.Play.Server.ENTITY_EQUIPMENT, player.getEntityId(), i, item)
                  .createPacket(player.getEntityId(), i, item));
        }
      }
      Location loc = player.getLocation();
      // If the disguised is sleeping for w/e reason
      if (player.isSleeping()) {
        sendSelfPacket(
            player,
            manager
                .createPacketConstructor(
                    PacketType.Play.Server.BED,
                    player,
                    loc.getBlockX(),
                    loc.getBlockY(),
                    loc.getBlockZ())
                .createPacket(player, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
      }

      // Resend any active potion effects
      for (Object potionEffect : player.getActivePotionEffects()) {
        sendSelfPacket(
            player,
            manager
                .createPacketConstructor(
                    PacketType.Play.Server.ENTITY_EFFECT, player.getEntityId(), potionEffect)
                .createPacket(player.getEntityId(), potionEffect));
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
  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.");
  }