Skip to content

Commit

Permalink
Add broadcastmsg and reload command
Browse files Browse the repository at this point in the history
  • Loading branch information
RhythmicSys committed Nov 16, 2024
1 parent 7d33e42 commit 6ae4e68
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 39 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Java CI with Maven

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven

# Build and verify
- run: mvn --batch-mode --update-snapshots verify

# Prepare the artifact for upload
- run: mkdir staging && cp target/*.jar staging

# Upload artifact
- uses: actions/upload-artifact@v4
with:
name: Package
path: staging

# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
- name: Update dependency graph
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>simplexity</groupId>
<artifactId>AdminHax</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<packaging>jar</packaging>

<name>AdminHax</name>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/simplexity/adminhax/AdminHax.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.plugin.java.JavaPlugin;
import simplexity.adminhax.commands.basic.BroadcastMsg;
import simplexity.adminhax.commands.basic.ReloadPlugin;
import simplexity.adminhax.commands.withargs.GodMode;
import simplexity.adminhax.commands.hax.Feed;
import simplexity.adminhax.commands.hax.Fly;
Expand Down Expand Up @@ -32,6 +34,8 @@ public void onEnable() {
this.getCommand("heal").setExecutor(new Heal(Util.HEAL_PERMISSION, Util.HEAL_OTHER_PERMISSION));
this.getCommand("repair").setExecutor(new Repair(Util.REPAIR_HAND_PERMISSION, "hand"));
this.getCommand("godmode").setExecutor(new GodMode(Util.GODMODE_PERMISSION, "toggle"));
this.getCommand("broadcastmsg").setExecutor(new BroadcastMsg());
this.getCommand("adminhaxreload").setExecutor(new ReloadPlugin());
this.getServer().getPluginManager().registerEvents(new FlyListeners(), this);
}

Expand Down
26 changes: 26 additions & 0 deletions src/main/java/simplexity/adminhax/commands/basic/BroadcastMsg.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package simplexity.adminhax.commands.basic;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import simplexity.adminhax.AdminHax;
import simplexity.adminhax.config.LocaleHandler;

public class BroadcastMsg implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
if (args.length == 0) {
sender.sendRichMessage(LocaleHandler.getInstance().getInvalidCommand());
return false;
}
StringBuilder msg = new StringBuilder();
for (String arg : args) {
msg.append(arg).append(" ");
}
String message = msg.toString().trim();
message = LocaleHandler.getInstance().getBroadcastServerPrefix() + message;
AdminHax.getInstance().getServer().sendMessage(AdminHax.getMiniMessage().deserialize(message));
return true;
}
}
18 changes: 18 additions & 0 deletions src/main/java/simplexity/adminhax/commands/basic/ReloadPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package simplexity.adminhax.commands.basic;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import simplexity.adminhax.config.ConfigHandler;
import simplexity.adminhax.config.LocaleHandler;

public class ReloadPlugin implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
ConfigHandler.getInstance().reloadConfigValues();
LocaleHandler.getInstance().loadLocale();
sender.sendRichMessage(LocaleHandler.getInstance().getConfigReloaded());
return true;
}
}
83 changes: 45 additions & 38 deletions src/main/java/simplexity/adminhax/config/LocaleHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class LocaleHandler {
private String repairSelf, repairOther, repairHeader, noItemsRepaired;
//GodMode messages
private String godmodeSelf, godmodeOther, godmodeGetSelf, godmodeGetOther;
//Broadcast Message
private String broadcastServerPrefix;
//Errors
private String invalidPlayer, noPermission, mustBePlayer, notEnoughArguments, invalidNumber, notInRange,
invalidCommand, configReloaded, cannotBeRepaired;
Expand Down Expand Up @@ -55,44 +57,45 @@ public void loadLocale() {
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
prefix = localeConfig.getString("insertion.prefix");
enabled = localeConfig.getString("insertion.enabled");
disabled = localeConfig.getString("insertion.disabled");
flyspeed = localeConfig.getString("insertion.flyspeed");
walkspeed = localeConfig.getString("insertion.walkspeed");
item = localeConfig.getString("insertion.item");
flySetOwn = localeConfig.getString("fly.own");
flySetOther = localeConfig.getString("fly.other");
flySetByOther = localeConfig.getString("fly.by-other");
speedGetOther = localeConfig.getString("speed.get.other");
speedGetOwn = localeConfig.getString("speed.get.own");
speedSetOwn = localeConfig.getString("speed.set.own");
speedResetOwn = localeConfig.getString("speed.reset.own");
speedSetOther = localeConfig.getString("speed.set.other");
speedResetOther = localeConfig.getString("speed.reset.other");
speedSetByOther = localeConfig.getString("speed.set.by-other");
speedResetByOther = localeConfig.getString("speed.reset.by-other");
feedSelf = localeConfig.getString("feed.self");
feedOther = localeConfig.getString("feed.other");
healSelf = localeConfig.getString("heal.self");
healOther = localeConfig.getString("heal.other");
repairSelf = localeConfig.getString("repair.self");
repairOther = localeConfig.getString("repair.other");
repairHeader = localeConfig.getString("repair.header");
godmodeSelf = localeConfig.getString("godmode.self");
godmodeOther = localeConfig.getString("godmode.other");
godmodeGetSelf = localeConfig.getString("godmode.get.self");
godmodeGetOther = localeConfig.getString("godmode.get.other");
noItemsRepaired = localeConfig.getString("repair.no-items-repaired");
invalidPlayer = localeConfig.getString("error.invalid-player");
noPermission = localeConfig.getString("error.no-permission");
mustBePlayer = localeConfig.getString("error.must-be-player");
notEnoughArguments = localeConfig.getString("error.not-enough-arguments");
invalidNumber = localeConfig.getString("error.invalid-number");
notInRange = localeConfig.getString("error.not-in-range");
invalidCommand = localeConfig.getString("error.invalid-command");
cannotBeRepaired = localeConfig.getString("error.cannot-be-repaired");
configReloaded = localeConfig.getString("plugin-messages.config-reloaded");
prefix = localeConfig.getString("insertion.prefix", "<green>[<yellow>SF</yellow>]</green> ");
enabled = localeConfig.getString("insertion.enabled", "<green>enabled</green>");
disabled = localeConfig.getString("insertion.disabled", "<red>disabled</red>");
flyspeed = localeConfig.getString("insertion.flyspeed", "<yellow>flyspeed</yellow>");
walkspeed = localeConfig.getString("insertion.walkspeed", "<yellow>walkspeed</yellow>");
item = localeConfig.getString("insertion.item", "\n<gray>• <lang:<item>></gray>");
flySetOwn = localeConfig.getString("fly.own", "Your fly has been <value>");
flySetOther = localeConfig.getString("fly.other", "<target>'s fly has been <value>");
flySetByOther = localeConfig.getString("fly.by-other", "<green>Your fly has been <value></green>");
speedGetOther = localeConfig.getString("speed.get.other", "<grey><target>'s current <speedtype> is <value></grey>");
speedGetOwn = localeConfig.getString("speed.get.own","<grey>Your <speedtype> is currently set to <value></grey>");
speedSetOwn = localeConfig.getString("speed.set.own", "<green>Your <speedtype> has been set to <value></green>");
speedResetOwn = localeConfig.getString("speed.reset.own", "<green>Your <speedtype> has been reset</green>");
speedSetOther = localeConfig.getString("speed.set.other", "<green>You set <target>'s <speedtype> to <value></green>");
speedResetOther = localeConfig.getString("speed.reset.other", "<green><target>'s <speedtype> has been reset</green>");
speedSetByOther = localeConfig.getString("speed.set.by-other", "<green>Your <speedtype> has been set to <value> by <initiator></green>");
speedResetByOther = localeConfig.getString("speed.reset.by-other", "<green>Your <speedtype> has been reset by <initiator></green>");
feedSelf = localeConfig.getString("feed.self", "<green>You have been fed</green>");
feedOther = localeConfig.getString("feed.other", "<green>You have fed <target></green>");
healSelf = localeConfig.getString("heal.self", "<green>You have been healed</green>");
healOther = localeConfig.getString("heal.other", "<green>You have healed <target></green>");
repairSelf = localeConfig.getString("repair.self", "<green><hover:show_text:'<items>'>Your items have been repaired!</hover></green>");
repairOther = localeConfig.getString("repair.other", "<green><hover:show_text:'<items>'>You have repaired <target>'s items!</hover><green>");
repairHeader = localeConfig.getString("repair.header", "<aqua><u>Repaired Items</u></aqua>");
godmodeSelf = localeConfig.getString("godmode.self", "<yellow>God-Mode has been <value></yellow>");
godmodeOther = localeConfig.getString("godmode.other", "<yellow>God-Mode has been <value> for <target></yellow>");
godmodeGetSelf = localeConfig.getString("godmode.get.self", "<yellow>God-Mode is currently <value></yellow>");
godmodeGetOther = localeConfig.getString("godmode.get.other", "<yellow><target>'s God-Mode is currently <value></yellow>");
noItemsRepaired = localeConfig.getString("repair.no-items-repaired", "<gray>No items were able to be repaired</gray>");
invalidPlayer = localeConfig.getString("error.invalid-player", "<red>That is not a valid player. Please check your spelling and try again</red>");
noPermission = localeConfig.getString("error.no-permission", "<red>You do not have permission to run this command</red>");
mustBePlayer = localeConfig.getString("error.must-be-player", "<red>You must be a player to run this command</red>");
notEnoughArguments = localeConfig.getString("error.not-enough-arguments", "<red>You did not provide enough arguments. Please check your syntax and try again</red>");
invalidNumber = localeConfig.getString("error.invalid-number", "<red>Sorry, you did not enter a valid flyspeed, please try again</red>");
notInRange = localeConfig.getString("error.not-in-range", "<red>Sorry, you must provide a number between <min> and <max></red>");
invalidCommand = localeConfig.getString("error.invalid-command", "<red>Sorry, that subcommand is invalid. Please check your syntax and try again</red>");
cannotBeRepaired = localeConfig.getString("error.cannot-be-repaired", "<red>That item cannot be repaired</red>");
configReloaded = localeConfig.getString("plugin-messages.config-reloaded", "<gold>Config Reloaded</gold>");
broadcastServerPrefix = localeConfig.getString("broadcast.server-prefix", "<green>[Server]</green> » ");
}

public String getPrefix() {
Expand Down Expand Up @@ -246,4 +249,8 @@ public String getGodmodeGetSelf() {
public String getGodmodeGetOther() {
return godmodeGetOther;
}

public String getBroadcastServerPrefix() {
return broadcastServerPrefix;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/locale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ error:
not-in-range : "<red>Sorry, you must provide a number between <min> and <max></red>"
invalid-command : "<red>Sorry, that subcommand is invalid. Please check your syntax and try again</red>"
cannot-be-repaired: "<red>That item cannot be repaired</red>"
broadcast:
server-prefix: "<green>[Server]</green> » "
plugin-messages:
config-reloaded: "<gold>Config Reloaded</gold>"
15 changes: 15 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ commands:
permission: adminhax.commands.godmode
description: allows you to toggle godmode/invincibility
usage: /<command> [get|toggle] <player>
broadcastmsg:
permissions: adminhax.commands.broadcast
description: allows you to broadcast a message server-wide
usage: /broadcastmsg <message>
aliases: [broadcast]
adminhaxreload:
permissions: adminhax.reload
description: reloads the plugin
usage: /adminhaxreload
permissions:
adminhax.commands.speed.walk:
default: op
Expand Down Expand Up @@ -134,3 +143,9 @@ permissions:
adminhax.commands.other.godmode.get:
default: op
description: allows you to see what others' godmode status is
adminhax.commands.broadcast:
default: op
description: Allows you to broadcast a message to the server
adminhax.reload:
default: op
description: Reloads the plugin

0 comments on commit 6ae4e68

Please sign in to comment.