Files
src
build.gradle
settings.gradle
Code
10 734
src/main/java/pl/zentrix/rozdzki/ZentrixRozdzki.java
package pl.zentrix.rozdzki;
import java.util.Objects;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.plugin.java.JavaPlugin;
public final class ZentrixRozdzki extends JavaPlugin {
private RodzkaItems items;
private TeleportManager teleportManager;
private Location spawnLocation;
@Override
public void onEnable() {
saveDefaultConfig();
loadSpawnLocation();
items = new RodzkaItems(this);
teleportManager = new TeleportManager(this, items);
RodzkaCommand command = new RodzkaCommand(this, items);
Objects.requireNonNull(getCommand("arozdzka")).setExecutor(command);
Objects.requireNonNull(getCommand("arozdzka")).setTabCompleter(command);
getServer().getPluginManager().registerEvents(new RodzkaListener(this, items, teleportManager), this);
}
@Override
public void onDisable() {
if (teleportManager != null) {
teleportManager.cancelAll();
}
}
public Location getSpawnLocation() {
return spawnLocation == null ? null : spawnLocation.clone();
}
public void setSpawnLocation(Location location) {
spawnLocation = location.clone();
getConfig().set("spawn-location.world", location.getWorld().getName());
getConfig().set("spawn-location.x", location.getX());
getConfig().set("spawn-location.y", location.getY());
getConfig().set("spawn-location.z", location.getZ());
getConfig().set("spawn-location.yaw", location.getYaw());
getConfig().set("spawn-location.pitch", location.getPitch());
saveConfig();
}
public void reloadPluginConfig() {
reloadConfig();
loadSpawnLocation();
}
private void loadSpawnLocation() {
String worldName = getConfig().getString("spawn-location.world");
World world = worldName == null ? null : Bukkit.getWorld(worldName);
if (world == null) {
spawnLocation = null;
return;
}
spawnLocation = new Location(
world,
getConfig().getDouble("spawn-location.x", 202.0),
getConfig().getDouble("spawn-location.y", 66.0),
getConfig().getDouble("spawn-location.z", -17.0),
(float) getConfig().getDouble("spawn-location.yaw", 90.0),
(float) getConfig().getDouble("spawn-location.pitch", 0.0));
}
}