diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..98b7f15 --- /dev/null +++ b/.classpath @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..a2bc9d6 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + EasySpawn + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..cf6931b --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.apt.core.prefs b/.settings/org.eclipse.jdt.apt.core.prefs new file mode 100644 index 0000000..ec0c557 --- /dev/null +++ b/.settings/org.eclipse.jdt.apt.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.apt.aptEnabled=false diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..e34d462 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.processAnnotations=disabled +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..14b697b --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/pom.xml b/pom.xml index d544e6a..3a07345 100644 --- a/pom.xml +++ b/pom.xml @@ -55,6 +55,7 @@ true plugin.yml + config.yml @@ -81,31 +82,3 @@ - - - - - - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - - - - org.spigotmc - spigot-api - 1.13-R0.1-SNAPSHOT - provided - - - - org.bukkit - bukkit - 1.13-R0.1-SNAPSHOT - provided - - \ No newline at end of file diff --git a/server.properties b/server.properties deleted file mode 100644 index 3533037..0000000 --- a/server.properties +++ /dev/null @@ -1,2 +0,0 @@ -#Minecraft server properties -#Thu Jul 26 07:47:14 GMT 2018 diff --git a/src/main/java/nz/1248/easyspawn/EasySpawn.java b/src/main/java/nz/1248/easyspawn/EasySpawn.java deleted file mode 100644 index 5394de4..0000000 --- a/src/main/java/nz/1248/easyspawn/EasySpawn.java +++ /dev/null @@ -1,37 +0,0 @@ -package nz.jimmy.easyspawn; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -public class EasySpawn extends JavaPlugin{ - - @Override - public boolean onCommand(CommandSender sender, Command command, - String label, String[] args) { - if(sender instanceof Player){ - Player player = (Player)sender; - if(command.getName().equalsIgnoreCase("spawn")){ - player.teleport(player.getWorld().getSpawnLocation()); - player.sendMessage("You have been teleported to spawn."); - return true; - } - if(command.getName().equalsIgnoreCase("setspawn")){ - player.getWorld().setSpawnLocation(player.getLocation().getBlockX(), - player.getLocation().getBlockY(),player.getLocation().getBlockZ()); - player.sendMessage("Spawn set."); - return true; - } - 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."); - return true; - } - } - return false; - } - -} diff --git a/src/main/java/nz/jimmy/easyspawn/Bed.java b/src/main/java/nz/jimmy/easyspawn/Bed.java new file mode 100644 index 0000000..3c09e27 --- /dev/null +++ b/src/main/java/nz/jimmy/easyspawn/Bed.java @@ -0,0 +1,33 @@ +package nz.jimmy.easyspawn; + +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.Configuration; +import org.bukkit.entity.Player; + +/** + * Bed + */ +public class Bed implements CommandExecutor { + EasySpawn plugin; + public Bed(EasySpawn plugin) { + this.plugin = plugin; + plugin.getCommand("bed").setExecutor(this); + } + + public boolean onCommand(CommandSender sender, Command cmd, String label, + String[] args) { + if(sender instanceof Player) { + Player player = (Player)sender; + //Check if player has a bed + if(player.getBedSpawnLocation()!=null){ + player.teleport(player.getBedSpawnLocation()); + player.sendMessage("You have been teleported to your bed."); + }else sender.sendMessage("You need to sleep in a bed first."); + return true; + } + return false; + } +} \ No newline at end of file diff --git a/src/main/java/nz/jimmy/easyspawn/EasySpawn.java b/src/main/java/nz/jimmy/easyspawn/EasySpawn.java new file mode 100644 index 0000000..8d506e1 --- /dev/null +++ b/src/main/java/nz/jimmy/easyspawn/EasySpawn.java @@ -0,0 +1,13 @@ +package nz.jimmy.easyspawn; + +import org.bukkit.plugin.java.JavaPlugin; + +public class EasySpawn extends JavaPlugin { + @Override + public void onEnable(){ + new PlayerListener(this); + new SetSpawn(this); + new Spawn(this); + new Bed(this); + } +} diff --git a/src/main/java/nz/jimmy/easyspawn/PlayerListener.java b/src/main/java/nz/jimmy/easyspawn/PlayerListener.java new file mode 100644 index 0000000..55ab199 --- /dev/null +++ b/src/main/java/nz/jimmy/easyspawn/PlayerListener.java @@ -0,0 +1,42 @@ +package nz.jimmy.easyspawn; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + + +/** + * PlayerListener + */ +public class PlayerListener implements Listener{ + EasySpawn plugin; + public PlayerListener(EasySpawn plugin) { + this.plugin = plugin; + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + if(!player.hasPlayedBefore()){ + World world = player.getWorld(); + String w = world.getName(); + FileConfiguration config = plugin.getConfig(); + //Check is spawn is set + if(config.contains("spawn."+w)){ + int x = config.getInt("spawn."+w+".x"); + int y = config.getInt("spawn."+w+".y"); + int z = config.getInt("spawn."+w+".z"); + float pitch = config.getInt("spawn."+w+".pitch"); + float yaw = config.getInt("spawn."+w+".yaw"); + player.teleport(new Location(world, x, y, z, yaw, pitch)); + } + } + } + +} + diff --git a/src/main/java/nz/jimmy/easyspawn/SetSpawn.java b/src/main/java/nz/jimmy/easyspawn/SetSpawn.java new file mode 100644 index 0000000..657d03a --- /dev/null +++ b/src/main/java/nz/jimmy/easyspawn/SetSpawn.java @@ -0,0 +1,38 @@ +package nz.jimmy.easyspawn; + +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.Configuration; +import org.bukkit.entity.Player; + +/** + * SetSpawn + */ +public class SetSpawn implements CommandExecutor{ + EasySpawn plugin; + public SetSpawn(EasySpawn plugin) { + this.plugin = plugin; + plugin.getCommand("setspawn").setExecutor(this); + } + + public boolean onCommand(CommandSender sender, Command cmd, String label, + String[] args) { + if( sender instanceof Player) { + Player player = (Player)sender; + Location location = player.getLocation(); + String world = player.getWorld().getName(); + Configuration config = plugin.getConfig(); + config.set("spawn."+world+".x", location.getBlockX()); + config.set("spawn."+world+".y", location.getBlockY()); + config.set("spawn."+world+".z", location.getBlockZ()); + config.set("spawn."+world+".pitch", location.getPitch()); + config.set("spawn."+world+".yaw", location.getYaw()); + plugin.saveConfig(); + player.sendMessage("Spawn set."); + return true; + } + return false; + } +} \ No newline at end of file diff --git a/src/main/java/nz/jimmy/easyspawn/Spawn.java b/src/main/java/nz/jimmy/easyspawn/Spawn.java new file mode 100644 index 0000000..dc6d323 --- /dev/null +++ b/src/main/java/nz/jimmy/easyspawn/Spawn.java @@ -0,0 +1,39 @@ +package nz.jimmy.easyspawn; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.Configuration; +import org.bukkit.entity.Player; + +/** + * Spawn + */ +public class Spawn implements CommandExecutor{ + private EasySpawn plugin; + public Spawn(EasySpawn plugin) { + this.plugin = plugin; + plugin.getCommand("spawn").setExecutor(this);; + } + + public boolean onCommand(CommandSender sender, Command cmd, String label, + String[] args) { + if(sender instanceof Player) { + Player player = (Player)sender; + Configuration config = plugin.getConfig(); + World world = player.getWorld(); + String w = world.getName(); + if(config.contains("spawn."+w)){ + Location location = new Location(world, config.getInt("spawn."+w+".x"), + config.getInt("spawn."+w+".y"),config.getInt("spawn."+w+".z"), + config.getInt("spawn."+w+".pitch"), config.getInt("spawn."+w+".yaw")); + player.teleport(location); + player.sendMessage("You have been teleported to spawn."); + }else player.sendMessage("This world has no spawn"); + return true; + } + return false; + } +} \ No newline at end of file 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