Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.jlsteelers.LoggerTP;
- import java.io.File;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- 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.PlayerQuitEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin implements Listener {
- public void onEnable() {
- getLogger().info("Plugin Enabled");
- if(!(new File(getDataFolder(), "config.yml").exists())){
- saveDefaultConfig();
- getServer().getPluginManager().registerEvents(this, this);
- }
- }
- public void onDisable() {
- getLogger().info("Plugin Disabled");
- }
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- Player player = (Player) sender;
- if (cmd.getName().equalsIgnoreCase("lastlog")) {
- //Check for the arguments length.
- // Example: /lastlog [player]
- if(args.length == 1){
- String target = args[0];
- if(getConfig().contains(target)){
- //Grab all the config values
- int x = getConfig().getInt(target + ".x");
- int y = getConfig().getInt(target + ".y");
- int z = getConfig().getInt(target + ".z");
- String world = getConfig().getString(target + ".world");
- Location loc = new Location(Bukkit.getWorld(world), x, y, z); //Build the location object
- player.teleport(loc); //Teleport the player
- } else {
- player.sendMessage(ChatColor.RED + "That player hasn't played before!");
- }
- } else {
- player.sendMessage(ChatColor.RED + "Usage: /lastlog <player>");
- }
- }
- return false;
- }
- @EventHandler
- public void onPlayerQuit(PlayerQuitEvent event){
- Player player = event.getPlayer();
- Location loc = player.getLocation();
- String name = player.getName();
- //Set values
- getConfig().set(name + ".x", loc.getBlockX());
- getConfig().set(name + ".y", loc.getBlockY());
- getConfig().set(name + ".z", loc.getBlockZ());
- getConfig().set(name + ".world", loc.getWorld().getName());
- //Save the config
- //Nothing will happen without this!
- saveConfig();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement