From 69a1000d77410db08a9b7014678b9a84156554fe Mon Sep 17 00:00:00 2001 From: Jimmy Allen Date: Fri, 27 Jul 2018 14:10:08 +1200 Subject: [PATCH] When player first joins they will be teleported to the set spawn Changed permission error messages --- .../java/nz/jimmy/easyspawn/EasySpawn.java | 31 +++++++++++++++++-- src/main/resources/plugin.yml | 6 ++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main/java/nz/jimmy/easyspawn/EasySpawn.java b/src/main/java/nz/jimmy/easyspawn/EasySpawn.java index b0dfe73..4c50a2e 100644 --- a/src/main/java/nz/jimmy/easyspawn/EasySpawn.java +++ b/src/main/java/nz/jimmy/easyspawn/EasySpawn.java @@ -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)); + } + } + } + } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8a18c81..98ad750 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -10,17 +10,17 @@ commands: description: Teleports you to spawn usage: /spawn permission: easyspawn.spawn - permission-message: You don't have + 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-message: You are not allowed setspawn: description: Sets spawn location usage: /setspawn permission: easyspawn.setspawn - permission-message: You don't have + permission-message: You are not allowed permissions: easyspawn.spawn: description: Teleports you to spawn