Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implementation of CommandFilters, replacing cooldowns and costs#3886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
FrankHeijden wants to merge15 commits intoEssentialsX:2.x
base:2.x
Choose a base branch
Loading
fromFrankHeijden:extract-command-filters
Open
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
15 commits
Select commitHold shift + click to select a range
7739d94
Implementation of CommandFilters, replacing cooldowns and costs
FrankHeijdenDec 29, 2020
0a03e50
Add command-filters.yml to .gitignore
FrankHeijdenDec 30, 2020
76e45fd
Change automatic upgrading of command-costs to 'command' instead
FrankHeijdenDec 30, 2020
dfda202
@FrankHeijden
FrankHeijdenDec 31, 2020
78f0ea2
Merge branch '2.x' into extract-command-filters
FrankHeijdenJan 2, 2021
20f5bbf
Merge branch '2.x' into extract-command-filters
FrankHeijdenJan 16, 2021
6825aff
Merge branch '2.x' into extract-command-filters
FrankHeijdenFeb 21, 2021
8e66e8b
Merge branch '2.x' into extract-command-filters
FrankHeijdenJun 15, 2021
b681c1c
Convert to sponge config
FrankHeijdenJun 15, 2021
2712e41
Merge branch '2.x' into extract-command-filters
FrankHeijdenDec 3, 2021
9dbd5dd
Update to configurate
FrankHeijdenDec 3, 2021
a2ad09b
Merge branch '2.x' into extract-command-filters
JRoyOct 14, 2022
96a95be
Merge branch 'EssentialsX:2.x' into extract-command-filters
FrankHeijdenOct 30, 2022
2103974
Merge remote-tracking branch 'upstream/2.x' into extract-command-filters
JRoyNov 11, 2023
2b8c8bf
Fix build
JRoyNov 11, 2023
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
PrevPrevious commit
NextNext commit
Update to configurate
  • Loading branch information
@FrankHeijden
FrankHeijden committedDec 3, 2021
commit9dbd5dda35d843b3e81c19d6301172c7063fba43
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
package com.earth2me.essentials;

import com.earth2me.essentials.config.ConfigurateUtil;
import com.earth2me.essentials.config.EssentialsConfiguration;
import net.ess3.api.IUser;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemoryConfiguration;
import org.spongepowered.configurate.CommentedConfigurationNode;

