Jump to content

Help with making Plugin


Recommended Posts

Hello,

I'm trying to make a plugin to delete the bugged Buildcraft pipe each time it appears on console.

Current Code;

import java.util.List;

import java.util.logging.Filter;

import java.util.logging.LogRecord;

import java.util.logging.Logger;

 

import org.bukkit.Bukkit;

import org.bukkit.Location;

import org.bukkit.Material;

import org.bukkit.World;

import org.bukkit.block.Block;

import org.bukkit.plugin.java.JavaPlugin;

 

public class LogFilter implements Filter {

 

    private String pipeBug = "Pipe failed to load from NBT at";

   

    @Override

    public boolean isLoggable(LogRecord record) {

        String message = record.getMessage();

        if(message != null) {

            if(message.contains(pipeBug)) {

                checkPipe(message);

            }

        }

        return true;

    }

   

    public void checkPipe(String message) {

        String[] hold = message.split(" ");

        String[] location = hold[(hold.length - 1)].split(",");

        List<World> worlds = Bukkit.getServer().getWorlds();

       

        int count = 0;

        int countTotal = worlds.size();

       

        while (count < countTotal) {

            Block block = new Location(worlds.get(count), Double.valueOf(location[0]), Double.valueOf(location[1]), Double.valueOf(location[2])).getBlock();

            if(block.getTypeId() == 166) {

                block.breakNaturally();

                count = countTotal;

            }

        }

    }

 

}


 

I've checked that block.breakNaturally() works on bugged Buildcraft pipes by setting up a command that does that on Player.getTargetBlock() and it does work.

 

I've also checked that the bugged .getTypeID is 166.

 

I've tried to check the messages that receives by doing a Broadcast or sending me a message, but it seems to break the whole thing (I also have code that denies "<Player> joined with: [" from being logged and I notice this doesn't work when I try to send any debug messages, whether it be "Bukkit.getServer().getLogger()" or "Logger.getLogger("Minecraft")".

 

On my main Class I've added;


Logger.getLogger("ForgeModLoader").setFilter(new LogFilter());


To filter the "<Player> joined with: [" I also do (in the same class as LogFilter, but I removed the code from above).

 

I've also tried;


        Logger.getLogger("global").setFilter(new LogFilter());

        Logger.getLogger("Patcher").setFilter(new LogFilter());

        Logger.getLogger("").setFilter(new LogFilter());

        Logger.getLogger("Client").setFilter(new LogFilter());


But they also don't seem to pick up Buildcraft log messages ("Pipe failed to load from NBT at").

 

I've done this on onEnable();


        Enumeration<String> cc =LogManager.getLogManager().getLoggerNames();

        while(cc.hasMoreElements()) {

            getLogger().info(Logger.getLogger(cc.nextElement()).getName());

        }


 

And got this list;


Loader

global

sun.net.www.protocol.http.HttpURLConnection

com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource

com.sk89q.minecraft.util.commands.CommandsManager

Client

Minecraft

com.sk89q.wepif.PermissionsResolverManager

Votifier

com.google.common.collect.CustomConcurrentHashMap

com.mchange.v2.log.MLog

com.sk89q.minecraft.util.commands.SimpleInjector

com.enjin.officialplugin.EnjinMinecraftPlugin

Minecraft.WorldEdit

ForgeModLoader

Patcher

 

(Last one is "". If I filter "Minecraft", there is a infinite recursion.)

So I think my question is, what logger do I have to set my Filter to, so I can Filter "Pipe failed to load from NBT at" messages?

Or am I doing something wrong in my approach?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...