/** * Creates a new {@link YamlConfiguration}, loading from the given reader. * <p> * Any errors loading the Configuration will be logged and then ignored. * If the specified input is not a valid config, a blank config will be * returned. * * @param reader input * @return resulting configuration * @throws IllegalArgumentException Thrown if stream is null */ public static YamlConfiguration loadConfiguration(Reader reader) { Validate.notNull(reader, "Stream cannot be null"); YamlConfiguration config = new YamlConfiguration(); try { config.load(reader); } catch (IOException ex) { Bukkit.getLogger().log(Level.SEVERE, "Cannot load configuration from stream", ex); } catch (InvalidConfigurationException ex) { Bukkit.getLogger().log(Level.SEVERE, "Cannot load configuration from stream", ex); } return config; } }
/** * Creates a new {@link YamlConfiguration}, loading from the given file. * <p> * Any errors loading the Configuration will be logged and then ignored. * If the specified input is not a valid config, a blank config will be * returned. * <p> * The encoding used may follow the system dependent default. * * @param file Input file * @return Resulting configuration * @throws IllegalArgumentException Thrown if file is null */ public static YamlConfiguration loadConfiguration(File file) { Validate.notNull(file, "File cannot be null"); YamlConfiguration config = new YamlConfiguration(); try { config.load(file); } catch (FileNotFoundException ex) { } catch (IOException ex) { Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex); } catch (InvalidConfigurationException ex) { Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file , ex); } return config; }
/** * Creates a new {@link YamlConfiguration}, loading from the given stream. * <p> * Any errors loading the Configuration will be logged and then ignored. * If the specified input is not a valid config, a blank config will be * returned. * * @param stream Input stream * @return Resulting configuration * @throws IllegalArgumentException Thrown if stream is null * @deprecated does not properly consider encoding * @see #load(InputStream) * @see #loadConfiguration(Reader) */ @Deprecated public static YamlConfiguration loadConfiguration(InputStream stream) { Validate.notNull(stream, "Stream cannot be null"); YamlConfiguration config = new YamlConfiguration(); try { config.load(stream); } catch (IOException ex) { Bukkit.getLogger().log(Level.SEVERE, "Cannot load configuration from stream", ex); } catch (InvalidConfigurationException ex) { Bukkit.getLogger().log(Level.SEVERE, "Cannot load configuration from stream", ex); } return config; }
/** * Attempt to get the default logger from Bukkit. * @return Bukkit default logger. */ private static Logger tryGetLogger() { try { return Bukkit.getLogger(); } catch (Exception e) { return null; } }
@Override public void log(Level level, String content) { try { Bukkit.getLogger().log(level, "[NoCheatPlus] " + content); } catch (Throwable t) {} } };
private static Logger getBukkitLogger() { try { return Bukkit.getLogger(); } catch (LinkageError e) { return Logger.getLogger("Minecraft"); } }
@Override public void printStackTrace(){ super.printStackTrace(); Bukkit.getLogger().log(Level.WARNING, " Basic format : (addon.yml)"); Bukkit.getLogger().log(Level.WARNING, " main: path.to.your.MainClass"); Bukkit.getLogger().log(Level.WARNING, " name: <NameOfYourModule>"); Bukkit.getLogger().log(Level.WARNING, " authors: <AuthorA> | <AuthorA, AuthorB>"); Bukkit.getLogger().log(Level.WARNING, " version: YourVersion"); } }
public static void debug(String s, long start) { long elapsed = System.currentTimeMillis() - start; if (DEBUG || elapsed > 4) { Bukkit.getLogger().log(Level.INFO, "At {0}. Time since start: {1}ms", new Object[]{s, (elapsed)}); } }
@Override public void closeConnection() { if (connection != null) { try { connection.close(); } catch (SQLException e) { Bukkit.getLogger().severe("Could not close MariaDB database connection"); } } } }
@Override public void onLoad() { Bukkit.getLogger().info("[NoCheatPlus] onLoad: Early set up of static API, configuration, logging."); // Bukkit logger. setupBasics(); }
@Override public void spawnAbandonedTARDIS(Location location) { try { spawnAbandonedTARDIS(location, "BUDGET", PRESET.FACTORY, COMPASS.SOUTH); } catch (TARDISException ex) { Bukkit.getLogger().log(Level.SEVERE, null, ex); } }
@Override @Nonnull public ItemStack getURLSkull(String url) { try { // The "MHF_Question" is here so serialization doesn't cause an NPE return getURLSkull(new URL(url), "MHF_Question", UUID.randomUUID()); } catch (MalformedURLException e) { Bukkit.getLogger().log(Level.WARNING, "Malformed URL: " + url, e); } return new ItemStack(Material.AIR); }
@Override public Connection createConnection() { try { connection = DriverManager.getConnection(connectionUrl, dbSettings.getUsername(), dbSettings.getPassword()); } catch (SQLException e) { Bukkit.getLogger().severe("Could not connect to the database! " + e.getMessage()); } return connection; }
@Override public Connection createConnection() { try { connection = DriverManager.getConnection(connectionUrl, dbSettings.getUsername(), dbSettings.getPassword()); } catch (SQLException e) { Bukkit.getLogger().severe("Could not connect to the database! " + e.getMessage()); } return connection; }
public static FrameType getFromString(String frameType) { if (frameType.equalsIgnoreCase("random")) return FrameType.RANDOM(); else try { return FrameType.valueOf(frameType); } catch (EnumConstantNotPresentException e) { Bukkit.getLogger().info("[AdvancementAPI] Unknown FrameType given. Using default (TASK)"); return FrameType.TASK; } }
/** * Saves the FileConfiguration retrievable by getConfig(). */ public void saveConfig() { try { getConfig().save(new File(dataFolder, ADDON_CONFIG_FILENAME)); } catch (IOException e) { Bukkit.getLogger().severe("Could not save config!"); } }
public static Class<?> getVersionedBukkitClass(String newVersion, String oldVersion) { Class<?> c = getBukkitClass(newVersion); if (c == null) { c = getBukkitClass(oldVersion); if (c == null) { Bukkit.getLogger().warning("Could not bind to " + newVersion + " or " + oldVersion); } } return c; }
@Override public void onEnable() { update.addListener(((oldVal, newVal) -> { Bukkit.getLogger().info("配置项 enableUpdate 的值由 " + oldVal + " 变为了 " + newVal); if (newVal) { Updater.start(); } else { Updater.stop(); } })); }
public void loginOffline() { try { GameProfile profile = connection.getProfile(); profile.setOriginalUUID(networkManager.getSpoofedUUID() != null ? networkManager.getSpoofedUUID() : Profile.generateOfflineModeUUID(profile.getName())); networkManager.getSpoofedProperties().forEach(profile::addProperty); finishLogin(); } catch (Exception exception) { disconnect("Failed to verify username!"); Bukkit.getLogger().log(Level.SEVERE, "Exception verifying " + connection.getProfile().getOriginalName(), exception); } }