Skip to content

Commit d1ebe9e

Browse files
committed
Cleanup, more performant debug logs. Kotlin 1.5.21 and Velocity 3.0.0
1 parent 6661484 commit d1ebe9e

File tree

23 files changed

+122
-120
lines changed

23 files changed

+122
-120
lines changed

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
buildscript {
2-
ext.kotlin_version = '1.4.21-2'
2+
ext.kotlin_version = '1.5.21'
33
repositories {
44
jcenter()
55
maven {
@@ -16,7 +16,7 @@ buildscript {
1616

1717
plugins {
1818
id 'java' apply true
19-
id 'org.jetbrains.kotlin.jvm' version '1.4.32'
19+
id 'org.jetbrains.kotlin.jvm' version '1.5.21'
2020
id 'net.nemerosa.versioning' version '2.14.0'
2121
id "io.freefair.lombok" version "5.3.0"
2222
id 'signing'
@@ -50,7 +50,7 @@ allprojects {
5050
// version = versioning.info.full
5151
ext.buildVer = "1.9.0"
5252
ext.aikarVer = "0.5.0-SNAPSHOT"
53-
ext.adventureAPI = "4.7.0"
53+
ext.adventureAPI = "4.8.1"
5454
ext.adventureAPIPlatform = "4.0.0-SNAPSHOT"
5555
ext.slf4j_ver = "1.7.30"
5656
project.ext.beta_version = '4' // Only modify when beta

bungee/src/main/java/com/github/fernthedev/fernapi/server/bungee/BungeeInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public OfflineFPlayer<ProxiedPlayer> getPlayerFromName(String name) {
123123
public OfflineFPlayer<ProxiedPlayer> getPlayerFromUUID(UUID uuid) {
124124
ProxiedPlayer player = fernBungeeAPI.getProxy().getPlayer(uuid);
125125

126-
Universal.debug("Player uuid " + uuid + " for player " + player);
126+
Universal.debug(() ->"Player uuid " + uuid + " for player " + player);
127127

128128
if (player == null) {
129129
return new OfflineFPlayer<>(uuid);

bungee/src/main/java/com/github/fernthedev/fernapi/server/bungee/chat/BungeeChatHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ public BaseComponent parseComponent(BaseMessage baseMessage) {
3232

3333
if (baseMessage.getExtra() != null)
3434
for (BaseMessage extra : baseMessage.getExtra()) {
35-
Universal.debug("Adding message " + extra.toPlainText());
35+
Universal.debug(() ->"Adding message " + extra.toPlainText());
3636
builder.addExtra(parseComponent(extra));
3737
}
3838

3939

40-
Universal.debug("Parsed " + builder.toPlainText());
40+
Universal.debug(() ->"Parsed " + builder.toPlainText());
4141

4242
// new RuntimeException(builder.toString(), new RuntimeException(baseMessage.toString())).printStackTrace();
4343

bungee/src/main/java/com/github/fernthedev/fernapi/server/bungee/network/BungeeMessageHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void sendPluginData(IFPlayer fplayer, @NonNull PluginMessageData data) {
191191
}
192192
out.writeBoolean(data.isUseGson());
193193
out.writeUTF(data.getGsonName());
194-
Universal.debug("Use gson status: " + data.isUseGson());
194+
Universal.debug(() -> "Use gson status: " + data.isUseGson());
195195

196196

197197
if (data.isUseGson()) {
@@ -212,10 +212,10 @@ public void sendPluginData(IFPlayer fplayer, @NonNull PluginMessageData data) {
212212
if (data.getServer().equalsIgnoreCase("all")) {
213213
for (ServerInfo server : ProxyServer.getInstance().getServers().values()) {
214214
server.sendData(data.getMessageChannel().getFullChannelName(), stream.toByteArray());
215-
Universal.debug(server.getName() + " " + server);
215+
Universal.debug(() ->server.getName() + " " + server);
216216
}
217217
} else {
218-
Universal.debug("fplayer == null" + (fplayer == null));
218+
Universal.debug(() -> "fplayer == null" + (fplayer == null));
219219
if (fplayer == null) {
220220
ServerInfo serverInfo = ProxyServer.getInstance().getServerInfo(data.getServer());
221221
if(serverInfo == null) {
@@ -224,12 +224,12 @@ public void sendPluginData(IFPlayer fplayer, @NonNull PluginMessageData data) {
224224

225225
ProxyServer.getInstance().getScheduler().runAsync(bungee, () -> serverInfo.sendData(data.getMessageChannel().getFullChannelName(), stream.toByteArray(), true));
226226

227-
Universal.debug(serverInfo.getName() + " " + serverInfo + " sent");
227+
Universal.debug(() -> serverInfo.getName() + " " + serverInfo + " sent");
228228
} else {
229229
Server serverInfo = player.getServer();
230230
ProxyServer.getInstance().getScheduler().runAsync(bungee, () -> serverInfo.sendData(data.getMessageChannel().getFullChannelName(), stream.toByteArray()));
231231

232-
Universal.debug(serverInfo.getInfo().getName() + " " + serverInfo.getInfo() + " sent");
232+
Universal.debug(() ->serverInfo.getInfo().getName() + " " + serverInfo.getInfo() + " sent");
233233
}
234234
}
235235
}

core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies {
1717
implementation 'org.mariadb.jdbc:mariadb-java-client:2.7.1'
1818

1919
// api "co.aikar:idb-core:1.0.0-SNAPSHOT"
20-
api 'com.github.Fernthedev:db:292c0bb'
20+
api 'com.github.Fernthedev:db:1c2118c7f7'
2121
api 'com.github.Fernthedev:java-api-for-mysql:4c51dbe' // For MySQL annotations
2222

2323

core/src/main/java/com/github/fernthedev/fernapi/universal/Universal.java

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.slf4j.Logger;
2020

2121
import java.util.Locale;
22+
import java.util.function.Supplier;
2223

2324
/**
2425
* Holds most of the core api
@@ -90,17 +91,6 @@ public void setup(@NonNull MethodInterface<?, ?> methodInterface, FernAPIPlugin
9091
comhand.getCommandContexts().registerContext(OfflineFPlayer.class, new UniversalContextResolvers.SingularIFPlayerContextResolver());
9192
comhand.getCommandContexts().registerContext(IFPlayer[].class, new UniversalContextResolvers.OnlineIFPlayerArrayCommandResolver());
9293

93-
94-
// comhand.getCommandCompletions().registerAsyncCompletion("fernPlayers", context ->
95-
// mi.getPlayers().parallelStream()
96-
// .filter(player -> !context.getIssuer().isPlayer() ||
97-
// IFPlayer.canSee(
98-
// Universal.getMethods()
99-
// .convertCommandSenderToAPISender(context.getIssuer().getIssuer()),
100-
// player)
101-
// ).map(IFPlayer::getName)
102-
// .collect(Collectors.toList()));
103-
10494
comhand.getCommandCompletions().setDefaultCompletion("players", IFPlayer.class, IFPlayer[].class, OfflineFPlayer.class, FernCommandIssuer.class);
10595

10696
messageHandler.registerPacketParser("fernapi", json -> new Gson().fromJson(json, PluginMessageData.class));
@@ -122,8 +112,36 @@ protected static void checkNull() {
122112
}
123113
}
124114

115+
/**
116+
* Logs as debug info lazily. Does not construct string unless needed
117+
* @param message Lazy string
118+
* @param params
119+
*/
120+
public static void debug(Supplier<String> message, Object... params) {
121+
if(debug) {
122+
getMethods().getAbstractLogger().info("[DEBUG] " + message.get(), params);
123+
}
124+
}
125125

126+
/**
127+
* Logs as debug info lazily. Does not construct string unless needed
128+
* @param message Lazy string
129+
* @param params
130+
*/
131+
public static void debug(Supplier<String> message, Supplier<Object[]> params) {
132+
if(debug) {
133+
getMethods().getAbstractLogger().info("[DEBUG] " + message.get(), params.get());
134+
}
135+
}
126136

137+
/**
138+
*
139+
* @param message
140+
* @param params
141+
* @deprecated Use {@link #debug(Supplier, Object...)} or {@link #debug(Supplier, Supplier)}
142+
*
143+
*/
144+
@Deprecated
127145
public static void debug(String message, Object... params) {
128146
if(debug) {
129147
getMethods().getAbstractLogger().info("[DEBUG] " + message, params);

core/src/main/java/com/github/fernthedev/fernapi/universal/handlers/UUIDFetchManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ public void stopHourTask() {
6868
}
6969

7070
private static void debug(Object log) {
71-
Universal.debug("[" + Universal.getMethods().getServerType() + "] [UUIDFetcher] " + log);
71+
Universal.debug(() -> "[" + Universal.getMethods().getServerType() + "] [UUIDFetcher] " + log);
7272
}
7373
}

core/src/main/java/com/github/fernthedev/fernapi/universal/mysql/AikarFernDatabase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public static PooledDatabaseOptions getRecommendedOptions(FernAPIPlugin plugin,
2121
try {
2222
Class.forName("org.mariadb.jdbc.MariaDbDataSource");
2323
optimizations = false;
24-
Universal.debug("Disabling optimizations since MariaDB is used. Should this be done?");
24+
Universal.debug(() -> "Disabling optimizations since MariaDB is used. Should this be done?");
2525
} catch (ClassNotFoundException e) {
26-
Universal.debug("Enabling optimizations");
26+
Universal.debug(() -> "Enabling optimizations");
2727
}
2828

2929
DatabaseOptions options = DatabaseOptions

core/src/main/java/com/github/fernthedev/fernapi/universal/mysql/DatabaseListener.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void connect() {
140140
*/
141141
public CompletableFuture<List<DbRow>> getTableRows(String name) {
142142
@Language("SQL") String sql = "SELECT * FROM " + name + ";";
143-
Universal.debug(ChatColor.GREEN + "Executing {}", sql);
143+
Universal.debug(() -> ChatColor.GREEN + "Executing {}", sql);
144144

145145
return database.getResultsAsync(sql).handle(this::handleException);
146146
}
@@ -160,7 +160,7 @@ public <T extends RowData> CompletableFuture<Void> removeRowIfColumnContainsValu
160160
return database.queryAsync(sql).thenAccept(dbStatement -> {
161161
try (DbStatement statement = dbStatement) {
162162
statement.execute(value);
163-
Universal.debug("Executing {} {} ",sql, value);
163+
Universal.debug(() -> "Executing {} {} ",sql, value);
164164
tableInfo.loadFromDB(this);
165165
} catch (SQLException throwables) {
166166
throwables.printStackTrace();
@@ -183,11 +183,11 @@ public <T extends RowData> CompletableFuture<Integer> insertIntoTable(TableInfo<
183183

184184
@Language("SQL") String sql = "INSERT INTO " + tableInfo.getTableName() + "(" + columnName + ") VALUES (" + columnValues + ");";
185185

186-
Universal.debug("Executing {}", sql);
186+
Universal.debug(() ->"Executing {}", sql);
187187

188188
return database.executeUpdateAsync(sql)
189189
.thenApply(dbStatement -> {
190-
Universal.debug(ChatColor.GREEN + "Fully Executed {}", sql);
190+
Universal.debug(() ->ChatColor.GREEN + "Fully Executed {}", sql);
191191
try {
192192
tableInfo.loadFromDB(this).get();
193193
} catch (InterruptedException e) {
@@ -215,11 +215,11 @@ public <T extends RowData> CompletableFuture<Integer> updateRow(TableInfo<T> tab
215215

216216
String columnValues = getColumnValues(newRow);
217217

218-
Universal.debug("Executing {} ({}) {} {}", sql, columnValues, conditionKey, conditionValue);
218+
Universal.debug(() ->"Executing {} ({}) {} {}", sql, columnValues, conditionKey, conditionValue);
219219

220220
return database.executeUpdateAsync(sql, columnValues, conditionKey, conditionValue)
221221
.thenApply(integer -> {
222-
Universal.debug(ChatColor.GREEN + "Fully Executed {} {} ({}) {} {}", sql, tableInfo.getTableName(), columnValues, conditionKey, conditionValue);
222+
Universal.debug(() ->ChatColor.GREEN + "Fully Executed {} {} ({}) {} {}", sql, tableInfo.getTableName(), columnValues, conditionKey, conditionValue);
223223
tableInfo.loadFromDB(DatabaseListener.this);
224224
return integer;
225225
}).handle(this::handleException);
@@ -235,7 +235,7 @@ public <T extends RowData> CompletableFuture<Integer> updateRow(TableInfo<T> tab
235235
public <T extends RowData> CompletableFuture<Integer> removeTable(TableInfo<T> tableInfo) throws DatabaseException {
236236
@Language("SQL") String sql = "DROP TABLE IF EXISTS " + tableInfo.getTableName() + ";";
237237

238-
Universal.debug("Executing {}", sql);
238+
Universal.debug(() -> "Executing {}", sql);
239239

240240
return database.executeUpdateAsync(sql).handle(this::handleException);
241241
}
@@ -382,16 +382,16 @@ public <T extends RowData> CompletableFuture<Void> createTable(@NonNull TableInf
382382

383383
sql.append(");");
384384

385-
Universal.debug("Executing {}", sql.toString());
385+
Universal.debug(() ->"Executing {}", sql.toString());
386386

387387
return database.executeUpdateAsync(sql.toString()).thenRun(() -> {
388-
Universal.debug(ChatColor.GREEN + "Fully Executed {} {}", sql, tableDataInfo.getTableName());
388+
Universal.debug(() ->ChatColor.GREEN + "Fully Executed {} {}", sql, tableDataInfo.getTableName());
389389
// Create indexes
390390
for (Field field : indexed) {
391391
try {
392392
@Language("SQL") String indexSql = mysqlProxy.buildIndex(tableDataInfo.getTableName(), field);
393393

394-
Universal.debug("Executing {}", indexSql);
394+
Universal.debug(() ->"Executing {}", indexSql);
395395

396396
database.executeUpdate(indexSql);
397397
} catch (SQLException throwables) {

core/src/main/java/com/github/fernthedev/fernapi/universal/util/ProxyAskPlaceHolder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public ProxyAskPlaceHolder(IFPlayer<?> player, String placeHolderValue, ProxyPla
6969
}
7070

7171

72-
Universal.debug("Current uuid is " + uuid);
72+
Universal.debug(() -> "Current uuid is {}", uuid);
7373

7474
data.addData(placeHolderValue); //MESSAGE 1 (placeholder requested)
7575
oldPlaceValue = placeHolderValue;
@@ -122,7 +122,7 @@ public void onMessageReceived(PluginMessageData data, Channel channel) {
122122

123123
ProxyAskPlaceHolder instance = instances.get(uuide);
124124
if (instance == null) {
125-
Universal.debug("There were no instances");
125+
Universal.debug(() -> "There were no instances");
126126
}
127127

128128

@@ -145,7 +145,7 @@ public void onMessageReceived(PluginMessageData data, Channel channel) {
145145
instances.remove(uuide);
146146

147147
} else {
148-
Universal.debug(ChatColor.RED + "The incoming message was not expected. From an attacker?");
148+
Universal.debug(() -> ChatColor.RED + "The incoming message was not expected. From an attacker?");
149149
}
150150
}
151151

0 commit comments

Comments
 (0)