Skip to content

Commit

Permalink
Merge pull request #83 from BlueTree242/develop
Browse files Browse the repository at this point in the history
Merge dev with beta
  • Loading branch information
BlueTree242 authored Oct 31, 2021
2 parents e1d17ee + 31ad85b commit d661583
Show file tree
Hide file tree
Showing 102 changed files with 1,318 additions and 1,073 deletions.
32 changes: 16 additions & 16 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
version: 2
updates:
- package-ecosystem: gradle
target-branch: "development"
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 4
ignore:
- dependency-name: org.mariadb.jdbc:mariadb-java-client
versions:
- 2.7.2
- dependency-name: org.hsqldb:hsqldb
versions:
- 2.5.1
- dependency-name: com.zaxxer:HikariCP
versions:
- 4.0.1
- package-ecosystem: gradle
target-branch: "development"
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 4
ignore:
- dependency-name: org.mariadb.jdbc:mariadb-java-client
versions:
- 2.7.2
- dependency-name: org.hsqldb:hsqldb
versions:
- 2.5.1
- dependency-name: com.zaxxer:HikariCP
versions:
- 4.0.1
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# DiscordSRVUtils

Here is the source code! feel free to make pull requests!

Download: https://www.spigotmc.org/resources/discordsrvutils.85958/

# API

Put these into your pom.xml

```xml
<repository>
<id>jitpack.io</id>
Expand All @@ -21,18 +24,20 @@ Put these into your pom.xml
```

For gradle

```gradle
repositories {
// Any other repository...
maven { url 'https://jitpack.io' }
}
```

```gradle
dependencies {
implementation 'com.github.BlueTree242:DiscordSRVUtils:VERSION'
}
```

