T2C-OPSecurity/src/main/java/de/jatitv/opsecurity/config/config/SelectConfig.java

156 lines
6.9 KiB
Java

// This claas was created by JaTiTV
package de.jatitv.opsecurity.config.config;
import de.jatitv.opsecurity.config.languages.SelectMessages;
import de.jatitv.opsecurity.objects.PlayerObject;
import de.jatitv.opsecurity.system.Main;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class SelectConfig {
// Config
public static Integer ConfigVersion;
public static Boolean UpdateCheckOnJoin;
public static String language;
public static Boolean OnlyOPcanUseThePlugin;
public static Boolean CheckOnJoin;
public static Boolean CheckOnInteract;
public static Boolean CheckOnCommand;
public static Boolean CheckOnChat;
public static String KickCommand;
public static Boolean Notify_Warn;
public static Boolean Notify_Sound_Enable;
public static Sound Notify_Sound;
public static String Notify_Sound_input;
public static Boolean Timer_Enable;
public static int RefreshTime;
public static Boolean OP_Whitelist_Enable;
public static Boolean PlayerMustBeOnlineToOp;
public static Boolean no_OP_Player_deop;
public static Boolean sendPlayerDEOPmsg;
public static Boolean no_OP_Player_kick;
public static Boolean customCommand_Enable;
public static List<String> customKickCommand;
public static Boolean Permission_Whitelist_Enable;
public static List<String> Permissions;
public static Boolean PlayerWhithPermission_kick;
public static Boolean Perm_Command_enable;
public static List<String> Perm_Command;
public static Boolean LP_Enable;
public static Boolean LP_AllowFromConsole;
public static List<String> LP_Whitelist;
//help
public static void Help(CommandSender sender) {
sender.sendMessage(Main.Prefix + " §8----- §2OP§4Security §chelp §8-----");
sender.sendMessage(Main.Prefix);
sender.sendMessage(Main.Prefix + " §8'§b/opsecurity reload§8' §eReload the Plugin.");
sender.sendMessage(Main.Prefix + " §8'§b/opsecurity help§8' §eOpens this help.");
sender.sendMessage(Main.Prefix + " §8'§b/opsecurity info§8' §eCall the info about §2OP§4Security§e.");
sender.sendMessage(Main.Prefix);
sender.sendMessage(Main.Prefix + " §8----------------------------");
}
public static void onSelect() {
File configYML = new File(Main.plugin.getDataFolder().getPath(), "config.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(configYML);
Main.opHashMap.clear();
Main.permissionHashMap.clear();
ConfigVersion = yamlConfiguration.getInt("ConfigVersion");
UpdateCheckOnJoin = yamlConfiguration.getBoolean("Plugin.UpdateCheckOnJoin");
language = yamlConfiguration.getString("Plugin.language");
OnlyOPcanUseThePlugin = yamlConfiguration.getBoolean("Plugin.OnlyOPcanUseThePlugin");
CheckOnJoin = yamlConfiguration.getBoolean("Check.OnJoin");
CheckOnInteract = yamlConfiguration.getBoolean("Check.OnInteract");
CheckOnCommand = yamlConfiguration.getBoolean("Check.OnCommand");
CheckOnChat = yamlConfiguration.getBoolean("Check.OnChat");
Timer_Enable = yamlConfiguration.getBoolean("Check.Timer.Enable");
RefreshTime = yamlConfiguration.getInt("Check.Timer.RefreshTime_inSec");
KickCommand = yamlConfiguration.getString("Kick.Command");
Notify_Warn = yamlConfiguration.getBoolean("Notify.JoinWarn.Enable");
Notify_Sound_Enable = yamlConfiguration.getBoolean("Notify.Sound.Enable");
Notify_Sound_input = yamlConfiguration.getString("Notify.Sound.Sound");
OP_Whitelist_Enable = yamlConfiguration.getBoolean("OP_Whitelist.Enable");
PlayerMustBeOnlineToOp = yamlConfiguration.getBoolean("OP_Whitelist.PlayerMustBeOnlineToOp");
ArrayList<PlayerObject> opWhitelist = new ArrayList<>();
for (String key : yamlConfiguration.getConfigurationSection("OP_Whitelist.Whitelist").getKeys(false)) {
PlayerObject player = new PlayerObject(
yamlConfiguration.getString("OP_Whitelist.Whitelist." + key + ".UUID").replace("-",""));
opWhitelist.add(player);
Main.opHashMap.put(key, player);
}
no_OP_Player_deop = yamlConfiguration.getBoolean("OP_Whitelist.noOpPlayerDeop.Enable");
sendPlayerDEOPmsg = yamlConfiguration.getBoolean("OP_Whitelist.noOpPlayerDeop.PlayerSendMessage");
no_OP_Player_kick = yamlConfiguration.getBoolean("OP_Whitelist.noOpPlayerKick.Enable");
customCommand_Enable = yamlConfiguration.getBoolean("OP_Whitelist.customCommands.Enable");
customKickCommand = yamlConfiguration.getStringList("OP_Whitelist.customCommands.Commands");
Permission_Whitelist_Enable = yamlConfiguration.getBoolean("Permission_Whitelist.Enable");
Permissions = yamlConfiguration.getStringList("Permission_Whitelist.Permissions");
ArrayList<PlayerObject> permWhitelist = new ArrayList<>();
for (String key : yamlConfiguration.getConfigurationSection("Permission_Whitelist.Whitelist").getKeys(false)) {
PlayerObject player = new PlayerObject(
yamlConfiguration.getString("Permission_Whitelist.Whitelist." + key + ".UUID").replace("-",""));
permWhitelist.add(player);
Main.permissionHashMap.put(key, player);
}
PlayerWhithPermission_kick = yamlConfiguration.getBoolean("Permission_Whitelist.PlayerWhithPermission_kick");
Perm_Command_enable = yamlConfiguration.getBoolean("Permission_Whitelist.customCommands.Enable");
Perm_Command = yamlConfiguration.getStringList("Permission_Whitelist.customCommands.Commands");
LP_Enable = yamlConfiguration.getBoolean("LuckPerms_Whitelist.Enable");
LP_AllowFromConsole = yamlConfiguration.getBoolean("LuckPerms_Whitelist.AllowFromConsole");
LP_Whitelist = yamlConfiguration.getStringList("LuckPerms_Whitelist.Whitelist");
}
public static void sound() {
String soundNotify;
if (Main.minecraft1_8) {
soundNotify = CreateConfig.Notify_Sound_1_8;
} else if (Main.minecraft1_9 || Main.minecraft1_10 || Main.minecraft1_11 || Main.minecraft1_12) {
soundNotify = CreateConfig.Notify_Sound_1_9_to_1_12;
} else soundNotify = CreateConfig.Notify_Sound_from_1_13;
try {
Sound sound_Notify = Sound.valueOf(Notify_Sound_input);
if (sound_Notify != null) {
Notify_Sound = sound_Notify;
}
} catch (Exception e) {
Bukkit.getConsoleSender().sendMessage("§4\n§4\n§4\n" + SelectMessages.SoundNotFound.replace("[prefix]", Main.Prefix)
.replace("[sound]", "§8PlayerNotFound: §6" + Notify_Sound_input) + "§4\n§4\n§4\n");
Notify_Sound = Sound.valueOf(soundNotify);
}
}
}