/[projects]/miscJava/bukkit-minecraft-plugins/CreativeWorld/src/dk/thoerup/bukkit/creativeworld/TeleportCommand.java
ViewVC logotype

Contents of /miscJava/bukkit-minecraft-plugins/CreativeWorld/src/dk/thoerup/bukkit/creativeworld/TeleportCommand.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1657 - (show annotations) (download)
Sat Dec 10 19:33:19 2011 UTC (12 years, 5 months ago) by torben
File size: 3580 byte(s)
Import creative world


1 package dk.thoerup.bukkit.creativeworld;
2
3 import org.bukkit.ChatColor;
4 import org.bukkit.Location;
5 import org.bukkit.World;
6 import org.bukkit.command.Command;
7 import org.bukkit.command.CommandExecutor;
8 import org.bukkit.command.CommandSender;
9 import org.bukkit.entity.Player;
10
11 import org.bukkit.configuration.*;
12
13 public class TeleportCommand implements CommandExecutor {
14
15 CreativeMain plugin;
16
17 public TeleportCommand(CreativeMain plugin) {
18 this.plugin = plugin;
19 }
20
21 @Override
22 public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
23
24 if (!(sender instanceof Player)) { // it's not a console command
25 return false;
26 }
27
28 Configuration config = plugin.getConfig();
29
30
31 Player p = (Player) sender;
32
33
34 if (command.getName().equalsIgnoreCase("creative")) {
35 if (p.getWorld().getName().equalsIgnoreCase("creative")) {
36 p.sendMessage(ChatColor.YELLOW + "You are already in creative");
37 } else {
38 Location old = p.getLocation();
39
40 config.set( p.getName() + ".loc.survival.x", old.getX() );
41 config.set( p.getName() + ".loc.survival.y", old.getY() );
42 config.set( p.getName() + ".loc.survival.z", old.getZ() );
43 config.set( p.getName() + ".loc.survival.yaw", old.getYaw() );
44 config.set( p.getName() + ".loc.survival.pitch", old.getPitch() );
45 config.set( p.getName() + ".loc.survival.world", old.getWorld().getName() );
46
47
48 World creative = sender.getServer().getWorld("creative");
49 double creativeX = config.getDouble( p.getName() + ".loc.creative.x", -1.0);
50 double creativeY = config.getDouble( p.getName() + ".loc.creative.y", -1.0);
51 double creativeZ = config.getDouble( p.getName() + ".loc.creative.z", -1.0);
52 double creativeYaw = config.getDouble( p.getName() + ".loc.creative.yaw", -1.0);
53 double creativePitch = config.getDouble( p.getName() + ".loc.creative.pitch", -1.0);
54
55 Location loc;
56 if ( creativeY == -1) {
57 loc = creative.getSpawnLocation();
58 } else {
59 loc = new Location(creative, creativeX, creativeY, creativeZ, (float) creativeYaw, (float) creativePitch);
60 }
61
62 p.teleport( loc );
63 }
64 } else {
65 if (!p.getWorld().getName().equalsIgnoreCase("creative")) {
66 p.sendMessage(ChatColor.YELLOW + "You are already in survival");
67 } else {
68 Location old = p.getLocation();
69
70 config.set( p.getName() + ".loc.creative.x", old.getX() );
71 config.set( p.getName() + ".loc.creative.y", old.getY() );
72 config.set( p.getName() + ".loc.creative.z", old.getZ() );
73 config.set( p.getName() + ".loc.creative.yaw", old.getYaw() );
74 config.set( p.getName() + ".loc.creative.pitch", old.getPitch() );
75
76 double survivalX = config.getDouble( p.getName() + ".loc.survival.x", -1.0);
77 double survivalY = config.getDouble( p.getName() + ".loc.survival.y", -1.0);
78 double survivalZ = config.getDouble( p.getName() + ".loc.survival.z", -1.0);
79 double survivalYaw = config.getDouble( p.getName() + ".loc.survival.yaw", -1.0);
80 double survivalPitch = config.getDouble( p.getName() + ".loc.survival.pitch", -1.0);
81 String survivalWorld = config.getString( p.getName() + ".loc.survival.world");
82
83 Location loc;
84 if (survivalY == -1) {
85 World world = sender.getServer().getWorld("world");
86 loc = world.getSpawnLocation();
87 } else {
88 World world = sender.getServer().getWorld(survivalWorld);
89 loc = new Location(world, survivalX, survivalY, survivalZ, (float)survivalYaw, (float)survivalPitch);
90
91 }
92
93 p.teleport( loc );
94 }
95 }
96
97 plugin.saveConfig();
98
99 return true;
100 }
101 }

  ViewVC Help
Powered by ViewVC 1.1.20