Please help! on warp sign coding

Discussion in 'Plugin Development' started by ClydetorkleGaming, Nov 2, 2013.

Thread Status:
Not open for further replies.
  1. Code:java
    1. package me.clydetorklegaming.warpandspawn;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Location;
    7. import org.bukkit.block.Sign;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.Action;
    12. import org.bukkit.event.block.BlockBreakEvent;
    13. import org.bukkit.event.block.SignChangeEvent;
    14. import org.bukkit.event.player.PlayerInteractEvent;
    15.  
    16. public class MainListener implements Listener {
    17.  
    18. public static MainListener plugin;
    19. public final HashMap<Location, String> signs = new HashMap<Location, String>();
    20.  
    21. @EventHandler
    22. public void onSignChange(SignChangeEvent event) {
    23. Player player = event.getPlayer();
    24. if(event.getLine(0).equalsIgnoreCase("[Warps]") && event.getLine(1) != null) {
    25. //saveConfig();
    26. }else {
    27. player.sendMessage("You need to name this warp");
    28.  
    29. }
    30. }
    31.  
    32. @EventHandler
    33. public void onBlockBreak(BlockBreakEvent event) {
    34. Player player = event.getPlayer();
    35. if(signs.containsKey(event.getBlock()) && !signs.containsValue(event.getPlayer().getName()) || !player.isOp()) {
    36.  
    37. }
    38. }
    39.  
    40. @EventHandler
    41. public void onPlayerInteract(PlayerInteractEvent event) {
    42. if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
    43. if (event.getClickedBlock().getState() instanceof Sign) {
    44. Sign s = (Sign) event.getClickedBlock().getState();
    45. if (s.getLine(0).equalsIgnoreCase("[Warp]")) {
    46. event.getPlayer().sendMessage(ChatColor.GREEN + "Sucessfuly warped!");
    47. }
    48. }
    49. }
    50. }
    51. }


    This my current code for WarpandSpawn plugin, I'm wanting to add this to it for the next update. The only problem is it is not working like it should be. I'm wanting where when a player places a sign and on the first line types "warp" and on the second line they type the "warp name" they set earlier with the /setwarp command. I want it to get the string with the coordinates so when they right click the warp sign it will teleport them to the warp without them having to enter the /warp command. When I load it to my server and do what I said before it doesn't warp you like it should. NOTE this is only the MainListener class I have two other classes that handle the commands. If you see anything that would be causing it to not get the string for the coordinates to warp you please comment!
     
  2. Offline

    GusGold

    ClydetorkleGaming
    From the code you have here, you aren't ever actually attempting to teleport the player when they click on the sign. Line 46 is where you tell the player that they have been teleported, but you never actually teleport them.
    Between lines 45 and 46, I suggest you do something like this:
    • check if there is content on the 2nd line of the sign (the place that should have the warp name)
      • if so, check that the warp is set in your nameToLocation map (I assume you have this in another class. It would be the same as how you check if the warpName the players enter when typing "/warp warpName" is set)
        • If so, get the location that corresponds to warpName
        • player.teleport(warpNameLocation);
      • else tell the player that the warp is not defined yet
    • else tell the player that there isn't a warpName set on the sign (You may think this is redudant, because of your onSignChange(event), but what happens if someone had made a sign with 'warp' on the first line, while your plugin isn't enabled? It would never tell the player that the sign is invalid)
     
  3. GusGold did I fix this right, and exactly how would I check for the warp name on the second line. Also where you said "I assume you have another class that has the warp name" I have it in a data.yml file. So i didn't know if I would have to do it different. Sorry if anything I ask is dumb I'm new java, specifically bukkit coding. Thanks for your help, if possible give me an example of how I would fix it in code
    Code:java
    1. package me.clydetorklegaming.warpandspawn;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Location;
    7. import org.bukkit.block.Sign;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.Action;
    12. import org.bukkit.event.block.BlockBreakEvent;
    13. import org.bukkit.event.block.SignChangeEvent;
    14. import org.bukkit.event.player.PlayerInteractEvent;
    15.  
    16. public class MainListener implements Listener {
    17.  
    18. public static MainListener plugin;
    19. public final HashMap<Location, String> signs = new HashMap<Location, String>();
    20.  
    21. @EventHandler
    22. public void onSignChange(SignChangeEvent event) {
    23. Player player = event.getPlayer();
    24. if(event.getLine(0).equalsIgnoreCase("[Warps]") && event.getLine(1) != null) {
    25. //saveConfig();
    26. }else {
    27. player.sendMessage("You need to name this warp");
    28.  
    29. }
    30. }
    31.  
    32. @EventHandler
    33. public void onBlockBreak(BlockBreakEvent event) {
    34. Player player = event.getPlayer();
    35. if(signs.containsKey(event.getBlock()) && !signs.containsValue(event.getPlayer().getName()) || !player.isOp()) {
    36.  
    37. }
    38. }
    39.  
    40. @EventHandler
    41. public void onPlayerInteract(PlayerInteractEvent event) {
    42. if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
    43. if (event.getClickedBlock().getState() instanceof Sign) {
    44. Sign s = (Sign) event.getClickedBlock().getState();
    45. if (s.getLine(0).equalsIgnoreCase("[Warp]")) {
    46. event.getPlayer().teleport(warpNameLocation);
    47. event.getPlayer().sendMessage(ChatColor.GREEN + "Sucessfuly warped!");
    48. }
    49. }
    50. }
    51. }
    52. }
    53.  


    GusGold also where it has warpnamelocation it give me an error, saying make method or local variable.

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

    GusGold

    ClydetorkleGaming
    Never worry about asking dumb questions! Without asking the dumb ones, you won't ever be able to ask the smart ones :)
    So, first off, can you show me the code you are using for your commands? i.e. where you check the cmd == 'warp' and you warp the player
     
  5. GusGold Here is my main class that extends java.
    Code:java
    1. package me.clydetorklegaming.warpandspawn;
    2.  
    3. import me.clydetorklegaming.warpandspawn.SettingsManager;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Location;
    8. import org.bukkit.World;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class Main extends JavaPlugin {
    15.  
    16. SettingsManager settings = SettingsManager.getInstance();
    17.  
    18. public void onEnable() {
    19. getConfig().options().copyDefaults(true);
    20. saveConfig();
    21. settings.setup(this);
    22. }
    23.  
    24. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    25.  
    26. if (!(sender instanceof Player)) {
    27. sender.sendMessage(ChatColor.RED + "This plugin is for players only!");
    28. return true;
    29. }
    30.  
    31. Player p = (Player) sender;
    32.  
    33.  
    34. if (cmd.getName().equalsIgnoreCase("setspawn")) {
    35. if(sender.hasPermission("ws.setspawn")){
    36.  
    37. settings.getData().set("spawn.world", p.getLocation().getWorld().getName());
    38. settings.getData().set("spawn.x", p.getLocation().getX());
    39. settings.getData().set("spawn.y", p.getLocation().getY());
    40. settings.getData().set("spawn.z", p.getLocation().getZ());
    41. settings.saveData();
    42. p.sendMessage(ChatColor.GREEN + "Successfully set spawn!");
    43. return true;
    44. }else{
    45. p.sendMessage(ChatColor.RED + "You do not have permission!");
    46.  
    47.  
    48. }
    49.  
    50. if (cmd.getName().equalsIgnoreCase("spawn")) {
    51. if (settings.getData().getConfigurationSection("spawn") == null) {
    52. p.sendMessage(ChatColor.RED + "The spawn has not been set!");
    53. return true;
    54. }
    55. World w = Bukkit.getServer().getWorld(settings.getData().getString("spawn.world"));
    56. double x = settings.getData().getDouble("spawn.x");
    57. double y = settings.getData().getDouble("spawn.y");
    58. double z = settings.getData().getDouble("spawn.z");
    59. p.teleport(new Location(w, x, y, z));
    60. p.sendMessage(ChatColor.GREEN + "Welcome to spawn!");
    61. }
    62. }
    63.  
    64. if (cmd.getName().equalsIgnoreCase("setwarp")) {
    65. if(sender.hasPermission("ws.setwarp")){
    66.  
    67. if (args.length == 0) {
    68. p.sendMessage(ChatColor.RED + "Please specify a name!");
    69. return true;
    70. }
    71. settings.getData().set("warps." + args[0] + ".world", p.getLocation().getWorld().getName());
    72. settings.getData().set("warps." + args[0] + ".x", p.getLocation().getX());
    73. settings.getData().set("warps." + args[0] + ".y", p.getLocation().getY());
    74. settings.getData().set("warps." + args[0] + ".z", p.getLocation().getZ());
    75. settings.saveData();
    76. p.sendMessage(ChatColor.GREEN + "Set warp " + args[0] + "!");
    77. }else{
    78. p.sendMessage(ChatColor.RED + "You do not have permission!");
    79.  
    80. }
    81. }
    82.  
    83. if (cmd.getName().equalsIgnoreCase("warp")) {
    84. if (args.length == 0) {
    85. p.sendMessage(ChatColor.RED + "Please specify a name!");
    86. return true;
    87. }
    88. if (settings.getData().getConfigurationSection("warps." + args[0]) == null) {
    89. p.sendMessage(ChatColor.RED + "Warp " + args[0] + " does not exist!");
    90. return true;
    91. }
    92. World w = Bukkit.getServer().getWorld(settings.getData().getString("warps." + args[0] + ".world"));
    93. double x = settings.getData().getDouble("warps." + args[0] + ".x");
    94. double y = settings.getData().getDouble("warps." + args[0] + ".y");
    95. double z = settings.getData().getDouble("warps." + args[0] + ".z");
    96. p.teleport(new Location(w, x, y, z));
    97. p.sendMessage(ChatColor.GREEN + "Teleported to " + args[0] + "!");
    98. }
    99.  
    100. if (cmd.getName().equalsIgnoreCase("delwarp")) {
    101. if(sender.hasPermission("ws.delwarp")){
    102.  
    103. if (args.length == 0) {
    104. p.sendMessage(ChatColor.RED + "Please specify a name!");
    105. return true;
    106. }
    107. if (settings.getData().getConfigurationSection("warps." + args[0]) == null) {
    108. p.sendMessage(ChatColor.RED + "Warp " + args[0] + " does not exist!");
    109. return true;
    110. }
    111. settings.getData().set("warps." + args[0], null);
    112. settings.saveData();
    113. p.sendMessage(ChatColor.GREEN + "Successfully removed warp " + args[0] + "!");
    114. }else{
    115. p.sendMessage(ChatColor.RED + "You do not have permission!");
    116.  
    117.  
    118. }
    119. }
    120. return true;
    121. }
    122. }
    123.  
    124.  

    Here is my SettingsManager. This class is where it makes the data.yml to save the warps to.
    Code:java
    1. package me.clydetorklegaming.warpandspawn;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.configuration.file.FileConfiguration;
    9. import org.bukkit.configuration.file.YamlConfiguration;
    10. import org.bukkit.plugin.Plugin;
    11. import org.bukkit.plugin.PluginDescriptionFile;
    12.  
    13. public class SettingsManager {
    14.  
    15. private SettingsManager() { }
    16.  
    17. static SettingsManager instance = new SettingsManager();
    18.  
    19. public static SettingsManager getInstance() {
    20. return instance;
    21. }
    22.  
    23. Plugin p;
    24.  
    25. FileConfiguration config;
    26. File cfile;
    27.  
    28. FileConfiguration data;
    29. File dfile;
    30.  
    31. public void setup(Plugin p) {
    32. cfile = new File(p.getDataFolder(), "config.yml");
    33. config = p.getConfig();
    34. //config.options().copyDefaults(true);
    35. //saveConfig();
    36.  
    37. if (!p.getDataFolder().exists()) {
    38. p.getDataFolder().mkdir();
    39. }
    40.  
    41. dfile = new File(p.getDataFolder(), "data.yml");
    42.  
    43. if (!dfile.exists()) {
    44. try {
    45. dfile.createNewFile();
    46. }
    47. catch (IOException e) {
    48. Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not create data.yml!");
    49. }
    50. }
    51.  
    52. data = YamlConfiguration.loadConfiguration(dfile);
    53. }
    54.  
    55. public FileConfiguration getData() {
    56. return data;
    57. }
    58.  
    59. public void saveData() {
    60. try {
    61. data.save(dfile);
    62. }
    63. catch (IOException e) {
    64. Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save data.yml!");
    65. }
    66. }
    67.  
    68. public void reloadData() {
    69. data = YamlConfiguration.loadConfiguration(dfile);
    70. }
    71.  
    72. public FileConfiguration getConfig() {
    73. return config;
    74. }
    75.  
    76. public void saveConfig() {
    77. try {
    78. config.save(cfile);
    79. }
    80. catch (IOException e) {
    81. Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save config.yml!");
    82. }
    83. }
    84.  
    85. public void reloadConfig() {
    86. config = YamlConfiguration.loadConfiguration(cfile);
    87. }
    88.  
    89. public PluginDescriptionFile getDesc() {
    90. return p.getDescription();
    91. }
    92. }


    GusGold by the way i subscribed to your youtube channel. Nice channel!

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

    GusGold

    ClydetorkleGaming
    This is the code you will want to reuse (Lines 88 to 97 of your main class that extends java) with some slight alterations that I will show you to make it work:)
    Code:java
    1. if (settings.getData().getConfigurationSection("warps." + args[0]) == null) {
    2. p.sendMessage(ChatColor.RED + "Warp " + args[0] + " does not exist!");
    3. return true;
    4. }
    5. World w = Bukkit.getServer().getWorld(settings.getData().getString("warps." + args[0] + ".world"));
    6. double x = settings.getData().getDouble("warps." + args[0] + ".x");
    7. double y = settings.getData().getDouble("warps." + args[0] + ".y");
    8. double z = settings.getData().getDouble("warps." + args[0] + ".z");
    9. p.teleport(new Location(w, x, y, z));

    So, rather than using args[0] as the variable storing the warp's name, we want to get the 2nd line of text on the sign. So we change every 'args[0]' we find to 's.getLine(1)' like:
    Code:java
    1. /*Line 1*/if (settings.getData().getConfigurationSection("warps." + s.getLine(1) == null) {

    Next thing to fix are all of the 'p' variables. In your onPlayerInteract() method, you don't set the Player to anything, so we need to add and intialise a Player object variable before this code block:
    Code:java
    1. Player p = event.getPlayer();

    Final thing we need to do before using this code is to do with the return line. Because your onPlayerInteract() method is set to 'void', you can't return anything, including a boolean like 'return true;' would, so we just chop off the 'true':
    Code:java
    1. /*Line 3*/ return;

    Now your code will look like this:
    Code:java
    1. Player p = event.getPlayer();
    2. if (settings.getData().getConfigurationSection("warps." + s.getLine(1)) == null) {
    3. p.sendMessage(ChatColor.RED + "Warp " + s.getLine(1) + " does not exist!");
    4. return;
    5. }
    6. World w = Bukkit.getServer().getWorld(settings.getData().getString("warps." + s.getLine(1) + ".world"));
    7. double x = settings.getData().getDouble("warps." + s.getLine(1) + ".x");
    8. double y = settings.getData().getDouble("warps." + s.getLine(1) + ".y");
    9. double z = settings.getData().getDouble("warps." + s.getLine(1) + ".z");
    10. p.teleport(new Location(w, x, y, z));

    To insert this in to your MainListener class, put it between lines 45 and 46 and you are done.
    Please note though that I did all this code within the reply box, so none of the spelling has been error checked :)

    Thanks :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  7. GusGold Thanks so much! This is what I have, did I insert this correctly, and one more question where it says settings it underline it in red and ask if I want create a field, local variable, class, parameter, constant, or method what do I select.
    New classes:
    Code:java
    1. package me.clydetorklegaming.warpandspawn;
    2.  
    3. import me.clydetorklegaming.warpandspawn.SettingsManager;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Location;
    8. import org.bukkit.World;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class Main extends JavaPlugin {
    15.  
    16. SettingsManager settings = SettingsManager.getInstance();
    17.  
    18. public void onEnable() {
    19. getConfig().options().copyDefaults(true);
    20. saveConfig();
    21. settings.setup(this);
    22. }
    23.  
    24. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    25.  
    26. if (!(sender instanceof Player)) {
    27. sender.sendMessage(ChatColor.RED + "This plugin is for players only!");
    28. return true;
    29. }
    30.  
    31. Player p = (Player) sender;
    32.  
    33.  
    34. if (cmd.getName().equalsIgnoreCase("setspawn")) {
    35. if(sender.hasPermission("ws.setspawn")){
    36.  
    37. settings.getData().set("spawn.world", p.getLocation().getWorld().getName());
    38. settings.getData().set("spawn.x", p.getLocation().getX());
    39. settings.getData().set("spawn.y", p.getLocation().getY());
    40. settings.getData().set("spawn.z", p.getLocation().getZ());
    41. settings.saveData();
    42. p.sendMessage(ChatColor.GREEN + "Successfully set spawn!");
    43. return true;
    44. }else{
    45. p.sendMessage(ChatColor.RED + "You do not have permission!");
    46.  
    47.  
    48. }
    49.  
    50. if (cmd.getName().equalsIgnoreCase("spawn")) {
    51. if (settings.getData().getConfigurationSection("spawn") == null) {
    52. p.sendMessage(ChatColor.RED + "The spawn has not been set!");
    53. return true;
    54. }
    55. World w = Bukkit.getServer().getWorld(settings.getData().getString("spawn.world"));
    56. double x = settings.getData().getDouble("spawn.x");
    57. double y = settings.getData().getDouble("spawn.y");
    58. double z = settings.getData().getDouble("spawn.z");
    59. p.teleport(new Location(w, x, y, z));
    60. p.sendMessage(ChatColor.GREEN + "Welcome to spawn!");
    61. }
    62. }
    63.  
    64. if (cmd.getName().equalsIgnoreCase("setwarp")) {
    65. if(sender.hasPermission("ws.setwarp")){
    66.  
    67. if (args.length == 0) {
    68. p.sendMessage(ChatColor.RED + "Please specify a name!");
    69. return true;
    70. }
    71. settings.getData().set("warps." + args[0] + ".world", p.getLocation().getWorld().getName());
    72. settings.getData().set("warps." + args[0] + ".x", p.getLocation().getX());
    73. settings.getData().set("warps." + args[0] + ".y", p.getLocation().getY());
    74. settings.getData().set("warps." + args[0] + ".z", p.getLocation().getZ());
    75. settings.saveData();
    76. p.sendMessage(ChatColor.GREEN + "Set warp " + args[0] + "!");
    77. }else{
    78. p.sendMessage(ChatColor.RED + "You do not have permission!");
    79.  
    80. }
    81. }
    82.  
    83. if (cmd.getName().equalsIgnoreCase("warp")) {
    84. if (args.length == 0) {
    85. p.sendMessage(ChatColor.RED + "Please specify a name!");
    86. return true;
    87. }
    88. if (settings.getData().getConfigurationSection("warps." + args[0]) == null) {
    89. p.sendMessage(ChatColor.RED + "Warp " + args[0] + " does not exist!");
    90. return true;
    91. }
    92. World w = Bukkit.getServer().getWorld(settings.getData().getString("warps." + args[0] + ".world"));
    93. double x = settings.getData().getDouble("warps." + args[0] + ".x");
    94. double y = settings.getData().getDouble("warps." + args[0] + ".y");
    95. double z = settings.getData().getDouble("warps." + args[0] + ".z");
    96. p.teleport(new Location(w, x, y, z)); }
    97.  
    98. if (cmd.getName().equalsIgnoreCase("delwarp")) {
    99. if(sender.hasPermission("ws.delwarp")){
    100.  
    101. if (args.length == 0) {
    102. p.sendMessage(ChatColor.RED + "Please specify a name!");
    103. return true;
    104. }
    105. if (settings.getData().getConfigurationSection("warps." + args[0]) == null) {
    106. p.sendMessage(ChatColor.RED + "Warp " + args[0] + " does not exist!");
    107. return true;
    108. }
    109. settings.getData().set("warps." + args[0], null);
    110. settings.saveData();
    111. p.sendMessage(ChatColor.GREEN + "Successfully removed warp " + args[0] + "!");
    112. }else{
    113. p.sendMessage(ChatColor.RED + "You do not have permission!");
    114.  
    115.  
    116. }
    117. }
    118. return true;
    119. }
    120. }
    121.  
    122.  

    Code:java
    1. package me.clydetorklegaming.warpandspawn;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Location;
    8. import org.bukkit.World;
    9. import org.bukkit.block.Sign;
    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.BlockBreakEvent;
    15. import org.bukkit.event.block.SignChangeEvent;
    16. import org.bukkit.event.player.PlayerInteractEvent;
    17.  
    18. public class MainListener implements Listener {
    19.  
    20. public static MainListener plugin;
    21. public final HashMap<Location, String> signs = new HashMap<Location, String>();
    22.  
    23. @EventHandler
    24. public void onSignChange(SignChangeEvent event) {
    25. Player player = event.getPlayer();
    26. if (settings.getData().getConfigurationSection("warps." + s.getLine(1) == null) {
    27. //saveConfig();
    28. }else {
    29. player.sendMessage("You need to name this warp");
    30.  
    31. }
    32. }
    33.  
    34. @EventHandler
    35. public void onBlockBreak(BlockBreakEvent event) {
    36. Player player = event.getPlayer();
    37. if(signs.containsKey(event.getBlock()) && !signs.containsValue(event.getPlayer().getName()) || !player.isOp()) {
    38.  
    39. }
    40. }
    41.  
    42. @EventHandler
    43. public void onPlayerInteract(PlayerInteractEvent event) {
    44. if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
    45. if (event.getClickedBlock().getState() instanceof Sign) {
    46. Sign s = (Sign) event.getClickedBlock().getState();
    47. Player p = event.getPlayer();
    48. if (settings.getData().getConfigurationSection("warps." + s.getLine(1)) == null) {
    49. p.sendMessage(ChatColor.RED + "Warp " + s.getLine(1) + " does not exist!");
    50. return;
    51. }
    52. World w = Bukkit.getServer().getWorld(settings.getData().getString("warps." + s.getLine(1) + ".world"));
    53. double x = settings.getData().getDouble("warps." + s.getLine(1) + ".x");
    54. double y = settings.getData().getDouble("warps." + s.getLine(1) + ".y");
    55. double z = settings.getData().getDouble("warps." + s.getLine(1) + ".z");
    56. p.teleport(new Location(w, x, y, z));
    57. event.getPlayer().sendMessage(ChatColor.GREEN + "Sucessfuly warped!");
    58. return;
    59. }
    60. }
    61. }
    62. }
    63.  
    64.  
     
  8. Offline

    fls1234

    PogoSticks Warping tutorial?
     
  9. Offline

    GusGold

    ClydetorkleGaming
    I've never used SettingsManager, but what the error means is that you haven't imported what ever file contains the SettingsManager Class.
    If you were following a tutorial and they used SettingsManager, you may want to try to find and download that class, and then import it into your project.
     
  10. fls1234 Part of it, I mad a lot of changes but I used it to start off my plugin.
     
  11. Offline

    GusGold

    If that is the case, then you will need to get the SettingsManager class from that plugin, and import it into your project
     
  12. GusGold do I need to delete settingsmanager.

    GusGold It already is in my project as SettingsManager.

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

    GusGold

    ClydetorkleGaming
    Then you need to import it into your every class that uses settings.anything()
     
  14. Im really sorry I'm not trying to be annoying but I'm confused this is my SettingsManager class:
    Code:java
    1. package me.clydetorklegaming.warpandspawn;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Location;
    8. import org.bukkit.World;
    9. import org.bukkit.block.BlockState;
    10. import org.bukkit.block.Sign;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.block.Action;
    15. import org.bukkit.event.block.BlockBreakEvent;
    16. import org.bukkit.event.block.SignChangeEvent;
    17. import org.bukkit.event.player.PlayerInteractEvent;
    18.  
    19. public class MainListener implements Listener {
    20.  
    21. public static MainListener plugin;
    22. public final HashMap<Location, String> signs = new HashMap<Location, String>();
    23.  
    24. @EventHandler
    25. public void onSignChange(SignChangeEvent event) {
    26. Player player = event.getPlayer();
    27. if (settings.getData().getConfigurationSection("warps." + s.getLine(1) == null) {
    28. //saveConfig();
    29. }else {
    30. player.sendMessage("You need to name this warp");
    31.  
    32. }
    33. }
    34.  
    35. @EventHandler
    36. public void onBlockBreak(BlockBreakEvent event) {
    37. Player player = event.getPlayer();
    38. if(signs.containsKey(event.getBlock()) && !signs.containsValue(event.getPlayer().getName()) || !player.isOp()) {
    39.  
    40. }
    41. }
    42.  
    43. @EventHandler
    44. public void onPlayerInteract(PlayerInteractEvent event) {
    45. if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
    46. if (event.getClickedBlock().getState() instanceof Sign) {
    47. Sign s = (Sign) event.getClickedBlock().getState();
    48. Player p = event.getPlayer();
    49. if (settings.getData().getConfigurationSection("warps." + s.getLine(1)) == null) {
    50. p.sendMessage(ChatColor.RED + "Warp " + s.getLine(1) + " does not exist!");
    51. return;
    52. }
    53. World w = Bukkit.getServer().getWorld(settings.getData().getString("warps." + s.getLine(1) + ".world"));
    54. double x = settings.getData().getDouble("warps." + s.getLine(1) + ".x");
    55. double y = settings.getData().getDouble("warps." + s.getLine(1) + ".y");
    56. double z = settings.getData().getDouble("warps." + s.getLine(1) + ".z");
    57. p.teleport(new Location(w, x, y, z));
    58. event.getPlayer().sendMessage(ChatColor.GREEN + "Sucessfuly warped!");
    59. return;
    60. }
    61. }
    62. }
    63. }
    64.  
    65.  

    I'm having my error in the MainListener class on line 27,49,and 53-56. The error is the settings thing and where it says "s" on line 27.
    Code:java
    1. package me.clydetorklegaming.warpandspawn;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Location;
    8. import org.bukkit.World;
    9. import org.bukkit.block.BlockState;
    10. import org.bukkit.block.Sign;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.block.Action;
    15. import org.bukkit.event.block.BlockBreakEvent;
    16. import org.bukkit.event.block.SignChangeEvent;
    17. import org.bukkit.event.player.PlayerInteractEvent;
    18.  
    19. public class MainListener implements Listener {
    20.  
    21. public static MainListener plugin;
    22. public final HashMap<Location, String> signs = new HashMap<Location, String>();
    23.  
    24. @EventHandler
    25. public void onSignChange(SignChangeEvent event) {
    26. Player player = event.getPlayer();
    27. if (settings.getData().getConfigurationSection("warps." + s.getLine(1) == null) {
    28. //saveConfig();
    29. }else {
    30. player.sendMessage("You need to name this warp");
    31.  
    32. }
    33. }
    34.  
    35. @EventHandler
    36. public void onBlockBreak(BlockBreakEvent event) {
    37. Player player = event.getPlayer();
    38. if(signs.containsKey(event.getBlock()) && !signs.containsValue(event.getPlayer().getName()) || !player.isOp()) {
    39.  
    40. }
    41. }
    42.  
    43. @EventHandler
    44. public void onPlayerInteract(PlayerInteractEvent event) {
    45. if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
    46. if (event.getClickedBlock().getState() instanceof Sign) {
    47. Sign s = (Sign) event.getClickedBlock().getState();
    48. Player p = event.getPlayer();
    49. if (settings.getData().getConfigurationSection("warps." + s.getLine(1)) == null) {
    50. p.sendMessage(ChatColor.RED + "Warp " + s.getLine(1) + " does not exist!");
    51. return;
    52. }
    53. World w = Bukkit.getServer().getWorld(settings.getData().getString("warps." + s.getLine(1) + ".world"));
    54. double x = settings.getData().getDouble("warps." + s.getLine(1) + ".x");
    55. double y = settings.getData().getDouble("warps." + s.getLine(1) + ".y");
    56. double z = settings.getData().getDouble("warps." + s.getLine(1) + ".z");
    57. p.teleport(new Location(w, x, y, z));
    58. event.getPlayer().sendMessage(ChatColor.GREEN + "Sucessfuly warped!");
    59. return;
    60. }
    61. }
    62. }
    63. }
    64.  
    65.  
     
  15. Offline

    GusGold

    ClydetorkleGaming
    So you see on lines 5 - 17 how you are importing classes, you need to do the same for SettingsManager. The command will look something like 'import com.someaddress.someplugin.SettingsManager'. Just be sure to import it correctly because it is case sensitive.
     
  16. GusGold So basically Im deleting where it says "settings" and changing it to "SettingsManager", I just tried that and when I hover over the error it says "change .getdata to static". Is that right?
     
  17. Offline

    GusGold

    ClydetorkleGaming
    No, don't change it, the problem is, your plugin doesn't know where to find the class 'SettingsManager', so you need to tell it by typing something like 'import com.someaddress.someplugin.SettingsManager' in.
    Maybe try to get a screenshot of your project explorer?
     
  18. GusGold I fixed the "settings" to "SettingManager" and changed ".getData()." to static in the SettingsManager. It is on line 55. But there is one last thing in "MainListener" where it says "s.getLine(1) it give the "s" an error.
    Code:java
    1. package me.clydetorklegaming.warpandspawn;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.configuration.file.FileConfiguration;
    9. import org.bukkit.configuration.file.YamlConfiguration;
    10. import org.bukkit.plugin.Plugin;
    11. import org.bukkit.plugin.PluginDescriptionFile;
    12.  
    13. public class SettingsManager {
    14.  
    15. private SettingsManager() { }
    16.  
    17. static SettingsManager instance = new SettingsManager();
    18.  
    19. public static SettingsManager getInstance() {
    20. return instance;
    21. }
    22.  
    23. Plugin p;
    24.  
    25. FileConfiguration config;
    26. File cfile;
    27.  
    28. static FileConfiguration data;
    29. File dfile;
    30.  
    31. public void setup(Plugin p) {
    32. cfile = new File(p.getDataFolder(), "config.yml");
    33. config = p.getConfig();
    34. //config.options().copyDefaults(true);
    35. //saveConfig();
    36.  
    37. if (!p.getDataFolder().exists()) {
    38. p.getDataFolder().mkdir();
    39. }
    40.  
    41. dfile = new File(p.getDataFolder(), "data.yml");
    42.  
    43. if (!dfile.exists()) {
    44. try {
    45. dfile.createNewFile();
    46. }
    47. catch (IOException e) {
    48. Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not create data.yml!");
    49. }
    50. }
    51.  
    52. data = YamlConfiguration.loadConfiguration(dfile);
    53. }
    54.  
    55. public static FileConfiguration getData() {
    56. return data;
    57. }
    58.  
    59. public void saveData() {
    60. try {
    61. data.save(dfile);
    62. }
    63. catch (IOException e) {
    64. Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save data.yml!");
    65. }
    66. }
    67.  
    68. public void reloadData() {
    69. data = YamlConfiguration.loadConfiguration(dfile);
    70. }
    71.  
    72. public FileConfiguration getConfig() {
    73. return config;
    74. }
    75.  
    76. public void saveConfig() {
    77. try {
    78. config.save(cfile);
    79. }
    80. catch (IOException e) {
    81. Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save config.yml!");
    82. }
    83. }
    84.  
    85. public void reloadConfig() {
    86. config = YamlConfiguration.loadConfiguration(cfile);
    87. }
    88.  
    89. public PluginDescriptionFile getDesc() {
    90. return p.getDescription();
    91. }
    92. }


    GusGold Im not able to upload a picture it's no letting me. So on line 5-17 I would put "import me.clydetorklegaming.warpandspawn.SettingsManager"?

    GusGold I fixed it and imported what you said. But there is one last thing in "MainListener" where it says "s.getLine(1) it give the "s" an error.

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

    GusGold

  20. GusGold Its on line 30 where it says "s.getline(1)" the "s" is returing an error
    Code:java
    1. package me.clydetorklegaming.warpandspawn;
    2.  
    3. import me.clydetorklegaming.warpandspawn.SettingsManager;
    4.  
    5. import java.util.HashMap;
    6.  
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.Location;
    11. import org.bukkit.World;
    12. import org.bukkit.block.BlockState;
    13. import org.bukkit.block.Sign;
    14. import org.bukkit.entity.Player;
    15. import org.bukkit.event.EventHandler;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.event.block.Action;
    18. import org.bukkit.event.block.BlockBreakEvent;
    19. import org.bukkit.event.block.SignChangeEvent;
    20. import org.bukkit.event.player.PlayerInteractEvent;
    21.  
    22. public class MainListener implements Listener {
    23.  
    24. public static MainListener plugin;
    25. public final HashMap<Location, String> signs = new HashMap<Location, String>();
    26.  
    27. @EventHandler
    28. public void onSignChange(SignChangeEvent event) {
    29. Player player = event.getPlayer();
    30. if (SettingsManager.getData().getConfigurationSection("warps." + s.getLine(1) == null)) {
    31. //saveConfig();
    32. }else {
    33. player.sendMessage("You need to name this warp");
    34.  
    35. }
    36. }
    37.  
    38. @EventHandler
    39. public void onBlockBreak(BlockBreakEvent event) {
    40. Player player = event.getPlayer();
    41. if(signs.containsKey(event.getBlock()) && !signs.containsValue(event.getPlayer().getName()) || !player.isOp()) {
    42.  
    43. }
    44. }
    45.  
    46. @EventHandler
    47. public void onPlayerInteract(PlayerInteractEvent event) {
    48. if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
    49. if (event.getClickedBlock().getState() instanceof Sign) {
    50. Sign s = (Sign) event.getClickedBlock().getState();
    51. Player p = event.getPlayer();
    52. if (SettingsManager.getData().getConfigurationSection("warps." + s.getLine(1)) == null) {
    53. p.sendMessage(ChatColor.RED + "Warp " + s.getLine(1) + " does not exist!");
    54. return;
    55. }
    56. World w = Bukkit.getServer().getWorld(SettingsManager.getData().getString("warps." + s.getLine(1) + ".world"));
    57. double x = SettingsManager.getData().getDouble("warps." + s.getLine(1) + ".x");
    58. double y = SettingsManager.getData().getDouble("warps." + s.getLine(1) + ".y");
    59. double z = SettingsManager.getData().getDouble("warps." + s.getLine(1) + ".z");
    60. p.teleport(new Location(w, x, y, z));
    61. event.getPlayer().sendMessage(ChatColor.GREEN + "Sucessfuly warped!");
    62. return;
    63. }
    64. }
    65. }
    66. }
     
  21. Offline

    GusGold

    ClydetorkleGaming
    That's because the variable 's' is never declared within the scope of the method. Rather than using the s as our sign object, the event gives us the lines. So replace 's' on line 30 with 'event'. You can see the methods here
     
  22. GusGold Thanks so much for the help! I'll will test it shortly and let you know if it works. You can find my plugin WarpandSpawn on bukkit dev.

    GusGold so now I will be able to put anything on line 0 and put the warp name I set earlier on line 2 and will teleport me correct?

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

    GusGold

  24. GusGold Sorry to bug you,but when I change that to "event" it gives line 30 .getConfigurationsection an error.
     
  25. Offline

    GusGold

    ClydetorkleGaming likes this.
  26. GusGold line 30 where it says ".getConfigurationSection(1)" is where the error is.
    Code:java
    1. package me.clydetorklegaming.warpandspawn;
    2.  
    3. import me.clydetorklegaming.warpandspawn.SettingsManager;
    4.  
    5. import java.util.HashMap;
    6.  
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.Location;
    11. import org.bukkit.World;
    12. import org.bukkit.block.BlockState;
    13. import org.bukkit.block.Sign;
    14. import org.bukkit.entity.Player;
    15. import org.bukkit.event.EventHandler;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.event.block.Action;
    18. import org.bukkit.event.block.BlockBreakEvent;
    19. import org.bukkit.event.block.SignChangeEvent;
    20. import org.bukkit.event.player.PlayerInteractEvent;
    21.  
    22. public class MainListener implements Listener {
    23.  
    24. public static MainListener plugin;
    25. public final HashMap<Location, String> signs = new HashMap<Location, String>();
    26.  
    27. @EventHandler
    28. public void onSignChange(SignChangeEvent event) {
    29. Player player = event.getPlayer();
    30. if (SettingsManager.getData().getConfigurationSection("warps." + event.getLine(1) == null)) {
    31. //saveConfig();
    32. }else {
    33. player.sendMessage(ChatColor.RED + "You need to name this warp");
    34.  
    35. }
    36. }
    37.  
    38. @EventHandler
    39. public void onBlockBreak(BlockBreakEvent event) {
    40. Player player = event.getPlayer();
    41. if(signs.containsKey(event.getBlock()) && !signs.containsValue(event.getPlayer().getName()) || !player.isOp()) {
    42.  
    43. }
    44. }
    45.  
    46. @EventHandler
    47. public void onPlayerInteract(PlayerInteractEvent event) {
    48. if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
    49. if (event.getClickedBlock().getState() instanceof Sign) {
    50. Sign s = (Sign) event.getClickedBlock().getState();
    51. Player p = event.getPlayer();
    52. if (SettingsManager.getData().getConfigurationSection("warps." + s.getLine(1)) == null) {
    53. p.sendMessage(ChatColor.RED + "Warp " + s.getLine(1) + " does not exist!");
    54. return;
    55. }
    56. World w = Bukkit.getServer().getWorld(SettingsManager.getData().getString("warps." + s.getLine(1) + ".world"));
    57. double x = SettingsManager.getData().getDouble("warps." + s.getLine(1) + ".x");
    58. double y = SettingsManager.getData().getDouble("warps." + s.getLine(1) + ".y");
    59. double z = SettingsManager.getData().getDouble("warps." + s.getLine(1) + ".z");
    60. p.teleport(new Location(w, x, y, z));
    61. event.getPlayer().sendMessage(ChatColor.GREEN + "Sucessfuly warped!");
    62. return;
    63. }
    64. }
    65. }
    66. }
     
  27. Offline

    GusGold

    ClydetorkleGaming
    Ahh, pesky bracket was in the wrong spot:
    Code:java
    1. if(SettingsManager.getData().getConfigurationSection("warps."+ event.getLine(1)==null)){
    2. //add here ^ ^ remove here
     
    ClydetorkleGaming likes this.
  28. Thanks so this:
    Code:java
    1. if (SettingsManager.getData().getConfigurationSection("warps." + event.getLine(1)) == null) {
     
  29. Offline

    GusGold

  30. GusGold Thanks so much for the help!
     
Thread Status:
Not open for further replies.

Share This Page