Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 7bd4f9c
Author: Ethan <ethpsa09@gmail.com>
Date:   Sun Jul 21 21:50:37 2024 +0800

    Half complete GuiData commit, needs some changes most likely

commit d78441a
Merge: 6338d1c 4547431
Author: Ethan <ethpsa09@gmail.com>
Date:   Sun Jul 21 21:33:41 2024 +0800

    Merge branch 'send-toast-api' of https://github.com/letsgoawaydev/Geyser into send-toast-api

commit 6338d1c
Author: Ethan <ethpsa09@gmail.com>
Date:   Sun Jul 21 21:33:37 2024 +0800

    test

commit 0654d2d
Author: chris <github@onechris.mozmail.com>
Date:   Sun Jul 21 13:11:27 2024 +0200

    Fix: Text display offset <GeyserMC#4439> (GeyserMC#4883)

commit 57919db
Author: chris <github@onechris.mozmail.com>
Date:   Sun Jul 21 02:15:38 2024 +0200

    Somewhat fix: firework recipe not showing up in recipe book (GeyserMC#4873)

    * Somewhat fix firework crafting

    * Use instanceof instead of casting

commit 23d53db
Author: chris <github@onechris.mozmail.com>
Date:   Sun Jul 21 02:10:51 2024 +0200

    Fix: Only shutdown/close handlers in onDisable if they're nonnull (GeyserMC#4882)

commit 6459f67
Author: LetsGoAway <68365423+letsgoawaydev@users.noreply.github.com>
Date:   Sat Jul 20 18:09:22 2024 +0800

    Use the correct way of sending block breaking particles (GeyserMC#4825)

commit ebc7f30
Author: Camotoy <20743703+Camotoy@users.noreply.github.com>
Date:   Sat Jul 20 23:22:04 2024 -0400

    Respect block range attribute where we can

    GeyserMC#4864

commit bf16ddb
Author: Camotoy <20743703+Camotoy@users.noreply.github.com>
Date:   Sat Jul 20 23:21:36 2024 -0400

    Small cleanups

commit 2d73e51
Author: chris <github@onechris.mozmail.com>
Date:   Wed Jul 17 21:44:53 2024 +0200

    Properly fix hanging signs (GeyserMC#4872)

commit 3fad986
Author: Camotoy <20743703+Camotoy@users.noreply.github.com>
Date:   Wed Jul 17 14:21:41 2024 -0400

    Fix GeyserMC#4870

commit 3144721
Author: Valaphee The Meerkat <32491319+valaphee@users.noreply.github.com>
Date:   Tue Jul 16 14:13:34 2024 +0200

    Empty player list on phase transition, despawn skulls, always reset weather (GeyserMC#4847)

    * Empty player list on transition, despawn skulls

    * Always reset weather

commit 07bdc1c
Author: masel.io <git@byteexception.eu>
Date:   Tue Jul 16 11:23:30 2024 +0200

    Add Timeout to CompletableFuture in GeyserBungeePingPassthrough to Prevent Memory Leak (GeyserMC#4858)

    * fix: Add timeout for GeyserBungeePingPassthrough#getPingInformation

    Signed-off-by: ByteExceptionM <git@byteexception.eu>

    * fix: Use Geyser Logger instead of Bungee Logger

    Signed-off-by: ByteExceptionM <git@byteexception.eu>

    * Fix typo

    Co-authored-by: Konicai <71294714+Konicai@users.noreply.github.com>

    * chore: Add ip suppression if configured

    Signed-off-by: ByteExceptionM <git@byteexception.eu>

    * Remove empty line

    Co-authored-by: chris <github@onechris.mozmail.com>

    * Remove empty line

    Co-authored-by: chris <github@onechris.mozmail.com>

    ---------

    Signed-off-by: ByteExceptionM <git@byteexception.eu>
    Co-authored-by: Konicai <71294714+Konicai@users.noreply.github.com>
    Co-authored-by: chris <github@onechris.mozmail.com>

commit ea4a21c
Author: Camotoy <20743703+Camotoy@users.noreply.github.com>
Date:   Mon Jul 15 15:16:45 2024 -0400

    Indicate support for Bedrock 1.21.3

commit 6dfb1a8
Author: chris <github@onechris.mozmail.com>
Date:   Mon Jul 15 01:31:03 2024 +0200

    Fix: Block place sounds on mod platforms (GeyserMC#4859)

commit 215b12e
Author: chris <github@onechris.mozmail.com>
Date:   Sun Jul 14 21:55:57 2024 +0200

    Fix: Totem animation when playing totem effects manually (GeyserMC#4860)

    * Fix: Totem animation for manually played totem effects

    * Ensure we always reset the offhand correctly

commit 92112f4
Author: chris <github@onechris.mozmail.com>
Date:   Sun Jul 14 20:17:22 2024 +0200

    Fix: Send a container close packet to Java for containers that could not be opened (GeyserMC#4861)

    * Close containers if we did not manage to open it

    * Mark session inventory translator as nonnull

commit 054fc09
Author: LetsGoAway <68365423+letsgoawaydev@users.noreply.github.com>
Date:   Sun Jul 14 16:44:39 2024 +0800

    Correctly cap scale attribute (GeyserMC#4856)

    * Fix scale attribute cap

    * Update LivingEntity.java

commit c862d5a
Author: chris <github@onechris.mozmail.com>
Date:   Sat Jul 13 22:00:15 2024 +0200

    Fix: Manually translated item names for block items not showing up properly (GeyserMC#4857)

commit 94f17d1
Author: chris <github@onechris.mozmail.com>
Date:   Sat Jul 13 18:53:13 2024 +0200

    Fix: Item color names/glint for rare items (GeyserMC#4763)

    * debug stick changes

    * yay light purple item name

    * Address review

    * Auto-generate rarity

    * Add glint generation

    * Translate all rare items properly

    * Use putIfAbsent instead of double checks

commit e127f9e
Author: chris <github@onechris.mozmail.com>
Date:   Fri Jul 12 20:55:40 2024 +0200

    Fix: hanging sign recipe not showing up in the recipe book (GeyserMC#4814)

commit 4547431
Merge: 96aecd2 b213fb5
Author: Ethan <ethpsa09@gmail.com>
Date:   Sun Jul 21 21:02:04 2024 +0800

    Merge branch 'send-toast-api' of https://github.com/letsgoawaydev/Geyser into send-toast-api

commit 96aecd2
Author: chris <github@onechris.mozmail.com>
Date:   Sun Jul 14 22:09:55 2024 +0200

    Feature: API to switch items in the offhand/mainhand (GeyserMC#4819)

commit a9c6d8b
Author: chris <github@onechris.mozmail.com>
Date:   Fri Jul 12 20:42:31 2024 +0200

    Add a /geyser ping command  (GeyserMC#4131)

    * Init: Add /geyser ping command

    * Block just console execution, not everything but console senders

    * Use RTT as that seems to vary less wildly compared to getPing()

    * Cleanup, use lang strings

    * Add ping() method to GeyserConnection in api

    * Update to cloud changes

commit a57671e
Author: Konicai <71294714+Konicai@users.noreply.github.com>
Date:   Thu Jul 11 23:56:42 2024 -0500

    Cloud for commands (GeyserMC#3808)

    Co-authored-by: onebeastchris <github@onechris.mozmail.com>
  • Loading branch information
letsgoawaydev committed Jul 21, 2024
1 parent 1187b3a commit 0a602dc
Show file tree
Hide file tree
Showing 9 changed files with 325 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.bedrock.gui.GuiElement;
import org.geysermc.geyser.api.connection.GeyserConnection;
import org.geysermc.geyser.api.bedrock.gui.GuiData;

import java.util.Set;
import java.util.UUID;
Expand Down Expand Up @@ -150,7 +152,9 @@ public interface CameraData {
* Hides a {@link GuiElement} on the client's side.
*
* @param element the {@link GuiElement} to hide
* @deprecated Use {@link GuiData#hideElement(GuiElement...)} instead
*/
@Deprecated
void hideElement(@NonNull GuiElement... element);

/**
Expand All @@ -161,20 +165,26 @@ public interface CameraData {
* If no elements are specified, this will reset all currently hidden elements
*
* @param element the {@link GuiElement} to reset
* @deprecated Use {@link GuiData#resetElement(GuiElement...)} instead
*/
@Deprecated
void resetElement(@NonNull GuiElement @Nullable... element);

/**
* Determines whether a {@link GuiElement} is currently hidden.
*
* @param element the {@link GuiElement} to check
* @deprecated Use {@link GuiData#isHudElementHidden(GuiElement)} instead
*/
@Deprecated
boolean isHudElementHidden(@NonNull GuiElement element);

/**
* Returns the currently hidden {@link GuiElement}s.
*
* @return an unmodifiable view of all currently hidden {@link GuiElement}s
* @deprecated Use {@link GuiData#hiddenElements()} instead
*/
@Deprecated
@NonNull Set<GuiElement> hiddenElements();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,31 @@

package org.geysermc.geyser.api.bedrock.camera;

import org.geysermc.geyser.api.bedrock.gui.GuiData;

/**
* Represent GUI elements on the players HUD display.
* These can be hidden using {@link CameraData#hideElement(GuiElement...)},
* and one can reset their visibility using {@link CameraData#resetElement(GuiElement...)}.
* These can be hidden using {@link GuiData#hideElement(org.geysermc.geyser.api.bedrock.gui.GuiElement...)},
* and one can reset their visibility using {@link GuiData#resetElement(org.geysermc.geyser.api.bedrock.gui.GuiElement...)}.
* @deprecated use {@link org.geysermc.geyser.api.bedrock.gui.GuiElement}
*/
public class GuiElement {
public static final GuiElement PAPER_DOLL = new GuiElement(0);
public static final GuiElement ARMOR = new GuiElement(1);
public static final GuiElement TOOL_TIPS = new GuiElement(2);
public static final GuiElement TOUCH_CONTROLS = new GuiElement(3);
public static final GuiElement CROSSHAIR = new GuiElement(4);
public static final GuiElement HOTBAR = new GuiElement(5);
public static final GuiElement HEALTH = new GuiElement(6);
public static final GuiElement PROGRESS_BAR = new GuiElement(7);
public static final GuiElement FOOD_BAR = new GuiElement(8);
public static final GuiElement AIR_BUBBLES_BAR = new GuiElement(9);
public static final GuiElement VEHICLE_HEALTH = new GuiElement(10);
public static final GuiElement EFFECTS_BAR = new GuiElement(11);
public static final GuiElement ITEM_TEXT_POPUP = new GuiElement(12);
public class GuiElement extends org.geysermc.geyser.api.bedrock.gui.GuiElement {
public static final org.geysermc.geyser.api.bedrock.gui.GuiElement PAPER_DOLL = org.geysermc.geyser.api.bedrock.gui.GuiElement.PAPER_DOLL;
public static final org.geysermc.geyser.api.bedrock.gui.GuiElement ARMOR = org.geysermc.geyser.api.bedrock.gui.GuiElement.ARMOR;
public static final org.geysermc.geyser.api.bedrock.gui.GuiElement TOOL_TIPS = org.geysermc.geyser.api.bedrock.gui.GuiElement.TOOL_TIPS;
public static final org.geysermc.geyser.api.bedrock.gui.GuiElement TOUCH_CONTROLS = org.geysermc.geyser.api.bedrock.gui.GuiElement.TOUCH_CONTROLS;
public static final org.geysermc.geyser.api.bedrock.gui.GuiElement CROSSHAIR = org.geysermc.geyser.api.bedrock.gui.GuiElement.CROSSHAIR;
public static final org.geysermc.geyser.api.bedrock.gui.GuiElement HOTBAR = org.geysermc.geyser.api.bedrock.gui.GuiElement.HOTBAR;
public static final org.geysermc.geyser.api.bedrock.gui.GuiElement HEALTH = org.geysermc.geyser.api.bedrock.gui.GuiElement.HEALTH;
public static final org.geysermc.geyser.api.bedrock.gui.GuiElement PROGRESS_BAR = org.geysermc.geyser.api.bedrock.gui.GuiElement.PROGRESS_BAR;
public static final org.geysermc.geyser.api.bedrock.gui.GuiElement FOOD_BAR = org.geysermc.geyser.api.bedrock.gui.GuiElement.FOOD_BAR;
public static final org.geysermc.geyser.api.bedrock.gui.GuiElement AIR_BUBBLES_BAR = org.geysermc.geyser.api.bedrock.gui.GuiElement.AIR_BUBBLES_BAR;
public static final org.geysermc.geyser.api.bedrock.gui.GuiElement VEHICLE_HEALTH = org.geysermc.geyser.api.bedrock.gui.GuiElement.VEHICLE_HEALTH;
public static final org.geysermc.geyser.api.bedrock.gui.GuiElement EFFECTS_BAR = org.geysermc.geyser.api.bedrock.gui.GuiElement.EFFECTS_BAR;
public static final org.geysermc.geyser.api.bedrock.gui.GuiElement ITEM_TEXT_POPUP = org.geysermc.geyser.api.bedrock.gui.GuiElement.ITEM_TEXT_POPUP;

private GuiElement(int id) {
this.id = id;
}

private final int id;

/**
* Internal use only; don't depend on these values being consistent.
*/
public int id() {
return this.id;
public GuiElement(int id) {
super(id);
}
}

70 changes: 70 additions & 0 deletions api/src/main/java/org/geysermc/geyser/api/bedrock/gui/GuiData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2024 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.geyser.api.bedrock.gui;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.Set;

public interface GuiData {
/**
* Hides a {@link GuiElement} on the client's side.
*
* @param element the {@link GuiElement} to hide
*/
void hideElement(@NonNull GuiElement... element);

/**
* Resets a {@link GuiElement} on the client's side.
* This makes the client decide on its own - e.g. based on client settings -
* whether to show or hide the gui element.
* <p>
* If no elements are specified, this will reset all currently hidden elements
*
* @param element the {@link GuiElement} to reset
*/
void resetElement(@NonNull GuiElement @Nullable ... element);

/**
* Determines whether a {@link GuiElement} is currently hidden.
*
* @param element the {@link GuiElement} to check
*/
boolean isHudElementHidden(@NonNull GuiElement element);

/**
* Returns the currently hidden {@link GuiElement}s.
*
* @return an unmodifiable view of all currently hidden {@link GuiElement}s
*/
@NonNull Set<GuiElement> hiddenElements();

/**
* Sends a notification toast to the client.
*/
void sendToast(@NonNull String title, @NonNull String content);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2024 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.geyser.api.bedrock.gui;

/**
* Represent GUI elements on the players HUD display.
* These can be hidden using {@link GuiData#hideElement(GuiElement...)},
* and one can reset their visibility using {@link GuiData#resetElement(GuiElement...)}.
*/
public class GuiElement {
public static final GuiElement PAPER_DOLL = new GuiElement(0);
public static final GuiElement ARMOR = new GuiElement(1);
public static final GuiElement TOOL_TIPS = new GuiElement(2);
public static final GuiElement TOUCH_CONTROLS = new GuiElement(3);
public static final GuiElement CROSSHAIR = new GuiElement(4);
public static final GuiElement HOTBAR = new GuiElement(5);
public static final GuiElement HEALTH = new GuiElement(6);
public static final GuiElement PROGRESS_BAR = new GuiElement(7);
public static final GuiElement FOOD_BAR = new GuiElement(8);
public static final GuiElement AIR_BUBBLES_BAR = new GuiElement(9);
public static final GuiElement VEHICLE_HEALTH = new GuiElement(10);
public static final GuiElement EFFECTS_BAR = new GuiElement(11);
public static final GuiElement ITEM_TEXT_POPUP = new GuiElement(12);

public GuiElement(int id) {
this.id = id;
}

private final int id;

/**
* Internal use only; don't depend on these values being consistent.
*/
public int id() {
return this.id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.geysermc.api.connection.Connection;
import org.geysermc.geyser.api.bedrock.camera.CameraData;
import org.geysermc.geyser.api.bedrock.camera.CameraShake;
import org.geysermc.geyser.api.bedrock.gui.GuiData;
import org.geysermc.geyser.api.command.CommandSource;
import org.geysermc.geyser.api.entity.EntityData;
import org.geysermc.geyser.api.entity.type.GeyserEntity;
Expand Down Expand Up @@ -60,6 +61,14 @@ public interface GeyserConnection extends Connection, CommandSource {
*/
@NonNull EntityData entities();

/**
* Exposes the {@link GuiData} for this connection.
* It allows you to hide GUI elements, and send notification toasts.
*
* @return the GuiData for this connection.
*/
@NonNull GuiData gui();

/**
* @param javaId the Java entity ID to look up.
* @return a {@link GeyserEntity} if present in this connection's entity tracker.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@
import org.geysermc.geyser.api.bedrock.camera.CameraPerspective;
import org.geysermc.geyser.api.bedrock.camera.CameraPosition;
import org.geysermc.geyser.api.bedrock.camera.CameraShake;
import org.geysermc.geyser.api.bedrock.camera.GuiElement;
import org.geysermc.geyser.api.bedrock.gui.GuiElement;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.HashSet;
Expand All @@ -58,21 +59,6 @@
import java.util.UUID;

public class GeyserCameraData implements CameraData {
private static final HudElement[] HUD_ELEMENT_VALUES = HudElement.values();
private static final Set<HudElement> ALL_HUD_ELEMENTS = Set.of(HUD_ELEMENT_VALUES);

/**
* An array of elements to hide when the player is in spectator mode.
* Helps with tidying up the GUI; Java-style.
*/
private static final GuiElement[] SPECTATOR_HIDDEN_ELEMENTS = {
GuiElement.AIR_BUBBLES_BAR,
GuiElement.ARMOR,
GuiElement.HEALTH,
GuiElement.FOOD_BAR,
GuiElement.PROGRESS_BAR,
GuiElement.TOOL_TIPS
};

private final GeyserSession session;

Expand All @@ -83,10 +69,6 @@ public class GeyserCameraData implements CameraData {

private final Set<UUID> cameraLockOwners = new HashSet<>();

/**
* All currently hidden HUD elements
*/
private final Set<GuiElement> hiddenHudElements = new HashSet<>();

@Getter
private CameraPerspective cameraPerspective;
Expand Down Expand Up @@ -260,64 +242,21 @@ public boolean isCameraLocked() {

@Override
public void hideElement(GuiElement... elements) {
Objects.requireNonNull(elements);
SetHudPacket packet = new SetHudPacket();
packet.setVisibility(HudVisibility.HIDE);
Set<HudElement> elementSet = packet.getElements();

for (GuiElement element : elements) {
this.hiddenHudElements.add(element);
elementSet.add(HUD_ELEMENT_VALUES[element.id()]);
}

session.sendUpstreamPacket(packet);
session.gui().hideElement(elements);
}

@Override
public void resetElement(GuiElement... elements) {
SetHudPacket packet = new SetHudPacket();
packet.setVisibility(HudVisibility.RESET);
Set<HudElement> elementSet = packet.getElements();

if (elements != null && elements.length != 0) {
for (GuiElement element : elements) {
this.hiddenHudElements.remove(element);
elementSet.add(HUD_ELEMENT_VALUES[element.id()]);
}
} else {
this.hiddenHudElements.clear();
elementSet.addAll(ALL_HUD_ELEMENTS);
}

session.sendUpstreamPacket(packet);
public void resetElement(@NotNull @NonNull GuiElement @Nullable ... element) {
session.gui().resetElement(element);
}

@Override
public boolean isHudElementHidden(@NonNull GuiElement element) {
Objects.requireNonNull(element);
return this.hiddenHudElements.contains(element);
return session.gui().isHudElementHidden(element);
}

@Override
public @NonNull Set<GuiElement> hiddenElements() {
return Collections.unmodifiableSet(hiddenHudElements);
}

/**
* Deals with hiding hud elements while in spectator.
*
* @param currentlySpectator whether the player is currently in spectator mode
* @param newGameMode the new GameMode to switch to
*/
public void handleGameModeChange(boolean currentlySpectator, GameMode newGameMode) {
if (newGameMode == GameMode.SPECTATOR) {
if (!currentlySpectator) {
hideElement(SPECTATOR_HIDDEN_ELEMENTS);
}
} else {
if (currentlySpectator) {
resetElement(SPECTATOR_HIDDEN_ELEMENTS);
}
}
return session.gui().hiddenElements();
}
}
Loading

0 comments on commit 0a602dc

Please sign in to comment.