/[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 1614 by torben, Thu Oct 20 17:06:20 2011 UTC miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/HomeCommand.java revision 2434 by torben, Mon Mar 9 14:16:47 2015 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;
13  import org.bukkit.entity.Player;  import org.bukkit.entity.Player;
14  import org.bukkit.plugin.Plugin;  import org.bukkit.plugin.Plugin;
15    import org.bukkit.configuration.Configuration;
16  import org.bukkit.configuration.file.YamlConfiguration;  import org.bukkit.configuration.file.YamlConfiguration;
17    
18  public class HomeCommand implements CommandExecutor {  public class HomeCommand implements CommandExecutor {
# Line 33  public class HomeCommand implements Comm Line 35  public class HomeCommand implements Comm
35                          System.out.println("[HoerupUtils] exception loading config file: " + e.getMessage() );                          System.out.println("[HoerupUtils] exception loading config file: " + e.getMessage() );
36                  }                  }
37          }          }
38    
39            Configuration getConfig() {
40                    return config;
41            }
42                    
43    
44          @Override          @Override
# Line 41  public class HomeCommand implements Comm Line 47  public class HomeCommand implements Comm
47                  if (!(sender instanceof Player)) {                  if (!(sender instanceof Player)) {
48                          return false;                          return false;
49                  }                  }
50                  Player p = (Player) sender;                  final Player p = (Player) sender;
51    
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                                    @SuppressWarnings("deprecation")
64                                  World world = p.getServer().getWorld(worldName);                                  OfflinePlayer op = sender.getServer().getOfflinePlayer(args[0]);        
65                                    if (op.hasPlayedBefore() == false && op.isOnline() == false) {
66                                  Location loc = new Location( world, x, y, z, (float)yaw, (float)pitch);                                          sender.sendMessage("Player not found");                                
67                                    } else {
68                                  p.teleport(loc);                                          p.sendMessage("Sending you to " + op.getName() + "'s home");
69                                            tpUser(p, op.getName() );
70                                    }
71                          } else {                          } else {
72                                  p.sendMessage(ChatColor.YELLOW + "You haven't set a home yet!");                                  p.sendMessage("Only operators may use this command");
73                          }                          }
74                  }                  }
75    
# Line 84  public class HomeCommand implements Comm Line 92  public class HomeCommand implements Comm
92                                    
93                  return true;                  return true;
94          }          }
95            
96            private void tpUser(final Player p, String name) {
97                    String worldName = config.getString( name + ".world");
98                    if (worldName != null) {
99                            double yaw = config.getDouble( name + ".yaw", 0.0);    
100                            double pitch = config.getDouble( name + ".pitch", 0.0);
101                            double x = config.getDouble( name + ".x", 0.0);
102                            double y = config.getDouble( name + ".y", 0.0);
103                            double z = config.getDouble( name + ".z", 0.0);
104    
105                            World world = p.getServer().getWorld(worldName);
106                            int blockX = (int) Math.floor(x);
107                            int blockZ = (int) Math.floor(z);
108                            world.loadChunk(blockX, blockZ);        
109    
110                            final Location loc = new Location( world, x, y, z, (float)yaw, (float)pitch);
111    
112                            Runnable r = new Runnable() {
113                                    public void run() {
114                                            p.teleport(loc);
115                                    }
116                            };
117                            int tickCount = 2; // 2 ticks = 100ms
118    
119                            p.getServer().getScheduler().scheduleSyncDelayedTask(plugin, r, tickCount);
120    
121                    } else {
122                            p.sendMessage(ChatColor.YELLOW + "You haven't set a home yet!");
123                    }
124                    
125            }
126  }  }

Legend:
Removed from v.1614  
changed lines
  Added in v.2434

  ViewVC Help
Powered by ViewVC 1.1.20