2020-07-10 12:21:29 +02:00
|
|
|
/*
|
|
|
|
* _____ _ _ _____ _
|
|
|
|
* | __ \| | | | / ____| | |
|
|
|
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
|
|
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
|
|
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
|
|
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
|
|
|
* | |
|
|
|
|
* |_|
|
|
|
|
* PlotSquared plot management system for Minecraft
|
2021-01-01 00:19:45 +01:00
|
|
|
* Copyright (C) 2021 IntellectualSites
|
2020-07-10 12:21:29 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-08-15 14:59:29 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-07-10 12:21:29 +02:00
|
|
|
*/
|
|
|
|
package com.plotsquared.bukkit.util;
|
|
|
|
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
import com.plotsquared.core.location.World;
|
|
|
|
import org.bukkit.Bukkit;
|
2021-01-09 22:28:41 +01:00
|
|
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
2020-07-10 12:21:29 +02:00
|
|
|
|
|
|
|
import java.util.Map;
|
2020-07-17 17:24:45 +02:00
|
|
|
import java.util.Objects;
|
2020-07-10 12:21:29 +02:00
|
|
|
|
2020-07-17 17:24:45 +02:00
|
|
|
public class BukkitWorld implements World<org.bukkit.World> {
|
2020-07-10 12:21:29 +02:00
|
|
|
|
|
|
|
private static final Map<String, BukkitWorld> worldMap = Maps.newHashMap();
|
|
|
|
|
|
|
|
private final org.bukkit.World world;
|
|
|
|
|
2020-07-14 18:49:40 +02:00
|
|
|
private BukkitWorld(final org.bukkit.World world) {
|
2020-07-10 12:21:29 +02:00
|
|
|
this.world = world;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a new {@link BukkitWorld} from a world name
|
|
|
|
*
|
|
|
|
* @param worldName World name
|
|
|
|
* @return World instance
|
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public @NonNull static BukkitWorld of(final @NonNull String worldName) {
|
2020-07-10 12:21:29 +02:00
|
|
|
final org.bukkit.World bukkitWorld = Bukkit.getWorld(worldName);
|
|
|
|
if (bukkitWorld == null) {
|
|
|
|
throw new IllegalArgumentException(String.format("There is no world with the name '%s'", worldName));
|
|
|
|
}
|
|
|
|
return of(bukkitWorld);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a new {@link BukkitWorld} from a Bukkit world
|
|
|
|
*
|
|
|
|
* @param world Bukkit world
|
|
|
|
* @return World instance
|
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public @NonNull static BukkitWorld of(final org.bukkit.World world) {
|
2020-07-10 12:21:29 +02:00
|
|
|
BukkitWorld bukkitWorld = worldMap.get(world.getName());
|
|
|
|
if (bukkitWorld != null && bukkitWorld.getPlatformWorld().equals(world)) {
|
|
|
|
return bukkitWorld;
|
|
|
|
}
|
|
|
|
bukkitWorld = new BukkitWorld(world);
|
|
|
|
worldMap.put(world.getName(), bukkitWorld);
|
|
|
|
return bukkitWorld;
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public org.bukkit.World getPlatformWorld() {
|
2020-07-10 12:21:29 +02:00
|
|
|
return this.world;
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public @NonNull String getName() {
|
2020-07-10 12:21:29 +02:00
|
|
|
return this.world.getName();
|
|
|
|
}
|
|
|
|
|
2020-07-17 17:24:45 +02:00
|
|
|
public boolean equals(final Object o) {
|
|
|
|
if (o == this) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!(o instanceof BukkitWorld)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final BukkitWorld other = (BukkitWorld) o;
|
|
|
|
if (!other.canEqual(this)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!Objects.equals(this.world, other.world)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean canEqual(final Object other) {
|
|
|
|
return other instanceof BukkitWorld;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int hashCode() {
|
|
|
|
final int PRIME = 59;
|
|
|
|
int result = 1;
|
|
|
|
final Object $world = this.world;
|
|
|
|
result = result * PRIME + ($world == null ? 43 : $world.hashCode());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String toString() {
|
|
|
|
return "BukkitWorld(world=" + this.world + ")";
|
|
|
|
}
|
2021-01-09 22:28:41 +01:00
|
|
|
|
2020-07-10 12:21:29 +02:00
|
|
|
}
|