Files
src
build.gradle
Code
8 310
src/main/java/com/spawn/SpawnTeleporter.java
package com.spawn;
import com.spawn.commands.SpawnCommand;
import com.spawn.commands.UstawSpawnCommand;
import com.spawn.listeners.PlayerMoveListener;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class SpawnTeleporter extends JavaPlugin {
private final Map<UUID, BukkitTask> pendingTeleports = new HashMap<>();
private Location spawnLocation;
private ConfigManager configManager;
@Override
public void onEnable() {
saveDefaultConfig();
configManager = new ConfigManager(this);
spawnLocation = configManager.loadSpawnLocation();
getCommand("ustawspawn").setExecutor(new UstawSpawnCommand(this));
getCommand("spawn").setExecutor(new SpawnCommand(this));
getServer().getPluginManager().registerEvents(new PlayerMoveListener(this), this);
getLogger().info("SpawnTeleporter włączony!");
}
@Override
public void onDisable() {
cancelAllTeleports();
getLogger().info("SpawnTeleporter wyłączony!");
}
public Location getSpawnLocation() {
return spawnLocation;
}
public void setSpawnLocation(Location location) {
this.spawnLocation = location;
configManager.saveSpawnLocation(location);
}
public boolean hasPendingTeleport(UUID uuid) {
return pendingTeleports.containsKey(uuid);
}
public void addPendingTeleport(UUID uuid, BukkitTask task) {
pendingTeleports.put(uuid, task);
}
public void cancelTeleport(UUID uuid) {
BukkitTask task = pendingTeleports.remove(uuid);
if (task != null) {
task.cancel();
}
}
private void cancelAllTeleports() {
for (BukkitTask task : pendingTeleports.values()) {
task.cancel();
}
pendingTeleports.clear();
}
public String color(String message) {
return message.replace('&', '§');
}
public String getMessage(String path) {
return color(getConfig().getString("messages." + path, "&cBrak wiadomości: " + path));
}
public int getTeleportDelay() {
return getConfig().getInt("teleport-delay", 5);
}
}