Solved DRIVING ME CRAZY | World Teleporter Read From Config.yml

Discussion in 'Plugin Development' started by Xyplo, Mar 9, 2014.

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

    Xyplo

    So i'm creating my second plugin for my server.
    I'm trying to create a random location teleporter that reads the world to teleport the player to from the config.yml.

    I've got this coding (bottom of this page) but it doesn't work at all... Please help as once I get past this I'm fine and I can release the plugin. The problem isn't the overall coding. I just don't know how I would get it to read the world name from the config.yml and to import it into the coding to TP them...

    CODING
    Code:java
    1. package me.xyplorandomteleport;
    2.  
    3. import java.util.Random;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Location;
    7. import org.bukkit.Material;
    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 XyploRandomTP extends JavaPlugin{
    15.  
    16. @Override
    17. public void onEnable(){
    18. getLogger().info("Loaded without errors... Hopefully!");
    19.  
    20. saveDefaultConfig();
    21.  
    22. }
    23.  
    24. @Override
    25. public void onDisable(){
    26. getLogger().info("Has successfull been disabled...");
    27.  
    28. }
    29.  
    30. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    31. //config stuff//
    32.  
    33. //Coming in the next update
    34.  
    35. //end of 'config stuff'//
    36.  
    37. if (cmd.getName().equalsIgnoreCase("xyplors") && sender instanceof Player) {
    38.  
    39. Player player = (Player) sender;
    40.  
    41. Location originalLocation = player.getLocation();
    42.  
    43. Random random = new Random();
    44.  
    45. int x = random.nextInt(49999) +1;
    46. int y = 150;
    47. int z = random.nextInt(49999) +1;
    48.  
    49. boolean isOnLand = false;
    50.  
    51. while (isOnLand == false) {
    52.  
    53. Location teleportLocation = new Location((World) getConfig().get("world"), x, y, z);
    54.  
    55. if (teleportLocation.getBlock().getType() != Material.AIR) {
    56. isOnLand = true;
    57. } else y--;
    58.  
    59. player.teleport(new Location((World) getConfig().get("world"), teleportLocation.getX(), teleportLocation.getY() + 1, teleportLocation.getZ()));
    60. player.teleport(teleportLocation);
    61.  
    62. player.sendMessage(ChatColor.GOLD + "You've been teleported " + (int)teleportLocation.distance(originalLocation) + "blocks away!");
    63.  
    64. }
    65. return true;
    66. }
    67. return false;
    68. }
    69. }
    70.  


    Config.yml
    Code:
    # XyploRandomTeleport created for XyploCraft (xyplo.hopto.org) and coded by nGx_IEpiiKZz_x / LoonyRules.
    # Made with love <3
     
    #This is the world it'll tp the player(s).
    world: world
    
    Thanks - Xyplo.
     
  2. Offline

    Mmarz11

    Xyplo Change:
    (World) getConfig().get("world")

    To:
    this.getServer().getWorld(getConfig().get("world"))
     
  3. Offline

    Xyplo


    I Get This Error...

    'The method getWorld(String) in the type Server is not applicable for the arguments'
     
  4. Offline

    Mmarz11

    My bad, I thought that would do something different than what it actually does. Here you go:

    this.getServer().getWorld(getConfig().getString("world"))
     
  5. Offline

    Xyplo

    So the only thing I needed to add really was 'this.getServer()'

    Ohh And Thanks It Worked <3 :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page