001/* 002 * PlotSquared, a land and world management plugin for Minecraft. 003 * Copyright (C) IntellectualSites <https://intellectualsites.com> 004 * Copyright (C) IntellectualSites team and contributors 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 018 */ 019package com.plotsquared.core.location; 020 021import net.kyori.adventure.key.Key; 022import net.kyori.adventure.key.Keyed; 023import org.checkerframework.checker.nullness.qual.NonNull; 024import org.jetbrains.annotations.NotNull; 025 026import java.nio.file.Path; 027 028/** 029 * PlotSquared representation of a platform world 030 * 031 * @param <T> Platform world type 032 */ 033public interface World<T> extends Keyed { 034 035 /** 036 * Get a {@link NullWorld} implementation 037 * 038 * @param <T> implementation-specific world object type e.g. a bukkit World 039 * @return NullWorld instance 040 */ 041 static <T> NullWorld<T> nullWorld() { 042 return new NullWorld<>(); 043 } 044 045 /** 046 * Get the platform world represented by this world 047 * 048 * @return Platform world 049 */ 050 @NonNull T getPlatformWorld(); 051 052 /** 053 * Get the name of the world 054 * 055 * @return World name 056 */ 057 @NonNull String getName(); 058 059 /** 060 * Get the min world height. Inclusive. 061 * 062 * @since 6.6.0 063 */ 064 int getMinHeight(); 065 066 067 /** 068 * Get the max world height. Inclusive. 069 * 070 * @since 6.6.0 071 */ 072 int getMaxHeight(); 073 074 /** 075 * Get the path to this worlds' folder (for legacy versions the folder containing the {@code level.dat} file, for newer 076 * versions the namespaced dimension folder). 077 * 078 * @return the path 079 * @since 7.6.0 080 */ 081 @NonNull Path getWorldFolder(); 082 083 class NullWorld<T> implements World<T> { 084 085 private NullWorld() { 086 } 087 088 @NonNull 089 @Override 090 public T getPlatformWorld() { 091 throw new UnsupportedOperationException("Cannot get platform world from NullWorld"); 092 } 093 094 @Override 095 public @NonNull String getName() { 096 return ""; 097 } 098 099 @Override 100 public int getMinHeight() { 101 return 0; 102 } 103 104 @Override 105 public int getMaxHeight() { 106 return 0; 107 } 108 109 @Override 110 public @NonNull Path getWorldFolder() { 111 throw new UnsupportedOperationException("Cannot get world folder from NullWorld"); 112 } 113 114 @Override 115 public @NotNull Key key() { 116 throw new UnsupportedOperationException("Cannot get key from NullWorld"); 117 } 118 119 @Override 120 public boolean equals(final Object obj) { 121 return obj instanceof NullWorld; 122 } 123 124 @Override 125 public int hashCode() { 126 return "null".hashCode(); 127 } 128 129 } 130 131}