@Entity()
@Table(name="seen")
public class PlayerHistoryInfo {
    
    @Id
    public Integer id;

    @NotNull
    @Length(max=25)
    public String nickname;

    @NotNull
    public String text;

    @NotNull
    @Length(max=25)
    public String act;

    @NotNull
    @Length(max=25)
    public String channel;

    @Temporal(TemporalType.TIMESTAMP)
    public Date date;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getAct() {
        return act;
    }

    public void setAct(String act) {
        this.act = act;
    }

    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }
} @Entity()
@Table(name="tcutils_players")
public class PlayerInfo {
    @Id
    public int Id;

    @NotNull
    public String name;

    public String nick;
    
    public Long lastseen;

    public int getId() {
        return Id;
    }

    public void setId(int id) {
        Id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getLastseen() {
        return lastseen;
    }

    public void setLastseen(Long lastseen) {

        this.lastseen = lastseen;
    }

    public String getNick() {
        return nick;
    }

    public void setNick(String nick) {
        this.nick = nick;
    }
} public class CommandException extends Exception {
    public CommandException(String e) {
        super(e);
    }
} public class CommandSenderException extends Exception {
    public CommandSenderException(String e) {
        super(e);
    }
} public class CommandUsageException extends Exception {
    public CommandUsageException(String e) {
        super(e);
    }
} public class PermissionsException extends Exception {
    public PermissionsException(String e) {
        super(e);
    }
} public class LocalPlayer {

    private String name;
    private UUID uuid;
    private Player bukkitPlayer;
    private OfflinePlayer bukkitOfflinePlayer;
    private ChatMode chatMode;
    private boolean afk;
    private int spamcounter;
    private long lastmessagetime;
    private String nick = null;
    private boolean tpOff = false;
    private boolean invisible = false;
    private boolean invisiblePickup = false;
    private String replyTo = null;
    private boolean tntArrow = false;
    private boolean allowedFlight = false;
    private String capeURL = null;
    private String skinURL = null;

    public boolean isInvisible() {
        return this.invisible;
    }

    public boolean isAllowedFlight() {
        return allowedFlight;
    }

    public void setAllowedFlight(boolean hasFlight) {
        this.allowedFlight = hasFlight;
        if(getBukkitPlayer()!=null)
            getBukkitPlayer().setAllowFlight(hasFlight);
    }

    public UUID getUuid() {
        return uuid;
    }

    public void setUuid(UUID uuid) {
        this.uuid = uuid;
    }

    public void setInvisible(boolean state) {
        this.invisible = state;
    }

    public boolean isTpOff() {
        return tpOff;
    }

    public void setTpOff(boolean state) {
        this.tpOff = state;
    }

    public void setInvisiblePickup(boolean state) {
        this.invisiblePickup = state;
    }

    public boolean isTntArrow() {
        return tntArrow;
    }

    public void setTntArrow(boolean tntArrow) {
        this.tntArrow = tntArrow;
    }

    public boolean hasNick() {
        return nick != null;
    }

    public String getNick() {
        return this.nick;
    }

    public String getReplyTo() {
        return replyTo;
    }

    public void setReplyTo(String replyTo) {
        this.replyTo = replyTo;
    }

    public void setNick(String nick) {
        this.nick = nick;
    }

    public OfflinePlayer getBukkitOfflinePlayer() {
        OfflinePlayer op = getBukkitPlayerSafe();
        if(op == null) op = Bukkit.getOfflinePlayer(name);

        return op;
    }

    public Player getBukkitPlayerSafe() {
        if (this.bukkitPlayer == null) {
            Player p = Bukkit.getPlayerExact(name);
            if (p != null) bukkitPlayer = p;
        }
        return bukkitPlayer;
    }

    public Player getBukkitPlayer() {
        return bukkitPlayer;
    }

    public void setBukkitPlayer(Player bukkitPlayer) {
        this.bukkitPlayer = bukkitPlayer;
    }

    public boolean isAfk() {
        return afk;
    }

    public void setAfk(boolean afk) {
        this.afk = afk;
        this.getBukkitPlayerSafe().setSleepingIgnored(afk);
    }

    public long getLastmessagetime() {
        return lastmessagetime;
    }

    public void setLastmessagetime(long lastmessagetime) {
        this.lastmessagetime = lastmessagetime;
    }

    public int getSpamcounter() {
        return spamcounter;
    }

    public void setSpamcounter(int spamcounter) {
        this.spamcounter = spamcounter;
    }

    public String getName() {
        return name;
    }

    public LocalPlayer(Player player) {
        this.bukkitPlayer = player;
        this.name = player.getName();
        this.uuid = player.getUniqueId();
    }

    public LocalPlayer(String name) {
        this.name = name;
    }

    public LocalPlayer(UUID uuid) {
        this.uuid = uuid;
    }

    public LocalPlayer(String name, UUID uuid) {
        this.name = name;
        this.uuid = uuid;
    }

    public ChatMode getChatMode() {
        return chatMode;
    }

    public void setChatMode(ChatMode chatMode) {
        this.chatMode = chatMode;
    }
    
    public void setCapeURL(String URL) {
        this.capeURL = URL;
    }

    public void setSkinURL(String URL) {
        this.skinURL = URL;
    }

    public boolean isInvisiblePickup() {
        return invisiblePickup;
    }

    public String getCapeURL() {
        return this.capeURL;
    }

    public String getSkinURL() {
        return this.skinURL;
    }

    /**
     * Try to resolve a ChatMode and set it
     *
     * @param chathandler The ChatHandler instance
     * @param chatmode    String defining the ChatMode
     * @throws ChatModeException Thrown when either the ChatMode isn't found, or isn't enabled
     */
    public boolean toggleChatMode(ChatHandler chathandler, String chatmode) throws ChatModeException {
        ChatMode cm = null;
        cm = chathandler.getChatMode(chatmode);

        if (cm != null && chathandler.getTCUtilsInstance().check(this.bukkitPlayer, "chat.mode." + chatmode)) {
            this.setChatMode(cm);
            return true;
        }

        return false;
    }
} public final class TamerMode {

    private Boolean state;
    private TamerModes mode;
    private Integer data;

    public static enum TamerModes {
        INFO,
        TAME,
        ANGRY,
        HEAL,
        SIT,
        SETAGE,
        SETAGELOCK,
        NONE
    }

    public TamerMode(Boolean state, TamerModes mode) {
        this.state = state;
        this.mode = mode;
    }

    public Boolean getState() {
        return state;
    }

    public TamerModes getMode() {
        return mode;
    }

    public void setMode(TamerModes mode) {
        this.mode = mode;
    }

    public void setState(Boolean state) {
        this.state = state;
    }

    public Integer getData() {
        return data;
    }

    public void setData(Integer data) {
        this.data = data;
    }
} public final class ArgumentParser {

    private Map<String, Argument> _namedargs;
    private List<Argument> _args;
    private List<String> _flagsUsed;

    public ArgumentParser(String[] args) {
        _namedargs = new HashMap<String, Argument>();
        _args = new ArrayList<Argument>();
        _flagsUsed = new ArrayList<String>();
        int x=0;
        for(String arg: args) {
            if(arg.startsWith("-")) { /* Flag type */
                Argument argument = new Argument(x, arg.substring(1), null);
                argument.setArgType(true);
                if(args.length > x+1) { /* Add the value as well! */
                    argument.setArgvalue(args[x+1]);
                }
                _namedargs.put(argument.getArgname(), argument);
                _args.add(argument);
            } else { /* Possible argname:argvalue type */
                String[] argslist = arg.split("\\:", 2);
                // _args.put(argslist)
                if(argslist.length>1) {
                    argslist[0] = argslist[0].toLowerCase();
                    Argument argument = new Argument(x, argslist[0], argslist[1]);
                    argument.setArgType(false);
                    _namedargs.put(argslist[0], argument);
                    _args.add(argument);
                } else {
                    Argument argument = new Argument(x, null, argslist[0]);
                    _args.add(argument);
                }
            }
            // arglist
            x++;
        }
    }

    public ArgumentParser() { }

    public void setUsed(String argName, boolean state) {
        Argument arg = null;
        // First the named argument map, this is the easiest one.
        arg = _namedargs.get(argName);
        if(arg!=null)  {
            arg.set_used(state);
            if(arg.isArgType()) {
                int pos = arg.getId();
                if(_args.size()>pos+1) _args.get(pos+1).set_used(true);
            }
        }
        // Second the List<Argument> one, this'll require a for loop
        for(int x=0; x<_args.size(); x++) {
            arg = _args.get(x);
            if(arg.getArgname() != null && arg.getArgname().equals(argName)) arg.set_used(state);
            if(arg.isArgType()) {
                if(_args.size()>x+1) _args.get(x+1).set_used(true);
            }
        }
    }

    public int getSize() {
        return _args.size();
    }

    public Object getValue(int pos) {
        if(pos<0)
            return null;
        else if(pos>this.getSize())
            return null;
        else {
            this.setUsed(_args.get(pos).getArgname(), true);
            return _args.get(pos).getArgvalue();
        }
    }

    public Boolean getBoolean(String argname, Boolean defaultval) {
        if(_namedargs.containsKey(argname)) {
            this.setUsed(argname, true);
            return Boolean.parseBoolean((String) _namedargs.get(argname).getArgvalue());
        } else
            return defaultval;
    }

    public Integer getInteger(String argname, Integer defaultval) {
        if(_namedargs.containsKey(argname)) {
            this.setUsed(argname, true);
            return Integer.parseInt((String) _namedargs.get(argname).getArgvalue());
        } else
            return defaultval;
    }

    public Boolean getBoolean(int pos, Boolean defaultval) {
        if(pos >=0 && this.getSize()>pos) {
            this.setUsed(_args.get(pos).getArgname(), true);
            return Boolean.parseBoolean((String) _args.get(pos).getArgvalue());
        } else
            return defaultval;
    }

    public Integer getInteger(int pos, Integer defaultval) {
        if(pos >=0 && this.getSize()>pos) {
            this.setUsed(_args.get(pos).getArgname(), true);
            return Integer.parseInt((String)_args.get(pos).getArgvalue());
        } else
            return defaultval;
    }

    public String getString(int pos, String defaultval) {
        if(pos >=0 && this.getSize()>pos) {
            this.setUsed(_args.get(pos).getArgname(), true);
            return (String)_args.get(pos).getArgvalue();
        } else
            return defaultval;
    }

    public String getString(String argname, String defaultval) {
        if(_namedargs.containsKey(argname)) {
            this.setUsed(argname, true);
            return (String) _namedargs.get(argname).getArgvalue();
        }
        else
            return defaultval;
    }

    public boolean is_Flag(Argument arg) {
        boolean flag = false;
        int pos = arg.getId();
        if(pos < _args.size()) {
            if(arg.isArgType()) flag = true;
        }
        if(!flag && pos > 0) {
            if(_args.get(pos-1).isArgType()) flag = true;
        }
        return flag;
    }

    public List<Argument> getDefaultArguments() {
        List<Argument> vals = new ArrayList<Argument>();
        for(Argument arg: _args) {
            if(!is_Flag(arg) && arg.getArgname() == null)
                vals.add(arg);
        }
        return vals;
    }

    public List<Argument> getUnusedArgsList() {
        List<Argument> vals = new ArrayList<Argument>();
        for(Argument arg : _args) {
            if(is_Flag(arg) && !arg.is_used()) {
                vals.add(arg);
            } else if(arg.getArgname()==null || !arg.is_used())
                vals.add(arg);
        }
        return vals;
    }

    public boolean isflagUsed(String needle) { /* Reserved for simple flag checking */
        for(Argument arg : _args) {
            String lookFor = null;
            if(arg.isArgType())
                if(arg.getArgname().equals(needle)) {
                    _flagsUsed.add(needle);
                    return true;
                }
        }
        return false;
    }

    public String[] getUnusedArgs() {
        // return (String[]) this.getUnusedArgsList().toArray();
        List<Argument> als = this.getUnusedArgsList();
        // String[] args = new String[als.size()];
        List<String> args = new ArrayList<String>();
        int x=0;
        while(x<als.size()) {
            String tmp = "";
            Argument arg = als.get(x);
            if(is_Flag(arg)) {
                boolean flagUsed = false;
                if(arg.getArgname()!=null) {
                    flagUsed =  _flagsUsed.contains(arg.getArgname());
                    if(!flagUsed) { args.add("-"+arg.getArgname()); }
                }
                if(arg.getArgvalue()!=null) { x++; tmp+=(String)arg.getArgvalue(); args.add(tmp); }
            } else {
                if(arg.getArgname()!=null) { tmp+=arg.getArgname()+":"; }
                if(arg.getArgvalue()!=null) tmp+=(String)arg.getArgvalue();
                args.add(tmp);
            }
            x++;
        }
        return args.toArray(new String[args.size()]);
    }

    public String[] getNormalArgs() {
        List<Argument> al = this.getDefaultArguments();
        String[] lijst = new String[al.size()];
        for(int x=0;x<al.size();x++) {
            lijst[x]=(String)al.get(x).getArgvalue();
        }
        return lijst;
    }

} public class TamerTool {

    private TweakcraftUtils plugin;
    private Map<Player, TamerMode> tamers = new HashMap<Player, TamerMode>();

    public TamerTool(TweakcraftUtils instance) {
        this.plugin = instance;
    }

    public Map<Player, TamerMode> getTamers() {
        return tamers;
    }

    public void getOwner(Player player, Tameable tameable) {
        String className = tameable.getClass().getCanonicalName().split("Craft")[1];
        if (className.equals("Ocelot")) className = "Ozelot";
        if (className.equals("Horse")) className = "EntityHorse";
        EntityType entityType = EntityType.fromName(className);

        String cname = entityType.getName().toLowerCase();

        player.sendMessage(ChatColor.AQUA + "Tameable type : " + cname);

        if (tameable.isTamed()) {
            AnimalTamer tamer = tameable.getOwner();
            if (tamer instanceof Player || tamer instanceof OfflinePlayer) {
                // Player ptamer = (Player) tamer;
                boolean online = false;
                Player ptamer = null;
                OfflinePlayer offlinetamer = null;
                if (tamer instanceof Player) {
                    ptamer = (Player) tamer;
                    online = true;
                } else {
                    offlinetamer = (OfflinePlayer) tamer;
                    online = false;
                }

                boolean allowed = true;
                if (online && !ptamer.equals(player)) {
                    if (!plugin.check(player, "tamer.info.other"))
                        allowed = false;
                }
                if (allowed) {
                    player.sendMessage(ChatColor.AQUA + "Tameable owner : " + (online ? ptamer.getDisplayName() : offlinetamer.getName()));
                } else {
                    player.sendMessage(ChatColor.RED + "You do not have the permission to check the ownership of other wolves!");
                }
            } else {
                player.sendMessage(ChatColor.AQUA + "This tameable is owned by an entity/offline player!");
            }
        } else {
            player.sendMessage(ChatColor.AQUA + "This tameable isn't tamed!");
        }
        player.sendMessage(ChatColor.AQUA + "Tameable health : " + ((LivingEntity) tameable).getHealth());
        if (tameable instanceof Ageable) {
            player.sendMessage(ChatColor.AQUA + "Tameable age : " + ((Ageable) tameable).getAge() + (((Ageable) tameable).getAgeLock() ? ChatColor.RED + " L" : ""));
        }
        if (tameable instanceof Ocelot) {
            player.sendMessage(ChatColor.AQUA + "Tameable cat-type : " + ((Ocelot) tameable).getCatType().toString().toLowerCase());
        }
        if (tameable instanceof Horse) {
            Horse horse = (Horse) tameable;

            player.sendMessage(ChatColor.AQUA + "Tameable color : " + horse.getColor().toString().toLowerCase());
            player.sendMessage(ChatColor.AQUA + "Tameable style : " + horse.getStyle().toString().toLowerCase());
            player.sendMessage(ChatColor.AQUA + "Tameable variant : " + horse.getVariant().toString().toLowerCase());
            player.sendMessage(ChatColor.AQUA + "Tameable jumpstrength : " + horse.getJumpStrength());
            player.sendMessage(ChatColor.AQUA + "Tameable domestication : " + horse.getDomestication());
            player.sendMessage(ChatColor.AQUA + "Tameable maxdomestication : " + horse.getMaxDomestication());
        }
        if (tameable instanceof Wolf) {
            Wolf wolf = (Wolf) tameable;
            if (wolf.isAngry()) {
                player.sendMessage(ChatColor.AQUA + "This tameable is " + ChatColor.RED + "angry" + ChatColor.AQUA + "!");
                LivingEntity le = wolf.getTarget();
                String target = "";
                if (le instanceof OfflinePlayer)
                    if (((OfflinePlayer) le).isOnline())
                        target = ((Player) le).getDisplayName();
                    else
                        target = ((OfflinePlayer) le).getName();
                else {
                    String extraInfo = "";
                    if (le != null) {
                        EntityType et = le.getType();
                        extraInfo = et.getName();
                    }
                    target = "Animal " + extraInfo;// +le!=null?" ("+(et.getName())+")":"";
                }
                player.sendMessage(ChatColor.AQUA + "Target : " + target);
            }
        }
    }

    public void setTame(Tameable tameable, Boolean tame, Player player) {
        if (plugin.check(player, "tamer.tame")) {
            Boolean allowed = true;
            if (tame == null) {
                tame = !tameable.isTamed();
            }
            if (tameable.isTamed() && !tame) {
                AnimalTamer tamer = tameable.getOwner();

                if (tamer instanceof Player) {
                    if (!((Player) tamer).equals(player)) {
                        if (!plugin.check(player, "tamer.tame.untame.other"))
                            allowed = false;
                    } else {
                        if (!plugin.check(player, "tamer.tame.untame.own"))
                            allowed = false;
                    }
                }
                if (allowed) {
                    tameable.setOwner(null);
                    tameable.setTamed(false);
                } else {
                    player.sendMessage(ChatColor.RED + "You do not have permission to untame this tameables!");
                }
            } else if (!tameable.isTamed() && tame) {
                if (!plugin.check(player, "tamer.tame.tame"))
                    allowed = false;

                if (allowed) {
                    tameable.setTamed(true);
                    if (tameable instanceof Wolf) {
                        ((Wolf) tameable).setAngry(false);
                    }
                    ((Creature) tameable).setTarget(null);

                    tameable.setOwner(player);
                } else {
                    player.sendMessage(ChatColor.RED + "You do not have permission to tame this tameables!");
                }
            }
        } else {
            player.sendMessage(ChatColor.RED + "You do not have permission to tame tameables!");
        }
    }

    public void setAngry(Tameable tameable, Boolean angry, Player player) {
        if (plugin.check(player, "tamer.angry")) {
            if (tameable instanceof Wolf) {
                Wolf wolf = (Wolf) tameable;
                Boolean allowed = true;
                if (tameable.isTamed()) {
                    if (tameable.getOwner().equals(player)) {
                        if (!plugin.check(player, "tamer.angry.own"))
                            allowed = false;
                    } else {
                        if (!plugin.check(player, "tamer.angry.other"))
                            allowed = false;
                    }

                }
                if (angry == null) {
                    angry = !wolf.isAngry();
                }
                if (allowed) {
                    wolf.setAngry(angry);

                    if (!angry) {
                        wolf.setTarget(null);
                    }
                } else {
                    player.sendMessage(ChatColor.RED + "You do not have permission to anger this tameables!");
                }
            } else {
                player.sendMessage(ChatColor.RED + "You can't anger anything else than wolves!");
            }
        } else {
            player.sendMessage(ChatColor.RED + "You do not have permission to anger tameables!");
        }
    }

    public void sit(Tameable tameable, Boolean sit, Player player) {
        if (plugin.check(player, "tamer.sit")) {
            Boolean allowed = true;

            Boolean sitting = tameable instanceof Ocelot ? ((Ocelot) tameable).isSitting() :
                tameable instanceof Wolf && ((Wolf) tameable).isSitting();


            if (sitting) {
                if (tameable.getOwner() != null && tameable.getOwner().equals(player)) {
                    if (!plugin.check(player, "tamer.sit.own"))
                        allowed = false;
                } else {
                    if (!plugin.check(player, "tamer.sit.other"))
                        allowed = false;
                }
            } else {
                if (!plugin.check(player, "tamer.sit.wild"))
                    allowed = false;
            }
            if (sit == null)
                sit = !sitting;

            if (allowed) {
                if (tameable instanceof Wolf)
                    ((Wolf) tameable).setSitting(sit);
                if (tameable instanceof Ocelot)
                    ((Ocelot) tameable).setSitting(sit);
            } else
                player.sendMessage(ChatColor.RED + "You do not have permission to command this tameables!");
        } else {
            player.sendMessage(ChatColor.RED + "You do not have permission to command tameables!");
        }
    }

    public void heal(Tameable tameable, Boolean kill, Player player) {
        if (plugin.check(player, "tamer.heal")) {
            Boolean allowed = true;
            if (tameable.isTamed()) {
                if (tameable.getOwner() != null && tameable.getOwner().equals(player)) {
                    if (!plugin.check(player, "tamer.heal.own"))
                        allowed = false;
                } else {
                    if (!plugin.check(player, "tamer.heal.other"))
                        allowed = false;
                }
            } else {
                if (!plugin.check(player, "tamer.heal.wild"))
                    allowed = false;
            }

            if (allowed)
                ((LivingEntity) tameable).setHealth(((LivingEntity) tameable).getMaxHealth());
            else
                player.sendMessage(ChatColor.RED + "You do not have permission to heal this tameables!");
        } else {
            player.sendMessage(ChatColor.RED + "You do not have permission to heal tameables!");
        }
    }

    public void setAge(Tameable tameable, Integer age, Player player) {
        if (plugin.check(player, "tamer.setage")) {
            if (tameable instanceof Ageable) ((Ageable) tameable).setAge(age);
        }
    }

    public void setAgeLock(Tameable tameable, Boolean lock, Player player) {
        if (plugin.check(player, "tamer.setage")) {
            if (tameable instanceof Ageable) {
                player.sendMessage(ChatColor.BLUE + "Setting animal agelock to " + lock);
                ((Ageable) tameable).setAgeLock(lock);
            }
        }
    }

    public void handleEvent(Player player, Tameable tameable) {
        if (!tamers.containsKey(player))
            return;

        TamerMode tamermode = tamers.get(player);
        switch (tamermode.getMode()) {
            case INFO:
                this.getOwner(player, tameable);
                break;
            case TAME:
                this.setTame(tameable, tamermode.getState(), player);
                break;
            case ANGRY:
                this.setAngry(tameable, tamermode.getState(), player);
                break;
            case SIT:
                this.sit(tameable, tamermode.getState(), player);
                break;
            case HEAL:
                this.heal(tameable, tamermode.getState(), player);
                break;
            case SETAGELOCK:
                this.setAgeLock(tameable, tamermode.getState(), player);
                break;
            case SETAGE:
                this.setAge(tameable, tamermode.getData(), player);
                break;
        }
    }
} public class TweakcraftUtils extends JavaPlugin {

    protected WorldGuardPlugin wg = null;
    protected CraftIRC circ = null;
    protected Zones zones = null;
    protected LogBlock lb = null;
    protected WorldEditPlugin we = null;
    // protected TCUtilsClientBridgePlugin tcUtilsClientBridgePlugin = null;
    // protected NoLagg nolagg = null;
    // protected PermissionHandler ph = null;

    private final TweakcraftPlayerListener playerListener = new TweakcraftPlayerListener(this);
    private final TweakcraftEntityListener entityListener = new TweakcraftEntityListener(this);
    private final TweakcraftBlockListener blockListener = new TweakcraftBlockListener(this);
    private final TweakcraftWorldListener worldListener = new TweakcraftWorldListener(this);
    private final CommandHandler commandHandler = new CommandHandler(this);
    private final BanHandler banhandler = new BanHandler(this);
    private final ItemDB itemDB = new ItemDB(this);
    private final WorldManager worldmanager = new WorldManager(this);
    private final ConfigurationHandler configHandler = new ConfigurationHandler(this);
    private final TeleportHistory telehistory = new TeleportHistory(this);
    private final TamerTool tamertool = new TamerTool(this);
    private final ChatHandler chathandler = new ChatHandler(this);
    private final PermissionsResolver permsResolver = new PermissionsResolver(this);

    private final UUIDResolver uuidResolver = new UUIDResolver(this);

    private HashMap<String, LocalPlayer> localPlayers = new HashMap<String, LocalPlayer>();

    private Object circendpoint = null;
    private Object cirdlogendpoint = null;
    private Object circadminendpoint = null;

    private Set<String> donottplist;
    private List<String> MOTDLines;

    protected PluginDescriptionFile pdfFile = null;

    private Set<Player> cuiPlayers;
    public String CUIPattern = "§7§3§3§4";

    private Set<Player> mod_InfDuraplayers;
    public String ToolDuraPattern = "§1§1§1§1";

    public static TweakcraftUtils instance = null;

    public Map<String, String> playerReplyDB;
    public boolean databaseloaded = false;

    public boolean isServerInOnlineMode = false;


    public Set<Player> getMod_InfDuraplayers() {
        return mod_InfDuraplayers;
    }

    public PermissionsResolver getPermissions() {
        return this.permsResolver;
    }

    public Permissions getPermissionsResolver() {
        return this.getPermissions().getResolver();
    }

    public Set<Player> getCUIPlayers() {
        return cuiPlayers;
    }

    public static TweakcraftUtils getInstance() {
        /* Do not create a new instance, could be dangerous!
         * It'll get set at the onEnable() method!
         */
        /* if(instance==null)
            instance = new TweakcraftUtils(); */

        return instance;
    }

    public void sendCUIChatMode(Player player) {
        if (this.cuiPlayers != null && this.cuiPlayers.contains(player)) {
            ChatMode cm = getChathandler().getPlayerChatMode(player);

            if (cm == null)
                player.sendRawMessage(CUIPattern + "null");
            else
                player.sendRawMessage(CUIPattern + "[" + cm.getPrefix() + "]");
        }
        /* if(tcUtilsClientBridgePlugin != null)
            tcUtilsClientBridgePlugin.sendChatMode(player); */
        TweakcraftUtilsEvent event = new TweakcraftUtilsEvent(TweakcraftUtilsEvent.Action.CHATMODE_CHANGED);
        event.setPlayer(wrapPlayer(player));
        this.getServer().getPluginManager().callEvent(event);
    }

    public LocalPlayer wrapPlayer(Player player) {
        LocalPlayer p = this.wrapPlayer(player.getName());
        if (p.getBukkitPlayer() == null || p.getBukkitPlayer() != player)
            p.setBukkitPlayer(player);

        if(isServerInOnlineMode && p.getUuid() == null)
            p.setUuid(player.getUniqueId());

        return p;
    }

    public LocalPlayer wrapPlayer(String player) {
        if (!this.localPlayers.containsKey(player.toLowerCase()))
            this.localPlayers.put(player.toLowerCase(), new LocalPlayer(player));

        return this.localPlayers.get(player.toLowerCase());
    }

    public void sendCUIHandShake(Player player) {
        if (getConfigHandler().enableCUI) {
            player.sendRawMessage(CUIPattern); // HANDSHAKE
        }
    }

    public UUIDResolver getUUIDResolver() {
        return uuidResolver;
    }

    /**
     * Send the player a mod_InfDura string, setting the new ToolDurabilty mode
     *
     * @param player The player to send the mode to
     */
    public void sendToolDuraMode(Player player) {
        this.sendToolDuraMode(player, player.getWorld());
    }

    /**
     * Send the player a mod_InfDura string, setting the new ToolDurabilty mode
     *
     * @param player The player to send the mode to
     * @param world  The world to check the ToolDurability mode
     */
    public void sendToolDuraMode(Player player, World world) {
        if (getConfigHandler().enablemod_InfDura && mod_InfDuraplayers.contains(player)) {
            player.sendRawMessage(ToolDuraPattern + world.getToolDurability());
        }
        /* if(tcUtilsClientBridgePlugin != null)
            tcUtilsClientBridgePlugin.getPlayerListener().sendToolDuraMode(player, world); */

    }

    /**
     * Send the specified player the mod_InfDura handshake
     *
     * @param player The player that will receive the initiation
     */
    public void sendmod_InfDuraHandshake(Player player) {
        if (getConfigHandler().enablemod_InfDura) {
            player.sendRawMessage(ToolDuraPattern);
        }
    }

    public String findinlist(String find, Set<String> list) {
        for (String name : list) {
            if (name.toLowerCase().contains(find.toLowerCase())) {
                return name;
            }
        }
        return null;
    }

    /**
     * Get the Teleport History tool
     *
     * @return TeleportHistory instance
     */
    public TeleportHistory getTelehistory() {
        return telehistory;
    }

    /**
     * Get the PlayerListener instance
     *
     * @return TweakcraftUtils's PlayerListener instance
     */
    public TweakcraftPlayerListener getPlayerListener() {
        return playerListener;
    }

    /**
     * Get the ItemDB instance
     *
     * @return ItemDB instance
     */
    public ItemDB getItemDB() {
        return itemDB;
    }

    /**
     * Get the WorldManager instance
     *
     * @return WorldManager instance
     */
    public WorldManager getworldManager() {
        return worldmanager;
    }

    /**
     * Get the TamerTool tool instance
     *
     * @return TamerTool instance
     */
    public TamerTool getTamerTool() {
        return tamertool;
    }

    public String getCompassDirection(Float rotation) {
        String dir = null;
        Float rot = (rotation - 90) % 360;
        if (rot < 0) {
            rot += 360;
        }
        Integer r = rot.intValue();

        if (r < 23)
            dir = "N";
        else if (r < 68)
            dir = "NE";
        else if (r < 113)
            dir = "E";
        else if (r < 158)
            dir = "SE";
        else if (r < 203)
            dir = "S";
        else if (r < 248)
            dir = "SW";
        else if (r < 293)
            dir = "W";
        else if (r < 338)
            dir = "NW";
        else
            dir = "N";

        return dir;
    }

    @Override
    public List<Class<?>> getDatabaseClasses() {
        List<Class<?>> list = new ArrayList<Class<?>>();
        list.add(PlayerInfo.class);
        list.add(PlayerHistoryInfo.class);
        list.add(PlayerOptions.class);
        return list;
    }

    public void setupDatabase() {
        try {
            getDatabase().find(PlayerInfo.class).findRowCount();
            getDatabase().find(PlayerOptions.class).findRowCount();
            if (configHandler.useTweakBotSeen)
                getDatabase().find(PlayerHistoryInfo.class).findRowCount();
        } catch (PersistenceException ex) {
            this.getLogger().info("Installing database for " + getDescription().getName() + " due to first time usage");
            if (configHandler.useTweakBotSeen)
                this.getLogger().info("Also creating the TweakBot !seen helpen table");
            installDDL();
        }
        databaseloaded = true;
    }

    public String listToString(List<String> lijst) {
        StringBuilder builder = new StringBuilder();
        int c = 0;
        if (lijst.size() != 0) {
            while (c < lijst.size()) {
                builder.append(lijst.get(c));
                if (c != lijst.size() - 1) builder.append(",");
                c++;
            }
        }
        return builder.toString();
    }

    private List<String> toList(String str) {
        List<String> result = new ArrayList<String>();
        try {
            String[] names = str.split(",");
            for (String n : names)
                result.add(n.trim());

        } catch (NullPointerException e) {
            // result = new ArrayList<String>();
        }
        return result;
    }

    public static List<Player> findPlayerByNick(String part) {
        /* return  getPlayerListener().findPlayerNameByNick(part); */
        if (getInstance() != null)
            return getInstance().findPlayerasPlayerList(part);
        else
            return null;
    }

    public static List<String> findPlayerByNick_string(String part) {
        if (getInstance() != null) {
            List<Player> lijst = getInstance().findPlayerasPlayerList(part);
            List<String> userList = new ArrayList<String>();
            if(lijst.size()>0) {
                for(Player p : lijst) {
                    userList.add(p.getName());
                }
            }
            return userList;
        } else
            return null;
    }

    public Player findPlayerasPlayer(String partOfName) {
        // Go for the nicks first!
        Player nick = playerListener.findPlayerByNick(partOfName);
        if (nick == null) {
            for (Player p : this.getServer().getOnlinePlayers()) {
                if (p.getName().toLowerCase().contains(partOfName.toLowerCase())) // found, return the fullname!
                    return p;
            }
        }

        // not found, just return partOfName
        return nick;
    }

    public Player getPlayer(String nick, boolean findNick) {
        Player p = findNick ? getPlayerByNick(nick) : null;
        if (p == null) p = this.getServer().getPlayerExact(nick);
        return p;
    }

    public Player getPlayerByNick(String nick) {
        return playerListener.findPlayerByNick(nick, true);
    }

    public List<Player> findPlayerasPlayerList(String partOfName) {
        // Go for the nicks first!
        List<Player> players = playerListener.findPlayersByNick(partOfName);
        for (Player p : this.getServer().getOnlinePlayers()) {
            if (p.getName().toLowerCase().contains(partOfName.toLowerCase())
                && !players.contains(p)) // found, return the fullname!
                players.add(p);
        }
        return players;
    }


    public String findPlayer(String partOfName) {
        // Go for the nicks first!
        for (Player p : this.getServer().getOnlinePlayers()) {
            if (p.getName().toLowerCase().contains(partOfName.toLowerCase())) // found, return the fullname!
                return p.getName();
        }
        // not found, just return partOfName
        return partOfName;
    }


    /**
     * Register the Bukkit events to the appropriate event handlers.
     */
    private void registerEvents() {
        PluginManager manager = getServer().getPluginManager();

        manager.registerEvents(playerListener, this);
        manager.registerEvents(entityListener, this);
        manager.registerEvents(blockListener, this);
        manager.registerEvents(worldListener, this);
    }

    public TweakcraftWorldListener getWorldListener() {
        return worldListener;
    }

    public List<String> getMOTD() {
        return MOTDLines;
    }

    public CraftIRC getCraftIRC() {
        return circ;
    }

    public WorldEditPlugin getWorldEdit() {
        return we;
    }

    public WorldGuardPlugin getWorldGuard() {
        return wg;
    }

    public String getPlayerColor(String playername) {
        return this.getPlayerColor(playername, false);
    }

    public String getPlayerColor(String playername, boolean change) {
        String pref = "";
        Player p = null;
        try {
            p = this.getServer().getPlayerExact(playername);
            pref = this.getPermissions().getResolver().getUserPrefix(p.getWorld().getName(), p);
        } catch (NullPointerException e) {
            pref = "§f";
        }
        String col = ChatColor.WHITE.toString();
        if (p == null && change) col = ChatColor.AQUA + "[NC] " + pref;
        if (p != null) col += pref;
        return col;

    }

    public ChatHandler getChathandler() {
        return this.chathandler;
    }

    @Deprecated
    public static List<String> splitUp(String msg) {
        int maxlength = 55;
        List<String> lijst = new ArrayList<String>();
        String toadd;
        int x = 0;
        while (x < msg.length() - maxlength) {
            toadd = msg.substring(x, x + maxlength);
            if (!toadd.trim().equals(""))
                lijst.add(toadd.trim());
            x += maxlength;
        }
        lijst.add(msg.substring(x));

        return lijst;
    }


    public void setupCraftIRC() {
        if (this.getConfigHandler().enableIRC) {
            Plugin plugin = this.getServer().getPluginManager().getPlugin("CraftIRC");

            if (circ == null) {
                if (plugin != null) {
                    circ = (CraftIRC) plugin;
                } else {
                    this.getConfigHandler().enableIRC = false;
                    this.getLogger().warning("WARNING: Couldn't find CraftIRC, but is enabled in the config.");
                    this.getLogger().warning("WARNING: Disabling CraftIRC support.");
                }
            }
        }
    }

    public void setupWorldGuard() {
        if (this.getConfigHandler().enableWorldGuard) {
            Plugin plugin = this.getServer().getPluginManager().getPlugin("WorldGuard");

            if (wg == null) {
                if (plugin != null) {
                    wg = (WorldGuardPlugin) plugin;
                } else {
                    this.getConfigHandler().enableWorldGuard = false;
                    this.getLogger().warning("WARNING: Couldn't find WorldGuard, but is enabled in the config.");
                    this.getLogger().warning("WARNING: Disabling WorldGuard support.");
                }
            }
        }
    }

    public void setupZones() {
        if (this.getConfigHandler().enableZones) {
            Plugin plugin = this.getServer().getPluginManager().getPlugin("Zones");

            if (zones == null) {
                if (plugin != null) {
                    zones = (Zones) plugin;
                } else {
                    this.getConfigHandler().enableZones = false;
                    this.getLogger().warning("WARNING: Couldn't find Zones, but is enabled in the config.");
                    this.getLogger().warning("WARNING: Disabling Zones support.");
                }
            }
        }
    }

    public void setupLogBlock() {
        if (this.getConfigHandler().enableLogBlock) {
            Plugin plugin = this.getServer().getPluginManager().getPlugin("LogBlock");

            if (lb == null) {
                if (plugin != null) {
                    lb = (LogBlock) plugin;
                } else {
                    this.getConfigHandler().enableLogBlock = false;
                    this.getLogger().warning("WARNING: Couldn't find LogBlock, but is enabled in the config.");
                    this.getLogger().warning("WARNING: Disabling LogBlock support.");
                }
            }
        }
    }

    public void setupWorldEdit() {
        Plugin plugin = this.getServer().getPluginManager().getPlugin("WorldEdit");

        if (we == null) {
            if (plugin != null) {
                we = (WorldEditPlugin) plugin;
            } /* We don't care if it failed because it's mostly a fallback for permissions. */
        }
    }

    public Zones getZones() {
        return zones;
    }

    public LogBlock getLogBlock() {
        return lb;
    }

    public void reloadMOTD() {
        File motdfile = new File(this.getDataFolder(), "motd.txt");
        MOTDLines = new ArrayList<String>();
        try {
            BufferedReader motdfilereader = new BufferedReader(new FileReader(motdfile));
            String line = "";
            while ((line = motdfilereader.readLine()) != null) {
                MOTDLines.add(line.replace('&', '§'));
            }
            motdfilereader.close();
        } catch (FileNotFoundException e) {
            this.getLogger().severe("MOTD file not found!");
        } catch (IOException e) {
            this.getLogger().severe("IOException occured while loadign the MOTD file!");
        }

    }

    public CommandHandler getCommandHandler() {
        return commandHandler;
    }

    public String getNickWithColors(String player) {
        String nick = this.wrapPlayer(player).getNick();

        String realname = player;
        if (nick == null) nick = realname;

        /// return getPlayerColor(realname, false) + nick + ChatColor.WHITE;
        return this.getPermissions().getResolver().getUserPrefix(player) + nick + ChatColor.WHITE;
    }

    public String getNick(String player) {
        String nick = playerListener.getNick(player);
        String realname = player;
        if (nick == null) nick = realname;
        return nick;
    }

    public boolean check(CommandSender sender, String permNode) {
        return !(sender instanceof Player) || this.check(((Player) sender), permNode);
    }

    public boolean check(Player player, String permNode) {
        return player.isOp() ||
            this.getPermissions().hasPermission(player.getWorld().getName(), player, "tweakcraftutils." + permNode);
    }

    public boolean checkfull(Player player, String permNode) {
        return player.isOp() ||
            this.getPermissions().getResolver().hasPermission(player.getWorld().getName(), player, permNode);
    }

    public BanHandler getBanhandler() {
        return banhandler;
    }

    public boolean hasNick(String player) {
        return playerListener.getNick(player) != null;
    }


    @Override
    public void onEnable() {
        pdfFile = this.getDescription();
        instance = this;

        // Check for "online mode", for UUID safety
        isServerInOnlineMode = this.getServer().getOnlineMode();

        donottplist = new HashSet<String>();
        MOTDLines = new ArrayList<String>();
        this.reloadMOTD();
        configHandler.setGlobalConfig(new File(this.getDataFolder(), "config.yml"));
        configHandler.reloadConfig();

        if(configHandler.enablePersistence) {
            if(!databaseloaded) {
                setupDatabase();
            }
        }

        this.cuiPlayers = new HashSet<Player>();
        this.mod_InfDuraplayers = new HashSet<Player>();

        this.setupWorldEdit();
        this.setupWorldGuard();
        this.setupCraftIRC();
        this.setupZones();
        this.setupLogBlock();
        // this.setupNoLagg();

        playerReplyDB = new HashMap<String, String>();
        this.registerEvents();

        itemDB.loadDataBase();
        banhandler.reloadBans();

        if (configHandler.enableIRC) {
            circendpoint = new CraftIRCEndPoint(this, "tcutils");
            cirdlogendpoint = new CraftIRCEndPoint(this, "tcutilslog");
            circadminendpoint = new CraftIRCAdminEndPoint(this);
        }

        if (configHandler.enableDebug)
            commandHandler.checkCommands();

        commandHandler.addHelpTopics();

        /* itemDB.writeDB(); */

        playerListener.reloadInvisTable();
        worldmanager.setupWorlds();

        this.getLogger().info("[" + pdfFile.getName() + "] " + pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!");

    }

    public EndPoint getEndPoint() {
        return (EndPoint) circendpoint;
    }

    public EndPoint getAdminEndPoint() {
        return (EndPoint) circadminendpoint;
    }
    
    public String getVersion() {
        return pdfFile.getVersion();
    }
    
    public EndPoint getLogginEndPoint() {
        return (EndPoint) cirdlogendpoint;
    }

    public Set<String> getDonottplist() {
        return donottplist;
    }

    @Override
    public void onDisable() {
        instance = null;
        this.getLogger().info("[" + pdfFile.getName() + "] Shutting down!");
        // this.getDatabase().
    }

    public ConfigurationHandler getConfigHandler() {
        return configHandler;
    }

    @Override
    public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
        return worldmanager.getDefaultWorldGenerator(worldName, id);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] unfilteredargs) {

        List<String> argsa = new ArrayList<String>();
        // String[] args = new String[];
        //int argc = 0;
        for (String a : unfilteredargs) {
            if (a != null && !a.trim().equals("")) {
                argsa.add(a);
                // argc++;
            }
        }
        String[] args = argsa.toArray(new String[argsa.size()]);

        if (commandHandler.getCommandMap().containsKey(cmd.getName())) {
            return commandHandler.executeCommand(sender, cmd.getName(), unfilteredargs);
        }
        return false;
    }
} public class EntityLocation {

    private Location entityLocation;

    public EntityLocation(LivingEntity entity) {
        this.entityLocation = entity.getLocation();
    }

    public Integer getDistance(LivingEntity entity) {
        Location dloc;
        // Integer xdiff, zdiff;
        Integer xdiffi, zdiffi;
        dloc = entity.getLocation();
        if (dloc.getWorld() != entityLocation.getWorld())
            return null; // Different world, different result!

        
        xdiffi = dloc.getBlockX() - entityLocation.getBlockX();
        // xdiffi = xdiff.intValue();
        if (xdiffi < 0) {
            xdiffi = ~xdiffi + 1;
        }
        zdiffi = dloc.getBlockZ() - entityLocation.getBlockZ();
        // zdiffi = zdiff.intValue();
        if (zdiffi < 0) {
            zdiffi = ~zdiffi + 1;
        }

        return zdiffi + xdiffi;
    }

}
import com.ensifera.animosity.craftirc.RelayedMessage;
import com.guntherdw.bukkit.tweakcraft.Commands.aCommand;
import com.guntherdw.bukkit.tweakcraft.DataSources.PersistenceClass.PlayerHistoryInfo;
import com.guntherdw.bukkit.tweakcraft.DataSources.PersistenceClass.PlayerInfo;
import com.guntherdw.bukkit.tweakcraft.Exceptions.CommandException;
import com.guntherdw.bukkit.tweakcraft.Exceptions.CommandSenderException;
import com.guntherdw.bukkit.tweakcraft.Exceptions.CommandUsageException;
import com.guntherdw.bukkit.tweakcraft.Exceptions.PermissionsException;
import com.guntherdw.bukkit.tweakcraft.Packages.LocalPlayer;
import com.guntherdw.bukkit.tweakcraft.Packages.TamerMode;
import com.guntherdw.bukkit.tweakcraft.Tools.ArgumentParser;
import com.guntherdw.bukkit.tweakcraft.Tools.TamerTool;
import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
import com.guntherdw.bukkit.tweakcraft.Util.EntityLocation;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import java.text.SimpleDateFormat;
import java.util.*;
    @aCommand(
        aliases = { "nick" },
        permissionBase = "nick",
        description = "Give someone a nick",
        section = "general"
    )
    public boolean setNick(CommandSender sender, String command, String[] args)
        throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
        if(sender instanceof Player)
            if(!plugin.check((Player)sender, "nick"))
                throw new PermissionsException(command);

        // Player player = (Player) sender;

        if(args.length==1 && !(sender instanceof Player))
            throw new CommandUsageException("If you're only giving me one var, give me a player!");

        if(args.length==1) {
            if(args[0].equalsIgnoreCase("reset")) {
                sender.sendMessage(ChatColor.GOLD + "Resetting nick to your real name.");
                plugin.getPlayerListener().removeNick(((Player)sender).getName());
            } else {
                sender.sendMessage(ChatColor.GOLD + "Setting nick to : "+args[0]);
                if(!plugin.getPlayerListener().nickTakenPersistance(((Player)sender).getName(), args[0])
                    && !plugin.getPlayerListener().nickTakenCheck(((Player)sender).getName(), args[0]))
                    plugin.getPlayerListener().setNick(((Player)sender).getName(), args[0]);
                else
                    throw new CommandException("Nick is already taken!");
            }
        } else if(args.length==2) {
            if(sender instanceof Player)
                if(!plugin.check((Player)sender, "nick.other"))
                    throw new PermissionsException(command);

            List<Player> search = plugin.getServer().matchPlayer(args[0]);
            if(search.size()!=1) {
                throw new CommandException("Can't find the other player!");
            } else {
                if(args[1].equalsIgnoreCase("reset")) {
                    sender.sendMessage("Resetting "+search.get(0).getName()+"'s nick");
                    plugin.getPlayerListener().removeNick(search.get(0).getName());
                } else {
                    Player otherplayer = search.get(0);
                    sender.sendMessage(ChatColor.GOLD + "Setting "+search.get(0).getName()+"'s nick to "+args[1]);
                    List<Player> find = plugin.getServer().matchPlayer(args[0]);
                    for(Player f : find) {
                        if(f.getName().toLowerCase().equals(args[1].toLowerCase()))
                            throw new CommandException("Nick is already taken!");
                    }
                    if(!plugin.getPlayerListener().nickTakenPersistance(otherplayer.getName(), args[1])
                        && !plugin.getPlayerListener().nickTakenCheck(otherplayer.getName(), args[1]))
                        plugin.getPlayerListener().setNick(otherplayer.getName(), args[1]);
                    else
                        throw new CommandException("Nick is already taken!");
                }
            }
        } else {
            throw new CommandUsageException("I need a nick!");
        }
        return true;
    }

    @aCommand(
        aliases = { "toggleinvispickup", "tip" },
        permissionBase = "tpinvis",
        description = "Toggle the picking up of items for invisble players",
        section = "general"
    )
    public boolean toggleInvisiblePickup(CommandSender sender, String command, String[] args)
        throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
        if(!(sender instanceof Player)) {
            throw new CommandSenderException("What were you trying to do?");
        }

        final Player player = (Player) sender;
        final LocalPlayer localPlayer = plugin.wrapPlayer(player);


        if(localPlayer.isInvisible()) {
            boolean newstate = !localPlayer.isInvisiblePickup();
            player.sendMessage(ChatColor.YELLOW+"Set pickup state to "+(newstate?ChatColor.GREEN+"ENABLED":ChatColor.RED+"DISABLED")+ChatColor.YELLOW+"!");
            localPlayer.setInvisiblePickup(newstate);
        } else {
            player.sendMessage(ChatColor.RED+"You're not invisible, what were you trying to do?");
        }

        return true;
    }

    @aCommand(
        aliases = { "seen" },
        permissionBase = "seen",
        description = "Report the last logout time of the player",
        section = "general"
    )
    public boolean seen(CommandSender sender, String command, String[] args)
        throws PermissionsException, CommandSenderException, CommandUsageException {
        if (args.length < 1) {
            throw new CommandUsageException("You did not specify a name!");
        }
        if (plugin.getConfigHandler().getSeenconfig() != null || plugin.getConfigHandler().enablePersistence) {
            Player pla;
            String playername = "";
            if ((pla = plugin.getServer().getPlayer(args[0])) != null) {
                sender.sendMessage(ChatColor.GOLD + pla.getName() + " is online right now!");
            } else {
                String seen = "";
                String extramsg = "";
                String newline = null;
                if(!plugin.getConfigHandler().enablePersistence) {
                    seen = plugin.getConfigHandler().getSeenconfig().getString(args[0].toLowerCase(), "");
                    playername = args[0];
                } else {
                    if(!plugin.getConfigHandler().useTweakBotSeen) {
                        PlayerInfo pi = plugin.getDatabase().find(PlayerInfo.class).where().ieq("name", args[0]).findUnique();
                        if(pi!=null) {
                            seen = pi.getLastseen().toString();
                            playername = pi.getName();
                        }
                    } else {
                        PlayerHistoryInfo phi = plugin.getDatabase().find(PlayerHistoryInfo.class).where().ieq("nickname", args[0]).findUnique();