Skip to content

Commit

Permalink
API: change player class to Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Nov 22, 2021
1 parent 5b415ce commit 966c215
Show file tree
Hide file tree
Showing 394 changed files with 1,100 additions and 1,111 deletions.
26 changes: 3 additions & 23 deletions api/base/src/main/java/org/geysermc/api/Geyser.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,49 +32,29 @@
*/
@NonNull
public class Geyser {
private static Api api;
private static GeyserApi api;

/**
* Returns the base api.
*
* @return the base api
*/
public static Api api() {
public static GeyserApi api() {
if (api == null) {
throw new RuntimeException("Api has not been registered yet!");
}

return api;
}

/**
* Returns the api of the given type.
*
* @param apiClass the api class
* @param <T> the type
* @return the api of the given type
*/
@SuppressWarnings("unchecked")
public static <T extends Api> T api(@NonNull Class<T> apiClass) {
if (apiClass.isInstance(api)) {
return (T) api;
}

if (api == null) {
throw new RuntimeException("Api has not been registered yet!");
} else {
throw new RuntimeException("Api was not an instance of " + apiClass + "! Was " + api.getClass().getCanonicalName());
}
}

/**
* Registers the given api type. The api cannot be
* registered if {@link #registered()} is true as
* an api has already been specified.
*
* @param api the api
*/
public static void set(@NonNull Api api) {
public static void set(@NonNull GeyserApi api) {
if (Geyser.api != null) {
throw new RuntimeException("Cannot redefine already registered api!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.api.session.Session;
import org.geysermc.api.geyser.GeyserExtensionApi;
import org.geysermc.api.session.Connection;

import java.util.List;
import java.util.UUID;

/**
* The base API class.
*/
public interface Api {

public interface GeyserApi {
/**
* Gets the session from the given
* UUID, if applicable.
* Gets the session from the given UUID, if applicable. The player must be logged in to the Java server
* for this to return a non-null value.
*
* @param uuid the UUID of the session
* @return the session from the given UUID, if applicable
*/
@Nullable
Session sessionByUuid(@NonNull UUID uuid);
Connection connectionByUuid(@NonNull UUID uuid);

/**
* Gets the session from the given
Expand All @@ -55,7 +55,7 @@ public interface Api {
* @return the session from the given UUID, if applicable
*/
@Nullable
Session sessionByXuid(@NonNull String xuid);
Connection connectionByXuid(@NonNull String xuid);

/**
* Gets the session from the given
Expand All @@ -65,13 +65,36 @@ public interface Api {
* @return the session from the given name, if applicable
*/
@Nullable
Session sessionByName(@NonNull String name);
Connection connectionByName(@NonNull String name);

/**
* Gets all the online sessions.
*
* @return all the online sessions
*/
@NonNull
List<? extends Session> onlineSessions();
List<? extends Connection> onlineConnections();

/**
* Returns this as the Geyser extension API, if the platform supports it.
*
* @return the extension API, if this platform supports it.
*/
default GeyserExtensionApi asExtensionApi() {
return null;
}

/**
* @return the major API version. Bumped whenever a significant breaking change or feature addition is added.
*/
default int majorApiVersion() {
return 0;
}

/**
* @return the minor API version. May be bumped for new API additions.
*/
default int minorApiVersion() {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.api.session;
package org.geysermc.api.geyser;

import org.geysermc.api.session.Session;
import org.geysermc.api.session.Connection;

/**
* Represents a player session used in Geyser.
*/
public interface GeyserSession extends Session {
public interface GeyserConnection extends Connection {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,14 @@
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.api;
package org.geysermc.api.geyser;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.api.Api;
import org.geysermc.api.Geyser;
import org.geysermc.api.session.Session;
import org.geysermc.geyser.api.session.GeyserSession;

import java.util.List;
import java.util.UUID;
import org.geysermc.api.GeyserApi;

/**
* Represents the API used in Geyser.
*/
public interface GeyserApi extends Api {

public interface GeyserExtensionApi extends GeyserApi {
/**
* Shuts down the current Geyser instance.
*/
Expand All @@ -58,36 +49,8 @@ public interface GeyserApi extends Api {
*/
boolean productionEnvironment();

/**
* {@inheritDoc}
*/
@Override
@Nullable GeyserSession sessionByUuid(@NonNull UUID uuid);

/**
* {@inheritDoc}
*/
@Override
@Nullable GeyserSession sessionByXuid(@NonNull String xuid);

/**
* {@inheritDoc}
*/
@Override
@Nullable GeyserSession sessionByName(@NonNull String name);

/**
* {@inheritDoc}
*/
@NonNull
List<? extends GeyserSession> onlineSessions();

/**
* Gets the {@link GeyserApi}.
*
* @return the Geyser API
*/
static GeyserApi api() {
return Geyser.api(GeyserApi.class);
default GeyserExtensionApi asExtensionApi() {
return this;
}
}
29 changes: 29 additions & 0 deletions api/base/src/main/java/org/geysermc/api/geyser/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
*
* 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:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 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.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/

/**
*
*/
package org.geysermc.api.geyser;
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,30 @@
import java.util.UUID;

/**
* Represents a player session.
* Represents a player connection.
*/
@NonNull
public interface Session {

public interface Connection {
/**
* Gets the name of the session.
* Gets the name of the connection.
*
* @return the name of the session
* @return the name of the connection
*/
String name();

/**
* Gets the {@link UUID} of the session.
* Gets the {@link UUID} of the connection.
*
* @return the UUID of the session
* @return the UUID of the connection
*/
UUID uuid();

/**
* Gets the XUID of the session.
* Gets the XUID of the connection.
*
* @return the XUID of the session
* @return the XUID of the connection
*/
String xuid();


}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandExecutor;
import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.session.GeyserSessionImpl;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale;

import java.util.Arrays;
Expand All @@ -50,7 +50,7 @@ public GeyserBungeeCommandExecutor(GeyserImpl geyser) {
@Override
public void execute(CommandSender sender, String[] args) {
BungeeCommandSender commandSender = new BungeeCommandSender(sender);
GeyserSessionImpl session = this.commandExecutor.getGeyserSession(commandSender);
GeyserSession session = this.commandExecutor.getGeyserSession(commandSender);

if (args.length > 0) {
GeyserCommand command = this.commandExecutor.getCommand(args[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandExecutor;
import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.session.GeyserSessionImpl;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale;

import java.util.Arrays;
Expand All @@ -48,7 +48,7 @@ public GeyserSpigotCommandExecutor(GeyserImpl geyser) {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
SpigotCommandSender commandSender = new SpigotCommandSender(sender);
GeyserSessionImpl session = getGeyserSession(commandSender);
GeyserSession session = getGeyserSession(commandSender);

if (args.length > 0) {
GeyserCommand geyserCommand = getCommand(args[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.session.GeyserSessionImpl;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.cache.PistonCache;
import org.geysermc.geyser.level.block.BlockStateValues;
import org.geysermc.geyser.translator.level.block.entity.PistonBlockEntity;
Expand Down Expand Up @@ -88,12 +88,12 @@ private void onPistonAction(BlockPistonEvent event) {
Object2IntMap<Vector3i> attachedBlocks = new Object2IntOpenHashMap<>();
boolean blocksFilled = false;

for (Map.Entry<UUID, GeyserSessionImpl> entry : geyser.getSessionManager().getSessions().entrySet()) {
for (Map.Entry<UUID, GeyserSession> entry : geyser.getSessionManager().getSessions().entrySet()) {
Player player = Bukkit.getPlayer(entry.getKey());
if (player == null || !player.getWorld().equals(world)) {
continue;
}
GeyserSessionImpl session = entry.getValue();
GeyserSession session = entry.getValue();

int dX = Math.abs(location.getBlockX() - player.getLocation().getBlockX()) >> 4;
int dZ = Math.abs(location.getBlockZ() - player.getLocation().getBlockZ()) >> 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import org.bukkit.inventory.ShapelessRecipe;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.network.MinecraftProtocol;
import org.geysermc.geyser.session.GeyserSessionImpl;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.inventory.item.ItemTranslator;
import org.geysermc.geyser.util.InventoryUtils;

Expand Down Expand Up @@ -79,8 +79,8 @@ public GeyserSpigot1_11CraftingListener(GeyserImpl geyser) {

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
GeyserSessionImpl session = null;
for (GeyserSessionImpl otherSession : geyser.getSessionManager().getSessions().values()) {
GeyserSession session = null;
for (GeyserSession otherSession : geyser.getSessionManager().getSessions().values()) {
if (otherSession.name().equals(event.getPlayer().getName())) {
session = otherSession;
break;
Expand All @@ -93,7 +93,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
sendServerRecipes(session);
}

public void sendServerRecipes(GeyserSessionImpl session) {
public void sendServerRecipes(GeyserSession session) {
int netId = InventoryUtils.LAST_RECIPE_NET_ID;

CraftingDataPacket craftingDataPacket = new CraftingDataPacket();
Expand Down Expand Up @@ -161,7 +161,7 @@ public void sendServerRecipes(GeyserSessionImpl session) {
}

@SuppressWarnings("deprecation")
private Pair<ItemStack, ItemData> translateToBedrock(GeyserSessionImpl session, org.bukkit.inventory.ItemStack itemStack) {
private Pair<ItemStack, ItemData> translateToBedrock(GeyserSession session, org.bukkit.inventory.ItemStack itemStack) {
if (itemStack != null && itemStack.getData() != null) {
if (itemStack.getType().getId() == 0) {
return new Pair<>(null, ItemData.AIR);
Expand Down
Loading

0 comments on commit 966c215

Please sign in to comment.