Skip to content

Commit

Permalink
update 1.2.11
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueTree242 committed Dec 21, 2022
2 parents 33dd04a + e0cd754 commit dc73d54
Show file tree
Hide file tree
Showing 57 changed files with 1,102 additions and 753 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ hs_err_pid*

# Custom files
build/
core/build/
bukkit/build/
.idea/
.gradle/
1 change: 1 addition & 0 deletions bukkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dependencies {
compileOnly urlFile("https://github.com/Zrips/CMI-API/releases/download/8.7.8.2/CMIAPI8.7.8.2.jar", "CMI-API")
compileOnly 'net.lapismc:AFKPlus:3.3.15'
implementation project(":core")
implementation('org.slf4j:slf4j-api:2.0.1')
compileOnly('com.discordsrv:discordsrv:1.26.0')
implementation 'org.jooq:jooq:3.14.16'
compileOnly 'net.essentialsx:EssentialsX:2.19.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ private List<Map<String, String>> getDSUFiles() throws Exception {
files.add(fileMap("leveling.yml", Utils.readFile(core.getPlatform().getDataFolder() + core.fileseparator + "leveling.yml")));
files.add(fileMap("status.yml", Utils.readFile(core.getPlatform().getDataFolder() + core.fileseparator + "status.yml")));
files.add(fileMap("suggestions.yml", Utils.readFile(core.getPlatform().getDataFolder() + core.fileseparator + "suggestions.yml")));
files.add(fileMap("leveling-roles.json", Utils.readFile(core.getPlatform().getDataFolder() + core.fileseparator + "leveling-roles.json")));
files.add(fileMap("leveling-roles.json", Utils.readFile(core.getPlatform().getDataFolder() + core.fileseparator + "leveling-roles.json")));
files.add(fileMap("leveling-rewards.json", Utils.readFile(core.getPlatform().getDataFolder() + core.fileseparator + "leveling-rewards.json")));
return files;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ public class BukkitPlatformServer extends PlatformServer {
private final DiscordSRVUtils core;
@Getter
private final Debugger debugger;
private final DiscordSRVUtilsBukkit bcore;

public BukkitPlatformServer(DiscordSRVUtils core) {
public BukkitPlatformServer(DiscordSRVUtils core, DiscordSRVUtilsBukkit bcore) {
this.core = core;
debugger = new BukkitDebugger(core);
this.bcore = bcore;
}

@Override
Expand Down Expand Up @@ -96,5 +98,23 @@ public PlatformPlayer getOfflinePlayer(UUID uuid) {
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid), core);
}

@Override
public PlatformPlayer getPlayer(UUID uuid) {
Player player = Bukkit.getPlayer(uuid);
if (player == null) return null;
return new BukkitPlayer(core, player);
}

@Override
public void executeConsoleCommands(String... cmds) {
Runnable runnable = () -> {
for (String cmd : cmds) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);
}
};
if (Bukkit.isPrimaryThread()) runnable.run();
else Bukkit.getScheduler().runTask(bcore, runnable);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public File getDataFolder() {

@Override
public PlatformServer getServer() {
return new BukkitPlatformServer(core);
return new BukkitPlatformServer(core, main);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,31 @@
import org.bstats.charts.AdvancedPie;
import org.bstats.charts.SimplePie;
import org.bukkit.plugin.java.JavaPlugin;
import org.slf4j.LoggerFactory;
import tk.bluetree242.discordsrvutils.DiscordSRVUtils;
import tk.bluetree242.discordsrvutils.bukkit.discordsrv.SlashCommandProvider;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class DiscordSRVUtilsBukkit extends JavaPlugin {

static {
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(DiscordSRVUtilsBukkit.class.getClassLoader());
try {
Method method = LoggerFactory.class.getDeclaredMethod("bind");
method.setAccessible(true);
method.invoke(null);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
} finally {
Thread.currentThread().setContextClassLoader(oldCl);
}
}

@Getter
private DiscordSRVUtils core = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@
@RequiredArgsConstructor
public class SlashCommandProvider implements github.scarsz.discordsrv.api.commands.SlashCommandProvider {
private final DiscordSRVUtilsBukkit core;

@Override
public Set<PluginSlashCommand> getSlashCommands() {
Set<PluginSlashCommand> commands = new HashSet<>();
if (core.getCore() == null || !core.getCore().isEnabled() || !core.getCore().getMainConfig().register_slash()) return commands;
if (core.getCore() == null || !core.getCore().isEnabled() || !core.getCore().getMainConfig().register_slash())
return commands;
CommandManager manager = core.getCore().getCommandManager();
for (Command command : manager.getCommands()) {
if (!command.isEnabled()) continue;
Expand All @@ -68,49 +70,49 @@ private PluginSlashCommand getCmd(String alias, Command cmd) {
public void onCommand(SlashCommandEvent e) {
DiscordSRVUtils core = this.core.getCore();
if (core.getMainConfig().bungee_mode()) return;
String cmd = e.getName();
Command executor = core.getCommandManager().getCommandHashMap().get(cmd);
if (executor == null || !executor.isEnabled()) return;
CommandEvent event = new CommandEvent(core, e.getMember(), e.getUser(), e.getChannel(), e.getJDA(), e);
try {
if (executor.getRequiredPermission() != null) {
if (e.getChannel() instanceof TextChannel) {
if (!e.getMember().hasPermission(executor.getRequiredPermission())) {
e.replyEmbeds(Embed.error("You don't have permission to use this command.", "Required: " + executor.getRequiredPermission())).queue();
return;
}
String cmd = e.getName();
Command executor = core.getCommandManager().getCommandHashMap().get(cmd);
if (executor == null || !executor.isEnabled()) return;
CommandEvent event = new CommandEvent(core, e.getMember(), e.getUser(), e.getChannel(), e.getJDA(), e);
try {
if (executor.getRequiredPermission() != null) {
if (e.getChannel() instanceof TextChannel) {
if (!e.getMember().hasPermission(executor.getRequiredPermission())) {
e.replyEmbeds(Embed.error("You don't have permission to use this command.", "Required: " + executor.getRequiredPermission())).queue();
return;
}
}
if (e.getChannel() instanceof TextChannel) {
if (executor.isOwnerOnly()) {
if (!e.getMember().isOwner()) {
e.replyEmbeds(Embed.error("Only Guild Owner can use this command.")).queue();
return;
}
}
if (e.getChannel() instanceof TextChannel) {
if (executor.isOwnerOnly()) {
if (!e.getMember().isOwner()) {
e.replyEmbeds(Embed.error("Only Guild Owner can use this command.")).queue();
return;
}
if (executor.isAdminOnly()) {
if (!core.getJdaManager().isAdmin(e.getUser().getIdLong())) {
e.replyEmbeds(Embed.error("Only Admins can use this command.", "Your id must be in admin list on the config.yml")).queue();
return;
}
}
if (executor.isAdminOnly()) {
if (!core.getJdaManager().isAdmin(e.getUser().getIdLong())) {
e.replyEmbeds(Embed.error("Only Admins can use this command.", "Your id must be in admin list on the config.yml")).queue();
return;
}
}
core.getLogger().info(e.getUser().getAsTag() + " Used " + "/" + cmd + " Command");
executor.run(event);
} catch (InsufficientPermissionException ex) {
ex.printStackTrace();
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();
} catch (Exception exception) {
exception.printStackTrace();
e.replyEmbeds(Embed.error("An error happened while executing this Command. Please report to the devs!")).queue();
}
if (event.isConnOpen()) {
try {
event.getConnection().configuration().connectionProvider().acquire().close();
} catch (SQLException throwables) {
core.getErrorHandler().defaultHandle(throwables);
}
core.getLogger().info(e.getUser().getAsTag() + " Used " + "/" + cmd + " Command");
executor.run(event);
} catch (InsufficientPermissionException ex) {
ex.printStackTrace();
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();
} catch (Exception exception) {
exception.printStackTrace();
e.replyEmbeds(Embed.error("An error happened while executing this Command. Please report to the devs!")).queue();
}
if (event.isConnOpen()) {
try {
event.getConnection().configuration().connectionProvider().acquire().close();
} catch (SQLException throwables) {
core.getErrorHandler().defaultHandle(throwables);
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@
package tk.bluetree242.discordsrvutils.bukkit.listeners.punishments.libertybans;

import lombok.RequiredArgsConstructor;
import org.bukkit.Bukkit;
import space.arim.libertybans.api.Operator;
import space.arim.libertybans.api.PlayerOperator;
import space.arim.libertybans.api.PlayerVictim;
import space.arim.libertybans.api.Victim;
import space.arim.libertybans.api.*;
import tk.bluetree242.discordsrvutils.interfaces.Punishment;
import tk.bluetree242.discordsrvutils.utils.Utils;

import java.util.UUID;
import java.util.concurrent.ExecutionException;

@RequiredArgsConstructor
public class LibertyBansPunishment implements Punishment<space.arim.libertybans.api.punish.Punishment> {
private final space.arim.libertybans.api.punish.Punishment punishment;
private final Operator operator;
private final boolean revoke;
private final LibertyBans plugin;

private String operatorName = null;
private String targetName = null;

@Override
public String getDuration() {
Expand All @@ -50,8 +51,7 @@ public String getOperator() {
if (operator.getType() == Operator.OperatorType.CONSOLE) {
return "CONSOLE";
} else {
PlayerOperator operatorplayer = (PlayerOperator) operator;
String name = Bukkit.getOfflinePlayer(operatorplayer.getUUID()).getName();
String name = retrieveName(true);
return name == null ? "Unknown" : name;
}
}
Expand All @@ -61,8 +61,7 @@ public String getName() {
if (punishment.getVictim().getType() == Victim.VictimType.ADDRESS) {
return "Unknown";
} else {
PlayerVictim victim = (PlayerVictim) punishment.getVictim();
String name = Bukkit.getOfflinePlayer(victim.getUUID()).getName();
String name = retrieveName(false);
return name == null ? "Unknown" : name;
}
}
Expand Down Expand Up @@ -112,4 +111,28 @@ public UUID getTargetUUID() {
return victim.getUUID();
}
}

private String retrieveName(boolean operator) {
String saved = operator ? operatorName : targetName;
if (saved != null) return saved.equals("NONE@*") ? null : saved;
String result = null;
try {
result = plugin.getUserResolver().lookupName(operator ? getOperatorUUID() : getTargetUUID()).get().orElse(null);
} catch (InterruptedException | ExecutionException e) {
//nothing
}
if (result != null) {
if (operator) operatorName = result;
else targetName = result;
} else {
if (operator) operatorName = "NONE@*";
else targetName = "NONE@*";
}
return result;
}

private UUID getOperatorUUID() {
if (operator.getType() != Operator.OperatorType.PLAYER) return null;
return ((PlayerOperator) operator).getUUID();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class PunishmentListener implements EventConsumer<PostPunishEvent> {
@Override
public void accept(PostPunishEvent e) {
core.getAsyncManager().executeAsync(() -> {
LibertyBansPunishment punishment = new LibertyBansPunishment(e.getPunishment(), e.getPunishment().getOperator(), false);
LibertyBansPunishment punishment = new LibertyBansPunishment(e.getPunishment(), e.getPunishment().getOperator(), false, plugin);
tk.bluetree242.discordsrvutils.interfaces.Punishment.handlePunishment(punishment, core);
});
}
Expand All @@ -72,7 +72,7 @@ public class PardonListener implements EventConsumer<PostPardonEvent> {
@Override
public void accept(PostPardonEvent e) {
core.getAsyncManager().executeAsync(() -> {
LibertyBansPunishment punishment = new LibertyBansPunishment(e.getPunishment(), e.getPunishment().getOperator(), true);
LibertyBansPunishment punishment = new LibertyBansPunishment(e.getPunishment(), e.getPunishment().getOperator(), true, plugin);
tk.bluetree242.discordsrvutils.interfaces.Punishment.handlePunishment(punishment, core);
});
}
Expand Down
Loading

0 comments on commit dc73d54

Please sign in to comment.