Skip to content

Commit

Permalink
Improvements and fixes
Browse files Browse the repository at this point in the history
Improved PersistentDataContainer Adapter (SyntaxContainer) for 1.14 -
latest -> There were some methods which didn't really work, they will
now throw UnsupportedOperationException's
Improved entity kill -> Entities will now disappear for players instead
of just being killed on the server
Improved Skin handling -> Skins can now be downloaded with the
MojangProfileServer class, this means you don't need to create a Mojang
object (only needed for custom skins)

Fixed that all players were kicked if NmsPlayer.update() was called
without a skin change

Bumped Version to 1.1.4
  • Loading branch information
Lauriichan committed Apr 6, 2021
1 parent 45591d6 commit 0d0513c
Show file tree
Hide file tree
Showing 65 changed files with 701 additions and 569 deletions.
516 changes: 259 additions & 257 deletions pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public NmsPlayer getPlayer(UUID uniqueId) {

public NmsPlayer getPlayer(Player player) {
if (players.containsKey(player.getUniqueId())) {
return players.get(player.getUniqueId());
NmsPlayer nmsPlayer = players.get(player.getUniqueId());
if (nmsPlayer.getBukkitPlayer() != player) {
players.put(player.getUniqueId(), nmsPlayer = createPlayer(player));
}
return nmsPlayer;
}
NmsPlayer nmsPlayer = createPlayer(player);
players.put(player.getUniqueId(), nmsPlayer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.sourcewriters.minecraft.versiontools.reflection.data.WrapType;
import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContainer;
import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContext;
import net.sourcewriters.minecraft.versiontools.skin.Skin;
import net.sourcewriters.minecraft.versiontools.utils.minecraft.Skin;

public final class SkinDataType implements WrapType<WrappedContainer, Skin> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.bukkit.entity.Player;

import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContainer;
import net.sourcewriters.minecraft.versiontools.skin.Skin;
import net.sourcewriters.minecraft.versiontools.utils.minecraft.Skin;

public interface NmsPlayer extends NmsEntityLiving {

Expand All @@ -14,6 +14,8 @@ public interface NmsPlayer extends NmsEntityLiving {
void setSkin(Skin skin);

Skin getSkin();

Skin getRealSkin();

void setName(String name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public Player[] getVisibleAsPlayer() {

@Override
public void kill() {
hide(getVisibleAsPlayer());
handle.die();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@
import net.sourcewriters.minecraft.versiontools.reflection.data.wrap.SimpleSyntaxContainer;
import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsPlayer;
import net.sourcewriters.minecraft.versiontools.reflection.reflect.ReflectionProvider;
import net.sourcewriters.minecraft.versiontools.skin.Skin;
import net.sourcewriters.minecraft.versiontools.utils.bukkit.MojangProfileServer;
import net.sourcewriters.minecraft.versiontools.utils.bukkit.Players;
import net.sourcewriters.minecraft.versiontools.utils.minecraft.MojangProfileServer;
import net.sourcewriters.minecraft.versiontools.utils.minecraft.Skin;
import net.sourcewriters.minecraft.versiontools.utils.thread.PostAsync;

public class Player1_10_R1 extends EntityLiving1_10_R1<EntityPlayer> implements NmsPlayer {

private String realName;
private Skin realSkin;

private final WrappedContainer dataAdapter;

public Player1_10_R1(Player player, PersistentContainer<?> container) {
Expand Down Expand Up @@ -78,7 +80,12 @@ public void setSkin(Skin skin) {

@Override
public Skin getSkin() {
return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE);
return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, realSkin);
}

@Override
public Skin getRealSkin() {
return realSkin;
}

@Override
Expand Down Expand Up @@ -261,7 +268,10 @@ public void update() {
}

private final void update(boolean flag) {
PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId()));
PostAsync.forcePost(() -> {
realName = MojangProfileServer.getName(getUniqueId());
realSkin = MojangProfileServer.getSkin(realName, getUniqueId());
});
if (flag) {
GameProfile profile = handle.getProfile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.bukkit.entity.Player;

import net.sourcewriters.minecraft.versiontools.reflection.tools.SkinTools;
import net.sourcewriters.minecraft.versiontools.skin.Skin;
import net.sourcewriters.minecraft.versiontools.utils.minecraft.Skin;

public class SkinTools1_10_R1 extends SkinTools {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public Player[] getVisibleAsPlayer() {

@Override
public void kill() {
hide(getVisibleAsPlayer());
handle.die();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@
import net.sourcewriters.minecraft.versiontools.reflection.data.wrap.SimpleSyntaxContainer;
import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsPlayer;
import net.sourcewriters.minecraft.versiontools.reflection.reflect.ReflectionProvider;
import net.sourcewriters.minecraft.versiontools.skin.Skin;
import net.sourcewriters.minecraft.versiontools.utils.bukkit.MojangProfileServer;
import net.sourcewriters.minecraft.versiontools.utils.bukkit.Players;
import net.sourcewriters.minecraft.versiontools.utils.minecraft.MojangProfileServer;
import net.sourcewriters.minecraft.versiontools.utils.minecraft.Skin;
import net.sourcewriters.minecraft.versiontools.utils.thread.PostAsync;

public class Player1_11_R1 extends EntityLiving1_11_R1<EntityPlayer> implements NmsPlayer {

private String realName;
private Skin realSkin;

private final WrappedContainer dataAdapter;

public Player1_11_R1(Player player, PersistentContainer<?> container) {
Expand Down Expand Up @@ -77,7 +79,12 @@ public void setSkin(Skin skin) {

@Override
public Skin getSkin() {
return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE);
return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, realSkin);
}

@Override
public Skin getRealSkin() {
return realSkin;
}

@Override
Expand Down Expand Up @@ -260,7 +267,10 @@ public void update() {
}

private final void update(boolean flag) {
PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId()));
PostAsync.forcePost(() -> {
realName = MojangProfileServer.getName(getUniqueId());
realSkin = MojangProfileServer.getSkin(realName, getUniqueId());
});
if (flag) {
GameProfile profile = handle.getProfile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.bukkit.entity.Player;

import net.sourcewriters.minecraft.versiontools.reflection.tools.SkinTools;
import net.sourcewriters.minecraft.versiontools.skin.Skin;
import net.sourcewriters.minecraft.versiontools.utils.minecraft.Skin;

public class SkinTools1_11_R1 extends SkinTools {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public Player[] getVisibleAsPlayer() {

@Override
public void kill() {
hide(getVisibleAsPlayer());
handle.die();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@
import net.sourcewriters.minecraft.versiontools.reflection.data.wrap.SimpleSyntaxContainer;
import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsPlayer;
import net.sourcewriters.minecraft.versiontools.reflection.reflect.ReflectionProvider;
import net.sourcewriters.minecraft.versiontools.skin.Skin;
import net.sourcewriters.minecraft.versiontools.utils.bukkit.MojangProfileServer;
import net.sourcewriters.minecraft.versiontools.utils.bukkit.Players;
import net.sourcewriters.minecraft.versiontools.utils.minecraft.MojangProfileServer;
import net.sourcewriters.minecraft.versiontools.utils.minecraft.Skin;
import net.sourcewriters.minecraft.versiontools.utils.thread.PostAsync;

public class Player1_12_R1 extends EntityLiving1_12_R1<EntityPlayer> implements NmsPlayer {

private String realName;
private Skin realSkin;

private final WrappedContainer dataAdapter;

public Player1_12_R1(Player player, PersistentContainer<?> container) {
Expand Down Expand Up @@ -77,7 +79,12 @@ public void setSkin(Skin skin) {

@Override
public Skin getSkin() {
return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE);
return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, realSkin);
}

@Override
public Skin getRealSkin() {
return realSkin;
}

@Override
Expand Down Expand Up @@ -260,7 +267,10 @@ public void update() {
}

private final void update(boolean flag) {
PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId()));
PostAsync.forcePost(() -> {
realName = MojangProfileServer.getName(getUniqueId());
realSkin = MojangProfileServer.getSkin(realName, getUniqueId());
});
if (flag) {
GameProfile profile = handle.getProfile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.bukkit.entity.Player;

import net.sourcewriters.minecraft.versiontools.reflection.tools.SkinTools;
import net.sourcewriters.minecraft.versiontools.skin.Skin;
import net.sourcewriters.minecraft.versiontools.utils.minecraft.Skin;

public class SkinTools1_12_R1 extends SkinTools {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ public Player[] getVisibleAsPlayer() {

@Override
public void kill() {
hide(getVisibleAsPlayer());
handle.die();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@
import net.sourcewriters.minecraft.versiontools.reflection.data.wrap.SimpleSyntaxContainer;
import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsPlayer;
import net.sourcewriters.minecraft.versiontools.reflection.reflect.ReflectionProvider;
import net.sourcewriters.minecraft.versiontools.skin.Skin;
import net.sourcewriters.minecraft.versiontools.utils.bukkit.MojangProfileServer;
import net.sourcewriters.minecraft.versiontools.utils.bukkit.Players;
import net.sourcewriters.minecraft.versiontools.utils.minecraft.MojangProfileServer;
import net.sourcewriters.minecraft.versiontools.utils.minecraft.Skin;
import net.sourcewriters.minecraft.versiontools.utils.thread.PostAsync;

public class Player1_13_R1 extends EntityLiving1_13_R1<EntityPlayer> implements NmsPlayer {

private String realName;
private Skin realSkin;

private final WrappedContainer dataAdapter;

public Player1_13_R1(Player player, PersistentContainer<?> container) {
Expand Down Expand Up @@ -76,7 +78,12 @@ public void setSkin(Skin skin) {

@Override
public Skin getSkin() {
return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE);
return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, realSkin);
}

@Override
public Skin getRealSkin() {
return realSkin;
}

@Override
Expand Down Expand Up @@ -258,7 +265,10 @@ public void update() {
}

private final void update(boolean flag) {
PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId()));
PostAsync.forcePost(() -> {
realName = MojangProfileServer.getName(getUniqueId());
realSkin = MojangProfileServer.getSkin(realName, getUniqueId());
});
if (flag) {
GameProfile profile = handle.getProfile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.bukkit.entity.Player;

import net.sourcewriters.minecraft.versiontools.reflection.tools.SkinTools;
import net.sourcewriters.minecraft.versiontools.skin.Skin;
import net.sourcewriters.minecraft.versiontools.utils.minecraft.Skin;

public class SkinTools1_13_R1 extends SkinTools {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ public Player[] getVisibleAsPlayer() {

@Override
public void kill() {
hide(getVisibleAsPlayer());
handle.die();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@
import net.sourcewriters.minecraft.versiontools.reflection.data.wrap.SimpleSyntaxContainer;
import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsPlayer;
import net.sourcewriters.minecraft.versiontools.reflection.reflect.ReflectionProvider;
import net.sourcewriters.minecraft.versiontools.skin.Skin;
import net.sourcewriters.minecraft.versiontools.utils.bukkit.MojangProfileServer;
import net.sourcewriters.minecraft.versiontools.utils.bukkit.Players;
import net.sourcewriters.minecraft.versiontools.utils.minecraft.MojangProfileServer;
import net.sourcewriters.minecraft.versiontools.utils.minecraft.Skin;
import net.sourcewriters.minecraft.versiontools.utils.thread.PostAsync;

public class Player1_13_R2 extends EntityLiving1_13_R2<EntityPlayer> implements NmsPlayer {

private String realName;
private Skin realSkin;

private final WrappedContainer dataAdapter;

public Player1_13_R2(Player player, PersistentContainer<?> container) {
Expand Down Expand Up @@ -76,7 +78,12 @@ public void setSkin(Skin skin) {

@Override
public Skin getSkin() {
return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE);
return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, realSkin);
}

@Override
public Skin getRealSkin() {
return realSkin;
}

@Override
Expand Down Expand Up @@ -258,7 +265,10 @@ public void update() {
}

private final void update(boolean flag) {
PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId()));
PostAsync.forcePost(() -> {
realName = MojangProfileServer.getName(getUniqueId());
realSkin = MojangProfileServer.getSkin(realName, getUniqueId());
});
if (flag) {
GameProfile profile = handle.getProfile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.bukkit.entity.Player;

import net.sourcewriters.minecraft.versiontools.reflection.tools.SkinTools;
import net.sourcewriters.minecraft.versiontools.skin.Skin;
import net.sourcewriters.minecraft.versiontools.utils.minecraft.Skin;

public class SkinTools1_13_R2 extends SkinTools {

Expand Down
Loading

0 comments on commit 0d0513c

Please sign in to comment.