private void save(LocationManager<T> manager) { try { manager.save(); } catch (IOException e) { logger().warning("Failed to save warps: " + e.getMessage()); } }
public WrappedSpawnManager(File configFile) { configFile.getParentFile().mkdirs(); if (!configFile.exists()) try { configFile.createNewFile(); } catch (IOException e) { CommandBook.logger().log(Level.SEVERE, "CommandBook: Spawn storage file creation error: {0}", e.getMessage()); } config = new YAMLProcessor(configFile, true, YAMLFormat.COMPACT); load(); }
public CSVBanDatabase(File banStorageDir) { storageFile = new File(banStorageDir, "bans.csv"); // Set up an audit trail try { FileHandler handler = new FileHandler( (new File(banStorageDir, "bans.%g.%u.log")).getAbsolutePath() .replace("\\", "/"), true); handler.setFormatter(new Formatter() { @Override public String format(LogRecord record) { return "[" + dateFormat.format(new Date()) + "] " + record.getMessage() + "\r\n"; } }); auditLogger.addHandler(handler); } catch (SecurityException e) { logger().warning("Failed to setup audit log for the " + "CSV ban database: " + e.getMessage()); } catch (IOException e) { logger().warning("Failed to setup audit log for the " + "CSV ban database: " + e.getMessage()); } }
private boolean migrate(String commander, File dest) { boolean result = false; try { // Try to parse the commander as a player's UUID OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(commander)); if (player != null) { // A player was found, see if they have an old file based on their name to migrate File oldUserFile = new File(sessionsDir.getPath() + File.separator + player.getName() + ".yml"); if (oldUserFile.exists()) { // Move the file, and print an error if the move operation failed result = oldUserFile.renameTo(dest); if (!result) { CommandBook.logger().warning("Could not update a player's session file to use UUID: " + commander); } } } } catch (IllegalArgumentException ignored) { } // Wasn't a player return result; }
userFile.createNewFile(); } catch (IOException e) { CommandBook.logger().log(Level.WARNING, "Could not create sessions persistence file for user " + commander, e); processor.load(); } catch (IOException e) { CommandBook.logger().log(Level.WARNING, "Error loading sessions persistence file for user " + commander, e);
private void configureWorldLocks() { if (config.timeLocks != null) { for (Map.Entry<String, Object> entry : config.timeLocks.entrySet()) { int time = 0; try { time = InputUtil.TimeParser.matchMCWorldTime(String.valueOf(entry.getValue())); } catch (CommandException e) { CommandBook.logger().warning("Time lock: Failed to parse time '" + entry.getValue() + "'"); continue; } lockedTimes.put(entry.getKey(), time); World world = CommandBook.server().getWorld(entry.getKey()); if (world == null) { CommandBook.logger().info("Could not time-lock unknown world '" + entry.getKey() + "'"); continue; } world.setTime(time); lock(world); CommandBook.logger().info("Time locked to '" + ChatUtil.getTimeString(time) + "' for world '" + world.getName() + "'"); } } }
@Override public void load(ConfigurationNode node) { super.load(node); boolean error = false; try { pmColor = ChatColor.valueOf(pmColorString); } catch (IllegalArgumentException e) { CommandBook.logger().warning("Unknown PM Color '" + pmColorString + "'! Resetting to GRAY"); pmColor = ChatColor.GRAY; pmColorString = "GRAY"; error = true; } try { pmTextColor = ChatColor.valueOf(pmTextColorString); } catch (IllegalArgumentException e) { CommandBook.logger().warning("Unknown PM Color '" + pmTextColorString + "'! Resetting to GRAY"); pmTextColor = ChatColor.GRAY; pmTextColorString = "GRAY"; error = true; } if (error) { save(node); } } }
kit.setCoolDown((long) (Double.parseDouble(coolDownTime) * 1000)); } catch (NumberFormatException e) { logger().warning("Invalid cool down for " + line); continue; logger().warning("Missing \"[kitname]\" section for " + line); continue; logger().warning(" Unknown kit item '" + parts[0].replaceAll(" ", "") + "'"); continue; item.setAmount(Integer.parseInt(parts[1])); } catch (NumberFormatException e) { logger().warning("Invalid amount: '" + parts[1] + "'"); logger().info(kits.size() + " kit(s) loaded."); } catch (FileNotFoundException ignore) { } catch (UnsupportedEncodingException ignore) { } catch (IOException e) { logger().warning("Failed to load kits.txt: " + e.getMessage()); } finally {
int lineLen = line.length; if (lineLen < 5) { logger().warning("A ban entry with < 5 fields was found!"); continue; UUIDBan.put(ID, ban); } else if (name != null) { logger().finest("Converting " + name + "'s ban record to UUID..."); ID = UUIDUtil.convert(name); if (ID != null) { logger().finest("Success!"); } else { if (nameBan == null) { logger().warning(ban.toString() + " could not be converted!"); } catch (IllegalArgumentException i) { if (i instanceof NumberFormatException) { logger().warning("Non-long long field found in ban!"); } else { logger().warning("Invalid UUID field found in ban!"); logger().info(bans.size() + " banned name(s) loaded."); } catch (FileNotFoundException ignored) { } catch (IOException e) { nameBan = new HashMap<String, Ban>(); ipBan = new HashMap<String, Ban>(); logger().warning("Failed to load " + storageFile.getAbsolutePath()
@EventHandler public void onLogin(PlayerLoginEvent event) { if (!namePattern.matcher(event.getPlayer().getName()).matches()) { CommandBook.logger().info("Name verification: " + event.getPlayer().getName() + " was kicked " + "for having an invalid name (to disable, turn off the name-verification component in CommandBook)"); event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Invalid player name detected!"); } } }
@EventHandler public void onJoin(PlayerJoinEvent event) { MidiJingleSequencer sequencer; try { File file = new File(CommandBook.inst().getDataFolder(), "intro.mid"); if (file.exists()) { sequencer = new MidiJingleSequencer(file, false); getJingleNoteManager().play(event.getPlayer().getName(), sequencer); } } catch (MidiUnavailableException e) { CommandBook.logger().log(Level.WARNING, "Failed to access MIDI: " + e.getMessage()); } catch (InvalidMidiDataException e) { CommandBook.logger().log(Level.WARNING, "Failed to read intro MIDI file: " + e.getMessage()); } catch (FileNotFoundException ignored) { } catch (IOException e) { CommandBook.logger().log(Level.WARNING, "Failed to read intro MIDI file: " + e.getMessage()); } }
public void importFrom(BanDatabase bans) { for (Ban ban : bans) { boolean set = false; if (ban.getID() != null) { set = true; UUIDBan.put(ban.getID(), ban); } if (ban.getAddress() != null && !ban.getAddress().isEmpty()) { set = true; ipBan.put(ban.getAddress(), ban); } if (set) { this.bans.add(ban); } else { logger().warning(ban.toString() + " could not be imported!"); } } }
public RootLocationManager(LocationManagerFactory<LocationManager<T>> factory, boolean perWorld) { this.factory = factory; this.perWorld = perWorld; if (perWorld) { managers = new HashMap<String, LocationManager<T>>(); for (World world : CommandBook.server().getWorlds()) { updateWorlds(world); } } else { rootManager = factory.createManager(); try { rootManager.load(); } catch (IOException e) { logger().warning("Failed to load warps: " + e.getMessage()); } } }
int lineLen = line.length; if (lineLen < 8) { logger().warning(type + " data file has an invalid line with < 8 fields"); } else { try { warp.setCreatorID(UUID.fromString(creator)); } catch (IllegalArgumentException ex) { logger().finest("Converting " + type + " " + name + "'s owner record to UUID..."); UUID creatorID = UUIDUtil.convert(creator); if (creatorID != null) { warp.setCreatorID(creatorID); needsSaved = true; logger().finest("Success!"); } else { warp.setCreatorName(creator); logger().warning(type + " " + name + "'s owner could not be converted!"); logger().warning(type + " data file has an invalid line with an invalid UUID field"); } else { logger().warning(type + " data file has an invalid line with non-numeric numeric fields"); logger().info(locs.size() + " " + type + "(s) loaded for " + castWorld.getName()); } else { logger().info(locs.size() + " " + type + "(s) loaded");
private LocationManager<T> getManager(World world) { if (!perWorld) { return rootManager; } LocationManager<T> manager = managers.get(world.getName()); if (manager != null) { return manager; } manager = factory.createManager(world); manager.castWorld(world); try { manager.load(); } catch (IOException e) { logger().warning("Failed to load warps for world " + world.getName() + ": " + e.getMessage()); } managers.put(world.getName(), manager); return manager; }
writer.close(); } catch (IOException e) { logger().warning("Failed to save " + storageFile.getAbsolutePath() + ": " + e.getMessage()); successful = false;
/** * Loads the configuration. */ @Override public YAMLProcessor createConfiguration() { final File configFile = new File(getDataFolder(), "config.yml"); YAMLProcessor config = new YAMLProcessor(configFile, true, YAMLFormat.EXTENDED); YAMLProcessor comments = new DefaultsFileYAMLProcessor("config-comments.yml", false); try { if (!configFile.exists()) { configFile.getParentFile().mkdirs(); configFile.createNewFile(); } config.load(); comments.load(); } catch (Exception e) { getLogger().log(Level.WARNING, "Error loading configuration: ", e); } for (Map.Entry<String, Object> e : comments.getMap().entrySet()) { if (e.getValue() != null) { config.setComment(e.getKey(), e.getValue().toString()); } } // Migrate the old configuration, if we need to final String result = new LegacyCommandBookConfigurationMigrator(configFile, config).migrate(); if (result != null) { logger().severe("Error migrating CommandBook configuration: " + result); } return config; }
/** * Called when a World is loaded. */ @EventHandler public void onWorldLoad(WorldLoadEvent event) { World world = event.getWorld(); Integer lockedTime = getLockedTimes().get(world.getName()); if (lockedTime != null) { world.setTime(lockedTime); lock(world); CommandBook.logger().info("Time locked to '" + ChatUtil.getTimeString(lockedTime) + "' for world '" + world.getName() + "'"); } }
@Command(aliases = {"reload"}, usage = "", desc = "Reload CommandBook's settings", min = 0, max = 0) @CommandPermissions({"commandbook.reload"}) public static void reload(CommandContext args, CommandSender sender) throws CommandException { try { CommandBook.inst().getGlobalConfiguration().load(); } catch (IOException e) { sender.sendMessage(ChatColor.RED + "Error reolading configuration: " + e.getMessage()); sender.sendMessage(ChatColor.RED + "See console for details!"); CommandBook.logger().log(Level.WARNING, "Error reloading configuration: " + e, e); } CommandBook.inst().loadConfiguration(); CommandBook.inst().getComponentManager().reloadComponents(); sender.sendMessage(ChatColor.YELLOW + "CommandBook's configuration has been reloaded."); }
public void messagePlayer(CommandSender sender, String target, String message) throws CommandException { CommandSender receiver = InputUtil.PlayerParser.matchPlayerOrConsole(sender, target); UserSession receiverSession = sessions.getSession(UserSession.class, receiver); AFKComponent.AFKSession afkSession = sessions.getSession(AFKComponent.AFKSession.class, receiver); if (afkSession.isAFK()) { String status = afkSession.getIdleStatus(); sender.sendMessage(config.pmColor + ChatUtil.toColoredName(receiver, config.pmColor) + " is afk. " + "They might not see your message." + (status.trim().length() == 0 ? "" : " (" + status + ")")); } receiver.sendMessage(config.pmColor + "(From " + ChatUtil.toColoredName(sender, config.pmColor) + "): " + config.pmTextColor + message); sender.sendMessage(config.pmColor + "(To " + ChatUtil.toColoredName(receiver, config.pmColor) + "): " + config.pmTextColor + message); CommandBook.logger().info("(PM) " + ChatUtil.toColoredName(sender, ChatColor.RESET) + " -> " + ChatUtil.toColoredName(receiver, ChatColor.RESET) + ": " + message); sessions.getSession(UserSession.class, sender).setLastRecipient(receiver); // If the receiver hasn't had any player talk to them yet or hasn't // send a message, then we add it to the receiver's last message target // so s/he can /reply easily receiverSession.setNewLastRecipient(sender); }