Skip to content

Commit

Permalink
Major update
Browse files Browse the repository at this point in the history
  • Loading branch information
TBG1000 committed Jul 5, 2022
1 parent af96541 commit fe7bcc5
Show file tree
Hide file tree
Showing 15 changed files with 584 additions and 22 deletions.
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ This plugin was originally created for use on [Overcast Community](https://oc.tc

## Features and functionality

- Nitro Boosting privileges can be claimed or redeemed by users to the Minecraft account/player of their choice. To do this, simply instruct the user to enter `!nitro <user>` into the designated redemption channel (specified in `config.yml` through `channel-main`).
- Using `!nitro help` will show the user a list of available commands.

- Nitro Boosting privileges can be claimed or redeemed by users to the Minecraft account/player of their choice. To do this, simply instruct the user to enter `!nitro-redeem <minecraft username>` into the designated redemption channel (specified in `config.yml` through `channel-main`).

- Users may also remove their own privileges by using `!nitro-remove`.

- When the user does redeem Nitro privileges, the plugin will execute, through the console, the commands present in `redemption-commands`. A similar process will take place once the user stops boosting the server or loses the "boosting" role (meaning the removal commands will be executed).

Expand Down Expand Up @@ -44,6 +48,21 @@ nitro-boosters:
- Discord alerts channel
![image](https://user-images.githubusercontent.com/46306028/172479405-7abfd61d-0646-4aec-a819-0700e8ccf056.png)

## Management and staff commands

A number of commands are only available to staff in the configured staff channel of the configuration (`channel-staff`).

- `!nitro-list <boosters|bans|commands>`
- `boosters`: Lists all Nitro boosters that have redeemed Nitro privileges.
- `bans`: Lists all users that have been banned from redeemed Nitro privileges.
- `commands`: Lists the redemption and removal commands present in the configuration.
- `!nitro-force-remove`: Forcefully removes an active Nitro booster from the `nitro-boosters` list in the configuration. This command will execute the available removal commands for the targeted user.
- `!nitro-ban <discriminated username> <discord id>`: Bans a user from redeeming Nitro privileges.
- Banning a user will prevent them from using `!nitro-redeem` or `!nitro-remove` again until they are unbanned.
- If the user was present in the `nitro-boosters` list, they will also be removed from it and removal commands will be executed.
- `!nitro-unban <discriminated username> <discord id>`: Unbans a user from redeeming Nitro privileges.
- Unbanning a user will allow them to use `!nitro-redeem` or `!nitro-remove` again.
- `!nitro-reload`: Reloads the configuration file.
## Building

1. First, [clone](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository) or download the project's source code.
Expand Down Expand Up @@ -71,8 +90,9 @@ When creating the bot that will be linked to Nitro's plugin `.jar`, be sure to t
- The ID of the server in which the bot will be functioning.
- The ID of the Nitro Booster role.
- This role can be any role, not necessarily the legitimate "Nitro Booster" role.
- The ID of the channel in which redemption/removal logs will be sent.
- The ID of the channel in which users can redeem Nitro Boosting privileges.
- The ID of the channel in which logs will be sent.
- The ID of the channel in which users can redeem/remove Nitro Boosting privileges.
- The ID of the channel in which staff members can use the management commands.
- The command(s) to be executed on the Minecraft server once a user redeems privileges.
- The command(s) to be executed on the Minecraft server once a user stops boosting the Discord server.
4. Restart the server once again for the changes to take place. Once your bot goes online, users may start redeeming their privileges in the designated channel.
Expand All @@ -91,6 +111,7 @@ nitro-role: "" # ID of the nitro role
channel-alerts: "" # ID of channel where logs from bot are sent
channel-main: "" # ID of channel where command can be used
channel-staff: "" # ID of channel where staff can use management commands
# List of redemption commands, executed when the user boosts the server
redemption-commands:
Expand All @@ -104,4 +125,10 @@ removal-commands:
# Discriminated Discord username : User Discord ID : Minecraft username : Minecraft username
nitro-boosters:
- ""
# List of users banned from redemption privileges
# Format
# Discriminated Discord username : User Discord ID
banned-boosters:
- ""
```
6 changes: 6 additions & 0 deletions src/main/java/tc/oc/occ/nitro/NitroCloudy.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ public static NitroCloudy get() {
public void callSyncEvent(Event event) {
getServer().getScheduler().runTask(this, () -> getServer().getPluginManager().callEvent(event));
}

public void reloadBotConfig() {
this.reloadConfig();
config.reload(getConfig());
bot.reload();
}
}
23 changes: 21 additions & 2 deletions src/main/java/tc/oc/occ/nitro/NitroConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.UUID;
import java.util.stream.Collectors;
import org.bukkit.configuration.Configuration;
import tc.oc.occ.nitro.data.BannedNitroUser;
import tc.oc.occ.nitro.data.NitroUser;

public class NitroConfig {
Expand All @@ -16,9 +17,11 @@ public class NitroConfig {
private String nitroRole;

private List<NitroUser> nitroUsers;
private List<BannedNitroUser> bannedUsers;

private String alertChannel;
private String mainChannel;
private String staffChannel;

private List<String> redemptionCommands;
private List<String> removalCommands;
Expand All @@ -34,6 +37,7 @@ public void reload(Configuration config) {
this.nitroRole = config.getString("nitro-role");
this.alertChannel = config.getString("channel-alerts");
this.mainChannel = config.getString("channel-main");
this.staffChannel = config.getString("channel-staff");
this.redemptionCommands = config.getStringList("redemption-commands");
this.removalCommands = config.getStringList("removal-commands");

Expand All @@ -43,6 +47,13 @@ public void reload(Configuration config) {
.filter(str -> str != null && !str.isEmpty())
.map(NitroUser::of)
.collect(Collectors.toList());

List<String> bannedData = config.getStringList("banned-boosters");
this.bannedUsers =
bannedData.stream()
.filter(str -> str != null && !str.isEmpty())
.map(BannedNitroUser::of)
.collect(Collectors.toList());
}

public boolean isEnabled() {
Expand All @@ -69,15 +80,23 @@ public String getMainChannel() {
return mainChannel;
}

public String getStaffChannel() {
return staffChannel;
}

public List<NitroUser> getUsers() {
return nitroUsers;
}

public List<String> getRedemptionCommands(String playerId) {
public List<BannedNitroUser> getBannedUsers() {
return bannedUsers;
}

public List<String> getRedemptionCommands() {
return redemptionCommands;
}

public List<String> getRemovalCommands(String playerId) {
public List<String> getRemovalCommands() {
return removalCommands;
}

Expand Down
9 changes: 4 additions & 5 deletions src/main/java/tc/oc/occ/nitro/NitroListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public void onNitroAdd(NitroUserAddEvent event) {
+ parts[3]
+ ")");
// Iterate through the list of strings from redemption-commands in the config
for (String redemptionCommand :
api.getConfig().getRedemptionCommands(event.getUser().getPlayerId().toString())) {
for (String redemptionCommand : api.getConfig().getRedemptionCommands()) {
// Print the redemption command(s) in console
Bukkit.getConsoleSender().sendMessage("[Nitro] Executing redemption command: " + redemptionCommand);
Bukkit.getConsoleSender()
.sendMessage("[Nitro] Executing redemption command: " + redemptionCommand);
// Execute the command
if (redemptionCommand.contains("%s")) {
Bukkit.getServer()
Expand Down Expand Up @@ -85,8 +85,7 @@ public void onNitroRemove(NitroUserRemoveEvent event) {
+ parts[1]
+ ") is no longer boosting the server.");
// Iterate through the list of strings from removal-commands in the config
for (String removalCommand :
api.getConfig().getRemovalCommands(event.getUser().getPlayerId().toString())) {
for (String removalCommand : api.getConfig().getRemovalCommands()) {
// Print the removal command(s) in console
Bukkit.getConsoleSender().sendMessage("[Nitro] Executing removal command: " + removalCommand);
// Execute the command
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/tc/oc/occ/nitro/data/BannedNitroUser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package tc.oc.occ.nitro.data;

/** NitroUser - A linked player who has nitro * */
public class BannedNitroUser {

private String discriminatedUsername;
private String discordId;

public BannedNitroUser(String discriminatedUsername, String discordId) {
this.discriminatedUsername = discriminatedUsername;
this.discordId = discordId;
}

public String getDiscriminatedUsername() {
return discriminatedUsername;
}

public String getDiscordId() {
return discordId;
}

@Override
public String toString() {
return String.format("%s:%s", discriminatedUsername, discordId);
}

@Override
public boolean equals(Object other) {
return (other instanceof BannedNitroUser)
&& ((BannedNitroUser) other).getDiscordId().equalsIgnoreCase(getDiscordId());
}

public static BannedNitroUser of(String data) {
String[] parts = data.split(":");
if (parts.length == 2) {
String discordName = parts[0];
String discordId = parts[1];
return new BannedNitroUser(discordName, discordId);
}
return null;
}
}
9 changes: 6 additions & 3 deletions src/main/java/tc/oc/occ/nitro/discord/DiscordBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import org.javacord.api.entity.intent.Intent;
import org.javacord.api.entity.server.Server;
import tc.oc.occ.nitro.NitroConfig;
import tc.oc.occ.nitro.discord.listener.NitroAddAlert;
import tc.oc.occ.nitro.discord.listener.NitroRedeemer;
import tc.oc.occ.nitro.discord.listener.NitroRemoveAlert;
import tc.oc.occ.nitro.discord.listener.*;

public class DiscordBot {

Expand Down Expand Up @@ -42,6 +40,11 @@ public void enable() {
setAPI(api);
api.setMessageCacheSize(1, 60 * 60);
api.addListener(new NitroRedeemer(this, getConfig()));
api.addListener(new NitroRemover(this, getConfig()));
api.addListener(new NitroList(this, getConfig()));
api.addListener(new NitroBan(this, getConfig()));
api.addListener(new NitroHelp(this, getConfig()));
api.addListener(new NitroReload(this, getConfig()));
api.addListener(new NitroAddAlert(this, getConfig()));
api.addListener(new NitroRemoveAlert(this, getConfig()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public void onUserRoleAdd(UserRoleAddEvent event) {
if (isNitro(event.getRole())) {
// ADD ROLE
api.sendMessage(
":100: Thanks for boosting the server "
":tada: Thanks for boosting the server "
+ event.getUser().getMentionTag()
+ "! Use `!nitro <minecraft username>` to claim your in-game privileges :tada:",
+ "! Use `!nitro-redeem <minecraft username>` to claim your in-game privileges. If you need assistance, use `!nitro-help` or contact a staff member.",
false);
}
}
Expand Down
141 changes: 141 additions & 0 deletions src/main/java/tc/oc/occ/nitro/discord/listener/NitroBan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package tc.oc.occ.nitro.discord.listener;

import org.javacord.api.entity.message.MessageBuilder;
import org.javacord.api.event.message.MessageCreateEvent;
import org.javacord.api.listener.message.MessageCreateListener;
import tc.oc.occ.nitro.NitroCloudy;
import tc.oc.occ.nitro.NitroConfig;
import tc.oc.occ.nitro.data.BannedNitroUser;
import tc.oc.occ.nitro.data.NitroUser;
import tc.oc.occ.nitro.discord.DiscordBot;
import tc.oc.occ.nitro.events.NitroUserRemoveEvent;

public class NitroBan extends NitroListener implements MessageCreateListener {

public NitroBan(DiscordBot api, NitroConfig config) {
super(api, config);
}

@Override
public void onMessageCreate(MessageCreateEvent event) {
if (event.getChannel().getIdAsString().equals(config.getStaffChannel())) {
if (event.getMessage().getContent().startsWith("!nitro-ban")) {
if (event.getMessage().getContent().split(" ").length == 3) {
String discriminatedUsername = event.getMessage().getContent().split(" ")[1];
String discordId = event.getMessage().getContent().split(" ")[2];
if (discordId.length() == 18) {
if (config.getBannedUsers().stream()
.noneMatch(user -> user.getDiscordId().equals(discordId))) {
new MessageBuilder()
.append(
":hammer: "
+ event.getMessageAuthor().asUser().get().getMentionTag()
+ " The user `"
+ discriminatedUsername
+ "` with Discord ID `"
+ discordId
+ "` has been banned from redeeming Nitro.")
.send(event.getChannel());
api.alert(
":hammer: `"
+ event.getMessageAuthor().getDiscriminatedName()
+ "` (`"
+ event.getMessageAuthor().getIdAsString()
+ "`) has banned `"
+ discriminatedUsername
+ "` with Discord ID `"
+ discordId
+ "` from redeeming Nitro.");
config.getBannedUsers().add(new BannedNitroUser(discriminatedUsername, discordId));
// If the user was an active booster, remove him from the nitro-boosters list.
if (config.getUsers().stream()
.anyMatch(user -> user.getDiscordId().equals(discordId))) {
NitroUser nitro = config.getUser(discordId).get();
NitroCloudy.get().callSyncEvent(new NitroUserRemoveEvent(nitro));
}
} else {
new MessageBuilder()
.append(
":negative_squared_cross_mark: "
+ event.getMessageAuthor().asUser().get().getMentionTag()
+ " The user `"
+ discriminatedUsername
+ "` with Discord ID `"
+ discordId
+ "` is already banned. Use `!nitro-list bans` to see the list of banned users.")
.send(event.getChannel());
}
} else {
new MessageBuilder()
.append(
":negative_squared_cross_mark: "
+ event.getMessageAuthor().asUser().get().getMentionTag()
+ " The Discord ID `"
+ discordId
+ "` is not a valid 18-digit ID.")
.send(event.getChannel());
}
} else {
new MessageBuilder()
.append(
":warning: Incorrect syntax! Please use `!nitro-ban <discriminated user> <discord id>`")
.send(event.getChannel());
}
} else if (event.getMessage().getContent().startsWith("!nitro-unban")) {
if (event.getMessage().getContent().split(" ").length == 3) {
String discriminatedUsername = event.getMessage().getContent().split(" ")[1];
String discordId = event.getMessage().getContent().split(" ")[2];
if (discordId.length() == 18) {
if (config.getBannedUsers().stream()
.anyMatch(user -> user.getDiscordId().equals(discordId))) {
new MessageBuilder()
.append(
":white_check_mark: "
+ event.getMessageAuthor().asUser().get().getMentionTag()
+ " The user `"
+ discriminatedUsername
+ "` with Discord ID `"
+ discordId
+ "` has been unbanned. They may now redeem Nitro.")
.send(event.getChannel());
api.alert(
":flag_white: `"
+ event.getMessageAuthor().getDiscriminatedName()
+ "` (`"
+ event.getMessageAuthor().getIdAsString()
+ "`) has unbanned `"
+ discriminatedUsername
+ "` with Discord ID `"
+ discordId
+ "` from redeeming Nitro.");
config.getBannedUsers().removeIf(user -> user.getDiscordId().equals(discordId));
} else {
new MessageBuilder()
.append(
":negative_squared_cross_mark: "
+ event.getMessageAuthor().asUser().get().getMentionTag()
+ " The user with Discord ID `"
+ discordId
+ "` is not currently banned. Use `!nitro-list bans` to see the list of banned users.")
.send(event.getChannel());
}
} else {
new MessageBuilder()
.append(
":negative_squared_cross_mark: "
+ event.getMessageAuthor().asUser().get().getMentionTag()
+ " The Discord ID `"
+ discordId
+ "` is not a valid 18-digit ID. Please try again.")
.send(event.getChannel());
}
} else {
new MessageBuilder()
.append(
":warning: Incorrect syntax! Please use `!nitro-unban <discriminated user> <discord id>`")
.send(event.getChannel());
}
}
}
}
}
Loading

0 comments on commit fe7bcc5

Please sign in to comment.