NmsBasics. NPE Evasion. Sign handle.
This commit is contained in:
parent
78c3ece4cb
commit
3c23493eb3
@ -1,6 +1,7 @@
|
|||||||
package com.massivecraft.massivecore.nms;
|
package com.massivecraft.massivecore.nms;
|
||||||
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scoreboard.Objective;
|
import org.bukkit.scoreboard.Objective;
|
||||||
@ -55,6 +56,11 @@ public class NmsBasics extends Mixin
|
|||||||
throw this.notImplemented();
|
throw this.notImplemented();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> T getHandle(Sign sign)
|
||||||
|
{
|
||||||
|
throw this.notImplemented();
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// GET BUKKIT
|
// GET BUKKIT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -3,6 +3,7 @@ package com.massivecraft.massivecore.nms;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scoreboard.Objective;
|
import org.bukkit.scoreboard.Objective;
|
||||||
@ -52,6 +53,11 @@ public class NmsBasics17R4P extends NmsBasics
|
|||||||
// org.bukkit.craftbukkit.scoreboard.CraftObjective#objective
|
// org.bukkit.craftbukkit.scoreboard.CraftObjective#objective
|
||||||
private Field fieldCraftObjectiveHandle;
|
private Field fieldCraftObjectiveHandle;
|
||||||
|
|
||||||
|
// org.bukkit.craftbukkit.block.CraftSign
|
||||||
|
private Class<?> classCraftSign;
|
||||||
|
// org.bukkit.craftbukkit.block.CraftSign#sign
|
||||||
|
private Field fieldclassCraftSignHandle;
|
||||||
|
|
||||||
// GET BUKKIT
|
// GET BUKKIT
|
||||||
// net.minecraft.server.Entity
|
// net.minecraft.server.Entity
|
||||||
private Class<?> classNmsEntity;
|
private Class<?> classNmsEntity;
|
||||||
@ -99,6 +105,9 @@ public class NmsBasics17R4P extends NmsBasics
|
|||||||
this.classCraftObjective = PackageType.CRAFTBUKKIT_SCOREBOARD.getClass("CraftObjective");
|
this.classCraftObjective = PackageType.CRAFTBUKKIT_SCOREBOARD.getClass("CraftObjective");
|
||||||
this.fieldCraftObjectiveHandle = ReflectionUtil.getField(this.classCraftObjective, "objective");
|
this.fieldCraftObjectiveHandle = ReflectionUtil.getField(this.classCraftObjective, "objective");
|
||||||
|
|
||||||
|
this.classCraftSign = PackageType.CRAFTBUKKIT_BLOCK.getClass("CraftSign");
|
||||||
|
this.fieldclassCraftSignHandle = ReflectionUtil.getField(this.classCraftSign, "sign");
|
||||||
|
|
||||||
// GET BUKKIT
|
// GET BUKKIT
|
||||||
this.classNmsEntity = PackageType.MINECRAFT_SERVER.getClass("Entity");
|
this.classNmsEntity = PackageType.MINECRAFT_SERVER.getClass("Entity");
|
||||||
this.methodNmsEntityGetBukkitEntity = ReflectionUtil.getMethod(this.classNmsEntity, "getBukkitEntity");
|
this.methodNmsEntityGetBukkitEntity = ReflectionUtil.getMethod(this.classNmsEntity, "getBukkitEntity");
|
||||||
@ -122,33 +131,45 @@ public class NmsBasics17R4P extends NmsBasics
|
|||||||
@Override
|
@Override
|
||||||
public <T> T getHandle(Entity entity)
|
public <T> T getHandle(Entity entity)
|
||||||
{
|
{
|
||||||
|
if (entity == null) return null;
|
||||||
return ReflectionUtil.invokeMethod(this.methodCraftEntityGetHandle, entity);
|
return ReflectionUtil.invokeMethod(this.methodCraftEntityGetHandle, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T getHandle(World world)
|
public <T> T getHandle(World world)
|
||||||
{
|
{
|
||||||
|
if (world == null) return null;
|
||||||
return ReflectionUtil.getField(this.fieldCraftWorldWorld, world);
|
return ReflectionUtil.getField(this.fieldCraftWorldWorld, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T getHandle(Scoreboard scoreboard)
|
public <T> T getHandle(Scoreboard scoreboard)
|
||||||
{
|
{
|
||||||
|
if (scoreboard == null) return null;
|
||||||
return ReflectionUtil.getField(this.fieldCraftScoreboardHandle, scoreboard);
|
return ReflectionUtil.getField(this.fieldCraftScoreboardHandle, scoreboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T getHandle(Team team)
|
public <T> T getHandle(Team team)
|
||||||
{
|
{
|
||||||
|
if (team == null) return null;
|
||||||
return ReflectionUtil.getField(this.fieldCraftTeamHandle, team);
|
return ReflectionUtil.getField(this.fieldCraftTeamHandle, team);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T getHandle(Objective objective)
|
public <T> T getHandle(Objective objective)
|
||||||
{
|
{
|
||||||
|
if (objective == null) return null;
|
||||||
return ReflectionUtil.getField(this.fieldCraftObjectiveHandle, objective);
|
return ReflectionUtil.getField(this.fieldCraftObjectiveHandle, objective);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T getHandle(Sign sign)
|
||||||
|
{
|
||||||
|
if (sign == null) return null;
|
||||||
|
return ReflectionUtil.getField(this.fieldclassCraftSignHandle, sign);
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// GET BUKKIT
|
// GET BUKKIT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -156,6 +177,7 @@ public class NmsBasics17R4P extends NmsBasics
|
|||||||
@Override
|
@Override
|
||||||
public <T extends Entity> T getBukkit(Object handle)
|
public <T extends Entity> T getBukkit(Object handle)
|
||||||
{
|
{
|
||||||
|
if (handle == null) return null;
|
||||||
return ReflectionUtil.invokeMethod(this.methodNmsEntityGetBukkitEntity, handle);
|
return ReflectionUtil.invokeMethod(this.methodNmsEntityGetBukkitEntity, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user