Last active
September 12, 2022 20:59
-
-
Save DreamTexX/7220ec0253fb9f54bac720bc7ad9885b to your computer and use it in GitHub Desktop.
[Create Fake Player] #Spigot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// These two lines should be outside the npc spawn function for caching | |
HashMap<String, String> skins = new HashMap<>(); | |
HashMap<String, String> signatures = new HashMap<>(); | |
// This code was written inside an command, thats why (Player) commandSender | |
Player player = (Player) commandSender; | |
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); | |
WorldServer world = ((CraftWorld) player.getWorld()).getHandle(); | |
Location loc = player.getLocation(); | |
for (int x = loc.getBlockX() - 16; x < loc.getBlockX() + 16; x++) { | |
for (int z = loc.getBlockZ() - 16; z < loc.getBlockZ() + 16; z++) { | |
GameProfile profile = new GameProfile(UUID.randomUUID(), player.getName()); | |
if (skins.containsKey(player.getName())) { | |
profile.getProperties().put("textures", new Property("textures", skins.get(player.getName()), signatures.get(player.getName()))); | |
} else { | |
try { | |
HttpsURLConnection connection = (HttpsURLConnection) new URL(String.format("https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false", UUIDTypeAdapter.fromUUID(player.getUniqueId()))).openConnection(); | |
if (connection.getResponseCode() == HttpsURLConnection.HTTP_OK) { | |
String reply = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine(); | |
String skin = reply.split("\"value\":\"")[1].split("\"")[0]; | |
String signature = reply.split("\"signature\":\"")[1].split("\"")[0]; | |
skins.put(player.getName(), skin); | |
signatures.put(player.getName(), signature); | |
profile.getProperties().put("textures", new Property("textures", skin, signature)); | |
} else { | |
System.out.println("Connection could not be opened (Response code " + connection.getResponseCode() + ", " + connection.getResponseMessage() + ")"); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
EntityPlayer npc = new EntityPlayer(server, world, profile, new PlayerInteractManager(world)); | |
Location spawn = player.getLocation(); | |
npc.setLocation(x, loc.getBlockY(), z, 0, 0); | |
for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) { | |
PlayerConnection connection = ((CraftPlayer) onlinePlayer).getHandle().playerConnection; | |
connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc)); | |
connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc)); | |
} | |
} | |
} |
Both, skin and signature should be an ArrayList<String, String> if i read my code correctly. I will add it
Edit: I meant HashMap not ArrayList
ArrayList has a method called put
?
I thought more this is a HashMap, because the HashMap Class has a put
method, but I just asked to be sure.
Of course its an hashmap, i'm just lost xD
Ok, that makes more sense
Anyways thanks xD
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It has some mistakes, like it will not spawn for players that connect after the npc is spawned but that could be easily fixed when you store the npcs and send it when the player spawns.