Skip to content

Commit 5feeea1

Browse files
authored
GH-120 Add debug mode (#120)
1 parent 249f759 commit 5feeea1

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

src/main/java/com/eternalcode/parcellockers/ParcelLockers.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,16 @@
6666
import java.util.logging.Level;
6767
import java.util.logging.Logger;
6868
import java.util.stream.Stream;
69+
import org.slf4j.helpers.NOPLogger;
6970

7071
public final class ParcelLockers extends JavaPlugin {
7172

72-
private LiteCommands<CommandSender> liteCommands;
73+
public static org.slf4j.Logger DEBUG_LOGGER = NOPLogger.NOP_LOGGER;
7374

75+
private LiteCommands<CommandSender> liteCommands;
7476
private BukkitAudiences audiences;
75-
7677
private SkullAPI skullAPI;
77-
7878
private Economy economy;
79-
8079
private DatabaseManager databaseManager;
8180

8281
@Override
@@ -111,6 +110,10 @@ public void onEnable() {
111110
});
112111
}
113112

113+
if (config.settings.debug) {
114+
DEBUG_LOGGER = org.slf4j.LoggerFactory.getLogger("ParcelLockers] [DEBUG");
115+
}
116+
114117
LoggerFactory.setLogBackendFactory(new NullLogBackend.NullLogBackendFactory());
115118

116119
DatabaseManager databaseManager = new DatabaseManager(config, this.getLogger(), this.getDataFolder());

src/main/java/com/eternalcode/parcellockers/configuration/implementation/PluginConfiguration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public static class Settings {
3939
"# You can learn more about Sentry here: https://sentry.io/" })
4040
public boolean enableSentry = true;
4141

42+
@Description({ " ", "# Set to enable debug mode and receive more detailed information in the console." })
43+
public boolean debug = false;
44+
4245
@Description({ " ", "# Whether the player after entering the server should receive information about the new version of the plugin?" })
4346
public boolean receiveUpdates = true;
4447

src/main/java/com/eternalcode/parcellockers/database/wrapper/AbstractRepositoryOrmLite.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.eternalcode.parcellockers.database.wrapper;
22

33
import com.eternalcode.commons.scheduler.Scheduler;
4+
import com.eternalcode.parcellockers.ParcelLockers;
45
import com.eternalcode.parcellockers.database.DatabaseManager;
56
import com.j256.ormlite.dao.Dao;
67
import panda.std.function.ThrowingFunction;
@@ -21,34 +22,56 @@ protected AbstractRepositoryOrmLite(DatabaseManager databaseManager, Scheduler s
2122
}
2223

2324
protected <T> CompletableFuture<Dao.CreateOrUpdateStatus> save(Class<T> type, T entity) {
24-
return this.action(type, dao -> dao.createOrUpdate(entity));
25+
return this.action(type, dao -> {
26+
ParcelLockers.DEBUG_LOGGER.info("Saving entity: {}", entity);
27+
return dao.createOrUpdate(entity);
28+
});
2529
}
2630

2731
protected <T> CompletableFuture<T> saveIfNotExist(Class<T> type, T entity) {
28-
return this.action(type, dao -> dao.createIfNotExists(entity));
32+
return this.action(type, dao -> {
33+
ParcelLockers.DEBUG_LOGGER.info("Saving entity (IF NOT EXIST mode): {}", entity);
34+
return dao.createIfNotExists(entity);
35+
});
2936
}
3037

3138
protected <T, ID> CompletableFuture<T> select(Class<T> type, ID id) {
32-
return this.action(type, dao -> dao.queryForId(id));
39+
return this.action(type, dao -> {
40+
ParcelLockers.DEBUG_LOGGER.info("Selecting: {}", id);
41+
return dao.queryForId(id);
42+
});
3343
}
3444

3545
protected <T, ID> CompletableFuture<Optional<T>> selectSafe(Class<T> type, ID id) {
36-
return this.action(type, dao -> Optional.ofNullable(dao.queryForId(id)));
46+
return this.action(type, dao -> {
47+
ParcelLockers.DEBUG_LOGGER.info("Selecting (safe mode): {}", id);
48+
return Optional.ofNullable(dao.queryForId(id));
49+
});
3750
}
3851

3952
protected <T> CompletableFuture<Integer> delete(Class<T> type, T entity) {
40-
return this.action(type, dao -> dao.delete(entity));
53+
return this.action(type, dao -> {
54+
ParcelLockers.DEBUG_LOGGER.info("Deleting: {}", entity);
55+
return dao.delete(entity);
56+
});
4157
}
4258

4359
protected <T> CompletableFuture<Integer> deleteAll(Class<T> type) {
44-
return this.action(type, dao -> dao.deleteBuilder().delete());
60+
return this.action(type, dao -> {
61+
ParcelLockers.DEBUG_LOGGER.info("Deleting all entities of type: {}", type.getSimpleName());
62+
return dao.deleteBuilder().delete();
63+
});
4564
}
4665

4766
protected <T, ID> CompletableFuture<Integer> deleteById(Class<T> type, ID id) {
48-
return this.action(type, dao -> dao.deleteById(id));
67+
return this.action(type, dao -> {
68+
ParcelLockers.DEBUG_LOGGER.info("Deleting: {}", id);
69+
return dao.deleteById(id);
70+
});
4971
}
5072

5173
protected <T> CompletableFuture<List<T>> selectAll(Class<T> type) {
74+
ParcelLockers.DEBUG_LOGGER.info("Selecting all entities of type: {}", type.getSimpleName());
5275
return this.action(type, Dao::queryForAll);
5376
}
5477

0 commit comments

Comments
 (0)