Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
plugins {
java
`maven-publish`
id("com.gradleup.shadow") version "9.2.2"
}

repositories {
mavenLocal()

maven {
url = uri("https://repo.papermc.io/repository/maven-public/")
}
Expand All @@ -13,6 +16,10 @@ repositories {
}

mavenCentral()

maven {
url = uri("https://repo.infernalsuite.com/repository/maven-snapshots/")
}
}

dependencies {
Expand All @@ -21,6 +28,8 @@ dependencies {
compileOnly("io.papermc.paper:paper-api:26.1.2.build.+")
implementation("org.apache.commons:commons-lang3:3.20.0")
compileOnly("dev.plex:api:2.0-SNAPSHOT")
compileOnly("com.infernalsuite.asp:api:4.0.0-SNAPSHOT")
implementation("com.infernalsuite.asp:file-loader:4.0.0-SNAPSHOT")
implementation("org.jetbrains:annotations:26.1.0")
}

Expand All @@ -45,6 +54,16 @@ tasks.getByName<Jar>("jar") {
archiveVersion.set("")
}

tasks.shadowJar {
archiveBaseName.set("Module-Guilds")
archiveClassifier.set("")
archiveVersion.set("")
}

tasks.build {
dependsOn(tasks.shadowJar)
}

tasks {
compileJava {
options.encoding = Charsets.UTF_8.name()
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/dev/plex/Guilds.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import dev.plex.config.ModuleConfig;
import dev.plex.guild.GuildHolder;
import dev.plex.handler.ChatHandlerImpl;
import dev.plex.handler.GuildMenuListener;
import dev.plex.handler.GuildWorldProtectionListener;
import dev.plex.handler.RankPermissionMenuListener;
import dev.plex.module.PlexModule;
import dev.plex.api.storage.ModuleStorage;
import dev.plex.storage.GuildRepository;
import dev.plex.storage.JdbiGuildRepository;
import dev.plex.world.GuildWorldService;
import lombok.Getter;

import java.sql.SQLException;
Expand All @@ -18,6 +22,10 @@ public class Guilds extends PlexModule
{
private static Guilds module;
private final GuildHolder guildHolder = new GuildHolder();
private final GuildMenuListener guildMenuListener = new GuildMenuListener();
private final GuildWorldProtectionListener guildWorldProtectionListener = new GuildWorldProtectionListener();
private final RankPermissionMenuListener rankPermissionMenuListener = new RankPermissionMenuListener();
private final GuildWorldService guildWorldService = new GuildWorldService();

private GuildRepository guildRepository;

Expand All @@ -36,10 +44,11 @@ public void load()
@Override
public void enable()
{
guildWorldService.enable();
ModuleStorage storage = api().storage().forModule(this);
try
{
storage.migrations().run(List.of("001_initial_schema"));
storage.migrations().run(List.of("001_initial_schema", "002_guild_world_permissions"));
}
catch (SQLException e)
{
Expand All @@ -62,11 +71,15 @@ public void enable()
guildHolder.replaceAll(guilds);
});
registerListener(new ChatHandlerImpl());
registerListener(guildMenuListener);
registerListener(guildWorldProtectionListener);
registerListener(rankPermissionMenuListener);
}

@Override
public void disable()
{
guildWorldService.disable();
guildHolder.clear();
}

Expand Down
13 changes: 12 additions & 1 deletion src/main/java/dev/plex/command/GuildCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,29 @@ public GuildCommand()
this.registerSubCommand(new ChatSubCommand());
this.registerSubCommand(new SetHomeSubCommand());
this.registerSubCommand(new HomeSubCommand());
this.registerSubCommand(new WorldSubCommand());
this.registerSubCommand(new PermissionsSubCommand());
this.registerSubCommand(new OwnerSubCommand());
this.registerSubCommand(new InviteSubCommand());
this.registerSubCommand(new AcceptSubCommand());
this.registerSubCommand(new DenySubCommand());
this.registerSubCommand(new MenuSubCommand());
}

@Override
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
{
if (args.length == 0)
{
return getSubs();
if (player == null)
{
return getSubs();
}
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(
guild -> Guilds.get().getGuildMenuListener().openHome(player, guild),
() -> player.sendMessage(messageComponent("guildNotFound"))
);
return null;
}
if (args[0].equalsIgnoreCase("help"))
{
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/dev/plex/command/sub/CreateSubCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ protected Component execute(@NotNull CommandSender commandSender, @Nullable Play
{
return messageComponent("alreadyInGuild");
}
Guilds.get().getGuildRepository().createGuild(player, StringUtils.join(args, " ")).whenComplete((guild, throwable) ->
Guilds.get().getGuildRepository().createGuild(player, StringUtils.join(args, " "))
.thenCompose(guild -> Guilds.get().getGuildWorldService().ensureWorld(guild).thenApply(world -> guild))
.whenComplete((guild, throwable) ->
{
if (throwable != null)
{
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/dev/plex/command/sub/MenuSubCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package dev.plex.command.sub;

import dev.plex.Guilds;
import dev.plex.command.source.RequiredCommandSource;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class MenuSubCommand extends GuildSubCommand
{
public MenuSubCommand()
{
super(command("menu")
.description("Opens the guild management menu")
.usage("/guild <command>")
.aliases("gui,panel")
.permission("plex.guilds.menu")
.source(RequiredCommandSource.IN_GAME)
.build());
}

@Override
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
{
assert player != null;
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(
guild -> Guilds.get().getGuildMenuListener().openHome(player, guild),
() -> send(player, messageComponent("guildNotFound"))
);
return null;
}
}
39 changes: 39 additions & 0 deletions src/main/java/dev/plex/command/sub/PermissionsSubCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package dev.plex.command.sub;

import dev.plex.Guilds;
import dev.plex.command.source.RequiredCommandSource;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class PermissionsSubCommand extends GuildSubCommand
{
public PermissionsSubCommand()
{
super(command("permissions")
.description("Opens the rank permissions GUI")
.usage("/guild <command>")
.aliases("perms")
.permission("plex.guilds.permissions")
.source(RequiredCommandSource.IN_GAME)
.build());
}

@Override
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
{
assert player != null;
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild ->
{
if (!guild.isOwner(player.getUniqueId()))
{
send(player, messageComponent("guildNotOwner"));
return;
}
Guilds.get().getRankPermissionMenuListener().openRankList(player, guild);
}, () -> send(player, messageComponent("guildNotFound")));
return null;
}
}
55 changes: 55 additions & 0 deletions src/main/java/dev/plex/command/sub/WorldSubCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package dev.plex.command.sub;

import dev.plex.Guilds;
import dev.plex.command.source.RequiredCommandSource;
import net.kyori.adventure.text.Component;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class WorldSubCommand extends GuildSubCommand
{
public WorldSubCommand()
{
super(command("world")
.description("Teleports to your guild world")
.usage("/guild <command>")
.aliases("base")
.permission("plex.guilds.world")
.source(RequiredCommandSource.IN_GAME)
.build());
}

@Override
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
{
assert player != null;
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild ->
{
send(player, messageComponent("guildWorldLoading"));
Guilds.get().getGuildWorldService().ensureWorld(guild).whenComplete((world, throwable) ->
{
if (throwable != null)
{
Guilds.get().api().scheduler().executeGlobal(() ->
{
throwable.printStackTrace();
send(player, messageComponent("guildWorldLoadFailed"));
});
return;
}
Guilds.get().api().scheduler().executeEntity(player, () -> teleport(player, world), 1L);
});
}, () -> send(player, messageComponent("guildNotFound")));
return null;
}

private void teleport(Player player, World world)
{
Location spawnLocation = world.getSpawnLocation().toCenterLocation();
player.teleportAsync(spawnLocation);
}
}
17 changes: 17 additions & 0 deletions src/main/java/dev/plex/gui/GuildMenuInventoryHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dev.plex.gui;

import dev.plex.guild.Guild;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

public record GuildMenuInventoryHolder(Guild guild, GuildMenuView view, UUID memberUuid) implements InventoryHolder
{
@Override
public @NotNull Inventory getInventory()
{
throw new UnsupportedOperationException();
}
}
8 changes: 8 additions & 0 deletions src/main/java/dev/plex/gui/GuildMenuView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dev.plex.gui;

public enum GuildMenuView
{
HOME,
MEMBERS,
MEMBER
}
15 changes: 15 additions & 0 deletions src/main/java/dev/plex/gui/RankPermissionInventoryHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev.plex.gui;

import dev.plex.guild.Guild;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull;

public record RankPermissionInventoryHolder(Guild guild, String rankName) implements InventoryHolder
{
@Override
public @NotNull Inventory getInventory()
{
throw new UnsupportedOperationException();
}
}
Loading
Loading