Skip to content

Commit e76bb07

Browse files
committed
Merge branch 'base' into mc/1.13
2 parents 7a50666 + de99536 commit e76bb07

File tree

25 files changed

+141
-100
lines changed

25 files changed

+141
-100
lines changed

BlueMapBukkit/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ repositories {
1010

1111
dependencies {
1212
shadow "org.bukkit:bukkit:1.13.2-R0.1-SNAPSHOT"
13-
compile group: 'org.bstats', name: 'bstats-bukkit-lite', version: '1.5'
13+
14+
compile group: 'org.bstats', name: 'bstats-bukkit-lite', version: '1.7'
1415

1516
compile (project(':BlueMapCommon')) {
1617
//exclude dependencies provided by bukkit

BlueMapBukkit/src/main/java/de/bluecolored/bluemap/bukkit/BukkitCommands.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ public void onTabComplete(TabCompleteEvent evt) {
8686
completions.sort((s1, s2) -> s1.compareToIgnoreCase(s2));
8787
evt.setCompletions(completions);
8888
}
89-
} catch (InterruptedException | ExecutionException | TimeoutException ignore) {}
89+
} catch (InterruptedException ignore) {
90+
Thread.currentThread().interrupt();
91+
} catch (ExecutionException | TimeoutException ignore) {}
9092
}
9193

