Solved Making a player an IronGolem without utilizing Packets?

Discussion in 'Plugin Development' started by MayoDwarf, May 2, 2014.

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

    MayoDwarf

    blablubbabc If you give the Golem slowness then the looking around randomly is fixed.

    blablubbabc Please take a look at my code. I may have a mistake which may be causing the timeOuts:
    Code:java
    1. package com.core.mayodwarf.golemfall.titans;
    2.  
    3. import com.core.mayodwarf.golemfall.main.Main;
    4. import org.bukkit.*;
    5. import org.bukkit.entity.*;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.block.Action;
    9. import org.bukkit.event.player.PlayerInteractEntityEvent;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11. import org.bukkit.event.player.PlayerMoveEvent;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.meta.FireworkMeta;
    14. import org.bukkit.inventory.meta.ItemMeta;
    15. import org.bukkit.potion.PotionEffect;
    16. import org.bukkit.potion.PotionEffectType;
    17.  
    18. import java.util.HashMap;
    19.  
    20. /**
    21. * Created with IntelliJ IDEA.
    22. * User: MayoDwarf
    23. * Date: 5/1/14
    24. * Time: 5:13 PM
    25. * To change this template use File | Settings | File Templates.
    26. */
    27. public class SummonGolem implements Listener {
    28. private HashMap<String, GolemType> gType = new HashMap<String, GolemType>();
    29. private HashMap<String, IronGolem> golem = new HashMap<String, IronGolem>();
    30. Main main;
    31. public SummonGolem(Main main) {
    32. this.main = main;
    33. }
    34. public void summonGolem(Player p, Location tFall, GolemType gt) {
    35. IronGolem ig = (IronGolem) p.getWorld().spawnEntity(new Location(p.getWorld(), tFall.getX(), 200, tFall.getZ(), tFall.getYaw(), tFall.getPitch()), EntityType.IRON_GOLEM);
    36. ig.setCustomName(ChatColor.DARK_RED+""+p.getDisplayName());
    37. ig.setCustomNameVisible(true);
    38. ig.setPlayerCreated(true);
    39. ig.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, Integer.MAX_VALUE));
    40. gType.put(p.getDisplayName(), gt);
    41. golem.put(p.getDisplayName(), ig);
    42. }
    43. public void enterGolem(final Player p, Entity e) {
    44. if(e instanceof IronGolem) {
    45. final IronGolem ig = (IronGolem) e;
    46. if(golem.get(p.getDisplayName()) == ig) {
    47. p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, Integer.MAX_VALUE));
    48. ItemStack chainGun = new ItemStack(Material.WOOD_HOE);
    49. ItemStack rocketSalvo = new ItemStack(Material.WOOD_AXE);
    50. ItemMeta cIM = chainGun.getItemMeta();
    51. ItemMeta rIM = rocketSalvo.getItemMeta();
    52. cIM.setDisplayName(ChatColor.LIGHT_PURPLE+"XO-16 Chaingun");
    53. rIM.setDisplayName(ChatColor.DARK_PURPLE+"Rocket Salvo");
    54. rocketSalvo.setItemMeta(rIM);
    55. chainGun.setItemMeta(cIM);
    56. p.getInventory().setItem(0, chainGun);
    57. p.getInventory().setItem(1, rocketSalvo);
    58. }
    59. }
    60. }
    61. @EventHandler
    62. public void onInteract(PlayerInteractEntityEvent evt) {
    63. Player p = evt.getPlayer();
    64. Entity e = evt.getRightClicked();
    65. if(e instanceof IronGolem) {
    66. IronGolem ig = (IronGolem) e;
    67. if(ChatColor.stripColor(ig.getCustomName()).equals(p.getDisplayName())) {
    68. enterGolem(p, e);
    69. }
    70. }
    71. }
    72. @EventHandler
    73. public void onMove(PlayerMoveEvent evt) {
    74. Player p = evt.getPlayer();
    75. Location from = evt.getFrom();
    76. Location to = evt.getTo();
    77. if(golem.containsKey(p.getDisplayName())) {
    78. if(from.getX() < to.getX()) {
    79. golem.get(p.getDisplayName()).teleport(from);
    80. } else
    81. if(from.getZ() < to.getZ()) {
    82. golem.get(p.getDisplayName()).teleport(from);
    83. }
    84. }
    85. }
    86. @EventHandler
    87. public void onClick(PlayerInteractEvent evt) {
    88. Player p = evt.getPlayer();
    89. ItemStack i = p.getItemInHand();
    90. if(evt.getAction() == Action.RIGHT_CLICK_BLOCK) {
    91. if(i.getType() == Material.NETHER_STAR) {
    92. summonGolem(p, evt.getClickedBlock().getLocation(), GolemType.ATTACK);
    93. }
    94. }
    95. }
    96. }
    97.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    TGRHavoc

    MayoDwarf
    I believe that the PlayerMoveEvent is the culprit. Try removing it and see if the lag persists..
     
  3. Offline

    MayoDwarf

    TGRHavoc It happens when I summon the Golem too however... I get the server overloaded there also...
     
  4. Offline

    iZanax

    MayoDwarf

    Maybe this is a bit too late, but if u still want to use an easy Disguise Library.

    http://dev.bukkit.org/bukkit-plugins/libs-disguises/ #Supports nametags.
    Code:java
    1. MobDisguise zombie = new MobDisguise(me.libraryaddict.disguise.disguisetypes.DisguiseType.ZOMBIE);
    2. LivingWatcher watcher = (LivingWatcher) zombie.getWatcher();
    3. watcher.setCustomName(player.getName());
    4. watcher.setCustomNameVisible(true);
    5. DisguiseAPI.disguiseToAll(player, zombie);
     
  5. Offline

    MayoDwarf

    iZanax If only you had came 50 hours earlier xD :p Thank you so much! I will try this right now! :D Does this also get recognized in events?
     
  6. Offline

    iZanax

    MayoDwarf

    Yes it even show the damage red-flash effect which Diguisecraft didn't had ^^
    But I have to point out that every Diguise library has some flaws, like sometimes movement looks a bit sketchy.
    Goodluck ^^
     
  7. Offline

    blablubbabc

    MayoDwarf
    I found out where the timeouts were coming from, I think: the issue is somehow related to the very high amplifier of the slowness potion effect you assign to the golem.
     
  8. Offline

    MayoDwarf

  9. Offline

    blablubbabc

    MayoDwarf
    By using a lower amplifier for the potion effect.
    Using some disguise plugin is probably the easiest way to not having to care about all these other things around..

    On a side note: the attack timeout of the iron golem seems to get reset whenever he is teleported. Means: his attacks are in high speed :D
     
  10. Offline

    TGRHavoc

    blablubbabc
    I know this is off topic but:
    You could probably make an IronGolem trampoline with that... :D
     
  11. Offline

    MayoDwarf

    blablubbabc Apparently that wasn't the issue either... It happens when it falls from the sky too...Can you test this for me and see if you get different results please?
     
  12. Offline

    blablubbabc

    MayoDwarf
    Well, during my last test I had the potion effect completly removed. If the randomly-looking-around is a big issue you could of course also remove the entity goals via reflection or nms dependency.

    It's already quite late here.. so I hope you can figure this out yourself or with the help of others.

    I would probably do some tests with the disguise lib: if it works out of the box without all those issues related to the golem being a real entity then I would probably use that instead..
     
  13. Offline

    Cirno

    There was a way to actually do this without packets, but it's a whole convoluted method involving abusing the entity ID. This only worked for a short period of time and in a fairly old edition of MC, and often resulted in client crashes.
     
Thread Status:
Not open for further replies.

Share This Page