Skip to content

Commit 7655471

Browse files
committed
Update libraries + cleanup
1 parent 7cdda68 commit 7655471

File tree

10 files changed

+47
-79
lines changed

10 files changed

+47
-79
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.idea/
33
DbLib.iml
44
src/test/
5-
target/
5+
target/
6+
dependency-reduced-pom.xml

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# DbLib
2-
DbLib a library for Nukkit and Voxelwind, that include ORMLite, Sql2o and jdbc-connectors (MySQL and SQLite).
2+
DbLib a library for Nukkit that include ORMLite, Sql2o and jdbc-connectors (MySQL and SQLite).
33

4-
[**Release (outdated, use dev builds)**](http://nukkit.ru/resources/dblib.14/)
4+
[**Download**](https://cloudburstmc.org/resources/dblib.12/)
55

6-
[**Latest Dev Build** ![CircleCI](https://circleci.com/gh/fromgate/DbLib.svg?style=shield)](https://circleci.com/gh/fromgate/DbLib)
7-
8-
Example project: [DbExample](https://github.com/fromgate/DbExample)
6+
[Example Project](https://github.com/fromgate/DbExample)
97

108

119
## Features
@@ -76,7 +74,7 @@ Here is example of creating new table:
7674
```
7775
public boolean connectToDbLib(){
7876
if (this.getServer().getPluginManager().getPlugin("DbLib") == null){
79-
this.getLogger().info(TextFormat.RED+"DbLib plugin not found");
77+
this.getLogger().info("DbLib plugin not found");
8078
return false;
8179
}
8280
connectionSource = DbLib.getConnectionSource();

pom.xml

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>ru.nukkit.dblib</groupId>
77
<artifactId>DbLib</artifactId>
8-
<version>1.0.1</version>
8+
<version>1.0.2-SNAPSHOT</version>
99

1010
<properties>
1111
<maven.compiler.source>1.8</maven.compiler.source>
@@ -17,23 +17,10 @@
1717
<repositories>
1818
<repository>
1919
<id>nukkitx-repo</id>
20-
<url>http://repo.nukkitx.com/snapshot</url>
20+
<url>https://repo.opencollab.dev/snapshot</url>
2121
</repository>
2222
</repositories>
2323

24-
<distributionManagement>
25-
<repository>
26-
<id>releases</id>
27-
<name>nukkitx-releases</name>
28-
<url>https://repo.nukkitx.com/release</url>
29-
</repository>
30-
<snapshotRepository>
31-
<id>snapshots</id>
32-
<name>nukkitx-snapshots</name>
33-
<url>https://repo.nukkitx.com/snapshot</url>
34-
</snapshotRepository>
35-
</distributionManagement>
36-
3724
<dependencies>
3825
<dependency>
3926
<groupId>cn.nukkit</groupId>
@@ -44,13 +31,13 @@
4431
<dependency>
4532
<groupId>mysql</groupId>
4633
<artifactId>mysql-connector-java</artifactId>
47-
<version>8.0.13</version>
34+
<version>8.0.33</version>
4835
<scope>compile</scope>
4936
</dependency>
5037
<dependency>
5138
<groupId>org.xerial</groupId>
5239
<artifactId>sqlite-jdbc</artifactId>
53-
<version>3.25.2</version>
40+
<version>3.49.1.0</version>
5441
<scope>compile</scope>
5542
</dependency>
5643
<dependency>
@@ -73,11 +60,7 @@
7360
</dependency>
7461
</dependencies>
7562

76-
7763
<build>
78-
<finalName>${project.name}</finalName>
79-
<defaultGoal>clean package</defaultGoal>
80-
8164
<resources>
8265
<resource>
8366
<directory>src/main/resources</directory>
@@ -89,7 +72,7 @@
8972
<plugin>
9073
<groupId>org.apache.maven.plugins</groupId>
9174
<artifactId>maven-shade-plugin</artifactId>
92-
<version>3.1.0</version>
75+
<version>3.6.0</version>
9376
<executions>
9477
<execution>
9578
<phase>package</phase>

src/main/java/ru/nukkit/dblib/DbLib.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
import com.j256.ormlite.db.DatabaseType;
44
import com.j256.ormlite.db.DatabaseTypeUtils;
55
import com.j256.ormlite.db.SqliteDatabaseType;
6-
import com.j256.ormlite.jdbc.DataSourceConnectionSource;
76
import com.j256.ormlite.jdbc.JdbcConnectionSource;
87
import com.j256.ormlite.jdbc.JdbcPooledConnectionSource;
9-
import com.j256.ormlite.jdbc.JdbcSingleConnectionSource;
108
import com.j256.ormlite.logger.LocalLog;
119
import com.j256.ormlite.support.ConnectionSource;
12-
import com.j256.ormlite.support.DatabaseConnection;
1310
import org.sql2o.Sql2o;
1411
import ru.nukkit.dblib.connectionsource.LockedJdbcSingleConnectionSource;
1512
import ru.nukkit.dblib.core.M;

src/main/java/ru/nukkit/dblib/core/M.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ public enum M {
1818

1919
private static boolean debugMode = false;
2020
private static String language = "default";
21-
private static boolean saveLanguage = false;
22-
private static char c1 = 'a';
23-
private static char c2 = '2';
24-
private static String pluginName;
21+
private static final char c1 = 'a';
22+
private static final char c2 = '2';
2523

2624

2725
public static String colorize(String text) {
@@ -39,7 +37,7 @@ public static String colorize(String text) {
3937
public static void BC(Object... s) {
4038
if (!debugMode) return;
4139
if (s.length == 0) return;
42-
StringBuilder sb = new StringBuilder("&3[").append(pluginName).append("]&f ");
40+
StringBuilder sb = new StringBuilder("&3[DbLib]&f ");
4341
for (Object str : s)
4442
sb.append(str.toString()).append(" ");
4543

@@ -172,10 +170,10 @@ public String getText(Object... keys) {
172170
int count = 1;
173171
int c = 0;
174172
DecimalFormat fmt = new DecimalFormat("####0.##");
175-
for (int i = 0; i < keys.length; i++) {
176-
String s = messenger.toString(keys[i], fullFloat);//keys[i].toString();
177-
if (c < 2 && keys[i] instanceof Character) {
178-
colors[c] = (Character) keys[i];
173+
for (Object key : keys) {
174+
String s = messenger.toString(key, fullFloat);//keys[i].toString();
175+
if (c < 2 && key instanceof Character) {
176+
colors[c] = (Character) key;
179177
c++;
180178
continue;
181179
} else if (s.startsWith("prefix:")) {
@@ -190,12 +188,12 @@ public String getText(Object... keys) {
190188
} else if (s.equals("FULLFLOAT")) {
191189
fullFloat = true;
192190
continue;
193-
} else if (keys[i] instanceof Double || keys[i] instanceof Float) {
194-
if (!fullFloat) s = fmt.format((Double) keys[i]);
191+
} else if (key instanceof Double || key instanceof Float) {
192+
if (!fullFloat) s = fmt.format((Double) key);
195193
}
196194

197-
String from = (new StringBuilder("%").append(count).append("%")).toString();
198-
String to = skipDefaultColors ? s : (new StringBuilder("&").append(colors[1]).append(s).append("&").append(colors[0])).toString();
195+
String from = "%" + count + "%";
196+
String to = skipDefaultColors ? s : "&" + colors[1] + s + "&" + colors[0];
199197
str = str.replace(from, to);
200198
count++;
201199
}
@@ -213,8 +211,8 @@ private void initMessage(String message) {
213211
}
214212

215213
private String message;
216-
private Character color1;
217-
private Character color2;
214+
private final Character color1;
215+
private final Character color2;
218216

219217
M(String msg) {
220218
message = msg;
@@ -245,9 +243,8 @@ public static void init(String pluginName, Messenger mess, String lang, boolean
245243
messenger = mess;
246244
language = lang.equalsIgnoreCase("default") ? "eng" : lang;
247245
debugMode = debug;
248-
saveLanguage = save;
249246
initMessages();
250-
if (saveLanguage) saveMessages();
247+
if (save) saveMessages();
251248
LNG_CONFIG.debug(M.values().length, language, true, debugMode);
252249
}
253250

@@ -268,16 +265,17 @@ public static boolean isDebug() {
268265
private static void initMessages() {
269266
Map<String, String> lng = messenger.load(language);
270267
for (M key : M.values()) {
271-
if (lng.containsKey(key.name().toLowerCase())) {
272-
key.initMessage(lng.get(key.name().toLowerCase()));
268+
String keyLow = key.name().toLowerCase(Locale.ROOT);
269+
if (lng.containsKey(keyLow)) {
270+
key.initMessage(lng.get(keyLow));
273271
}
274272
}
275273
}
276274

277275
private static void saveMessages() {
278-
Map<String, String> messages = new LinkedHashMap<String, String>();
276+
Map<String, String> messages = new LinkedHashMap<>();
279277
for (M msg : M.values()) {
280-
messages.put(msg.name().toLowerCase(), msg.message);
278+
messages.put(msg.name().toLowerCase(Locale.ROOT), msg.message);
281279
}
282280
messenger.save(language, messages);
283281
}
@@ -325,7 +323,7 @@ public static void printPage(Object sender, List<String> lines, M title, int pag
325323

326324
public static void printPage(Object sender, List<String> lines, M title, M footer, int pageNum, int linesPerPage) {
327325
if (lines == null || lines.isEmpty()) return;
328-
List<String> page = new ArrayList<String>();
326+
List<String> page = new ArrayList<>();
329327
if (title != null) page.add(title.message);
330328

331329
int pageCount = lines.size() / linesPerPage + 1;

src/main/java/ru/nukkit/dblib/nukkit/DbLibPlugin.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package ru.nukkit.dblib.nukkit;
22

33
import cn.nukkit.plugin.PluginBase;
4-
import cn.nukkit.utils.TextFormat;
54
import ru.nukkit.dblib.DbLib;
65
import ru.nukkit.dblib.core.M;
76

@@ -14,19 +13,15 @@ public static DbLibPlugin getPlugin() {
1413
return plugin;
1514
}
1615

17-
private ConfigNukkit cfg;
18-
19-
private boolean debugLog;
20-
2116
@Override
2217
public void onLoad() {
2318
plugin = this;
2419
this.saveDefaultConfig();
25-
this.cfg = new ConfigNukkit(this);
26-
this.cfg.load();
20+
ConfigNukkit cfg = new ConfigNukkit(this);
21+
cfg.load();
2722
M.init("DbLib", new MessengerNukkit(this), cfg.language, cfg.debugMode, cfg.saveLanguage);
2823
DbLib.init(cfg, this.getDataFolder());
29-
getLogger().info(TextFormat.colorize("&eDbLib " + this.getDescription().getVersion() + " created by fromgate for nukkit.ru"));
24+
getLogger().info("DbLib " + this.getDescription().getVersion() + " created by fromgate");
3025
}
3126

3227

src/main/java/ru/nukkit/dblib/nukkit/MessengerNukkit.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
import java.io.File;
1313
import java.io.InputStream;
1414
import java.text.DecimalFormat;
15-
import java.util.ArrayList;
16-
import java.util.HashMap;
17-
import java.util.List;
18-
import java.util.Map;
15+
import java.util.*;
1916

2017
import static ru.nukkit.dblib.core.M.LNG_SAVE_FAIL;
2118
import static ru.nukkit.dblib.core.M.debugException;
@@ -92,7 +89,7 @@ public boolean print(Object obj, String text) {
9289

9390
@Override
9491
public boolean broadcast(String permission, String text) {
95-
List<Player> playerList = new ArrayList<Player>();
92+
List<Player> playerList = new ArrayList<>();
9693
for (Player player : Server.getInstance().getOnlinePlayers().values()) {
9794
if (permission == null || permission.isEmpty() || player.hasPermission(permission)) {
9895
player.sendMessage(text);
@@ -116,11 +113,10 @@ public String toString(Object obj, boolean fullFloat) {
116113
return s;
117114
}
118115

119-
@SuppressWarnings("deprecation")
120116
@Override
121117
public Map<String, String> load(String language) {
122118
File f = new File(plugin.getDataFolder() + File.separator + language + ".lng");
123-
Config lng = null;
119+
Config lng;
124120
if (!f.exists()) {
125121
lng = new Config(f, Config.YAML);
126122
InputStream is = plugin.getClass().getResourceAsStream("/lang/" + language + ".lng");
@@ -131,7 +127,7 @@ public Map<String, String> load(String language) {
131127
}
132128
} else lng = new Config(f, Config.YAML);
133129

134-
Map<String, String> msg = new HashMap<String, String>();
130+
Map<String, String> msg = new HashMap<>();
135131
for (String key : lng.getKeys(true)) {
136132
if (lng.isSection(key)) continue;
137133
msg.put(key, lng.getString(key));
@@ -144,7 +140,7 @@ public void save(String language, Map<String, String> messages) {
144140
File f = new File(plugin.getDataFolder() + File.separator + language + ".lng");
145141
Config lng = new Config(f, Config.YAML);
146142
for (String key : messages.keySet())
147-
lng.set(key.toLowerCase(), messages.get(key));
143+
lng.set(key.toLowerCase(Locale.ROOT), messages.get(key));
148144
try {
149145
lng.save();
150146
} catch (Exception e) {

src/main/resources/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# DbLib plugin for Nukkit
2-
# https://nukkitx.com/resources/dblib.12/
2+
# https://cloudburstmc.org/resources/dblib.12/
33
#
44
general:
55
language: default

src/main/resources/lang/eng.lng

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
lng_load_fail: Failed to load languages from file. Default message used
2-
lng_save_fail: Failed to save translation file
3-
lng_print_fail: Could not display message (%1%). The receiver is null.
4-
lng_config: '[MESSAGES] Posts:%1% Language:%2% Debug Mode:%3%'
5-
err_fail_to_connect: 'Could not connect to:%1% (name:%2%)'
6-
url_log: 'Establishing a connection with%1% (user:%2%)'
1+
lng_load_fail: 'Failed to load languages from file. Default message used'
2+
lng_save_fail: 'Failed to save language file'
3+
lng_print_fail: 'Failed to print message %1%. Sender object is null.'
4+
lng_config: '[MESSAGES] Messages: %1% Language: %2% Debug mode: %3%'
5+
err_fail_to_connect: 'Failed to connect to: %1% (user: %2%)'
6+
url_log: 'Connecting to: %1% (user: %2%)'

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ main: ru.nukkit.dblib.nukkit.DbLibPlugin
33
version: ${project.version}
44
author: fromgate, nukkit.ru
55
api: ["1.0.8"]
6-
description: SQLite/MySQL library for your plugins (Nukkit)
6+
description: SQLite/MySQL library for your plugins

0 commit comments

Comments
 (0)