Solved Warp bug

Discussion in 'Plugin Development' started by xepisolonxx, Mar 27, 2014.

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

    xepisolonxx

    So it does not put the yaw or pitch anyway i can fix this?
    SettingsManager
    Code:
    package me.jr.main.listeners;
     
    import java.io.File;
    import java.io.IOException;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginDescriptionFile;
     
        public class SettingsManager {
         
            private SettingsManager() { }
       
            static SettingsManager instance = new SettingsManager();
       
            public static SettingsManager getInstance() {
                    return instance;
            }
       
            Plugin p;
       
            FileConfiguration config;
            File cfile;
       
            FileConfiguration data;
            File dfile;
       
            public void setup(Plugin p) {
                    cfile = new File(p.getDataFolder(), "config.yml");
                    config = p.getConfig();
                    //config.options().copyDefaults(true);
                    //saveConfig();
               
                    if (!p.getDataFolder().exists()) {
                            p.getDataFolder().mkdir();
                    }
               
                    dfile = new File(p.getDataFolder(), "data.yml");
               
                    if (!dfile.exists()) {
                            try {
                                    dfile.createNewFile();
                            }
                            catch (IOException e) {
                                    Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not create data.yml!");
                            }
                    }
               
                    data = YamlConfiguration.loadConfiguration(dfile);
            }
       
            public FileConfiguration getData() {
                    return data;
            }
       
            public void saveData() {
                    try {
                            data.save(dfile);
                    }
                    catch (IOException e) {
                            Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save data.yml!");
                    }
            }
       
            public void reloadData() {
                    data = YamlConfiguration.loadConfiguration(dfile);
            }
       
            public FileConfiguration getConfig() {
                    return config;
            }
       
            public void saveConfig() {
                    try {
                            config.save(cfile);
                    }
                    catch (IOException e) {
                            Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save config.yml!");
                    }
            }
       
            public void reloadConfig() {
                    config = YamlConfiguration.loadConfiguration(cfile);
            }
       
            public PluginDescriptionFile getDesc() {
                    return p.getDescription();
            }
    }
    My warping class
    Code:
    package me.jr.main.commands;
     
    import java.util.ArrayList;
     
    import me.jr.main.Main;
    import me.jr.main.listeners.SettingsManager;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Sound;
    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 Warp implements CommandExecutor{
     
        private Main plugin;
        public static ArrayList<String> teleport = new ArrayList<String>();
     
        String message = ChatColor.BLUE + "" + ChatColor.BOLD + "[" + "" + ChatColor.RESET + "" + ChatColor.BOLD + ChatColor.GOLD + "ThunderKits" + "" + ChatColor.BOLD
                + ChatColor.BLUE +  "]" + ChatColor.RESET;
     
     
        public Warp(Main instance) {
        this.plugin = instance;
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, final String[] args){
            if (!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.RED + "Only players can do that!");
                return true;
     
        }
            final SettingsManager settings = SettingsManager.getInstance();
            final Player p = (Player)sender;
              if (cmd.getName().equalsIgnoreCase("warp") || cmd.getName().equalsIgnoreCase("warps")) {
                  if (args.length == 0) {
                      StringBuilder sb = new StringBuilder();
           
                      for (String warpName : settings.getData().getConfigurationSection("warps").getKeys(false)) {
                      sb.append(warpName).append(", ");
                      }
                   
                      p.sendMessage(ChatColor.WHITE + "Warps: " + ChatColor.GOLD + sb.substring(0, sb.length() - 2));
                      return true;
                  }
                  if (settings.getData().getConfigurationSection("warps." + args[0]) == null) {
                          p.sendMessage(ChatColor.RED + "Warp " + args[0] + " does not exist!");
                          return true;
                  }
                  p.sendMessage(message + ChatColor.GREEN + " Preparing to teleport to " + args[0] + " please wait" + ChatColor.GOLD
                          + " 5" + ChatColor.GREEN + " seconds.");
     
                  teleport.remove(p.getName());
                  teleport.add(p.getName());
                  Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {     
                      public void run() {
                          if (teleport.contains(p.getName()) == true){
                   
                  World w = Bukkit.getServer().getWorld(settings.getData().getString("warps." + args[0] + ".world"));
                  double x = settings.getData().getDouble("warps." + args[0] + ".x");
                  double y = settings.getData().getDouble("warps." + args[0] + ".y");
                  double z = settings.getData().getDouble("warps." + args[0] + ".z");
               
                  float yaw = settings.getData().getInt("warps." + args[0] + ".yaw");
                  float pitch = settings.getData().getInt("warps." + args[0] + ".pitch");
     
                  p.teleport(new Location(w, x, y, z));
                  p.getLocation().setYaw(yaw);
                  p.getLocation().setPitch(pitch);
     
     
                  teleport.remove(p.getName());
                  p.playSound(p.getLocation(), Sound.ENDERMAN_TELEPORT, 1, 1);
                      }
                       
                      }
                  }, 100);
       
              }
            return false;
           
              }
    }
        
    My setwarp class
    Code:
    package me.jr.main.commands;
     
    import me.jr.main.listeners.SettingsManager;
     
    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 Setwarp implements CommandExecutor{
       
     
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if (!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.RED + "Only players can do that!");
                return true;
       
        }
            SettingsManager settings = SettingsManager.getInstance();
            Player p =(Player)sender;
     
            if (cmd.getName().equalsIgnoreCase("setwarp")) {
                if (p.hasPermission("admin.setwarp")){
                if (args.length == 0) {
                        p.sendMessage(ChatColor.RED + "Please specify a name!");
                        return true;
                }
                settings.getData().set("warps." + args[0] + ".world", p.getLocation().getWorld().getName());
                settings.getData().set("warps." + args[0] + ".x", p.getLocation().getX());
                settings.getData().set("warps." + args[0] + ".y", p.getLocation().getY());
                settings.getData().set("warps." + args[0] + ".z", p.getLocation().getZ());
                settings.getData().set("warps." + args[0] + ".yaw", p.getLocation().getYaw());
                settings.getData().set("warps." + args[0] + ".pitch", p.getLocation().getPitch());
     
     
                settings.saveData();
                p.sendMessage(ChatColor.GREEN + "You have created warp " + args[0] + "!");
        }
    }
            return false;
            }
            }
    
     
  2. Offline

    ShadowLAX

    xepisolonxx Yaw and pitch are floats, not integers.
     
  3. Offline

    xepisolonxx

    So should i use
    Code:
                  float yaw = settings.getData().getInt("warps." + args[0] + ".yaw");
    
    or
    Code:
                  float yaw = (float) settings.getData().get("warps." + args[0] + ".yaw");
    
     
  4. Offline

    ShadowLAX

  5. Offline

    GotRice

    xepisolonxx Pretty sure you cant just cast a string to a float..
     
  6. Offline

    xTigerRebornx

Thread Status:
Not open for further replies.

Share This Page