When player first joins they will be teleported to the set spawn

Changed permission error messages
This commit is contained in:
Jimmy Allen 2018-07-27 14:10:08 +12:00
parent 189eb7492a
commit 69a1000d77
2 changed files with 32 additions and 5 deletions

View File

@ -3,10 +3,17 @@ package nz.jimmy.easyspawn;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.Location;
import org.bukkit.World;
public class EasySpawn extends JavaPlugin{
public class EasySpawn extends JavaPlugin implements Listener{
@Override
public void onEnable(){
getServer().getPluginManager().registerEvents(this, this);
}
@Override
public boolean onCommand(CommandSender sender, Command command,
@ -18,6 +25,7 @@ public class EasySpawn extends JavaPlugin{
if(command.getName().equalsIgnoreCase("spawn")){
World world = player.getWorld();
String w = world.getName();
//Check is spawn is set
if(getConfig().contains("spawn."+w)){
int x = getConfig().getInt("spawn."+w+".x");
int y = getConfig().getInt("spawn."+w+".y");
@ -26,7 +34,7 @@ public class EasySpawn extends JavaPlugin{
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.");
}else{ player.sendMessage("This world has no spawn");}
}else player.sendMessage("This world has no spawn");
return true;
}
@ -46,6 +54,7 @@ public class EasySpawn extends JavaPlugin{
//Bed
if(command.getName().equalsIgnoreCase("bed")){
//Check if player has a bed
if(player.getBedSpawnLocation()!=null){
player.teleport(player.getBedSpawnLocation());
player.sendMessage("You have been teleported to your bed.");
@ -56,4 +65,22 @@ public class EasySpawn extends JavaPlugin{
return false;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if(!player.hasPlayedBefore()){
World world = player.getWorld();
String w = world.getName();
//Check is spawn is set
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));
}
}
}
}

View File

@ -10,17 +10,17 @@ commands:
description: Teleports you to spawn
usage: /spawn
permission: easyspawn.spawn
permission-message: You don't have <permission>
permission-message: You are not allowed
bed:
description: Teleports you to your bed
usage: /bed
permission: easyspawn.bed
permission-message: You don't have <permission>
permission-message: You are not allowed
setspawn:
description: Sets spawn location
usage: /setspawn
permission: easyspawn.setspawn
permission-message: You don't have <permission>
permission-message: You are not allowed
permissions:
easyspawn.spawn:
description: Teleports you to spawn