Initial commit
This commit is contained in:
commit
65c654d6e7
28
.gitea/workflows/maven.yml
Normal file
28
.gitea/workflows/maven.yml
Normal file
|
@ -0,0 +1,28 @@
|
|||
name: Build plugin
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: "21"
|
||||
distribution: "temurin"
|
||||
cache: maven
|
||||
- name: Install Maven
|
||||
uses: https://github.com/stCarolas/setup-maven@v4
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --file pom.xml
|
||||
- run: mkdir staging && cp target/*.jar staging
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: compiled-jar
|
||||
path: staging
|
||||
retention-days: 90
|
118
.gitignore
vendored
Normal file
118
.gitignore
vendored
Normal file
|
@ -0,0 +1,118 @@
|
|||
# User-specific stuff
|
||||
.idea/
|
||||
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
Thumbs.db:encryptable
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
target/
|
||||
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
.flattened-pom.xml
|
||||
|
||||
# Common working directory
|
||||
run/
|
||||
|
||||
.settings/
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
33
.run/SGM [build].run.xml
Normal file
33
.run/SGM [build].run.xml
Normal file
|
@ -0,0 +1,33 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="SGM [build]" type="MavenRunConfiguration" factoryName="Maven">
|
||||
<MavenSettings>
|
||||
<option name="myGeneralSettings" />
|
||||
<option name="myRunnerSettings" />
|
||||
<option name="myRunnerParameters">
|
||||
<MavenRunnerParameters>
|
||||
<option name="cmdOptions" />
|
||||
<option name="profiles">
|
||||
<set />
|
||||
</option>
|
||||
<option name="goals">
|
||||
<list>
|
||||
<option value="clean" />
|
||||
<option value="package" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="multimoduleDir" />
|
||||
<option name="pomFileName" />
|
||||
<option name="profilesMap">
|
||||
<map />
|
||||
</option>
|
||||
<option name="projectsCmdOptionValues">
|
||||
<list />
|
||||
</option>
|
||||
<option name="resolveToWorkspace" value="false" />
|
||||
<option name="workingDirPath" value="$PROJECT_DIR$" />
|
||||
</MavenRunnerParameters>
|
||||
</option>
|
||||
</MavenSettings>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
152
pom.xml
Normal file
152
pom.xml
Normal file
|
@ -0,0 +1,152 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>xyz.twovb</groupId>
|
||||
<artifactId>sgm</artifactId>
|
||||
<version>${git.branch}</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>SGM</name>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.mainClass>${project.groupId}.${project.artifactId}.${project.name}</project.mainClass>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>io.github.git-commit-id</groupId>
|
||||
<artifactId>git-commit-id-maven-plugin</artifactId>
|
||||
<version>5.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>get-the-git-infos</id>
|
||||
<goals>
|
||||
<goal>revision</goal>
|
||||
</goals>
|
||||
<phase>initialize</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<generateGitPropertiesFile>false</generateGitPropertiesFile>
|
||||
<generateGitPropertiesFilename>project.build.outputDirectory/git.properties</generateGitPropertiesFilename>
|
||||
<includeOnlyProperties>
|
||||
<includeOnlyProperty>^git.branch$</includeOnlyProperty>
|
||||
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
|
||||
<includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
|
||||
<includeOnlyProperty>^git.commit.message.short$</includeOnlyProperty>
|
||||
</includeOnlyProperties>
|
||||
<commitIdGenerationMode>full</commitIdGenerationMode>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>shade</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>xyz.twovb.toolbox</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}.toolbox</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc-repo</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype-oss-snapshots1</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>panda-repository</id>
|
||||
<url>https://repo.panda-lang.org/releases</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>twovb-repo</id>
|
||||
<name>2vb :3</name>
|
||||
<url>https://maven.twovb.xyz/releases</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.20.6-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.30</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>24.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.rollczi</groupId>
|
||||
<artifactId>litecommands-bukkit</artifactId>
|
||||
<version>3.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.twovb</groupId>
|
||||
<artifactId>Toolbox</artifactId>
|
||||
<version>0.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
96
src/main/java/xyz/twovb/sgm/SGM.java
Normal file
96
src/main/java/xyz/twovb/sgm/SGM.java
Normal file
|
@ -0,0 +1,96 @@
|
|||
package xyz.twovb.sgm;
|
||||
|
||||
import dev.rollczi.litecommands.bukkit.LiteBukkitMessages;
|
||||
import dev.rollczi.litecommands.bukkit.LiteCommandsBukkit;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import xyz.twovb.sgm.commands.impl.SGMCommand;
|
||||
import xyz.twovb.sgm.commands.handlers.InvalidArgsHandler;
|
||||
import xyz.twovb.sgm.commands.handlers.NoPermissionsHandler;
|
||||
import xyz.twovb.sgm.listeners.TestListener;
|
||||
import xyz.twovb.toolbox.managers.ConfigManager;
|
||||
import xyz.twovb.toolbox.managers.PlaceholderManager;
|
||||
import xyz.twovb.toolbox.managers.DatabaseManager;
|
||||
import xyz.twovb.toolbox.utils.ToolLogger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class SGM extends JavaPlugin {
|
||||
|
||||
@Getter
|
||||
private static SGM instance;
|
||||
private FileConfiguration BuildInfo;
|
||||
|
||||
@Getter
|
||||
private FileConfiguration Messages;
|
||||
@Getter
|
||||
private ToolLogger toolLogger;
|
||||
private ConfigManager configManager;
|
||||
@Getter
|
||||
private DatabaseManager databaseManager;
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
toolLogger = new ToolLogger(this);
|
||||
configManager = new ConfigManager(this);
|
||||
Messages = configManager.loadConfig("messages.yml");
|
||||
this.saveDefaultConfig();
|
||||
BuildInfo = new YamlConfiguration();
|
||||
try {
|
||||
BuildInfo.load(Objects.requireNonNull(this.getTextResource("build-info.yml")));
|
||||
} catch (IOException | InvalidConfigurationException ignored) {}
|
||||
registerCommands();
|
||||
registerPlaceholders();
|
||||
connectToDatabase();
|
||||
}
|
||||
|
||||
private void connectToDatabase() {
|
||||
databaseManager = new DatabaseManager();
|
||||
try {
|
||||
databaseManager.connect(DatabaseManager.DatabaseType.SQLITE, this, "sgm");
|
||||
toolLogger.log("Connected to database");
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerPlaceholders() {
|
||||
PlaceholderManager pm = new PlaceholderManager();
|
||||
pm.registerPlaceholder("%commit.id%", BuildInfo.getString("commit.id"));
|
||||
pm.registerPlaceholder("%commit.branch%", BuildInfo.getString("commit.branch"));
|
||||
pm.registerPlaceholder("%commit.message%", BuildInfo.getString("commit.message"));
|
||||
pm.registerPlaceholder("%name%", this.getName());
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
LiteCommandsBukkit.builder()
|
||||
.settings(settings -> settings.fallbackPrefix("sgm").nativePermissions(false))
|
||||
.commands(new SGMCommand())
|
||||
.invalidUsage(new InvalidArgsHandler())
|
||||
.missingPermission(new NoPermissionsHandler())
|
||||
.message(LiteBukkitMessages.PLAYER_NOT_FOUND, input -> Messages.getString("commands.invalid-player").replace("%player%", input))
|
||||
.message(LiteBukkitMessages.PLAYER_ONLY, input -> Messages.getString("commands.player-only"))
|
||||
.build();
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvents(new TestListener(), this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package xyz.twovb.sgm.commands.handlers;
|
||||
|
||||
import dev.rollczi.litecommands.handler.result.ResultHandlerChain;
|
||||
import dev.rollczi.litecommands.invalidusage.InvalidUsage;
|
||||
import dev.rollczi.litecommands.invalidusage.InvalidUsageHandler;
|
||||
import dev.rollczi.litecommands.invocation.Invocation;
|
||||
import dev.rollczi.litecommands.schematic.Schematic;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.toolbox.managers.PlaceholderManager;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class InvalidArgsHandler implements InvalidUsageHandler<CommandSender> {
|
||||
@Override
|
||||
public void handle(Invocation<CommandSender> invocation, InvalidUsage<CommandSender> result, ResultHandlerChain<CommandSender> chain) {
|
||||
CommandSender sender = invocation.sender();
|
||||
Schematic schematic = result.getSchematic();
|
||||
String message = SGM.getInstance().getMessages().getString("commands.wrong-args");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.insert(0, "\n");
|
||||
if (schematic.isOnlyFirst()) {
|
||||
message = message.replace("%usage%", "\n&8 - &7" + schematic.first());
|
||||
} else {
|
||||
List<String> schemes = schematic.all();
|
||||
for (int i = 0; i < schemes.size(); i++) {
|
||||
String scheme = schemes.get(i);
|
||||
|
||||
// Append the formatted scheme entry
|
||||
builder.append("&8 - &7").append(scheme);
|
||||
|
||||
// Check if the current element is not the last one
|
||||
if (i < schemes.size() - 1) {
|
||||
builder.append("\n"); // Append newline if not the last element
|
||||
}
|
||||
}
|
||||
message = message.replace("%usage%", builder.toString());
|
||||
}
|
||||
sender.sendMessage(ChatUtils.translate(PlaceholderManager.setPlaceholders(message, sender)));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package xyz.twovb.sgm.commands.handlers;
|
||||
|
||||
import dev.rollczi.litecommands.handler.result.ResultHandlerChain;
|
||||
import dev.rollczi.litecommands.invocation.Invocation;
|
||||
import dev.rollczi.litecommands.permission.MissingPermissions;
|
||||
import dev.rollczi.litecommands.permission.MissingPermissionsHandler;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import xyz.twovb.sgm.SGM;
|
||||
|
||||
public class NoPermissionsHandler implements MissingPermissionsHandler<CommandSender> {
|
||||
@Override
|
||||
public void handle(Invocation<CommandSender> invocation, MissingPermissions missingPermissions, ResultHandlerChain<CommandSender> chain) {
|
||||
String permissions = missingPermissions.asJoinedText();
|
||||
CommandSender sender = invocation.sender();
|
||||
sender.sendMessage(SGM.getInstance().getMessages().getString("commands.no-permissions").replace("%permission%", permissions));
|
||||
}
|
||||
}
|
27
src/main/java/xyz/twovb/sgm/commands/impl/SGMCommand.java
Normal file
27
src/main/java/xyz/twovb/sgm/commands/impl/SGMCommand.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package xyz.twovb.sgm.commands.impl;
|
||||
|
||||
import dev.rollczi.litecommands.annotations.command.Command;
|
||||
import dev.rollczi.litecommands.annotations.context.Context;
|
||||
import dev.rollczi.litecommands.annotations.execute.Execute;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import xyz.twovb.$REPO_NAME_LOWER.SGM
|
||||
import xyz.twovb.toolbox.managers.PlaceholderManager;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
|
||||
@Command(name = "sgm")
|
||||
public class SGMCommand {
|
||||
|
||||
@Execute
|
||||
void command(@Context CommandSender sender) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.insert(0, SGM.getInstance().getMessages().getString("main-command.lines.1"));
|
||||
builder.append("\n");
|
||||
builder.append(SGM.getInstance().getMessages().getString("main-command.lines.2"));
|
||||
builder.append("\n");
|
||||
builder.append(SGM.getInstance().getMessages().getString("main-command.lines.3"));
|
||||
String string = builder.toString();
|
||||
sender.sendMessage(ChatUtils.translate(PlaceholderManager.setPlaceholders(string, sender)));
|
||||
}
|
||||
|
||||
}
|
16
src/main/java/xyz/twovb/sgm/listeners/TestListener.java
Normal file
16
src/main/java/xyz/twovb/sgm/listeners/TestListener.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
package xyz.twovb.sgm.listeners;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class TestListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onLogin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
player.sendMessage("Hello " + player.getName());
|
||||
}
|
||||
|
||||
}
|
5
src/main/resources/build-info.yml
Normal file
5
src/main/resources/build-info.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
commit:
|
||||
branch: ${git.branch}
|
||||
build-time: ${git.build.time}
|
||||
id: ${git.commit.id.abbrev}
|
||||
message: ${git.commit.message.short}
|
0
src/main/resources/config.yml
Normal file
0
src/main/resources/config.yml
Normal file
10
src/main/resources/messages.yml
Normal file
10
src/main/resources/messages.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
main-command:
|
||||
lines:
|
||||
1: "&e%name%&7 - Build:&e %commit.id%"
|
||||
2: "&7Branch:&e %commit.branch%"
|
||||
3: "&7Commit Message:&e %commit.message%"
|
||||
commands:
|
||||
invalid-player: "&7Player &e%player%&f not found."
|
||||
player-only: "&7You must be a player to run this command."
|
||||
no-permissions: "&7You do not have the required permission &e%permission%&7 to do this."
|
||||
wrong-args: "&7Invalid command usage. %usage%"
|
6
src/main/resources/plugin.yml
Normal file
6
src/main/resources/plugin.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
name: '${project.name}'
|
||||
version: 'Git-${git.commit.id.abbrev}-${project.version}'
|
||||
main: '${project.mainClass}'
|
||||
author: '2vb'
|
||||
api-version: '1.20'
|
||||
softdepend: [PlaceholderAPI]
|
Loading…
Reference in New Issue
Block a user