Skip to content

Commit db0b33f

Browse files
authored
Merge pull request #6 from Pinont/dev
Bump into Plugin Version
2 parents 5c0ec11 + 1e7df84 commit db0b33f

34 files changed

Lines changed: 860 additions & 1915 deletions

pom.xml

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.pinont</groupId>
88
<artifactId>singularitylib</artifactId>
9-
<version>1.0.0</version>
9+
<version>1.3.0-SNAPSHOT</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SingularityLib</name>
@@ -52,6 +52,9 @@
5252

5353
<properties>
5454
<java.version>23</java.version>
55+
<paperapi.version>1.21.8-R0.1-SNAPSHOT</paperapi.version>
56+
<mockbukkit.version>4.87.0</mockbukkit.version>
57+
<paper.version.from.mockbukkit>${paperapi.version}</paper.version.from.mockbukkit>
5558
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5659
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
5760
<maven.compiler.release>${java.version}</maven.compiler.release>
@@ -74,6 +77,10 @@
7477
<id>sonatype</id>
7578
<url>https://oss.sonatype.org/content/groups/public/</url>
7679
</repository>
80+
<repository>
81+
<id>jitpack.io</id>
82+
<url>https://jitpack.io</url>
83+
</repository>
7784
</repositories>
7885

7986
<build>
@@ -130,6 +137,40 @@
130137
<artifactId>maven-deploy-plugin</artifactId>
131138
<version>3.1.2</version>
132139
</plugin>
140+
141+
142+
<plugin>
143+
<groupId>org.codehaus.gmaven</groupId>
144+
<artifactId>groovy-maven-plugin</artifactId>
145+
<version>2.1.1</version>
146+
<executions>
147+
<execution>
148+
<phase>initialize</phase>
149+
<goals>
150+
<goal>execute</goal>
151+
</goals>
152+
<configuration>
153+
<source>
154+
// Extract Paper version from MockBukkit JAR
155+
def mockbukkitJar = project.artifacts.find {
156+
it.artifactId.startsWith('mockbukkit-')
157+
}?.file
158+
159+
if (mockbukkitJar) {
160+
def jar = new java.util.jar.JarFile(mockbukkitJar)
161+
def manifest = jar.manifest
162+
def paperVersion = manifest.mainAttributes.getValue('Paper-Version')
163+
jar.close()
164+
165+
if (paperVersion) {
166+
project.properties['paper.version.from.mockbukkit'] = paperVersion
167+
}
168+
}
169+
</source>
170+
</configuration>
171+
</execution>
172+
</executions>
173+
</plugin>
133174
</plugins>
134175

135176
<resources>
@@ -144,7 +185,13 @@
144185
<dependency>
145186
<groupId>io.papermc.paper</groupId>
146187
<artifactId>paper-api</artifactId>
147-
<version>1.21.8-R0.1-SNAPSHOT</version>
188+
<version>${paperapi.version}</version>
189+
<scope>provided</scope>
190+
</dependency>
191+
<dependency>
192+
<groupId>dev.folia</groupId>
193+
<artifactId>folia-api</artifactId>
194+
<version>${paperapi.version}</version>
148195
<scope>provided</scope>
149196
</dependency>
150197
<dependency>
@@ -165,7 +212,13 @@
165212
<dependency>
166213
<groupId>org.mockbukkit.mockbukkit</groupId>
167214
<artifactId>mockbukkit-v1.21</artifactId>
168-
<version>4.77.0</version>
215+
<version>${mockbukkit.version}</version>
216+
<scope>test</scope>
217+
</dependency>
218+
<dependency>
219+
<groupId>io.papermc.paper</groupId>
220+
<artifactId>paper-api</artifactId>
221+
<version>${paper.version.from.mockbukkit}</version>
169222
<scope>test</scope>
170223
</dependency>
171224
<dependency>
@@ -174,5 +227,11 @@
174227
<version>2.0.16</version>
175228
<scope>test</scope>
176229
</dependency>
230+
<dependency>
231+
<groupId>com.github.Pinont</groupId>
232+
<artifactId>Singularity-DevTool</artifactId>
233+
<version>cbd0e31e44</version>
234+
<scope>provided</scope>
235+
</dependency>
177236
</dependencies>
178237
</project>

