Reputation: 511
So I am basicly making a Warping system but I am using it for a minigame. I want the owners of the server to be able to set the warp for the different players to spawn in when the minigame starts. For some reason, I am getting a error which is saying that I cannot teleport the player, here is my code for the teleporting part:
if(cmd.getName().equalsIgnoreCase("cakestart")){
if(getConfig().contains("locations." + args[0])){
int locationsX = this.getConfig().getInt("locations" + args[0] + ".X");
int locationsY = this.getConfig().getInt("locations" + args[0] + ".Y");
int locationsZ = this.getConfig().getInt("locations" + args[0] + ".Z");
int locationsYaw = this.getConfig().getInt("locations" + args[0] + ".Yaw");
int locationsPitch = this.getConfig().getInt("locations" + args[0] + ".Pitch");
Object locationsworld = this.getConfig().get("locations" + args[0] + ".World");
Location cakestart = new Location((World) locationsworld, locationsX, locationsY, locationsZ, locationsYaw, locationsPitch);
p.teleport(cakestart);
p.sendMessage("TPED!");
}
}
The error is happening with:
p.teleport(cakestart);
I can give any more info you need.
Upvotes: 0
Views: 1423
Reputation: 135
It is possible that the Object cannot be cast to the World object. I would try saving the world as a string and parsing it to a world object using Bukkit.getWorld("string");
.
To get a World from the config all you have to do is this:
Bukkit.getWorld(getConfig().getString("path of the world in the config");
Upvotes: 0
Reputation: 2244
I would suggest that instead of
Object locationsworld = this.getConfig().get("locations" + args[0] + ".World");
Location cakestart = new Location((World) locationsworld, locationsX, locationsY, locationsZ, locationsYaw, locationsPitch);
You instead define locationsworld as a string, and then fetch the actual world from the server using it's unique case-sensitive name. Assuming you're in your main class that extends JavaPlugin, it would look like this:
String locationsworld = this.getConfig().get("locations" + args[0] + ".World");
World tworld = this.getServer().getWorld(locationsworld);
Location cakestart = new Location(tworld, locationsX, locationsY, locationsZ, locationsYaw, locationsPitch);
That way you don't have an invalid world. There's a lot more info in the world class that just a name, and unless you're saving all of it instead of just the World.getName();
, you're not going to have much success with a typecast.
EDIT: Afterthought: You would also probably do well to use doubles instead of integers for the other values, especially pitch and yaw.
Upvotes: 1