Skip to content
This repository has been archived by the owner on Aug 31, 2019. It is now read-only.

Provide access to PlayerSettings and an event when it updates #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Electroid
Copy link
Contributor

No description provided.

@Pablete1234
Copy link
Member

A big +1, had wanted to use this info for long now, hadn't been able to because it wasn't saved anywhere (not even in nms (atleast chunk distance)) and i didn't want to do packet sniffing directly to find that.

@Pablete1234
Copy link
Member

Is there any plans on this patch being merged? I would like to use it in another project and it would be great to see this merged. I've done some testing on my own, and have not found any issues so far.

Sadly, the minecraft client has a bug where it won't send the packet to the server sometimes: #MC-108315

@jedediah
Copy link
Member

jedediah commented Oct 6, 2016

I'll review it

+/**
+ * Represents the chat preferences of a {@link org.bukkit.entity.Player}.
+ */
+public enum ChatVisibility {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe FULL, SYSTEM, HIDDEN to match the NMS enum?

+/**
+ * Various client-established settings of a {@link Player}.
+ */
+public class PlayerSettings {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do any of these fields have to be nullable? There are default values for everything, right?

+ *
+ * @return locale of the player.
+ */
+ public String getLocale() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use java.util.Locale here?

+ * Get the parts of the skin the player wants to be rendered by others.
+ * @return parts of the skin.
+ */
+ public ImmutableSet<Skin.Part> getSkinParts() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't want to introduce Guava types into the Bukkit API. I'm not sure why the dependency exists at all.

+ if(this == o) return true;
+ if(o == null || getClass() != o.getClass()) return false;
+ PlayerSettings other = (PlayerSettings) o;
+ return new EqualsBuilder()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise for Apache Commons types (EqualsBuilder and HashCodeBuilder)

+ /**
+ * Transform one enum to another enum type based on {@link Enum#ordinal()}.
+ */
+ public static <F extends Enum<F>, T extends Enum<T>> T transform(F from, Class<T> to, T def) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably throw an exception if the enums have different lengths. I would also keep it in CraftBukkit, doesn't need to be in the public API.

+
+import java.io.IOException;
+
+public class PacketPlayInSettings implements Packet<PacketListenerPlayIn> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import this file in the "Import necessary NMS classes" patch

return event;
}

- public static PlayerLocaleChangeEvent callPlayerLocaleChangeEvent(EntityHuman who, String oldLocale, String newLocale) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this patch is overwriting a lot of stuff from the locale change event patch, then it should just be combined with that patch. When we rebase, we don't want to merge code that gets thrown away in later patches.

public class EntityPlayer extends EntityHuman implements ICrafting {

private static final Logger bS = LogManager.getLogger();
- public String locale = null; // SportBukkit - make public and default to null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we copy to/from these NMS fields instead of replacing them? This approach could make rebasing difficult.

+ *
+ * @param settings the new player settings.
+ */
+ void setSettings(PlayerSettings settings);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you ever want to call this method after receiving the client settings packet? That would just desync the server and client. Maybe this method should do nothing if the packet has already been received?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants