Skip to content

Commit

Permalink
Implemented fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dawson Hessler committed Jun 1, 2020
1 parent 4b5afa8 commit bdae031
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
String display() default "";
boolean playerOnly() default false;
boolean consoleOnly() default false;
boolean opOnly() default false;
boolean async() default false;
String[] permission() default {};
String[] tabCompletions() default {}; //Format label::result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, S
Command command = entry.getMethod().getMethod().getAnnotation(Command.class);
Atlas.getInstance().getProfile().start("anCommand:" + cmd.getLabel());
Runnable runnable = () -> {
if(command.playerOnly() && !(sender instanceof Player)) {
if(command.opOnly() && !sender.isOp()) {
sender.sendMessage(Color.translate(command.noPermissionMessage()));
} else if(command.playerOnly() && !(sender instanceof Player)) {
sender.sendMessage(Color.Red + "This command is for players only!");
} else if(command.consoleOnly() && !(sender instanceof ConsoleCommandSender)) {
sender.sendMessage(Color.Red + "This command can only be run via terminal.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import cc.funkemunky.api.reflections.types.WrappedMethod;
import cc.funkemunky.api.tinyprotocol.api.ProtocolVersion;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
Expand All @@ -22,7 +21,6 @@ public class CraftReflection {
public static WrappedClass craftWorld = Reflections.getCBClass("CraftWorld"); //1.7-1.14
public static WrappedClass craftInventoryPlayer = Reflections.getCBClass("inventory.CraftInventoryPlayer"); //1.7-1.14
public static WrappedClass craftServer = Reflections.getCBClass("CraftServer"); //1.7-1.14
public static WrappedClass craftMagicNumbers = Reflections.getCBClass("util.CraftMagicNumbers");

//Vanilla Instances
private static WrappedMethod itemStackInstance = craftItemStack.getMethod("asNMSCopy", ItemStack.class); //1.7-1.14
Expand All @@ -34,9 +32,6 @@ public class CraftReflection {
private static WrappedMethod getInventory = craftInventoryPlayer.getMethod("getInventory"); //1.7-1.14
private static WrappedMethod mcServerInstance = craftServer.getMethod("getServer"); //1.7-1.14
private static WrappedMethod entityPlayerInstance = craftPlayer.getMethod("getHandle");
private static WrappedMethod magicBlockFromMaterial = craftMagicNumbers.getMethod("getBlock", Material.class);
private static WrappedMethod magicMaterialBlock = craftMagicNumbers.getMethod("getMaterial",
MinecraftReflection.block.getParent());

public static <T> T getVanillaItemStack(ItemStack stack) {
return itemStackInstance.invoke(null, stack);
Expand All @@ -60,10 +55,6 @@ public static <T> T getVanillaBlock(Block block) {
} else return blockInstance.invoke(block);
}

public static <T> T getVanillaBlock(Material material) {
return magicBlockFromMaterial.invoke(null, material);
}

public static <T> T getVanillaWorld(World world) {
return worldInstance.invoke(world);
}
Expand All @@ -80,9 +71,6 @@ public static <T> T getMinecraftServer() {
return mcServerInstance.invoke(Bukkit.getServer());
}

public static Material getTypeFromVanillaBlock(Object vanillaBlock) {
return magicMaterialBlock.invoke(null, vanillaBlock);
}
static {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class MinecraftReflection {
private static WrappedField pingField = entityPlayer.getFieldByName("ping");

//Blocks
private static WrappedMethod addCBoxes, bdGetBlock;
private static WrappedMethod addCBoxes;
public static WrappedClass blockPos;
private static WrappedConstructor blockPosConstructor;
private static WrappedMethod getBlockData;
Expand Down Expand Up @@ -302,10 +302,6 @@ public static <T> T getPlayerConnection(Object player) {
return connectionField.get(entityPlayer);
}

public static <T> T getBlockFromBlockData(Object blockData) {
return bdGetBlock.invoke(blockData);
}

//Can either use Player or EntityPlayer object.
public static <T> T getNetworkManager(Object player) {
return connectionNetworkField.get(getPlayerConnection(player));
Expand Down Expand Up @@ -360,7 +356,6 @@ public static <T> List<T> getVanillaChunks(Object provider) {
.getConstructor(double.class, double.class, double.class, double.class, double.class, double.class);
iBlockData = Reflections.getNMSClass("IBlockData");
worldGetType = worldServer.getMethod("getType", blockPos.getParent());
bdGetBlock = iBlockData.getMethodByType(block.getParent(), 0);
} else {
idioticOldStaticConstructorAABB = axisAlignedBB.getMethod("a",
double.class, double.class, double.class, double.class, double.class, double.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ private final class PacketInterceptor extends ChannelDuplexHandler {
public void channelRead(ChannelHandlerContext ctx, Object msg) {
// Intercept channel
final Channel channel = ctx.channel();

if (PACKET_LOGIN_IN_START.isInstance(msg)) {
GameProfile profile = getGameProfile.get(msg);
channelLookup.put(profile.getName(), channel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ public void process(Player player, ProtocolVersion version) {

@Override
public void updateObject() {
invulnerableField.set(getObject(), invulnerable);
flyingField.set(getObject(), flying);
allowedFlightField.set(getObject(), allowedFlight);
creativeModeField.set(getObject(), creativeMode);
flySpeedField.set(getObject(), flySpeed);
walkSpeedField.set(getObject(), walkSpeed);
setObject(NMSObject.construct(getObject(),
packet, invulnerable, flying, allowedFlight, creativeMode, flySpeed, walkSpeed));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void process(Player player, ProtocolVersion version) {
@Override
public void updateObject() {
if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_9)) {
mainHandField.set(getObject(), enumHand.getEnum(mainHand ? "MAIN_HAND" : "OFF_HAND"));
setObject(NMSObject.construct(getObject(), packet, enumHand.getEnum(mainHand ? "MAIN_HAND" : "OFF_HAND")));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package cc.funkemunky.api.tinyprotocol.packet.in;

import cc.funkemunky.api.reflections.Reflections;
import cc.funkemunky.api.reflections.types.WrappedClass;
import cc.funkemunky.api.tinyprotocol.api.NMSObject;
import cc.funkemunky.api.tinyprotocol.api.ProtocolVersion;
import cc.funkemunky.api.tinyprotocol.packet.types.BaseBlockPosition;
Expand Down Expand Up @@ -37,17 +35,7 @@ public WrappedInBlockDigPacket(Object packet, Player player) {

@Override
public void updateObject() {
if(ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_8)) {
fieldPosX.set(getObject(), position.getX());
fieldPosY.set(getObject(), position.getY());
fieldPosZ.set(getObject(), position.getZ());
face.set(getObject(), direction.ordinal());
intAction.set(getObject(), action.ordinal());
} else {
fieldBlockPosition.set(getObject(), position.getAsBlockPosition());
fieldDirection.set(getObject(), direction.toVanilla());
fieldDigType.set(getObject(), action.toVanilla());
}

}

@Override
Expand Down Expand Up @@ -79,21 +67,5 @@ public enum EnumPlayerDigType {
DROP_ITEM,
RELEASE_USE_ITEM,
SWAP_HELD_ITEMS;

static WrappedClass epdtClass = null;

public <T> T toVanilla() {
if(epdtClass == null ) return null;
return (T) epdtClass.getEnum(toString());
}

static {
if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_8)) {
epdtClass = Reflections.getNMSClass(ProtocolVersion.getGameVersion()
.isAbove(ProtocolVersion.V1_8)
? "EnumPlayerDigType"
: "PacketPlayInBlockDig.EnumPlayerDigType");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,29 @@
import cc.funkemunky.api.reflections.types.WrappedField;
import cc.funkemunky.api.tinyprotocol.api.NMSObject;
import cc.funkemunky.api.tinyprotocol.api.ProtocolVersion;
import cc.funkemunky.api.tinyprotocol.reflection.FieldAccessor;
import lombok.Getter;
import org.bukkit.entity.Player;

public class WrappedOutAbilitiesPacket extends NMSObject {
private static final String packet = Server.ABILITIES;

private static WrappedClass abilitiesClass = Reflections.getNMSClass(Server.ABILITIES);
private static WrappedField invulnerableField = abilitiesClass.getFieldByType(boolean.class, 0);
private static WrappedField flyingField = abilitiesClass.getFieldByType(boolean.class, 1);
private static WrappedField allowedFlightField = abilitiesClass.getFieldByType(boolean.class, 2);
private static WrappedField creativeModeField = abilitiesClass.getFieldByType(boolean.class, 3);
private static WrappedField flySpeedField = abilitiesClass.getFieldByType(float.class, 0);
private static WrappedField walkSpeedField = abilitiesClass.getFieldByType(float.class, 1);
private static FieldAccessor<Boolean>
invulnerableField = fetchField(packet, boolean.class, 0),
flyingField = fetchField(packet, boolean.class, 1),
allowedFlightField = fetchField(packet, boolean.class, 2),
creativeModeField = fetchField(packet, boolean.class, 3);
private static FieldAccessor<Float>
flySpeedField = fetchField(packet, float.class, 0),
walkSpeedField = fetchField(packet, float.class, 1);

private static WrappedClass abilitiesClass = Reflections.getNMSClass("PlayerAbilities");
private static WrappedField invulnerableAcc = abilitiesClass.getFieldByType(boolean.class, 0);
private static WrappedField flyingAcc = abilitiesClass.getFieldByType(boolean.class, 1);
private static WrappedField allowedFlightAcc = abilitiesClass.getFieldByType(boolean.class, 2);
private static WrappedField creativeModeAcc = abilitiesClass.getFieldByType(boolean.class, 3);
private static WrappedField flySpeedAcc = abilitiesClass.getFieldByType(float.class, 0);
private static WrappedField walkSpeedAcc = abilitiesClass.getFieldByType(float.class, 1);
@Getter
private boolean invulnerable, flying, allowedFlight, creativeMode;
@Getter
Expand All @@ -30,12 +40,12 @@ public WrappedOutAbilitiesPacket(Object object, Player player) {

public WrappedOutAbilitiesPacket(boolean invulernable, boolean flying, boolean allowedFlight, boolean creativeMode, float flySpeed, float walkSpeed) {
Object abilities = abilitiesClass.getConstructorAtIndex(0).newInstance();
invulnerableField.set(abilities, invulernable);
flyingField.set(abilities, flying);
allowedFlightField.set(abilities, allowedFlight);
creativeModeField.set(abilities, creativeMode);
flySpeedField.set(abilities, flySpeed);
walkSpeedField.set(abilities, walkSpeed);
invulnerableAcc.set(abilities, invulernable);
flyingAcc.set(abilities, flying);
allowedFlightAcc.set(abilities, allowedFlight);
creativeModeAcc.set(abilities, creativeMode);
flySpeedAcc.set(abilities, flySpeed);
walkSpeedAcc.set(abilities, walkSpeed);

setObject(Reflections.getNMSClass(packet).getConstructor(abilitiesClass.getParent()).newInstance(abilities));
}
Expand All @@ -52,11 +62,6 @@ public void process(Player player, ProtocolVersion version) {

@Override
public void updateObject() {
invulnerableField.set(getObject(), invulnerable);
flyingField.set(getObject(), flying);
allowedFlightField.set(getObject(), allowedFlight);
creativeModeField.set(getObject(), creativeMode);
flySpeedField.set(getObject(), flySpeed);
walkSpeedField.set(getObject(), walkSpeed);

}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cc.funkemunky.api.tinyprotocol.packet.out;

import cc.funkemunky.api.reflections.Reflections;
import cc.funkemunky.api.reflections.impl.CraftReflection;
import cc.funkemunky.api.reflections.impl.MinecraftReflection;
import cc.funkemunky.api.reflections.types.WrappedClass;
import cc.funkemunky.api.reflections.types.WrappedField;
import cc.funkemunky.api.reflections.types.WrappedMethod;
Expand All @@ -13,7 +11,6 @@
import cc.funkemunky.api.tinyprotocol.reflection.FieldAccessor;
import cc.funkemunky.api.utils.ReflectionsUtil;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;

Expand All @@ -25,19 +22,20 @@ public class WrappedOutBlockChange extends NMSObject {
private static FieldAccessor<Integer> legacyX;
private static FieldAccessor<Integer> legacyY;
private static FieldAccessor<Integer> legacyZ;
private static WrappedField blockChangeBlockField;
private static WrappedField blockDataIntField;
private static WrappedMethod getDataMethod;

//1.8 and newer
private static FieldAccessor<Object> blockPosAccessor;

private static WrappedField blockField;
private static WrappedField iBlockDataField;


private static WrappedClass blockChangeClass = Reflections.getNMSClass(packet);
private static WrappedClass nmsBlockClass = Reflections.getNMSClass("Block");
private static WrappedClass craftBlockClass = Reflections.getCBClass("CraftBlock");

private BaseBlockPosition position;
private Material type;

public WrappedOutBlockChange(Object packet) {
super(packet);
Expand All @@ -55,24 +53,14 @@ public WrappedOutBlockChange(Block block) {
public void process(Player player, ProtocolVersion version) {
if (ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_8)) {
position = new BaseBlockPosition(fetch(legacyX), fetch(legacyY), fetch(legacyZ));
type = CraftReflection.getTypeFromVanillaBlock(fetch(blockField));
} else {
position = new BaseBlockPosition(fetch(blockPosAccessor));
type = CraftReflection.getTypeFromVanillaBlock(MinecraftReflection.getBlockFromBlockData(fetch(blockField)));
}
}

@Override
public void updateObject() {
if(ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_8)) {
legacyX.set(getObject(), position.getX());
legacyY.set(getObject(), position.getY());
legacyZ.set(getObject(), position.getZ());
blockField.set(getObject(), CraftReflection.getVanillaBlock(type));
} else {
blockPosAccessor.set(getObject(), position.getAsBlockPosition());
blockField.set(getObject(), MinecraftReflection.getBlockData(CraftReflection.getVanillaBlock(type)));
}

}

static {
Expand All @@ -81,12 +69,13 @@ public void updateObject() {
legacyY = fetchField(packet, int.class, 1);
legacyZ = fetchField(packet, int.class, 2);

blockField = blockChangeClass.getFirstFieldByType(MinecraftReflection.block.getParent());

blockChangeBlockField = blockChangeClass.getFirstFieldByType(nmsBlockClass.getParent());
blockDataIntField = blockChangeClass.getFieldByName("data");
getDataMethod = Reflections.getNMSClass("World").getMethod("getData", int.class, int.class, int.class);
} else {
blockPosAccessor = fetchField(packet, Object.class, 0);
blockField = blockChangeClass.getFieldByType(ReflectionsUtil.iBlockData, 0);
iBlockDataField = blockChangeClass.getFieldByType(ReflectionsUtil.iBlockData, 0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void process(Player player, ProtocolVersion version) {

@Override
public void updateObject() {

}

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ public class WrappedOutEntityEffectPacket extends NMSObject {
public byte flags;

private static WrappedClass wrapped = Reflections.getNMSClass(Server.ENTITY_EFFECT);
private static WrappedField fieldEntityId = wrapped.getFieldByType(int.class, 0),
fieldEffectId = wrapped.getFieldByType(byte.class, 0),
fieldAmplifier = wrapped.getFieldByType(byte.class, 1),
fieldDuration = wrapped.getFieldByType(int.class, 1),
fieldFlags = wrapped.getFieldByType(byte.class, 2);
private static WrappedField fieldEntityId,
fieldEffectId,
fieldAmplifier,
fieldDuration, fieldFlags;

public WrappedOutEntityEffectPacket(Object object, Player player) {
super(object, player);
Expand All @@ -32,15 +31,26 @@ public void updateObject() {
fieldEffectId.set(getObject(), effectId);
fieldAmplifier.set(getObject(), amplifier);
fieldDuration.set(getObject(), duration);
fieldFlags.set(getObject(), flags);
if(ProtocolVersion.getGameVersion().isAbove(ProtocolVersion.V1_7_10)) fieldFlags.set(getObject(), flags);
}

@Override
public void process(Player player, ProtocolVersion version) {
entityId = fieldEntityId.get(getObject());
effectId = fieldEntityId.get(getObject());
effectId = fieldEffectId.get(getObject());
amplifier = fieldAmplifier.get(getObject());
duration = fieldDuration.get(getObject());
flags = fieldFlags.get(getObject());
duration = ProtocolVersion.getGameVersion().isAbove(ProtocolVersion.V1_7_10)
? fieldDuration.get(getObject()) : (short) fieldDuration.get(getObject());
if(ProtocolVersion.getGameVersion().isAbove(ProtocolVersion.V1_7_10))flags = fieldFlags.get(getObject());
}

static {
fieldEntityId = wrapped.getFieldByType(int.class, 0);
fieldEffectId = wrapped.getFieldByType(byte.class, 0);
fieldAmplifier = wrapped.getFieldByType(byte.class, 1);
if(ProtocolVersion.getGameVersion().isAbove(ProtocolVersion.V1_7_10)) {
fieldDuration = wrapped.getFieldByType(int.class, 1);
fieldFlags = wrapped.getFieldByType(byte.class, 2);
} else fieldDuration = wrapped.getFieldByType(short.class, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public WrappedOutOpenWindow(int id, String name, WrappedChatMessage msg, int siz
public void process(Player player, ProtocolVersion version) {
id = fetch(idField);
name = fetch(nameField);
if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_8))
chatComponent = new WrappedChatComponent(fetch(chatCompField));
size = fetch(inventorySize);
}

Expand Down
Loading

0 comments on commit bdae031

Please sign in to comment.