Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.pluginpack;
- import java.io.File;
- import java.io.IOException;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- 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.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.java.JavaPlugin;
- public class homeMain
- extends JavaPlugin
- implements CommandExecutor
- {
- mainClass plugin;
- public homeMain(mainClass passedPlugin)
- {
- this.plugin = passedPlugin;
- }
- private File homesFile = new File(getDataFolder(), "me.kapsel.yml");
- private YamlConfiguration homes = YamlConfiguration.loadConfiguration(this.homesFile);
- public void onDisable()
- {
- saveHomesFile();
- }
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- Player player = (Player)sender;
- String prefixSet = ChatColor.BLUE + "Set Home > " + ChatColor.GRAY;
- String prefixHome = ChatColor.BLUE + "Home > " + ChatColor.GRAY;
- if (command.getName().equalsIgnoreCase("sethome"))
- {
- if (!player.hasPermission("home.sethome"))
- {
- player.sendMessage(prefixSet + ChatColor.RED + "You need permission to perform this command!");
- return false;
- }
- double x = player.getLocation().getX();
- double y = player.getLocation().getY();
- double z = player.getLocation().getZ();
- float yaw = player.getLocation().getYaw();
- float pitch = player.getLocation().getPitch();
- String worldName = player.getWorld().getName();
- this.homes.set("Homes." + player.getUniqueId().toString() + ".X", Double.valueOf(x));
- this.homes.set("Homes." + player.getUniqueId().toString() + ".Y", Double.valueOf(y));
- this.homes.set("Homes." + player.getUniqueId().toString() + ".Z", Double.valueOf(z));
- this.homes.set("Homes." + player.getUniqueId().toString() + ".Yaw", Float.valueOf(yaw));
- this.homes.set("Homes." + player.getUniqueId().toString() + ".Pitch", Float.valueOf(pitch));
- this.homes.set("Homes." + player.getUniqueId().toString() + ".World", worldName);
- saveHomesFile();
- player.sendMessage(prefixSet + "You have successfully set your new home!");
- return false;
- }
- if (command.getName().equalsIgnoreCase("home"))
- {
- if (!player.hasPermission("home.home"))
- {
- player.sendMessage(prefixHome + ChatColor.RED + "You need permission to perform this command!");
- return false;
- }
- double existCheck = (float)this.homes.getLong("Homes." + player.getUniqueId().toString() + ".Yaw");
- if (existCheck != 0) {
- double x = this.homes.getDouble("Homes." + player.getUniqueId().toString() + ".X");
- double y = this.homes.getDouble("Homes." + player.getUniqueId().toString() + ".Y");
- double z = this.homes.getDouble("Homes." + player.getUniqueId().toString() + ".Z");
- float yaw = (float)this.homes.getLong("Homes." + player.getUniqueId().toString() + ".Yaw");
- float pitch = (float)this.homes.getLong("Homes." + player.getUniqueId().toString() + ".Pitch");
- World world = Bukkit.getWorld(this.homes.getString("Homes." + player.getUniqueId().toString() + ".World"));
- Location home = new Location(world, x, y, z, yaw, pitch);
- player.teleport(home);
- player.sendMessage(prefixHome + "You have been sent to your home!");
- return false;
- }
- else {
- player.sendMessage(prefixHome + "You don't have set home!");
- return false;
- }
- }
- return false;
- }
- private void saveHomesFile()
- {
- try
- {
- this.homes.save(this.homesFile);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment