Skip to content

Commit

Permalink
Remove redundant code after Blue's big upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnicJelle committed Jan 15, 2023
1 parent 95b8515 commit 2ed55de
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 292 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ To get support with this plugin, join the [BlueMap Discord server](https://bluec
## Special thanks to

[Seercat3160](https://github.com/Seercat3160), [Mark-255](https://github.com/Mark-225),
[elsing](https://github.com/elsing) and [LOOHP](https://github.com/LOOHP) for their contributions to the project!
[elsing](https://github.com/elsing), [LOOHP](https://github.com/LOOHP)
and [Blue](https://github.com/TBlueF) for their contributions to the project!

[pop4959](https://github.com/pop4959/BlueMap-Essentials) and [JotaFaD](https://github.com/JotaFaD/CivsExtras) for their
open-source plugins that gave me great examples to learn from.\
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.technicjelle</groupId>
<artifactId>BlueMapOfflinePlayerMarkers</artifactId>
<version>2.0.2</version>
<version>2.1.0</version>
<packaging>jar</packaging>

<name>BlueMapOfflinePlayerMarkers</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.util.Objects;

Expand All @@ -24,9 +22,6 @@ private FileConfiguration configFile() {
}

public String markerSetName;
public boolean useBlueMapSource;
public URL skinURL;
public boolean verboseErrors;

public Config(Main plugin) {
this.plugin = plugin;
Expand All @@ -47,16 +42,5 @@ public Config(Main plugin) {

//Load config values into variables
markerSetName = configFile().getString("MarkerSetName");
useBlueMapSource = configFile().getBoolean("UseBlueMapSource");

try {
//Check if the skinURL is a valid URL
skinURL = new URL(configFile().getString("SkinURL"));
} catch (MalformedURLException e) {
logger.warning("Invalid skin URL: " + skinURL);
e.printStackTrace();
}

verboseErrors = configFile().getBoolean("VerboseErrors");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.Nullable;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -27,9 +23,6 @@ public final class Main extends JavaPlugin implements Listener {
public static Logger logger;
public static Config config;

@Nullable
public MarkerHandler markers;

@Override
public void onEnable() {
new Metrics(this, 16425);
Expand All @@ -48,46 +41,31 @@ public void onEnable() {

config = new Config(this);

Path webroot = api.getWebApp().getWebRoot();

// "registerStyle" has to be invoked inside the consumer (=> not in the async scheduled task below)
copyResourceToBlueMapWebApp(webroot, "style.css", "bmopm.css");
api.getWebApp().registerStyle("assets/bmopm.css");

copyResourceToBlueMapWebApp(webroot, "script.js", "bmopm.js");
api.getWebApp().registerScript("assets/bmopm.js");

Path webroot = api.getWebApp().getWebRoot();
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
try {
// load steve
BufferedImage steve = ImageIO.read(new File(webroot + "/assets/steve.png"));

markers = new MarkerHandler(steve);
markers.loadOfflineMarkers();
} catch (IOException ex) {
Main.logger.log(Level.SEVERE, "Failed to load steve from BlueMap's webroot!", ex);
}

// update custom style
Path stylePath = webroot.resolve("assets").resolve("bmopm.css");
try (
InputStream in = getResource("style.css");
OutputStream out = Files.newOutputStream(stylePath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)
){
in.transferTo(out);
} catch (IOException ex) {
Main.logger.log(Level.SEVERE, "Failed to update bmopm.css in BlueMap's webroot!", ex);
}

// update custom script
Path scriptPath = webroot.resolve("assets").resolve("bmopm.js");
try (
InputStream in = getResource("script.js");
OutputStream out = Files.newOutputStream(scriptPath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)
){
in.transferTo(out);
} catch (IOException ex) {
Main.logger.log(Level.SEVERE, "Failed to update bmopm.js in BlueMap's webroot!", ex);
}
});
//create marker handler and add all offline players in a separate thread, so the server doesn't hang up while it's going
Bukkit.getScheduler().runTaskAsynchronously(this, MarkerHandler::loadOfflineMarkers);
};

private void copyResourceToBlueMapWebApp(Path webroot, String fromResource, String toAsset) {
Path toPath = webroot.resolve("assets").resolve(toAsset);
try (
InputStream in = getResource(fromResource);
OutputStream out = Files.newOutputStream(toPath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)
){
in.transferTo(out);
} catch (IOException ex) {
logger.log(Level.SEVERE, "Failed to update " + toAsset + " in BlueMap's webroot!", ex);
}
}

Consumer<BlueMapAPI> onDisableListener = api -> {
logger.info("API disabled! BlueMap Offline Player Markers shutting down...");
//not much to do here, actually...
Expand All @@ -103,15 +81,11 @@ public void onDisable() {

@EventHandler
public void onJoin(PlayerJoinEvent e) {
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
if (markers != null) markers.remove(e.getPlayer());
});
Bukkit.getScheduler().runTaskAsynchronously(this, () -> MarkerHandler.remove(e.getPlayer()));
}

@EventHandler
public void onLeave(PlayerQuitEvent e) {
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
if (markers != null) markers.add(e.getPlayer());
});
Bukkit.getScheduler().runTaskAsynchronously(this, () -> MarkerHandler.add(e.getPlayer()));
}
}
Loading

0 comments on commit 2ed55de

Please sign in to comment.