9294
private class CommandProxy extends BukkitCommand {

BlueMapBukkit/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@
5656
import de.bluecolored.bluemap.common.plugin.serverinterface.ServerEventListener;
5757
import de.bluecolored.bluemap.common.plugin.serverinterface.ServerInterface;
5858
import de.bluecolored.bluemap.core.logger.Logger;
59+
import de.bluecolored.bluemap.core.resourcepack.ParseResourceException;
5960

6061
public class BukkitPlugin extends JavaPlugin implements ServerInterface, Listener {
6162

6263
private static BukkitPlugin instance;
6364

64-
private Plugin bluemap;
65+
private Plugin pluginInstance;
6566
private EventForwarder eventForwarder;
6667
private BukkitCommands commands;
6768

@@ -76,15 +77,15 @@ public BukkitPlugin() {
7677
this.onlinePlayerList = Collections.synchronizedList(new ArrayList<>());
7778

7879
this.eventForwarder = new EventForwarder();
79-
this.bluemap = new Plugin("bukkit", this);
80-
this.commands = new BukkitCommands(this.bluemap);
80+
this.pluginInstance = new Plugin("bukkit", this);
81+
this.commands = new BukkitCommands(this.pluginInstance);
8182

8283
BukkitPlugin.instance = this;
8384
}
8485

8586
@Override
8687
public void onEnable() {
87-
new MetricsLite(this);
88+
new MetricsLite(this, 5912);
8889

8990
//save world so the level.dat is present on new worlds
9091
Logger.global.logInfo("Saving all worlds once, to make sure the level.dat is present...");
@@ -113,17 +114,27 @@ public void onEnable() {
113114
//tab completions
114115
getServer().getPluginManager().registerEvents(commands, this);
115116

117+
//update online-player collections
118+
this.onlinePlayerList.clear();
119+
this.onlinePlayerMap.clear();
120+
for (org.bukkit.entity.Player player : getServer().getOnlinePlayers()) {
121+
BukkitPlayer bukkitPlayer = new BukkitPlayer(player);
122+
onlinePlayerMap.put(player.getUniqueId(), bukkitPlayer);
123+
onlinePlayerList.add(bukkitPlayer);
124+
}
125+
116126
//start updating players
117127
getServer().getScheduler().runTaskTimer(this, this::updateSomePlayers, 1, 1);
118128

119129
//load bluemap
120130
getServer().getScheduler().runTaskAsynchronously(this, () -> {
121131
try {
122132
Logger.global.logInfo("Loading...");
123-
this.bluemap.load();
124-
if (bluemap.isLoaded()) Logger.global.logInfo("Loaded!");
125-
} catch (Throwable t) {
126-
Logger.global.logError("Failed to load!", t);
133+
this.pluginInstance.load();
134+
if (pluginInstance.isLoaded()) Logger.global.logInfo("Loaded!");
135+
} catch (IOException | ParseResourceException | RuntimeException e) {
136+
Logger.global.logError("Failed to load!", e);
137+
this.pluginInstance.unload();
127138
}
128139
});
129140
}
@@ -132,7 +143,7 @@ public void onEnable() {
132143
public void onDisable() {
133144
Logger.global.logInfo("Stopping...");
134145
getServer().getScheduler().cancelTasks(this);
135-
bluemap.unload();
146+
pluginInstance.unload();
136147
Logger.global.logInfo("Saved and stopped!");
137148
}
138149

@@ -165,6 +176,7 @@ public UUID getUUIDForWorld(File worldFolder) throws IOException {
165176
try {
166177
return futureUUID.get();
167178
} catch (InterruptedException e) {
179+
Thread.currentThread().interrupt();
168180
throw new IOException(e);
169181
} catch (ExecutionException e) {
170182
if (e.getCause() instanceof IOException) {
@@ -197,7 +209,7 @@ public File getConfigFolder() {
197209
}
198210

199211
public Plugin getBlueMap() {
200-
return bluemap;
212+
return pluginInstance;
201213
}
202214

203215
public static BukkitPlugin getInstance() {

BlueMapCLI/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public void renderMaps() throws IOException {
222222
while(renderManager.getRenderTaskCount() != 0) {
223223
try {
224224
Thread.sleep(200);
225-
} catch (InterruptedException e) {}
225+
} catch (InterruptedException e) { Thread.currentThread().interrupt(); return; }
226226

227227

228228
long now = System.currentTimeMillis();
@@ -390,7 +390,7 @@ public static void main(String[] args) throws IOException, ParseResourceExceptio
390390
//wait a second to let the webserver start, looks nicer in the log
391391
try {
392392
Thread.sleep(1000);
393-
} catch (InterruptedException ignore) {}
393+
} catch (InterruptedException ignore) { Thread.currentThread().interrupt(); }
394394
}
395395

396396

@@ -452,7 +452,7 @@ private static void printHelp() {
452452
filename = file.getAbsolutePath();
453453
}
454454
}
455-
} catch (Exception ex) {}
455+
} catch (IOException ex) {}
456456

457457
String command = "java -jar " + filename;
458458

BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/RenderManager.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public synchronized void stop() {
7575
for (int i = 0; i < renderThreads.length; i++) {
7676
if (renderThreads[i] != null) {
7777
renderThreads[i].interrupt();
78-
renderThreads[i] = null;
7978
}
8079
}
8180

@@ -141,7 +140,7 @@ public boolean removeRenderTask(RenderTask renderTask) {
141140
private void renderThread() {
142141
RenderTicket ticket = null;
143142

144-
while (!Thread.interrupted() && running) {
143+
while (running) {
145144
synchronized (renderTickets) {
146145
ticket = renderTickets.poll();
147146
if (ticket != null) renderTicketMap.remove(ticket);
@@ -163,17 +162,22 @@ private void renderThread() {
163162
if (ticket != null) {
164163
try {
165164
ticket.render();
166-
} catch (Exception e) {
165+
} catch (RuntimeException e) {
167166
//catch possible runtime exceptions, display them, and wait a while .. then resurrect this render-thread
168167
Logger.global.logError("Unexpected exception in render-thread!", e);
169168
try {
170169
Thread.sleep(10000);
171-
} catch (InterruptedException interrupt) { break; }
170+
} catch (InterruptedException interrupt) { Thread.currentThread().interrupt(); break; }
172171
}
173172
} else {
174173
try {
175174
Thread.sleep(1000); // we don't need a super fast response time, so waiting a second is totally fine
176-
} catch (InterruptedException interrupt) { break; }
175+
} catch (InterruptedException interrupt) { Thread.currentThread().interrupt(); break; }
176+
}
177+
178+
if (Thread.interrupted()) {
179+
Thread.currentThread().interrupt();
180+
break;
177181
}
178182
}
179183
}

BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/MapUpdateHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void onWorldSaveToDisk(final UUID world) {
6666
}
6767

6868
}
69-
} catch (InterruptedException ignore) {}
69+
} catch (InterruptedException ignore) { Thread.currentThread().interrupt(); }
7070

7171
}).start();
7272
}

BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Plugin.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ public synchronized void load() throws IOException, ParseResourceException {
262262
}
263263
}
264264
} catch (InterruptedException ex){
265+
Thread.currentThread().interrupt();
265266
return;
266267
}
267268
});
@@ -316,6 +317,7 @@ public synchronized void load() throws IOException, ParseResourceException {
316317
Thread.sleep(TimeUnit.MINUTES.toMillis(30));
317318
}
318319
} catch (InterruptedException ex){
320+
Thread.currentThread().interrupt();
319321
return;
320322
}
321323
});
@@ -338,11 +340,19 @@ public synchronized void unload() {
338340
serverInterface.unregisterAllListeners();
339341

340342
//stop scheduled threads
341-
if (metricsThread != null) metricsThread.interrupt();
342-
metricsThread = null;
343+
if (metricsThread != null) {
344+
metricsThread.interrupt();
345+
try {metricsThread.join(1000);} catch (InterruptedException ignore) { Thread.currentThread().interrupt(); }
346+
if (metricsThread.isAlive()) Logger.global.logWarning("The metricsThread did not terminate correctly in time!");
347+
metricsThread = null;
348+
}
343349

344-
if (periodicalSaveThread != null) periodicalSaveThread.interrupt();
345-
periodicalSaveThread = null;
350+
if (periodicalSaveThread != null) {
351+
periodicalSaveThread.interrupt();
352+
try {periodicalSaveThread.join(1000);} catch (InterruptedException ignore) { Thread.currentThread().interrupt(); }
353+
if (periodicalSaveThread.isAlive()) Logger.global.logWarning("The periodicalSaveThread did not terminate correctly in time!");
354+
periodicalSaveThread = null;
355+
}
346356

347357
//stop services
348358
if (renderManager != null) renderManager.stop();

BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import de.bluecolored.bluemap.core.mca.Chunk;
6161
import de.bluecolored.bluemap.core.mca.ChunkAnvil112;
6262
import de.bluecolored.bluemap.core.mca.MCAWorld;
63+
import de.bluecolored.bluemap.core.resourcepack.ParseResourceException;
6364
import de.bluecolored.bluemap.core.world.Block;
6465
import de.bluecolored.bluemap.core.world.World;
6566

@@ -307,7 +308,7 @@ public int reloadCommand(CommandContext<S> context) {
307308
source.sendMessage(Text.of(TextColor.RED, "Could not load BlueMap! See the console for details!"));
308309
}
309310

310-
} catch (Exception ex) {
311+
} catch (IOException | ParseResourceException | RuntimeException ex) {
311312
Logger.global.logError("Failed to reload BlueMap!", ex);
312313

313314
source.sendMessage(Text.of(TextColor.RED, "There was an error reloading BlueMap! See the console for details!"));

BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/skins/PlayerSkin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void update(File storageFolder) {
7373
Logger.global.logDebug("Failed to load player-skin from mojang-servers: " + e);
7474
} catch (IOException e) {
7575
Logger.global.logError("Failed to write player-head image!", e);
76-
} catch (InterruptedException ignore) {}
76+
} catch (InterruptedException ignore) { Thread.currentThread().interrupt(); }
7777
}).start();
7878
}
7979

