Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.lapismc.HomeSpawn;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.logging.Level;
- 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.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.java.JavaPlugin;
- public class HomeSpawn extends JavaPlugin {
- public static HomeSpawn plugin;
- private File configFile;
- private FileConfiguration fileConfiguration;
- private YamlConfiguration Homes = null;
- private File HomesFile = null;
- private YamlConfiguration Spawn = null;
- private File SpawnFile = null;
- @Override
- public void onEnable() {
- Enable();
- Configs();
- }
- @Override
- public void onDisable() {
- Disable();
- }
- public void Enable() {
- Bukkit.getConsoleSender().sendMessage(
- "[HomeSpawn] V." + getDescription().getVersion()
- + " Has Been Enabled!");
- }
- public void Disable() {
- Bukkit.getConsoleSender().sendMessage(
- "[HomeSpawn] Plugin Has Been Disabled!");
- }
- public void Configs() {
- saveDefaultConfig();
- saveConfig();
- saveDefaultHomes();
- saveHomes();
- saveDefaultSpawn();
- saveSpawn();
- }
- @SuppressWarnings("deprecation")
- public void reloadHomes() {
- fileConfiguration = YamlConfiguration.loadConfiguration(configFile);
- InputStream defConfigStream = plugin.getResource("Homes.yml");
- if (defConfigStream != null) {
- YamlConfiguration defConfig = YamlConfiguration
- .loadConfiguration(defConfigStream);
- fileConfiguration.setDefaults(defConfig);
- }
- }
- public void saveDefaultHomes() {
- if (HomesFile == null) {
- plugin.saveResource("Homes.yml", true);
- }
- }
- public void saveHomes() {
- if (Homes == null || HomesFile == null) {
- return;
- }
- try {
- getHomes().save(HomesFile);
- } catch (IOException ex) {
- getLogger().log(Level.SEVERE,
- "Could not save config to " + HomesFile, ex);
- }
- }
- public FileConfiguration getHomes() {
- if (Homes == null) {
- reloadHomes();
- }
- return Homes;
- }
- @SuppressWarnings("deprecation")
- public void reloadSpawn() {
- fileConfiguration = YamlConfiguration.loadConfiguration(configFile);
- InputStream defConfigStream = plugin.getResource("Spawn.yml");
- if (defConfigStream != null) {
- YamlConfiguration defConfig = YamlConfiguration
- .loadConfiguration(defConfigStream);
- fileConfiguration.setDefaults(defConfig);
- }
- }
- public void saveDefaultSpawn() {
- if (SpawnFile == null) {
- plugin.saveResource("Spawn.yml", false);
- }
- }
- public void saveSpawn() {
- if (Homes == null || HomesFile == null) {
- return;
- }
- try {
- getSpawn().save(SpawnFile);
- } catch (IOException ex) {
- getLogger().log(Level.SEVERE,
- "Could not save config to " + HomesFile, ex);
- }
- }
- public FileConfiguration getSpawn() {
- if (Spawn == null) {
- reloadSpawn();
- }
- return Spawn;
- }
- @Override
- public boolean onCommand(CommandSender sender, Command cmd,
- String commandLabel, String[] args) {
- if (sender instanceof Player) {
- Player player = (Player) sender;
- if (commandLabel.equalsIgnoreCase("sethome")) {
- player.sendMessage(ChatColor.GOLD + "Home Set");
- getHomes().set(player.getDisplayName() + ".x",
- player.getLocation().getBlockX());
- getHomes().set(player.getDisplayName() + ".y",
- player.getLocation().getBlockY());
- getHomes().set(player.getDisplayName() + ".z",
- player.getLocation().getBlockZ());
- getHomes().set(player.getDisplayName() + ".world",
- player.getLocation().getWorld());
- getHomes().set(player.getDisplayName() + ".HasHome", "Yes");
- } else if (commandLabel.equalsIgnoreCase("home")) {
- if (getHomes().getString(player.getDisplayName() + ".HasHome")
- == "Yes") {
- int x = getHomes().getInt(player.getDisplayName() + ".x");
- int y = getHomes().getInt(player.getDisplayName() + ".y");
- int z = getHomes().getInt(player.getDisplayName() + ".z");
- String cworld = getHomes().getString(
- player.getDisplayName() + ".world");
- World world = getServer().getWorld(cworld);
- Location home = new Location(world, x, y, z);
- player.sendMessage(ChatColor.GOLD + "Welcome Home");
- player.teleport(home);
- } else {
- player.sendMessage("You First Need To Set a Home With /
- sethome");
- }
- } else if (commandLabel.equalsIgnoreCase("delhome")) {
- if (getHomes().getString(player.getDisplayName() + ".HasHome") == "No"
- || !getHomes().contains(
- player.getDisplayName() + ".HasHome")) {
- player.sendMessage(ChatColor.RED
- + "You Need To Set a Home Before You Can
- Remove One!");
- } else if (getHomes().getString(
- player.getDisplayName() + ".HasHome") == "Yes") {
- player.sendMessage(ChatColor.GOLD + "Home Removed");
- getHomes().set(player.getDisplayName() + ".HasHome", "No");
- }
- } else if (commandLabel.equalsIgnoreCase("setspawn")) {
- player.sendMessage(ChatColor.GOLD + "Spawn Set");
- getSpawn().set("spawn.SpawnSet", "Yes");
- getSpawn().set("spawn.X", player.getLocation().getBlockX());
- getSpawn().set("spawn.Y", player.getLocation().getBlockY());
- getSpawn().set("spawn.Z", player.getLocation().getBlockZ());
- getSpawn().set("spawn.World", player.getWorld());
- } else if (commandLabel.equals("spawn")) {
- if (getSpawn().getString("spawn.SpawnSet") == "Yes") {
- int x = getSpawn().getInt("spawn.X");
- int y = getSpawn().getInt("spawn.Y");
- int z = getSpawn().getInt("spawn.Z");
- String cworld = getSpawn().getString("spawn.World");
- World world = getServer().getWorld(cworld);
- Location Spawn = new Location(world, x, y, z);
- player.sendMessage(ChatColor.GOLD + "Welcome To Spawn");
- player.teleport(Spawn);
- } else {
- player.sendMessage(ChatColor.RED + "The Spawn Isn't Set");
- }
- } else if (commandLabel.equalsIgnoreCase("delspawn")) {
- if (getSpawn().getString("spawn.SpawnSet") == "No"
- || !getSpawn().contains("spawn.SpawnSet")) {
- player.sendMessage(ChatColor.RED
- + "You Must First Set a Spawn Before You Can
- Remove It!");
- } else if (getSpawn().getString("spawn.SpawnSet") == "Yes")
- getSpawn().set("spawn.SpawnSet", "No");
- player.sendMessage(ChatColor.GOLD + "Spawn Removed!");
- }
- } else {
- sender.sendMessage("You Must Be a Player To Do That");
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement