Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
clear & optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbit4 committed May 1, 2023
1 parent 6bf39c0 commit b31417c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
11 changes: 10 additions & 1 deletion src/main/java/pl/norbit/discordmc/DiscordMc.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pl.norbit.discordmc;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.MessageChannel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
Expand Down Expand Up @@ -28,6 +29,8 @@ public final class DiscordMc extends JavaPlugin {
private static Long timeServer;
private static DiscordMc instance;

private static Guild guild;

private static ConsoleCommandSender commandSender;
private static JDA jda;

Expand Down Expand Up @@ -68,7 +71,9 @@ private boolean start() throws InterruptedException {

jda = discordBot.getJda();

if(jda.awaitReady().getGuildById(PluginConfig.SERVER_ID) == null) {
guild = jda.awaitReady().getGuildById(PluginConfig.SERVER_ID);

if(guild == null) {
sendMessage("&c[ERROR] Wrong discord server ID");
sendMessage("&cHow to get discord server id?");
sendMessage("&chttps://github.com/Norbit4/DiscordMc/wiki/Configuration#id");
Expand Down Expand Up @@ -208,4 +213,8 @@ public static DiscordMc getInstance() {
public static JDA getJda() {
return jda;
}

public static Guild getGuild(){
return guild;
}
}
3 changes: 1 addition & 2 deletions src/main/java/pl/norbit/discordmc/bot/embed/Embed.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ public static EmbedBuilder getConsoleMessage(String tittle, String message, Colo
}

public static EmbedBuilder getProfileMessage(){
EmbedBuilder embedBuilder = getBuilder(PluginConfig.EMBED_PROFILE_TITLE, "",
return getBuilder(PluginConfig.EMBED_PROFILE_TITLE, "",
new Color(
PluginConfig.EMBED_PROFILE_R,
PluginConfig.EMBED_PROFILE_G,
PluginConfig.EMBED_PROFILE_B),
false, "");
return embedBuilder;
}
public static boolean isUsernamePremium(String username) throws IOException {
URL url = new URL("https://api.mojang.com/users/profiles/minecraft/"+ username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DiscordUserUpdateTask {
private static final Queue<UUID> queue = new LinkedList<>();

public static void start(){
if(!PluginConfig.SYNC_RANK_ENABLE) return;
if(!PluginConfig.SYNC_PERM_ENABLE) return;
new BukkitRunnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void run() {
if (PluginConfig.EXECUTE_COMMAND_ON_SYNC_CLEAR)
ConsoleUtil.executeCommand(p, PluginConfig.COMMANDS_ON_SYNC_CLEAR.toArray(new String[0]));


instance.getServer().getPluginManager().callEvent(new SyncClearEvent(playerUUID, discordId));
}
}.runTaskLater(DiscordMc.getInstance(), 4);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/pl/norbit/discordmc/serverinfo/InfoUpdater.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class InfoUpdater {
PluginConfig.MESSAGE_RELOAD_TIME
}

var messageID: String
val messageID: String
val textChannel = jda?.awaitReady()?.getTextChannelById(PluginConfig.CHANNEL_INFO_ID)
val color = Color(PluginConfig.EMBED_INFO_R, PluginConfig.EMBED_INFO_G, PluginConfig.EMBED_INFO_B)

Expand Down Expand Up @@ -51,8 +51,6 @@ class InfoUpdater {
PluginConfig.EMBED_INFO_ARGS
)

if(messageID == null) return

textChannel.editMessageById(messageID, "*").setEmbeds(message?.build()).queue()
}
}.runTaskTimerAsynchronously(DiscordMc.getInstance(), 20 * 6, reloadTime.toLong() * 20)
Expand Down
17 changes: 6 additions & 11 deletions src/main/java/pl/norbit/discordmc/sync/SyncTimerTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ public static void runTaskTimer(JavaPlugin javaPlugin) {
new BukkitRunnable() {
@Override
public void run() {
if(!syncPlayerList.isEmpty()) {
if(syncPlayerList.isEmpty()) return;

syncPlayerList.forEach(syncPlayer -> {

if(syncPlayer.time() == 1){
removeSyncPlayer(syncPlayer);
}
});
}
syncPlayerList.forEach(syncPlayer -> {
if(syncPlayer.time() == 1) removeSyncPlayer(syncPlayer);
});
}
}.runTaskTimerAsynchronously(javaPlugin, 0, 20);
}
Expand All @@ -32,10 +28,9 @@ public static void addSyncPlayer(SyncPlayer syncPlayer){
}

public static SyncPlayer getSyncPlayer(UUID playerUUID){
Optional<SyncPlayer> optionalSyncPlayer = syncPlayerList.stream()
return syncPlayerList.stream()
.filter(syncPlayer1 -> syncPlayer1.getPlayer().getUniqueId().equals(playerUUID))
.findFirst();
return optionalSyncPlayer.orElse(null);
.findFirst().orElse(null);
}

public static void removeSyncPlayer(SyncPlayer syncPlayer){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public PermissionUtil(Player p) {
});
}

public boolean hasPermission(String [] perms) {
public boolean hasPermission(String... perms) {

for (String perm : perms) {

Expand Down

0 comments on commit b31417c

Please sign in to comment.