Skip to content

Commit

Permalink
* Using full implementation of AnvilGUI for now to fix mapping issues.
Browse files Browse the repository at this point in the history
* Fixed LegacyCheckService.java
  • Loading branch information
Hempfest committed Sep 30, 2024
1 parent 7d727da commit c7bdf14
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.sanctum.labyrinth.library.StringUtils;
import com.github.sanctum.panther.annotation.Removal;
import com.github.sanctum.panther.util.PantherString;
import org.bukkit.Bukkit;

/**
Expand All @@ -10,7 +11,7 @@
@Removal
public interface LegacyCheckService extends Service {

String VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3].substring(1);
String VERSION = new WesVersionMatcher().match();

default boolean isModded() {
return StringUtils.use(Bukkit.getServer().getName()).containsIgnoreCase("forge", "magma");
Expand All @@ -31,6 +32,10 @@ default boolean isLegacy() {
return fin >= 8 && fin < 14;
}

default boolean isJava20() {
return new PantherString(VERSION).contains("1_20_R3", "1_20_R4", "1_20_R5", "1_20_R6", "1_21");
}

/**
* Check if the environment of the server is newer.
*
Expand Down
5 changes: 5 additions & 0 deletions labyrinth-gui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui</artifactId>
<version>1.10.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.the-h-team</groupId>
<artifactId>labyrinth-skulls</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.github.sanctum.labyrinth.gui.unity.construct;

import com.github.sanctum.labyrinth.LabyrinthProvider;
import com.github.sanctum.labyrinth.api.LabyrinthAPI;
import com.github.sanctum.labyrinth.api.LegacyCheckService;
import com.github.sanctum.labyrinth.data.service.AnvilMechanics;
import com.github.sanctum.labyrinth.gui.unity.impl.InventoryElement;
import com.github.sanctum.labyrinth.gui.unity.impl.OpeningElement;
import com.github.sanctum.labyrinth.gui.unity.impl.PreProcessElement;
import com.github.sanctum.labyrinth.library.StringUtils;
import net.wesjd.anvilgui.AnvilGUI;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
Expand All @@ -14,12 +18,16 @@ public class PrintableMenu extends Menu {
public PrintableMenu(Plugin host, String title, Rows rows, Type type, Property... properties) {
super(host, title, rows, type, properties);
this.properties.add(Property.SHAREABLE);
AnvilMechanics mechanics = Bukkit.getServicesManager().load(AnvilMechanics.class);
if (mechanics != null) {
addElement(new InventoryElement.Printable(title, mechanics, this));
if (!LabyrinthProvider.getInstance().isJava20()) {
AnvilMechanics mechanics = Bukkit.getServicesManager().load(AnvilMechanics.class);
if (mechanics != null) {
addElement(new InventoryElement.Printable(title, mechanics, this));
} else {
LabyrinthProvider.getInstance().getLogger().severe("- No anvil mechanic service found!!");
addElement(new InventoryElement.Printable(title, (AnvilMechanics) null, this));
}
} else {
LabyrinthProvider.getInstance().getLogger().severe("- No anvil mechanic service found!!");
addElement(new InventoryElement.Printable(title, null, this));
addElement(new InventoryElement.Printable(title, new AnvilGUI.Builder().plugin(LabyrinthProvider.getInstance().getPluginInstance()).title(StringUtils.use(title).translate()), this));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@
import com.github.sanctum.panther.util.AbstractPaginatedCollection;
import com.github.sanctum.panther.util.SpecialID;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import net.wesjd.anvilgui.AnvilGUI;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -966,6 +962,8 @@ public synchronized void open(Player player) {
public static class Printable extends InventoryElement {

private final AnvilMechanics nms;
private final AnvilGUI.Builder builder;
private AnvilGUI gui = null;

private int containerId;

Expand All @@ -974,6 +972,13 @@ public static class Printable extends InventoryElement {
public Printable(String title, AnvilMechanics mechanics, Menu menu) {
super(StringUtils.use(title).translate(), menu, true);
this.nms = mechanics;
this.builder = null;
}

public Printable(String title, AnvilGUI.Builder builder, Menu menu) {
super(StringUtils.use(title).translate(), menu, true);
this.nms = null;
this.builder = builder;
}

public boolean isVisible(Player player) {
Expand All @@ -986,17 +991,25 @@ public synchronized void close(Player player) {
}

public void close(Player player, boolean sendPacket) {
if (nms == null || !visible.contains(player)) return;
if (!visible.contains(player)) return;
visible.remove(player);
AnvilMechanics.Container container = nms.getContainer(player);
if (container != null) container.close(player);
if (nms != null) {
AnvilMechanics.Container container = nms.getContainer(player);
if (container != null) container.close(player);
} else {
if (this.gui != null) {
this.gui.closeInventory();
} else {
// TODO: input warning message
}
}
}

@Override
public void open(Player player) {
if (nms == null) {
if (this.builder == null && nms == null) {
Mailer mailer = Mailer.empty(player).prefix().start("&7[").middle("&2&lLabyrinth").end("&7]").finish();
String reason = LabyrinthProvider.getInstance().isModded() ? "Modded Environment" : "Unknown";
String reason = LabyrinthProvider.getInstance().isModded() ? "Modded Environment" : "Missing version support";
mailer.chat("&c&lAn internal matter has prevented you from accessing this menu.").deploy(m -> {
if (player.isOp()) {
mailer.chat("&eReason: &f" + reason).queue();
Expand All @@ -1006,26 +1019,43 @@ public void open(Player player) {
return;
}

final AnvilMechanics.Container container = nms.newContainer(player, this.getTitle(), true);

setElement(container.getBukkitInventory());
if (this.builder == null) {
final AnvilMechanics.Container container = nms.newContainer(player, this.getTitle(), true);

for (ItemElement<?> it : getAttachment()) {
if (it.getSlot().isPresent()) {
int slot = it.getSlot().get();
if (slot == 0) {
getElement().setItem(0, it.getElement());
}
if (slot == 1) {
getElement().setItem(1, it.getElement());
setElement(container.getBukkitInventory());
for (ItemElement<?> it : getAttachment()) {
if (it.getSlot().isPresent()) {
int slot = it.getSlot().get();
if (slot == 0) {
getElement().setItem(0, it.getElement());
}
if (slot == 1) {
getElement().setItem(1, it.getElement());
}
if (slot == 2) {
getElement().setItem(2, it.getElement());
}
}
if (slot == 2) {
getElement().setItem(2, it.getElement());
}

container.open(player);
} else {
for (ItemElement<?> it : getAttachment()) {
if (it.getSlot().isPresent()) {
int slot = it.getSlot().get();
if (slot == 0) {
builder.itemLeft(it.getElement());
}
if (slot == 1) {
builder.itemRight(it.getElement());
}
}
}
builder.onClick((integer, stateSnapshot) -> Collections.emptyList());
this.gui = builder.open(player);
setElement(gui.getInventory());
}

container.open(player);
visible.add(player);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.event.EventHandler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.sanctum.labyrinth.data.service;

import com.github.sanctum.labyrinth.LabyrinthProvider;
import com.github.sanctum.labyrinth.api.LabyrinthAPI;
import com.github.sanctum.labyrinth.api.LegacyCheckService;
import com.github.sanctum.labyrinth.data.FileList;
import com.github.sanctum.panther.annotation.Ordinal;
import com.github.sanctum.panther.util.Task;
Expand Down Expand Up @@ -42,11 +44,16 @@ public static final class Handshake extends Task {
Handshake(LabyrinthAPI instance) {
super("Labyrinth-Handshake", TaskChain.getSynchronous());
this.instance = instance;
this.version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3].substring(1);
this.version = LegacyCheckService.VERSION;
}

@Ordinal
private void initialize() {
if (LabyrinthProvider.getInstance().isJava20()) {
instance.getLogger().info("- Using new mappings " + version + ", switching to WesJD AnvilGUI.");
return;
}

if (!shook) {
// create a stream containing the version jar.
InputStream stream = instance.getPluginInstance().getResource(version + ".jar");
Expand Down Expand Up @@ -84,6 +91,7 @@ private void initialize() {
if (mechanics != null) {
if (!service.getServerVersion().contains(version)) {
instance.getLogger().severe("- Version service " + service.getServerVersion() + " invalid for " + version);
instance.getLogger().severe("- Anvil GUI interfacing will not work correctly.");
return;
}
Bukkit.getServicesManager().register(AnvilMechanics.class, mechanics, instance.getPluginInstance(), ServicePriority.High);
Expand Down
34 changes: 34 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,36 @@
<compilerArgument>-XDignore.symbol.file</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version> <!-- The version must be at least 3.5.0 -->
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>net.wesjd.anvilgui</pattern>
<shadedPattern>com.github.sanctum.labyrinth.anvilgui</shadedPattern> <!-- Replace [YOUR_PLUGIN_PACKAGE] with your namespace -->
</relocation>
</relocations>
<filters>
<filter>
<artifact>*:*</artifact>
<excludeDefaults>false</excludeDefaults>
<includes>
<include>net/wesjd/anvilgui/**</include>
</includes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
Expand Down Expand Up @@ -117,6 +147,10 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>codemc-snapshots</id>
<url>https://repo.codemc.io/repository/maven-snapshots/</url>
</repository>
</repositories>

<dependencyManagement>
Expand Down

0 comments on commit c7bdf14

Please sign in to comment.