src/main/java/com/github/pinont/singularitylib/plugin/CorePlugin.java renamed to src/main/java/com/github/pinont/plugin/CorePlugin.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package com.github.pinont.singularitylib.plugin;
1+
package com.github.pinont.plugin;
22

3+
import com.github.pinont.plugin.listener.PlayerListener;
34
import com.github.pinont.singularitylib.api.command.SimpleCommand;
45
import com.github.pinont.singularitylib.api.manager.ConfigManager;
5-
import com.github.pinont.singularitylib.plugin.listener.PlayerListener;
6-
import com.github.pinont.singularitylib.plugin.register.Register;
6+
import com.github.pinont.plugin.register.Register;
77
import org.bukkit.Bukkit;
88
import org.bukkit.ChatColor;
99
import org.bukkit.configuration.file.FileConfiguration;
@@ -45,12 +45,17 @@ public CorePlugin() {
4545

4646
private static String prefix;
4747
private static Long startTime;
48+
private static boolean isFolia;
4849

4950
/**
5051
* Flag indicating if the plugin is running in test mode.
5152
*/
5253
public boolean isTest = false;
5354

55+
public static boolean isFolia() {
56+
return isFolia;
57+
}
58+
5459
/**
5560
* Gets the time when the plugin started loading.
5661
*
@@ -94,8 +99,8 @@ public static void sendConsoleMessage(String message) {
9499
* @return the API version string
95100
*/
96101
public static String getAPIVersion() {
97-
String version = new ConfigManager("api-version.yml").getConfig().getString("version");
98-
// String version = "1.0.0";
102+
new ConfigManager("api-version.yml").saveConfig();
103+
String version = new ConfigManager("api-version.yml").getConfig().getString("version") == null ? "1.0.0" : new ConfigManager("api-version.yml").getConfig().getString("version");
99104
return "V-" + version;
100105
}
101106

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

172+
isFolia = foliaCheck();
173+
if (isFolia) {
174+
sendConsoleMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "Folia environment detected, enabling Folia compatibility mode...");
175+
}
176+
167177
// Initialize API To Plugin.
168178
sendConsoleMessage(ChatColor.WHITE + "" + ChatColor.ITALIC + "Hooked " + ChatColor.YELLOW + ChatColor.ITALIC + this.getName() + ChatColor.WHITE + ChatColor.ITALIC + " into " + ChatColor.LIGHT_PURPLE + ChatColor.ITALIC + "SingularityAPI! " + getAPIVersion());
169179
onPluginStart();
@@ -178,6 +188,15 @@ public final void onEnable() {
178188
}
179189
}
180190

191+
private boolean foliaCheck() {
192+
try {
193+
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
194+
return true;
195+
} catch (ClassNotFoundException e) {
196+
return false;
197+
}
198+
}
199+
181200
private void registerAPIListener(Plugin plugin, Listener... listener) {
182201
sendConsoleMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "Initializing API listeners for " + plugin.getName() + "...");
183202
for (Listener l : listener) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.github.pinont.plugin.listener;
2+
3+
import com.github.pinont.singularitylib.api.annotation.AutoRegister;
4+
import com.github.pinont.singularitylib.api.event.PlayerDamageByPlayerEvent;
5+
import org.bukkit.entity.Player;
6+
import org.bukkit.event.EventHandler;
7+
import org.bukkit.event.Listener;
8+
import org.bukkit.event.entity.EntityDamageByEntityEvent;
9+
10+
@AutoRegister
11+
public class EntityDamageListener implements Listener {
12+
13+
@EventHandler
14+
public void onEntityDamage(EntityDamageByEntityEvent event) {
15+
if (event.getEntity() instanceof Player player && event.getDamager() instanceof Player damager) {
16+
PlayerDamageByPlayerEvent playerDamageEvent = new PlayerDamageByPlayerEvent(player, damager);
17+
event.setCancelled(playerDamageEvent.callEvent());
18+
}
19+
}
20+
21+
}

src/main/java/com/github/pinont/singularitylib/plugin/listener/PlayerListener.java renamed to src/main/java/com/github/pinont/plugin/listener/PlayerListener.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package com.github.pinont.singularitylib.plugin.listener;
1+
package com.github.pinont.plugin.listener;
22

