[NMS] DataWatcherRegistry issue

Discussion in 'Spigot Plugin Development' started by Asynchronous, May 18, 2016.


What's my level in English ? :D

Poll closed May 25, 2016.
  1. Low

    0 vote(s)
  2. Understandable

    2 vote(s)
  3. Not so dusty

    3 vote(s)
  1. Hello :),

    Like you know, now in 1.9.2, instead of doing this (when creating a new datawatcher):
    Code (Text):
    DataWatcher watcher = new DataWatcher(null);
    watcher.a(6, (float) 20);
    We need to do this:
    Code (Text):
    DataWatcher watcher = new DataWatcher(null);
    watcher.set(DataWatcherRegistry.c.a(6), 20F);
    What I understood:
    In the last code, the variable "c" means that the second part of the method needs to be a java.lang.Float.
    And each variable from DataWatcherRegistry was created for a special type. For example:
    • DataWatcherRegistry.h → java.lang.Boolean
    • DataWatcherRegistry.d → java.lang.String
    • Etcetera...
    Here is the list of all variables in DataWatcherRegistry class and their associated type:

    I want to use the variable f because i need to add an ItemStack to the dataWatcher.
    BUT, the variable f needs to be composed by the com.google.common.base.Optional class :(.

    So i've tested a lot of ways...
    Code (Text):
    watcher.set(DataWatcherRegistry.f.a(5), Optional.of(myItemStack));
    Code (Text):
    watcher.set(DataWatcherRegistry.f.a(5), Optional.fromNullable(myItemStack));
    But always → Null pointer exception (btw, the client was always kicked :/)

    So, i'm here to ask you if you know how i can specify my itemstack with the class Optional.
    I'm not a god in Java but i'm learning the basics so if how i explain things seems wrong, tell me how i can improve it.

    Thanks for reading and please help me :3 ♥
    I'm French so sorry for my explanations.
    Any constructive idea is appreciated :)

    Note: My main aim is to spawn a firework without spawning it (just the sound of explosion) but that's not the problem here ;)
  2. Hello, how to make this with reflection ? Because I have a problem with that :)
    • Like Like x 1
  3. You could try checking the server's source and seeing where it sets an ItemStack using that method?
    • Like Like x 1
  4. Yes, and I have a problem with get DataWatcherObject
    • Like Like x 1
  5. I assume you want a new instance of it:
    Code (Java):
    Class<?> dataWatcherClass = Class.forName("net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] + ".DataWatcher");
    Constructor<?> dataWatcerConst = dataWatcherClass.getConstructor();
    Object dataWatcher = dataWatcherConst.newInstance(); // Your DataWatcher object
    • Like Like x 1
  6. Yes, thanks :)
  7. I have a instance of DataWatcher, but wants to get DataWatcherObject - DataWatcherRegistry.c.a (6)