Get selected beacon effects.

Discussion in 'Plugin Development' started by Qwertyness_, Aug 16, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Qwertyness_

    I have been trying to find a way to get the selected effects in a beacon. There is no way to hook to it through the Bukkit API, so I tried getting them reflectively through TileEntityBeacon:
    Code:
    TileEntityBeacon beacon = ((CraftBeacon)block.getState()).getTileEntity();
    //m and n are private integer fields in a net.minecraft.server repository I found.  I also tried primaryEffect and secondaryEffect as it is in MCP.
    Field primary = beacon.getField("m");
    primary.setAccessible(true);
    Field secondary = beacon.getField("n");
    secondary.setAccessible(true);
    int primaryEffect = primary.getInt(beacon);
    int secondaryEffect = secondary.getInt(beacon);
    Both sets of field names errored that the field couldn't be found. Does anyone know the correct field names or a different way to get the effects?

    I used the code from MCP and this repository to find the field names I tried (yes, I realize the repository is 1.7.10)
     
  2. Offline

    mine-care

    @Qwertyness_ Field names strongly depend on the build you use, they are not recomended. You can do a search thru the fields if they are unique, For instance if there is only 1 String field that you want to acces, loop through all fields in that class and check if the field class is String. if it is there you go! you found it! :D
     
  3. Offline

    Qwertyness_

    @mine-care I did try looping through the fields to see what was there with this:
    Code:
    for (Field field : beacon.getClass().getFields()) {
        System.out.println("Name: " + field.getName() + " Type: " + field.getType().getName());
    }
    But only got this in response:
    Code:
    Name: a Type: [[Lnet.minecraft.server.v1_8_R3.MobEffect
    Name: transaction Type: java.util.List
    Name: MAX_STACK Type: int
    Name: tickTimer Type: org.spigotmc.CustomTimingsHandler
    There is the List<MobEffect>, but that may just be a list of the possible, not the active effects.
    I am trying to get and print the list to check, but I can't figure out how to get past the class check before the Object>List cast.
    Code:
    if (field.get(beacon).getClass().isAssignableFrom(List.class)) {
    That check doesn't return true where field is the "a" field in the beacon class.
     
  4. Offline

    mine-care

    try swaping the List.class and field.get(...).getClass(), this way they should work.

    Hmm, use a decompiler to open the jar of your server and check the class to fing the field names.
     
  5. Offline

    Qwertyness_

    @mine-care I tried swapping them, but the condition still returned false.

    Also, I used JavaDecompiler to decompile the TileEntityBeacon class from the spigot jar. That showed fields "l" and "k" as the integer effect fields, but once again, they couldn't be found and aren't listed when I iterate the class's fields through reflection.
     
Thread Status:
Not open for further replies.

Share This Page