001package net.tnemc.plugincore.bukkit.impl; 002/* 003 * The New Plugin Core 004 * Copyright (C) 2022 - 2025 Daniel "creatorfromhell" Vidmar 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU Affero 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 Affero General Public License for more details. 015 * 016 * You should have received a copy of the GNU Affero General Public License 017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 018 */ 019 020import net.tnemc.plugincore.core.compatibility.ChunkProvider; 021import net.tnemc.plugincore.core.compatibility.Location; 022import net.tnemc.plugincore.core.compatibility.WorldProvider; 023import org.bukkit.World; 024import org.jetbrains.annotations.NotNull; 025 026/** 027 * BukkitWorldProvider 028 * 029 * @author creatorfromhell 030 * @since 1.1.0.1 031 */ 032public class BukkitWorldProvider implements WorldProvider { 033 034 private final World world; 035 036 public BukkitWorldProvider(final World world) { 037 this.world = world; 038 } 039 040 /** 041 * Returns the name associated with this object. 042 * 043 * @return a string representing the name. 044 */ 045 @Override 046 public @NotNull String name() { 047 048 return world.getName(); 049 } 050 051 /** 052 * Returns the dimension of the world provider. 053 * 054 * @return a string representing the dimension of the world provider. 055 */ 056 @Override 057 public @NotNull String dimension() { 058 059 return world.getEnvironment().name(); 060 } 061 062 /** 063 * Retrieves the spawn location. 064 * 065 * @return a Location object representing the spawn location. 066 */ 067 @Override 068 public @NotNull Location spawn() { 069 070 final org.bukkit.Location spawn = world.getSpawnLocation(); 071 072 return new Location(name(), spawn.getX(), spawn.getY(), spawn.getZ()); 073 } 074 075 /** 076 * Retrieves the phase of the moon. 077 * 078 * @return a string representing the phase of the moon. 079 */ 080 @Override 081 public @NotNull String moonPhase() { 082 083 //Spigot doesn't have an API to get the moon phase 084 return "FULL"; 085 } 086 087 /** 088 * Retrieves the current weather conditions. 089 * 090 * @return a string representing the current weather conditions. 091 */ 092 @Override 093 public @NotNull String weather() { 094 095 if(world.isThundering()) { 096 return "THUNDER"; 097 } 098 099 if(world.hasStorm()) { 100 return "DOWNFALL"; 101 } 102 103 return "CLEAR"; 104 } 105 106 /** 107 * Retrieves the current world time. 108 * 109 * @return the current world time as a long value. 110 */ 111 @Override 112 public long worldTime() { 113 114 return world.getTime(); 115 } 116 117 /** 118 * Returns the current game time. 119 * 120 * @return the current game time as a long value. 121 */ 122 @Override 123 public long gameTime() { 124 125 return world.getGameTime(); 126 } 127 128 /** 129 * Retrieves a ChunkProvider object based on the provided coordinates. 130 * 131 * @param x The x-coordinate for the ChunkProvider. 132 * @param y The y-coordinate for the ChunkProvider. 133 * @param z The z-coordinate for the ChunkProvider. 134 * 135 * @return A ChunkProvider object that handles chunk-related operations for the specified 136 * coordinates. 137 */ 138 @Override 139 public ChunkProvider chunkProvider(final int x, final int y, final int z) { 140 141 return new BukkitChunkProvider(world.getChunkAt(x, z), y); 142 } 143}