Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions src/main/java/tfmc/justin/activity/ActivityAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,12 @@

import java.util.UUID;

// ====================================
// The intake path for plugins that compile against this jar. The other two
// are the custom events and /activity add, so nothing has to depend on us.
// ====================================
public final class ActivityAPI {

private ActivityAPI() {
}

/**
* Record progress towards an activity for a player.
* <p>
* Main thread only. Unknown activity ids and non-positive amounts are ignored.
*
* @param uuid the player, online or not
* @param activityId an id from the 'activities' section of config.yml
* @param amount how much progress to add
* @throws IllegalStateException if called off the main thread
*/
public static void record(UUID uuid, String activityId, int amount) {
// Loud rather than a corrupted store: everything downstream mutates
// player state without a lock because it assumes it is on a tick
if (!Bukkit.isPrimaryThread()) {
throw new IllegalStateException("ActivityAPI.record must be called on the main thread");
}
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/tfmc/justin/activity/ActivityPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

public class ActivityPlugin extends JavaPlugin {

// Held only so onDisable can take it back out of PlaceholderAPI - an
// expansion left registered keeps this classloader alive across a reload
private PlaceholderHook placeholderHook;

@Override
Expand All @@ -45,7 +43,6 @@ public void onEnable() {
getCommand("activity").setTabCompleter(command);

getServer().getPluginManager().registerEvents(new JoinListener(manager), this);
// Vanilla crafting - no soft-depend to check, unlike registerHooks below
getServer().getPluginManager().registerEvents(new CraftListener(manager), this);
getServer().getPluginManager().registerEvents(gui, this);

Expand All @@ -56,11 +53,6 @@ public void onEnable() {

@Override
public void onDisable() {
// ====================================
// Save first: the final write must land no matter what happens next.
// Unregistering from PAPI runs after, wrapped so a teardown throw from
// another plugin's classloader can never follow-skip or interrupt it.
// ====================================
if (ActivityManager.getInstance() != null) {
ActivityManager.getInstance().shutdown();
}
Expand All @@ -76,12 +68,6 @@ public void onDisable() {
getLogger().info("activity has been disabled!");
}

// ====================================
// Source plugins are compiled against but optional at runtime. Each
// listener is only constructed inside its own isPluginEnabled check, so
// the class - and the missing event type it references - is never loaded
// on a server that does not have the plugin installed.
// ====================================
private void registerHooks() {
if (Bukkit.getPluginManager().isPluginEnabled("VotingPlugin")) {
getServer().getPluginManager().registerEvents(new VoteListener(this, ActivityManager.getInstance()), this);
Expand Down
168 changes: 0 additions & 168 deletions src/main/java/tfmc/justin/activity/commands/ActivityCommand.java

Large diffs are not rendered by default.

497 changes: 0 additions & 497 deletions src/main/java/tfmc/justin/activity/config/ActivityConfiguration.java

Large diffs are not rendered by default.

33 changes: 0 additions & 33 deletions src/main/java/tfmc/justin/activity/config/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,18 @@
import java.io.Reader;
import java.nio.charset.StandardCharsets;

// ====================================
// Every string the plugin sends to chat, read from messages.yml.
//
// The packaged copy is installed as the defaults, so a key an admin deleted
// still resolves to shipped text rather than showing a raw path in chat.
// ====================================
public class Messages {

public static final String FILE = "messages.yml";

private final JavaPlugin plugin;

// Volatile: /activity reload swaps it on the main thread while
// PlaceholderAPI can be reading a message off one
private volatile YamlConfiguration messages;

// Not loaded here: ActivityConfiguration.load() calls reload() before
// anything can ask for a message, and parsing the file twice per enable
// was the only thing the constructor call added
public Messages(JavaPlugin plugin) {
this.plugin = plugin;
}

// ====================================
// Re-read messages.yml from disk, so /activity reload picks up text edits.
// Built entirely into a local 'next' and only assigned to the volatile
// field as the last step, so a reader on another thread never observes it
// between being loaded and having its defaults applied.
// ====================================
public void reload() {
File file = new File(plugin.getDataFolder(), FILE);
if (!file.exists()) {
Expand All @@ -56,15 +39,9 @@ public void reload() {
messages = next;
}

// ====================================
// Look up a message and fill in its placeholders.
// Pairs are given inline: get("admin.add-done", "%count%", n, "%player%", name)
// ====================================
public String get(String path, Object... placeholderPairs) {
String raw = messages.getString(path);
if (raw == null) {
// Only reachable if the key is missing from both the live file and
// the packaged defaults, which means a typo in a call site
plugin.getLogger().warning("Missing message '" + path + "' in " + FILE);
return path;
}
Expand All @@ -74,11 +51,6 @@ public String get(String path, Object... placeholderPairs) {
return Utils.colorize(raw);
}

// ====================================
// Colour codes are translated before the values go in, so a value that
// happens to contain '&c' or a hex code lands in chat as literal text
// instead of recolouring the rest of the line.
// ====================================
String message = Utils.colorize(raw);
for (int index = 0; index < placeholderPairs.length; index += 2) {
message = message.replace(String.valueOf(placeholderPairs[index]),
Expand All @@ -88,11 +60,6 @@ public String get(String path, Object... placeholderPairs) {
return message;
}

// ====================================
// Verbatim lookup: no colour translation, no placeholder substitution and
// no warning on a miss, where get() logs one. The path is returned as-is
// when the key resolves to nothing. Callers colorize what they get back.
// ====================================
public String raw(String path) {
String value = messages.getString(path);
return value == null ? path : value;
Expand Down
Loading
Loading