Skip to content

Commit 8ad4dee

Browse files
author
games647
committed
Replace database executor with hikari's impl (Fixes #203)
1 parent 9e0ab75 commit 8ad4dee

File tree

14 files changed

+32
-97
lines changed

14 files changed

+32
-97
lines changed

pom.xml

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,14 @@
1010
<name>ScoreboardStats</name>
1111
<inceptionYear>2013</inceptionYear>
1212
<description>Show the Scoreboard with many custom variables</description>
13-
<version>0.10.1</version>
14-
<url>http://dev.bukkit.org/bukkit-plugins/scoreboardstats</url>
13+
<version>0.10.3</version>
14+
<url>https://dev.bukkit.org/bukkit-plugins/scoreboardstats</url>
1515

1616
<properties>
1717
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1818
<powermock.version>1.7.0</powermock.version>
19-
<!--Possibility to deploy directly to the plugins folder-->
20-
<outputDir>${basedir}/target</outputDir>
2119
</properties>
2220

23-
<issueManagement>
24-
<system>GitHub</system>
25-
<url>https://github.com/games647/ScoreboardStats/issues</url>
26-
</issueManagement>
27-
28-
<scm>
29-
<url>https://github.com/games647/ScoreboardStats</url>
30-
<connection>scm:git:git://github.com/games647/ScoreboardStats.git</connection>
31-
<developerConnection>scm:git:ssh://git@github.com:games647/ScoreboardStats.git</developerConnection>
32-
</scm>
33-
34-
<licenses>
35-
<license>
36-
<name>The MIT License</name>
37-
<url>http://opensource.org/licenses/MIT</url>
38-
<distribution>repo</distribution>
39-
</license>
40-
</licenses>
41-
4221
<build>
4322
<defaultGoal>install</defaultGoal>
4423
<!--Just use the project name to replace an old version of the plugin if the user does only copy-paste-->
@@ -52,17 +31,6 @@
5231
<configuration>
5332
<source>1.8</source>
5433
<target>1.8</target>
55-
<showWarnings>true</showWarnings>
56-
<showDeprecation>true</showDeprecation>
57-
</configuration>
58-
</plugin>
59-
60-
<plugin>
61-
<groupId>org.apache.maven.plugins</groupId>
62-
<artifactId>maven-jar-plugin</artifactId>
63-
<version>3.0.2</version>
64-
<configuration>
65-
<outputDirectory>${outputDir}</outputDirectory>
6634
</configuration>
6735
</plugin>
6836

@@ -100,14 +68,6 @@
10068
<!--Replace variables-->
10169
<filtering>true</filtering>
10270
</resource>
103-
104-
<!--Add the license to jar in order to see it in the final jar-->
105-
<resource>
106-
<directory>${basedir}</directory>
107-
<includes>
108-
<include>LICENSE</include>
109-
</includes>
110-
</resource>
11171
</resources>
11272
</build>
11373

@@ -121,7 +81,7 @@
12181
<!--mcmmo-->
12282
<repository>
12383
<id>md_5-releases</id>
124-
<url>http://repo.md-5.net/content/groups/public/</url>
84+
<url>https://repo.md-5.net/content/groups/public/</url>
12585
</repository>
12686

12787
<!--Vault and Heroes-->
@@ -174,7 +134,7 @@
174134
<repository>
175135
<id>bintray-tastybento-maven-repo</id>
176136
<name>bintray</name>
177-
<url>http://dl.bintray.com/tastybento/maven-repo</url>
137+
<url>https://dl.bintray.com/tastybento/maven-repo</url>
178138
</repository>
179139

180140
<!--MyPet-->

