Skip to content

Commit

Permalink
Merge pull request #2 from alpine-network/dev/0.4.0
Browse files Browse the repository at this point in the history
v0.4.0: User Interfaces
  • Loading branch information
BestBearr authored Jul 27, 2024
2 parents bde1ba4 + f4ea70a commit 2d1cf72
Show file tree
Hide file tree
Showing 96 changed files with 6,250 additions and 483 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Alpine Core
> Current version: 0.3.6
> Current version: 0.4.0
A lightweight library for creating modern yet widely compatible Minecraft server plugins.

Expand Down Expand Up @@ -37,6 +37,16 @@ The project consists of the following core systems:
- A server command that is automatically registered
- Includes a more convenient API for registering completions and conditions
- Utilizes [LiteCommands](https://github.com/Rollczi/LiteCommands) to enable the efficient creation of complex command structures
- User Interfaces
- Provides an advanced inventory GUI framework designed for simplicity, with recipe-like slot mask configuration for element placement
- Allows the efficient creation of interactive user interfaces in the plugin
- Utilizes `UIHandler` to initialize the menu to handle user interactions
- Teleportation
- Managed by `TeleportManager`
- Provides a centralized system for point-to-point teleportation
- Curate a teleportation sequence with the `TeleportTask` builder
- Handle the lifecycle of a teleportation request, from initialization to the execution
- Add a countdown, event handlers, & cancellation policies
- Events
- Extended from `AlpineEvent`
- A generic Bukkit event, minus the boilerplate
Expand All @@ -53,7 +63,7 @@ repositories {
}
dependencies {
compileOnly 'co.crystaldev:alpinecore:0.3.6'
compileOnly 'co.crystaldev:alpinecore:0.4.0'
}
```

Expand Down
23 changes: 13 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,24 @@ dependencies {
testImplementation("org.testng:testng:7.5.1") // v7.6+ requires JDK 11
testImplementation("commons-lang:commons-lang:2.6")

shade(this, "org.apache.commons:commons-dbcp2:2.12.0")
shade(this, "com.zaxxer:HikariCP:5.1.0")

shade(this, "org.jetbrains:annotations:24.1.0")
shade(this, "de.exlll:configlib-spigot:4.2.0")
shade(this, "com.github.cryptomorin:XSeries:9.9.0")
shade(this, "com.github.cryptomorin:XSeries:11.2.0.1")
shade(this, "com.github.PikaMug:LocaleLib:60b38e1fbe") // TODO: unpin version

val liteCommands = "3.4.0"
val liteCommands = "3.4.2"
shade(this, "dev.rollczi:litecommands-bukkit:$liteCommands")
shade(this, "dev.rollczi:litecommands-adventure-platform:$liteCommands")

val adventure = "4.16.0"
val adventure = "4.17.0"
shade(this, "net.kyori:adventure-platform-bukkit:4.3.0")
shade(this, "net.kyori:adventure-api:$adventure")
shade(this, "net.kyori:adventure-text-minimessage:$adventure")
shade(this, "net.kyori:adventure-text-serializer-plain:$adventure")

val lombok = "org.projectlombok:lombok:1.18.30"
val lombok = "org.projectlombok:lombok:1.18.34"
compileOnly(lombok)
annotationProcessor(lombok)
}
Expand Down Expand Up @@ -168,11 +169,13 @@ publishing {
val dependenciesNode = asNode().appendNode("dependencies")

project.configurations["api"].allDependencies.forEach { dependency ->
val dependencyNode = dependenciesNode.appendNode("dependency")
dependencyNode.appendNode("groupId", dependency.group)
dependencyNode.appendNode("artifactId", dependency.name)
dependencyNode.appendNode("version", dependency.version)
dependencyNode.appendNode("scope", "compile")
if (dependency.name != "LocaleLib") {
val dependencyNode = dependenciesNode.appendNode("dependency")
dependencyNode.appendNode("groupId", dependency.group)
dependencyNode.appendNode("artifactId", dependency.name)
dependencyNode.appendNode("version", dependency.version)
dependencyNode.appendNode("scope", "compile")
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repositories {
maven("https://lib.alpn.cloud/alpine-public/")
maven("https://repo.viaversion.com/")
maven("https://repo.panda-lang.org/releases")
maven("https://jitpack.io/")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void onStop() {
}

@Override
public void setupDefaultVariables(@NotNull VariableConsumer variableConsumer) {
public void setupVariables(@NotNull VariableConsumer variableConsumer) {
variableConsumer.addVariable("prefix", "<dark_gray>[</dark_gray><gradient:#e81cff:#40c9ff>Example</gradient><dark_gray>]</dark_gray>");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import co.crystaldev.alpinecore.AlpinePlugin;
import co.crystaldev.alpinecore.framework.command.AlpineArgumentResolver;
import co.crystaldev.alpinecore.framework.command.AlpineCommand;
import co.crystaldev.alpinecore.framework.teleport.TeleportTask;
import co.crystaldev.alpinecore.util.Components;
import co.crystaldev.alpinecore.util.Messaging;
import dev.rollczi.litecommands.annotations.argument.Arg;
import dev.rollczi.litecommands.annotations.argument.Key;
Expand All @@ -19,14 +21,18 @@
import dev.tomwmth.exampleplugin.config.Config;
import dev.tomwmth.exampleplugin.storage.Statistics;
import dev.tomwmth.exampleplugin.storage.StatisticsStore;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;

import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -56,7 +62,7 @@ public void execute(@Context CommandSender sender, @Arg("target") @Key("lookingA
}

@Execute(name = "subcommand")
public void execute(@Context Player sender, @Arg("action") ExampleAction action) {
public void executeSubcommand(@Context Player sender, @Arg("action") ExampleAction action) {
Config config = this.plugin.getConfigManager().getConfig(Config.class);
World world = sender.getWorld();
String message;
Expand All @@ -80,6 +86,36 @@ public void execute(@Context Player sender, @Arg("action") ExampleAction action)
);
}

@Execute(name = "move")
public void move(@Context Player sender, @Arg("offset_x") int x, @Arg("offset_y") int y, @Arg("offset_z") int z) {

Location destination = sender.getLocation().clone().add(x, y, z);
TeleportTask teleport = TeleportTask.builder(sender, destination)
.delay(5, TimeUnit.SECONDS)
.resetPitchAndYaw()
.onInit(ctx -> {
ctx.message(Components.joinSpaces(
Component.text("Teleporting to").color(TextColor.color(0xA6D1FD)),
Component.text(destination.getBlockX() + ", " + destination.getBlockY() + ", " + destination.getBlockZ()).color(TextColor.color(0x56CAFF))
));
})
.onCountdown(ctx -> {
ctx.message(Components.joinSpaces(
Component.text("Teleporting in:").color(TextColor.color(0xA6D1FD)),
Component.text(ctx.timeUntilTeleport(TimeUnit.SECONDS) + " second(s)").color(TextColor.color(0x56CAFF))
));
})
.onTeleport(ctx -> {
ctx.message(Component.text("Teleporting...").color(TextColor.color(0xA6D1FD)));
})
.onMove(ctx -> {
ctx.message(Component.text("Cancelled Teleportation due to movement").color(TextColor.color(0xFD3115)));
})
.build();

this.plugin.getTeleportManager().initiateTeleport(teleport);
}

private enum ExampleAction {
SPAWN_PIG,
SPAWN_COW,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package dev.tomwmth.exampleplugin.command;

import co.crystaldev.alpinecore.AlpinePlugin;
import co.crystaldev.alpinecore.framework.command.AlpineCommand;
import co.crystaldev.alpinecore.framework.ui.type.InventoryUI;
import co.crystaldev.alpinecore.util.Messaging;
import dev.rollczi.litecommands.annotations.command.Command;
import dev.rollczi.litecommands.annotations.context.Context;
import dev.rollczi.litecommands.annotations.description.Description;
import dev.rollczi.litecommands.annotations.execute.Execute;
import dev.rollczi.litecommands.annotations.permission.Permission;
import dev.tomwmth.exampleplugin.config.Config;
import dev.tomwmth.exampleplugin.ui.DemoUIHandler;
import dev.tomwmth.exampleplugin.ui.MutableUIHandler;
import dev.tomwmth.exampleplugin.ui.StackedUIHandler;
import org.bukkit.entity.Player;

/**
* @since 0.4.0
*/
@Command(name = "exampleui")
@Description("This is an example command!")
@Permission("exampleplugin.exampleui")
public final class ExampleUICommand extends AlpineCommand {
protected ExampleUICommand(AlpinePlugin plugin) {
super(plugin);
}

@Execute(name = "demoui")
public void executeDemoUI(@Context Player sender) {
Config config = this.plugin.getConfigManager().getConfig(Config.class);
InventoryUI ui = config.paginatedUI.build(this.plugin, DemoUIHandler.getInstance());
ui.view(sender);

Messaging.send(sender,
config.actionMessage.build(this.plugin,
"action", "Opened Paginated Demo Inventory UI")
);
}

@Execute(name = "mutableui")
public void executeMutableUI(@Context Player sender) {
Config config = this.plugin.getConfigManager().getConfig(Config.class);
InventoryUI ui = config.mutableUI.build(this.plugin, MutableUIHandler.getInstance());
ui.view(sender);

Messaging.send(sender,
config.actionMessage.build(this.plugin,
"action", "Opened Mutable Demo Inventory UI")
);
}

@Execute(name = "stackui")
public void executeStackUI(@Context Player sender) {
Config config = this.plugin.getConfigManager().getConfig(Config.class);
InventoryUI ui = StackedUIHandler.UI_SCREENS.get(0).build(this.plugin, new StackedUIHandler(0));
ui.view(sender);

Messaging.send(sender,
config.actionMessage.build(this.plugin,
"action", "Opened Stacked Demo Inventory UI")
);
}
}
93 changes: 93 additions & 0 deletions example/src/main/java/dev/tomwmth/exampleplugin/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import co.crystaldev.alpinecore.framework.config.AlpineConfig;
import co.crystaldev.alpinecore.framework.config.object.ConfigMessage;
import co.crystaldev.alpinecore.framework.config.object.item.DefinedConfigItem;
import co.crystaldev.alpinecore.framework.config.object.item.VaryingConfigItem;
import co.crystaldev.alpinecore.framework.ui.type.ConfigInventoryUI;
import com.cryptomorin.xseries.XMaterial;
import de.exlll.configlib.Comment;

/**
Expand All @@ -17,4 +21,93 @@ public class Config extends AlpineConfig {
"The custom tags used here are located in the AlpineCore config."
})
public ConfigMessage integrationJoinMessage = ConfigMessage.of("%prefix% <emphasis>Via reports your protocol version as <highlight>%protocol%</highlight>.</emphasis>");

@Comment({
"",
"Create an advanced and configurable inventory",
"UI with ease!"
})
public ConfigInventoryUI paginatedUI = ConfigInventoryUI.builder()
.name("<gradient:#a074f2:#f27a74><b>Test InventoryUI Screen")
.slots(
"#########",
"#|||||||#",
"#|||||||#",
"#########",
"--<-I->--"
)
.dictionary(
"#", "background",
"-", "footer",
"|", "stock-selection",
"<", "previous-page",
">", "next-page",
"I", "page-info"
)
.item("background", DefinedConfigItem
.builder(XMaterial.LIGHT_GRAY_STAINED_GLASS_PANE)
.name("")
.build())
.item("footer", DefinedConfigItem
.builder(XMaterial.BLACK_STAINED_GLASS_PANE)
.name("")
.build())
.item("previous-page", DefinedConfigItem
.builder(XMaterial.ARROW)
.name("<info>Previous Page</info> <bracket>[<emphasis>Left Click</emphasis>]</bracket>")
.build())
.item("next-page", DefinedConfigItem
.builder(XMaterial.ARROW)
.name("<info>Next Page</info> <bracket>[<emphasis>Left Click</emphasis>]</bracket>")
.build())
.item("page-info", DefinedConfigItem
.builder(XMaterial.CLOCK)
.name("<info>Page Information</info>")
.lore(
"<info> *</info> <emphasis>Current Page:</emphasis> %page%/%page_count%",
"<info> *</info> <emphasis>Total Elements:</emphasis> %element_count%"
)
.build())
.build();

@Comment("")
public VaryingConfigItem stockSelectionItem = VaryingConfigItem.builder()
.name("<highlight>%item_name%</highlight>")
.lore(
"<info> *</info> <emphasis>Price:</emphasis> $%price%/ea",
"<info> *</info> <emphasis>Purchase:</emphasis> Left Click",
"<info> *</info> <emphasis>Sell All:</emphasis> Right Click"
)
.build();

@Comment("")
public DefinedConfigItem stockPlaceholderItem = DefinedConfigItem.builder(XMaterial.WHITE_STAINED_GLASS_PANE)
.name("")
.build();

@Comment({
"",
"This is another basic UI screen meant to demo",
"user interaction with elements"
})
public ConfigInventoryUI mutableUI = ConfigInventoryUI.builder()
.name("<gradient:#a074f2:#f27a74><b>Test InventoryUI Screen")
.slots(
"#########",
"#|||||||#",
"#|||||||#",
"#|||||||#",
"#|||||||#",
"#########"
)
.dictionary(
"#", "background",
"|", "storage"
)
.item("background", DefinedConfigItem
.builder(XMaterial.BLACK_STAINED_GLASS_PANE)
.name("")
.enchanted()
.build())
.build();
}
Loading

0 comments on commit 2d1cf72

Please sign in to comment.