Skip to content

Commit

Permalink
Update test plugin to use the default paper builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelillo15 committed Jul 2, 2024
1 parent 689ba71 commit 47d7667
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 91 deletions.

This file was deleted.

87 changes: 13 additions & 74 deletions NookureInventory-Test/src/main/java/com/nookure/core/inv/Main.java
Original file line number Diff line number Diff line change
@@ -1,62 +1,39 @@
package com.nookure.core.inv;

import com.nookure.core.inv.paper.PaperNookureInventoryEngine;
import com.nookure.core.inv.template.extension.PaginationItemExtension;
import com.nookure.core.inv.paper.InventoryContainer;
import com.nookure.core.inv.paper.InventoryListener;
import com.nookure.core.inv.paper.PaperOpenInventoryRegistry;
import com.nookure.core.inv.paper.service.CustomActionRegistry;
import com.nookure.core.inv.parser.GuiLayout;
import jakarta.xml.bind.JAXBException;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main extends JavaPlugin implements InventoryOpener<Player> {
private NookureInventoryEngine engine;
private static Main instance;
private I18nAdapter<Player> i18nAdapter;
private final PaperOpenInventoryRegistry registry = new PaperOpenInventoryRegistry();
public class Main extends JavaPlugin {
private PaperNookureInventoryEngine engine;

@Override
public void onEnable() {
instance = this;
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
i18nAdapter = new I18nMyPluginAdapter();

try {
engine = new NookureInventoryEngine(getDataFolder().toPath(), new PaginationItemExtension());
} catch (JAXBException e) {
throw new RuntimeException(e);
}
saveResource("gui/GuiLayoutTest.xml", false);
saveResource("gui/PaginationTest.peb", true);
saveResource("gui/PaginationCommon.peb", true);

if (Bukkit.getServicesManager().load(CustomActionRegistry.class) == null) {
Bukkit.getServicesManager()
.register(
CustomActionRegistry.class,
new CustomActionRegistry(),
this,
ServicePriority.Normal
);
}

saveResource("GuiLayoutTest.xml", false);
saveResource("PaginationTest.peb", true);
saveResource("PaginationCommon.peb", true);
engine = new PaperNookureInventoryEngine.Builder()
.templateFolder("gui")
.plugin(this)
.extensions(new PaginationItemExtension())
.build();

CommandMap commandMap = Bukkit.getServer().getCommandMap();

Bukkit.getPluginManager().registerEvents(new InventoryListener(registry), this);

commandMap.register("nookure", new Command("test") {
@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
Expand All @@ -66,52 +43,14 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLab

Arrays.stream(Material.values()).forEach(material -> materials.add(material.toString()));

openInventoryAsync(player, "PaginationTest.peb", "materials", materials, "page", 1, "player", player);
engine.openAsync(player, "PaginationTest.peb", "materials", materials, "page", 1, "player", player);
return true;
}

openInventoryAsync(player, "GuiLayoutTest.xml");
engine.openAsync(player, "GuiLayoutTest.xml");
}
return true;
}
});
}

private void openInventoryAsync(Player player, String template, Object... args) {
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
GuiLayout guiLayout;

try {
if (args.length > 0) {
guiLayout = engine.parseLayout(template, args);
} else {
guiLayout = engine.parseLayout(template, "player", player);
}
} catch (JAXBException e) {
throw new RuntimeException(e);
}

Bukkit.getScheduler().runTask(this, () -> {
player.openInventory(
new InventoryContainer(
player,
guiLayout,
i18nAdapter,
registry,
Main.getInstance(),
new GuiMetadata(template, args)
).getInventory()
);
});
});
}

public static Main getInstance() {
return instance;
}

@Override
public void openAsync(@NotNull Player player, @NotNull String layout, Object... args) {
openInventoryAsync(player, layout, args);
}
}

0 comments on commit 47d7667

Please sign in to comment.