Skip to content

Commit

Permalink
Everything update
Browse files Browse the repository at this point in the history
- Split the NMS classes into seperate Gradle submodules
- Refactored the NMS classes to not depend on the 'core'
- On join, players now get checked for if they're premium, if so, their normal skin will be set
- package files renamed to fileHandlers
- Think that's all? Anyway it works now
  • Loading branch information
TheDutchMC committed Aug 13, 2020
1 parent b5016e2 commit 59712f9
Show file tree
Hide file tree
Showing 17 changed files with 285 additions and 113 deletions.
5 changes: 5 additions & 0 deletions Spigot_1_16_R1/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apply plugin: 'java'
dependencies {
compileOnly 'org.spigotmc:spigot:1.16.1-R0.1-SNAPSHOT'
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
Expand All @@ -16,12 +13,14 @@
import net.minecraft.server.v1_16_R1.EntityPlayer;
import net.minecraft.server.v1_16_R1.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_16_R1.PacketPlayOutPlayerInfo.EnumPlayerInfoAction;
import nl.thedutchmc.SkinFixer.SkinFixer;

public class ChangeGameProfile_1_16_r1 implements ChangeGameProfile {
/* It is normal for all net.minecraft.server and org.bukkit.craftbukkit imports
* to error when you are not working on that version.
* Gradle cannot handle multiple versions
*/
public class ChangeGameProfile_1_16_r1 {

@Override
public void changeProfile(UUID uuid, String skinValue, String skinSignature) {
public static void changeProfile(UUID uuid, String skinValue, String skinSignature) {
Player player = Bukkit.getPlayer(uuid);

//Fetch the EntityPlayer and their GameProfile
Expand All @@ -40,38 +39,16 @@ public void changeProfile(UUID uuid, String skinValue, String skinSignature) {
//Remove the old texture, and set the new one.
pm.put("textures", new Property("textures", skinValue, skinSignature));

//Reload the player for all online players
for(Player p : Bukkit.getOnlinePlayers()) {
p.hidePlayer(SkinFixer.INSTANCE, player);
p.showPlayer(SkinFixer.INSTANCE, player);
}

//Reload the skin for the player itself
reloadSkinForSelf(player);
}

@Override
public void reloadSkinForSelf(Player player) {
public static void reloadSkinForSelf(Player player) {
final EntityPlayer ep = ((CraftPlayer) player).getHandle();
final PacketPlayOutPlayerInfo removeInfo = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, ep);
final PacketPlayOutPlayerInfo addInfo = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, ep);
final Location loc = player.getLocation().clone();

ep.playerConnection.sendPacket(removeInfo);
ep.playerConnection.sendPacket(addInfo);

World teleportToWorld = null;
for(World w : Bukkit.getWorlds()) {
if(!w.equals(loc.getWorld())) teleportToWorld = w;
}

player.teleport(new Location(teleportToWorld, 0, 255, 0));
new BukkitRunnable() {
@Override
public void run() {
player.teleport(loc);
player.updateInventory();
}
}.runTaskLater(SkinFixer.INSTANCE, 5L);
}
}
5 changes: 5 additions & 0 deletions Spigot_1_16_R2/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apply plugin: 'java'
dependencies {
compileOnly 'org.spigotmc:spigot:1.16.2-R0.1-SNAPSHOT'
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package nl.thedutchmc.SkinFixer.changeSkin.changeGameProfile;

import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;

import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;

import net.minecraft.server.v1_16_R2.EntityPlayer;
import net.minecraft.server.v1_16_R2.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_16_R2.PacketPlayOutPlayerInfo.EnumPlayerInfoAction;

public class ChangeGameProfile_1_16_r2 {

public static void changeProfile(UUID uuid, String skinValue, String skinSignature) {
Player player = Bukkit.getPlayer(uuid);

//Fetch the EntityPlayer and their GameProfile
EntityPlayer ep = ((CraftPlayer)player).getHandle();
GameProfile gp = ep.getProfile();

//Get the skin texture property
PropertyMap pm = gp.getProperties();

//Check if the propertyMap contains a texture value, if so, remove it.
if(pm.containsKey("textures")) {
Property property = pm.get("textures").iterator().next();
pm.remove("textures", property);
}

//Remove the old texture, and set the new one.
pm.put("textures", new Property("textures", skinValue, skinSignature));

//Reload the skin for the player itself
reloadSkinForSelf(player);
}

public static void reloadSkinForSelf(Player player) {
final EntityPlayer ep = ((CraftPlayer) player).getHandle();
final PacketPlayOutPlayerInfo removeInfo = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, ep);
final PacketPlayOutPlayerInfo addInfo = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, ep);

ep.playerConnection.sendPacket(removeInfo);
ep.playerConnection.sendPacket(addInfo);
}
}
21 changes: 14 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
id 'java'
id 'eclipse'
id 'com.github.johnrengelman.shadow' version '5.0.0'
id 'com.github.johnrengelman.shadow' version '5.0.0'

}

Expand Down Expand Up @@ -36,19 +36,26 @@ allprojects {
}

dependencies {

compileOnly 'org.spigotmc:spigot:1.16.1-R0.1-SNAPSHOT'
//Apache HTTP Client
compile 'org.apache.httpcomponents:httpclient:4.5.12'
compile 'org.json:json:20200518'

//JSON
compile 'org.json:json:20200518'

//JDA, for hooking into Discord
//JDA
implementation ('net.dv8tion:JDA:4.2.0_168') {
exclude module: 'opus-java'
}

//Spigot 1.16.1
compileOnly 'org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT'

//NMS classes
compile project('Spigot_1_16_R1')
compile project('Spigot_1_16_R2')
}

shadowJar() {

classifier = ''
relocate 'net.dv8tion.jda', 'nl.thedutchmc.libs.jda'
}
}
11 changes: 2 additions & 9 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user guide at https://docs.gradle.org/5.1.1/userguide/multi_project_builds.html
*/

