Hush/src/main/java/com/zerohighdef/hush/Hush.java

75 lines
2.6 KiB
Java

package com.zerohighdef.hush;
import com.zerohighdef.hush.commands.MainCommand;
import com.zerohighdef.hush.listeners.HushAsyncChatListener;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.time.OffsetDateTime;
import java.util.*;
import java.util.logging.Logger;
public final class Hush extends JavaPlugin {
private final Logger log = Logger.getLogger("Minecraft");
private HashMap<String, List<WatchCategory>> watchLists;
private final HashMap<UUID, OffsetDateTime> cooldowns = new HashMap<>();
@Override
public void onEnable() {
saveDefaultConfig();
reloadConfig();
if (isEnabled()) {
new HushAsyncChatListener(this);
new MainCommand(this);
}
}
@Override
public void reloadConfig() {
super.reloadConfig();
buildWatchLists();
}
private void buildWatchLists() {
watchLists = new HashMap<>();
ConfigurationSection watchListSection = getConfig().getConfigurationSection("watch_lists");
for (String permission: watchListSection.getKeys(false)) {
ConfigurationSection permissionSection = watchListSection.getConfigurationSection(permission);
LinkedList<WatchCategory> watchCategories = new LinkedList<>();
for (String category: permissionSection.getKeys(false)) {
ConfigurationSection categorySection = permissionSection.getConfigurationSection(category);
List<String> filters = categorySection.getStringList("filters");
List<String> commands = categorySection.getStringList("commands");
boolean cancelMsg = categorySection.getBoolean("cancel_msg", false);
watchCategories.add(new WatchCategory(category, filters, commands, cancelMsg));
}
watchLists.put(permission, watchCategories);
}
}
public void log(String message) {
log.info( "[Hush]: " + message );
}
public Map<String, List<WatchCategory>> getWatchLists() {
return watchLists;
}
public void addCoolDown(Player player) {
cooldowns.put(player.getUniqueId(), OffsetDateTime.now());
}
public boolean isInCoolDown(Player player) {
if (cooldowns.containsKey(player.getUniqueId())) {
int cooldownTime = getConfig().getInt("cooldown", 5);
OffsetDateTime now = OffsetDateTime.now();
return now.minusMinutes(cooldownTime).compareTo(cooldowns.get(player.getUniqueId())) < 0;
}
return false;
}
}