2020-04-29 20:01:53 +00:00
|
|
|
/*
|
2022-01-01 19:03:05 +00:00
|
|
|
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
2020-04-29 20:01:53 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2020-04-29 20:01:53 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2020-04-29 20:01:53 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
2020-04-29 20:01:53 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
2020-04-29 20:01:53 +00:00
|
|
|
*/
|
|
|
|
|
2021-11-20 23:29:46 +00:00
|
|
|
package org.geysermc.geyser.level;
|
2020-04-29 20:01:53 +00:00
|
|
|
|
2020-08-08 22:41:12 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
|
|
|
import com.github.steveice10.mc.protocol.data.game.setting.Difficulty;
|
2022-12-18 02:05:41 +00:00
|
|
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
2020-05-23 23:26:20 +00:00
|
|
|
import com.nukkitx.math.vector.Vector3i;
|
2020-12-28 05:29:27 +00:00
|
|
|
import com.nukkitx.nbt.NbtMap;
|
2021-11-22 19:52:26 +00:00
|
|
|
import org.geysermc.geyser.session.GeyserSession;
|
2022-12-18 02:05:41 +00:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2020-04-29 20:01:53 +00:00
|
|
|
|
2022-12-18 02:05:41 +00:00
|
|
|
import javax.annotation.Nonnull;
|
2022-12-02 19:11:56 +00:00
|
|
|
import java.util.Locale;
|
2022-12-18 02:05:41 +00:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
2022-12-02 19:11:56 +00:00
|
|
|
|
2020-04-29 20:01:53 +00:00
|
|
|
/**
|
|
|
|
* Class that manages or retrieves various information
|
|
|
|
* from the world. Everything in this class should be
|
|
|
|
* safe to return null or an empty value in the event
|
|
|
|
* that chunk caching or anything of the sort is disabled
|
|
|
|
* on the standalone version of Geyser.
|
|
|
|
*/
|
|
|
|
public abstract class WorldManager {
|
|
|
|
|
2020-05-23 23:26:20 +00:00
|
|
|
/**
|
2020-11-17 17:03:12 +00:00
|
|
|
* Gets the Java block state at the specified location
|
2020-05-23 23:26:20 +00:00
|
|
|
*
|
|
|
|
* @param session the session
|
|
|
|
* @param vector the position
|
|
|
|
* @return the block state at the specified location
|
|
|
|
*/
|
2022-05-25 23:17:49 +00:00
|
|
|
public final int getBlockAt(GeyserSession session, Vector3i vector) {
|
2020-05-23 23:26:20 +00:00
|
|
|
return this.getBlockAt(session, vector.getX(), vector.getY(), vector.getZ());
|
|
|
|
}
|
|
|
|
|
2020-04-29 20:01:53 +00:00
|
|
|
/**
|
2020-11-17 17:03:12 +00:00
|
|
|
* Gets the Java block state at the specified location
|
2020-04-29 20:01:53 +00:00
|
|
|
*
|
|
|
|
* @param session the session
|
|
|
|
* @param x the x coordinate to get the block at
|
|
|
|
* @param y the y coordinate to get the block at
|
|
|
|
* @param z the z coordinate to get the block at
|
|
|
|
* @return the block state at the specified location
|
|
|
|
*/
|
2021-11-22 19:52:26 +00:00
|
|
|
public abstract int getBlockAt(GeyserSession session, int x, int y, int z);
|
2020-08-08 22:41:12 +00:00
|
|
|
|
2020-10-15 06:30:25 +00:00
|
|
|
/**
|
2021-03-14 16:26:47 +00:00
|
|
|
* Checks whether or not this world manager requires a separate chunk cache/has access to more block data than the chunk cache.
|
2020-10-15 06:30:25 +00:00
|
|
|
* <p>
|
|
|
|
* Some world managers (e.g. Spigot) can provide access to block data outside of the chunk cache, and even with chunk caching disabled. This
|
|
|
|
* method provides a means to check if this manager has this capability.
|
|
|
|
*
|
|
|
|
* @return whether or not this world manager has access to more block data than the chunk cache
|
|
|
|
*/
|
2021-03-14 16:26:47 +00:00
|
|
|
public abstract boolean hasOwnChunkCache();
|
2020-10-15 06:30:25 +00:00
|
|
|
|
2020-12-28 05:29:27 +00:00
|
|
|
/**
|
|
|
|
* Sigh. <br>
|
|
|
|
*
|
|
|
|
* So, on Java Edition, the lectern is an inventory. Java opens it and gets the contents of the book there.
|
|
|
|
* On Bedrock, the lectern contents are part of the block entity tag. Therefore, Bedrock expects to have the contents
|
|
|
|
* of the lectern ready and present in the world. If the contents are not there, it takes at least two clicks for the
|
|
|
|
* lectern to update the tag and then present itself. <br>
|
|
|
|
*
|
|
|
|
* We solve this problem by querying all loaded lecterns, where possible, and sending their information in a block entity
|
|
|
|
* tag.
|
|
|
|
*
|
|
|
|
* @param session the session of the player
|
|
|
|
* @param x the x coordinate of the lectern
|
|
|
|
* @param y the y coordinate of the lectern
|
|
|
|
* @param z the z coordinate of the lectern
|
|
|
|
* @param isChunkLoad if this is called during a chunk load or not. Changes behavior in certain instances.
|
|
|
|
* @return the Bedrock lectern block entity tag. This may not be the exact block entity tag - for example, Spigot's
|
|
|
|
* block handled must be done on the server thread, so we send the tag manually there.
|
|
|
|
*/
|
2021-11-22 19:52:26 +00:00
|
|
|
public abstract NbtMap getLecternDataAt(GeyserSession session, int x, int y, int z, boolean isChunkLoad);
|
2020-12-28 05:29:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return whether we should expect lectern data to update, or if we have to fall back on a workaround.
|
|
|
|
*/
|
|
|
|
public abstract boolean shouldExpectLecternHandled();
|
|
|
|
|
2020-08-08 22:41:12 +00:00
|
|
|
/**
|
|
|
|
* Updates a gamerule value on the Java server
|
|
|
|
*
|
|
|
|
* @param session The session of the user that requested the change
|
|
|
|
* @param name The gamerule to change
|
|
|
|
* @param value The new value for the gamerule
|
|
|
|
*/
|
2022-12-02 19:11:56 +00:00
|
|
|
public void setGameRule(GeyserSession session, String name, Object value) {
|
|
|
|
session.sendCommand("gamerule " + name + " " + value);
|
|
|
|
}
|
2020-08-08 22:41:12 +00:00
|
|
|
|
|
|
|
/**
|
2020-11-17 17:03:12 +00:00
|
|
|
* Gets a gamerule value as a boolean
|
2020-08-08 22:41:12 +00:00
|
|
|
*
|
|
|
|
* @param session The session of the user that requested the value
|
|
|
|
* @param gameRule The gamerule to fetch the value of
|
|
|
|
* @return The boolean representation of the value
|
|
|
|
*/
|
2022-12-02 19:11:56 +00:00
|
|
|
public abstract boolean getGameRuleBool(GeyserSession session, GameRule gameRule);
|
2020-08-08 22:41:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a gamerule value as an integer
|
|
|
|
*
|
|
|
|
* @param session The session of the user that requested the value
|
|
|
|
* @param gameRule The gamerule to fetch the value of
|
|
|
|
* @return The integer representation of the value
|
|
|
|
*/
|
2021-11-22 19:52:26 +00:00
|
|
|
public abstract int getGameRuleInt(GeyserSession session, GameRule gameRule);
|
2020-08-08 22:41:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the game mode of the given session
|
|
|
|
*
|
|
|
|
* @param session The session of the player to change the game mode of
|
|
|
|
* @param gameMode The game mode to change the player to
|
|
|
|
*/
|
2022-12-02 19:11:56 +00:00
|
|
|
public void setPlayerGameMode(GeyserSession session, GameMode gameMode) {
|
|
|
|
session.sendCommand("gamemode " + gameMode.name().toLowerCase(Locale.ROOT));
|
|
|
|
}
|
2020-08-08 22:41:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the difficulty of the Java server
|
|
|
|
*
|
|
|
|
* @param session The session of the user that requested the change
|
|
|
|
* @param difficulty The difficulty to change to
|
|
|
|
*/
|
2022-12-02 19:11:56 +00:00
|
|
|
public void setDifficulty(GeyserSession session, Difficulty difficulty) {
|
|
|
|
session.sendCommand("difficulty " + difficulty.name().toLowerCase(Locale.ROOT));
|
|
|
|
}
|
2020-08-08 22:41:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given session's player has a permission
|
|
|
|
*
|
|
|
|
* @param session The session of the player to check the permission of
|
|
|
|
* @param permission The permission node to check
|
|
|
|
* @return True if the player has the requested permission, false if not
|
|
|
|
*/
|
2021-11-22 19:52:26 +00:00
|
|
|
public abstract boolean hasPermission(GeyserSession session, String permission);
|
2022-12-13 18:53:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of biome identifiers available on the server.
|
|
|
|
*/
|
|
|
|
@Nullable
|
|
|
|
public String[] getBiomeIdentifiers(boolean withTags) {
|
|
|
|
return null;
|
|
|
|
}
|
2022-12-18 02:05:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used for pick block, so we don't need to cache more data than necessary.
|
|
|
|
*
|
|
|
|
* @return expected NBT for this item.
|
|
|
|
*/
|
|
|
|
@Nonnull
|
|
|
|
public CompletableFuture<@Nullable CompoundTag> getPickItemNbt(GeyserSession session, int x, int y, int z, boolean addNbtData) {
|
|
|
|
return CompletableFuture.completedFuture(null);
|
|
|
|
}
|
2020-04-29 20:01:53 +00:00
|
|
|
}
|