From b7981f1b6dff88369883200ef61f59905868bd02 Mon Sep 17 00:00:00 2001 From: brenoepics <59066707+brenoepics@users.noreply.github.com> Date: Sun, 16 Jan 2022 20:26:15 -0300 Subject: [PATCH] Initial commit --- .gitattributes | 2 + .gitignore | 3 + README.md | 49 +++++++++++ pom.xml | 70 +++++++++++++++ src/main/java/com/brenoepic/PrizePlugin.java | 83 ++++++++++++++++++ .../com/brenoepic/command/PrizeCommand.java | 60 +++++++++++++ .../command/UpdateLevelsCommand.java | 32 +++++++ src/main/java/com/brenoepic/level/Level.java | 51 +++++++++++ .../com/brenoepic/level/LevelManager.java | 87 +++++++++++++++++++ .../java/com/brenoepic/utils/Functions.java | 47 ++++++++++ src/main/resources/plugin.json | 5 ++ 11 files changed, 489 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 README.md create mode 100644 pom.xml create mode 100644 src/main/java/com/brenoepic/PrizePlugin.java create mode 100644 src/main/java/com/brenoepic/command/PrizeCommand.java create mode 100644 src/main/java/com/brenoepic/command/UpdateLevelsCommand.java create mode 100644 src/main/java/com/brenoepic/level/Level.java create mode 100644 src/main/java/com/brenoepic/level/LevelManager.java create mode 100644 src/main/java/com/brenoepic/utils/Functions.java create mode 100644 src/main/resources/plugin.json diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b208915 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ +target/* +!target/MentionPlugin-*-jar-with-dependencies.jar \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b0f5503 --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +# PrizePlugin + +Working with Arcturus Morningstar 3.0.0 + +## How to use? +you just need to send: +```:prize ``` + +- update prize list with :update_prize [x] +- Prize per level (credits, diamonds, duckets, points, badge, furni...)[x] +- Kick user [x] +- User won event BubbleAlert[x] +- Discord logging [x] + +## How can i install it? + + 1. Download a pre-compiled version. [PrizePlugin](https://github.com/brenoepics/PrizePlugin/releases/) + 2. Run the sql and add badges/texts. + 3. Paste the PrizePlugin-1.0-jar-with-dependencies.jar file into your emulator's plugins folder and start/restart the emulator. + 4. Now you need to give permission for your staffs to use prize command, to do it open your database in the permissions table, and change the permissions cmd_prize and cmd_update_prize. + 5. Then, open prize_plugin table, and configure rewards. + 6. Now, enter your hotel and type: :update_permissions and :update_prize and then try :prize + + 7. if you want to configure webhooks check [Config webhook](#Discord) + +## configuration + +OBS: the level -1 is the default reward if there's none on user's level. + + Permissions: + +| Key | Default Value | +|----------------------|---------------| +| cmd_prize | 0 | +| cmd_update_prize | 0 | + +## Discord +![print](https://imgur.com/4VgDJ5c.png) +1. Open your emulator_settings, and change the key `prizeplugin.logging_discord` to 1. +2. Go to the discord channel, Click the gear icon (Edit Channel) of the channel you want to post to. +3. Click Webhooks in the left menu. +4. Click the Create Webhook button. +5. Enter a Name of your choice. +6. Click the Copy button of the Webhook URL. +7. Click the Save button. +8. Paste the Webhook URL into emulator_settings, key `prizeplugin.logging.discord-webhook.url` + + +My Discord: BrenoEpic#9671 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..b979588 --- /dev/null +++ b/pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + + com.brenoepic + PrizePlugin + 1.0 + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + maven-assembly-plugin + + + + com.brenoepic.PrizePlugin + + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + + + UTF-8 + + + + jitpack.io + https://jitpack.io + + + + + com.eu.habbo + Habbo + 3.0.0 + provided + + + com.github.brenoepics + discord-webhooks + 0.2.1 + compile + + + + \ No newline at end of file diff --git a/src/main/java/com/brenoepic/PrizePlugin.java b/src/main/java/com/brenoepic/PrizePlugin.java new file mode 100644 index 0000000..cfbe001 --- /dev/null +++ b/src/main/java/com/brenoepic/PrizePlugin.java @@ -0,0 +1,83 @@ +package com.brenoepic; + +import com.brenoepic.command.UpdateLevelsCommand; +import com.brenoepic.level.LevelManager; +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.brenoepic.command.PrizeCommand; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PrizePlugin extends HabboPlugin implements EventListener { + + PrizePlugin INSTANCE; + public static final Logger LOGGER = LoggerFactory.getLogger(PrizePlugin.class); + public static LevelManager levels; + + public void onEnable(){ + Emulator.getPluginManager().registerEvents(this, this); + INSTANCE = this; + LOGGER.info("[prizeplugin 1.0] was successfully Loaded! Discord: BrenoEpic#9671"); + } + + public void onDisable(){ + + } + + public boolean hasPermission(Habbo habbo, String s) { + return false; + } + + @EventHandler + public void onEmulatorLoaded(EmulatorLoadedEvent event){ + levels = new LevelManager(); + // Load texts + Emulator.getTexts().register("commands.description.cmd_prize", ":prize "); + Emulator.getTexts().register("commands.description.cmd_update_prize", ":update_prize"); + Emulator.getTexts().register("commands.keys.cmd_update_prize", "update_prize"); + Emulator.getTexts().register("commands.keys.cmd_prize", "prize"); + Emulator.getTexts().register("commands.cmd_prize.none", "Missing the winning username!"); + Emulator.getTexts().register("commands.cmd_prize.not-found", "User not found or offline!!"); + Emulator.getTexts().register("commands.cmd_prize.not-self", "You can't reward yourself!"); + Emulator.getTexts().register("commands.cmd_prize.successfully", "You have successfully awarded user %USERNAME%!"); + Emulator.getTexts().register("commands.cmd_prize.update-successfully", "You have successfully updated rewards!"); + Emulator.getTexts().register("commands.cmd_prize.update-error", "Oops, Something went wrong!"); + Emulator.getTexts().register("prizeplugin.bubblealert-message", "The user %WINNER% won an event"); + Emulator.getTexts().register("prizeplugin.webhook-message", "The user %WINNER% won an event and reached level %LEVEL%"); + + Emulator.getTexts().register("prizeplugin.webhook.title", "A user has just won an event!"); + + // Load config + Emulator.getConfig().register("prizeplugin.webhook.hotel-url", "https://habbo.com"); + Emulator.getConfig().register("prizeplugin.prize_badge-prefix", "LVL"); + Emulator.getConfig().register("prizeplugin.bubblealert-image", "${image.library.url}notifications/fig/%LOOK%.png"); + Emulator.getConfig().register("prizeplugin.webhook-thumbnail", "https://habbo.com/habbo-imaging/avatarimage?figure=%LOOK%&head_direction=4&headonly=1"); + Emulator.getConfig().register("prizeplugin.prize_level.type", "504"); + Emulator.getConfig().register("prizeplugin.kickonwin", "1"); + + Emulator.getConfig().register("prizeplugin.logging_discord", "0"); + Emulator.getConfig().register("prizeplugin.logging.discord-webhook.url", "DISCORDWEBHOOKURL"); + + + // Commands + CommandHandler.addCommand(new PrizeCommand("cmd_prize", Emulator.getTexts().getValue("commands.keys.cmd_prize").split(";"))); + CommandHandler.addCommand(new UpdateLevelsCommand("cmd_update_prize", Emulator.getTexts().getValue("commands.keys.cmd_update_prize").split(";"))); + + } + + public static LevelManager getLevels(){ + return levels; + } + + public static void main(String[] args) { + System.out.println("Hello world!"); + } + +} diff --git a/src/main/java/com/brenoepic/command/PrizeCommand.java b/src/main/java/com/brenoepic/command/PrizeCommand.java new file mode 100644 index 0000000..00e6bb5 --- /dev/null +++ b/src/main/java/com/brenoepic/command/PrizeCommand.java @@ -0,0 +1,60 @@ +package com.brenoepic.command; + +import com.brenoepic.PrizePlugin; +import com.brenoepic.utils.Functions; +import com.eu.habbo.habbohotel.commands.Command; +import com.eu.habbo.habbohotel.gameclients.GameClient; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer; + + +import static com.eu.habbo.Emulator.*; + + +public class PrizeCommand extends Command { + + public PrizeCommand(String permission, String[] keys) + { + super(permission, keys); + } + + @Override + public boolean handle(GameClient gameClient, String[] params) + { + if (params.length < 2){ + gameClient.getHabbo().whisper(getTexts().getValue("commands.cmd_prize.none")); + return false; + }else{ + + Habbo habbo = getGameEnvironment().getHabboManager().getHabbo(params[1]); + if(habbo == null){ + gameClient.getHabbo().whisper(getTexts().getValue("commands.cmd_prize.not-found")); + return false; + } + + if (habbo == gameClient.getHabbo()) { + gameClient.getHabbo().whisper(getTexts().getValue("commands.cmd_prize.not-self")); + return false; + } + final int level = habbo.getHabboInfo().getCurrencyAmount(getConfig().getInt("prizeplugin.prize_level.type", 504)); + final int NewLevel = (level + 1); + + boolean rewarded = PrizePlugin.getLevels().giveReward(habbo.getHabboInfo().getId(), NewLevel); + + getGameServer().getGameClientManager().sendBroadcastResponse(new BubbleAlertComposer("prizeplugin", Functions.BubbleAlert(habbo))); + + final Room room = habbo.getHabboInfo().getCurrentRoom(); + if (room != null && getConfig().getBoolean("prizeplugin.kickonwin")) { + room.kickHabbo(habbo.getHabboInfo().getCurrentRoom().getHabbo(habbo.getHabboInfo().getUsername()), false); + } + if(rewarded) { + gameClient.getHabbo().whisper(getTexts().getValue("commands.cmd_prize.successfully").replace("%USERNAME%", habbo.getHabboInfo().getUsername())); + Functions.DiscordEmbed(habbo, gameClient.getHabbo()); + }else{ + gameClient.getHabbo().whisper(getTexts().getValue("commands.cmd_prize.update-error")); + } + } + return true; + } +} \ No newline at end of file diff --git a/src/main/java/com/brenoepic/command/UpdateLevelsCommand.java b/src/main/java/com/brenoepic/command/UpdateLevelsCommand.java new file mode 100644 index 0000000..01c21ac --- /dev/null +++ b/src/main/java/com/brenoepic/command/UpdateLevelsCommand.java @@ -0,0 +1,32 @@ +package com.brenoepic.command; + +import com.brenoepic.PrizePlugin; +import com.brenoepic.utils.Functions; +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.commands.Command; +import com.eu.habbo.habbohotel.gameclients.GameClient; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer; + + +import static com.eu.habbo.Emulator.*; + + +public class UpdateLevelsCommand extends Command { + + public UpdateLevelsCommand(String permission, String[] keys) + { + super(permission, keys); + } + + @Override + public boolean handle(GameClient gameClient, String[] params) + { + boolean loaded = PrizePlugin.getLevels().load(); + if(loaded) + gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.cmd_prize.update-successfully")); + else gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.cmd_prize.update-error")); + return true; + } +} \ No newline at end of file diff --git a/src/main/java/com/brenoepic/level/Level.java b/src/main/java/com/brenoepic/level/Level.java new file mode 100644 index 0000000..98f91c9 --- /dev/null +++ b/src/main/java/com/brenoepic/level/Level.java @@ -0,0 +1,51 @@ +package com.brenoepic.level; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class Level +{ + private final int level; + private final int credits; + private final int diamonds; + private final int pixels; + private final int points; + private final int points_type; + private final int furni; + public Level(final ResultSet result) throws SQLException { + this.level = result.getInt("level"); + this.credits = result.getInt("credits"); + this.diamonds = result.getInt("diamonds"); + this.points = result.getInt("points"); + this.points_type = result.getInt("points_type"); + this.furni = result.getInt("item"); + this.pixels = result.getInt("pixels"); + } + + public int getLevel() { + return this.level; + } + + public int getCredits() { + return this.credits; + } + + public int getDiamonds() { + return this.diamonds; + } + + public int getPixels(){ + return this.pixels; + } + public int getPoints() { + return this.points; + } + + public int getPointsType() { + return this.points_type; + } + + public int getFurniture() { + return this.furni; + } +} diff --git a/src/main/java/com/brenoepic/level/LevelManager.java b/src/main/java/com/brenoepic/level/LevelManager.java new file mode 100644 index 0000000..d11aa8d --- /dev/null +++ b/src/main/java/com/brenoepic/level/LevelManager.java @@ -0,0 +1,87 @@ +package com.brenoepic.level; + + +import com.brenoepic.PrizePlugin; +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboItem; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +import static com.eu.habbo.Emulator.getConfig; + +public class LevelManager +{ + private final Map levels; + + public LevelManager() { + this.levels = new HashMap<>(); + this.load(); + } + + public boolean load() { + this.dispose(); + try (final Connection connection = Emulator.getDatabase().getDataSource().getConnection(); + final PreparedStatement statement = connection.prepareStatement("SELECT * FROM `prize_plugin`"); + final ResultSet set = statement.executeQuery()) { + while (set.next()) { + final Level reward = new Level(set); + this.levels.put(set.getInt("level"), reward); + } + } + catch (SQLException e) { + PrizePlugin.LOGGER.error("[prizeplugin]", e); + return false; + } + return true; + } + + public void dispose() { + this.levels.clear(); + } + + public boolean Exists(final int level) { + return this.levels.containsKey(level); + } + + public Level getLevel(final int level) { + return this.levels.get(level); + } + + public boolean giveReward(final int userId, final int level) { + final Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); + if (habbo == null) return false; + Level reward; + if (!this.Exists(level)) reward = this.getLevel(-1); else reward = this.getLevel(level); + if(reward == null) return false; + if (reward.getCredits() > 0) { + habbo.giveCredits(reward.getCredits()); + } + if (reward.getDiamonds() > 0) { + habbo.givePoints(5, reward.getDiamonds()); + } + if (reward.getPixels() > 0) { + habbo.givePoints(0, reward.getPixels()); + } + if (reward.getFurniture() > -1) { + int furni_id = reward.getFurniture(); + final Item baseItem = Emulator.getGameEnvironment().getItemManager().getItem(furni_id); + if (baseItem != null) { + final HabboItem item = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getHabboInfo().getId(), baseItem, 0, 0, ""); + habbo.addFurniture(item); + } + } + if (reward.getPoints() > 0) { + habbo.givePoints(reward.getPointsType(), reward.getPoints()); + } + habbo.givePoints(getConfig().getInt("prizeplugin.prize_level.type", 504), 1); + habbo.addBadge(getConfig().getValue("prizeplugin.prize_badge-prefix") + level); + return true; + } +} diff --git a/src/main/java/com/brenoepic/utils/Functions.java b/src/main/java/com/brenoepic/utils/Functions.java new file mode 100644 index 0000000..d04b85a --- /dev/null +++ b/src/main/java/com/brenoepic/utils/Functions.java @@ -0,0 +1,47 @@ +package com.brenoepic.utils; + +import club.minnced.discord.webhook.WebhookClient; +import club.minnced.discord.webhook.send.AllowedMentions; +import club.minnced.discord.webhook.send.WebhookEmbed; +import club.minnced.discord.webhook.send.WebhookEmbedBuilder; +import club.minnced.discord.webhook.send.WebhookMessageBuilder; +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.users.Habbo; +import gnu.trove.map.hash.THashMap; + +import static com.eu.habbo.Emulator.getConfig; +import static com.eu.habbo.Emulator.getTexts; + + +public class Functions { + + + public static THashMap BubbleAlert(Habbo winner) { + + THashMap notification = new THashMap<>(); + notification.put("display", "BUBBLE"); + notification.put("image", getConfig().getValue("prizeplugin.bubblealert-image").replace("%LOOK%", winner.getHabboInfo().getLook())); + notification.put("message", getTexts().getValue("prizeplugin.bubblealert-message").replace("%WINNER%", winner.getHabboInfo().getUsername())); + return notification; + } + + public static void DiscordEmbed(Habbo winner, Habbo staff) { + if (getConfig().getBoolean("prizeplugin.logging_discord", true)) { + WebhookClient client = WebhookClient.withUrl(Emulator.getConfig().getValue("prizeplugin.logging.discord-webhook.url")); + WebhookMessageBuilder message = new WebhookMessageBuilder() + .setAllowedMentions(AllowedMentions.none()); + WebhookEmbed embed = new WebhookEmbedBuilder() + .setColor(0x03A9F4) + .setAuthor(new WebhookEmbed.EmbedAuthor(getConfig().getValue("hotel.name"), null, getConfig().getValue("prizeplugin.webhook.hotel-url"))) + .setTitle(new WebhookEmbed.EmbedTitle(getTexts().getValue("prizeplugin.webhook.title"), null)) + .setDescription(getTexts().getValue("prizeplugin.webhook-message").replace("%WINNER%", winner.getHabboInfo().getUsername()).replace("%LEVEL%", "" + winner.getHabboInfo().getCurrencyAmount(getConfig().getInt("prizeplugin.prize_level.type", 504)))) + .setThumbnailUrl(getConfig().getValue("prizeplugin.webhook-thumbnail").replace("%LOOK%", winner.getHabboInfo().getLook())) + .setFooter(new WebhookEmbed.EmbedFooter(staff.getHabboInfo().getUsername(), null)) + .build(); + message.append("[PRIZE-PLUGIN]"); + message.addEmbeds(embed); + client.send(message.build()); + } + + } +} \ No newline at end of file diff --git a/src/main/resources/plugin.json b/src/main/resources/plugin.json new file mode 100644 index 0000000..9148c31 --- /dev/null +++ b/src/main/resources/plugin.json @@ -0,0 +1,5 @@ +{ + "main" : "com.brenoepic.PrizePlugin", + "name" : "PrizePlugin 1.0", + "author" : "BrenoEpic#9671" +} \ No newline at end of file