src/main/java/com/github/games647/scoreboardstats/RefreshTask.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ public void run() {
3939
int remainingUpdates = getNextUpdates();
4040
for (Map.Entry<Player, MutableInt> entry : queue.entrySet()) {
4141
Player player = entry.getKey();
42-
MutableInt remanigTicks = entry.getValue();
43-
if (remanigTicks.intValue() == 0) {
42+
MutableInt remainingTicks = entry.getValue();
43+
if (remainingTicks.intValue() == 0) {
4444
if (remainingUpdates != 0) {
4545
//Smoother refreshing; limit the updates
4646
plugin.getScoreboardManager().onUpdate(player);
47-
remanigTicks.setValue(20 * Settings.getInterval());
47+
remainingTicks.setValue(20 * Settings.getInterval());
4848
remainingUpdates--;
4949
}
5050
} else {
51-
remanigTicks.decrement();
51+
remainingTicks.decrement();
5252
}
5353
}
5454

src/main/java/com/github/games647/scoreboardstats/commands/SidebarCommands.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.google.common.collect.Maps;
77

88
import java.util.Arrays;
9-
import java.util.Collections;
109
import java.util.List;
1110
import java.util.Map;
1211
import java.util.stream.Collectors;
@@ -78,7 +77,7 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
7877
suggestion = commandHandler.onTabComplete(sender, subCommand, Arrays.copyOfRange(args, 1, args.length));
7978
if (suggestion != null) {
8079
//Prevent NPEs and the usage of this method in nearly every handler
81-
Collections.sort(suggestion, String.CASE_INSENSITIVE_ORDER);
80+
suggestion.sort(String.CASE_INSENSITIVE_ORDER);
8281
}
8382

8483
return suggestion;

src/main/java/com/github/games647/scoreboardstats/pvpstats/Database.java

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.github.games647.scoreboardstats.config.Settings;
77
import com.google.common.collect.Lists;
88
import com.google.common.collect.Maps;
9-
import com.google.common.util.concurrent.ThreadFactoryBuilder;
109
import com.zaxxer.hikari.HikariDataSource;
1110

1211
import java.sql.Connection;
@@ -21,10 +20,7 @@
2120
import java.util.Objects;
2221
import java.util.UUID;
2322
import java.util.concurrent.CancellationException;
24-
import java.util.concurrent.Executors;
2523
import java.util.concurrent.Future;
26-
import java.util.concurrent.ScheduledExecutorService;
27-
import java.util.concurrent.TimeUnit;
2824
import java.util.function.Function;
2925
import java.util.logging.Level;
3026
import java.util.stream.Collectors;
@@ -42,8 +38,6 @@ public class Database {
4238

4339
private final ScoreboardStats plugin;
4440

45-
private final ScheduledExecutorService executor;
46-
4741
private final Map<String, Integer> toplist = Maps.newHashMapWithExpectedSize(Settings.getTopitems());
4842

4943
private final DatabaseConfiguration dbConfig;
@@ -52,11 +46,6 @@ public class Database {
5246
public Database(ScoreboardStats plugin) {
5347
this.plugin = plugin;
5448
this.dbConfig = new DatabaseConfiguration(plugin);
55-
56-
//SQL transactions are mainly blocking so there is no need to update them smooth
57-
executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder()
58-
//Give the thread a name so we can find them
59-
.setNameFormat(plugin.getName() + "-Database").build());
6049
}
6150

6251
/**
@@ -84,7 +73,8 @@ public PlayerStats getCachedStats(Player request) {
8473
*/
8574
public void loadAccountAsync(Player player) {
8675
if (getCachedStats(player) == null && dataSource != null) {
87-
executor.execute(new StatsLoader(plugin, dbConfig.isUuidUse(), player, this));
76+
Runnable statsLoader = new StatsLoader(plugin, dbConfig.isUuidUse(), player, this);
77+
Bukkit.getScheduler().runTaskAsynchronously(plugin, statsLoader);
8878
}
8979
}
9080

@@ -172,7 +162,7 @@ public PlayerStats loadAccount(Player player) {
172162
* @param stats PlayerStats data
173163
*/
174164
public void saveAsync(PlayerStats stats) {
175-
executor.submit(() -> save(Lists.newArrayList(stats)));
165+
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> save(Lists.newArrayList(stats)));
176166
}
177167

178168
/**
@@ -291,15 +281,10 @@ public void saveAll() {
291281
save(toSave);
292282
}
293283

294-
executor.shutdown();
295-
296-
executor.awaitTermination(15, TimeUnit.MINUTES);
297-
} catch (InterruptedException ex) {
298-
plugin.getLogger().log(Level.SEVERE, "Couldn't save the stats to the database", ex);
284+
dataSource.close();
299285
} finally {
300286
//Make rally sure we remove all even on error
301287
BackwardsCompatibleUtil.getOnlinePlayers()
302-
.stream()
303288
.forEach(player -> player.removeMetadata(METAKEY, plugin));
304289
}
305290
}
@@ -340,9 +325,8 @@ public void setupDatabase() {
340325
close(conn);
341326
}
342327

343-
executor.scheduleWithFixedDelay(this::updateTopList, 0, 5, TimeUnit.MINUTES);
344-
345-
executor.scheduleWithFixedDelay(() -> {
328+
Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, this::updateTopList, 20 * 60 * 5, 0);
329+
Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () -> {
346330
if (dataSource == null) {
347331
return;
348332
}
@@ -367,7 +351,7 @@ public void setupDatabase() {
367351
} catch (Exception ex) {
368352
plugin.getLogger().log(Level.SEVERE, null, ex);
369353
}
370-
}, 0, 1, TimeUnit.MINUTES);
354+
}, 20 * 60, 0);
371355

372356
registerEvents();
373357
}

src/main/java/com/github/games647/scoreboardstats/scoreboard/bukkit/BukkitScoreboardManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void createTopListScoreboard(Player player) {
128128
objective.setDisplayName(Settings.getTempTitle());
129129

130130
//Colorize and send all elements
131-
plugin.getStatsDatabase().getTop().stream().forEach((entry) -> {
131+
plugin.getStatsDatabase().getTop().forEach((entry) -> {
132132
String scoreName = stripLength(Settings.getTempColor() + entry.getKey());
133133
sendScore(objective, scoreName, entry.getValue(), true);
134134
});

src/main/java/com/github/games647/scoreboardstats/scoreboard/protocol/PacketListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class PacketListener extends PacketAdapter {
3535
/**
3636
* Creates a new packet listener
3737
*
38-
* @param plugin plugin for registration into ProtcolLib
38+
* @param plugin plugin for registration into ProtocolLib
3939
* @param manager packet manager instance
4040
*/
4141
public PacketListener(Plugin plugin, PacketSbManager manager) {

src/main/java/com/github/games647/scoreboardstats/scoreboard/protocol/PacketSbManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ public PacketSbManager(ScoreboardStats plugin) {
4141
* @return the scoreboard instance
4242
*/
4343
public PlayerScoreboard getScoreboard(Player player) {
44-
PlayerScoreboard scoreboard = scoreboards
44+
return scoreboards
4545
.computeIfAbsent(player.getUniqueId(), key -> new PlayerScoreboard(player));
46-
return scoreboard;
4746
}
4847

4948
@Override

src/main/java/com/github/games647/scoreboardstats/scoreboard/protocol/PlayerScoreboard.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public Objective createSidebarObjective(String objectiveName, String displayName
5757
}
5858

5959
if (objectivesByName.containsKey(objectiveName)) {
60-
//the objecive already exits. I assume that no other use this unique name
60+
//the objective already exits. I assume that no other use this unique name
6161
//so we expect that a other sidebar was showing
6262
Objective objective = objectivesByName.get(objectiveName);
6363
PacketFactory.sendDisplayPacket(objective);
@@ -130,7 +130,7 @@ void resetScore(String scoreName) {
130130
* Very weird that minecraft always ignore the name of the parent objective and
131131
* will remove the score from the complete scoreboard
132132
*/
133-
objectivesByName.values().stream().forEach(entry -> entry.items.remove(scoreName));
133+
objectivesByName.values().forEach(entry -> entry.items.remove(scoreName));
134134
}
135135

136136
void createOrUpdateScore(String scoreName, String parent, int score) {

src/main/java/com/github/games647/scoreboardstats/variables/PluginListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void onPluginEnable(PluginEnableEvent enableEvent) {
3131
//Register the listener back again if the plugin is available
3232
String enablePluginName = enableEvent.getPlugin().getName();
3333
Map<Class<? extends VariableReplaceAdapter<?>>, String> defaults = replaceManager.getDefaults();
34-
defaults.entrySet().stream().forEach(entry -> {
34+
defaults.entrySet().forEach(entry -> {
3535
String pluginName = entry.getValue();
3636
if (enablePluginName.equals(entry.getValue())) {
3737
replaceManager.registerDefault(entry.getKey(), pluginName);

src/main/java/com/github/games647/scoreboardstats/variables/Replaceable.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*
88
* @deprecated not fully featured and returns magic values. Will be removed in future versions
99
*/
10+
@FunctionalInterface
1011
@Deprecated
1112
public interface Replaceable {
1213

0 commit comments

Comments
 (0)