Endermage help!

Discussion in 'Plugin Development' started by Swagger_Saurus, Sep 17, 2014.

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

    Swagger_Saurus

    Alright so im trying to code endermage, if you do not know what endermage is or what it does then hopefully the code will speak for its self.
    @EventHandler
    public void onMage(final BlockPlaceEvent e) {
    final Player p = e.getPlayer();
    if(p.getItemInHand().getType() == Material.PORTAL) {
    if(p.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.GOLD + "Mage Portal!")) {
    if(plugin.Endermage.contains(p.getName())) {
    if(plugin.Cooldown.contains(p.getName())){
    p.sendMessage(ChatColor.RED + "Sorry but it seems you are stil on cooldown!");
    e.setCancelled(true);
    } else {
    e.setCancelled(false);


    final ItemStack portal = new ItemStack(Material.PORTAL);
    ItemMeta portaln = portal.getItemMeta();
    portaln.setDisplayName(ChatColor.GOLD + "Mage Portal");
    portal.setItemMeta(portaln);

    p.getInventory().remove(portal);

    final World w = e.getBlock().getWorld();
    final double x = e.getBlock().getLocation().getX();
    final double y = e.getBlock().getLocation().getY();
    final double z = e.getBlock().getLocation().getZ();

    e.getBlock().setType(Material.ENDER_PORTAL_FRAME);
    Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
    public void run() {
    if(p.getNearbyEntities(2, 256, 2).isEmpty()) {
    p.sendMessage(ChatColor.RED + "Hmm.. There's no one there?");
    p.getInventory().addItem(portal);
    e.getBlock().setType(Material.AIR);
    } else {
    for(Entity nb : p.getNearbyEntities(2, 256, 2)) {
    if(nb instanceof Player) {
    final Player n = (Player) nb;
    if(plugin.Endermage.contains(n.getName())) {
    p.sendMessage(ChatColor.RED + "Hmm.. There's no one there?");
    p.getInventory().addItem(portal);
    e.getBlock().setType(Material.AIR);
    }
    }
    }
    }
    }
    }, 20 * 5);
    for(Entity nb : p.getNearbyEntities(2, 256, 2)) {
    if(nb instanceof Player) {
    final Player n = (Player) nb;
    if(!plugin.Endermage.contains(n.getName())) {

    e.getBlock().setType(Material.AIR);
    nb.teleport(new Location(w, x, y, z));
    p.teleport(new Location(w, x, y, z));
    n.sendMessage(ChatColor.RED + "You have been teleported, so dont act dum. You are invincible for 5 seconds!");
    p.sendMessage(ChatColor.RED + "You are invincible for 5 seconds!");
    plugin.maged.add(p.getName());
    plugin.maged.add(n.getName());
    p.getInventory().addItem(portal);
    Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
    public void run() {
    plugin.maged.remove(p.getName());
    plugin.maged.remove(n.getName());
    n.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "You are no longer invincible!");
    p.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "You are no longer invincible!");
    }
    }, 20 * 5);
    }
    }
    }
    }
    }
    }
    }
    }
    That is the code so far, however when i export the plugin and test it out for some reason it just doesn't do anything. Could someone please help. Cheers.
     
  2. Offline

    Swagger_Saurus

    AdamQpzm
    it didnt change anything, the endermage still does not work. Unless i dont know where to put that code in the main class or the events?
     
  3. Swagger_Saurus It's not supposed to change anything. By debug you code I mean put in System.out.println(whatever) statements so that you can see what parts are executed and the various values for the variables you have.
     
  4. Offline

    fireblast709

    Please indent the code and post it on a paste service (pastebin, for example). Plaintext, unindented code is a pain to read :p
     
  5. Offline

    Swagger_Saurus

  6. Offline

    teej107

  7. Offline

    ChipDev

    For those who must, teej107
    Code:java
    1. @EventHandler
    2. public void onMage(final BlockPlaceEvent e) {
    3. final Player p = e.getPlayer();
    4. if(p.getItemInHand().getType() == Material.PORTAL) {
    5. if(p.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.GOLD + "Mage Portal!")) {
    6. if(plugin.Endermage.contains(p.getName())) {
    7. if(plugin.Cooldown.contains(p.getName())){
    8. p.sendMessage(ChatColor.RED + "Sorry but it seems you are stil on cooldown!");
    9. e.setCancelled(true);
    10. } else {
    11. e.setCancelled(false);
    12.  
    13.  
    14. final ItemStack portal = new ItemStack(Material.PORTAL);
    15. ItemMeta portaln = portal.getItemMeta();
    16. portaln.setDisplayName(ChatColor.GOLD + "Mage Portal");
    17. portal.setItemMeta(portaln);
    18.  
    19. p.getInventory().remove(portal);
    20.  
    21. final World w = e.getBlock().getWorld();
    22. final double x = e.getBlock().getLocation().getX();
    23. final double y = e.getBlock().getLocation().getY();
    24. final double z = e.getBlock().getLocation().getZ();
    25.  
    26. e.getBlock().setType(Material.ENDER_PORTAL_FRAME);
    27. Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
    28. public void run() {
    29. if(p.getNearbyEntities(2, 256, 2).isEmpty()) {
    30. p.sendMessage(ChatColor.RED + "Hmm.. There's no one there?");
    31. p.getInventory().addItem(portal);
    32. e.getBlock().setType(Material.AIR);
    33. } else {
    34. for(Entity nb : p.getNearbyEntities(2, 256, 2)) {
    35. if(nb instanceof Player) {
    36. final Player n = (Player) nb;
    37. if(plugin.Endermage.contains(n.getName())) {
    38. p.sendMessage(ChatColor.RED + "Hmm.. There's no one there?");
    39. p.getInventory().addItem(portal);
    40. e.getBlock().setType(Material.AIR);
    41. }
    42. }
    43. }
    44. }
    45. }
    46. }, 20 * 5);
    47. for(Entity nb : p.getNearbyEntities(2, 256, 2)) {
    48. if(nb instanceof Player) {
    49. final Player n = (Player) nb;
    50. if(!plugin.Endermage.contains(n.getName())) {
    51.  
    52. e.getBlock().setType(Material.AIR);
    53. nb.teleport(new Location(w, x, y, z));
    54. p.teleport(new Location(w, x, y, z));
    55. n.sendMessage(ChatColor.RED + "You have been teleported, so dont act dum. You are invincible for 5 seconds!");
    56. p.sendMessage(ChatColor.RED + "You are invincible for 5 seconds!");
    57. plugin.maged.add(p.getName());
    58. plugin.maged.add(n.getName());
    59. p.getInventory().addItem(portal);
    60. Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
    61. public void run() {
    62. plugin.maged.remove(p.getName());
    63. plugin.maged.remove(n.getName());
    64. n.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "You are no longer invincible!");
    65. p.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "You are no longer invincible!");
    66. }
    67. }, 20 * 5);
    68. }
    69. }
    70. }
    71. }
    72. }
    73. }
    74. }
    75. }
     
  8. Offline

    Swagger_Saurus

    Can someone just actually help
     
  9.  
  10. Offline

    fireblast709

    Code with no indentation and no syntax highlighting is a bit hard (and annoying) to read.
    Highlighted and indented (open)
    Code:java
    1. @EventHandler
    2. public void onMage(final BlockPlaceEvent e)
    3. {
    4. final Player p = e.getPlayer();
    5. if(p.getItemInHand().getType() == Material.PORTAL)
    6. {
    7. if(p.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.GOLD + "Mage Portal!"))
    8. {
    9. if(plugin.Endermage.contains(p.getName()))
    10. {
    11. if(plugin.Cooldown.contains(p.getName()))
    12. {
    13. p.sendMessage(ChatColor.RED + "Sorry but it seems you are stil on cooldown!");
    14. e.setCancelled(true);
    15. }
    16. else
    17. {
    18. e.setCancelled(false);
    19. final ItemStack portal = new ItemStack(Material.PORTAL);
    20. ItemMeta portaln = portal.getItemMeta();
    21. portaln.setDisplayName(ChatColor.GOLD + "Mage Portal");
    22. portal.setItemMeta(portaln);
    23.  
    24. p.getInventory().remove(portal);
    25.  
    26. final World w = e.getBlock().getWorld();
    27. final double x = e.getBlock().getLocation().getX();
    28. final double y = e.getBlock().getLocation().getY();
    29. final double z = e.getBlock().getLocation().getZ();
    30.  
    31. e.getBlock().setType(Material.ENDER_PORTAL_FRAME);
    32. Bukkit.getScheduler().runTaskLater(plugin, new Runnable()
    33. {
    34. public void run()
    35. {
    36. if(p.getNearbyEntities(2, 256, 2).isEmpty())
    37. {
    38. p.sendMessage(ChatColor.RED + "Hmm.. There's no one there?");
    39. p.getInventory().addItem(portal);
    40. e.getBlock().setType(Material.AIR);
    41. }
    42. else
    43. {
    44. for(Entity nb : p.getNearbyEntities(2, 256, 2))
    45. {
    46. if(nb instanceof Player)
    47. {
    48. final Player n = (Player) nb;
    49. if(plugin.Endermage.contains(n.getName()))
    50. {
    51. p.sendMessage(ChatColor.RED + "Hmm.. There's no one there?");
    52. p.getInventory().addItem(portal);
    53. e.getBlock().setType(Material.AIR);
    54. }
    55. }
    56. }
    57. }
    58. }
    59. }, 20 * 5);
    60. for(Entity nb : p.getNearbyEntities(2, 256, 2))
    61. {
    62. if(nb instanceof Player)
    63. {
    64. final Player n = (Player) nb;
    65. if(!plugin.Endermage.contains(n.getName()))
    66. {
    67.  
    68. e.getBlock().setType(Material.AIR);
    69. nb.teleport(new Location(w, x, y, z));
    70. p.teleport(new Location(w, x, y, z));
    71. n.sendMessage(ChatColor.RED + "You have been teleported, so dont act dum. You are invincible for 5 seconds!");
    72. p.sendMessage(ChatColor.RED + "You are invincible for 5 seconds!");
    73. plugin.maged.add(p.getName());
    74. plugin.maged.add(n.getName());
    75. p.getInventory().addItem(portal);
    76. Bukkit.getScheduler().runTaskLater(plugin, new Runnable()
    77. {
    78. public void run()
    79. {
    80. plugin.maged.remove(p.getName());
    81. plugin.maged.remove(n.getName());
    82. n.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "You are no longer invincible!");
    83. p.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "You are no longer invincible!");
    84. }
    85. }, 20 * 5);
    86. }
    87. }
    88. }
    89. }
    90. }
    91. }
    92. }
    93. }
    And now it's time for a checklist:
    • Did you register the Listener that contains this code?
    • Print out the name of the item the player holds (does this match ChatColor.GOLD + "Mage Portal!"?)
    • Print out whether the plugin.Endermage collection contains the player's name
     
  11. Offline

    Swagger_Saurus

Thread Status:
Not open for further replies.

Share This Page