forked from SteamWar/SteamWar
Add DynamicRegionSystem
This commit is contained in:
+88
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.region.dynamic.MovementListener;
|
||||
import de.steamwar.bausystem.region.dynamic.Tile;
|
||||
import de.steamwar.bausystem.region.dynamic.global.DynamicGlobalRegion;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class DynamicRegionSystem implements RegionSystem {
|
||||
|
||||
public static DynamicRegionSystem INSTANCE;
|
||||
|
||||
private static Map<Tile, UUID> tileMap = new HashMap<>();
|
||||
private static Map<UUID, Region> regionMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
INSTANCE = this;
|
||||
Bukkit.getPluginManager().registerEvents(new MovementListener(), BauSystem.getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Location getWorldSpawn() {
|
||||
return new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Region getGlobalRegion() {
|
||||
return DynamicGlobalRegion.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Region get(@NonNull Location location) {
|
||||
Optional<Tile> tile = Tile.fromLocation(location);
|
||||
if (tile.isEmpty()) return DynamicGlobalRegion.INSTANCE;
|
||||
UUID uuid = tileMap.get(tile.get());
|
||||
if (uuid == null) return DynamicGlobalRegion.INSTANCE;
|
||||
Region region = regionMap.get(uuid);
|
||||
if (region == null) return DynamicGlobalRegion.INSTANCE;
|
||||
return region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Region> getRegion(@NonNull UUID id) {
|
||||
return Optional.ofNullable(regionMap.get(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Stream<Region> getRegions() {
|
||||
return regionMap.values().stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModular() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user