package tk.mwmaksim.mwcoordstp;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
public class MWCoordsTP extends JavaPlugin implements Listener {
public void onEnable() {
getLogger().info("Плагин запускается!");
getServer().getPluginManager().registerEvents(this, (Plugin)this);
getLogger().info("Загрузка конфигурации...");
saveDefaultConfig();
getLogger().info("Конфигурация загружен!");
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("mwctp-reload")) {
if (!sender.hasPermission("mwctp.reload")) {
sender.sendMessage(getConfig().getString("messages.nopermission"));
return false;
}
reloadConfig();
sender.sendMessage("Конфиг перезагружен!");
return true;
}
if (cmd.getName().equalsIgnoreCase("spawn")) {
FileConfiguration config = getConfig();
Player player = (Player) sender;
String esc = config.getString("enable-spawn-command");
if (esc == "true") {
double x = config.getDouble("x");
double y = config.getDouble("y");
double z = config.getDouble("z");
String worldName = config.getString("world");
World world = getServer().getWorld(worldName);
Location location = new Location(world, x, y, z);
player.teleport(location);
player.sendMessage(config.getString("messages.spawn"));
if (config.getString("enable-logs") == "true") {
getLogger().info("Телепортирован " + player.getName() + " в " + worldName + " на (" + x + ", " + y + ", " + z + ")");
}
return true;
}
return false;
}
if (cmd.getName().equalsIgnoreCase("setcoords")) {
if (sender instanceof Player) {
if (!sender.hasPermission("mwctp.set")) {
sender.sendMessage(getConfig().getString("messages.nopermission"));
return false;
}
FileConfiguration config = getConfig();
Player player = (Player) sender;
double X = player.getLocation().getBlockX();
double Y = player.getLocation().getBlockY();
double Z = player.getLocation().getBlockZ();
String world = player.getLocation().getWorld().getName();
config.set("x", X);
config.set("y", Y);
config.set("z", Z);
config.set("world", world);
saveConfig();
player.sendMessage(config.getString("messages.set"));
return true;
}
return false;
}
return false;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
FileConfiguration config = getConfig();
String esoj = config.getString("enable-spawn-on-join");
if (esoj == "true") {
double x = config.getDouble("x");
double y = config.getDouble("y");
double z = config.getDouble("z");
String worldName = config.getString("world");
World world = getServer().getWorld(worldName);
if (world == null) {
getLogger().warning("Мир не найден: " + worldName);
return;
}
Location location = new Location(world, x, y, z);
player.teleport(location);
if (config.getString("enable-logs") == "true") {
getLogger().info("Телепортирован " + player.getName() + " в " + worldName + " на (" + x + ", " + y + ", " + z + ")");
}
}
}
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
if (event.getCause() == EntityDamageEvent.DamageCause.VOID) {
FileConfiguration config = getConfig();
boolean enableVoidTp = config.getBoolean("enable-void-tp");
if (!enableVoidTp) {
return;
}
double x = config.getDouble("x");
double y = config.getDouble("y");
double z = config.getDouble("z");
String worldName = config.getString("world");
World world = getServer().getWorld(worldName);
if (world == null) {
getLogger().warning("Мир не найден: " + worldName);
return;
}
Location location = new Location(world, x, y, z);
player.teleport(location);
if (config.getBoolean("enable-logs")) {
getLogger().info("Телепортирован " + player.getName() + " в " + worldName + " на (" + x + ", " + y + ", " + z + ")");
}
event.setCancelled(true);
}
}
}
}