Skip to content

Commit

Permalink
Add advancements GUI (GeyserMC#1579)
Browse files Browse the repository at this point in the history
Using /geyser advancements, Bedrock clients can get a visual on their progress.

Co-authored-by: yehudahrrs <[email protected]>
Co-authored-by: Olivia <[email protected]>
Co-authored-by: rtm516 <[email protected]>
Co-authored-by: DoctorMacc <[email protected]>
Co-authored-by: rtm516 <[email protected]>
Co-authored-by: Camotoy <[email protected]>
  • Loading branch information
7 people authored Jan 12, 2021
1 parent 1c0cc46 commit fb283fc
Show file tree
Hide file tree
Showing 10 changed files with 654 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public CommandManager(GeyserConnector connector) {
registerCommand(new VersionCommand(connector, "version", "geyser.commands.version.desc", "geyser.command.version"));
registerCommand(new SettingsCommand(connector, "settings", "geyser.commands.settings.desc", "geyser.command.settings"));
registerCommand(new StatisticsCommand(connector, "statistics", "geyser.commands.statistics.desc", "geyser.command.statistics"));
registerCommand(new AdvancementsCommand(connector, "advancements", "geyser.commands.advancements.desc", "geyser.command.advancements"));
}

public void registerCommand(GeyserCommand command) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.connector.command.defaults;

import org.geysermc.common.window.SimpleFormWindow;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandSender;
import org.geysermc.connector.command.GeyserCommand;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.session.cache.AdvancementsCache;

public class AdvancementsCommand extends GeyserCommand {

private final GeyserConnector connector;

public AdvancementsCommand(GeyserConnector connector, String name, String description, String permission) {
super(name, description, permission);

this.connector = connector;
}

@Override
public void execute(CommandSender sender, String[] args) {
if (sender.isConsole()) {
return;
}

// Make sure the sender is a Bedrock edition client
GeyserSession session = null;
if (sender instanceof GeyserSession) {
session = (GeyserSession) sender;
} else {
// Needed for Spigot - sender is not an instance of GeyserSession
for (GeyserSession otherSession : connector.getPlayers()) {
if (sender.getName().equals(otherSession.getPlayerEntity().getUsername())) {
session = otherSession;
break;
}
}
}
if (session == null) return;

SimpleFormWindow window = session.getAdvancementsCache().buildMenuForm();
session.sendForm(window, AdvancementsCache.ADVANCEMENTS_MENU_FORM_ID);
}

@Override
public boolean isExecutableOnConsole() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,9 @@
import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.configuration.GeyserConfiguration;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.session.cache.AdvancementsCache;
import org.geysermc.connector.network.translators.PacketTranslatorRegistry;
import org.geysermc.connector.utils.LanguageUtils;
import org.geysermc.connector.utils.LoginEncryptionUtils;
import org.geysermc.connector.utils.MathUtils;
import org.geysermc.connector.utils.ResourcePack;
import org.geysermc.connector.utils.ResourcePackManifest;
import org.geysermc.connector.utils.SettingsUtils;
import org.geysermc.connector.utils.StatisticsUtils;
import org.geysermc.connector.utils.*;

import java.io.FileInputStream;
import java.io.InputStream;
Expand Down Expand Up @@ -144,12 +139,19 @@ public boolean handle(ResourcePackClientResponsePacket packet) {

@Override
public boolean handle(ModalFormResponsePacket packet) {
if (packet.getFormId() == SettingsUtils.SETTINGS_FORM_ID) {
return SettingsUtils.handleSettingsForm(session, packet.getFormData());
} else if (packet.getFormId() == StatisticsUtils.STATISTICS_MENU_FORM_ID) {
return StatisticsUtils.handleMenuForm(session, packet.getFormData());
} else if (packet.getFormId() == StatisticsUtils.STATISTICS_LIST_FORM_ID) {
return StatisticsUtils.handleListForm(session, packet.getFormData());
switch (packet.getFormId()) {
case AdvancementsCache.ADVANCEMENT_INFO_FORM_ID:
return session.getAdvancementsCache().handleInfoForm(packet.getFormData());
case AdvancementsCache.ADVANCEMENTS_LIST_FORM_ID:
return session.getAdvancementsCache().handleListForm(packet.getFormData());
case AdvancementsCache.ADVANCEMENTS_MENU_FORM_ID:
return session.getAdvancementsCache().handleMenuForm(packet.getFormData());
case SettingsUtils.SETTINGS_FORM_ID:
return SettingsUtils.handleSettingsForm(session, packet.getFormData());
case StatisticsUtils.STATISTICS_LIST_FORM_ID:
return StatisticsUtils.handleListForm(session, packet.getFormData());
case StatisticsUtils.STATISTICS_MENU_FORM_ID:
return StatisticsUtils.handleMenuForm(session, packet.getFormData());
}

return LoginEncryptionUtils.authenticateFromForm(session, connector, packet.getFormId(), packet.getFormData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public class GeyserSession implements CommandSender {
private final SessionPlayerEntity playerEntity;
private PlayerInventory inventory;

private AdvancementsCache advancementsCache;
private BookEditCache bookEditCache;
private ChunkCache chunkCache;
private EntityCache entityCache;
Expand Down Expand Up @@ -350,6 +351,7 @@ public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServ
this.connector = connector;
this.upstream = new UpstreamSession(bedrockServerSession);

this.advancementsCache = new AdvancementsCache(this);
this.bookEditCache = new BookEditCache(this);
this.chunkCache = new ChunkCache(this);
this.entityCache = new EntityCache(this);
Expand Down Expand Up @@ -684,6 +686,7 @@ public void disconnect(String reason) {
tickThread.cancel(true);
}

this.advancementsCache = null;
this.bookEditCache = null;
this.chunkCache = null;
this.entityCache = null;
Expand Down
Loading

0 comments on commit fb283fc

Please sign in to comment.