Setting a warp.

Discussion in 'Plugin Development' started by HyrulesLegend, Oct 29, 2012.

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

    HyrulesLegend

    I wanna make some donor warps, and well, it's annoying having to add perms to every group, if I set essentials to per-permission-warps.
    Soooooo
    I wanna learn to make a command, to setwarp.
    Basically,
    /pro -- Takes you to warp., /setpro - Sets the pro location (sets location of /pro)
     
  2. Offline

    KingMagnus

    Do you know how to use configuration files like getting and saving it?
    Because if you do you'd would save the location of the place you're standing when you do the command like if(commandLabel.equalsIgnoreCase("setpro"){
    Player player = sender.getPlayer();
    int x = player.getX();
    int y = player.getY();
    int z = player.getZ();
    String warp = x + "," + y + "," + z;
    then you would get your config so
    this.getConfig().set("warp", warp}
    after that to return to said location just do
    if(commandLabel.equalsIgnoreCase("pro"){
    Location newlocation = this.getConfig().get("warp")
    Player player = sender.getPlayer();
    player.teleport(newlocation)}

    this is a kind of quick solution but it should work. To set multiple locations you would need to either make multiple pro/set commands or use mutliple arguments to call different config sections
     
    CeramicTitan likes this.
  3. Offline

    CeramicTitan

    OMG I LOVE YOU! I HAVE BEEN LOOKING FOR SOMETHING LIKE THIS FOR AGES! <3
     
  4. Offline

    HyrulesLegend

    Do you know whats wrong with this?
    Code:
    package me.kyrp.KitPvP;
     
     
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class KitPvPCasual implements CommandExecutor {
        @SuppressWarnings("unused")
        private KitPvP plugin;
        public KitPvPCasual(KitPvP plugin) {
            this.plugin = plugin;
        }
     
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if(commandLabel.equalsIgnoreCase("casual"));     
        Bukkit.broadcastMessage(ChatColor.DARK_AQUA + "[SonicKitPvP] " + sender.getName() + " is at casual, msg him for a 1v1!");
        if(commandLabel.equalsIgnoreCase("setpro")) {
            Player player = (Player) sender;
            int x = player.getX();
            int y = player.getY();
            int z = player.getZ();
            String warp = x + "," + y + "," + z;
            this.getConfig().set("warp", warp);
     
         
            if(commandLabel.equalsIgnoreCase("pro"){
            Location newlocation = this.getConfig().get("warp")
            Player player = sender.getPlayer();
            player.teleport(newlocation)}
        return false;
        }
    }
    CeramicTitan do you know whats wrong? :p
     
  5. Offline

    CeramicTitan

    A number of things could be wrong, 1. Are the commands defined in your plugin.yml? 2. Have you defined the executor onEnable(). 3. where it says return false, return true the return false later. 4. Do you have a config?
     
  6. Offline

    HyrulesLegend

    I haven't done those yet, But I get errors all over the place with this code:
    Code:
    package me.kyrp.KitPvP;
     
     
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class KitPvPCasual implements CommandExecutor {
        @SuppressWarnings("unused")
        private KitPvP plugin;
        public KitPvPCasual(KitPvP plugin) {
            this.plugin = plugin;
        }
     
            public boolean onCommand1(CommandSender sender, Command cmd, String commandLabel, String[] args) {
                if(commandLabel.equalsIgnoreCase("setcasual"));
            Player player = (Player) sender;
            int x = player.getX();
            int y = player.getY();
            int z = player.getZ();
            String warp = x + "," + y + "," + z;
            this.getConfig().set("warp", warp);
     
           
            if(commandLabel.equalsIgnoreCase("casual"){
            Location newlocation = this.getConfig().get("warp")
            Player player = sender.getPlayer();
            player.teleport(newlocation)}
        return false;
        }
    }
        @Override
        public boolean onCommand(CommandSender arg0, Command arg1, String arg2,
                String[] arg3) {
            // TODO Auto-generated method stub
            return true;
        }
    }
    
     
  7. Offline

    CeramicTitan

    where are the problems?
     
  8. Offline

    HyrulesLegend

    Code:
    package me.kyrp.KitPvP;
     
     
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class KitPvPCasual implements CommandExecutor {  - Error here
    @SuppressWarnings("unused")
    private KitPvP plugin;
    public KitPvPCasual(KitPvP plugin) {
    this.plugin = plugin;
    }
     
    public boolean onCommand1(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if(commandLabel.equalsIgnoreCase("setcasual"));
      Player player = (Player) sender;
        int x = player.getX(); - Error Here
        int y = player.getY(); - Error Here
        int z = player.getZ(); - Error here
      String warp = x + "," + y + "," + z;
        this.getConfig().set("warp", warp); - Error Here
     
     
      if(commandLabel.equalsIgnoreCase("casual"));
        Location newlocation = this.getConfig().get("warp") - Error Here
        Player player = sender.getPlayer(); - Error Here
        player.teleport(newlocation)} - Error Here
    return true;
    {
    }
    }
    }
    
    CeramicTitan
    I put "- Error Here" where ever there was an error.
     
  9. Offline

    CeramicTitan

    change these:
    int x = player.getX(); - Error Here
    int y = player.getY(); - Error Here
    int z = player.getZ(); - Error Here

    To these:
    int x = player.getLocation().getBlockX();
    int y = player.getLocation.getBlockY();
    int z = player.getLocation().getBlockZ();

    Also the config problem, add this to the top of the class:

    private *main class name* plugin:
    public *current class name*(*main class name* plugin){
    this.plugin = plugin;
    }
    then change "this" to "plugin"
     
  10. Offline

    HyrulesLegend

    Already have that,
    Code:
    private KitPvP plugin;
        public KitPvPCasual(KitPvP plugin) {
            this.plugin = plugin;
     
  11. Offline

    Woobie

  12. Offline

    CeramicTitan

    alright make my changes and see if it works
     
  13. Offline

    HyrulesLegend

    Only got rid of 2 errors, on the Z and X. the y has an error. and everywhere else still does.

    Here's my code:
    Code:
    package me.kyrp.KitPvP;
     
     
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class KitPvPCasual implements CommandExecutor {
        @SuppressWarnings("unused")
        private KitPvP plugin;
        public KitPvPCasual(KitPvP plugin) {
            this.plugin = plugin;
        }
     
            public boolean onCommand1(CommandSender sender, Command cmd, String commandLabel, String[] args) {
                if(commandLabel.equalsIgnoreCase("setcasual"));
            Player player = (Player) sender;
            int x = player.getLocation().getBlockX();
            int y = player.getLocation.getBlockY();
            int z = player.getLocation().getBlockZ();
            String warp = x + "," + y + "," + z;
            this.getConfig().set("warp", warp);
     
           
            if(commandLabel.equalsIgnoreCase("casual"));
            Location newlocation = this.getConfig().get("warp")
            Player player = sender.getPlayer();
            player.teleport(newlocation)}
        return true;
            {
            }
        }
    }
    Woobie im confused. xD

    MrBluebear3 do you know whats wrong? ;P

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

    Woobie

    Just use this inside your on command
    Code:
                    Location loc = player.getLocation();
                    config.addDefault("your.path", loc.getX());
                    config.addDefault("your.path", loc.getY());
                    config.addDefault("your.path", loc.getZ());
    If your config already contains thoes locations, use
    config.set("your.path etc...);

    and when you wanna teleport to the warp:
    Code:
                double x = config.getInt("main.lobby.location.x");
                double y = config.getInt("main.lobby.location.y");
                double z = config.getInt("main.lobby.location.z");
                Location lobbyspawn = new Location(p.getServer().getWorld(config.getString("your.path.world")), x, y, z);
                player.teleport(lobbyspawn);
    If you still dont get it, I'll give you the full code.
     
  15. Offline

    HyrulesLegend

    I'm still a bit confused, :p Could you give me the full code? xD
     
  16. Offline

    Woobie

    Are you trying to make it in your main class or listener class?
     
  17. Offline

    HyrulesLegend

    Just a normal class, :p
    So I guess, a listener class? xD
     
  18. Offline

    Woobie

    I mean do you have a separate class for this?
    Or are you trying to make this in the class that extends JavaPlugin? Which is the main class.
     
  19. Offline

    HyrulesLegend

    All I know is that it's not my main class. Here's my main class:

    Code:
    package me.kyrp.KitPvP;
     
     
    import me.kyrp.KitPvP.KitPvPArcher;
     
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class KitPvP extends JavaPlugin {
        private KitPvPArcher executor;
        private KitPvPKit executor1;
        private KitPvPElite executor2;
        private KitPvPSuper executor3;
        private KitPvPWarrior executor4;
        private KitPvPBoss executer5;
        private Pyro executor6;
        private Grandpa executor7;
        private Enderman executor8;
        private Miner executor9;
        private Kits executor10;
        private KitPvPCasual executor11;
       
        public void onEnable(){
            getConfig().options().copyDefaults(true);
            saveConfig();
            executor = new KitPvPArcher(this);
            getCommand("archer").setExecutor(executor);
            executor1 = new KitPvPKit(this);
            getCommand("pvp").setExecutor(executor1);
            executor2 = new KitPvPElite(this);
            getCommand("chemist").setExecutor(executor2);
            executor3 = new KitPvPSuper(this);
            getCommand("knight").setExecutor(executor3);
            executor4 = new KitPvPWarrior(this);
            getCommand("tank").setExecutor(executor4);
            executer5 = new KitPvPBoss(this);
            getCommand("boss").setExecutor(executer5);
            executor6 = new Pyro(this);
            getCommand("pyro").setExecutor(executor6);
            executor7 = new Grandpa(this);
            getCommand("grandpa").setExecutor(executor7);
            executor8 = new Enderman(this);
            getCommand("enderman").setExecutor(executor8);
            executor9 = new Miner(this);
            getCommand("miner").setExecutor(executor9);
            executor10 = new Kits(this);
            getCommand("kits").setExecutor(executor10);
            executor11 = new KitPvPCasual(this);
            getCommand("casual").setExecutor(executor11);       
           
        }
    
    A separate class, :p

    :p

    Perhaps MrBluebear3 knows, :D

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

    Hoolean

    W
    What you be confuddled about? :D

    (yes that senteance made sense, be quiet)
     
  21. Offline

    HyrulesLegend

    Above ^
    Trying to make a warp plugin.
     
  22. Offline

    fireblast709

    Somewhere you made an error, and don't know if you already fixed it:
    Code:java
    1. int y = player.getLocation.getBlockY();
    Should be
    Code:java
    1. int y = player.getLocation().getBlockY();
    Also where you do your warp setting (so at your "setwarp" command, or however it is called):
    Code:java
    1. Location loc = player.getLocation();
    2. config.set("your.path", loc.getX());
    3. config.set("your.path", loc.getY());
    4. config.set("your.path", loc.getZ());

    And where you want to teleport to them (your "warp" command)
    Code:java
    1. World w = p.getServer().getWorld(config.getString("your.path.world", ""));
    2. Double x = config.getInt("main.lobby.location.x");
    3. Double y = config.getInt("main.lobby.location.y");
    4. Double z = config.getInt("main.lobby.location.z");
    5. if(w == null || x == null || y == null || z == null)
    6. {
    7. p.sendMessage("Warp does not exist");
    8. return true; // depending on your method. If it is void you should use 'return;'
    9. }
    10. Location lobbyspawn = new Location(w, x, y, z);
    11. player.teleport(lobbyspawn);
     
  23. Offline

    HyrulesLegend

    fireblast709
    Code:
    package me.kyrp.KitPvP;
     
     
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class KitPvPCasual implements CommandExecutor {
        @SuppressWarnings("unused")
        private KitPvP plugin;
        public KitPvPCasual(KitPvP plugin) {
            this.plugin = plugin;
        }
     
            public boolean onCommand1(CommandSender sender, Command cmd, String commandLabel, String[] args) {
                if(commandLabel.equalsIgnoreCase("setcasual"));
            Player player = (Player) sender;
            Location loc = player.getLocation();
            config.set("your.path", loc.getX());
            config.set("your.path", loc.getY());
            config.set("your.path", loc.getZ());
           
            if(commandLabel.equalsIgnoreCase("casual"));
            World w = player.getServer().getWorld(config.getString("your.path.world", ""));
            Double x = config.getInt("main.lobby.location.x");
            Double y = config.getInt("main.lobby.location.y");
            Double z = config.getInt("main.lobby.location.z");
            if(w == null || x == null || y == null || z == null)
            {
                player.sendMessage("Warp does not exist");
                return true; // depending on your method. If it is void you should use 'return;'
            }
            Location lobbyspawn = new Location(w, x, y, z);
            player.teleport(lobbyspawn);
        }
    }
    That's my code, every line with "config.get" or config.set has an error.
    "config cannot be resolved"
     
  24. Offline

    fireblast709

    what is the name of the .yml file you are using? if you are using config.yml, use "plugin.getConfig().get(" and "plugin.getConfig().set("
     
  25. Offline

    HyrulesLegend

    Ok, fixed first 3, now what do I do for this code?

    Double y = config.getInt("main.lobby.location.y"); and so on, what do I replace the config.getInt with?

    Here's my whole code, BTW:

    Code:
    package me.kyrp.KitPvP;
     
     
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class KitPvPCasual implements CommandExecutor {
        @SuppressWarnings("unused")
        private KitPvP plugin;
        public KitPvPCasual(KitPvP plugin) {
            this.plugin = plugin;
        }
     
            public boolean onCommand1(CommandSender sender, Command cmd, String commandLabel, String[] args) {
                if(commandLabel.equalsIgnoreCase("setcasual"));
            Player player = (Player) sender;
            Location loc = player.getLocation();
            plugin.getConfig().set("your.path", loc.getX());
            plugin.getConfig().set("your.path", loc.getY());
            plugin.getConfig().set("your.path", loc.getZ());
           
            if(commandLabel.equalsIgnoreCase("casual"));
            Bukkit.broadcastMessage(ChatColor.GOLD + "[SonicKitPvP] " + sender.getName() + "is at casual, Do /casual to 1v1 him!")
            World w = player.getServer().getWorld(config.getString("your.path.world", ""));
            Double x = config.getInt("main.lobby.location.x");
            Double y = config.getInt("main.lobby.location.y");
            Double z = config.getInt("main.lobby.location.z");
            if(w == null || x == null || y == null || z == null)
            {
                player.sendMessage("Warp does not exist");
                return true; // depending on your method. If it is void you should use 'return;'
            }
            Location lobbyspawn = new Location(w, x, y, z);
            player.teleport(lobbyspawn);
        }
    }
    
    Config.yml

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

    fireblast709

    plugin.getConfig().getDouble("path")
     
  27. Offline

    HyrulesLegend

    This line:
    World w = player.getServer().getWorld(config.getString("your.path.world", ""))

    has an error. Once again, cannot resolve "config"
     
  28. Offline

    Woobie

    Max_The_Link_Fan
    Your tag was a fail, setting the warps is easy, but warping to the warps is complicated.

    I know an easy way to teleport to a warp, if the file contains only 1 warp, but using more than 1, is tricky.
    Maybe fireblast709 knows an easy way to use
    Code:
    if(args[0].matches(config.whatHere? 
    I tried getting the section, so it would check if the argument matches to 1 of the warps in this section, but nope!
     
  29. Offline

    fireblast709

    Woobie solely depends on your config. If it is something like this:
    Code:
    #You could add pitch and yaw, obviously.
    warps:
      home:
        x: 
        y:
        z
        world:
      mine:
        x:
        y:
        z:
        world:
    you could use plugin.getConfig().getConfigurationSection("warps."+args[0]) and check for null. If it is, the warp is non-existant. If it is you warp to is getting the Location like usual. Deleting warp would mean setting the section to null.
    Setting is a bit harder. This would need a check if it exists, otherwise create it. Then set the x,y,z and world like usual

    Max_The_Link_Fan use it like this
    Code:java
    1. player.getServer().getWorld(plugin.getConfig().getString("your.path.world", ""));
     
  30. Offline

    Woobie

    My config is exactly like that.
    I'll try that tomorrow, thanks.
    This is not something I need, at all, but its always fun to learn new things :p
     
Thread Status:
Not open for further replies.

Share This Page