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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1671 - (hide annotations) (download)
Thu Dec 22 20:30:28 2011 UTC (12 years, 5 months ago) by torben
File size: 2758 byte(s)
add diver command and add player homes to status XML
1 torben 1592 package dk.thoerup.bukkit.hoeruputils;
2    
3     import java.io.File;
4 torben 1614 import java.io.IOException;
5 torben 1592
6     import org.bukkit.ChatColor;
7     import org.bukkit.Location;
8     import org.bukkit.World;
9     import org.bukkit.command.Command;
10     import org.bukkit.command.CommandExecutor;
11     import org.bukkit.command.CommandSender;
12     import org.bukkit.entity.Player;
13     import org.bukkit.plugin.Plugin;
14 torben 1671 import org.bukkit.configuration.Configuration;
15 torben 1614 import org.bukkit.configuration.file.YamlConfiguration;
16 torben 1592
17     public class HomeCommand implements CommandExecutor {
18    
19     Plugin plugin;
20    
21 torben 1614 YamlConfiguration config;
22 torben 1592
23 torben 1614 File file;
24    
25 torben 1592 public HomeCommand(Plugin plugin) {
26     this.plugin = plugin;
27    
28 torben 1614 file = new File( plugin.getDataFolder(), "homes.yml");
29 torben 1592
30 torben 1614 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 torben 1592 }
37 torben 1671
38     Configuration getConfig() {
39     return config;
40     }
41 torben 1592
42    
43     @Override
44     public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
45    
46     if (!(sender instanceof Player)) {
47     return false;
48     }
49 torben 1666 final Player p = (Player) sender;
50 torben 1592
51     String name = p.getName();
52    
53     if ( command.getName().equals("home") ) {
54    
55     String worldName = config.getString( name + ".world");
56     if (worldName != null) {
57     double yaw = config.getDouble( name + ".yaw", 0.0);
58     double pitch = config.getDouble( name + ".pitch", 0.0);
59     double x = config.getDouble( name + ".x", 0.0);
60     double y = config.getDouble( name + ".y", 0.0);
61     double z = config.getDouble( name + ".z", 0.0);
62    
63     World world = p.getServer().getWorld(worldName);
64 torben 1666 int blockX = (int) Math.floor(x);
65     int blockZ = (int) Math.floor(z);
66     world.loadChunk(blockX, blockZ);
67 torben 1592
68 torben 1666 final Location loc = new Location( world, x, y, z, (float)yaw, (float)pitch);
69 torben 1592
70 torben 1666 Runnable r = new Runnable() {
71     public void run() {
72     p.teleport(loc);
73     }
74     };
75     int tickCount = 2; // 2 ticks = 100ms
76    
77     p.getServer().getScheduler().scheduleSyncDelayedTask(plugin, r, tickCount);
78    
79 torben 1592 } else {
80     p.sendMessage(ChatColor.YELLOW + "You haven't set a home yet!");
81     }
82     }
83    
84     if (command.getName().equals("sethome") ) {
85     Location loc = p.getLocation();
86 torben 1614 config.set( name + ".yaw", loc.getYaw() );
87     config.set( name + ".pitch", loc.getPitch() );
88     config.set( name + ".world", loc.getWorld().getName() );
89     config.set( name + ".x", loc.getX() );
90     config.set( name + ".y", loc.getY() );
91     config.set( name + ".z", loc.getZ() );
92 torben 1592
93 torben 1614 try {
94     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 torben 1592 }
100    
101     return true;
102     }
103     }

  ViewVC Help
Powered by ViewVC 1.1.20