cn.nukkit.utils.MainLogger Java Examples
The following examples show how to use
cn.nukkit.utils.MainLogger.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BanList.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public void load() { this.list = new LinkedHashMap<>(); File file = new File(this.file); try { if (!file.exists()) { file.createNewFile(); this.save(); } else { LinkedList<TreeMap<String, String>> list = new Gson().fromJson(Utils.readFile(this.file), new TypeToken<LinkedList<TreeMap<String, String>>>() { }.getType()); for (TreeMap<String, String> map : list) { BanEntry entry = BanEntry.fromMap(map); this.list.put(entry.getName(), entry); } } } catch (IOException e) { MainLogger.getLogger().error("Could not load ban list: ", e); } }
Example #2
Source File: CraftingManager.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public CraftingManager() { InputStream recipesStream = Server.class.getClassLoader().getResourceAsStream("recipes.json"); if (recipesStream == null) { throw new AssertionError("Unable to find recipes.json"); } Config recipesConfig = new Config(Config.JSON); recipesConfig.load(recipesStream); this.loadRecipes(recipesConfig); String path = Server.getInstance().getDataPath() + "custom_recipes.json"; File filePath = new File(path); if (filePath.exists()) { Config customRecipes = new Config(filePath, Config.JSON); this.loadRecipes(customRecipes); } this.rebuildPacket(); MainLogger.getLogger().info("Loaded " + this.recipes.size() + " recipes."); }
Example #3
Source File: ItemMap.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void setImage(BufferedImage image) { try { if (image.getHeight() != 128 || image.getWidth() != 128) { //resize this.image = new BufferedImage(128, 128, image.getType()); Graphics2D g = this.image.createGraphics(); g.drawImage(image, 0, 0, 128, 128, null); g.dispose(); } else { this.image = image; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(this.image, "png", baos); this.getNamedTag().putByteArray("Colors", baos.toByteArray()); } catch (IOException e) { MainLogger.getLogger().logException(e); } }
Example #4
Source File: Item.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") private static void initCreativeItems() { clearCreativeItems(); Config config = new Config(Config.YAML); config.load(Server.class.getClassLoader().getResourceAsStream("creativeitems.json")); List<Map> list = config.getMapList("items"); for (Map map : list) { try { addCreativeItem(fromJson(map)); } catch (Exception e) { MainLogger.getLogger().logException(e); } } }
Example #5
Source File: PluginManager.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void disablePlugin(Plugin plugin) { if (plugin.isEnabled()) { try { plugin.getPluginLoader().disablePlugin(plugin); } catch (Exception e) { MainLogger logger = this.server.getLogger(); if (logger != null) { logger.logException(e); } } this.server.getScheduler().cancelTask(plugin); HandlerList.unregisterAll(plugin); for (Permission permission : plugin.getDescription().getPermissions()) { this.removePermission(permission); } } }
Example #6
Source File: PluginManager.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void enablePlugin(Plugin plugin) { if (!plugin.isEnabled()) { try { for (Permission permission : plugin.getDescription().getPermissions()) { this.addPermission(permission); } plugin.getPluginLoader().enablePlugin(plugin); } catch (Throwable e) { MainLogger logger = this.server.getLogger(); if (logger != null) { logger.logException(new RuntimeException(e)); } this.disablePlugin(plugin); } } }
Example #7
Source File: BanList.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void save() { this.removeExpired(); try { File file = new File(this.file); if (!file.exists()) { file.createNewFile(); } LinkedList<LinkedHashMap<String, String>> list = new LinkedList<>(); for (BanEntry entry : this.list.values()) { list.add(entry.getMap()); } Utils.writeFile(this.file, new ByteArrayInputStream(new GsonBuilder().setPrettyPrinting().create().toJson(list).getBytes(StandardCharsets.UTF_8))); } catch (IOException e) { MainLogger.getLogger().error("Could not save ban list ", e); } }
Example #8
Source File: BanList.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void load() { this.list = new LinkedHashMap<>(); File file = new File(this.file); try { if (!file.exists()) { file.createNewFile(); this.save(); } else { LinkedList<TreeMap<String, String>> list = new Gson().fromJson(Utils.readFile(this.file), new TypeToken<LinkedList<TreeMap<String, String>>>() { }.getType()); for (TreeMap<String, String> map : list) { BanEntry entry = BanEntry.fromMap(map); this.list.put(entry.getName(), entry); } } } catch (IOException e) { MainLogger.getLogger().error("Could not load ban list: ", e); } }
Example #9
Source File: BanList.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void load() { this.list = new LinkedHashMap<>(); File file = new File(this.file); try { if (!file.exists()) { file.createNewFile(); this.save(); } else { LinkedList<TreeMap<String, String>> list = new Gson().fromJson(Utils.readFile(this.file), new TypeToken<LinkedList<TreeMap<String, String>>>() { }.getType()); for (TreeMap<String, String> map : list) { BanEntry entry = BanEntry.fromMap(map); this.list.put(entry.getName(), entry); } } } catch (IOException e) { MainLogger.getLogger().error("Could not load ban list: ", e); } }
Example #10
Source File: BanList.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void save() { this.removeExpired(); try { File file = new File(this.file); if (!file.exists()) { file.createNewFile(); } LinkedList<LinkedHashMap<String, String>> list = new LinkedList<>(); for (BanEntry entry : this.list.values()) { list.add(entry.getMap()); } Utils.writeFile(this.file, new ByteArrayInputStream(new GsonBuilder().setPrettyPrinting().create().toJson(list).getBytes(StandardCharsets.UTF_8))); } catch (IOException e) { MainLogger.getLogger().error("Could not save ban list ", e); } }
Example #11
Source File: PluginManager.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void enablePlugin(Plugin plugin) { if (!plugin.isEnabled()) { try { for (Permission permission : plugin.getDescription().getPermissions()) { this.addPermission(permission); } plugin.getPluginLoader().enablePlugin(plugin); } catch (Throwable e) { MainLogger logger = this.server.getLogger(); if (logger != null) { logger.logException(new RuntimeException(e)); } this.disablePlugin(plugin); } } }
Example #12
Source File: PluginManager.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void disablePlugin(Plugin plugin) { if (plugin.isEnabled()) { try { plugin.getPluginLoader().disablePlugin(plugin); } catch (Exception e) { MainLogger logger = this.server.getLogger(); if (logger != null) { logger.logException(e); } } this.server.getScheduler().cancelTask(plugin); HandlerList.unregisterAll(plugin); for (Permission permission : plugin.getDescription().getPermissions()) { this.removePermission(permission); } } }
Example #13
Source File: CraftingGrid.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public void removeFromAll(Item item) { int count = item.getCount(); for (int i = 0; i < this.size; i++) { Item target = this.getItem(i); if (target.equals(item, true, false)) { count--; target.count--; this.setItem(i, target); if (count <= 0) break; } } if (count != 0) { MainLogger.getLogger().debug("Unexpected ingredient count (" + count + ") in crafting grid"); } }
Example #14
Source File: CraftingGrid.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void removeFromAll(Item item) { int count = item.getCount(); for (int i = 0; i < this.size; i++) { Item target = this.getItem(i); if (target.equals(item, true, false)) { count--; target.count--; this.setItem(i, target); if (count <= 0) break; } } if (count != 0) { MainLogger.getLogger().debug("Unexpected ingredient count (" + count + ") in crafting grid"); } }
Example #15
Source File: PluginManager.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public void disablePlugin(Plugin plugin) { if (plugin.isEnabled()) { try { plugin.getPluginLoader().disablePlugin(plugin); } catch (Exception e) { MainLogger logger = this.server.getLogger(); if (logger != null) { logger.logException(e); } } this.server.getScheduler().cancelTask(plugin); HandlerList.unregisterAll(plugin); for (Permission permission : plugin.getDescription().getPermissions()) { this.removePermission(permission); } } }
Example #16
Source File: PluginManager.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public void enablePlugin(Plugin plugin) { if (!plugin.isEnabled()) { try { for (Permission permission : plugin.getDescription().getPermissions()) { this.addPermission(permission); } plugin.getPluginLoader().enablePlugin(plugin); } catch (Throwable e) { MainLogger logger = this.server.getLogger(); if (logger != null) { logger.logException(new RuntimeException(e)); } this.disablePlugin(plugin); } } }
Example #17
Source File: BanList.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public void save() { this.removeExpired(); try { File file = new File(this.file); if (!file.exists()) { file.createNewFile(); } LinkedList<LinkedHashMap<String, String>> list = new LinkedList<>(); for (BanEntry entry : this.list.values()) { list.add(entry.getMap()); } Utils.writeFile(this.file, new ByteArrayInputStream(new GsonBuilder().setPrettyPrinting().create().toJson(list).getBytes(StandardCharsets.UTF_8))); } catch (IOException e) { MainLogger.getLogger().error("Could not save ban list ", e); } }
Example #18
Source File: RakNetInterface.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void handleEncapsulated(String identifier, EncapsulatedPacket packet, int flags) { if (this.players.containsKey(identifier)) { DataPacket pk = null; try { if (packet.buffer.length > 0) { if (packet.buffer[0] == PING_DataPacket.ID) { PING_DataPacket pingPacket = new PING_DataPacket(); pingPacket.buffer = packet.buffer; pingPacket.decode(); this.networkLatency.put(identifier, (int) pingPacket.pingID); return; } pk = this.getPacket(packet.buffer); if (pk != null) { pk.decode(); this.players.get(identifier).handleDataPacket(pk); } } } catch (Exception e) { this.server.getLogger().logException(e); if (Nukkit.DEBUG > 1 && pk != null) { MainLogger logger = this.server.getLogger(); // if (logger != null) { logger.debug("Packet " + pk.getClass().getName() + " 0x" + Binary.bytesToHexString(packet.buffer)); //logger.logException(e); // } } if (this.players.containsKey(identifier)) { this.handler.blockAddress(this.players.get(identifier).getAddress(), 5); } } } }
Example #19
Source File: ItemMap.java From Nukkit with GNU General Public License v3.0 | 5 votes |
protected BufferedImage loadImageFromNBT() { try { byte[] data = getNamedTag().getByteArray("Colors"); return ImageIO.read(new ByteArrayInputStream(data)); } catch (IOException e) { MainLogger.getLogger().logException(e); } return null; }
Example #20
Source File: ConsoleCommandSender.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void sendMessage(String message) { message = this.getServer().getLanguage().translateString(message); for (String line : message.trim().split("\n")) { MainLogger.getLogger().info(line); } }
Example #21
Source File: FormattedCommandAlias.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { boolean result = false; ArrayList<String> commands = new ArrayList<>(); for (String formatString : formatStrings) { try { commands.add(buildCommand(formatString, args)); } catch (Exception e) { if (e instanceof IllegalArgumentException) { sender.sendMessage(TextFormat.RED + e.getMessage()); } else { sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.exception")); MainLogger logger = sender.getServer().getLogger(); if (logger != null) { logger.logException(e); } } return false; } } for (String command : commands) { result |= Server.getInstance().dispatchCommand(sender, command); } return result; }
Example #22
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public static Entity createEntity(String name, FullChunk chunk, CompoundTag nbt, Object... args) { Entity entity = null; if (knownEntities.containsKey(name)) { Class<? extends Entity> clazz = knownEntities.get(name); if (clazz == null) { return null; } for (Constructor constructor : clazz.getConstructors()) { if (entity != null) { break; } if (constructor.getParameterCount() != (args == null ? 2 : args.length + 2)) { continue; } try { if (args == null || args.length == 0) { entity = (Entity) constructor.newInstance(chunk, nbt); } else { Object[] objects = new Object[args.length + 2]; objects[0] = chunk; objects[1] = nbt; System.arraycopy(args, 0, objects, 2, args.length); entity = (Entity) constructor.newInstance(objects); } } catch (Exception e) { MainLogger.getLogger().logException(e); } } } return entity; }
Example #23
Source File: StandardMessenger.java From SynapseAPI with GNU General Public License v3.0 | 5 votes |
@Override public void dispatchIncomingMessage(SynapseEntry entry, String channel, byte[] message) { if (message == null) { throw new IllegalArgumentException("Message cannot be null"); } StandardMessenger.validateChannel(channel); Set<PluginMessageListenerRegistration> registrations = this.getIncomingChannelRegistrations(channel); for (PluginMessageListenerRegistration registration : registrations) { try { registration.getListener().onPluginMessageReceived(entry, channel, message); } catch (Throwable t) { MainLogger.getLogger().warning("Could not pass incoming plugin message to " + registration.getPlugin(), t); } } }
Example #24
Source File: SimpleCommandMap.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean dispatch(CommandSender sender, String cmdLine) { ArrayList<String> parsed = parseArguments(cmdLine); if (parsed.size() == 0) { return false; } String sentCommandLabel = parsed.remove(0).toLowerCase(); String[] args = parsed.toArray(new String[parsed.size()]); Command target = this.getCommand(sentCommandLabel); if (target == null) { return false; } target.timing.startTiming(); try { target.execute(sender, sentCommandLabel, args); } catch (Exception e) { sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.exception")); this.server.getLogger().critical(this.server.getLanguage().translateString("nukkit.command.exception", cmdLine, target.toString(), Utils.getExceptionMessage(e))); MainLogger logger = sender.getServer().getLogger(); if (logger != null) { logger.logException(e); } } target.timing.stopTiming(); return true; }
Example #25
Source File: DataPacketEidReplacer.java From SynapseAPI with GNU General Public License v3.0 | 5 votes |
private static EntityMetadata replaceMetadata(EntityMetadata data, long from, long to) { boolean changed = false; for (Integer key : replaceMetadata) { try { EntityData ed = data.get(key); if (ed == null) { continue; } if (ed.getType() != Entity.DATA_TYPE_LONG) { MainLogger.getLogger().info("Wrong entity data type (" + key + ") expected 'Long' got '" + dataTypeToString(ed.getType()) + "'"); continue; } long value = ((LongEntityData) ed).getData(); if (value == from) { if (!changed) { data = cloneMetadata(data); changed = true; } data.putLong(key, to); } } catch (Exception e) { MainLogger.getLogger().error("Exception while replacing metadata '" + key + "'", e); } } if (!changed) return null; return data; }
Example #26
Source File: SimpleCommandMap.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean dispatch(CommandSender sender, String cmdLine) { ArrayList<String> parsed = parseArguments(cmdLine); if (parsed.size() == 0) { return false; } String sentCommandLabel = parsed.remove(0).toLowerCase(); String[] args = parsed.toArray(new String[0]); Command target = this.getCommand(sentCommandLabel); if (target == null) { return false; } target.timing.startTiming(); try { target.execute(sender, sentCommandLabel, args); } catch (Exception e) { sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.exception")); this.server.getLogger().critical(this.server.getLanguage().translateString("nukkit.command.exception", cmdLine, target.toString(), Utils.getExceptionMessage(e))); MainLogger logger = sender.getServer().getLogger(); if (logger != null) { logger.logException(e); } } target.timing.stopTiming(); return true; }
Example #27
Source File: FormattedCommandAlias.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { boolean result = false; ArrayList<String> commands = new ArrayList<>(); for (String formatString : formatStrings) { try { commands.add(buildCommand(formatString, args)); } catch (Exception e) { if (e instanceof IllegalArgumentException) { sender.sendMessage(TextFormat.RED + e.getMessage()); } else { sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.exception")); MainLogger logger = sender.getServer().getLogger(); if (logger != null) { logger.logException(e); } } return false; } } for (String command : commands) { result |= Server.getInstance().dispatchCommand(sender, command); } return result; }
Example #28
Source File: ConsoleCommandSender.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void sendMessage(String message) { message = this.getServer().getLanguage().translateString(message); for (String line : message.trim().split("\n")) { MainLogger.getLogger().info(line); } }
Example #29
Source File: ItemMap.java From Nukkit with GNU General Public License v3.0 | 5 votes |
protected BufferedImage loadImageFromNBT() { try { byte[] data = getNamedTag().getByteArray("Colors"); image = ImageIO.read(new ByteArrayInputStream(data)); return image; } catch (IOException e) { MainLogger.getLogger().logException(e); } return null; }
Example #30
Source File: RakNetInterface.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void handleEncapsulated(String identifier, EncapsulatedPacket packet, int flags) { if (this.players.containsKey(identifier)) { DataPacket pk = null; try { if (packet.buffer.length > 0) { if (packet.buffer[0] == PING_DataPacket.ID) { PING_DataPacket pingPacket = new PING_DataPacket(); pingPacket.buffer = packet.buffer; pingPacket.decode(); this.networkLatency.put(identifier, (int) pingPacket.pingID); return; } pk = this.getPacket(packet.buffer); if (pk != null) { pk.decode(); this.players.get(identifier).handleDataPacket(pk); } } } catch (Exception e) { this.server.getLogger().logException(e); if (Nukkit.DEBUG > 1 && pk != null) { MainLogger logger = this.server.getLogger(); // if (logger != null) { logger.debug("Packet " + pk.getClass().getName() + " 0x" + Binary.bytesToHexString(packet.buffer)); //logger.logException(e); // } } if (this.players.containsKey(identifier)) { this.handler.blockAddress(this.players.get(identifier).getAddress(), 5); } } } }