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
65 changes: 62 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.pinont</groupId>
<artifactId>singularitylib</artifactId>
<version>1.0.0</version>
<version>1.3.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>SingularityLib</name>
Expand Down Expand Up @@ -52,6 +52,9 @@

<properties>
<java.version>23</java.version>
<paperapi.version>1.21.8-R0.1-SNAPSHOT</paperapi.version>
<mockbukkit.version>4.87.0</mockbukkit.version>
<paper.version.from.mockbukkit>${paperapi.version}</paper.version.from.mockbukkit>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.release>${java.version}</maven.compiler.release>
Expand All @@ -74,6 +77,10 @@
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<build>
Expand Down Expand Up @@ -130,6 +137,40 @@
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.2</version>
</plugin>


<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
// Extract Paper version from MockBukkit JAR
def mockbukkitJar = project.artifacts.find {
it.artifactId.startsWith('mockbukkit-')
}?.file

if (mockbukkitJar) {
def jar = new java.util.jar.JarFile(mockbukkitJar)
def manifest = jar.manifest
def paperVersion = manifest.mainAttributes.getValue('Paper-Version')
jar.close()

if (paperVersion) {
project.properties['paper.version.from.mockbukkit'] = paperVersion
}
}
</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

<resources>
Expand All @@ -144,7 +185,13 @@
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.8-R0.1-SNAPSHOT</version>
<version>${paperapi.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dev.folia</groupId>
<artifactId>folia-api</artifactId>
<version>${paperapi.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -165,7 +212,13 @@
<dependency>
<groupId>org.mockbukkit.mockbukkit</groupId>
<artifactId>mockbukkit-v1.21</artifactId>
<version>4.77.0</version>
<version>${mockbukkit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>${paper.version.from.mockbukkit}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -174,5 +227,11 @@
<version>2.0.16</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.Pinont</groupId>
<artifactId>Singularity-DevTool</artifactId>
<version>cbd0e31e44</version>
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using a git commit hash as a version for the Singularity-DevTool dependency is not recommended for production. Consider using a tagged release version for better version tracking and stability.

Suggested change
<version>cbd0e31e44</version>
<version>1.2.0</version>

Copilot uses AI. Check for mistakes.
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.pinont.singularitylib.plugin;
package com.github.pinont.plugin;

import com.github.pinont.plugin.listener.PlayerListener;
import com.github.pinont.singularitylib.api.command.SimpleCommand;
import com.github.pinont.singularitylib.api.manager.ConfigManager;
import com.github.pinont.singularitylib.plugin.listener.PlayerListener;
import com.github.pinont.singularitylib.plugin.register.Register;
import com.github.pinont.plugin.register.Register;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
Expand Down Expand Up @@ -45,12 +45,17 @@ public CorePlugin() {

private static String prefix;
private static Long startTime;
private static boolean isFolia;

/**
* Flag indicating if the plugin is running in test mode.
*/
public boolean isTest = false;

public static boolean isFolia() {
return isFolia;
}

/**
* Gets the time when the plugin started loading.
*
Expand Down Expand Up @@ -94,8 +99,8 @@ public static void sendConsoleMessage(String message) {
* @return the API version string
*/
public static String getAPIVersion() {
String version = new ConfigManager("api-version.yml").getConfig().getString("version");
// String version = "1.0.0";
new ConfigManager("api-version.yml").saveConfig();
String version = new ConfigManager("api-version.yml").getConfig().getString("version") == null ? "1.0.0" : new ConfigManager("api-version.yml").getConfig().getString("version");
return "V-" + version;
}

Expand Down Expand Up @@ -164,6 +169,11 @@ public final void onEnable() {
// TODO: Move to Devtool
// WorldManager.autoLoadWorlds();

isFolia = foliaCheck();
if (isFolia) {
sendConsoleMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "Folia environment detected, enabling Folia compatibility mode...");
}

// Initialize API To Plugin.
sendConsoleMessage(ChatColor.WHITE + "" + ChatColor.ITALIC + "Hooked " + ChatColor.YELLOW + ChatColor.ITALIC + this.getName() + ChatColor.WHITE + ChatColor.ITALIC + " into " + ChatColor.LIGHT_PURPLE + ChatColor.ITALIC + "SingularityAPI! " + getAPIVersion());
onPluginStart();
Expand All @@ -178,6 +188,15 @@ public final void onEnable() {
}
}

private boolean foliaCheck() {
try {
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}

private void registerAPIListener(Plugin plugin, Listener... listener) {
sendConsoleMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "Initializing API listeners for " + plugin.getName() + "...");
for (Listener l : listener) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.github.pinont.plugin.listener;

import com.github.pinont.singularitylib.api.annotation.AutoRegister;
import com.github.pinont.singularitylib.api.event.PlayerDamageByPlayerEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;

@AutoRegister
public class EntityDamageListener implements Listener {

@EventHandler
public void onEntityDamage(EntityDamageByEntityEvent event) {
if (event.getEntity() instanceof Player player && event.getDamager() instanceof Player damager) {
PlayerDamageByPlayerEvent playerDamageEvent = new PlayerDamageByPlayerEvent(player, damager);
event.setCancelled(playerDamageEvent.callEvent());
}
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.pinont.singularitylib.plugin.listener;
package com.github.pinont.plugin.listener;

import com.destroystokyo.paper.event.player.PlayerRecipeBookClickEvent;
import com.github.pinont.plugin.CorePlugin;
import com.github.pinont.singularitylib.api.event.ItemExecuteEvent;
import com.github.pinont.singularitylib.api.items.ItemCreator;
import com.github.pinont.singularitylib.api.items.ItemInteraction;
import com.github.pinont.singularitylib.api.ui.Button;
import com.github.pinont.singularitylib.api.ui.Menu;
Expand All @@ -24,19 +24,16 @@

import java.util.Objects;

import static com.github.pinont.singularitylib.plugin.CorePlugin.*;
import static com.github.pinont.singularitylib.api.items.ItemInteraction.*;
import static com.github.pinont.plugin.CorePlugin.*;

/**
* Event listener for handling player interactions and menu operations.
* Manages item interactions, inventory clicks, and player join/leave events.
*/
public class PlayerListener implements Listener {

/**
* Default constructor for PlayerListener.
*/
public PlayerListener() {
}
private final Plugin plugin = CorePlugin.getInstance();

/**
* Handles player interaction events for custom item interactions.
Expand All @@ -47,11 +44,11 @@ public PlayerListener() {
public void interaction(PlayerInteractEvent event) {
Player player = event.getPlayer();
ItemStack item = player.getInventory().getItemInMainHand();
if (!Common.isMainHandEmpty(player) && ItemCreator.isItemHasPersistData(item, "interaction", PersistentDataType.STRING)) {
if (!Common.isMainHandEmpty(player) && isItemHasPersistData(plugin, item, "interaction", PersistentDataType.STRING)) {
if (event.getPlayer().getCooldown(item) > 0) return;
ItemInteraction itemInteraction;
try {
itemInteraction = ItemCreator.getInteraction(item);
itemInteraction = getInteraction(plugin, item);
} catch (IllegalArgumentException e) {
sendInteractionError(player);
return;
Expand Down Expand Up @@ -171,7 +168,7 @@ private void removePlayerMetadata(Player player, Plugin plugin, String... keys)
}

private void sendInteractionError(Player player) {
sendConsoleMessage("Interaction ID is not valid: " + ItemCreator.getItemPersistData(player.getInventory().getItemInMainHand(), "interaction", PersistentDataType.STRING));
sendConsoleMessage("Interaction ID is not valid: " + getItemPersistData(plugin, player.getInventory().getItemInMainHand(), "interaction", PersistentDataType.STRING));
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.pinont.singularitylib.plugin.register;
package com.github.pinont.plugin.register;

import com.github.pinont.singularitylib.api.annotation.AutoRegister;
import com.github.pinont.singularitylib.api.command.SimpleCommand;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.github.pinont.singularitylib.api.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

/**
* Annotation to mark classes for automatic registration by the plugin.
* This annotation is used to mark classes that need to be registered during the plugin's startup process.
Expand All @@ -9,6 +12,8 @@
* <b>Hint:</b> Use this annotation to register commands, events, or custom items.
* It should only be used when the class extends {@code CustomItem}, {@code SimpleCommand}, or {@code Listener}.
*/

@Target({ElementType.TYPE})
public @interface AutoRegister {
/**
* Indicates that the annotated class should be automatically registered by the plugin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ public interface SimpleCommand extends BasicCommand {
*/
String getName();

// /**
// * Gets the description of the command.
// * This description is used in help messages and command documentation.
// *
// * @return the command description
// */
// String getDescription();

/**
* Gets the usage string for this command.
*
Expand All @@ -25,12 +33,4 @@ public interface SimpleCommand extends BasicCommand {
default String usage(Boolean bool) {
return "/" + getName();
}

/**
* Gets the description of the command.
* This description is used in help messages and command documentation.
*
* @return the command description
*/
String description();
}
Loading