001package net.tnemc.plugincore.paper.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 * PaperWorldProvider
028 *
029 * @author creatorfromhell
030 * @since 1.1.0.1
031 */
032public class PaperWorldProvider implements WorldProvider {
033
034  private final World world;
035
036  public PaperWorldProvider(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    return world.getMoonPhase().name();
084  }
085
086  /**
087   * Retrieves the current weather conditions.
088   *
089   * @return a string representing the current weather conditions.
090   */
091  @Override
092  public @NotNull String weather() {
093
094    if(world.isThundering()) {
095      return "THUNDER";
096    }
097
098    if(world.hasStorm()) {
099      return "DOWNFALL";
100    }
101
102    return "CLEAR";
103  }
104
105  /**
106   * Retrieves the current world time.
107   *
108   * @return the current world time as a long value.
109   */
110  @Override
111  public long worldTime() {
112
113    return world.getTime();
114  }
115
116  /**
117   * Returns the current game time.
118   *
119   * @return the current game time as a long value.
120   */
121  @Override
122  public long gameTime() {
123
124    return world.getGameTime();
125  }
126
127  /**
128   * Retrieves a ChunkProvider object based on the provided coordinates.
129   *
130   * @param x The x-coordinate for the ChunkProvider.
131   * @param y The y-coordinate for the ChunkProvider.
132   * @param z The z-coordinate for the ChunkProvider.
133   *
134   * @return A ChunkProvider object that handles chunk-related operations for the specified
135   * coordinates.
136   */
137  @Override
138  public ChunkProvider chunkProvider(final int x, final int y, final int z) {
139
140    return new PaperChunkProvider(world.getChunkAt(x, z), y);
141  }
142}