11 |
import org.bukkit.command.CommandSender; |
import org.bukkit.command.CommandSender; |
12 |
import org.bukkit.entity.Player; |
import org.bukkit.entity.Player; |
13 |
import org.bukkit.plugin.Plugin; |
import org.bukkit.plugin.Plugin; |
14 |
|
import org.bukkit.configuration.Configuration; |
15 |
import org.bukkit.configuration.file.YamlConfiguration; |
import org.bukkit.configuration.file.YamlConfiguration; |
16 |
|
|
17 |
public class HomeCommand implements CommandExecutor { |
public class HomeCommand implements CommandExecutor { |
34 |
System.out.println("[HoerupUtils] exception loading config file: " + e.getMessage() ); |
System.out.println("[HoerupUtils] exception loading config file: " + e.getMessage() ); |
35 |
} |
} |
36 |
} |
} |
37 |
|
|
38 |
|
Configuration getConfig() { |
39 |
|
return config; |
40 |
|
} |
41 |
|
|
42 |
|
|
43 |
@Override |
@Override |
46 |
if (!(sender instanceof Player)) { |
if (!(sender instanceof Player)) { |
47 |
return false; |
return false; |
48 |
} |
} |
49 |
Player p = (Player) sender; |
final Player p = (Player) sender; |
50 |
|
|
51 |
String name = p.getName(); |
String name = p.getName(); |
52 |
|
|
61 |
double z = config.getDouble( name + ".z", 0.0); |
double z = config.getDouble( name + ".z", 0.0); |
62 |
|
|
63 |
World world = p.getServer().getWorld(worldName); |
World world = p.getServer().getWorld(worldName); |
64 |
|
int blockX = (int) Math.floor(x); |
65 |
|
int blockZ = (int) Math.floor(z); |
66 |
|
world.loadChunk(blockX, blockZ); |
67 |
|
|
68 |
|
final Location loc = new Location( world, x, y, z, (float)yaw, (float)pitch); |
69 |
|
|
70 |
|
Runnable r = new Runnable() { |
71 |
|
public void run() { |
72 |
|
p.teleport(loc); |
73 |
|
} |
74 |
|
}; |
75 |
|
int tickCount = 2; // 2 ticks = 100ms |
76 |
|
|
77 |
Location loc = new Location( world, x, y, z, (float)yaw, (float)pitch); |
p.getServer().getScheduler().scheduleSyncDelayedTask(plugin, r, tickCount); |
78 |
|
|
|
p.teleport(loc); |
|
79 |
} else { |
} else { |
80 |
p.sendMessage(ChatColor.YELLOW + "You haven't set a home yet!"); |
p.sendMessage(ChatColor.YELLOW + "You haven't set a home yet!"); |
81 |
} |
} |