@@ -87,7 +87,7 @@ public BufferedImage createHead(BufferedImage skinTexture) {
8787
Graphics2D g = head.createGraphics();
8888
g.drawImage(layer1, 0, 0, null);
8989
g.drawImage(layer2, 0, 0, null);
90-
} catch (Throwable t) { // There might be problems with headless servers when loading the graphics class
90+
} catch (Throwable t) { // There might be problems with headless servers when loading the graphics class, so we catch every exception and error on purpose here
9191
Logger.global.noFloodWarning("headless-graphics-fail",
9292
"Could not access Graphics2D to render player-skin texture. Try adding '-Djava.awt.headless=true' to your startup flags or ignore this warning.");
9393

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAWorld.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,9 @@ private MCAWorld(
142142
}
143143

144144
public BlockState getBlockState(Vector3i pos) {
145-
try {
146-
147-
Vector2i chunkPos = blockToChunk(pos);
148-
Chunk chunk = getChunk(chunkPos);
149-
return chunk.getBlockState(pos);
150-
151-
} catch (Exception ex) {
152-
return BlockState.MISSING;
153-
}
145+
Vector2i chunkPos = blockToChunk(pos);
146+
Chunk chunk = getChunk(chunkPos);
147+
return chunk.getBlockState(pos);
154148
}
155149

156150
@Override
@@ -200,22 +194,22 @@ public Chunk getChunk(Vector2i chunkPos) {
200194
Chunk chunk = CHUNK_CACHE.get(new WorldChunkHash(this, chunkPos), () -> this.loadChunkOrEmpty(chunkPos, 2, 1000));
201195
return chunk;
202196
} catch (UncheckedExecutionException | ExecutionException e) {
197+
if (e.getCause() instanceof InterruptedException) Thread.currentThread().interrupt();
203198
throw new RuntimeException(e.getCause());
204199
}
205200
}
206201

207-
private Chunk loadChunkOrEmpty(Vector2i chunkPos, int tries, long tryInterval) {
202+
private Chunk loadChunkOrEmpty(Vector2i chunkPos, int tries, long tryInterval) throws InterruptedException {
208203
Exception loadException = null;
209204
for (int i = 0; i < tries; i++) {
210205
try {
211206
return loadChunk(chunkPos);
212-
} catch (Exception e) {
207+
} catch (IOException | RuntimeException e) {
208+
if (loadException != null) e.addSuppressed(loadException);
213209
loadException = e;
214210

215211
if (tryInterval > 0 && i+1 < tries) {
216-
try {
217-
Thread.sleep(tryInterval);
218-
} catch (InterruptedException interrupt) {}
212+
Thread.sleep(tryInterval);
219213
}
220214
}
221215
}
@@ -261,7 +255,7 @@ private Chunk loadChunk(Vector2i chunkPos) throws IOException {
261255
} else {
262256
throw new IOException("Invalid data tag: " + (tag == null ? "null" : tag.getClass().getName()));
263257
}
264-
} catch (Exception e) {
258+
} catch (RuntimeException | IOException e) {
265259
throw new IOException("Exception trying to load chunk (" + chunkPos + ")", e);
266260
}
267261
}
@@ -312,7 +306,7 @@ public Collection<Vector2i> getChunkList(long modifiedSinceMillis, Predicate<Vec
312306
}
313307
}
314308
}
315-
} catch (Exception ex) {
309+
} catch (RuntimeException | IOException ex) {
316310
Logger.global.logWarning("Failed to read .mca file: " + file.getAbsolutePath() + " (" + ex.toString() + ")");
317311
}
318312
}

0 commit comments

Comments
 (0)