Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
feat: #895 MCBansキャッシュを使う (#903)
Browse files Browse the repository at this point in the history
  • Loading branch information
book000 authored Aug 8, 2022
1 parent baaf7cf commit 6f74ab4
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 237 deletions.
69 changes: 35 additions & 34 deletions src/main/java/com/jaoafa/mymaid4/event/Event_FirstLogin.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import com.jaoafa.mymaid4.Main;
import com.jaoafa.mymaid4.lib.EventPremise;
import com.jaoafa.mymaid4.lib.MCBans;
import com.jaoafa.mymaid4.lib.MCBansCache;
import com.jaoafa.mymaid4.lib.MyMaidData;
import com.jaoafa.mymaid4.lib.MyMaidLibrary;
import net.dv8tion.jda.api.EmbedBuilder;
Expand Down Expand Up @@ -48,17 +48,10 @@ public void OnEvent_FirstLogin(PlayerJoinEvent event) {
return;
}

String reputation;
MCBans mcbans = null;
MCBansCache mcbans = null;
try {
mcbans = new MCBans(player);
if (mcbans.isFound()) {
reputation = String.valueOf(mcbans.getReputation());
} else {
reputation = "null";
}
} catch (IOException e) {
reputation = "null";
mcbans = MCBansCache.get(player);
} catch (IOException ignored) {
}

List<String> players = new ArrayList<>();
Expand All @@ -77,7 +70,7 @@ public void OnEvent_FirstLogin(PlayerJoinEvent event) {
builder.appendDescription("新規プレイヤー(`" + player.getName() + "`)がサーバにログインしました!");
builder.setColor(Color.GREEN);
builder.addField("プレイヤーID", "`" + player.getName() + "`", false);
builder.addField("評価値", reputation + " / 10", false);
builder.addField("評価値", (mcbans != null ? mcbans.getReputation() : "NULL") + " / 10", false);
builder.addField("プレイヤー数", Bukkit.getOnlinePlayers().size() + "人", false);
builder.addField("プレイヤー", "`" + String.join(", ", players) + "`", false);
builder.setTimestamp(Instant.now());
Expand All @@ -88,8 +81,8 @@ public void OnEvent_FirstLogin(PlayerJoinEvent event) {
jaotan.sendMessageEmbeds(builder.build()).queue();

if (mcbans != null && (mcbans.getGlobalCount() > 0 || mcbans.getLocalCount() > 0)) {
int[] global_ids = mcbans.getGlobalBanIds();
int[] local_ids = mcbans.getLocalBanIds();
List<MCBansCache.Ban> globalBans = mcbans.getGlobalBans();
List<MCBansCache.Ban> localBans = mcbans.getLocalBans();

EmbedBuilder embed = new EmbedBuilder();
embed.setTitle("MCBans DATA : " + player.getName(),
Expand All @@ -98,32 +91,40 @@ public void OnEvent_FirstLogin(PlayerJoinEvent event) {
embed.setDescription("Global: " + mcbans.getGlobalCount() + " / Local: " + mcbans.getLocalCount());
embed.setTimestamp(Instant.now());

for (int id : global_ids) {
for (MCBansCache.Ban ban : globalBans) {
try {
MCBans.Ban ban = new MCBans.Ban(id);
String reason = ban.getReason();
String date = ban.getDate();
String banned_by = ban.getBannedBy();
String server = ban.getServer();

embed.addField("[Global] `" + server + "`",
"Reason: " + reason + "\nBanned_by: `" + banned_by + "`\n" + date, false);
String reason = ban.reason();
String bannedAt = MyMaidLibrary.sdfFormat(ban.bannedAt());
MCBansCache.BanDetails details = ban.retrieveDetails();
if (details == null) {
embed.addField("BanID: " + ban.banId(), "Failed to get the data", false);
return;
}
String serverAddress = details.serverAddress();
String bannedByName = details.bannedByName();

embed.addField("[Global] `" + serverAddress + "`",
"Reason: " + reason + "\nBanned_by: `" + bannedByName + "`\n" + bannedAt, false);
} catch (IOException e) {
embed.addField("BanID: " + id, "Failed to get the data", false);
embed.addField("BanID: " + ban.banId(), "Failed to get the data", false);
}
}
for (int id : local_ids) {
for (MCBansCache.Ban ban : localBans) {
try {
MCBans.Ban ban = new MCBans.Ban(id);
String reason = ban.getReason();
String date = ban.getDate();
String banned_by = ban.getBannedBy();
String server = ban.getServer();

embed.addField("[Local] `" + server + "`",
"Reason: " + reason + "\nBanned_by: `" + banned_by + "`\n" + date, false);
String reason = ban.reason();
String bannedAt = MyMaidLibrary.sdfFormat(ban.bannedAt());
MCBansCache.BanDetails details = ban.retrieveDetails();
if (details == null) {
embed.addField("BanID: " + ban.banId(), "Failed to get the data", false);
return;
}
String serverAddress = details.serverAddress();
String bannedByName = details.bannedByName();

embed.addField("[Local] `" + serverAddress + "`",
"Reason: " + reason + "\nBanned_by: `" + bannedByName + "`\n" + bannedAt, false);
} catch (IOException e) {
embed.addField("BanID: " + id, "Failed to get the data", false);
embed.addField("BanID: " + ban.banId(), "Failed to get the data", false);
}
}

Expand Down
203 changes: 0 additions & 203 deletions src/main/java/com/jaoafa/mymaid4/lib/MCBans.java

This file was deleted.

Loading

0 comments on commit 6f74ab4

Please sign in to comment.