Skip to content

Commit dc73d54

Browse files
committed
update 1.2.11
2 parents 33dd04a + e0cd754 commit dc73d54

File tree

57 files changed

+1102
-753
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1102
-753
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ hs_err_pid*
2727

2828
# Custom files
2929
build/
30+
core/build/
31+
bukkit/build/
3032
.idea/
3133
.gradle/

bukkit/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ dependencies {
5656
compileOnly urlFile("https://github.com/Zrips/CMI-API/releases/download/8.7.8.2/CMIAPI8.7.8.2.jar", "CMI-API")
5757
compileOnly 'net.lapismc:AFKPlus:3.3.15'
5858
implementation project(":core")
59+
implementation('org.slf4j:slf4j-api:2.0.1')
5960
compileOnly('com.discordsrv:discordsrv:1.26.0')
6061
implementation 'org.jooq:jooq:3.14.16'
6162
compileOnly 'net.essentialsx:EssentialsX:2.19.0'

bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/BukkitDebugger.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ private List<Map<String, String>> getDSUFiles() throws Exception {
157157
files.add(fileMap("leveling.yml", Utils.readFile(core.getPlatform().getDataFolder() + core.fileseparator + "leveling.yml")));
158158
files.add(fileMap("status.yml", Utils.readFile(core.getPlatform().getDataFolder() + core.fileseparator + "status.yml")));
159159
files.add(fileMap("suggestions.yml", Utils.readFile(core.getPlatform().getDataFolder() + core.fileseparator + "suggestions.yml")));
160-
files.add(fileMap("leveling-roles.json", Utils.readFile(core.getPlatform().getDataFolder() + core.fileseparator + "leveling-roles.json")));
161-
files.add(fileMap("leveling-roles.json", Utils.readFile(core.getPlatform().getDataFolder() + core.fileseparator + "leveling-roles.json")));
160+
files.add(fileMap("leveling-rewards.json", Utils.readFile(core.getPlatform().getDataFolder() + core.fileseparator + "leveling-rewards.json")));
162161
return files;
163162
}
164163

bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/BukkitPlatformServer.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ public class BukkitPlatformServer extends PlatformServer {
4343
private final DiscordSRVUtils core;
4444
@Getter
4545
private final Debugger debugger;
46+
private final DiscordSRVUtilsBukkit bcore;
4647

47-
public BukkitPlatformServer(DiscordSRVUtils core) {
48+
public BukkitPlatformServer(DiscordSRVUtils core, DiscordSRVUtilsBukkit bcore) {
4849
this.core = core;
4950
debugger = new BukkitDebugger(core);
51+
this.bcore = bcore;
5052
}
5153

5254
@Override
@@ -96,5 +98,23 @@ public PlatformPlayer getOfflinePlayer(UUID uuid) {
9698
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid), core);
9799
}
98100

101+
@Override
102+
public PlatformPlayer getPlayer(UUID uuid) {
103+
Player player = Bukkit.getPlayer(uuid);
104+
if (player == null) return null;
105+
return new BukkitPlayer(core, player);
106+
}
107+
108+
@Override
109+
public void executeConsoleCommands(String... cmds) {
110+
Runnable runnable = () -> {
111+
for (String cmd : cmds) {
112+
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);
113+
}
114+
};
115+
if (Bukkit.isPrimaryThread()) runnable.run();
116+
else Bukkit.getScheduler().runTask(bcore, runnable);
117+
}
118+
99119

100120
}

bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/BukkitPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public File getDataFolder() {
9292

9393
@Override
9494
public PlatformServer getServer() {
95-
return new BukkitPlatformServer(core);
95+
return new BukkitPlatformServer(core, main);
9696
}
9797

9898
@Override

bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/DiscordSRVUtilsBukkit.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,31 @@
2828
import org.bstats.charts.AdvancedPie;
2929
import org.bstats.charts.SimplePie;
3030
import org.bukkit.plugin.java.JavaPlugin;
31+
import org.slf4j.LoggerFactory;
3132
import tk.bluetree242.discordsrvutils.DiscordSRVUtils;
3233
import tk.bluetree242.discordsrvutils.bukkit.discordsrv.SlashCommandProvider;
3334

35+
import java.lang.reflect.InvocationTargetException;
36+
import java.lang.reflect.Method;
3437
import java.util.HashMap;
3538
import java.util.Map;
3639

3740
public class DiscordSRVUtilsBukkit extends JavaPlugin {
41+
42+
static {
43+
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
44+
Thread.currentThread().setContextClassLoader(DiscordSRVUtilsBukkit.class.getClassLoader());
45+
try {
46+
Method method = LoggerFactory.class.getDeclaredMethod("bind");
47+
method.setAccessible(true);
48+
method.invoke(null);
49+
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
50+
throw new RuntimeException(e);
51+
} finally {
52+
Thread.currentThread().setContextClassLoader(oldCl);
53+
}
54+
}
55+
3856
@Getter
3957
private DiscordSRVUtils core = null;
4058

bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@
4444
@RequiredArgsConstructor
4545
public class SlashCommandProvider implements github.scarsz.discordsrv.api.commands.SlashCommandProvider {
4646
private final DiscordSRVUtilsBukkit core;
47+
4748
@Override
4849
public Set<PluginSlashCommand> getSlashCommands() {
4950
Set<PluginSlashCommand> commands = new HashSet<>();
50-
if (core.getCore() == null || !core.getCore().isEnabled() || !core.getCore().getMainConfig().register_slash()) return commands;
51+
if (core.getCore() == null || !core.getCore().isEnabled() || !core.getCore().getMainConfig().register_slash())
52+
return commands;
5153
CommandManager manager = core.getCore().getCommandManager();
5254
for (Command command : manager.getCommands()) {
5355
if (!command.isEnabled()) continue;
@@ -68,49 +70,49 @@ private PluginSlashCommand getCmd(String alias, Command cmd) {
6870
public void onCommand(SlashCommandEvent e) {
6971
DiscordSRVUtils core = this.core.getCore();
7072
if (core.getMainConfig().bungee_mode()) return;
71-
String cmd = e.getName();
72-
Command executor = core.getCommandManager().getCommandHashMap().get(cmd);
73-
if (executor == null || !executor.isEnabled()) return;
74-
CommandEvent event = new CommandEvent(core, e.getMember(), e.getUser(), e.getChannel(), e.getJDA(), e);
75-
try {
76-
if (executor.getRequiredPermission() != null) {
77-
if (e.getChannel() instanceof TextChannel) {
78-
if (!e.getMember().hasPermission(executor.getRequiredPermission())) {
79-
e.replyEmbeds(Embed.error("You don't have permission to use this command.", "Required: " + executor.getRequiredPermission())).queue();
80-
return;
81-
}
73+
String cmd = e.getName();
74+
Command executor = core.getCommandManager().getCommandHashMap().get(cmd);
75+
if (executor == null || !executor.isEnabled()) return;
76+
CommandEvent event = new CommandEvent(core, e.getMember(), e.getUser(), e.getChannel(), e.getJDA(), e);
77+
try {
78+
if (executor.getRequiredPermission() != null) {
79+
if (e.getChannel() instanceof TextChannel) {
80+
if (!e.getMember().hasPermission(executor.getRequiredPermission())) {
81+
e.replyEmbeds(Embed.error("You don't have permission to use this command.", "Required: " + executor.getRequiredPermission())).queue();
82+
return;
8283
}
8384
}
84-
if (e.getChannel() instanceof TextChannel) {
85-
if (executor.isOwnerOnly()) {
86-
if (!e.getMember().isOwner()) {
87-
e.replyEmbeds(Embed.error("Only Guild Owner can use this command.")).queue();
88-
return;
89-
}
85+
}
86+
if (e.getChannel() instanceof TextChannel) {
87+
if (executor.isOwnerOnly()) {
88+
if (!e.getMember().isOwner()) {
89+
e.replyEmbeds(Embed.error("Only Guild Owner can use this command.")).queue();
90+
return;
9091
}
91-
if (executor.isAdminOnly()) {
92-
if (!core.getJdaManager().isAdmin(e.getUser().getIdLong())) {
93-
e.replyEmbeds(Embed.error("Only Admins can use this command.", "Your id must be in admin list on the config.yml")).queue();
94-
return;
95-
}
92+
}
93+
if (executor.isAdminOnly()) {
94+
if (!core.getJdaManager().isAdmin(e.getUser().getIdLong())) {
95+
e.replyEmbeds(Embed.error("Only Admins can use this command.", "Your id must be in admin list on the config.yml")).queue();
96+
return;
9697
}
9798
}
98-
core.getLogger().info(e.getUser().getAsTag() + " Used " + "/" + cmd + " Command");
99-
executor.run(event);
100-
} catch (InsufficientPermissionException ex) {
101-
ex.printStackTrace();
102-
e.replyEmbeds(Embed.error("An error happened while executing this Command. Please report to the devs!", "The bot is missing the following permission: " + ex.getPermission())).queue();
103-
} catch (Exception exception) {
104-
exception.printStackTrace();
105-
e.replyEmbeds(Embed.error("An error happened while executing this Command. Please report to the devs!")).queue();
10699
}
107-
if (event.isConnOpen()) {
108-
try {
109-
event.getConnection().configuration().connectionProvider().acquire().close();
110-
} catch (SQLException throwables) {
111-
core.getErrorHandler().defaultHandle(throwables);
112-
}
100+
core.getLogger().info(e.getUser().getAsTag() + " Used " + "/" + cmd + " Command");
101+
executor.run(event);
102+
} catch (InsufficientPermissionException ex) {
103+
ex.printStackTrace();
104+
e.replyEmbeds(Embed.error("An error happened while executing this Command. Please report to the devs!", "The bot is missing the following permission: " + ex.getPermission())).queue();
105+
} catch (Exception exception) {
106+
exception.printStackTrace();
107+
e.replyEmbeds(Embed.error("An error happened while executing this Command. Please report to the devs!")).queue();
108+
}
109+
if (event.isConnOpen()) {
110+
try {
111+
event.getConnection().configuration().connectionProvider().acquire().close();
112+
} catch (SQLException throwables) {
113+
core.getErrorHandler().defaultHandle(throwables);
113114
}
115+
}
114116

115117
}
116118
}

bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/listeners/punishments/libertybans/LibertyBansPunishment.java

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,22 @@
2323
package tk.bluetree242.discordsrvutils.bukkit.listeners.punishments.libertybans;
2424

2525
import lombok.RequiredArgsConstructor;
26-
import org.bukkit.Bukkit;
27-
import space.arim.libertybans.api.Operator;
28-
import space.arim.libertybans.api.PlayerOperator;
29-
import space.arim.libertybans.api.PlayerVictim;
30-
import space.arim.libertybans.api.Victim;
26+
import space.arim.libertybans.api.*;
3127
import tk.bluetree242.discordsrvutils.interfaces.Punishment;
3228
import tk.bluetree242.discordsrvutils.utils.Utils;
3329

3430
import java.util.UUID;
31+
import java.util.concurrent.ExecutionException;
3532

3633
@RequiredArgsConstructor
3734
public class LibertyBansPunishment implements Punishment<space.arim.libertybans.api.punish.Punishment> {
3835
private final space.arim.libertybans.api.punish.Punishment punishment;
3936
private final Operator operator;
4037
private final boolean revoke;
38+
private final LibertyBans plugin;
39+
40+
private String operatorName = null;
41+
private String targetName = null;
4142

4243
@Override
4344
public String getDuration() {
@@ -50,8 +51,7 @@ public String getOperator() {
5051
if (operator.getType() == Operator.OperatorType.CONSOLE) {
5152
return "CONSOLE";
5253
} else {
53-
PlayerOperator operatorplayer = (PlayerOperator) operator;
54-
String name = Bukkit.getOfflinePlayer(operatorplayer.getUUID()).getName();
54+
String name = retrieveName(true);
5555
return name == null ? "Unknown" : name;
5656
}
5757
}
@@ -61,8 +61,7 @@ public String getName() {
6161
if (punishment.getVictim().getType() == Victim.VictimType.ADDRESS) {
6262
return "Unknown";
6363
} else {
64-
PlayerVictim victim = (PlayerVictim) punishment.getVictim();
65-
String name = Bukkit.getOfflinePlayer(victim.getUUID()).getName();
64+
String name = retrieveName(false);
6665
return name == null ? "Unknown" : name;
6766
}
6867
}
@@ -112,4 +111,28 @@ public UUID getTargetUUID() {
112111
return victim.getUUID();
113112
}
114113
}
114+
115+
private String retrieveName(boolean operator) {
116+
String saved = operator ? operatorName : targetName;
117+
if (saved != null) return saved.equals("NONE@*") ? null : saved;
118+
String result = null;
119+
try {
120+
result = plugin.getUserResolver().lookupName(operator ? getOperatorUUID() : getTargetUUID()).get().orElse(null);
121+
} catch (InterruptedException | ExecutionException e) {
122+
//nothing
123+
}
124+
if (result != null) {
125+
if (operator) operatorName = result;
126+
else targetName = result;
127+
} else {
128+
if (operator) operatorName = "NONE@*";
129+
else targetName = "NONE@*";
130+
}
131+
return result;
132+
}
133+
134+
private UUID getOperatorUUID() {
135+
if (operator.getType() != Operator.OperatorType.PLAYER) return null;
136+
return ((PlayerOperator) operator).getUUID();
137+
}
115138
}

bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/listeners/punishments/libertybans/LibertybansListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class PunishmentListener implements EventConsumer<PostPunishEvent> {
6161
@Override
6262
public void accept(PostPunishEvent e) {
6363
core.getAsyncManager().executeAsync(() -> {
64-
LibertyBansPunishment punishment = new LibertyBansPunishment(e.getPunishment(), e.getPunishment().getOperator(), false);
64+
LibertyBansPunishment punishment = new LibertyBansPunishment(e.getPunishment(), e.getPunishment().getOperator(), false, plugin);
6565
tk.bluetree242.discordsrvutils.interfaces.Punishment.handlePunishment(punishment, core);
6666
});
6767
}
@@ -72,7 +72,7 @@ public class PardonListener implements EventConsumer<PostPardonEvent> {
7272
@Override
7373
public void accept(PostPardonEvent e) {
7474
core.getAsyncManager().executeAsync(() -> {
75-
LibertyBansPunishment punishment = new LibertyBansPunishment(e.getPunishment(), e.getPunishment().getOperator(), true);
75+
LibertyBansPunishment punishment = new LibertyBansPunishment(e.getPunishment(), e.getPunishment().getOperator(), true, plugin);
7676
tk.bluetree242.discordsrvutils.interfaces.Punishment.handlePunishment(punishment, core);
7777
});
7878
}

0 commit comments

Comments
 (0)