Skip to content

Commit

Permalink
Update to v1.21-0.3.1 (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmitch215 authored Oct 19, 2024
2 parents 7beffd5 + ba0c94e commit 71e3ba9
Show file tree
Hide file tree
Showing 58 changed files with 1,169 additions and 63 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ tasks {

allprojects {
val mc = "1.21"
val pr = "0.3.0"
val pr = "0.3.1"

project.ext["minecraft_version"] = mc
project.ext["project_version"] = pr
Expand All @@ -73,6 +73,7 @@ allprojects {
project.ext["license"] = "GPL-3.0"
project.ext["github"] = "https://github.com/gmitch215/SocketMC"

project.ext["similar_versions"] = listOf("1.21.1")
project.ext["version_type"] = when {
version.toString().contains("SNAPSHOT") -> "alpha"
version.toString().split("-")[1].startsWith("0") -> "beta"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* <li>Instructions are immutable and cannot be modified after creation.</li>
* <li>Instructions are serializable and can be sent over the network as byte arrays.</li>
* <li>All X, Y, Height, Width, and other measurements used in drawing instructions are in pixels.</li>
* <li>Players render things on the screen based on their own FPS (Frames Per Second), hence the provision of timed renderings in milliseconds.</li>
* <li>Players render things on the screen based on their own FPS (Frames Per Second), hence the provision of timed renderings in milliseconds. In addition, you can specify {@code -1} for an infinite duration.</li>
* <li>SocketMC v0.1.3 introduced a permission system that allows or disallows specific types of Instructions. If permission is not given, the Instruction will <i>silently</i> fail.</li>
* </ul>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.jetbrains.annotations.NotNull;
import xyz.gmitch215.socketmc.config.ModPermission;
import xyz.gmitch215.socketmc.instruction.Instruction;
import xyz.gmitch215.socketmc.spigot.SocketPlugin;
import xyz.gmitch215.socketmc.util.Identifier;
import xyz.gmitch215.socketmc.util.InputType;

import java.io.*;
Expand Down Expand Up @@ -128,6 +130,21 @@ public final class RetrieverType<T> implements Serializable {
@RetrieverPermission(ModPermission.READ_GAME_PROPERTIES)
public static final RetrieverType<UUID[]> HIDDEN_PLAYERS = new RetrieverType<>("hidden_players", UUID[].class);

/**
* <p>A retriever for all of the drawn contents on the client's screen made through SocketMC Instructions.</p>
* <p>This currently includes the following instructions:</p>
* <ul>
* <li>{@link Instruction#DRAW_TEXT}</li>
* <li>{@link Instruction#DRAW_SHAPE}</li>
* <li>{@link Instruction#DRAW_TEXTURE}</li>
* <li>{@link Instruction#DRAW_BUFFER}</li>
* <li>{@link Instruction#DRAW_CONTEXT}</li>
* <li>{@link Instruction#DRAW_ITEMSTACK}</li>
* </ul>
*/
@RetrieverPermission(ModPermission.READ_GUI_PROPERTIES)
public static final RetrieverType<Identifier[]> DRAWN_CONTENTS = new RetrieverType<>("drawn_contents", Identifier[].class);

//<editor-fold desc="Implementation" defaultstate="collapsed">

private final String id;
Expand Down
89 changes: 87 additions & 2 deletions core/src/main/java/xyz/gmitch215/socketmc/screen/CustomScreen.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package xyz.gmitch215.socketmc.screen;

import xyz.gmitch215.socketmc.screen.layout.Layout;
import xyz.gmitch215.socketmc.util.render.text.Text;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
import xyz.gmitch215.socketmc.screen.layout.Layout;
import xyz.gmitch215.socketmc.util.render.text.Text;

import java.io.Serial;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Represents a custom screen to be displayed on the client's screen.
Expand All @@ -23,6 +26,7 @@ public final class CustomScreen extends AbstractScreen {
private boolean closeableOnEscape = true;

private final List<Positionable> children = new ArrayList<>();
private final Map<String, Object> attributes = new HashMap<>();

/**
* Constructs a new screen with the given title.
Expand Down Expand Up @@ -174,14 +178,95 @@ public void setCloseableOnEscape(boolean closeableOnEscape) {
this.closeableOnEscape = closeableOnEscape;
}

/**
* Gets an immutable copy of the attributes of this screen.
* @return Map of Attributes
*/
@Unmodifiable
@NotNull
public Map<String, Object> getAttributes() {
return Map.copyOf(attributes);
}

/**
* Gets an attribute from this screen.
* @param key the key of the attribute
* @return the attribute value, or null if the attribute does not exist
* @throws IllegalArgumentException if the key is null
*/
@Nullable
public Object getAttribute(@NotNull String key) throws IllegalArgumentException {
if (key == null) throw new IllegalArgumentException("Key cannot be null");
return attributes.get(key);
}

/**
* Gets an attribute from this screen.
* @param key the key of the attribute
* @param def the default value if the attribute does not exist
* @return the attribute value, or the default value if the attribute does not exist
* @throws IllegalArgumentException if the key is null
*/
public Object getAttribute(@NotNull String key, @Nullable Object def) throws IllegalArgumentException {
if (key == null) throw new IllegalArgumentException("Key cannot be null");
return attributes.getOrDefault(key, def);
}

/**
* Gets an attribute from this screen.
* @param key the key of the attribute
* @param type the type of the attribute
* @return the attribute value, or null if the attribute does not exist
* @param <T> the type of the attribute
*/
@Nullable
public <T> T getAttribute(@NotNull String key, @NotNull Class<T> type) {
if (key == null) throw new IllegalArgumentException("Key cannot be null");
if (type == null) throw new IllegalArgumentException("Type cannot be null");

return type.cast(attributes.get(key));
}

/**
* Gets an attribute from this screen.
* @param key the key of the attribute
* @param type the type of the attribute
* @param def the default value if the attribute does not exist
* @return the attribute value, or the default value if the attribute does not exist
* @param <T> the type of the attribute
*/
@Nullable
public <T> T getAttribute(@NotNull String key, @NotNull Class<T> type, @Nullable T def) {
if (key == null) throw new IllegalArgumentException("Key cannot be null");
if (type == null) throw new IllegalArgumentException("Type cannot be null");

return type.cast(attributes.getOrDefault(key, def));
}

/**
* Sets an attribute for this screen.
* @param key the key of the attribute
* @param value the value of the attribute
* @throws IllegalArgumentException if the key is null
*/
public void setAttribute(@NotNull String key, @Nullable Object value) throws IllegalArgumentException {
if (key == null) throw new IllegalArgumentException("Key cannot be null");

if (value == null) attributes.remove(key);
else attributes.put(key, value);
}

@Override
@NotNull
public String toString() {
return "CustomScreen{" +
"title='" + titleJSON + '\'' +
", narrationMessage='" + narrationMessageJSON + '\'' +
", children=" + children +
", background=" + background +
", layout=" + layout +
", closeableOnEscape=" + closeableOnEscape +
", attributes=" + attributes +
'}';
}
}
41 changes: 41 additions & 0 deletions core/src/main/java/xyz/gmitch215/socketmc/util/Arm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package xyz.gmitch215.socketmc.util;

import org.jetbrains.annotations.NotNull;

/**
* Represents a player's arm.
*/
public enum Arm {

/**
* Represents the left arm.
*/
LEFT,

/**
* Represents the right arm.
*/
RIGHT;

/**
* Returns the opposite arm.
* @return the opposite arm
*/
@NotNull
public Arm opposite() {
return this == LEFT ? RIGHT : LEFT;
}

/**
* Gets the Arm by its ordinal.
* @param ordinal
* @return Arm by ordinal
*/
@NotNull
public static Arm byOrdinal(int ordinal) {
return values()[ordinal];
}



}
21 changes: 21 additions & 0 deletions core/src/main/java/xyz/gmitch215/socketmc/util/Identifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;
import java.util.UUID;

/**
* <p>Represents a Namespaced Identifier.</p>
Expand Down Expand Up @@ -73,4 +74,24 @@ public static Identifier minecraft(@NotNull String path) {
return new Identifier("minecraft", path);
}

/**
* Creates a new Identifier with the namespace "socketmc".
* @param path The path of the Identifier.
* @return The new Identifier.
*/
@NotNull
public static Identifier socketmc(@NotNull String path) {
return new Identifier("socketmc", path);
}

/**
* Creates a new random Identifier with the namespace "socketmc" and a random UUID as its path.
* @return The new random Identifier.
*/
@NotNull
public static Identifier random() {
UUID uuid = UUID.randomUUID();
return Identifier.socketmc(uuid.toString());
}

}
Loading

0 comments on commit 71e3ba9

Please sign in to comment.