Makes any entity moves faster including the fireball

Discussion in 'Resources' started by ferrybig, Apr 28, 2013.

?

do you think this is usefull

  1. yes, I am going to use it

    6 vote(s)
    35.3%
  2. yes, its usefull, but I not going to use it

    9 vote(s)
    52.9%
  3. no, its not usefull

    2 vote(s)
    11.8%
Thread Status:
Not open for further replies.
  1. Offline

    ferrybig

    I have written some code I am wanting to share to your people to allow all the entities to move faster, including the fireball and the item without any use of potions, without the need of major updating between craftbukkit versions
    Code:java
    1. import java.lang.reflect.InvocationTargetException;
    2. import java.lang.reflect.Method;
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.entity.Entity;
    5.  
    6. /**
    7.  * EntityAccelerator v1.0
    8.  *
    9.  * EntityAccelerator provides a way to seed up entities
    10.  *
    11.  * 1. No warranty is given or implied. 2. All damage is your own responsibility. 3. You provide credit publicly to the original source should you release the plugin.
    12.  *
    13.  * Example use:
    14.  *
    15.  * <code>public class EntityAcceleratorPlugin implements Listener {
    16.  *
    17.  * EntityAccelerator acc = new EntityAccelerator();
    18.  *
    19.  * @EventHandler public void onYourEvent(YourEvent event) { acc.accelerateEntity(event.getEntity()); }
    20.  *
    21.  * }</code>
    22.  *
    23.  * @author ferrybig
    24.  */
    25. public class EntityAccelerator
    26. {
    27. // internal references, performance improvements
    28. private Method entityGetHandle = null;
    29. private Method nmsEntityMove = null;
    30.  
    31. /**
    32. *
    33. *
    34. * @param entity
    35. * @throws IllegalAccessException
    36. * @throws IllegalArgumentException
    37. * @throws InvocationTargetException
    38. */
    39. {
    40. Object nms_entity;
    41. /*
    42. * The reflection part, this gives us access to funky ways of messing around with things
    43. */
    44. if (entityGetHandle == null)
    45. {
    46. // get the methods of the craftbukkit objects
    47. entityGetHandle = getMethod(entity.getClass(), "getHandle");
    48. }
    49.  
    50. // invoke with no arguments
    51. nms_entity = entityGetHandle.invoke(entity, (Object[]) null);
    52.  
    53. // null checks are fast, so having this seperate is ok
    54. if (nmsEntityMove == null)
    55. {
    56. // get the method of the nms_world
    57. nmsEntityMove = getMethod(nms_entity.getClass(), getMoveMethodeBasedOnVersion());
    58. }
    59. nmsEntityMove.invoke(nms_entity, (Object[]) null);
    60. }
    61.  
    62. /**
    63. * Internal method, used as shorthand to grab our method in a nice friendly manner
    64. *
    65. * @param cl
    66. * @param method
    67. * @return Method (or null)
    68. */
    69. private static Method getMethod(Class<?> cl, String method)
    70. {
    71. for (Method m : cl.getMethods())
    72. {
    73. if (m.getName().equals(method))
    74. {
    75. return m;
    76. }
    77. }
    78. throw new IllegalStateException("Unknowns methode: " + method + ", class: " + cl.getName());
    79. }
    80.  
    81. private String getMoveMethodeBasedOnVersion()
    82. {
    83. String version = Bukkit.getServer().getBukkitVersion();
    84.  
    85. if (version.startsWith("1.5"))
    86. {
    87. if (version.startsWith("1.5.1"))
    88. {
    89. return "l_";
    90. }
    91. return "l_";
    92. }
    93. else if (version.startsWith("1.4")) // generic 1.4
    94. {
    95. return "j_"; // methode not changed between versions
    96. }
    97. else if (version.startsWith("1.3"))
    98. {
    99. return "h_"; // methode not changed between versions
    100. }
    101. else if (version.startsWith("1.2"))
    102. {
    103. if (version.startsWith("1.2.5"))
    104. {
    105. return "F_";
    106. }
    107. if (version.startsWith("1.2.3"))
    108. {
    109. return "G_";
    110. }
    111. // no generic version of 1.2
    112. }
    113. else if (version.startsWith("1.1"))
    114. {
    115. return "y_";
    116. }
    117. else if (version.startsWith("1.0"))
    118. {
    119. if (version.startsWith("1.0.0"))
    120. {
    121. return "w_";
    122. }
    123. }
    124. throw new IllegalStateException("Unknowns version: " + version);
    125. }
    126. }

    example use:
    Code:java
    1.  
    2. public class FasterMove extends JavaPlugin
    3. {
    4. EntityAccelerator acc = new EntityAccelerator();
    5.  
    6. @Override
    7. public void onEnable()
    8. {
    9. new BukkitRunnable()
    10. {
    11. @Override
    12. public void run()
    13. {
    14. try
    15. {
    16. for (World w : Bukkit.getWorlds())
    17. {
    18. for (Entity e : w.getEntities())
    19. {
    20. if (e instanceof Player)
    21. {
    22. continue; // never tested on players
    23. }
    24. acc.accelerateEntity(e);
    25. }
    26. }
    27. }
    28. catch (Exception e)
    29. {
    30. e.printStackTrace();
    31. this.cancel();
    32. }
    33. }
    34. }.runTaskTimer(this, 1, 1);
    35. }
    36. }

    build a plugin with this code and watch your server entities speeding up (and going crazy incase of doggies)
     
  2. Offline

    DSH105 Retired Staff

    ferrybig
    Nice, but is it possible to control speed?

    EDIT: I mean make the entity move slower and faster using this code :)
     
  3. Offline

    ferrybig

    not slower, it just calls the movement method to increase the speed of the entity
     
  4. Offline

    DSH105 Retired Staff

    So would that make it possible to control the rate at which an entity is accelerated? Or would that require other methods?

    Great resource BTW. Love it :)
     
    Phasesaber likes this.
  5. Offline

    ferrybig

    it would require other methods to make them move slower, it only simulates the move method of them
     
  6. Offline

    BungeeTheCookie

  7. Offline

    SoThatsIt

    BungeeTheCookie
    The move method can change but the util will still work, and will probably work well into the future.
     
  8. Offline

    NonameSL

    ferrybig , this doesn't work and the problem seems to be that getMoveMethodeBasedOnVersion() is only for versions 1.0 to 1.5, and it doesn't work with 1.7. Can you please upgrade this?
     
    Phasesaber likes this.
Thread Status:
Not open for further replies.

Share This Page