Now storing spawn locations in config.yml

This commit is contained in:
Jimmy Allen 2018-07-27 02:27:06 +12:00
parent 1105385d87
commit ba8b380b4d
2 changed files with 28 additions and 6 deletions

View File

@ -55,6 +55,7 @@
<filtering>true</filtering>
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
</includes>
</resource>
<resource>

View File

@ -4,7 +4,8 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.Location;
import org.bukkit.World;
public class EasySpawn extends JavaPlugin{
@Override
@ -12,22 +13,42 @@ public class EasySpawn extends JavaPlugin{
String label, String[] args) {
if(sender instanceof Player){
Player player = (Player)sender;
//Spawn
if(command.getName().equalsIgnoreCase("spawn")){
player.teleport(player.getWorld().getSpawnLocation());
player.sendMessage("You have been teleported to spawn.");
World world = player.getWorld();
String w = world.getName();
if(getConfig().contains("spawn."+w)) {
int x = getConfig().getInt("spawn."+w+".x");
int y = getConfig().getInt("spawn."+w+".y");
int z = getConfig().getInt("spawn."+w+".z");
float pitch = getConfig().getInt("spawn."+w+".pitch");
float yaw = getConfig().getInt("spawn."+w+".yaw");
player.teleport(new Location(world, x, y, z, yaw, pitch));
player.sendMessage("You have been teleported to spawn.");
}
return true;
}
//Setspawn
if(command.getName().equalsIgnoreCase("setspawn")){
player.getWorld().setSpawnLocation(player.getLocation().getBlockX(),
player.getLocation().getBlockY(),player.getLocation().getBlockZ());
Location location = player.getLocation();
String world = player.getWorld().getName();
getConfig().set("spawn."+world+".x", location.getBlockX());
getConfig().set("spawn."+world+".y", location.getBlockY());
getConfig().set("spawn."+world+".z", location.getBlockZ());
getConfig().set("spawn."+world+".pitch", location.getPitch());
getConfig().set("spawn."+world+".yaw", location.getYaw());
player.sendMessage("Spawn set.");
return true;
}
//Bed
if(command.getName().equalsIgnoreCase("bed")){
if(player.getBedSpawnLocation()!=null){
player.teleport(player.getBedSpawnLocation());
player.sendMessage("You have been teleported to your bed.");
}else sender.sendMessage("Your bed cannot be found.");
}else sender.sendMessage("You need to sleep in a bed first.");
return true;
}
}