Coordinate Teleportation & Inventory Updating

Discussion in 'Plugin Development' started by amazed2025, Oct 29, 2013.

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

    amazed2025

    Hey Guys!
    This plugin works fine so far, but only things wrong is that the inventory glitches. If I right-click the sign, one item would be given, if I did it again, only one item would be given, but when I do it again, it gives me the full kit. I'm guessing I need to update the inventory, but "p.updateInventory" doesn't work.
    Also, I can't find a way how to make it so the player would be teleported to a certain world/coordinate, if you could help... It'd be much appreciated! :D

    Here's the code:

    Code:java
    1. package net.theaura.AuraKits;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Material;
    7. import org.bukkit.block.Block;
    8. import org.bukkit.block.Sign;
    9. import org.bukkit.enchantments.Enchantment;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.block.Action;
    14. import org.bukkit.event.block.SignChangeEvent;
    15. import org.bukkit.event.player.PlayerInteractEvent;
    16. import org.bukkit.inventory.ItemStack;
    17. import org.bukkit.plugin.PluginDescriptionFile;
    18. import org.bukkit.plugin.java.JavaPlugin;
    19.  
    20. public class AuraKits extends JavaPlugin implements Listener {
    21.  
    22. public final Logger logger = Logger.getLogger("Minecraft");
    23. public static AuraKits plugin;
    24.  
    25. public void onEnable() {
    26. getServer().getPluginManager().registerEvents(this, this);
    27. PluginDescriptionFile pdfFile = this.getDescription();
    28. this.getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[" + ChatColor.RED + pdfFile.getName() + ChatColor.GREEN + "]" + ChatColor.GOLD + " Has been enabled!");
    29. }
    30.  
    31. public void onDisable() {
    32. PluginDescriptionFile pdfFile = this.getDescription();
    33. this.getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[" + ChatColor.RED + pdfFile.getName() + ChatColor.GREEN + "]" + ChatColor.DARK_RED + " Has been disabled!");
    34. }
    35. @EventHandler
    36. public void GAME1(SignChangeEvent sign){
    37. Player p = sign.getPlayer();
    38. if(sign.getLine(0).equalsIgnoreCase("[" + ChatColor.RED + "aurakits" + ChatColor.BLACK + "]")){
    39. if(sign.getLine(1).equalsIgnoreCase(ChatColor.BOLD + "tank")){
    40. p.sendMessage(ChatColor.YELLOW + "Tank class has successfully been added");
    41. }
    42.  
    43. }
    44. }
    45. @EventHandler
    46. public void clicksign(PlayerInteractEvent e) {
    47. Player p = e.getPlayer();
    48. if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    49. Block b = e.getClickedBlock();
    50. if (b.getType() == Material.SIGN_POST|| b.getType() == Material.WALL_SIGN) {
    51. Sign sign = (Sign) b.getState();
    52. if (sign.getLine(0).equalsIgnoreCase("[" + ChatColor.RED + "aurakits" + ChatColor.BLACK + "]")) {
    53. if (sign.getLine(1).equalsIgnoreCase(ChatColor.BOLD + "tank")) {
    54. if(p.hasPermission("AuraKits.kit.tank")){
    55. //HEALING
    56. p.setHealth(20.0);
    57. p.setFireTicks(0);
    58. p.setFoodLevel(20);
    59. //ITEMSTACKS
    60. ItemStack ihelmet = new ItemStack(Material.IRON_HELMET, 1);
    61. ItemStack ichestplate = new ItemStack(Material.IRON_CHESTPLATE, 1);
    62. ItemStack ileggings = new ItemStack(Material.IRON_LEGGINGS, 1);
    63. ItemStack iboots = new ItemStack(Material.IRON_BOOTS, 1);
    64. ItemStack isword = new ItemStack(Material.IRON_SWORD, 1);
    65. ItemStack bow = new ItemStack(Material.BOW, 1);
    66. ItemStack arrow = new ItemStack(Material.ARROW, 1);
    67. //ENCHANTS
    68. bow.addEnchantment(Enchantment.ARROW_INFINITE, 1);
    69. //ITEMS
    70. p.getInventory().addItem(ihelmet);
    71. p.getInventory().addItem(ichestplate);
    72. p.getInventory().addItem(ileggings);
    73. p.getInventory().addItem(iboots);
    74. p.getInventory().addItem(isword);
    75. p.getInventory().addItem(bow);
    76. p.getInventory().addItem(arrow);
    77. //MESSAGE
    78. p.sendMessage(ChatColor.GREEN + "You have been given the tank kit!");
    79. }else{
    80. p.sendMessage(ChatColor.DARK_RED + "You don't have permission to use tank kit!");
    81. }
    82. }
    83. }
    84. }
    85. }
    86. }
    87. }


    EDIT: Fixed some bad grammar XD

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

    calebbfmv

    Some things:
    Check if the player inventory contains certain items, if it does don't give him that item.
    I would also set all the items in an Array, to make it easier.
    Code:
    p.teleoprt(new Location(world, x, y, z);
    
     
    amazed2025 likes this.
  3. Offline

    reider45

    calebbfmv

    // Completely off topic
    Omg, your signature is so true right now... i'm going to have to remember all this stuff after all :|
     
    amazed2025 likes this.
  4. Offline

    amazed2025

    for the items, I did it separately because it would be easier to add enchantments. I'll try it out, but if I remember correctly... it didn't work before. Thanks for your help though .

    And how would I do that? since I'm not too good at coding since I forgot a ton of things as I took my break from it. calebbfmv

    and to top it off, I get this error; http://prntscr.com/20mw1c

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

    calebbfmv

    Make a World variable called arenas :p
     
  6. Offline

    amazed2025

    Told me to do this, http://prntscr.com/20nbox
    is that right?
     
  7. Offline

    calebbfmv

    Make sure your world is an actual world.
    Code:
    World arena = Bukkit.getServer().getWorld("worldNameHere");
    
     
Thread Status:
Not open for further replies.

Share This Page