Skip to content

Commit

Permalink
fix: fix issue#419
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Oct 1, 2024
1 parent ad61e67 commit 409cf34
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.allaymc.api.entity.component.player;

import it.unimi.dsi.fastutil.Pair;
import org.allaymc.api.client.data.Abilities;
import org.allaymc.api.client.data.AdventureSettings;
import org.allaymc.api.client.skin.Skin;
Expand Down Expand Up @@ -338,37 +339,23 @@ default void setFlying(boolean flying) {
Form removeForm(int id);

/**
* Get the server setting forms of the player.
* Get the server setting form and its id.
*
* @return The server setting forms of the player.
* @return The server setting form and its id.
*/
@UnmodifiableView
Map<Integer, Form> getServerSettingForms();
Pair<Integer, CustomForm> getServerSettingForm();

/**
* Add a server setting form to the player.
* Set a server setting form to the player.
*
* @param form The form to add.
*/
void addServerSettingForm(CustomForm form);

/**
* Get a server setting form by its ID.
*
* @param id The ID of the form.
*
* @return The form.
*/
CustomForm getServerSettingForm(int id);
void setServerSettingForm(CustomForm form);

/**
* Remove a server setting form by its ID.
*
* @param id The ID of the form.
*
* @return The removed form.
* Remove the server setting form.
*/
CustomForm removeServerSettingForm(int id);
void removeServerSettingForm();

/**
* Show a form to the player.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.allaymc.server.entity.component.player;

import com.google.common.base.Preconditions;
import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -119,7 +120,8 @@ public class EntityPlayerBaseComponentImpl extends EntityBaseComponentImpl imple
protected long startUsingItemInAirTime = -1;
protected AtomicInteger formIdCounter = new AtomicInteger(0);
protected Map<Integer, Form> forms = new Int2ObjectOpenHashMap<>();
protected Map<Integer, CustomForm> serverSettingForms = new Int2ObjectOpenHashMap<>();
protected CustomForm serverSettingForm;
protected int serverSettingFormId = -1;
@Getter
protected float movementSpeed = DEFAULT_MOVEMENT_SPEED;
@ComponentedObject
Expand Down Expand Up @@ -688,23 +690,20 @@ public Form removeForm(int id) {
}

@Override
public void addServerSettingForm(CustomForm form) {
serverSettingForms.put(assignFormId(), form);
public void setServerSettingForm(CustomForm form) {
serverSettingFormId = assignFormId();
serverSettingForm = form;
}

@Override
public Map<Integer, Form> getServerSettingForms() {
return Collections.unmodifiableMap(serverSettingForms);
public Pair<Integer, CustomForm> getServerSettingForm() {
return Pair.of(serverSettingFormId, serverSettingForm);
}

@Override
public CustomForm getServerSettingForm(int id) {
return serverSettingForms.get(id);
}

@Override
public CustomForm removeServerSettingForm(int id) {
return serverSettingForms.remove(id);
public void removeServerSettingForm() {
serverSettingForm = null;
serverSettingFormId = -1;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ public void handleSync(EntityPlayer player, ModalFormResponsePacket packet, long
var form = player.removeForm(id);
var isServerSettingsForm = false;
if (form == null) {
form = player.getServerSettingForm(id);
if (form == null) {
var serverSettingForm = player.getServerSettingForm();
if (id != serverSettingForm.left()) {
log.warn("Received response for unknown form from player {}: {}", player.getOriginName(), packet.getFormId());
return;
}

form = serverSettingForm.right();
isServerSettingsForm = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ public class ServerSettingsRequestProcessor extends PacketProcessor<ServerSettin
public PacketSignal handleAsync(EntityPlayer player, ServerSettingsRequestPacket packet, long receiveTime) {
// Geyser: fixes https://bugs.mojang.com/browse/MCPE-94012 because of the delay
player.getWorld().getScheduler().scheduleDelayed(Server.getInstance(), () -> {
player.getServerSettingForms().forEach((id, form) -> {
var pk = new ServerSettingsResponsePacket();
pk.setFormId(id);
pk.setFormData(form.toJson());
player.sendPacket(pk);
});
var serverSettingForm = player.getServerSettingForm();
var pk = new ServerSettingsResponsePacket();
pk.setFormId(serverSettingForm.left());
pk.setFormData(serverSettingForm.right().toJson());
player.sendPacket(pk);
return true;
}, 20);
return PacketSignal.HANDLED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ protected void onLoad(Map<String, PluginDescriptor> descriptors, Map<String, Plu
var iterator = pluginsSortedList.iterator();
start:
while (iterator.hasNext()) {
var s = iterator.next();
var descriptor = descriptors.get(s);
var str = iterator.next();
var descriptor = descriptors.get(str);
if (descriptor == null) continue;

var loader = loaders.get(s);
var loader = loaders.get(str);
for (var dependency : descriptor.getDependencies()) {
var dependencyContainer = plugins.get(dependency.name());

Expand Down

0 comments on commit 409cf34

Please sign in to comment.