/[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 1666 - (hide annotations) (download)
Wed Dec 21 16:42:43 2011 UTC (12 years, 5 months ago) by torben
File size: 2661 byte(s)
1)make statuslistener dump server info in xml and 2) a experimental commit to make /home preload the destination chunk and delay the teleport
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 1614 import org.bukkit.configuration.file.YamlConfiguration;
15 torben 1592
16     public class HomeCommand implements CommandExecutor {
17    
18     Plugin plugin;
19    
20 torben 1614 YamlConfiguration config;
21 torben 1592
22 torben 1614 File file;
23    
24 torben 1592 public HomeCommand(Plugin plugin) {
25     this.plugin = plugin;
26    
27 torben 1614 file = new File( plugin.getDataFolder(), "homes.yml");
28 torben 1592
29 torben 1614 config = new YamlConfiguration();
30     try {
31     config.load(file);
32     } catch (Exception e) {
33     System.out.println("[HoerupUtils] exception loading config file: " + e.getMessage() );
34     }
35 torben 1592 }
36    
37    
38     @Override
39     public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
40    
41     if (!(sender instanceof Player)) {
42     return false;
43     }
44 torben 1666 final Player p = (Player) sender;
45 torben 1592
46     String name = p.getName();
47    
48     if ( command.getName().equals("home") ) {
49    
50     String worldName = config.getString( name + ".world");
51     if (worldName != null) {
52     double yaw = config.getDouble( name + ".yaw", 0.0);
53     double pitch = config.getDouble( name + ".pitch", 0.0);
54     double x = config.getDouble( name + ".x", 0.0);
55     double y = config.getDouble( name + ".y", 0.0);
56     double z = config.getDouble( name + ".z", 0.0);
57    
58     World world = p.getServer().getWorld(worldName);
59 torben 1666 int blockX = (int) Math.floor(x);
60     int blockZ = (int) Math.floor(z);
61     world.loadChunk(blockX, blockZ);
62 torben 1592
63 torben 1666 final Location loc = new Location( world, x, y, z, (float)yaw, (float)pitch);
64 torben 1592
65 torben 1666 Runnable r = new Runnable() {
66     public void run() {
67     p.teleport(loc);
68     }
69     };
70     int tickCount = 2; // 2 ticks = 100ms
71    
72     p.getServer().getScheduler().scheduleSyncDelayedTask(plugin, r, tickCount);
73    
74 torben 1592 } else {
75     p.sendMessage(ChatColor.YELLOW + "You haven't set a home yet!");
76     }
77     }
78    
79     if (command.getName().equals("sethome") ) {
80     Location loc = p.getLocation();
81 torben 1614 config.set( name + ".yaw", loc.getYaw() );
82     config.set( name + ".pitch", loc.getPitch() );
83     config.set( name + ".world", loc.getWorld().getName() );
84     config.set( name + ".x", loc.getX() );
85     config.set( name + ".y", loc.getY() );
86     config.set( name + ".z", loc.getZ() );
87 torben 1592
88 torben 1614 try {
89     config.save(file);
90     p.sendMessage(ChatColor.YELLOW + "home is set");
91     } catch (IOException e) {
92     System.out.println("[HoerupUtils] : /sethome save threw an IO exception: " + e.getMessage() );
93     }
94 torben 1592 }
95    
96     return true;
97     }
98     }

  ViewVC Help
Powered by ViewVC 1.1.20