Skip to content

Commit

Permalink
update to spigot 1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
DPOH-VAR committed Jun 13, 2017
1 parent ec73fac commit 2a0e69f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<plugin-debug>false</plugin-debug>

<plugin-author>DPOH-VAR</plugin-author>
<plugin-website>http://dev.bukkit.org/bukkit-plugins/powernbt/</plugin-website>
<plugin-website>https://www.spigotmc.org/resources/powernbt.9098/</plugin-website>
<plugin-description>Powerful nbt editor for bukkit</plugin-description>

<java-version>1.6</java-version>

<bukkit-version>1.10.2-R0.1-SNAPSHOT</bukkit-version>
<spigot-version>1.10.2-R0.1-SNAPSHOT</spigot-version>
<bukkit-version>1.12-R0.1-SNAPSHOT</bukkit-version>
<spigot-version>1.12-R0.1-SNAPSHOT</spigot-version>

<github.global.server>github</github.global.server>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -30,7 +30,7 @@

<groupId>me.dpohvar.powernbt</groupId>
<artifactId>PowerNBT</artifactId>
<version>0.8.7</version>
<version>0.8.8</version>
<packaging>jar</packaging>

<description>Powerful NBT editor for CraftBukkit 1.5 and later</description>
Expand Down
36 changes: 19 additions & 17 deletions src/main/java/me/dpohvar/powernbt/utils/EntityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public class EntityUtils {
private RefClass cCraftEntity = getRefClass("{cb}.entity.CraftEntity, {CraftEntity}");
private RefClass cEntityPlayer = getRefClass("{nms}.EntityPlayer, {nm}.entity.player.EntityPlayer, {EntityPlayer}");
private RefMethod mGetHandleEntity = cCraftEntity.findMethodByReturnType(cEntity);
private RefMethod mReadEntity;
private RefMethod mWriteEntity;
private RefMethod mReadPlayer;
private RefMethod mWritePlayer;
private RefMethod mReadEntityToNBT;
private RefMethod mWriteNBTToEntity;
private RefMethod mReadPlayerToNBT;
private RefMethod mWriteNBTToPlayer;
private RefField fForgeData;

private RefMethod mCreateEntity;
Expand Down Expand Up @@ -62,13 +62,13 @@ private EntityUtils(){
fForgeData = cEntity.findField(cNBTTagCompound);
} catch (Exception ignored){}
try { // forge 1.6+
mWriteEntity = mWritePlayer = cEntity.findMethod(
mWriteNBTToEntity = mWriteNBTToPlayer = cEntity.findMethod(
new MethodCondition().withTypes(cNBTTagCompound).withSuffix("e")
);
mReadEntity = cEntity.findMethod(
mReadEntityToNBT = cEntity.findMethod(
new MethodCondition().withTypes(cNBTTagCompound).withSuffix("c").withIndex(0)
);
mReadPlayer = cEntity.findMethod(
mReadPlayerToNBT = cEntity.findMethod(
new MethodCondition().withTypes(cNBTTagCompound).withSuffix("d")
);
} catch (Exception e) {
Expand All @@ -77,23 +77,25 @@ private EntityUtils(){
}
} else {
try { // bukkit 1.6+
mWriteEntity = mWritePlayer = cEntity.findMethod(
mWriteNBTToEntity = mWriteNBTToPlayer = cEntity.findMethod(
new MethodCondition().withTypes(cNBTTagCompound).withName("f")
);
mReadEntity = cEntity.findMethod(
mReadEntityToNBT = cEntity.findMethod(
new MethodCondition().withTypes(cNBTTagCompound).withName("save"), // spigot 1.12
new MethodCondition().withTypes(cNBTTagCompound).withName("c")
);
mReadPlayer = cEntity.findMethod(
mReadPlayerToNBT = cEntity.findMethod(
new MethodCondition().withTypes(cNBTTagCompound).withName("save"), // spigot 1.12
new MethodCondition().withTypes(cNBTTagCompound).withName("e")
);
} catch (Exception ignored) { // old bukkit
mWriteEntity = mWritePlayer = cEntity.findMethod(
mWriteNBTToEntity = mWriteNBTToPlayer = cEntity.findMethod(
new MethodCondition().withTypes(cNBTTagCompound).withName("e")
);
mReadEntity = cEntity.findMethod(
mReadEntityToNBT = cEntity.findMethod(
new MethodCondition().withTypes(cNBTTagCompound).withName("c")
);
mReadPlayer = cEntity.findMethod(
mReadPlayerToNBT = cEntity.findMethod(
new MethodCondition().withTypes(cNBTTagCompound).withName("d")
);
}
Expand All @@ -107,18 +109,18 @@ public Object getHandleEntity(Entity entity){
public void readEntity(Entity entity, Object nbtTagCompound){
Object nmsEntity = getHandleEntity(entity);
if (cEntityPlayer.isInstance(nmsEntity)) {
mReadPlayer.of(nmsEntity).call(nbtTagCompound);
mReadPlayerToNBT.of(nmsEntity).call(nbtTagCompound);
} else {
mReadEntity.of(nmsEntity).call(nbtTagCompound);
mReadEntityToNBT.of(nmsEntity).call(nbtTagCompound);
}
}

public void writeEntity(Entity entity, Object nbtTagCompound){
Object liv = getHandleEntity(entity);
if(entity.getType() == EntityType.PLAYER){
mWritePlayer.of(liv).call(nbtTagCompound);
mWriteNBTToPlayer.of(liv).call(nbtTagCompound);
}else{
mWriteEntity.of(liv).call(nbtTagCompound);
mWriteNBTToEntity.of(liv).call(nbtTagCompound);
}
}

Expand Down
18 changes: 17 additions & 1 deletion src/main/java/me/dpohvar/powernbt/utils/ReflectionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public RefMethod findMethod(MethodCondition... condition) {
return c.find(this);
} catch (Exception ignored){
}
throw new RuntimeException("no such method");
throw new RuntimeException("no such method: " + Arrays.toString(condition) + " for class "+this.clazz.getName());
}

/**
Expand Down Expand Up @@ -456,6 +456,21 @@ public static class MethodCondition implements Cloneable{
private boolean checkStatic = false;
private boolean modStatic;

@Override
public String toString() {
StringBuilder b = new StringBuilder("");
if (name != null) b.append("name:").append(name).append(",");
if (prefix != null) b.append("prefix:").append(prefix).append(",");
if (suffix != null) b.append("suffix:").append(suffix).append(",");
if (checkForge) b.append("forge:").append(forge).append(",");
if (types != null) b.append("types:").append(types.toString()).append(",");
if (index != -1) b.append("index:").append(index).append(",");
if (checkAbstract) b.append("abstract:").append(modAbstract).append(",");
if (checkFinal) b.append("final:").append(modFinal).append(",");
if (checkStatic) b.append("modStatic:").append(modStatic).append(",");
return b.substring(0,b.length()-1);
}

public MethodCondition withForge(boolean forge){
this.checkForge = true;
this.forge = forge;
Expand Down Expand Up @@ -594,6 +609,7 @@ private RefMethod find(Class clazz) {
return new RefMethod(methods.get(index));
}
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: ${project.artifactId}
description: ${plugin-description}
author: ${plugin-author}
main: me.dpohvar.powernbt.PowerNBT
website: http://dev.bukkit.org/bukkit-plugins/varscript/
website: ${plugin-website}
version: ${project.version}
commands:
powernbt:
Expand Down

0 comments on commit 2a0e69f

Please sign in to comment.