Skip to content

Commit

Permalink
Renaming to DOTD, fixed Bugs, Debug Logs, Package Rename, Removed Dep…
Browse files Browse the repository at this point in the history
…endencies, Feature Improvements
  • Loading branch information
Velyn-N committed Oct 23, 2024
1 parent d162192 commit 56d3936
Show file tree
Hide file tree
Showing 20 changed files with 519 additions and 258 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Domain Deprecator Paper Plugin
# "Domain of the Day" Paper Plugin

A Plugin for [Paper](https://papermc.io) Minecraft Servers that detects the Domain used by a Player and sends them Messages depending on which one they use.

Expand All @@ -12,7 +12,9 @@ This plugin might help you in the early stages of a move where you want to grace

The Plugin supports per-Domain MOTDs and Join Messages.

All these aspects of the plugin can be customized in the config file and live-reloaded using the `/domain-deprecator` command.
The Command requires the `domain-deprecator.admin` Permission.
All these aspects of the plugin can be customized in the config file and live-reloaded using the `/dotd` command.
The Command requires the `dotd.admin` Permission.

The default config can be seen [here](./src/main/resources/config.yml).

The `/dotd players` Command allows you to see which Domains your players used for joining your server.
9 changes: 2 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.nmadev</groupId>
<artifactId>domain-deprecator</artifactId>
<groupId>me.velyn</groupId>
<artifactId>domain-of-the-day</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
Expand Down Expand Up @@ -33,11 +33,6 @@
<version>1.20.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
</dependencies>

<build>
Expand Down
50 changes: 0 additions & 50 deletions src/main/java/de/nmadev/domain/deprecator/ConfigManager.java

This file was deleted.

45 changes: 0 additions & 45 deletions src/main/java/de/nmadev/domain/deprecator/DomainDeprecator.java

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

82 changes: 82 additions & 0 deletions src/main/java/me/velyn/domain/dotd/ConfigManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package me.velyn.domain.dotd;

import me.velyn.domain.dotd.actions.DomainAction;
import org.bukkit.configuration.ConfigurationSection;

import java.util.*;
import java.util.logging.Logger;

public class ConfigManager {
private static final String DEFAULT_DOMAIN = "default";
private static final String CUSTOM_BLOCK = "custom";
public static final String DEBUG_LOG_PROP = "debug-log";

private final Logger log;

private boolean isDebugLog = false;

private final Map<String, List<DomainAction>> domainActions;

public ConfigManager(Logger logger) {
this.log = logger;
domainActions = new HashMap<>();
}

public void applyConfigValues(ConfigurationSection config) {
this.isDebugLog = config.getBoolean(DEBUG_LOG_PROP, false);

readBlock(config, DEFAULT_DOMAIN);

ConfigurationSection customs = config.getConfigurationSection(CUSTOM_BLOCK);
if (customs != null) {
customs.getKeys(false).forEach(key -> readBlock(customs, key));
}

if (isDebugLog()) {
log.info("---------------------------------------------");
log.info("Loaded the following DomainActions:");
log.info("---------------------------------------------");
domainActions.forEach((key, value) -> {
log.info(String.format("Domain: %s", key));
value.forEach(action -> log.info(String.format("Action: %s", action)));
log.info("---------------------------------------------");
});
}
}

private void readBlock(ConfigurationSection config, String blockKey) {
ConfigurationSection confBlock = config.getConfigurationSection(blockKey);
if (confBlock == null) {
log.info(String.format("Config Block %s appears to be empty", blockKey));
return;
}
List<DomainAction> actions = DomainAction.parseConfig(confBlock);
if (actions.isEmpty()) {
log.info(String.format("Config Block %s appears to contain no valid Actions!", blockKey));
return;
}
List<String> domains = confBlock.getStringList("domains");
if (domains.isEmpty()) {
log.info(String.format("Config Block %s does not specify domains, using the blockKey as Domain", blockKey));
domainActions.put(blockKey.toLowerCase(), actions);
} else {
domains.forEach(domain -> domainActions.put(domain.toLowerCase(), actions));
}
}

public boolean isDebugLog() {
return isDebugLog;
}

public List<DomainAction> getDomainActions(String domain) {
return domainActions.getOrDefault(domain.toLowerCase(), domainActions.getOrDefault(DEFAULT_DOMAIN, new ArrayList<>()));
}

public <T> Optional<T> getDomainAction(String domain, Class<T> type) {
return getDomainActions(domain)
.stream()
.filter(type::isInstance)
.map(type::cast)
.findAny();
}
}
Loading

0 comments on commit 56d3936

Please sign in to comment.