Advertisement
Guest User

Untitled

a guest
Jul 9th, 2014
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. package me.jlsteelers.LoggerTP;
  2.  
  3. import java.io.File;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.Location;
  8. import org.bukkit.command.Command;
  9. import org.bukkit.command.CommandSender;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.event.EventHandler;
  12. import org.bukkit.event.Listener;
  13. import org.bukkit.event.player.PlayerQuitEvent;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15.  
  16. public class Main extends JavaPlugin implements Listener {
  17.  
  18. public void onEnable() {
  19. getLogger().info("Plugin Enabled");
  20. if(!(new File(getDataFolder(), "config.yml").exists())){
  21. saveDefaultConfig();
  22. getServer().getPluginManager().registerEvents(this, this);
  23. }
  24. }
  25.  
  26. public void onDisable() {
  27. getLogger().info("Plugin Disabled");
  28. }
  29.  
  30. @Override
  31. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  32. Player player = (Player) sender;
  33. if (cmd.getName().equalsIgnoreCase("lastlog")) {
  34. //Check for the arguments length.
  35. // Example: /lastlog [player]
  36. if(args.length == 1){
  37. String target = args[0];
  38.  
  39. if(getConfig().contains(target)){
  40. //Grab all the config values
  41. int x = getConfig().getInt(target + ".x");
  42. int y = getConfig().getInt(target + ".y");
  43. int z = getConfig().getInt(target + ".z");
  44. String world = getConfig().getString(target + ".world");
  45. Location loc = new Location(Bukkit.getWorld(world), x, y, z); //Build the location object
  46.  
  47. player.teleport(loc); //Teleport the player
  48. } else {
  49. player.sendMessage(ChatColor.RED + "That player hasn't played before!");
  50. }
  51. } else {
  52. player.sendMessage(ChatColor.RED + "Usage: /lastlog <player>");
  53. }
  54.  
  55. }
  56. return false;
  57.  
  58. }
  59.  
  60. @EventHandler
  61. public void onPlayerQuit(PlayerQuitEvent event){
  62. Player player = event.getPlayer();
  63. Location loc = player.getLocation();
  64. String name = player.getName();
  65.  
  66. //Set values
  67. getConfig().set(name + ".x", loc.getBlockX());
  68. getConfig().set(name + ".y", loc.getBlockY());
  69. getConfig().set(name + ".z", loc.getBlockZ());
  70. getConfig().set(name + ".world", loc.getWorld().getName());
  71.  
  72. //Save the config
  73. //Nothing will happen without this!
  74. saveConfig();
  75. }
  76.  
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement