com.captainbern.minecraft.reflection.MinecraftReflection Java Examples

The following examples show how to use com.captainbern.minecraft.reflection.MinecraftReflection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InfoCommand.java    From HoloAPI with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        command = "info",
        description = "View information on active holograms",
        permission = "holoapi.holo.info"
)
public boolean command(CommandEvent event) {
    if (HoloAPI.getManager().getAllComplexHolograms().isEmpty()) {
        event.respond(Lang.NO_ACTIVE_HOLOGRAMS.getValue());
        return true;
    }

    event.respond(Lang.ACTIVE_DISPLAYS.getValue());
    info(event.sender(), HoloAPI.getManager().getAllComplexHolograms().keySet());
    if (MinecraftReflection.isUsingNetty() && event.sender() instanceof Player) {
        event.respond(Lang.TIP_HOVER_PREVIEW.getValue());
    }
    return true;
}
 
Example #2
Source File: HoloCommand.java    From HoloAPI with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        command = "holodebug",
        description = "Smashing bugs and coloring books",
        permission = "holo.debug"
)
public boolean debug(CommandEvent event) {
    event.respond("Debug results: ");
    event.respond("--------------[HoloAPI Stuff]--------------");
    event.respond("HoloAPI-Version: " + HoloAPI.getCore().getDescription().getVersion());
    event.respond("Message of the day: " + messages[GeneralUtil.random().nextInt(messages.length)]);
    event.respond("--------------[CraftBukkit Stuff]--------------");
    event.respond("Version tag: " + MinecraftReflection.getVersionTag());
    event.respond("NMS-package: " + MinecraftReflection.getMinecraftPackage());
    event.respond("CB-package: " + MinecraftReflection.getCraftBukkitPackage());
    event.respond("Bukkit version: " + Bukkit.getBukkitVersion());
    event.respond("--------------[Minecraft Server Stuff]--------------");
    event.respond("Using Netty: " + MinecraftReflection.isUsingNetty());
    event.respond("MinecraftServer: " + MinecraftReflection.getMinecraftClass("MinecraftServer").getCanonicalName());
    event.respond("Entity: " + MinecraftReflection.getMinecraftClass("Entity"));
    event.respond("Is (forge) Modded: " + (MinecraftReflection.getMinecraftClass("Entity").getCanonicalName().startsWith("net.minecraft.entity") ? "Definitely" : "Probably not"));
    return true;
}
 
Example #3
Source File: TagFormatter.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
public String formatForOldClient(String content) {
    int limit = 64;
    if (content.length() > limit && !MinecraftReflection.isUsingNetty()) {
        // 1.6.x client crashes if a name tag is longer than 64 characters
        // Unfortunate, but it must be accounted for
        content = content.substring(limit / 4, limit - (limit / 4));
    }

    return content;
}
 
Example #4
Source File: NearbyCommand.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        command = "nearby <radius>",
        description = "View information on all nearby holograms within the specified radius",
        permission = "holoapi.holo.nearby"
)
public boolean command(CommandEvent<Player> event) {
    int radius;
    try {
        radius = GeneralUtil.toInteger(event.variable("radius"));
    } catch (NumberFormatException e) {
        event.respond(Lang.INT_ONLY.getValue("string", event.variable("radius")));
        return true;
    }

    ArrayList<Hologram> nearby = new ArrayList<Hologram>();
    for (Hologram hologram : HoloAPI.getManager().getAllComplexHolograms().keySet()) {
        if (GeometryUtil.getNearbyEntities(hologram.getDefaultLocation(), radius).contains(event.sender())) {
            nearby.add(hologram);
        }
    }

    if (nearby.isEmpty()) {
        event.respond(Lang.NO_NEARBY_HOLOGRAMS.getValue("radius", radius));
        return true;
    }

    event.respond(Lang.HOLOGRAM_NEARBY.getValue("radius", radius));
    InfoCommand.info(event.sender(), nearby);
    if (MinecraftReflection.isUsingNetty()) {
        event.respond(Lang.TIP_HOVER_PREVIEW.getValue());
    }
    return true;
}
 
Example #5
Source File: HelpCommand.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        command = "help",
        description = "Retrieve help for all HoloAPI commands"
)
public boolean help(CommandEvent event) {
    HoloAPI.getCommandManager().getHelpService().sendPage(event.sender(), 1);
    if (MinecraftReflection.isUsingNetty() && event.sender() instanceof Player) {
        event.respond(Lang.TIP_HOVER_COMMANDS.getValue());
    }
    return true;
}
 
Example #6
Source File: HelpCommand.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        command = "help <index>",
        description = "Retrieve a certain help page of all HoloAPI commands"
)
public boolean helpPage(CommandEvent event) {
    try {
        HoloAPI.getCommandManager().getHelpService().sendPage(event.sender(), GeneralUtil.toInteger(event.variable("index")));
        if (MinecraftReflection.isUsingNetty() && event.sender() instanceof Player) {
            event.respond(Lang.TIP_HOVER_COMMANDS.getValue());
        }
    } catch (NumberFormatException e) {
        event.respond(Lang.HELP_INDEX_TOO_BIG.getValue("index", event.variable("index")));
    }
    return true;
}
 
