diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
new file mode 100644
index 0000000..2fab9b9
--- /dev/null
+++ b/.github/workflows/maven.yml
@@ -0,0 +1,37 @@
+# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
+# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path
+
+name: Maven Package
+
+on:
+ push:
+ branches:
+ - main
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ packages: write
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up JDK 11
+ uses: actions/setup-java@v2
+ with:
+ java-version: '11'
+ distribution: 'adopt'
+ server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
+ settings-path: ${{ github.workspace }} # location for the settings.xml file
+
+ - name: Build Plugins
+ run: mvn clean -B package --file pom.xml
+ - run: mkdir staging && cp target/*-jar-with-dependencies.jar staging
+ - run: cp *.sql staging
+ - uses: actions/upload-artifact@v1
+ with:
+ name: Plugin
+ path: staging
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/pom.xml b/pom.xml
index a7ac318..6f3c34c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,19 +8,90 @@
2.0
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ ${kotlin.version}
+
+
+ compile
+ compile
+
+ compile
+
+
+
+ test-compile
+ test-compile
+
+ test-compile
+
+
+
+
+ 1.8
+
+
org.apache.maven.plugins
maven-compiler-plugin
3.8.1
+
+
+ default-compile
+ none
+
+
+ default-testCompile
+ none
+
+
+ compile
+ compile
+
+ compile
+
+
+
+ testCompile
+ test-compile
+
+ testCompile
+
+
+
1.8
+
+ maven-assembly-plugin
+
+
+
+ io.github.brenoepics.NFTAvatar
+
+
+
+ jar-with-dependencies
+
+
+
+
+ make-assembly
+ package
+
+ single
+
+
+
+
UTF-8
+ 1.9.23
@@ -36,10 +107,21 @@
provided
- org.projectlombok
- lombok
- 1.18.30
- provided
+ org.slf4j
+ slf4j-api
+ 2.1.0-alpha1
+ compile
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-jdk8
+ ${kotlin.version}
+
+
+ org.jetbrains.kotlin
+ kotlin-test
+ ${kotlin.version}
+ test
\ No newline at end of file
diff --git a/src/main/java/com/brenoepic/NFTAvatar.java b/src/main/java/com/brenoepic/NFTAvatar.java
deleted file mode 100644
index b876af3..0000000
--- a/src/main/java/com/brenoepic/NFTAvatar.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.brenoepic;
-
-import static com.brenoepic.clothes.ClothingUtility.checkUpdate;
-import static com.brenoepic.util.Database.loadTexts;
-
-import com.brenoepic.clothes.ClothingManager;
-import com.brenoepic.command.UpdateLooksCommand;
-import com.eu.habbo.Emulator;
-import com.eu.habbo.habbohotel.commands.CommandHandler;
-import com.eu.habbo.habbohotel.users.Habbo;
-import com.eu.habbo.plugin.EventHandler;
-import com.eu.habbo.plugin.EventListener;
-import com.eu.habbo.plugin.HabboPlugin;
-import com.eu.habbo.plugin.events.emulator.EmulatorLoadedEvent;
-import com.eu.habbo.plugin.events.users.UserEnterRoomEvent;
-import com.eu.habbo.plugin.events.users.UserSavedLookEvent;
-import lombok.Getter;
-import lombok.extern.slf4j.Slf4j;
-
-@Slf4j
-@Getter
-public class NFTAvatar extends HabboPlugin implements EventListener {
- public static final ClothingManager manager = new ClothingManager();
-
- public void onEnable() {
- Emulator.getPluginManager().registerEvents(this, this);
- log.info("[NFTAvatarPlugin] was successfully loaded! Discord: brenoepic");
- }
-
- public void onDisable() {
- // empty, not needed
- }
-
- public boolean hasPermission(Habbo habbo, String s) {
- return false;
- }
-
- @EventHandler
- public void onEmulatorLoaded(EmulatorLoadedEvent event) {
- loadTexts();
-
- // Commands
- String[] keys = Emulator.getTexts().getValue("commands.keys.cmd_update_looks").split(";");
- CommandHandler.addCommand(new UpdateLooksCommand("cmd_update_looks", keys));
- }
-
- @EventHandler
- public void onUserEnterRoom(UserEnterRoomEvent event) {
- if (event.habbo == null || event.room == null) return;
- checkUpdate(event.habbo, event.room);
- }
-
- @EventHandler
- public void onUserSaveLookEvent(UserSavedLookEvent event) {
- if (event.habbo == null || event.habbo.getHabboInfo().getCurrentRoom() == null) return;
- checkUpdate(event.habbo, event.habbo.getHabboInfo().getCurrentRoom(), event.newLook);
- }
-
- public static void main(String[] args) {
- System.out.println("Hello world!");
- }
-}
diff --git a/src/main/java/com/brenoepic/clothes/Clothing.java b/src/main/java/com/brenoepic/clothes/Clothing.java
deleted file mode 100644
index 3c8d57b..0000000
--- a/src/main/java/com/brenoepic/clothes/Clothing.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.brenoepic.clothes;
-
-import lombok.Getter;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Objects;
-
-@Getter
-public class Clothing
-{
- private final int id;
- private final String type;
- private final String set;
- private final int effect;
- public Clothing(final ResultSet result) throws SQLException {
- this.id = result.getInt("id");
- this.type = result.getString("type");
- if(Objects.equals(this.type, "figure")) this.set = result.getString("figure");
- else this.set = result.getString("setid");
- this.effect = result.getInt("effect");
- }
-}
diff --git a/src/main/java/com/brenoepic/clothes/ClothingManager.java b/src/main/java/com/brenoepic/clothes/ClothingManager.java
deleted file mode 100644
index 67bfff2..0000000
--- a/src/main/java/com/brenoepic/clothes/ClothingManager.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.brenoepic.clothes;
-
-import com.eu.habbo.Emulator;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.*;
-import java.util.stream.Collectors;
-
-import lombok.extern.slf4j.Slf4j;
-
-@Slf4j
-public class ClothingManager {
- private final HashMap clothes;
-
- public ClothingManager() {
- this.clothes = new HashMap<>();
- this.load();
- }
-
- public boolean load() {
- this.dispose();
- try (final Connection connection = Emulator.getDatabase().getDataSource().getConnection();
- final PreparedStatement statement =
- connection.prepareStatement("SELECT * FROM `special_looks`");
- final ResultSet set = statement.executeQuery()) {
- while (set.next()) {
- final Clothing cloth = new Clothing(set);
- this.clothes.put(set.getInt("id"), cloth);
- }
- } catch (SQLException e) {
- log.error("[NFTAvatarPlugin]", e);
- return false;
- }
- log.info("[NFTAvatarPlugin] Loaded {} NFT avatars successfully!", this.clothes.size());
- return true;
- }
-
- public void dispose() {
- this.clothes.clear();
- }
-
- public Clothing getClothingBySetId(final int setId) {
- return this.clothes.values().stream()
- .filter(clothing -> filterSetId(setId, clothing))
- .findFirst()
- .orElse(null);
- }
-
- private static boolean filterSetId(int setId, Clothing clothing) {
- return clothing.getSet() != null
- && clothing.getType().equals("setid")
- && Integer.parseInt(clothing.getSet()) == setId;
- }
-
- public Clothing getClothing(final String figure) {
- return this.clothes.values().stream()
- .filter(clothing -> filterFigure(figure, clothing))
- .findFirst()
- .orElse(null);
- }
-
- private static boolean filterFigure(String figure, Clothing clothing) {
- return clothing.getSet() != null
- && clothing.getType().equals("figure")
- && clothing.getSet().equals(figure);
- }
-
- public List getEffectList() {
- return this.clothes.values().stream().map(Clothing::getEffect).collect(Collectors.toList());
- }
-}
diff --git a/src/main/java/com/brenoepic/clothes/ClothingUtility.java b/src/main/java/com/brenoepic/clothes/ClothingUtility.java
deleted file mode 100644
index 6aa7793..0000000
--- a/src/main/java/com/brenoepic/clothes/ClothingUtility.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.brenoepic.clothes;
-
-import com.brenoepic.NFTAvatar;
-import com.eu.habbo.Emulator;
-import com.eu.habbo.habbohotel.rooms.Room;
-import com.eu.habbo.habbohotel.users.Habbo;
-import java.util.Arrays;
-import java.util.regex.Pattern;
-
-public class ClothingUtility {
- private ClothingUtility() {
- throw new IllegalStateException("Utility class");
- }
-
- public static void checkUpdate(Habbo habbo, Room room) {
- checkUpdate(habbo, room, habbo.getHabboInfo().getLook());
- }
-
- public static void checkUpdate(Habbo habbo, Room room, String look) {
- Clothing clothing = NFTAvatar.manager.getClothing(look);
- if (clothing != null) {
- updateEffect(habbo, room, clothing);
- return;
- }
-
- checkLookParts(habbo, room, look);
- }
-
- public static void checkLookParts(Habbo habbo, Room room, String look) {
- String[] newLookParts = look.split(Pattern.quote("."));
- Arrays.stream(newLookParts).forEach(part -> handlePart(habbo, room, part));
- }
-
- public static void handlePart(Habbo habbo, Room room, String part) {
- if (!part.contains("-")) return;
-
- String[] data = part.split(Pattern.quote("-"));
- int setId = Integer.parseInt(data.length >= 2 ? data[1] : "-1");
- if (setId <= 0) {
- return;
- }
-
- Clothing clothing = NFTAvatar.manager.getClothingBySetId(setId);
- if (clothing != null) {
- updateEffect(habbo, room, clothing);
- }
- }
-
- public static void updateEffect(Habbo habbo, Room room, Clothing clothing) {
- Runnable giveEffect = () -> room.giveEffect(habbo, clothing.getEffect(), -1);
- Emulator.getThreading().run(giveEffect, 500);
- }
-}
diff --git a/src/main/java/com/brenoepic/command/UpdateLooksCommand.java b/src/main/java/com/brenoepic/command/UpdateLooksCommand.java
deleted file mode 100644
index 95af1ae..0000000
--- a/src/main/java/com/brenoepic/command/UpdateLooksCommand.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.brenoepic.command;
-
-import com.brenoepic.NFTAvatar;
-import com.eu.habbo.Emulator;
-import com.eu.habbo.habbohotel.commands.Command;
-import com.eu.habbo.habbohotel.gameclients.GameClient;
-
-public class UpdateLooksCommand extends Command {
-
- public UpdateLooksCommand(String permission, String[] keys) {
- super(permission, keys);
- }
-
- @Override
- public boolean handle(GameClient gameClient, String[] params) {
- boolean loaded = NFTAvatar.manager.load();
- gameClient.getHabbo().whisper(getResponse(loaded));
- return true;
- }
-
- private String getResponse(boolean loaded) {
- String success = "commands.cmd_update_looks.successfully";
- String error = "commands.cmd_update_looks.error";
- return Emulator.getTexts().getValue(loaded ? success : error);
- }
-}
diff --git a/src/main/java/com/brenoepic/util/Database.java b/src/main/java/com/brenoepic/util/Database.java
deleted file mode 100644
index 768b4b2..0000000
--- a/src/main/java/com/brenoepic/util/Database.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.brenoepic.util;
-
-import com.eu.habbo.Emulator;
-
-public class Database {
-
- public static void loadTexts() {
- // Load texts
- Emulator.getTexts().register("commands.description.cmd_update_looks", ":update_looks");
- Emulator.getTexts().register("commands.keys.cmd_update_looks", "update_looks");
- Emulator.getTexts()
- .register("commands.cmd_update_looks.successfully", "Successfully updated NFT Plugin!");
- Emulator.getTexts().register("commands.cmd_update_looks.error", "Oops, Something went wrong!");
- }
-}
diff --git a/src/main/java/io/github/brenoepics/NFTAvatar.kt b/src/main/java/io/github/brenoepics/NFTAvatar.kt
new file mode 100644
index 0000000..b2d9c02
--- /dev/null
+++ b/src/main/java/io/github/brenoepics/NFTAvatar.kt
@@ -0,0 +1,65 @@
+package io.github.brenoepics
+
+import io.github.brenoepics.clothes.ClothingManager
+import io.github.brenoepics.clothes.ClothingUtility.Companion.checkUpdate
+import io.github.brenoepics.command.UpdateLooksCommand
+import io.github.brenoepics.util.Database.loadTexts
+import com.eu.habbo.Emulator
+import com.eu.habbo.habbohotel.commands.CommandHandler
+import com.eu.habbo.habbohotel.users.Habbo
+import com.eu.habbo.plugin.EventHandler
+import com.eu.habbo.plugin.EventListener
+import com.eu.habbo.plugin.HabboPlugin
+import com.eu.habbo.plugin.events.emulator.EmulatorLoadedEvent
+import com.eu.habbo.plugin.events.users.UserEnterRoomEvent
+import com.eu.habbo.plugin.events.users.UserSavedLookEvent
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+@Suppress("unused")
+class NFTAvatar : HabboPlugin(), EventListener {
+ override fun onEnable() {
+ Emulator.getPluginManager().registerEvents(this, this)
+ log.info("[NFTAvatarPlugin] was successfully loaded! Discord: brenoepic")
+ }
+
+ override fun onDisable() {
+ // empty, not needed
+ }
+
+ override fun hasPermission(habbo: Habbo, s: String): Boolean {
+ return false
+ }
+
+ @EventHandler
+ fun onEmulatorLoaded(event: EmulatorLoadedEvent?) {
+ loadTexts()
+
+ // Commands
+ val keys: Array = Emulator.getTexts().getValue("commands.keys.cmd_update_looks").split(";".toRegex())
+ .dropLastWhile { it.isEmpty() }.toTypedArray()
+ CommandHandler.addCommand(UpdateLooksCommand("cmd_update_looks", keys))
+ }
+
+ @EventHandler
+ fun onUserEnterRoom(event: UserEnterRoomEvent) {
+ if (event.habbo == null || event.room == null) return
+ checkUpdate(event.habbo, event.room)
+ }
+
+ @EventHandler
+ fun onUserSaveLookEvent(event: UserSavedLookEvent) {
+ if (event.habbo == null || event.habbo.habboInfo.currentRoom == null) return
+ checkUpdate(event.habbo, event.habbo.habboInfo.currentRoom, event.newLook)
+ }
+
+ companion object {
+ val manager: ClothingManager = ClothingManager()
+ private val log: Logger = LoggerFactory.getLogger(NFTAvatar::class.java)
+
+ @JvmStatic
+ fun main(args: Array) {
+ println("Hello world!")
+ }
+ }
+}
diff --git a/src/main/java/io/github/brenoepics/clothes/Clothing.kt b/src/main/java/io/github/brenoepics/clothes/Clothing.kt
new file mode 100644
index 0000000..4cef0bb
--- /dev/null
+++ b/src/main/java/io/github/brenoepics/clothes/Clothing.kt
@@ -0,0 +1,17 @@
+package io.github.brenoepics.clothes
+
+import java.sql.ResultSet
+
+class Clothing
+ (result: ResultSet) {
+ val id: Int = result.getInt("id")
+ val type: String = result.getString("type")
+ var set: String? = null
+ val effect: Int
+
+ init {
+ if (this.type == "figure") this.set = result.getString("figure")
+ else this.set = result.getString("setid")
+ this.effect = result.getInt("effect")
+ }
+}
diff --git a/src/main/java/io/github/brenoepics/clothes/ClothingManager.kt b/src/main/java/io/github/brenoepics/clothes/ClothingManager.kt
new file mode 100644
index 0000000..59c0256
--- /dev/null
+++ b/src/main/java/io/github/brenoepics/clothes/ClothingManager.kt
@@ -0,0 +1,70 @@
+package io.github.brenoepics.clothes
+
+import com.eu.habbo.Emulator
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+import java.sql.SQLException
+import java.util.stream.Collectors
+
+class ClothingManager {
+ private val clothes = HashMap()
+
+ init {
+ this.load()
+ }
+
+ fun load(): Boolean {
+ this.dispose()
+ try {
+ Emulator.getDatabase().dataSource.connection.use { connection ->
+ connection.prepareStatement("SELECT * FROM `special_looks`").use { statement ->
+ statement.executeQuery().use { set ->
+ while (set.next()) {
+ clothes[set.getInt("id")] = Clothing(set)
+ }
+ }
+ }
+ }
+ } catch (e: SQLException) {
+ log.error("[NFTAvatarPlugin]", e)
+ return false
+ }
+ log.info(
+ "[NFTAvatarPlugin] Loaded {} NFT avatars successfully!",
+ clothes.size
+ )
+ return true
+ }
+
+ fun dispose() {
+ clothes.clear()
+ }
+
+ fun getClothingBySetId(setId: Int): Clothing? {
+ return clothes.values.stream()
+ .filter { clothing: Clothing? -> filterSetId(setId, clothing) }
+ .findFirst()
+ .orElse(null)
+ }
+
+ fun getClothing(figure: String): Clothing? {
+ return clothes.values.stream()
+ .filter { clothing: Clothing? -> filterFigure(figure, clothing) }
+ .findFirst()
+ .orElse(null)
+ }
+
+ val effectList: List
+ get() = clothes.values.stream().map { obj: Clothing? -> obj!!.effect }.collect(Collectors.toList())
+
+ companion object {
+ private val log: Logger = LoggerFactory.getLogger(ClothingManager::class.java)
+ private fun filterSetId(setId: Int, clothing: Clothing?): Boolean {
+ return clothing!!.set != null && clothing.type == "setid" && clothing.set!!.toInt() == setId
+ }
+
+ private fun filterFigure(figure: String, clothing: Clothing?): Boolean {
+ return clothing!!.set != null && clothing.type == "figure" && clothing.set == figure
+ }
+ }
+}
diff --git a/src/main/java/io/github/brenoepics/clothes/ClothingUtility.kt b/src/main/java/io/github/brenoepics/clothes/ClothingUtility.kt
new file mode 100644
index 0000000..0ee1700
--- /dev/null
+++ b/src/main/java/io/github/brenoepics/clothes/ClothingUtility.kt
@@ -0,0 +1,53 @@
+package io.github.brenoepics.clothes
+
+import io.github.brenoepics.NFTAvatar
+import com.eu.habbo.Emulator
+import com.eu.habbo.habbohotel.rooms.Room
+import com.eu.habbo.habbohotel.users.Habbo
+import java.util.*
+import java.util.regex.Pattern
+
+class ClothingUtility private constructor() {
+ init {
+ throw IllegalStateException("Utility class")
+ }
+
+ companion object {
+ @JvmStatic
+ @JvmOverloads
+ fun checkUpdate(habbo: Habbo, room: Room, look: String = habbo.habboInfo.look) {
+ val clothing = NFTAvatar.manager.getClothing(look)
+ if (clothing != null) {
+ updateEffect(habbo, room, clothing)
+ return
+ }
+
+ checkLookParts(habbo, room, look)
+ }
+
+ fun checkLookParts(habbo: Habbo?, room: Room, look: String) {
+ val newLookParts = look.split(Pattern.quote(".").toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
+ Arrays.stream(newLookParts).forEach { part: String -> handlePart(habbo, room, part) }
+ }
+
+ fun handlePart(habbo: Habbo?, room: Room, part: String) {
+ if (!part.contains("-")) return
+
+ val data = part.split(Pattern.quote("-").toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
+ val setId = (if (data.size >= 2) data[1] else "-1").toInt()
+ if (setId <= 0) {
+ return
+ }
+
+ val clothing = NFTAvatar.manager.getClothingBySetId(setId)
+ if (clothing != null) {
+ updateEffect(habbo, room, clothing)
+ }
+ }
+
+ fun updateEffect(habbo: Habbo?, room: Room, clothing: Clothing) {
+ val giveEffect = Runnable { room.giveEffect(habbo, clothing.effect, -1) }
+ Emulator.getThreading().run(giveEffect, 500)
+ }
+ }
+}
diff --git a/src/main/java/io/github/brenoepics/command/UpdateLooksCommand.kt b/src/main/java/io/github/brenoepics/command/UpdateLooksCommand.kt
new file mode 100644
index 0000000..21729bc
--- /dev/null
+++ b/src/main/java/io/github/brenoepics/command/UpdateLooksCommand.kt
@@ -0,0 +1,20 @@
+package io.github.brenoepics.command
+
+import io.github.brenoepics.NFTAvatar
+import com.eu.habbo.Emulator
+import com.eu.habbo.habbohotel.commands.Command
+import com.eu.habbo.habbohotel.gameclients.GameClient
+
+class UpdateLooksCommand(permission: String?, keys: Array?) : Command(permission, keys) {
+ override fun handle(gameClient: GameClient, params: Array): Boolean {
+ val loaded = NFTAvatar.manager.load()
+ gameClient.habbo.whisper(getResponse(loaded))
+ return true
+ }
+
+ private fun getResponse(loaded: Boolean): String {
+ val success = "commands.cmd_update_looks.successfully"
+ val error = "commands.cmd_update_looks.error"
+ return Emulator.getTexts().getValue(if (loaded) success else error)
+ }
+}
diff --git a/src/main/java/io/github/brenoepics/util/Database.kt b/src/main/java/io/github/brenoepics/util/Database.kt
new file mode 100644
index 0000000..3d5ff9d
--- /dev/null
+++ b/src/main/java/io/github/brenoepics/util/Database.kt
@@ -0,0 +1,15 @@
+package io.github.brenoepics.util
+
+import com.eu.habbo.Emulator
+
+object Database {
+ @JvmStatic
+ fun loadTexts() {
+ // Load texts
+ Emulator.getTexts().register("commands.description.cmd_update_looks", ":update_looks")
+ Emulator.getTexts().register("commands.keys.cmd_update_looks", "update_looks")
+ Emulator.getTexts()
+ .register("commands.cmd_update_looks.successfully", "Successfully updated NFT Plugin!")
+ Emulator.getTexts().register("commands.cmd_update_looks.error", "Oops, Something went wrong!")
+ }
+}
diff --git a/src/main/resources/plugin.json b/src/main/resources/plugin.json
index 38782fd..db0ce77 100644
--- a/src/main/resources/plugin.json
+++ b/src/main/resources/plugin.json
@@ -1,5 +1,5 @@
{
- "main" : "com.brenoepic.NFTAvatar",
+ "main" : "io.github.brenoepics.NFTAvatar",
"name" : "NFT Avatar Plugin 2.0",
"author" : "brenoepic"
}
\ No newline at end of file