Skip to content

Commit

Permalink
Config for marker set properties and duration
Browse files Browse the repository at this point in the history
Finishes point 2. in #1
  • Loading branch information
TechnicJelle committed May 6, 2023
1 parent 5fc5d30 commit 78df061
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
import java.util.function.Consumer;

public final class BlueMapChatMarkers extends JavaPlugin implements Listener {
private final String MARKERSET_ID = "chat-markers";
private Config config;
private UpdateChecker updateChecker;

private final int seconds = 60; //TODO: Make this configurable

@Override
public void onEnable() {
new Metrics(this, 16424);
Expand All @@ -42,6 +40,8 @@ public void onEnable() {
Consumer<BlueMapAPI> onEnableListener = api -> {
updateChecker.logUpdateMessage(getLogger());

config = new Config(this);

String styleFile = "textStyle.css";
try {
MCUtils.copyPluginResourceToConfigDir(this, styleFile, styleFile, false);
Expand All @@ -52,14 +52,12 @@ public void onEnable() {
};

private void createMarkerSet(BlueMapWorld bmWorld) {
getLogger().info("Creating MarkerSet for BlueMap World " + bmWorld.getId());
MarkerSet markerSet = new MarkerSet("Chat Markers");
markerSet.setDefaultHidden(false);
markerSet.setToggleable(true);
getLogger().info("Creating MarkerSet for BlueMap World '" + bmWorld.getSaveFolder().getFileName() + "'");
MarkerSet markerSet = new MarkerSet(config.markerSetName, config.toggleable, config.defaultHidden);

//add the markerset to all BlueMap maps of this world
for (BlueMapMap map : bmWorld.getMaps()) {
map.getMarkerSets().put(MARKERSET_ID, markerSet);
map.getMarkerSets().put(Config.MARKER_SET_ID, markerSet);
}
}

Expand All @@ -83,10 +81,10 @@ public void onPlayerChat(AsyncPlayerChatEvent event) {

//for all BlueMap Maps belonging to the BlueMap World the Player is in, add the Marker to the MarkerSet of that BlueMap World
bmWorld.getMaps().forEach(map -> {
if (!map.getMarkerSets().containsKey(MARKERSET_ID)) //if this world doesn't have a MarkerSet yet, create it
if (!map.getMarkerSets().containsKey(Config.MARKER_SET_ID)) //if this world doesn't have a MarkerSet yet, create it
createMarkerSet(bmWorld); //creates a new MarkerSet, and assigns it to each Map of this World

MarkerSet markerSet = map.getMarkerSets().get(MARKERSET_ID);
MarkerSet markerSet = map.getMarkerSets().get(Config.MARKER_SET_ID);

String key = "chat-marker_" + event.hashCode();

Expand All @@ -96,7 +94,7 @@ public void onPlayerChat(AsyncPlayerChatEvent event) {
//wait Seconds and remove the Marker
Bukkit.getScheduler().runTaskLater(this,
() -> markerSet.remove(key),
seconds * 20);
config.markerDuration * 20L);
});
});
}
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/com/technicjelle/bluemapchatmarkers/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.technicjelle.bluemapchatmarkers;

import com.technicjelle.MCUtils;
import org.bukkit.configuration.file.FileConfiguration;

import java.io.IOException;

public class Config {
public static final String MARKER_SET_ID = "chat-markers";

private final BlueMapChatMarkers plugin;

public String markerSetName;
public boolean toggleable;
public boolean defaultHidden;
public long markerDuration;

public Config(BlueMapChatMarkers plugin) {
this.plugin = plugin;

try {
MCUtils.copyPluginResourceToConfigDir(plugin, "config.yml", "config.yml", false);
} catch (IOException e) {
throw new RuntimeException(e);
}

//Load config from disk
plugin.reloadConfig();

//Load config values into variables
markerSetName = configFile().getString("MarkerSetName");
toggleable = configFile().getBoolean("Toggleable");
defaultHidden = configFile().getBoolean("DefaultHidden");
markerDuration = configFile().getLong("MarkerDuration");
}

private FileConfiguration configFile() {
return plugin.getConfig();
}
}
8 changes: 8 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Marker Set Options
# Documentation: https://bluemap.bluecolored.de/wiki/customization/Markers.html#marker-sets
MarkerSetName: "Chat Messages"
Toggleable: true
DefaultHidden: false

# Amount of time a chat marker stays on the map (in seconds)
MarkerDuration: 60

0 comments on commit 78df061

Please sign in to comment.