2014-08-26 20:46:46 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012-2014 Steven Lawson
|
|
|
|
*
|
|
|
|
* This file is part of BukkitTelnetClient.
|
|
|
|
*
|
|
|
|
* BukkitTelnetClient is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2014-08-17 17:52:11 +00:00
|
|
|
package me.StevenLawson.BukkitTelnetClient;
|
|
|
|
|
2014-08-23 03:00:33 +00:00
|
|
|
import java.lang.annotation.Annotation;
|
|
|
|
import java.lang.annotation.ElementType;
|
|
|
|
import java.lang.annotation.Retention;
|
|
|
|
import java.lang.annotation.RetentionPolicy;
|
|
|
|
import java.lang.annotation.Target;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
|
2014-08-20 17:46:50 +00:00
|
|
|
public class PlayerInfo
|
2014-08-17 17:52:11 +00:00
|
|
|
{
|
2014-08-23 03:00:33 +00:00
|
|
|
public static int numColumns;
|
|
|
|
public static String[] columnNames;
|
|
|
|
|
2014-08-17 17:52:11 +00:00
|
|
|
private final String name;
|
|
|
|
private final String ip;
|
|
|
|
private final String displayName;
|
2014-08-23 03:00:33 +00:00
|
|
|
private final String uuid;
|
|
|
|
|
|
|
|
// TFM tags:
|
|
|
|
private final boolean admin;
|
|
|
|
private final boolean telnetAdmin;
|
|
|
|
private final boolean seniorAdmin;
|
|
|
|
private final String tag;
|
|
|
|
private final String nickName;
|
|
|
|
|
|
|
|
static
|
|
|
|
{
|
|
|
|
final Map<Integer, String> columnNamesMap = new HashMap<>();
|
2014-08-17 17:52:11 +00:00
|
|
|
|
2014-08-23 03:00:33 +00:00
|
|
|
int _numColumns = 0;
|
|
|
|
final Method[] declaredMethods = PlayerInfo.class.getDeclaredMethods();
|
|
|
|
for (final Method method : declaredMethods)
|
|
|
|
{
|
|
|
|
final Annotation[] declaredAnnotations = method.getDeclaredAnnotations();
|
|
|
|
for (final Annotation annotation : declaredAnnotations)
|
|
|
|
{
|
|
|
|
if (annotation instanceof PlayerTableColumn)
|
|
|
|
{
|
|
|
|
PlayerTableColumn playerInfoTag = (PlayerTableColumn) annotation;
|
|
|
|
columnNamesMap.put(playerInfoTag.column(), playerInfoTag.name());
|
|
|
|
_numColumns++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final String[] _columnNames = new String[_numColumns];
|
|
|
|
for (int i = 0; i < _numColumns; i++)
|
|
|
|
{
|
|
|
|
_columnNames[i] = columnNamesMap.get(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
columnNames = _columnNames;
|
|
|
|
numColumns = _numColumns;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerInfo(String name, String ip, String displayName, String uuid, boolean admin, boolean telnetAdmin, boolean seniorAdmin, String tag, String nickName)
|
2014-08-17 17:52:11 +00:00
|
|
|
{
|
|
|
|
this.name = name;
|
|
|
|
this.ip = ip;
|
|
|
|
this.displayName = displayName;
|
2014-08-23 03:00:33 +00:00
|
|
|
this.uuid = uuid;
|
|
|
|
this.admin = admin;
|
|
|
|
this.telnetAdmin = telnetAdmin;
|
|
|
|
this.seniorAdmin = seniorAdmin;
|
|
|
|
this.tag = tag;
|
|
|
|
this.nickName = nickName;
|
2014-08-17 17:52:11 +00:00
|
|
|
}
|
|
|
|
|
2014-08-23 03:00:33 +00:00
|
|
|
@PlayerTableColumn(name = "Name", column = 0)
|
2014-08-17 17:52:11 +00:00
|
|
|
public String getName()
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2014-08-23 03:00:33 +00:00
|
|
|
@PlayerTableColumn(name = "IP", column = 1)
|
2014-08-17 17:52:11 +00:00
|
|
|
public String getIp()
|
|
|
|
{
|
|
|
|
return ip;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getDisplayName()
|
|
|
|
{
|
|
|
|
return displayName;
|
|
|
|
}
|
|
|
|
|
2014-08-23 03:00:33 +00:00
|
|
|
public String getUuid()
|
|
|
|
{
|
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isAdmin()
|
|
|
|
{
|
|
|
|
return admin;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isTelnetAdmin()
|
|
|
|
{
|
|
|
|
return telnetAdmin;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSeniorAdmin()
|
|
|
|
{
|
|
|
|
return seniorAdmin;
|
|
|
|
}
|
|
|
|
|
|
|
|
@PlayerTableColumn(name = "Tag", column = 2)
|
|
|
|
public String getTag()
|
|
|
|
{
|
|
|
|
return tag == null || tag.isEmpty() || tag.equalsIgnoreCase("null") ? "" : tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
@PlayerTableColumn(name = "Nickname", column = 3)
|
|
|
|
public String getNickName()
|
|
|
|
{
|
|
|
|
return nickName == null || nickName.isEmpty() || nickName.equalsIgnoreCase("null") ? "" : nickName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@PlayerTableColumn(name = "Admin Level", column = 4)
|
|
|
|
public String getAdminLevel()
|
|
|
|
{
|
|
|
|
if (isAdmin())
|
|
|
|
{
|
|
|
|
if (isSeniorAdmin())
|
|
|
|
{
|
|
|
|
return "Senior";
|
|
|
|
}
|
|
|
|
else if (isTelnetAdmin())
|
|
|
|
{
|
|
|
|
return "Telnet";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return "Super";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getColumnValue(int columnIndex)
|
|
|
|
{
|
|
|
|
final Method[] declaredMethods = this.getClass().getDeclaredMethods();
|
|
|
|
for (final Method method : declaredMethods)
|
|
|
|
{
|
|
|
|
final Annotation[] declaredAnnotations = method.getDeclaredAnnotations();
|
|
|
|
for (final Annotation annotation : declaredAnnotations)
|
|
|
|
{
|
|
|
|
if (annotation instanceof PlayerTableColumn)
|
|
|
|
{
|
|
|
|
PlayerTableColumn playerInfoTag = (PlayerTableColumn) annotation;
|
|
|
|
|
|
|
|
if (playerInfoTag.column() == columnIndex)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final Object value = method.invoke(this);
|
|
|
|
if (value != null)
|
|
|
|
{
|
|
|
|
return value.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex)
|
|
|
|
{
|
|
|
|
BukkitTelnetClient.LOGGER.log(Level.SEVERE, null, ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return "null";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "null";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME)
|
|
|
|
@Target(ElementType.METHOD)
|
|
|
|
public @interface PlayerTableColumn
|
|
|
|
{
|
|
|
|
public String name();
|
|
|
|
|
|
|
|
public int column();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Comparator<PlayerInfo> getComparator()
|
2014-08-17 17:52:11 +00:00
|
|
|
{
|
2014-08-23 03:00:33 +00:00
|
|
|
return new Comparator<PlayerInfo>()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public int compare(PlayerInfo a, PlayerInfo b)
|
|
|
|
{
|
|
|
|
return a.getName().compareTo(b.getName());
|
|
|
|
}
|
|
|
|
};
|
2014-08-17 17:52:11 +00:00
|
|
|
}
|
|
|
|
}
|