Skip to content

Commit

Permalink
Use plugin logger instead of Minecraft logger in README example
Browse files Browse the repository at this point in the history
The JavaPlugin class provides plugins with their own logger via getLogger() which is the preferred means of logging content to the console as it prepends the plugin's name. Using a Logger with the Minecraft prefix is non-descript and poor practice because it will not properly source from where the log message is coming. Beginners should not be given this poor practice as an example.
  • Loading branch information
2008Choco authored and cerealcable committed Aug 16, 2023
1 parent 9520d88 commit 8bad2c4
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ Implementing Vault is quite simple. It requires getting the Economy, Permission,
```java
package com.example.plugin;

import java.util.logging.Logger;

import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
Expand All @@ -82,20 +80,19 @@ import org.bukkit.plugin.java.JavaPlugin;

public class ExamplePlugin extends JavaPlugin {

private static final Logger log = Logger.getLogger("Minecraft");
private static Economy econ = null;
private static Permission perms = null;
private static Chat chat = null;

@Override
public void onDisable() {
log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
getLogger().info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
}

@Override
public void onEnable() {
if (!setupEconomy() ) {
log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
getServer().getPluginManager().disablePlugin(this);
return;
}
Expand Down Expand Up @@ -129,7 +126,7 @@ public class ExamplePlugin extends JavaPlugin {

public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
if(!(sender instanceof Player)) {
log.info("Only players are supported for this Example Plugin, but you should not do this!!!");
getLogger().info("Only players are supported for this Example Plugin, but you should not do this!!!");
return true;
}

Expand Down

0 comments on commit 8bad2c4

Please sign in to comment.