/[projects]/miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/HomeCommand.java
ViewVC logotype

Diff of /miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/HomeCommand.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

miscJava/bukkit-minecraft-plugins/HoerupUtils/src/dk/thoerup/bukkit/hoeruputils/HomeCommand.java revision 1592 by torben, Wed Aug 24 18:45:40 2011 UTC miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/HomeCommand.java revision 1684 by torben, Fri Jan 27 12:21:27 2012 UTC
# Line 1  Line 1 
1  package dk.thoerup.bukkit.hoeruputils;  package dk.thoerup.bukkit.hoeruputils;
2    
3  import java.io.File;  import java.io.File;
4    import java.io.IOException;
5    
6  import org.bukkit.ChatColor;  import org.bukkit.ChatColor;
7  import org.bukkit.Location;  import org.bukkit.Location;
# Line 10  import org.bukkit.command.CommandExecuto Line 11  import org.bukkit.command.CommandExecuto
11  import org.bukkit.command.CommandSender;  import org.bukkit.command.CommandSender;
12  import org.bukkit.entity.Player;  import org.bukkit.entity.Player;
13  import org.bukkit.plugin.Plugin;  import org.bukkit.plugin.Plugin;
14  import org.bukkit.util.config.Configuration;  import org.bukkit.configuration.Configuration;
15    import org.bukkit.configuration.file.YamlConfiguration;
16    
17  public class HomeCommand implements CommandExecutor {  public class HomeCommand implements CommandExecutor {
18    
19          Plugin plugin;          Plugin plugin;
20    
21          Configuration config;          YamlConfiguration config;
22    
23            File file;
24    
25          public HomeCommand(Plugin plugin) {          public HomeCommand(Plugin plugin) {
26                  this.plugin = plugin;                  this.plugin = plugin;
27    
28                  File file = new File( plugin.getDataFolder(), "homes.yml");                  file = new File( plugin.getDataFolder(), "homes.yml");
29    
30                    config = new YamlConfiguration();
31                    try {
32                            config.load(file);
33                    } catch (Exception e) {
34                            System.out.println("[HoerupUtils] exception loading config file: " + e.getMessage() );
35                    }
36            }
37    
38                  config = new Configuration( file );          Configuration getConfig() {
39                  config.load();                  return config;
40          }          }
41                    
42    
# Line 34  public class HomeCommand implements Comm Line 46  public class HomeCommand implements Comm
46                  if (!(sender instanceof Player)) {                  if (!(sender instanceof Player)) {
47                          return false;                          return false;
48                  }                  }
49                  Player p = (Player) sender;                  final Player p = (Player) sender;
50    
51                  String name = p.getName();                  String name = p.getName();
52    
53                  if ( command.getName().equals("home") ) {                  if ( command.getName().equals("home") ) {
                         config.load();  
54    
55                          String worldName = config.getString( name + ".world");                          String worldName = config.getString( name + ".world");
56                          if (worldName != null) {                          if (worldName != null) {
# Line 50  public class HomeCommand implements Comm Line 61  public class HomeCommand implements Comm
61                                  double z = config.getDouble( name + ".z", 0.0);                                  double z = config.getDouble( name + ".z", 0.0);
62    
63                                  World world = p.getServer().getWorld(worldName);                                  World world = p.getServer().getWorld(worldName);
64                                    int blockX = (int) Math.floor(x);
65                                    int blockZ = (int) Math.floor(z);
66                                    world.loadChunk(blockX, blockZ);        
67    
68                                    final Location loc = new Location( world, x, y, z, (float)yaw, (float)pitch);
69    
70                                    Runnable r = new Runnable() {
71                                            public void run() {
72                                                    p.teleport(loc);
73                                            }
74                                    };
75                                    int tickCount = 2; // 2 ticks = 100ms
76    
77                                  Location loc = new Location( world, x, y, z, (float)yaw, (float)pitch);                                  p.getServer().getScheduler().scheduleSyncDelayedTask(plugin, r, tickCount);
78    
                                 p.teleport(loc);  
79                          } else {                          } else {
80                                  p.sendMessage(ChatColor.YELLOW + "You haven't set a home yet!");                                  p.sendMessage(ChatColor.YELLOW + "You haven't set a home yet!");
81                          }                          }
# Line 61  public class HomeCommand implements Comm Line 83  public class HomeCommand implements Comm
83    
84                  if (command.getName().equals("sethome") ) {                  if (command.getName().equals("sethome") ) {
85                          Location loc = p.getLocation();                          Location loc = p.getLocation();
86                          config.setProperty( name + ".yaw", loc.getYaw() );                          config.set( name + ".yaw", loc.getYaw() );
87                          config.setProperty( name + ".pitch", loc.getPitch() );                          config.set( name + ".pitch", loc.getPitch() );
88                          config.setProperty( name + ".world", loc.getWorld().getName() );                          config.set( name + ".world", loc.getWorld().getName() );
89                          config.setProperty( name + ".x", loc.getX() );                          config.set( name + ".x", loc.getX() );
90                          config.setProperty( name + ".y", loc.getY() );                          config.set( name + ".y", loc.getY() );
91                          config.setProperty( name + ".z", loc.getZ() );                          config.set( name + ".z", loc.getZ() );
92    
93                          config.save();                          try {
94                          p.sendMessage(ChatColor.YELLOW + "home is set");                                  config.save(file);
95                                    p.sendMessage(ChatColor.YELLOW + "home is set");
96                            } catch (IOException e) {
97                                    System.out.println("[HoerupUtils] : /sethome save threw an IO exception: " + e.getMessage() );
98                            }
99                  }                  }
100                                    
101                  return true;                  return true;

Legend:
Removed from v.1592  
changed lines
  Added in v.1684

  ViewVC Help
Powered by ViewVC 1.1.20