33
import com.destroystokyo.paper.event.player.PlayerRecipeBookClickEvent;
4+
import com.github.pinont.plugin.CorePlugin;
45
import com.github.pinont.singularitylib.api.event.ItemExecuteEvent;
5-
import com.github.pinont.singularitylib.api.items.ItemCreator;
66
import com.github.pinont.singularitylib.api.items.ItemInteraction;
77
import com.github.pinont.singularitylib.api.ui.Button;
88
import com.github.pinont.singularitylib.api.ui.Menu;
@@ -24,19 +24,16 @@
2424

2525
import java.util.Objects;
2626

27-
import static com.github.pinont.singularitylib.plugin.CorePlugin.*;
27+
import static com.github.pinont.singularitylib.api.items.ItemInteraction.*;
28+
import static com.github.pinont.plugin.CorePlugin.*;
2829

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

35-
/**
36-
* Default constructor for PlayerListener.
37-
*/
38-
public PlayerListener() {
39-
}
36+
private final Plugin plugin = CorePlugin.getInstance();
4037

4138
/**
4239
* Handles player interaction events for custom item interactions.
@@ -47,11 +44,11 @@ public PlayerListener() {
4744
public void interaction(PlayerInteractEvent event) {
4845
Player player = event.getPlayer();
4946
ItemStack item = player.getInventory().getItemInMainHand();
50-
if (!Common.isMainHandEmpty(player) && ItemCreator.isItemHasPersistData(item, "interaction", PersistentDataType.STRING)) {
47+
if (!Common.isMainHandEmpty(player) && isItemHasPersistData(plugin, item, "interaction", PersistentDataType.STRING)) {
5148
if (event.getPlayer().getCooldown(item) > 0) return;
5249
ItemInteraction itemInteraction;
5350
try {
54-
itemInteraction = ItemCreator.getInteraction(item);
51+
itemInteraction = getInteraction(plugin, item);
5552
} catch (IllegalArgumentException e) {
5653
sendInteractionError(player);
5754
return;
@@ -171,7 +168,7 @@ private void removePlayerMetadata(Player player, Plugin plugin, String... keys)
171168
}
172169

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

177174
}

src/main/java/com/github/pinont/singularitylib/plugin/register/Register.java renamed to src/main/java/com/github/pinont/plugin/register/Register.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.pinont.singularitylib.plugin.register;
1+
package com.github.pinont.plugin.register;
22

33
import com.github.pinont.singularitylib.api.annotation.AutoRegister;
44
import com.github.pinont.singularitylib.api.command.SimpleCommand;

src/main/java/com/github/pinont/singularitylib/api/annotation/AutoRegister.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.github.pinont.singularitylib.api.annotation;
22

3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Target;
5+
36
/**
47
* Annotation to mark classes for automatic registration by the plugin.
58
* This annotation is used to mark classes that need to be registered during the plugin's startup process.
@@ -9,6 +12,8 @@
912
* <b>Hint:</b> Use this annotation to register commands, events, or custom items.
1013
* It should only be used when the class extends {@code CustomItem}, {@code SimpleCommand}, or {@code Listener}.
1114
*/
15+
16+
@Target({ElementType.TYPE})
1217
public @interface AutoRegister {
1318
/**
1419
* Indicates that the annotated class should be automatically registered by the plugin.

src/main/java/com/github/pinont/singularitylib/api/command/SimpleCommand.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ public interface SimpleCommand extends BasicCommand {
1616
*/
1717
String getName();
1818

19+
// /**
20+
// * Gets the description of the command.
21+
// * This description is used in help messages and command documentation.
22+
// *
23+
// * @return the command description
24+
// */
25+
// String getDescription();
26+
1927
/**
2028
* Gets the usage string for this command.
2129
*
@@ -25,12 +33,4 @@ public interface SimpleCommand extends BasicCommand {
2533
default String usage(Boolean bool) {
2634
return "/" + getName();
2735
}
28-
29-
/**
30-
* Gets the description of the command.
31-
* This description is used in help messages and command documentation.
32-
*
33-
* @return the command description
34-
*/
35-
String description();
3636
}

0 commit comments

Comments
 (0)