/** * Construct a new game profile with the same name, but different id. * * @param id - the new id of the profile to create. * @return The new game profile. */ public WrappedGameProfile withId(String id) { return new WrappedGameProfile(id, getName()); }
public static WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) { try { Object minecraftServer = getMinecraftServer(); for (Method method : getNmsClass("MinecraftServer").getMethods()) { if (method.getReturnType().getSimpleName().equals("MinecraftSessionService")) { Object session = method.invoke(minecraftServer); return WrappedGameProfile.fromHandle(session.getClass() .getDeclaredMethod("fillProfileProperties", gameProfile.getHandleType(), boolean.class) .invoke(session, gameProfile.getHandle(), true)); } } } catch (Exception ex) { ex.printStackTrace(); } return null; }
public static WrappedGameProfile getGameProfile(Player player) { return WrappedGameProfile.fromPlayer(player); }
/** * Construct a new game profile with the same ID, but different name. * * @param name - the new name of the profile to create. * @return The new game profile. */ public WrappedGameProfile withName(String name) { return new WrappedGameProfile(getId(), name); }
private static WrappedGameProfile getSentName(int sentEntityId, WrappedGameProfile sent, Player destinationPlayer) { // Preconditions.checkState(Bukkit.getServer().isPrimaryThread(), "Can only process events on main thread."); Player namedPlayer = entityIdMap.get(sentEntityId); if (namedPlayer == null) { // They probably were dead when we reloaded return sent; } PlayerReceiveNameTagEvent oldEvent = new PlayerReceiveNameTagEvent(destinationPlayer, namedPlayer, sent.getName()); Bukkit.getServer().getPluginManager().callEvent(oldEvent); StringBuilder builtUUID = new StringBuilder(); if (!sent.getId().contains("-")) { IntStream.range(0, uuidSplit.length - 1).forEach(i -> builtUUID.append(sent.getId(), uuidSplit[i], uuidSplit[i + 1]).append("-")); } else { builtUUID.append(sent.getId()); } AsyncPlayerReceiveNameTagEvent newEvent = new AsyncPlayerReceiveNameTagEvent(destinationPlayer, namedPlayer, getPlayerDisplayName(namedPlayer), UUID.fromString(builtUUID.toString())); Bukkit.getServer().getPluginManager().callEvent(newEvent); return new WrappedGameProfile(newEvent.getUUID(), newEvent.getTag().substring(0, Math.min(newEvent.getTag().length(), 16))); }
public static WrappedGameProfile getClonedProfile(WrappedGameProfile gameProfile) { return getGameProfileWithThisSkin(null, gameProfile.getName(), gameProfile); }
public static Object getPlayerInfoData(Object playerInfoPacket, WrappedGameProfile gameProfile) { try { Object playerListName = getNmsClass("ChatComponentText").getDeclaredConstructor(String.class) .newInstance(gameProfile.getName()); return getNmsClass("PacketPlayOutPlayerInfo$PlayerInfoData") .getDeclaredConstructor(getNmsClass("PacketPlayOutPlayerInfo"), gameProfile.getHandleType(), int.class, getNmsClass("EnumGamemode"), getNmsClass("IChatBaseComponent")) .newInstance(playerInfoPacket, gameProfile.getHandle(), 0, getNmsClass("EnumGamemode").getEnumConstants()[1], playerListName); } catch (Exception ex) { ex.printStackTrace(); } return null; }
/** * Retrieve the UUID of the player. * <p> * Note that Minecraft 1.7.5 and earlier doesn't use UUIDs internally, and it may not be possible to convert the string to an UUID. * <p> * We use the same lax conversion as in {@link #WrappedGameProfile(String, String)}. * * @return The UUID, or NULL if the UUID is NULL. * @throws IllegalStateException If we cannot parse the internal ID as an UUID. */ public UUID getUUID() { UUID uuid = parsedUUID; if (uuid == null) { try { if (GET_UUID_STRING != null) { uuid = parseUUID(getId()); } else if (GET_ID != null) { uuid = (UUID) GET_ID.invoke(handle); } else { throw new IllegalStateException("Unsupported getId() method"); } // Cache for later parsedUUID = uuid; } catch (IllegalArgumentException e) { throw new IllegalStateException("Cannot parse ID " + getId() + " as an UUID in player profile " + getName(), e); } } return uuid; }
WrappedGameProfile profile = WrappedGameProfile.fromPlayer(p); if (!profile.getProperties().isEmpty()) { DisguiseUtilities.addGameProfile(p.getName(), profile); addTab.getPlayerInfoDataLists().write(0, Collections.singletonList( new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(disguise.getGameProfile().getName()))));
private void setSkullSkin(ItemStack itemStack, SkinModel skinData) { if (itemStack == null || skinData == null || itemStack.getType() != Material.SKULL_ITEM) return; try { SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta(); WrappedGameProfile gameProfile = new WrappedGameProfile(UUID.randomUUID(), null); plugin.getApi().applyProperties(gameProfile, skinData); skullProfileSetter.invoke(skullMeta, gameProfile.getHandle()); itemStack.setItemMeta(skullMeta); } catch (Exception ex) { plugin.getLog().info("Failed to set skull item {} to {}", itemStack, skinData, ex); } catch (Throwable throwable) { //rethrow errors we shouldn't silence them like OutOfMemory throw (Error) throwable; } } }
WrappedGameProfile profile = WrappedGameProfile.fromHandle(LOGIN_GAME_PROFILE.get(packet)); factory.cacheInjector(profile.getName(), this);
public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName, WrappedGameProfile profileWithSkin) { try { WrappedGameProfile gameProfile = new WrappedGameProfile(uuid != null ? uuid : getRandomUUID(), playerName); if (profileWithSkin != null) { gameProfile.getProperties().putAll(profileWithSkin.getProperties()); } return gameProfile; } catch (Exception ex) { ex.printStackTrace(); } return null; }
@Override public void onLookup(WrappedGameProfile gameProfile) { if (DisguiseAPI.isDisguiseInUse(disguise) && (!gameProfile.getName() .equals(disguise.getSkin() != null ? disguise.getSkin() : disguise.getName()) || !gameProfile.getProperties().isEmpty())) { disguise.setGameProfile(gameProfile); DisguiseUtilities.refreshTrackers(disguise); } } }, LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true));
@Override public void onProfileLookupSucceeded(GameProfile profile) { gameProfile = WrappedGameProfile.fromHandle(profile); }
/** * Construct a wrapper around an existing game profile. * * @param handle - the underlying profile, or NULL. * @return A wrapper around an existing game profile. */ public static WrappedGameProfile fromHandle(Object handle) { if (handle == null) return null; return new WrappedGameProfile(handle); }
gameProfile.getHandleType(), playerinteractmanager.getClass()) .newInstance(minecraftServer, world, gameProfile.getHandle(), playerinteractmanager); break; case "EnderPearl":
@Override public void onPacketSending(final PacketEvent event) { if (event.isCancelled()) return; Player observer = event.getPlayer(); if (event.getPacket().getPlayerInfoAction().read(0) != PlayerInfoAction.ADD_PLAYER) return; List<PlayerInfoData> list = event.getPacket().getPlayerInfoDataLists().read(0); Iterator<PlayerInfoData> itel = list.iterator(); while (itel.hasNext()) { PlayerInfoData data = itel.next(); Player player = Bukkit.getPlayer(data.getProfile().getUUID()); if (player == null) continue; Disguise disguise = DisguiseAPI.getDisguise(observer, player); if (disguise == null) continue; if (!disguise.isHidePlayer()) continue; itel.remove(); } if (list.isEmpty()) { event.setCancelled(true); } else { event.getPacket().getPlayerInfoDataLists().write(0, list); } }
@Override public void applyProperties(WrappedGameProfile profile, SkinModel targetSkin) { //remove existing skins profile.getProperties().clear(); if (targetSkin != null) { profile.getProperties().put(SkinProperty.SKIN_KEY, convertToProperty(targetSkin)); } }