You also need to add DiscordSRV's dependecy and repository, which you can find here:
https://github.com/DiscordSRV/DiscordSRV/wiki#developers

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* LICENSE
* DiscordSRVUtils
Expand Down Expand Up @@ -116,6 +115,7 @@ dependencies {

group = 'me.bluetree.discordsrvutils'
version = '1.2.4-BETA-1'

description = 'DiscordSRVUtils'
compileJava.options.encoding 'UTF-8'
java.sourceCompatibility = JavaVersion.VERSION_11
Expand Down
337 changes: 115 additions & 222 deletions src/main/java/tk/bluetree242/discordsrvutils/DiscordSRVUtils.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
import org.bukkit.entity.Player;
import tk.bluetree242.discordsrvutils.leveling.LevelingManager;

import java.util.regex.Pattern;

public class PAPIExpansion extends PlaceholderExpansion {
private DiscordSRVUtils core = DiscordSRVUtils.get();

@Override
public String getIdentifier() {
return "DiscordSRVUtils";
Expand All @@ -42,7 +41,7 @@ public boolean canRegister() {

@Override
public String getAuthor() {
return String.join( ", ", core.getDescription().getAuthors());
return String.join(", ", core.getDescription().getAuthors());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,27 @@

package tk.bluetree242.discordsrvutils.commandmanagement;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import tk.bluetree242.discordsrvutils.DiscordSRVUtils;
import tk.bluetree242.discordsrvutils.utils.Utils;

public abstract class BukkitCommand implements CommandExecutor {
protected DiscordSRVUtils core = DiscordSRVUtils.get();
public abstract class BukkitCommand implements CommandExecutor {
protected DiscordSRVUtils core = DiscordSRVUtils.get();

@Override
public final boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
DiscordSRVUtils.get().executeAsync(() -> {
try {
onRunAsync(sender, command, label, args);
} catch (Throwable ex) {
ex.printStackTrace();
sender.sendMessage(Utils.colors("&cAn internal error occurred while executing this command"));
}
});
Bukkit.getScheduler().runTaskAsynchronously(DiscordSRVUtils.get(), () -> {
try {
onRunAsync(sender, command, label, args);
} catch (Throwable ex) {
ex.printStackTrace();
sender.sendMessage(Utils.colors("&cAn internal error occurred while executing this command"));
}
});
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder;
import github.scarsz.discordsrv.dependencies.jda.api.Permission;
import github.scarsz.discordsrv.dependencies.jda.api.entities.MessageEmbed;

import tk.bluetree242.discordsrvutils.DiscordSRVUtils;
import tk.bluetree242.discordsrvutils.utils.Utils;

Expand All @@ -39,10 +38,10 @@ public abstract class Command {
private final String description;
private final String usage;
private final String[] aliases;
public DiscordSRVUtils core = DiscordSRVUtils.get();
private boolean adminOnly = false;
private boolean ownerOnly = false;
private CommandCategory category = null;
public DiscordSRVUtils core = DiscordSRVUtils.get();

public Command(String cmd, CommandType type, String description, String usage, Permission requiredPermission, String... aliases) {
this.cmd = cmd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ public class CommandCategory {
public static final CommandCategory SUGGESTIONS = new CommandCategory("Suggestions", "\uD83D\uDCA1");
public static final CommandCategory SUGGESTIONS_ADMIN = new CommandCategory("Suggestions Admin", "\uD83D\uDCA1");
private static Set<CommandCategory> externals = new HashSet<>();
private List<Command> commands = new ArrayList<>();
private String name;
private String prefix;


private CommandCategory(String name, String prefix) {
this.name = name;
this.prefix = prefix;
}

public static CommandCategory[] values() {
ArrayList<CommandCategory> list = new ArrayList(Arrays.asList(new CommandCategory[]{TICKETS, TICKETS_ADMIN, ADMIN, LEVELING, SUGGESTIONS, SUGGESTIONS_ADMIN}));
for (CommandCategory external : externals) {
Expand All @@ -55,20 +65,10 @@ public static CommandCategory ofName(String name) {
return null;
}



private List<Command> commands = new ArrayList<>();

private String name;
private String prefix;
private CommandCategory(String name, String prefix) {
this.name = name;
this.prefix = prefix;
}

public String getName() {
return name;
}

public String getPrefix() {
return prefix;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@
import org.bukkit.entity.Player;
import tk.bluetree242.discordsrvutils.DiscordSRVUtils;
import tk.bluetree242.discordsrvutils.embeds.Embed;
import tk.bluetree242.discordsrvutils.messages.MessageManager;
import tk.bluetree242.discordsrvutils.exceptions.UnCheckedRateLimitedException;
import tk.bluetree242.discordsrvutils.messages.MessageManager;
import tk.bluetree242.discordsrvutils.placeholder.PlaceholdObject;
import tk.bluetree242.discordsrvutils.placeholder.PlaceholdObjectList;
import tk.bluetree242.discordsrvutils.utils.Utils;


import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

Expand Down Expand Up @@ -141,11 +140,10 @@ public CompletableFuture handleCF(CompletableFuture cf, boolean shouldDM, String
MessageChannel channel = shouldDM ? getAuthor().openPrivateChannel().complete() : getChannel();
if (ex instanceof UnCheckedRateLimitedException) {
channel.sendMessage(Embed.error(failure, "Rate limited. Try again in: " + Utils.getDuration(((RateLimitedException) ((UnCheckedRateLimitedException) ex).getCause()).getRetryAfter()))).queue();
} else
if (!(ex instanceof InsufficientPermissionException)) {
} else if (!(ex instanceof InsufficientPermissionException)) {
channel.sendMessage(Embed.error(failure)).queue();
DiscordSRVUtils.get().defaultHandle(ex);
} else {
} else {
InsufficientPermissionException exc = (InsufficientPermissionException) ex;
GuildChannel chnl = DiscordSRVUtils.get().getJDA().getShardManager().getGuildChannelById(exc.getChannelId());
channel.sendMessage(Embed.error(failure, "Missing " + exc.getPermission().getName() + " Permission" + (chnl == null ? "" : " In #" + chnl.getName()))).queue();
Expand All @@ -156,7 +154,6 @@ public CompletableFuture handleCF(CompletableFuture cf, boolean shouldDM, String
}



public <H> CompletableFuture<H> handleCF(CompletableFuture<H> cf, boolean shouldDM, String failure) {
Checks.notNull(cf, "CompletableFuture");
Checks.notNull(failure, "Failure Message");
Expand All @@ -166,11 +163,10 @@ public <H> CompletableFuture<H> handleCF(CompletableFuture<H> cf, boolean should
MessageChannel channel = shouldDM ? getAuthor().openPrivateChannel().complete() : getChannel();
if (ex instanceof UnCheckedRateLimitedException) {
channel.sendMessage(Embed.error(failure, "Rate limited. Try again in: " + Utils.getDuration(((RateLimitedException) ((UnCheckedRateLimitedException) ex).getCause()).getRetryAfter()))).queue();
} else
if (!(ex instanceof InsufficientPermissionException)) {
} else if (!(ex instanceof InsufficientPermissionException)) {
channel.sendMessage(Embed.error(failure)).queue();
DiscordSRVUtils.get().defaultHandle(ex);
} else {
} else {
InsufficientPermissionException exc = (InsufficientPermissionException) ex;
GuildChannel chnl = DiscordSRVUtils.get().getJDA().getGuildChannelById(exc.getChannelId());
channel.sendMessage(Embed.error(failure, "Missing " + exc.getPermission().getName() + " Permission" + chnl == null ? "" : " In #" + chnl.getName())).queue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,4 @@ public List<Command> getCommandsWithoutAliases() {
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,14 @@

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import space.arim.dazzleconf.error.ConfigFormatSyntaxException;
import space.arim.dazzleconf.error.InvalidConfigException;
import tk.bluetree242.discordsrvutils.DiscordSRVUtils;
import tk.bluetree242.discordsrvutils.commandmanagement.BukkitCommand;
import tk.bluetree242.discordsrvutils.exceptions.ConfigurationLoadException;
import tk.bluetree242.discordsrvutils.utils.DebugUtil;
import tk.bluetree242.discordsrvutils.utils.Utils;

import java.awt.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class DiscordSRVUtilsCommand extends BukkitCommand {
public void onRunAsync(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Throwable{
public void onRunAsync(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Throwable {
if (args.length == 0) {
sender.sendMessage(colors("&eRunning DiscordSRVUtils v" + core.getDescription().getVersion()));
sender.sendMessage(colors("&bStatus: " + (core.isReady() ? "&aRunning and functioning" : "&cNot running")));
Expand All @@ -60,9 +50,14 @@ public void onRunAsync(@NotNull CommandSender sender, @NotNull Command command,
}
return;
}
}else if (args[0].equalsIgnoreCase("debug")) {
} else if (args[0].equalsIgnoreCase("debug")) {
if (sender.hasPermission("discordsrvutils.debug")) {
sender.sendMessage(colors("&aYour Debug report is available at: &e" + DebugUtil.run()));
sender.sendMessage(ChatColor.GREEN + "Preparing Debug Report... Please wait");
try {
sender.sendMessage(colors("&aYour Debug report is available at: &e" + DebugUtil.run()));
} catch (Exception e) {
sender.sendMessage(colors("&cERROR: " + e.getMessage()));
}
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
List<String> values = new ArrayList<>();
if (args.length == 1) {
if (sender.hasPermission("discordsrvutils.reload"))
values.add("reload");
values.add("reload");
if (sender.hasPermission("discordsrvutils.debug"))
values.add("debug");
}

List<String> result = new ArrayList<>();
for (String a : values) {
if (a.toLowerCase().startsWith(args[args.length -1].toLowerCase()))
if (a.toLowerCase().startsWith(args[args.length - 1].toLowerCase()))
result.add(a);
}
return result.isEmpty() ? Collections.emptyList() : result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@
package tk.bluetree242.discordsrvutils.commands.discord;

import github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder;
import github.scarsz.discordsrv.dependencies.jda.api.Permission;
import github.scarsz.discordsrv.dependencies.jda.api.entities.MessageEmbed;
import tk.bluetree242.discordsrvutils.commandmanagement.*;
import tk.bluetree242.discordsrvutils.embeds.Embed;

import java.awt.*;
import java.time.Instant;
import java.util.ArrayList;
import java.util.StringJoiner;

public class HelpCommand extends Command {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* END
*/

package tk.bluetree242.discordsrvutils.commands.discord;
package tk.bluetree242.discordsrvutils.commands.discord.admin;

import org.json.JSONException;
import tk.bluetree242.discordsrvutils.commandmanagement.Command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
* END
*/

package tk.bluetree242.discordsrvutils.commands.discord;
package tk.bluetree242.discordsrvutils.commands.discord.leveling;

import github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder;
import github.scarsz.discordsrv.dependencies.jda.api.Permission;
import tk.bluetree242.discordsrvutils.commandmanagement.Command;
import tk.bluetree242.discordsrvutils.commandmanagement.CommandCategory;
import tk.bluetree242.discordsrvutils.commandmanagement.CommandEvent;
Expand Down Expand Up @@ -56,7 +55,7 @@ public void run(CommandEvent e) throws Exception {
case 3:
prefix = ":third_place:";
}
joiner.add("**" +player.getRank() + ".** " + prefix + player.getName() + " **Level:**" + player.getLevel());
joiner.add("**" + player.getRank() + ".** " + prefix + player.getName() + " **Level:**" + player.getLevel());
}
embed.setTitle("Leaderboard");
embed.setDescription(joiner.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
* END
*/

package tk.bluetree242.discordsrvutils.commands.discord;
package tk.bluetree242.discordsrvutils.commands.discord.leveling;

import github.scarsz.discordsrv.dependencies.jda.api.Permission;
import github.scarsz.discordsrv.dependencies.jda.api.entities.User;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import tk.bluetree242.discordsrvutils.commandmanagement.Command;
import tk.bluetree242.discordsrvutils.commandmanagement.CommandCategory;
import tk.bluetree242.discordsrvutils.commandmanagement.CommandEvent;
Expand All @@ -35,11 +32,9 @@
import tk.bluetree242.discordsrvutils.placeholder.PlaceholdObject;
import tk.bluetree242.discordsrvutils.placeholder.PlaceholdObjectList;

import java.util.UUID;

public class LevelCommand extends Command {
public LevelCommand() {
super("level", CommandType.EVERYWHERE, "Get leveling info about a user or yourself", "[P]level [Player name or user mention]", null, CommandCategory.LEVELING, "rank");
super("level", CommandType.EVERYWHERE, "Get leveling info about a user or yourself", "[P]level [Player name or user mention]", null, CommandCategory.LEVELING, "rank");
}

@Override
Expand Down
Loading

0 comments on commit d661583

Please sign in to comment.