Example #7
Source File: EntityUtil.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected static void initializeFields() {
    try {

        ClassTemplate goalTemplate = new Reflection().reflect(MinecraftReflection.getMinecraftClass("PathfinderGoalSelector"));

        List<SafeMethod<Void>> methodCandidates = goalTemplate.getSafeMethods(withArguments(int.class, MinecraftReflection.getMinecraftClass("PathfinderGoal")));
        if (methodCandidates.size() > 0) {
            ADD_GOAL = methodCandidates.get(0).getAccessor();
        } else {
            throw new RuntimeException("Failed to get the addGoal method!");
        }

        List<SafeField<List>> fieldCandidates = goalTemplate.getSafeFields(withType(List.class));
        if (fieldCandidates.size() > 1) {
            GOALS = fieldCandidates.get(0).getAccessor();
            ACTIVE_GOALS = fieldCandidates.get(0).getAccessor();
        } else {
            throw new RuntimeException("Failed to initialize the goal-lists!");
        }

        // The GoalSelector
        ClassTemplate entityTemplate = new Reflection().reflect(MinecraftReflection.getMinecraftClass("EntityInsentient"));
        List<SafeField<Object>> candidates = entityTemplate.getSafeFields(withType(goalTemplate.getReflectedClass()));

        if (candidates.size() > 0) {
            GOAL_SELECTOR = candidates.get(0).getAccessor(); // the normal selector is the first one
        } else {
            throw new RuntimeException("Failed to initialize the GoalSelector field for the entities");
        }

    } catch (Exception ಠ_ಠ) {
        throw new RuntimeException("Failed to initialize the goal-related fields!", ಠ_ಠ);
    }
}
 
Example #8
Source File: NMSEntityUtil.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
protected static void initializeFields() {
    try {

        ClassTemplate goalTemplate = new Reflection().reflect(MinecraftReflection.getMinecraftClass("PathfinderGoalSelector"));

        List<SafeMethod<Void>> methodCandidates = goalTemplate.getSafeMethods(withArguments(int.class, MinecraftReflection.getMinecraftClass("PathfinderGoal")));
        if (methodCandidates.size() > 0) {
            ADD_GOAL = methodCandidates.get(0).getAccessor();
        } else {
            throw new RuntimeException("Failed to get the addGoal method!");
        }

        List<SafeField<List>> fieldCandidates = goalTemplate.getSafeFields(withType(List.class));
        if (fieldCandidates.size() > 1) {
            GOALS = fieldCandidates.get(0).getAccessor();
            ACTIVE_GOALS = fieldCandidates.get(0).getAccessor();
        } else {
            throw new RuntimeException("Failed to initialize the goal-lists!");
        }

        // The GoalSelector
        ClassTemplate entityTemplate = new Reflection().reflect(MinecraftReflection.getMinecraftClass("EntityInsentient"));
        List<SafeField<Object>> candidates = entityTemplate.getSafeFields(withType(goalTemplate.getReflectedClass()));

        if (candidates.size() > 0) {
            GOAL_SELECTOR = candidates.get(0).getAccessor(); // the normal selector is the first one
        } else {
            throw new RuntimeException("Failed to initialize the GoalSelector field for the entities");
        }

    } catch (Exception ಠ_ಠ) {
        throw new RuntimeException("Failed to initialize the goal-related fields!", ಠ_ಠ);
    }
}
 
Example #9
Source File: NMSEntityUtil.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
protected static void initializeFields() {
    try {

        ClassTemplate goalTemplate = new Reflection().reflect(MinecraftReflection.getMinecraftClass("PathfinderGoalSelector"));

        List<SafeMethod<Void>> methodCandidates = goalTemplate.getSafeMethods(withArguments(int.class, MinecraftReflection.getMinecraftClass("PathfinderGoal")));
        if (methodCandidates.size() > 0) {
            ADD_GOAL = methodCandidates.get(0).getAccessor();
        } else {
            throw new RuntimeException("Failed to get the addGoal method!");
        }

        List<SafeField<List>> fieldCandidates = goalTemplate.getSafeFields(withType(List.class));
        if (fieldCandidates.size() > 1) {
            GOALS = fieldCandidates.get(0).getAccessor();
            ACTIVE_GOALS = fieldCandidates.get(0).getAccessor();
        } else {
            throw new RuntimeException("Failed to initialize the goal-lists!");
        }

        // The GoalSelector
        ClassTemplate entityTemplate = new Reflection().reflect(MinecraftReflection.getMinecraftClass("EntityInsentient"));
        List<SafeField<Object>> candidates = entityTemplate.getSafeFields(withType(goalTemplate.getReflectedClass()));

        if (candidates.size() > 0) {
            GOAL_SELECTOR = candidates.get(0).getAccessor(); // the normal selector is the first one
        } else {
            throw new RuntimeException("Failed to initialize the GoalSelector field for the entities");
        }

    } catch (Exception ಠ_ಠ) {
        throw new RuntimeException("Failed to initialize the goal-related fields!", ಠ_ಠ);
    }
}