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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1592 - (show annotations) (download)
Wed Aug 24 18:45:40 2011 UTC (12 years, 8 months ago) by torben
File size: 2072 byte(s)
Added my own home implementation and a command to control weather
1 package dk.thoerup.bukkit.hoeruputils;
2
3 import java.io.File;
4
5 import org.bukkit.ChatColor;
6 import org.bukkit.Location;
7 import org.bukkit.World;
8 import org.bukkit.command.Command;
9 import org.bukkit.command.CommandExecutor;
10 import org.bukkit.command.CommandSender;
11 import org.bukkit.entity.Player;
12 import org.bukkit.plugin.Plugin;
13 import org.bukkit.util.config.Configuration;
14
15 public class HomeCommand implements CommandExecutor {
16
17 Plugin plugin;
18
19 Configuration config;
20
21 public HomeCommand(Plugin plugin) {
22 this.plugin = plugin;
23
24 File file = new File( plugin.getDataFolder(), "homes.yml");
25
26 config = new Configuration( file );
27 config.load();
28 }
29
30
31 @Override
32 public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
33
34 if (!(sender instanceof Player)) {
35 return false;
36 }
37 Player p = (Player) sender;
38
39 String name = p.getName();
40
41 if ( command.getName().equals("home") ) {
42 config.load();
43
44 String worldName = config.getString( name + ".world");
45 if (worldName != null) {
46 double yaw = config.getDouble( name + ".yaw", 0.0);
47 double pitch = config.getDouble( name + ".pitch", 0.0);
48 double x = config.getDouble( name + ".x", 0.0);
49 double y = config.getDouble( name + ".y", 0.0);
50 double z = config.getDouble( name + ".z", 0.0);
51
52 World world = p.getServer().getWorld(worldName);
53
54 Location loc = new Location( world, x, y, z, (float)yaw, (float)pitch);
55
56 p.teleport(loc);
57 } else {
58 p.sendMessage(ChatColor.YELLOW + "You haven't set a home yet!");
59 }
60 }
61
62 if (command.getName().equals("sethome") ) {
63 Location loc = p.getLocation();
64 config.setProperty( name + ".yaw", loc.getYaw() );
65 config.setProperty( name + ".pitch", loc.getPitch() );
66 config.setProperty( name + ".world", loc.getWorld().getName() );
67 config.setProperty( name + ".x", loc.getX() );
68 config.setProperty( name + ".y", loc.getY() );
69 config.setProperty( name + ".z", loc.getZ() );
70
71 config.save();
72 p.sendMessage(ChatColor.YELLOW + "home is set");
73 }
74
75 return true;
76 }
77 }

  ViewVC Help
Powered by ViewVC 1.1.20