-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renaming to DOTD, fixed Bugs, Debug Logs, Package Rename, Removed Dep…
…endencies, Feature Improvements
- Loading branch information
Showing
20 changed files
with
519 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 0 additions & 50 deletions
50
src/main/java/de/nmadev/domain/deprecator/ConfigManager.java
This file was deleted.
Oops, something went wrong.
45 changes: 0 additions & 45 deletions
45
src/main/java/de/nmadev/domain/deprecator/DomainDeprecator.java
This file was deleted.
Oops, something went wrong.
67 changes: 0 additions & 67 deletions
67
src/main/java/de/nmadev/domain/deprecator/command/DomainDeprecatorCommand.java
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
src/main/java/de/nmadev/domain/deprecator/listener/JoinListener.java
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
src/main/java/de/nmadev/domain/deprecator/listener/MotdListener.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.