public TemporaryWhitelist(String filename, GenericConfig config, String prefix) { super(filename); if (!config.hasKey(prefix.concat("whiteouts"))) { isEnabled = false; setIsOverriden(true); Kikkit.MinecraftLog.info("Couldn't find key: " + prefix.concat("whiteouts")); } else { String[] data = config.getValue(prefix.concat("whiteouts")).split(","); for (String periodString : data) { String[] periodData = periodString.split("-"); if (periodData.length == 2) { WhiteoutPeriod p = new WhiteoutPeriod( fromPeriodDataString(periodData[0].split(":")), fromPeriodDataString(periodData[1].split(":"))); periods.add(p); Kikkit.MinecraftLog.info( "[" + prefix + "] Added period from " + p.Start + " to " + p.End + "."); } } } }
public void load(String groupsConfigFile, String playersConfigFile) { currentGroupFileName = groupsConfigFile; currentPlayerFileName = playersConfigFile; Kikkit.MinecraftLog.info("Loading security"); Kikkit.MinecraftLog.info(" Groups: " + groupsConfigFile); Kikkit.MinecraftLog.info(" Players: " + playersConfigFile); loadGroups(); loadPlayers(); }
private void loadGroups() { FileInputStream inputStream; InputStreamReader reader; Scanner scanner = null; try { inputStream = new FileInputStream(currentGroupFileName); reader = new InputStreamReader(inputStream, "UTF-8"); scanner = new Scanner(reader); String line = ""; while (scanner.hasNextLine()) { line = scanner.nextLine(); // Check for comments. if (line.startsWith("#") || line.startsWith("//")) continue; String[] data = line.split(":"); if (data.length < 2) continue; if (data.length >= 2) { Group newGroup = new Group(data[0]); groups.add(newGroup); newGroup.setColor(ChatColor.getByCode(Integer.parseInt(data[1]))); if (Kikkit.IsDebugging) Kikkit.MinecraftLog.info(" Added group: " + newGroup.getName()); if (data.length > 2) { String[] commands = data[2].split(","); // TODO: Why must we do a foreach here? // Because java doesn't understand IEnumerable for (String str : commands) { if (Kikkit.IsDebugging) Kikkit.MinecraftLog.info(" command: " + str); newGroup.Commands.add(str); } } } } } catch (Exception e) { // TODO Auto-generated catch block // e.printStackTrace(); Kikkit.MinecraftLog.info(e.getMessage()); } finally { if (scanner != null) scanner.close(); } }
public void save() { FileWriter outputFile = null; try { outputFile = new FileWriter(internalFilename, false); // PrintWriter out = new PrintWriter(outputFile); // for(String line : internalList){ for (int i = 0; i < internalList.size(); i++) { // out.println(line); String person = internalList.get(i); outputFile.write(person + "\n"); } } catch (IOException e) { Kikkit.MinecraftLog.info(e.getMessage()); } finally { // TODO: Why do we need to do this? try { if (outputFile != null) outputFile.close(); } catch (Exception ex) { } } }
private void loadPlayers() { FileInputStream inputStream; InputStreamReader reader; Scanner scanner = null; try { inputStream = new FileInputStream(currentPlayerFileName); reader = new InputStreamReader(inputStream, "UTF-8"); scanner = new Scanner(reader); String line = ""; while (scanner.hasNextLine()) { line = scanner.nextLine(); // Check for comments. if (line.startsWith("#") || line.startsWith("//")) continue; String[] data = line.split(":"); if (data.length < 2) continue; if (data.length == 2) { Group group = getGroup(data[1]); if (group == null) { // TODO: Log here continue; } group.Players.add(data[0]); if (Kikkit.IsDebugging) Kikkit.MinecraftLog.info(" Added player to " + group.getName() + ": " + data[0]); } } } catch (Exception e) { // TODO Auto-generated catch block // e.printStackTrace(); Kikkit.MinecraftLog.info(e.getMessage()); } finally { if (scanner != null) scanner.close(); } }
public boolean canUseCommand(String cmd) { for (String command : Commands) { if (Kikkit.IsDebugging) Kikkit.MinecraftLog.info(" internal command check: " + command); if (command.equalsIgnoreCase(cmd) || command.equalsIgnoreCase(ADMIN_OVERRIDE)) return true; } return false; }
public boolean canUseCommand(String player, String command) { if (Kikkit.IsDebugging) Kikkit.MinecraftLog.info("Groups to search: " + groups.size()); for (Group group : groups) { if (Kikkit.IsDebugging) Kikkit.MinecraftLog.info(" canUseCommand is looking at " + group.getName()); boolean ingroup = group.isInGroup(player); boolean canuse = group.canUseCommand(command); if (Kikkit.IsDebugging) { Kikkit.MinecraftLog.info(" isInGroup: " + ingroup); Kikkit.MinecraftLog.info(" canUseCommand: " + canuse); } // if(group.isInGroup(player) && group.canUseCommand(command)) return true; if (ingroup && canuse) return true; } return false; }
private Date fromPeriodDataString(String[] data) { Date date = new Date(); try { date.setHours(Integer.parseInt(data[0])); date.setMinutes(Integer.parseInt(data[1])); } catch (Exception ex) { Kikkit.MinecraftLog.info("There is an error in the whiteout data string."); } finally { } return date; }
public void load(String filename) { try { internalFilename = filename; FileInputStream inputStream = new FileInputStream(filename); InputStreamReader reader = new InputStreamReader(inputStream, "UTF-8"); Scanner scanner = new Scanner(reader); String data = ""; internalList.clear(); while (scanner.hasNextLine()) { data = scanner.nextLine(); internalList.add(data); } Kikkit.MinecraftLog.info("Whitelist Loaded from " + filename); } catch (Exception f) { Kikkit.MinecraftLog.warning("Could not load the whitelist file: " + filename); } finally { } }