Skip to content

Commit

Permalink
TEMPORARY: limit to 2 commands
Browse files Browse the repository at this point in the history
  • Loading branch information
TBG1000 committed Jun 10, 2022
1 parent 6bf8933 commit 46570db
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 31 deletions.
63 changes: 42 additions & 21 deletions src/main/java/tc/oc/occ/nitro/NitroListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,27 @@ public void onNitroAdd(NitroUserAddEvent event) {
// Print amount of commands to be executed
Bukkit.getConsoleSender()
.sendMessage("[Nitro] Executing " + commandsToExecute.length + " command(s)");
// Print the commands
for (int i = 0; i < commandsToExecute.length; i++) {
Bukkit.getConsoleSender()
.sendMessage("[Nitro] Command " + (i + 1) + ": " + commandsToExecute[i]);
// If the command contains the placeholder %s, replace it with the player's name
if (commandsToExecute[i].contains("%s")) {
Bukkit.dispatchCommand(
Bukkit.getConsoleSender(), commandsToExecute[i].replace("%s", parts[2]));
} else {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), commandsToExecute[i]);
}
// Execute commands
if (commandsToExecute.length == 1) {
Bukkit.getServer()
.dispatchCommand(Bukkit.getConsoleSender(), commandsToExecute[0].replace("%s", parts[2]));
} else {
Bukkit.getScheduler()
.runTaskLater(
plugin,
() ->
Bukkit.getServer()
.dispatchCommand(
Bukkit.getConsoleSender(), commandsToExecute[0].replace("%s", parts[2])),
20 * 2);
Bukkit.getScheduler()
.runTaskLater(
plugin,
() ->
Bukkit.getServer()
.dispatchCommand(
Bukkit.getConsoleSender(), commandsToExecute[1].replace("%s", parts[2])),
20 * 4);
}
api.getConfig().save(plugin.getConfig());
plugin.saveConfig();
Expand Down Expand Up @@ -93,16 +103,27 @@ public void onNitroRemove(NitroUserRemoveEvent event) {
// Print amount of commands to be executed
Bukkit.getConsoleSender()
.sendMessage("[Nitro] Executing " + commandsToExecute.length + " command(s)");
// Print the commands
for (int i = 0; i < commandsToExecute.length; i++) {
Bukkit.getConsoleSender()
.sendMessage("[Nitro] Command " + (i + 1) + ": " + commandsToExecute[i]);
if (commandsToExecute[i].contains("%s")) {
Bukkit.dispatchCommand(
Bukkit.getConsoleSender(), commandsToExecute[i].replace("%s", parts[2]));
} else {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), commandsToExecute[i]);
}
// Execute commands
if (commandsToExecute.length == 1) {
Bukkit.getServer()
.dispatchCommand(Bukkit.getConsoleSender(), commandsToExecute[0].replace("%s", parts[2]));
} else {
Bukkit.getScheduler()
.runTaskLater(
plugin,
() ->
Bukkit.getServer()
.dispatchCommand(
Bukkit.getConsoleSender(), commandsToExecute[0].replace("%s", parts[2])),
20 * 2);
Bukkit.getScheduler()
.runTaskLater(
plugin,
() ->
Bukkit.getServer()
.dispatchCommand(
Bukkit.getConsoleSender(), commandsToExecute[1].replace("%s", parts[2])),
20 * 4);
}
api.getConfig().removeNitro(event.getUser());
api.getConfig().save(plugin.getConfig());
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/tc/oc/occ/nitro/discord/DiscordBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public void enable() {
new DiscordApiBuilder()
.setToken(config.getToken())
.setWaitForServersOnStartup(false)
.setIntents(Intent.GUILDS, Intent.GUILD_MEMBERS, Intent.GUILD_PRESENCES, Intent.GUILD_MESSAGES)
.setIntents(
Intent.GUILDS, Intent.GUILD_MEMBERS, Intent.GUILD_PRESENCES, Intent.GUILD_MESSAGES)
.login()
.thenAcceptAsync(
api -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package tc.oc.occ.nitro.discord.listener;

import java.util.UUID;
import org.bukkit.Bukkit;
import org.javacord.api.entity.message.MessageBuilder;
import org.javacord.api.event.message.MessageCreateEvent;
import org.javacord.api.listener.message.MessageCreateListener;
Expand Down Expand Up @@ -53,15 +51,9 @@ public void onMessageCreate(MessageCreateEvent event) {
.thenAcceptAsync(
uuid -> {
if (uuid != null) {
String minecraftUsername =
Bukkit.getPlayer(UUID.fromString(uuid.toString()))
.getName();
NitroUser nitro =
config.addNitro(
discriminatedUsername,
discordId,
minecraftUsername,
uuid);
discriminatedUsername, discordId, username, uuid);
NitroCloudy.get().callSyncEvent(new NitroUserAddEvent(nitro));
new MessageBuilder()
.append(
Expand Down

0 comments on commit 46570db

Please sign in to comment.