public static WrappedGameProfile getGameProfileWithThisSkin(
     UUID uuid, String playerName, WrappedGameProfile profileWithSkin) {
   try {
     WrappedGameProfile gameProfile =
         new WrappedGameProfile(uuid != null ? uuid : UUID.randomUUID(), playerName);
     if (LibVersion.is1_7_6()) {
       gameProfile.getProperties().putAll(profileWithSkin.getProperties());
     }
     return gameProfile;
   } catch (Exception ex) {
     ex.printStackTrace();
   }
   return null;
 }
 public static WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) {
   try {
     Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null);
     for (Method method : getNmsClass("MinecraftServer").getMethods()) {
       if (method.getReturnType().getSimpleName().equals("MinecraftSessionService")) {
         Object session = method.invoke(minecraftServer);
         return WrappedGameProfile.fromHandle(
             session
                 .getClass()
                 .getMethod("fillProfileProperties", gameProfile.getHandleType(), boolean.class)
                 .invoke(session, gameProfile.getHandle(), true));
       }
     }
   } catch (Exception ex) {
     ex.printStackTrace();
   }
   return null;
 }
 public static Object createEntityInstance(String entityName) {
   try {
     Class<?> entityClass = getNmsClass("Entity" + entityName);
     Object entityObject;
     Object world = getWorld(Bukkit.getWorlds().get(0));
     if (entityName.equals("Player")) {
       Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null);
       Object playerinteractmanager =
           getNmsClass("PlayerInteractManager")
               .getConstructor(getNmsClass("World"))
               .newInstance(world);
       if (LibVersion.is1_7()) {
         WrappedGameProfile gameProfile = getGameProfile(null, "LibsDisguises");
         entityObject =
             entityClass
                 .getConstructor(
                     getNmsClass("MinecraftServer"),
                     getNmsClass("WorldServer"),
                     gameProfile.getHandleType(),
                     playerinteractmanager.getClass())
                 .newInstance(
                     minecraftServer, world, gameProfile.getHandle(), playerinteractmanager);
       } else {
         entityObject =
             entityClass
                 .getConstructor(
                     getNmsClass("MinecraftServer"),
                     getNmsClass("World"),
                     String.class,
                     playerinteractmanager.getClass())
                 .newInstance(minecraftServer, world, "LibsDisguises", playerinteractmanager);
       }
     } else {
       entityObject = entityClass.getConstructor(getNmsClass("World")).newInstance(world);
     }
     return entityObject;
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
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);
  }
 private static WrappedGameProfile getProfileFromMojang(
     final String origName, final Object runnable) {
   final String playerName = origName.toLowerCase();
   if (gameProfiles.containsKey(playerName)) {
     if (gameProfiles.get(playerName) != null) {
       return gameProfiles.get(playerName);
     }
   } else if (Pattern.matches("([A-Za-z0-9_]){1,16}", origName)) {
     getAddedByPlugins().add(playerName);
     Player player = Bukkit.getPlayerExact(playerName);
     if (player != null) {
       WrappedGameProfile gameProfile = ReflectionManager.getGameProfile(player);
       if (!LibVersion.is1_7_6() || !gameProfile.getProperties().isEmpty()) {
         gameProfiles.put(playerName, gameProfile);
         return gameProfile;
       }
     }
     // Add null so that if this is called again. I already know I'm doing something about it
     gameProfiles.put(playerName, null);
     Bukkit.getScheduler()
         .runTaskAsynchronously(
             libsDisguises,
             new Runnable() {
               public void run() {
                 try {
                   final WrappedGameProfile gameProfile = lookupGameProfile(origName);
                   Bukkit.getScheduler()
                       .runTask(
                           libsDisguises,
                           new Runnable() {
                             public void run() {
                               if (!LibVersion.is1_7_6()
                                   || !gameProfile.getProperties().isEmpty()) {
                                 if (gameProfiles.containsKey(playerName)
                                     && gameProfiles.get(playerName) == null) {
                                   gameProfiles.put(playerName, gameProfile);
                                 }
                                 if (runnables.containsKey(playerName)) {
                                   for (Object obj : runnables.remove(playerName)) {
                                     if (obj instanceof Runnable) {
                                       ((Runnable) obj).run();
                                     } else if (obj instanceof LibsProfileLookup) {
                                       ((LibsProfileLookup) obj).onLookup(gameProfile);
                                     }
                                   }
                                 }
                               }
                             }
                           });
                 } catch (Exception e) {
                   if (gameProfiles.containsKey(playerName)
                       && gameProfiles.get(playerName) == null) {
                     gameProfiles.remove(playerName);
                     getAddedByPlugins().remove(playerName);
                   }
                   System.out.print(
                       "[LibsDisguises] Error when fetching "
                           + playerName
                           + "'s uuid from mojang: "
                           + e.getMessage());
                 }
               }
             });
   } else {
     return ReflectionManager.getGameProfile(null, origName);
   }
   if (runnable != null) {
     if (!runnables.containsKey(playerName)) {
       runnables.put(playerName, new ArrayList<Object>());
     }
     runnables.get(playerName).add(runnable);
   }
   return ReflectionManager.getGameProfile(null, origName);
 }
 public static WrappedGameProfile getGameProfile(Player player) {
   if (LibVersion.is1_7()) {
     return WrappedGameProfile.fromPlayer(player);
   }
   return null;
 }