import java.io.File;
import java.math.BigDecimal;
Expand All@@ -11,88 +12,66 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public class CommandFilters implements IConf {

private final IEssentials essentials;
private final EssentialsConf config;
private ConfigurationSection filters;
private final EssentialsConfiguration config;
private Map<CommandFilter.Type, List<CommandFilter>> commandFilters;

public CommandFilters(final IEssentials essentials) {
this.essentials = essentials;
config = new EssentialsConf(new File(essentials.getDataFolder(), "command-filters.yml"));
config.setTemplateName("/command-filters.yml");
config = new EssentialsConfiguration(new File(essentials.getDataFolder(), "command-filters.yml"), "/command-filters.yml");

reloadConfig();
}

@Override
public void reloadConfig() {
config.load();
filters = _getCommandFilterSection();
commandFilters = _getCommandFilters();
commandFilters = parseCommandFilters(config);
}

private ConfigurationSection _getCommandFilterSection() {
if (config.isConfigurationSection("filters")) {
final ConfigurationSection section = config.getConfigurationSection("filters");
final ConfigurationSection newSection = new MemoryConfiguration();
for (final String filterItem : section.getKeys(false)) {
if (section.isConfigurationSection(filterItem)) {
newSection.set(filterItem.toLowerCase(Locale.ENGLISH), section.getConfigurationSection(filterItem));
}
}
return newSection;
}
return null;
}

private Map<CommandFilter.Type, List<CommandFilter>> _getCommandFilters() {
private Map<CommandFilter.Type, List<CommandFilter>> parseCommandFilters(EssentialsConfiguration config) {
final Map<CommandFilter.Type, List<CommandFilter>> commandFilters = new EnumMap<>(CommandFilter.Type.class);
for (final String name : filters.getKeys(false)) {
if (!filters.isConfigurationSection(name)) {
EssentialsConf.LOGGER.warning("Invalid command filter '" + name + "'");
continue;
}

final ConfigurationSection section = Objects.requireNonNull(filters.getConfigurationSection(name));
final Pattern pattern = section.isString("pattern") ? compileRegex(section.getString("pattern")) : null;
final String command = section.getString("command");
final CommentedConfigurationNode filterSection = config.getSection("filters");
for (final String filterItem : ConfigurateUtil.getKeys(filterSection)) {
final CommentedConfigurationNode section = filterSection.node(filterItem);
final String patternString = section.node("pattern").getString();
final Pattern pattern = patternString == null ? null : compileRegex(patternString);
final String command = section.node("command").getString();

if (pattern == null && command == null) {
EssentialsConf.LOGGER.warning("Invalid command filter '" +name + "', filter must either define 'pattern' or 'command'!");
EssentialsConf.LOGGER.warning("Invalid command filter '" +filterItem + "', filter must either define 'pattern' or 'command'!");
continue;
}

if (pattern != null && command != null) {
EssentialsConf.LOGGER.warning("Invalid command filter '" +name + "', filter can't have both 'pattern' and 'command'!");
EssentialsConf.LOGGER.warning("Invalid command filter '" +filterItem + "', filter can't have both 'pattern' and 'command'!");
continue;
}

Integer cooldown = section.getInt("cooldown",-1);
Integer cooldown = section.node("cooldown").getInt(-1);
if (cooldown < 0) {
cooldown = null;
} else {
cooldown *= 1000; // Convert to milliseconds
}

final boolean persistentCooldown = section.getBoolean("persistent-cooldown",true);
final BigDecimal cost = EssentialsConf.toBigDecimal(section.getString("cost"), null);
final boolean persistentCooldown = section.node("persistent-cooldown").getBoolean(true);
final BigDecimal cost = EssentialsConf.toBigDecimal(section.node("cost").getString(), null);

final StringlowerName =name.toLowerCase(Locale.ENGLISH);
final StringfilterItemName =filterItem.toLowerCase(Locale.ENGLISH);

if (pattern == null) {
commandFilters.computeIfAbsent(CommandFilter.Type.ESS, k -> new ArrayList<>()).add(new EssCommandFilter(lowerName, command, compileRegex(command), cooldown, persistentCooldown, cost));
commandFilters.computeIfAbsent(CommandFilter.Type.ESS, k -> new ArrayList<>()).add(new EssCommandFilter(filterItemName, command, compileRegex(command), cooldown, persistentCooldown, cost));
} else {
commandFilters.computeIfAbsent(CommandFilter.Type.REGEX, k -> new ArrayList<>()).add(new RegexCommandFilter(lowerName, pattern, cooldown, persistentCooldown, cost));
commandFilters.computeIfAbsent(CommandFilter.Type.REGEX, k -> new ArrayList<>()).add(new RegexCommandFilter(filterItemName, pattern, cooldown, persistentCooldown, cost));
}
}
config.save();
return commandFilters;
}

Expand All@@ -114,7 +93,7 @@ private Pattern compileRegex(String regex) {
}
}

publicEssentialsConf getConfig() {
publicEssentialsConfiguration getConfig() {
return config;
}

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -466,7 +466,7 @@ public void convertKits() {

public void convertCommandFilters() {
final CommandFilters commandFilters = ess.getCommandFilters();
finalEssentialsConf config = commandFilters.getConfig();
finalEssentialsConfiguration config = commandFilters.getConfig();
if (doneFile.getBoolean("commandFiltersYml", false)) {
return;
}
Expand All@@ -493,24 +493,29 @@ public void convertCommandFilters() {
LOGGER.info("Done converting command filters.");
}

private void convertCommandCooldowns(CommentedConfigurationNode commandCooldowns,EssentialsConf config) {
private void convertCommandCooldowns(CommentedConfigurationNode commandCooldowns,EssentialsConfiguration config) {
final boolean persistent = ess.getSettings().isCommandCooldownPersistent("dummy");
for (Map.Entry<String, Object> entry : ConfigurateUtil.getRawMap(commandCooldowns).entrySet()) {
LOGGER.info("Converting cooldown \"" + entry.getKey() + "\"");

final String key = entry.getKey().replace("\\.", "{dot}"); // Convert periods
config.set("filters." + key + ".pattern", entry.getKey());
config.set("filters." + key + ".cooldown", entry.getValue());
config.set("filters." + key + ".persistent-cooldown", persistent);
config.setProperty("filters." + key + ".pattern", entry.getKey());
final String cooldownKey = "filters." + key + ".cooldown";
if (entry.getValue() instanceof Double) {
config.setProperty(cooldownKey, (double) entry.getValue());
} else if (entry.getValue() instanceof Integer) {
config.setProperty(cooldownKey, (int) entry.getValue());
}
config.setProperty("filters." + key + ".persistent-cooldown", persistent);
}
}

private void convertCommandCosts(Map<String, BigDecimal> commandCosts,EssentialsConf config) {
private void convertCommandCosts(Map<String, BigDecimal> commandCosts,EssentialsConfiguration config) {
for (Map.Entry<String, BigDecimal> entry : commandCosts.entrySet()) {
LOGGER.info("Converting cost \"" + entry.getKey() + "\"");

config.set("filters." + entry.getKey() + ".command", entry.getKey());
config.set("filters." + entry.getKey() + ".cost", entry.getValue().toString());
config.setProperty("filters." + entry.getKey() + ".command", entry.getKey());
config.setProperty("filters." + entry.getKey() + ".cost", entry.getValue().toString());
}
}

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp