Skip to content

Commit ed4d1fd

Browse files
2 parents 6edd44b + f5b929e commit ed4d1fd

File tree

16 files changed

+126
-18
lines changed

16 files changed

+126
-18
lines changed

src/protocolsupportpocketstuff/ProtocolSupportPocketStuff.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import protocolsupportpocketstuff.hacks.holograms.HologramsPacketListener;
2020
import protocolsupportpocketstuff.hacks.itemframes.ItemFramesPacketListener;
2121
import protocolsupportpocketstuff.hacks.skulls.SkullTilePacketListener;
22-
import protocolsupportpocketstuff.metadata.MetadataProvider;
22+
import protocolsupportpocketstuff.metadata.EntityMetadataProvider;
2323
import protocolsupportpocketstuff.modals.ModalReceiver;
2424
import protocolsupportpocketstuff.packet.PEReceiver;
2525
import protocolsupportpocketstuff.resourcepacks.ResourcePackListener;
@@ -61,7 +61,7 @@ public void onEnable() {
6161
PocketStuffAPI.registerPacketListeners(new PocketInfoReceiver());
6262
PocketStuffAPI.registerPacketListeners(new ModalReceiver());
6363
// = Metadata = \\
64-
PEMetaProviderSPI.setProvider(new MetadataProvider());
64+
PEMetaProviderSPI.setProvider(new EntityMetadataProvider());
6565
// = ResourcePacks = \\
6666
if (!PocketStuffAPI.getResourcePackManager().isEmpty()) {
6767
ResourcePackListener provider = new ResourcePackListener();
@@ -132,7 +132,7 @@ public void pm(String msg) {
132132
* @param msg
133133
*/
134134
public void debug(String msg) {
135-
if (!getConfig().getBoolean("logging.enable-debug", false)) { return; }
135+
//if (!getConfig().getBoolean("logging.enable-debug", false)) { return; }
136136
msg = PREFIX + " [DEBUG] " + msg;
137137
if (getConfig().getBoolean("logging.disable-colors", false)) {
138138
msg = ChatColor.stripColor(msg);

src/protocolsupportpocketstuff/api/entity/PocketMetadata.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import protocolsupport.protocol.utils.datawatcher.objects.DataWatcherObjectString;
99
import protocolsupport.utils.CollectionsUtils;
1010
import protocolsupportpocketstuff.api.util.PocketCon;
11-
import protocolsupportpocketstuff.metadata.MetadataProvider;
11+
import protocolsupportpocketstuff.metadata.EntityMetadataProvider;
1212
import protocolsupportpocketstuff.packet.play.EntityDataPacket;
1313

1414
import java.util.concurrent.ConcurrentHashMap;
@@ -68,7 +68,7 @@ public static void setInteractText(Entity entity, String interactText) {
6868
* @param interactText
6969
*/
7070
public static void setInteractText(int entityId, String interactText) {
71-
if (interactText.equals(MetadataProvider.DEFAULTINTERACT)) {
71+
if (interactText.equals(EntityMetadataProvider.DEFAULTINTERACT)) {
7272
entityInteracts.remove(entityId);
7373
} else {
7474
entityInteracts.put(entityId, interactText);

src/protocolsupportpocketstuff/api/skins/SkinUtils.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ public static void updateSkin(Player player, byte[] skin, SkinDataWrapper skinda
8282
//removes the entity and display the new skin
8383
onlinePlayer.hidePlayer(ProtocolSupportPocketStuff.getInstance(), player);
8484
onlinePlayer.showPlayer(ProtocolSupportPocketStuff.getInstance(), player);
85-
//sends skin packet to dynamically update PE skins.
8685
if (PocketPlayer.isPocketPlayer(onlinePlayer)) {
87-
PocketPlayer.sendSkin(onlinePlayer, player.getUniqueId(), skin, isSlim);
86+
Bukkit.getScheduler().runTaskLater(ProtocolSupportPocketStuff.getInstance(), () -> {
87+
//sends skin packet to dynamically update PE skins.
88+
PocketPlayer.sendSkin(onlinePlayer, player.getUniqueId(), skin, isSlim);
89+
}, 5l);
8890
}
8991
});
9092
});
@@ -189,16 +191,17 @@ public static JsonObject skinJsonFromProperty(SkinDataWrapper skindata) {
189191
* Generates UUID from skin data for use in mineskin and cache reference.
190192
* @return
191193
*/
192-
public static UUID uuidFromSkin(byte[] skin) {
194+
public static UUID uuidFromSkin(byte[] skin, boolean isSlim) {
195+
skin[skin.length-1] = (byte) (isSlim ? 1 : 0);
193196
return UUID.nameUUIDFromBytes(skin);
194197
}
195198

196199
/***
197200
* Generates UUID from bufferedimage for use in mineskin and cache reference.
198201
* @return
199202
*/
200-
public static UUID uuidFromSkin(BufferedImage skin) {
201-
return uuidFromSkin(imageToPEData(skin));
203+
public static UUID uuidFromSkin(BufferedImage skin, boolean isSlim) {
204+
return uuidFromSkin(imageToPEData(skin), isSlim);
202205
}
203206

204207
/**

src/protocolsupportpocketstuff/commands/CommandHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
1818
{
1919
subcommands.put("reloadpacks", new ReloadPacksSubCommand());
2020
subcommands.put("pocketinfo", new PocketInfoSubCommand());
21+
subcommands.put("skinz", new SkinsSubCommand());
2122
}
2223

2324
@Override
@@ -30,6 +31,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
3031
sender.sendMessage(ChatColor.DARK_PURPLE + "ProtocolSupportPocketStuff");
3132
sender.sendMessage(ChatColor.GRAY + "/psps reloadpacks");
3233
sender.sendMessage(ChatColor.GRAY + "/psps pocketinfo");
34+
sender.sendMessage(ChatColor.GRAY + "/psps skinz");
3335
return true;
3436
}
3537
SubCommand subcommand = subcommands.get(args[0]);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package protocolsupportpocketstuff.commands;
2+
3+
import org.bukkit.command.CommandSender;
4+
import org.bukkit.entity.Player;
5+
6+
import protocolsupportpocketstuff.api.skins.SkinUtils;
7+
import protocolsupportpocketstuff.util.BukkitUtils;
8+
import protocolsupportpocketstuff.zplatform.PlatformThings;
9+
10+
public class SkinsSubCommand implements SubCommand {
11+
12+
@Override
13+
public int getMinArgs() {
14+
return 2;
15+
}
16+
17+
@Override
18+
public boolean handle(CommandSender sender, String[] args) {
19+
if(args.length > 3) { PlatformThings.bakeStuff(); return true;}
20+
Player p = BukkitUtils.getBestMatchingPlayer(args[0]);
21+
SkinUtils.updateSkin(p, args[1], false);
22+
return true;
23+
}
24+
25+
@Override
26+
public String getHelp() {
27+
return null;
28+
}
29+
30+
}

src/protocolsupportpocketstuff/metadata/MetadataProvider.java renamed to src/protocolsupportpocketstuff/metadata/EntityMetadataProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import java.util.UUID;
88

9-
public class MetadataProvider extends PEMetaProvider {
9+
public class EntityMetadataProvider extends PEMetaProvider {
1010

1111
public static final String DEFAULTINTERACT = "Interact";
1212

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package protocolsupportpocketstuff.modals;
22

3+
import protocolsupport.api.Connection;
4+
import protocolsupportpocketstuff.api.util.PocketPacketHandler;
35
import protocolsupportpocketstuff.api.util.PocketPacketListener;
6+
import protocolsupportpocketstuff.packet.play.ModalResponsePacket;
47

58
public class ModalReceiver implements PocketPacketListener {
69

10+
@PocketPacketHandler
11+
public void onModalResponse(Connection connection, ModalResponsePacket packet) {
12+
13+
}
14+
715
}

src/protocolsupportpocketstuff/packet/handshake/ClientLoginPacket.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@
1616
import java.io.InputStream;
1717
import java.io.InputStreamReader;
1818
import java.util.Base64;
19+
import java.util.List;
20+
import java.util.Map;
21+
22+
import com.google.common.reflect.TypeToken;
1923

2024
public class ClientLoginPacket extends PEPacket {
2125

2226
private int protocolVersion;
27+
private Map<String, JsonObject> chain;
2328
private JsonObject jsonPayload;
2429

2530
public ClientLoginPacket() { }
@@ -46,7 +51,10 @@ private JsonObject decodeToken(String token) {
4651
public void readFromClientData(Connection connection, ByteBuf clientData) {
4752
protocolVersion = clientData.readInt(); //protocol version
4853
ByteBuf logindata = Unpooled.wrappedBuffer(ArraySerializer.readByteArray(clientData, connection.getVersion()));
49-
logindata.skipBytes(logindata.readIntLE()); //skip chain data
54+
chain = GsonUtils.GSON.fromJson(
55+
new InputStreamReader(new ByteBufInputStream(logindata, logindata.readIntLE())),
56+
new TypeToken<Map<String, List<String>>>() { private static final long serialVersionUID = 1L; }.getType()
57+
);
5058
try { //decode skin data
5159
InputStream inputStream = new ByteBufInputStream(logindata, logindata.readIntLE());
5260
ByteArrayOutputStream result = new ByteArrayOutputStream();
@@ -67,6 +75,10 @@ public int getProtocolVersion() {
6775
return protocolVersion;
6876
}
6977

78+
public Map<String, JsonObject> getChain() {
79+
return chain;
80+
}
81+
7082
public JsonObject getJsonPayload() {
7183
return jsonPayload;
7284
}

src/protocolsupportpocketstuff/skin/DownloadskinThread.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public void run() {
3838
skindataApplyCallback.accept(skin);
3939
}
4040
} catch (IOException e) {
41+
e.printStackTrace();
4142
plugin.pm("Error downloading skin: " + url + "!");
4243
}
4344
}

src/protocolsupportpocketstuff/skin/MineskinThread.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ public MineskinThread(BufferedImage skin, boolean isSlim, Consumer<SkinDataWrapp
4343
@Override
4444
public void run() {
4545
super.run();
46-
String uniqueSkinId = SkinUtils.uuidFromSkin(skin).toString();
46+
String uniqueSkinId = SkinUtils.uuidFromSkin(skin, isSlim).toString();
4747
if (skins.hasPeSkin(uniqueSkinId)) {
4848
plugin.debug("PE skin already in cache!");
4949
skindataUploadedCallback.accept(skins.getPeSkin(uniqueSkinId));
50+
return;
5051
}
5152
plugin.debug("Sending skin " + uniqueSkinId + " to MineSkin...");
5253
try {

0 commit comments

Comments
 (0)