rootProject.name = pluginName
include ':Spigot_1_16_R1'
include ':Spigot_1_16_R2'
2 changes: 1 addition & 1 deletion src/main/java/nl/thedutchmc/SkinFixer/JdaHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.MessageChannel;
import nl.thedutchmc.SkinFixer.discordEvents.MessageReceivedEventListener;
import nl.thedutchmc.SkinFixer.files.ConfigurationHandler;
import nl.thedutchmc.SkinFixer.fileHandlers.ConfigurationHandler;

public class JdaHandler {

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/nl/thedutchmc/SkinFixer/SkinFixer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import nl.thedutchmc.SkinFixer.commandHandlers.GetCodeCommandExecutor;
import nl.thedutchmc.SkinFixer.commandHandlers.SetSkinCommandExecutor;
import nl.thedutchmc.SkinFixer.commandHandlers.SkinFixerCommandExecutor;
import nl.thedutchmc.SkinFixer.files.ConfigurationHandler;
import nl.thedutchmc.SkinFixer.files.StorageHandler;
import nl.thedutchmc.SkinFixer.fileHandlers.ConfigurationHandler;
import nl.thedutchmc.SkinFixer.fileHandlers.StorageHandler;
import nl.thedutchmc.SkinFixer.minecraftEvents.PlayerJoinEventListener;

public class SkinFixer extends JavaPlugin {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package nl.thedutchmc.SkinFixer.changeSkin;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;

public class CheckUserAgainstMojang {

public static String premiumUser(String playername) {
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("https://api.mojang.com/profiles/minecraft");

String jsonOut = "[\"" + playername + "\"]";

StringEntity requestEntity = new StringEntity(
jsonOut,
ContentType.APPLICATION_JSON);

httpPost.setEntity(requestEntity);

HttpResponse response = null;
try {
response = httpClient.execute(httpPost);
} catch (IOException e) {
e.printStackTrace();
}

HttpEntity entity = response.getEntity();

String json = "";
try {
json = EntityUtils.toString(entity, StandardCharsets.UTF_8);
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

JSONTokener tokener = new JSONTokener(json);
JSONArray array = (JSONArray) tokener.nextValue();
for(Object o : array) {
JSONObject jsonObj = (JSONObject) o;
String uuid = (String) jsonObj.getString("id");
return insertDashUUID(uuid);
}

return null;
}

private static String insertDashUUID(String uuid) {
StringBuilder sb = new StringBuilder(uuid);
sb.insert(8, "-");
sb = new StringBuilder(sb.toString());
sb.insert(13, "-");
sb = new StringBuilder(sb.toString());
sb.insert(18, "-");
sb = new StringBuilder(sb.toString());
sb.insert(23, "-");

return sb.toString();
}
}
30 changes: 30 additions & 0 deletions src/main/java/nl/thedutchmc/SkinFixer/changeSkin/GetSkin.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
Expand Down Expand Up @@ -58,4 +59,33 @@ public static String getSkin(String skinUrl, boolean slim) {

return null;
}

public static String getSkinOfValidPlayer(String uuid) {
HttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet("https://api.mineskin.org/generate/user/" + uuid);

try {
//Execute and get the response.
HttpResponse response = httpclient.execute(httpGet);
Scanner sc = new Scanner(response.getEntity().getContent());

StringBuilder responseBuilder = new StringBuilder();

while(sc.hasNext()) {
responseBuilder.append(sc.next());
}

sc.close();
return responseBuilder.toString();

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

return null;
}
}
Loading

0 comments on commit 59712f9

Please sign in to comment.