When player first joins they will be teleported to the set spawn
Changed permission error messages
This commit is contained in:
parent
189eb7492a
commit
69a1000d77
|
@ -3,10 +3,17 @@ package nz.jimmy.easyspawn;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
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.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
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
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command,
|
public boolean onCommand(CommandSender sender, Command command,
|
||||||
|
@ -18,6 +25,7 @@ public class EasySpawn extends JavaPlugin{
|
||||||
if(command.getName().equalsIgnoreCase("spawn")){
|
if(command.getName().equalsIgnoreCase("spawn")){
|
||||||
World world = player.getWorld();
|
World world = player.getWorld();
|
||||||
String w = world.getName();
|
String w = world.getName();
|
||||||
|
//Check is spawn is set
|
||||||
if(getConfig().contains("spawn."+w)){
|
if(getConfig().contains("spawn."+w)){
|
||||||
int x = getConfig().getInt("spawn."+w+".x");
|
int x = getConfig().getInt("spawn."+w+".x");
|
||||||
int y = getConfig().getInt("spawn."+w+".y");
|
int y = getConfig().getInt("spawn."+w+".y");
|
||||||
|
@ -26,7 +34,7 @@ public class EasySpawn extends JavaPlugin{
|
||||||
float yaw = getConfig().getInt("spawn."+w+".yaw");
|
float yaw = getConfig().getInt("spawn."+w+".yaw");
|
||||||
player.teleport(new Location(world, x, y, z, yaw, pitch));
|
player.teleport(new Location(world, x, y, z, yaw, pitch));
|
||||||
player.sendMessage("You have been teleported to spawn.");
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +54,7 @@ public class EasySpawn extends JavaPlugin{
|
||||||
|
|
||||||
//Bed
|
//Bed
|
||||||
if(command.getName().equalsIgnoreCase("bed")){
|
if(command.getName().equalsIgnoreCase("bed")){
|
||||||
|
//Check if player has a bed
|
||||||
if(player.getBedSpawnLocation()!=null){
|
if(player.getBedSpawnLocation()!=null){
|
||||||
player.teleport(player.getBedSpawnLocation());
|
player.teleport(player.getBedSpawnLocation());
|
||||||
player.sendMessage("You have been teleported to your bed.");
|
player.sendMessage("You have been teleported to your bed.");
|
||||||
|
@ -56,4 +65,22 @@ public class EasySpawn extends JavaPlugin{
|
||||||
return false;
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,17 +10,17 @@ commands:
|
||||||
description: Teleports you to spawn
|
description: Teleports you to spawn
|
||||||
usage: /spawn
|
usage: /spawn
|
||||||
permission: easyspawn.spawn
|
permission: easyspawn.spawn
|
||||||
permission-message: You don't have <permission>
|
permission-message: You are not allowed
|
||||||
bed:
|
bed:
|
||||||
description: Teleports you to your bed
|
description: Teleports you to your bed
|
||||||
usage: /bed
|
usage: /bed
|
||||||
permission: easyspawn.bed
|
permission: easyspawn.bed
|
||||||
permission-message: You don't have <permission>
|
permission-message: You are not allowed
|
||||||
setspawn:
|
setspawn:
|
||||||
description: Sets spawn location
|
description: Sets spawn location
|
||||||
usage: /setspawn
|
usage: /setspawn
|
||||||
permission: easyspawn.setspawn
|
permission: easyspawn.setspawn
|
||||||
permission-message: You don't have <permission>
|
permission-message: You are not allowed
|
||||||
permissions:
|
permissions:
|
||||||
easyspawn.spawn:
|
easyspawn.spawn:
|
||||||
description: Teleports you to spawn
|
description: Teleports you to spawn
|
||||||
|
|
Loading…
Reference in New Issue