/[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 1671 by torben, Thu Dec 22 20:30:28 2011 UTC miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/HomeCommand.java revision 1865 by torben, Mon Oct 15 13:41:10 2012 UTC
# Line 6  import java.io.IOException; Line 6  import java.io.IOException;
6  import org.bukkit.ChatColor;  import org.bukkit.ChatColor;
7  import org.bukkit.Location;  import org.bukkit.Location;
8  import org.bukkit.World;  import org.bukkit.World;
9    import org.bukkit.OfflinePlayer;
10  import org.bukkit.command.Command;  import org.bukkit.command.Command;
11  import org.bukkit.command.CommandExecutor;  import org.bukkit.command.CommandExecutor;
12  import org.bukkit.command.CommandSender;  import org.bukkit.command.CommandSender;
# Line 51  public class HomeCommand implements Comm Line 52  public class HomeCommand implements Comm
52                  String name = p.getName();                  String name = p.getName();
53    
54                  if ( command.getName().equals("home") ) {                  if ( command.getName().equals("home") ) {
55                            tpUser(p, name);
56                          String worldName = config.getString( name + ".world");                  }
57                          if (worldName != null) {                  if ( command.getName().equals("ophome") ) {
58                                  double yaw = config.getDouble( name + ".yaw", 0.0);                              if (args.length != 1) {
59                                  double pitch = config.getDouble( name + ".pitch", 0.0);                                  p.sendMessage("Usage: /ophome <player>");
60                                  double x = config.getDouble( name + ".x", 0.0);                                  return true;
61                                  double y = config.getDouble( name + ".y", 0.0);                          }
62                                  double z = config.getDouble( name + ".z", 0.0);                          if ( p.isOp() ) {
63                                    OfflinePlayer op = sender.getServer().getOfflinePlayer(args[0]);        
64                                  World world = p.getServer().getWorld(worldName);                                  if (op.hasPlayedBefore() == false && op.isOnline() == false) {
65                                  int blockX = (int) Math.floor(x);                                          sender.sendMessage("Player not found");                                
66                                  int blockZ = (int) Math.floor(z);                                  } else {
67                                  world.loadChunk(blockX, blockZ);                                                  p.sendMessage("Sending you to " + op.getName() + "'s home");
68                                            tpUser(p, op.getName() );
69                                  final Location loc = new Location( world, x, y, z, (float)yaw, (float)pitch);                                  }
   
                                 Runnable r = new Runnable() {  
                                         public void run() {  
                                                 p.teleport(loc);  
                                         }  
                                 };  
                                 int tickCount = 2; // 2 ticks = 100ms  
   
                                 p.getServer().getScheduler().scheduleSyncDelayedTask(plugin, r, tickCount);  
   
70                          } else {                          } else {
71                                  p.sendMessage(ChatColor.YELLOW + "You haven't set a home yet!");                                  p.sendMessage("Only operators may use this command");
72                          }                          }
73                  }                  }
74    
# Line 100  public class HomeCommand implements Comm Line 91  public class HomeCommand implements Comm
91                                    
92                  return true;                  return true;
93          }          }
94            
95            private void tpUser(final Player p, String name) {
96                    String worldName = config.getString( name + ".world");
97                    if (worldName != null) {
98                            double yaw = config.getDouble( name + ".yaw", 0.0);    
99                            double pitch = config.getDouble( name + ".pitch", 0.0);
100                            double x = config.getDouble( name + ".x", 0.0);
101                            double y = config.getDouble( name + ".y", 0.0);
102                            double z = config.getDouble( name + ".z", 0.0);
103    
104                            World world = p.getServer().getWorld(worldName);
105                            int blockX = (int) Math.floor(x);
106                            int blockZ = (int) Math.floor(z);
107                            world.loadChunk(blockX, blockZ);        
108    
109                            final Location loc = new Location( world, x, y, z, (float)yaw, (float)pitch);
110    
111                            Runnable r = new Runnable() {
112                                    public void run() {
113                                            p.teleport(loc);
114                                    }
115                            };
116                            int tickCount = 2; // 2 ticks = 100ms
117    
118                            p.getServer().getScheduler().scheduleSyncDelayedTask(plugin, r, tickCount);
119    
120                    } else {
121                            p.sendMessage(ChatColor.YELLOW + "You haven't set a home yet!");
122                    }
123                    
124            }
125  }  }

Legend:
Removed from v.1671  
changed lines
  Added in v.1865

  ViewVC Help
Powered by ViewVC 1.1.20