package dk.thoerup.bukkit.hoeruputils; import java.io.File; 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; import org.bukkit.plugin.Plugin; import org.bukkit.util.config.Configuration; public class HomeCommand implements CommandExecutor { Plugin plugin; Configuration config; public HomeCommand(Plugin plugin) { this.plugin = plugin; File file = new File( plugin.getDataFolder(), "homes.yml"); config = new Configuration( file ); config.load(); } @Override public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof Player)) { return false; } Player p = (Player) sender; String name = p.getName(); if ( command.getName().equals("home") ) { config.load(); String worldName = config.getString( name + ".world"); if (worldName != null) { double yaw = config.getDouble( name + ".yaw", 0.0); double pitch = config.getDouble( name + ".pitch", 0.0); double x = config.getDouble( name + ".x", 0.0); double y = config.getDouble( name + ".y", 0.0); double z = config.getDouble( name + ".z", 0.0); World world = p.getServer().getWorld(worldName); Location loc = new Location( world, x, y, z, (float)yaw, (float)pitch); p.teleport(loc); } else { p.sendMessage(ChatColor.YELLOW + "You haven't set a home yet!"); } } if (command.getName().equals("sethome") ) { Location loc = p.getLocation(); config.setProperty( name + ".yaw", loc.getYaw() ); config.setProperty( name + ".pitch", loc.getPitch() ); config.setProperty( name + ".world", loc.getWorld().getName() ); config.setProperty( name + ".x", loc.getX() ); config.setProperty( name + ".y", loc.getY() ); config.setProperty( name + ".z", loc.getZ() ); config.save(); p.sendMessage(ChatColor.YELLOW + "home is set"); } return true; } }