Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.EnderBro3D.LocTeleportator;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.logging.Level;
- import org.apache.commons.io.FileUtils;
- 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.YamlConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Loc extends JavaPlugin {
- protected static YamlConfiguration config;
- public static YamlConfiguration getConfig(JavaPlugin pl, String configName) {
- File file = new File(pl.getDataFolder(), configName);
- if (file.isDirectory()) {
- file.delete();
- }
- if (!file.exists()) {
- try (InputStream i = pl.getClass().getClassLoader().getResourceAsStream(configName)) {
- FileUtils.copyInputStreamToFile(i, file);
- } catch (IOException e) {
- pl.getLogger().log(Level.WARNING, "Ошибка при создании файла " + configName);
- }
- return new YamlConfiguration();
- }
- return YamlConfiguration.loadConfiguration(file);
- }
- @Override
- public void onEnable() {
- config = getConfig(this, "config.yml");
- }
- @Override
- public void onDisable() {
- try {
- config.save("config.yml");
- } catch (IOException ex) {
- this.getLogger().log(Level.WARNING, "Ошибка при сохранении конфигов", ex);
- }
- }
- public static boolean isLoc(String loc) {
- if(config.getConfigurationSection("Locations").isConfigurationSection(loc)) {
- return true;
- } else {
- return false;
- }
- }
- @Override
- public boolean onCommand(CommandSender s, Command cmd, String label, String[] args) {
- if(cmd.getName().equalsIgnoreCase("toLoc")) {
- if(args.length < 1) {
- s.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("LocTP.messages.empty")));
- return false;
- }
- if(args.length > 1) {
- s.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("LocTP.messages.syntax_error")));
- return false;
- }
- if(!isLoc(args[0])) {
- s.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("LocTP.messages.notfound")));
- s.sendMessage("\u00a7eLocation list:");
- s.sendMessage("\u00a7c"+config.getList("Locations.locationList").toString());
- return false;
- }
- double x = config.getDouble("Locations." + args[0] + ".x");
- int y = config.getInt("Locations." + args[0] + ".y");
- double z = config.getDouble("Locations." + args[0] + ".z");
- World world = Bukkit.getServer().getWorld(config.getString("Locations." + args[0] + ".world"));
- Location loc = new Location(world, x, y, z);
- Player sender = (Player) s;
- sender.teleport(loc);
- return true;
- }
- if(cmd.getName().equalsIgnoreCase("adminToLoc")) {
- if(!s.hasPermission("toLocation.admin")) {
- s.sendMessage("\u00a7c"+config.getString("LocTP.messages.not_perms"));
- return false;
- }
- if(args.length == 0) {
- s.sendMessage("\u00a76Author: EnderBro3D");
- s.sendMessage("\u00a7n-----------------------------------------");
- s.sendMessage("\u00a7e/adminToLoc create <name> - новая локация");
- s.sendMessage("\u00a7n-----------------------------------------");
- return false;
- }
- if(args[0].equalsIgnoreCase("create")) {
- if(args.length < 2) {
- s.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("LocTP.messages.syntax_error")));
- return false;
- }
- if(config == null) {
- s.sendMessage(">> \u00a7cОшибка с конфигурацией, config = null");
- return false;
- }
- String newLoc = args[1];
- if(config.isConfigurationSection("Locations." + newLoc)) {
- s.sendMessage(">> \u00a7cЛокация уже существует");
- return false;
- }
- Player sender = (Player) s;
- config.set("Locations." + newLoc + ".x", sender.getLocation().getX());
- config.set("Locations." + newLoc + ".y", sender.getLocation().getY());
- config.set("Locations." + newLoc + ".z", sender.getLocation().getZ());
- config.set("Locations." + newLoc + ".world", sender.getLocation().getWorld().toString());
- s.sendMessage(">> \u00a7aЛокация \u00a73" + newLoc + ", \u00a7aуспешно установлена.");
- return true;
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement