Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-20 15:00:11 +01:00
Add option#(uuid, type) method to api, add logger.debug(message, objects...) method to easily debug-log messages without debug checks preventing formatting overhead
Dieser Commit ist enthalten in:
Ursprung
18776a8000
Commit
19954a201c
@ -54,11 +54,11 @@ public abstract class SessionLoadResourcePacksEvent extends ConnectionEvent {
|
||||
/**
|
||||
* Registers a {@link ResourcePack} to be sent to the client.
|
||||
*
|
||||
* @param resourcePack a resource pack that will be sent to the client.
|
||||
* @param pack a resource pack that will be sent to the client.
|
||||
* @return true if the resource pack was added successfully,
|
||||
* or false if already present
|
||||
*/
|
||||
public abstract boolean register(@NonNull ResourcePack resourcePack);
|
||||
public abstract boolean register(@NonNull ResourcePack pack);
|
||||
|
||||
/**
|
||||
* Registers a {@link ResourcePack} to be sent to the client, alongside
|
||||
@ -89,6 +89,15 @@ public abstract class SessionLoadResourcePacksEvent extends ConnectionEvent {
|
||||
*/
|
||||
public abstract Collection<ResourcePackOption<?>> options(@NonNull UUID uuid);
|
||||
|
||||
/**
|
||||
* Returns the current option, or null, for a given ResourcePackOption type.
|
||||
*
|
||||
* @param uuid the resource pack for which the option type is set
|
||||
* @param type the {@link ResourcePackOption.Type} of the option to query
|
||||
* @throws IllegalArgumentException if the pack is not registered.
|
||||
*/
|
||||
public abstract @Nullable ResourcePackOption<?> option(@NonNull UUID uuid, ResourcePackOption.@NonNull Type type);
|
||||
|
||||
/**
|
||||
* Unregisters a resource pack from being sent to the client.
|
||||
*
|
||||
|
@ -51,12 +51,12 @@ public abstract class GeyserDefineResourcePacksEvent implements Event {
|
||||
* Registers a {@link ResourcePack} to be sent to the client, optionally alongside
|
||||
* specific options.
|
||||
*
|
||||
* @param resourcePack a resource pack that will be sent to the client.
|
||||
* @param pack a resource pack that will be sent to the client.
|
||||
* @param options {@link ResourcePackOption}'s that specify how clients load the pack
|
||||
* @return true if the resource pack was added successfully,
|
||||
* or false if already present
|
||||
*/
|
||||
public abstract boolean register(@NonNull ResourcePack resourcePack, @Nullable ResourcePackOption<?>... options);
|
||||
public abstract boolean register(@NonNull ResourcePack pack, @Nullable ResourcePackOption<?>... options);
|
||||
|
||||
/**
|
||||
* Sets {@link ResourcePackOption}'s for a resource pack
|
||||
@ -76,6 +76,15 @@ public abstract class GeyserDefineResourcePacksEvent implements Event {
|
||||
*/
|
||||
public abstract Collection<ResourcePackOption<?>> options(@NonNull UUID uuid);
|
||||
|
||||
/**
|
||||
* Returns the current option, or null, for a given ResourcePackOption type.
|
||||
*
|
||||
* @param uuid the resource pack for which the option type is set
|
||||
* @param type the {@link ResourcePackOption.Type} of the option to query
|
||||
* @throws IllegalArgumentException if the pack is not registered.
|
||||
*/
|
||||
public abstract @Nullable ResourcePackOption<?> option(@NonNull UUID uuid, ResourcePackOption.@NonNull Type type);
|
||||
|
||||
/**
|
||||
* Unregisters a {@link ResourcePack} from being sent to clients.
|
||||
*
|
||||
|
@ -75,4 +75,11 @@ public class GeyserBungeeLogger implements GeyserLogger {
|
||||
info(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String message, Object... arguments) {
|
||||
if (debug) {
|
||||
info(String.format(message, arguments));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,6 +84,13 @@ public class GeyserModLogger implements GeyserLogger {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String message, Object... arguments) {
|
||||
if (debug) {
|
||||
logger.info(message, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDebug(boolean debug) {
|
||||
this.debug = debug;
|
||||
|
@ -75,4 +75,11 @@ public class GeyserSpigotLogger implements GeyserLogger {
|
||||
info(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String message, Object... arguments) {
|
||||
if (debug) {
|
||||
info(String.format(message, arguments));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,6 +89,11 @@ public class GeyserStandaloneLogger extends SimpleTerminalConsole implements Gey
|
||||
log.debug(ChatColor.GRAY + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String message, Object... arguments) {
|
||||
log.debug(ChatColor.GRAY + message, arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDebug(boolean debug) {
|
||||
Configurator.setLevel(log.getName(), debug ? Level.DEBUG : Level.INFO);
|
||||
|
@ -73,4 +73,11 @@ public class GeyserVelocityLogger implements GeyserLogger {
|
||||
info(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String message, Object... arguments) {
|
||||
if (debug) {
|
||||
logger.info(message, arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -75,6 +75,13 @@ public class GeyserViaProxyLogger implements GeyserLogger, GeyserCommandSource {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String message, Object... arguments) {
|
||||
if (this.debug) {
|
||||
this.debug(String.format(message, arguments));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDebug(boolean debug) {
|
||||
this.debug = debug;
|
||||
|
@ -103,6 +103,15 @@ public interface GeyserLogger extends GeyserCommandSource {
|
||||
debug(String.valueOf(object));
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an object to console if debug mode is enabled,
|
||||
* and formats it with the provided arguments
|
||||
*
|
||||
* @param message the message to log
|
||||
* @param arguments the arguments to replace in the message
|
||||
*/
|
||||
void debug(String message, Object... arguments);
|
||||
|
||||
/**
|
||||
* Sets if the logger should print debug messages
|
||||
*
|
||||
|
@ -94,6 +94,19 @@ public class GeyserDefineResourcePacksEventImpl extends GeyserDefineResourcePack
|
||||
return packHolder.optionHolder().immutableValues();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ResourcePackOption<?> option(@NonNull UUID uuid, ResourcePackOption.@NonNull Type type) {
|
||||
Objects.requireNonNull(uuid);
|
||||
Objects.requireNonNull(type);
|
||||
|
||||
ResourcePackHolder packHolder = packs.get(uuid);
|
||||
if (packHolder == null) {
|
||||
throw new IllegalArgumentException("ResourcePack with " + uuid + " not found, unable to provide options");
|
||||
}
|
||||
|
||||
return packHolder.optionHolder().get(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unregister(@NonNull UUID uuid) {
|
||||
return packs.remove(uuid) != null;
|
||||
|
@ -97,7 +97,7 @@ public class SessionLoadResourcePacksEventImpl extends SessionLoadResourcePacksE
|
||||
Objects.requireNonNull(options);
|
||||
ResourcePackHolder holder = packs.get(uuid);
|
||||
if (holder == null) {
|
||||
throw new IllegalArgumentException("Pack with uuid %s not registered yet!".formatted(uuid));
|
||||
throw new IllegalArgumentException("ResourcePack with " + uuid + " not found, unable to provide options");
|
||||
}
|
||||
|
||||
registerOption(holder.pack(), options);
|
||||
@ -115,6 +115,23 @@ public class SessionLoadResourcePacksEventImpl extends SessionLoadResourcePacksE
|
||||
return optionHolder.immutableValues(packHolder.optionHolder());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ResourcePackOption<?> option(@NonNull UUID uuid, ResourcePackOption.@NonNull Type type) {
|
||||
Objects.requireNonNull(uuid);
|
||||
Objects.requireNonNull(type);
|
||||
|
||||
ResourcePackHolder packHolder = packs.get(uuid);
|
||||
if (packHolder == null) {
|
||||
throw new IllegalArgumentException("ResourcePack with " + uuid + " not found, unable to provide options");
|
||||
}
|
||||
|
||||
OptionHolder holder = options.get(uuid);
|
||||
OptionHolder defaultHolder = packHolder.optionHolder();
|
||||
Objects.requireNonNull(defaultHolder); // should never be null
|
||||
|
||||
return OptionHolder.getOptionByType(type, holder, defaultHolder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unregister(@NonNull UUID uuid) {
|
||||
options.remove(uuid);
|
||||
|
@ -302,8 +302,8 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
|
||||
ResourcePackHolder holder = this.resourcePackLoadEvent.getPacks().get(packet.getPackId());
|
||||
|
||||
if (holder == null) {
|
||||
GeyserImpl.getInstance().getLogger().debug("Client %s tried to request pack id (%s) not sent to it!"
|
||||
.formatted(session.bedrockUsername(), packet.getPackId()));
|
||||
GeyserImpl.getInstance().getLogger().debug("Client {0} tried to request pack id {1} not sent to it!",
|
||||
session.bedrockUsername(), packet.getPackId());
|
||||
session.disconnect("disconnectionScreen.resourcePack");
|
||||
return PacketSignal.HANDLED;
|
||||
}
|
||||
@ -356,8 +356,8 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
|
||||
String[] packID = id.split("_");
|
||||
|
||||
if (packID.length < 2) {
|
||||
GeyserImpl.getInstance().getLogger().debug("Client %s tried to request invalid pack id %s!"
|
||||
.formatted(session.bedrockUsername(), packID));
|
||||
GeyserImpl.getInstance().getLogger().debug("Client {0} tried to request invalid pack id {1}!",
|
||||
session.bedrockUsername(), packID);
|
||||
session.disconnect("disconnectionScreen.resourcePack");
|
||||
return;
|
||||
}
|
||||
@ -366,16 +366,16 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
|
||||
try {
|
||||
packId = UUID.fromString(packID[0]);
|
||||
} catch (IllegalArgumentException e) {
|
||||
GeyserImpl.getInstance().getLogger().debug("Client %s tried to request pack with an invalid id (%s)"
|
||||
.formatted(session.bedrockUsername(), id));
|
||||
GeyserImpl.getInstance().getLogger().debug("Client {0} tried to request pack with an invalid id {1})",
|
||||
session.bedrockUsername(), id);
|
||||
session.disconnect("disconnectionScreen.resourcePack");
|
||||
return;
|
||||
}
|
||||
|
||||
ResourcePackHolder holder = this.resourcePackLoadEvent.getPacks().get(packId);
|
||||
if (holder == null) {
|
||||
GeyserImpl.getInstance().getLogger().debug("Client %s tried to request pack id (%s) not sent to it!"
|
||||
.formatted(session.bedrockUsername(), id));
|
||||
GeyserImpl.getInstance().getLogger().debug("Client {0} tried to request pack id {1} not sent to it!",
|
||||
session.bedrockUsername(), id);
|
||||
session.disconnect("disconnectionScreen.resourcePack");
|
||||
return;
|
||||
}
|
||||
|
@ -78,6 +78,25 @@ public class OptionHolder extends HashMap<ResourcePackOption.Type, ResourcePackO
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public static ResourcePackOption<?> getOptionByType(ResourcePackOption.@NonNull Type type,
|
||||
@Nullable OptionHolder holder,
|
||||
@NonNull OptionHolder defaultHolder) {
|
||||
ResourcePackOption<?> option;
|
||||
|
||||
// First: the optionHolder's option, if it exists
|
||||
if (holder != null) {
|
||||
option = holder.get(type);
|
||||
if (option != null) {
|
||||
return option;
|
||||
}
|
||||
}
|
||||
|
||||
// Second: check the default optionHolder for the option, if it exists;
|
||||
// Or return null if the option isn't set.
|
||||
option = defaultHolder.get(type);
|
||||
return option;
|
||||
}
|
||||
|
||||
public void remove(ResourcePackOption<?> option) {
|
||||
super.remove(option.type());
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren