mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
I'm tired of seeing prs that make small code reformats so im doing a commit to fix it all at once
This commit is contained in:
parent
8bd8efc665
commit
60c627c591
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<!DOCTYPE module PUBLIC
|
<!DOCTYPE module PUBLIC
|
||||||
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
||||||
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
|
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
|
||||||
|
|
||||||
<module name="Checker">
|
<module name="Checker">
|
||||||
<property name="charset" value="UTF-8"/>
|
<property name="charset" value="UTF-8"/>
|
||||||
@ -9,7 +9,7 @@
|
|||||||
<property name="fileExtensions" value="java, properties, xml"/>
|
<property name="fileExtensions" value="java, properties, xml"/>
|
||||||
|
|
||||||
<module name="SuppressionFilter">
|
<module name="SuppressionFilter">
|
||||||
<property name="file" value="supressions.xml" />
|
<property name="file" value="supressions.xml"/>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
<module name="FileTabCharacter">
|
<module name="FileTabCharacter">
|
||||||
@ -20,7 +20,8 @@
|
|||||||
<module name="OuterTypeFilename"/>
|
<module name="OuterTypeFilename"/>
|
||||||
<module name="IllegalTokenText">
|
<module name="IllegalTokenText">
|
||||||
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
|
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
|
||||||
<property name="format" value="\\u00(08|09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
|
<property name="format"
|
||||||
|
value="\\u00(08|09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
|
||||||
<property name="message" value="Avoid using corresponding octal or Unicode escape."/>
|
<property name="message" value="Avoid using corresponding octal or Unicode escape."/>
|
||||||
</module>
|
</module>
|
||||||
<module name="LineLength">
|
<module name="LineLength">
|
||||||
@ -36,7 +37,8 @@
|
|||||||
</module>
|
</module>
|
||||||
<module name="RightCurly">
|
<module name="RightCurly">
|
||||||
<property name="option" value="alone"/>
|
<property name="option" value="alone"/>
|
||||||
<property name="tokens" value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT"/>
|
<property name="tokens"
|
||||||
|
value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT"/>
|
||||||
</module>
|
</module>
|
||||||
<module name="WhitespaceAround">
|
<module name="WhitespaceAround">
|
||||||
<property name="allowEmptyConstructors" value="true"/>
|
<property name="allowEmptyConstructors" value="true"/>
|
||||||
@ -114,7 +116,8 @@
|
|||||||
<module name="MethodParamPad"/>
|
<module name="MethodParamPad"/>
|
||||||
<module name="OperatorWrap">
|
<module name="OperatorWrap">
|
||||||
<property name="option" value="NL"/>
|
<property name="option" value="NL"/>
|
||||||
<property name="tokens" value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR "/>
|
<property name="tokens"
|
||||||
|
value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR "/>
|
||||||
</module>
|
</module>
|
||||||
<module name="AnnotationLocation">
|
<module name="AnnotationLocation">
|
||||||
<property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
|
<property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
|
||||||
|
@ -5,15 +5,18 @@ import ca.momothereal.mojangson.value.*;
|
|||||||
|
|
||||||
import static ca.momothereal.mojangson.MojangsonToken.*;
|
import static ca.momothereal.mojangson.MojangsonToken.*;
|
||||||
|
|
||||||
public class MojangsonFinder {
|
public class MojangsonFinder
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Automatically detects the appropriate MojangsonValue from the given value.
|
* Automatically detects the appropriate MojangsonValue from the given value.
|
||||||
|
*
|
||||||
* @param value The value to parse
|
* @param value The value to parse
|
||||||
* @return The resulting MojangsonValue. If the type couldn't be found, it falls back to MojangsonString
|
* @return The resulting MojangsonValue. If the type couldn't be found, it falls back to MojangsonString
|
||||||
* @throws MojangsonParseException if the given value could not be parsed
|
* @throws MojangsonParseException if the given value could not be parsed
|
||||||
*/
|
*/
|
||||||
public static MojangsonValue readFromValue(String value) throws MojangsonParseException {
|
public static MojangsonValue readFromValue(String value) throws MojangsonParseException
|
||||||
|
{
|
||||||
MojangsonValue val = new MojangsonString();
|
MojangsonValue val = new MojangsonString();
|
||||||
val.read(value);
|
val.read(value);
|
||||||
return val;
|
return val;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package ca.momothereal.mojangson;
|
package ca.momothereal.mojangson;
|
||||||
|
|
||||||
public enum MojangsonToken {
|
public enum MojangsonToken
|
||||||
|
{
|
||||||
|
|
||||||
COMPOUND_START(0, "Compound_Start", '{'),
|
COMPOUND_START(0, "Compound_Start", '{'),
|
||||||
COMPOUND_END(1, "Compound_End", '}'),
|
COMPOUND_END(1, "Compound_End", '}'),
|
||||||
@ -22,26 +23,31 @@ public enum MojangsonToken {
|
|||||||
private String name;
|
private String name;
|
||||||
private char symbol;
|
private char symbol;
|
||||||
|
|
||||||
MojangsonToken(int id, String name, char symbol) {
|
MojangsonToken(int id, String name, char symbol)
|
||||||
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.symbol = symbol;
|
this.symbol = symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId()
|
||||||
|
{
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName()
|
||||||
|
{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public char getSymbol() {
|
public char getSymbol()
|
||||||
|
{
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString()
|
||||||
|
{
|
||||||
return String.valueOf(symbol);
|
return String.valueOf(symbol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,41 @@
|
|||||||
package ca.momothereal.mojangson.ex;
|
package ca.momothereal.mojangson.ex;
|
||||||
|
|
||||||
public class MojangsonParseException extends Exception {
|
public class MojangsonParseException extends Exception
|
||||||
|
{
|
||||||
|
|
||||||
private ParseExceptionReason reason;
|
private ParseExceptionReason reason;
|
||||||
|
|
||||||
public MojangsonParseException(String message, ParseExceptionReason reason) {
|
public MojangsonParseException(String message, ParseExceptionReason reason)
|
||||||
|
{
|
||||||
super(message);
|
super(message);
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParseExceptionReason getReason() {
|
public ParseExceptionReason getReason()
|
||||||
|
{
|
||||||
return reason;
|
return reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMessage() {
|
public String getMessage()
|
||||||
|
{
|
||||||
return reason.getMessage() + ": " + super.getMessage();
|
return reason.getMessage() + ": " + super.getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ParseExceptionReason {
|
public enum ParseExceptionReason
|
||||||
|
{
|
||||||
INVALID_FORMAT_NUM("Given value is not numerical"),
|
INVALID_FORMAT_NUM("Given value is not numerical"),
|
||||||
UNEXPECTED_SYMBOL("Unexpected symbol in Mojangson string");
|
UNEXPECTED_SYMBOL("Unexpected symbol in Mojangson string");
|
||||||
|
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
ParseExceptionReason(String message) {
|
ParseExceptionReason(String message)
|
||||||
|
{
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMessage() {
|
public String getMessage()
|
||||||
|
{
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,35 +7,43 @@ import java.util.*;
|
|||||||
|
|
||||||
import static ca.momothereal.mojangson.MojangsonToken.*;
|
import static ca.momothereal.mojangson.MojangsonToken.*;
|
||||||
|
|
||||||
public class MojangsonCompound extends HashMap<String, List<MojangsonValue>> implements MojangsonValue<Map<String, MojangsonValue>> {
|
public class MojangsonCompound extends HashMap<String, List<MojangsonValue>> implements MojangsonValue<Map<String, MojangsonValue>>
|
||||||
|
{
|
||||||
|
|
||||||
private final int C_COMPOUND_START = 0; // Parsing context
|
private final int C_COMPOUND_START = 0; // Parsing context
|
||||||
private final int C_COMPOUND_PAIR_KEY = 1; // Parsing context
|
private final int C_COMPOUND_PAIR_KEY = 1; // Parsing context
|
||||||
private final int C_COMPOUND_PAIR_VALUE = 2; // Parsing context
|
private final int C_COMPOUND_PAIR_VALUE = 2; // Parsing context
|
||||||
|
|
||||||
public MojangsonCompound() {
|
public MojangsonCompound()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MojangsonCompound(Map map) {
|
public MojangsonCompound(Map map)
|
||||||
|
{
|
||||||
super(map);
|
super(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(StringBuilder builder) {
|
public void write(StringBuilder builder)
|
||||||
|
{
|
||||||
builder.append(COMPOUND_START);
|
builder.append(COMPOUND_START);
|
||||||
boolean start = true;
|
boolean start = true;
|
||||||
|
|
||||||
for (String key : keySet()) {
|
for (String key : keySet())
|
||||||
if (start) {
|
{
|
||||||
|
if (start)
|
||||||
|
{
|
||||||
start = false;
|
start = false;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
builder.append(ELEMENT_SEPERATOR);
|
builder.append(ELEMENT_SEPERATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append(key).append(ELEMENT_PAIR_SEPERATOR);
|
builder.append(key).append(ELEMENT_PAIR_SEPERATOR);
|
||||||
List<MojangsonValue> value = get(key);
|
List<MojangsonValue> value = get(key);
|
||||||
for(MojangsonValue val : value)
|
for (MojangsonValue val : value)
|
||||||
{
|
{
|
||||||
val.write(builder);
|
val.write(builder);
|
||||||
}
|
}
|
||||||
@ -44,46 +52,60 @@ public class MojangsonCompound extends HashMap<String, List<MojangsonValue>> imp
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(String string) throws MojangsonParseException {
|
public void read(String string) throws MojangsonParseException
|
||||||
|
{
|
||||||
int context = C_COMPOUND_START;
|
int context = C_COMPOUND_START;
|
||||||
String tmp_key = "", tmp_val = "";
|
String tmp_key = "", tmp_val = "";
|
||||||
int scope = 0;
|
int scope = 0;
|
||||||
boolean inString = false;
|
boolean inString = false;
|
||||||
|
|
||||||
for (int index = 0; index < string.length(); index++) {
|
for (int index = 0; index < string.length(); index++)
|
||||||
|
{
|
||||||
Character character = string.charAt(index);
|
Character character = string.charAt(index);
|
||||||
|
|
||||||
if (character == STRING_QUOTES.getSymbol()) {
|
if (character == STRING_QUOTES.getSymbol())
|
||||||
|
{
|
||||||
inString = !inString;
|
inString = !inString;
|
||||||
}
|
}
|
||||||
if (character == WHITE_SPACE.getSymbol()) {
|
if (character == WHITE_SPACE.getSymbol())
|
||||||
|
{
|
||||||
if (!inString)
|
if (!inString)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ((character == COMPOUND_START.getSymbol() || character == ARRAY_START.getSymbol()) && !inString) {
|
if ((character == COMPOUND_START.getSymbol() || character == ARRAY_START.getSymbol()) && !inString)
|
||||||
|
{
|
||||||
scope++;
|
scope++;
|
||||||
}
|
}
|
||||||
if ((character == COMPOUND_END.getSymbol() || character == ARRAY_END.getSymbol()) && !inString) {
|
if ((character == COMPOUND_END.getSymbol() || character == ARRAY_END.getSymbol()) && !inString)
|
||||||
|
{
|
||||||
scope--;
|
scope--;
|
||||||
}
|
}
|
||||||
if (context == C_COMPOUND_START) {
|
if (context == C_COMPOUND_START)
|
||||||
if (character != COMPOUND_START.getSymbol()) {
|
{
|
||||||
|
if (character != COMPOUND_START.getSymbol())
|
||||||
|
{
|
||||||
parseException(index, character);
|
parseException(index, character);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
context++;
|
context++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (context == C_COMPOUND_PAIR_KEY) {
|
if (context == C_COMPOUND_PAIR_KEY)
|
||||||
if (character == ELEMENT_PAIR_SEPERATOR.getSymbol() && scope <= 1) {
|
{
|
||||||
|
if (character == ELEMENT_PAIR_SEPERATOR.getSymbol() && scope <= 1)
|
||||||
|
{
|
||||||
context++;
|
context++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tmp_key += character;
|
tmp_key += character;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (context == C_COMPOUND_PAIR_VALUE) {
|
if (context == C_COMPOUND_PAIR_VALUE)
|
||||||
if ((character == ELEMENT_SEPERATOR.getSymbol() || character == COMPOUND_END.getSymbol()) && scope <= 1 && !inString) {
|
{
|
||||||
|
if ((character == ELEMENT_SEPERATOR.getSymbol() || character == COMPOUND_END.getSymbol()) && scope <= 1 && !inString)
|
||||||
|
{
|
||||||
context = C_COMPOUND_PAIR_KEY;
|
context = C_COMPOUND_PAIR_KEY;
|
||||||
computeIfAbsent(tmp_key, k -> new ArrayList<>()).add(MojangsonFinder.readFromValue(tmp_val));
|
computeIfAbsent(tmp_key, k -> new ArrayList<>()).add(MojangsonFinder.readFromValue(tmp_val));
|
||||||
tmp_key = tmp_val = "";
|
tmp_key = tmp_val = "";
|
||||||
@ -95,11 +117,12 @@ public class MojangsonCompound extends HashMap<String, List<MojangsonValue>> imp
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, MojangsonValue> getValue() {
|
public Map<String, MojangsonValue> getValue()
|
||||||
|
{
|
||||||
HashMap<String, MojangsonValue> hack = new HashMap<>();
|
HashMap<String, MojangsonValue> hack = new HashMap<>();
|
||||||
for(String string : keySet())
|
for (String string : keySet())
|
||||||
{
|
{
|
||||||
for(MojangsonValue value : get(string))
|
for (MojangsonValue value : get(string))
|
||||||
{
|
{
|
||||||
hack.put(string, value);
|
hack.put(string, value);
|
||||||
}
|
}
|
||||||
@ -108,11 +131,13 @@ public class MojangsonCompound extends HashMap<String, List<MojangsonValue>> imp
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class getValueClass() {
|
public Class getValueClass()
|
||||||
|
{
|
||||||
return Map.class;
|
return Map.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseException(int index, char symbol) throws MojangsonParseException {
|
private void parseException(int index, char symbol) throws MojangsonParseException
|
||||||
|
{
|
||||||
throw new MojangsonParseException("Index: " + index + ", symbol: \'" + symbol + "\'", MojangsonParseException.ParseExceptionReason.UNEXPECTED_SYMBOL);
|
throw new MojangsonParseException("Index: " + index + ", symbol: \'" + symbol + "\'", MojangsonParseException.ParseExceptionReason.UNEXPECTED_SYMBOL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,43 +3,54 @@ package ca.momothereal.mojangson.value;
|
|||||||
import ca.momothereal.mojangson.MojangsonToken;
|
import ca.momothereal.mojangson.MojangsonToken;
|
||||||
import ca.momothereal.mojangson.ex.MojangsonParseException;
|
import ca.momothereal.mojangson.ex.MojangsonParseException;
|
||||||
|
|
||||||
public class MojangsonString implements MojangsonValue<String> {
|
public class MojangsonString implements MojangsonValue<String>
|
||||||
|
{
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
public MojangsonString() {
|
public MojangsonString()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MojangsonString(String value) {
|
public MojangsonString(String value)
|
||||||
|
{
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue() {
|
public String getValue()
|
||||||
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(String value) {
|
public void setValue(String value)
|
||||||
|
{
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(StringBuilder builder) {
|
public void write(StringBuilder builder)
|
||||||
|
{
|
||||||
builder.append(MojangsonToken.STRING_QUOTES).append(value).append(MojangsonToken.STRING_QUOTES);
|
builder.append(MojangsonToken.STRING_QUOTES).append(value).append(MojangsonToken.STRING_QUOTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class getValueClass() {
|
public Class getValueClass()
|
||||||
|
{
|
||||||
return String.class;
|
return String.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(String string) throws MojangsonParseException {
|
public void read(String string) throws MojangsonParseException
|
||||||
|
{
|
||||||
Character lastChar = string.charAt(string.length() - 1);
|
Character lastChar = string.charAt(string.length() - 1);
|
||||||
Character firstChar = string.charAt(0);
|
Character firstChar = string.charAt(0);
|
||||||
|
|
||||||
if (firstChar == MojangsonToken.STRING_QUOTES.getSymbol() && lastChar == MojangsonToken.STRING_QUOTES.getSymbol()) {
|
if (firstChar == MojangsonToken.STRING_QUOTES.getSymbol() && lastChar == MojangsonToken.STRING_QUOTES.getSymbol())
|
||||||
|
{
|
||||||
value = string.substring(1, string.length() - 1);
|
value = string.substring(1, string.length() - 1);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
value = string;
|
value = string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,18 +4,22 @@ import ca.momothereal.mojangson.ex.MojangsonParseException;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a value inside a compound or array.
|
* Represents a value inside a compound or array.
|
||||||
|
*
|
||||||
* @param <T> The type of value this MojangsonValue holds
|
* @param <T> The type of value this MojangsonValue holds
|
||||||
*/
|
*/
|
||||||
public interface MojangsonValue<T> {
|
public interface MojangsonValue<T>
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the value to a StringBuilder buffer.
|
* Writes the value to a StringBuilder buffer.
|
||||||
|
*
|
||||||
* @param builder The buffer to write to
|
* @param builder The buffer to write to
|
||||||
*/
|
*/
|
||||||
void write(StringBuilder builder);
|
void write(StringBuilder builder);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses and updates the current value to the given string representation
|
* Parses and updates the current value to the given string representation
|
||||||
|
*
|
||||||
* @param string The string representation of the value
|
* @param string The string representation of the value
|
||||||
* @throws MojangsonParseException if the given value cannot be parsed
|
* @throws MojangsonParseException if the given value cannot be parsed
|
||||||
*/
|
*/
|
||||||
@ -23,12 +27,14 @@ public interface MojangsonValue<T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current literal value
|
* Gets the current literal value
|
||||||
|
*
|
||||||
* @return The current literal value of the MojangsonValue
|
* @return The current literal value of the MojangsonValue
|
||||||
*/
|
*/
|
||||||
T getValue();
|
T getValue();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the literal value's class
|
* Gets the literal value's class
|
||||||
|
*
|
||||||
* @return The literal value's class
|
* @return The literal value's class
|
||||||
*/
|
*/
|
||||||
Class getValueClass();
|
Class getValueClass();
|
||||||
|
@ -154,10 +154,10 @@ public class ChatManager extends FreedomService
|
|||||||
Admin admin = plugin.al.getAdmin(player);
|
Admin admin = plugin.al.getAdmin(player);
|
||||||
if (!Strings.isNullOrEmpty(admin.getAcFormat()))
|
if (!Strings.isNullOrEmpty(admin.getAcFormat()))
|
||||||
{
|
{
|
||||||
String format = admin.getAcFormat();
|
String format = admin.getAcFormat();
|
||||||
ChatColor color = getColor(admin, display);
|
ChatColor color = getColor(admin, display);
|
||||||
String msg = format.replace("%name%", sender.getName()).replace("%rank%", display.getAbbr()).replace("%rankcolor%", color.toString()).replace("%msg%", message);
|
String msg = format.replace("%name%", sender.getName()).replace("%rank%", display.getAbbr()).replace("%rankcolor%", color.toString()).replace("%msg%", message);
|
||||||
player.sendMessage(FUtil.colorize(msg));
|
player.sendMessage(FUtil.colorize(msg));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -500,9 +500,9 @@ public class FrontDoor extends FreedomService
|
|||||||
book.setTitle(ChatColor.DARK_GREEN + "Why you should go to TotalFreedom instead");
|
book.setTitle(ChatColor.DARK_GREEN + "Why you should go to TotalFreedom instead");
|
||||||
book.addPage(
|
book.addPage(
|
||||||
ChatColor.DARK_GREEN + "Why you should go to TotalFreedom instead\n"
|
ChatColor.DARK_GREEN + "Why you should go to TotalFreedom instead\n"
|
||||||
+ ChatColor.DARK_GRAY + "---------\n"
|
+ ChatColor.DARK_GRAY + "---------\n"
|
||||||
+ ChatColor.BLACK + "TotalFreedom is the original TotalFreedomMod server. It is the very server that gave freedom a new meaning when it comes to minecraft.\n"
|
+ ChatColor.BLACK + "TotalFreedom is the original TotalFreedomMod server. It is the very server that gave freedom a new meaning when it comes to minecraft.\n"
|
||||||
+ ChatColor.BLUE + "Join now! " + ChatColor.RED + "play.totalfreedom.me");
|
+ ChatColor.BLUE + "Join now! " + ChatColor.RED + "play.totalfreedom.me");
|
||||||
bookStack.setItemMeta(book);
|
bookStack.setItemMeta(book);
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers())
|
for (Player player : Bukkit.getOnlinePlayers())
|
||||||
|
@ -108,7 +108,7 @@ public class LoginProcess extends FreedomService
|
|||||||
final int forceIpPort = ConfigEntry.FORCE_IP_PORT.getInteger();
|
final int forceIpPort = ConfigEntry.FORCE_IP_PORT.getInteger();
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
|
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
|
||||||
ConfigEntry.FORCE_IP_KICKMSG.getString()
|
ConfigEntry.FORCE_IP_KICKMSG.getString()
|
||||||
.replace("%address%", ConfigEntry.SERVER_ADDRESS.getString() + (forceIpPort == DEFAULT_PORT ? "" : ":" + forceIpPort)));
|
.replace("%address%", ConfigEntry.SERVER_ADDRESS.getString() + (forceIpPort == DEFAULT_PORT ? "" : ":" + forceIpPort)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ public class AMP extends FreedomService
|
|||||||
@Override
|
@Override
|
||||||
protected void onStart()
|
protected void onStart()
|
||||||
{
|
{
|
||||||
if(!plugin.config.getBoolean(ConfigEntry.AMP_ENABLED))
|
if (!plugin.config.getBoolean(ConfigEntry.AMP_ENABLED))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -41,7 +41,8 @@ public class AMP extends FreedomService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package me.totalfreedom.totalfreedommod.amp;
|
|||||||
|
|
||||||
public enum AMPEndpoints
|
public enum AMPEndpoints
|
||||||
{
|
{
|
||||||
LOGIN("/API/Core/Login" , "{username:\"%s\", password:\"%s\", token:\"\", rememberMe:false}"),
|
LOGIN("/API/Core/Login", "{username:\"%s\", password:\"%s\", token:\"\", rememberMe:false}"),
|
||||||
RESTART("/API/Core/Restart", "{SESSIONID:\"%s\"}");
|
RESTART("/API/Core/Restart", "{SESSIONID:\"%s\"}");
|
||||||
|
|
||||||
private final String text;
|
private final String text;
|
||||||
@ -20,6 +20,7 @@ public enum AMPEndpoints
|
|||||||
{
|
{
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getParameters()
|
public String getParameters()
|
||||||
{
|
{
|
||||||
return parameters;
|
return parameters;
|
||||||
|
@ -22,7 +22,10 @@ public class AMPManager
|
|||||||
|
|
||||||
public AMPManager(TotalFreedomMod plugin, String url, String username, String password)
|
public AMPManager(TotalFreedomMod plugin, String url, String username, String password)
|
||||||
{
|
{
|
||||||
this.plugin = plugin; this.url = url; this.username = username; this.password = password;
|
this.plugin = plugin;
|
||||||
|
this.url = url;
|
||||||
|
this.username = username;
|
||||||
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connectAsync(final LoginCallback callback)
|
public void connectAsync(final LoginCallback callback)
|
||||||
@ -38,7 +41,7 @@ public class AMPManager
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
LoginResult resp = new Gson().fromJson(postRequestToEndpoint(apiEndpoint, body), LoginResult.class);
|
LoginResult resp = new Gson().fromJson(postRequestToEndpoint(apiEndpoint, body), LoginResult.class);
|
||||||
if(!resp.getSuccess())
|
if (!resp.getSuccess())
|
||||||
{
|
{
|
||||||
FLog.severe("AMP login unsuccessful. Check if login details are correct.");
|
FLog.severe("AMP login unsuccessful. Check if login details are correct.");
|
||||||
sessionID = "";
|
sessionID = "";
|
||||||
@ -48,7 +51,7 @@ public class AMPManager
|
|||||||
sessionID = resp.getSessionID();
|
sessionID = resp.getSessionID();
|
||||||
callback.loginDone(true);
|
callback.loginDone(true);
|
||||||
}
|
}
|
||||||
catch(IOException ex)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
FLog.severe("Could not login to AMP. Check if URL is correct. Stacktrace: " + ex.getMessage());
|
FLog.severe("Could not login to AMP. Check if URL is correct. Stacktrace: " + ex.getMessage());
|
||||||
sessionID = "";
|
sessionID = "";
|
||||||
@ -71,7 +74,7 @@ public class AMPManager
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
String resp = postRequestToEndpoint(apiEndpoint, body);
|
String resp = postRequestToEndpoint(apiEndpoint, body);
|
||||||
if(resp.contains("Unauthorized Access"))
|
if (resp.contains("Unauthorized Access"))
|
||||||
{
|
{
|
||||||
//try connecting one more time
|
//try connecting one more time
|
||||||
LoginCallback callback = new LoginCallback()
|
LoginCallback callback = new LoginCallback()
|
||||||
@ -79,7 +82,7 @@ public class AMPManager
|
|||||||
@Override
|
@Override
|
||||||
public void loginDone(boolean success)
|
public void loginDone(boolean success)
|
||||||
{
|
{
|
||||||
if(!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
FLog.severe("Failed to connect to AMP. Did the panel go down? Were panel user details changed/deleted? Check for more info above. Connection was successful when plugin started, but unsuccessful now." +
|
FLog.severe("Failed to connect to AMP. Did the panel go down? Were panel user details changed/deleted? Check for more info above. Connection was successful when plugin started, but unsuccessful now." +
|
||||||
" Using server.shutdown() instead.");
|
" Using server.shutdown() instead.");
|
||||||
@ -89,7 +92,7 @@ public class AMPManager
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
String response = postRequestToEndpoint(apiEndpoint, body);
|
String response = postRequestToEndpoint(apiEndpoint, body);
|
||||||
if(response.contains("Unauthorized Access"))
|
if (response.contains("Unauthorized Access"))
|
||||||
{
|
{
|
||||||
FLog.severe("Contact a developer. Panel gives Session ID but trying to use it gives a no perms error. The panel user set in config doesn't" +
|
FLog.severe("Contact a developer. Panel gives Session ID but trying to use it gives a no perms error. The panel user set in config doesn't" +
|
||||||
" have perms to restart server. Using server.shutdown() instead. ");
|
" have perms to restart server. Using server.shutdown() instead. ");
|
||||||
@ -107,7 +110,7 @@ public class AMPManager
|
|||||||
plugin.amp.ampManager.connectAsync(callback);
|
plugin.amp.ampManager.connectAsync(callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(IOException ex)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
FLog.severe("Could not restart. Using server.shutdown() instead. Stacktrace: " + ex.getMessage());
|
FLog.severe("Could not restart. Using server.shutdown() instead. Stacktrace: " + ex.getMessage());
|
||||||
plugin.getServer().shutdown();
|
plugin.getServer().shutdown();
|
||||||
@ -120,7 +123,7 @@ public class AMPManager
|
|||||||
private String postRequestToEndpoint(String endpoint, String body) throws IOException
|
private String postRequestToEndpoint(String endpoint, String body) throws IOException
|
||||||
{
|
{
|
||||||
URL url = new URL(endpoint);
|
URL url = new URL(endpoint);
|
||||||
if(endpoint.startsWith("https://"))
|
if (endpoint.startsWith("https://"))
|
||||||
{
|
{
|
||||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||||
connection.setRequestMethod("POST");
|
connection.setRequestMethod("POST");
|
||||||
@ -157,7 +160,8 @@ public class AMPManager
|
|||||||
String inputLine;
|
String inputLine;
|
||||||
StringBuffer response = new StringBuffer();
|
StringBuffer response = new StringBuffer();
|
||||||
|
|
||||||
while ((inputLine = in.readLine()) != null) {
|
while ((inputLine = in.readLine()) != null)
|
||||||
|
{
|
||||||
response.append(inputLine);
|
response.append(inputLine);
|
||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
|
@ -49,9 +49,9 @@ public class Ban implements ConfigLoadable, ConfigSavable, Validatable
|
|||||||
{
|
{
|
||||||
this(username,
|
this(username,
|
||||||
new String[]
|
new String[]
|
||||||
{
|
{
|
||||||
ip
|
ip
|
||||||
},
|
},
|
||||||
by,
|
by,
|
||||||
expire,
|
expire,
|
||||||
reason);
|
reason);
|
||||||
@ -80,9 +80,9 @@ public class Ban implements ConfigLoadable, ConfigSavable, Validatable
|
|||||||
public static Ban forPlayerIp(Player player, CommandSender by, Date expiry, String reason)
|
public static Ban forPlayerIp(Player player, CommandSender by, Date expiry, String reason)
|
||||||
{
|
{
|
||||||
return new Ban(null, new String[]
|
return new Ban(null, new String[]
|
||||||
{
|
{
|
||||||
Ips.getIp(player)
|
Ips.getIp(player)
|
||||||
}, by.getName(), expiry, reason);
|
}, by.getName(), expiry, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Ban forPlayerIp(String ip, CommandSender by, Date expiry, String reason)
|
public static Ban forPlayerIp(String ip, CommandSender by, Date expiry, String reason)
|
||||||
|
@ -275,7 +275,7 @@ public class BanManager extends FreedomService
|
|||||||
private void updateViews()
|
private void updateViews()
|
||||||
{
|
{
|
||||||
// Remove expired bans
|
// Remove expired bans
|
||||||
for (Iterator<Ban> it = bans.iterator(); it.hasNext();)
|
for (Iterator<Ban> it = bans.iterator(); it.hasNext(); )
|
||||||
{
|
{
|
||||||
if (it.next().isExpired())
|
if (it.next().isExpired())
|
||||||
{
|
{
|
||||||
|
@ -66,8 +66,8 @@ public class PermbanList extends FreedomService
|
|||||||
{
|
{
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
|
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
|
||||||
ChatColor.RED + "Your IP address is permanently banned from this server.\n"
|
ChatColor.RED + "Your IP address is permanently banned from this server.\n"
|
||||||
+ "Release procedures are available at\n"
|
+ "Release procedures are available at\n"
|
||||||
+ ChatColor.GOLD + ConfigEntry.SERVER_PERMBAN_URL.getString());
|
+ ChatColor.GOLD + ConfigEntry.SERVER_PERMBAN_URL.getString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,8 +79,8 @@ public class PermbanList extends FreedomService
|
|||||||
{
|
{
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
|
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
|
||||||
ChatColor.RED + "Your username is permanently banned from this server.\n"
|
ChatColor.RED + "Your username is permanently banned from this server.\n"
|
||||||
+ "Release procedures are available at\n"
|
+ "Release procedures are available at\n"
|
||||||
+ ChatColor.GOLD + ConfigEntry.SERVER_PERMBAN_URL.getString());
|
+ ChatColor.GOLD + ConfigEntry.SERVER_PERMBAN_URL.getString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class PVPBlocker extends FreedomService
|
|||||||
Player target = null;
|
Player target = null;
|
||||||
if (event.getEntity() instanceof Player)
|
if (event.getEntity() instanceof Player)
|
||||||
{
|
{
|
||||||
target = (Player)event.getEntity();
|
target = (Player) event.getEntity();
|
||||||
if (event.getDamager() instanceof Player)
|
if (event.getDamager() instanceof Player)
|
||||||
{
|
{
|
||||||
player = (Player) event.getDamager();
|
player = (Player) event.getDamager();
|
||||||
@ -59,7 +59,7 @@ public class PVPBlocker extends FreedomService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player != null &! plugin.al.isAdmin(player))
|
if (player != null & !plugin.al.isAdmin(player))
|
||||||
{
|
{
|
||||||
if (player.getGameMode() == GameMode.CREATIVE)
|
if (player.getGameMode() == GameMode.CREATIVE)
|
||||||
{
|
{
|
||||||
|
@ -43,7 +43,7 @@ public class PotionBlocker extends FreedomService
|
|||||||
Player player = null;
|
Player player = null;
|
||||||
if (projectileSource instanceof Player)
|
if (projectileSource instanceof Player)
|
||||||
{
|
{
|
||||||
player = (Player)projectileSource;
|
player = (Player) projectileSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDeathPotion(potion.getEffects()))
|
if (isDeathPotion(potion.getEffects()))
|
||||||
@ -64,7 +64,7 @@ public class PotionBlocker extends FreedomService
|
|||||||
Player player = null;
|
Player player = null;
|
||||||
if (projectileSource instanceof Player)
|
if (projectileSource instanceof Player)
|
||||||
{
|
{
|
||||||
player = (Player)projectileSource;
|
player = (Player) projectileSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDeathPotion(potion.getEffects()))
|
if (isDeathPotion(potion.getEffects()))
|
||||||
|
@ -39,7 +39,7 @@ public class CommandBlockerEntry
|
|||||||
{
|
{
|
||||||
if (action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player)
|
if (action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player)
|
||||||
{
|
{
|
||||||
TotalFreedomMod.plugin().ae.autoEject((Player)sender, "You used a prohibited command: " + command);
|
TotalFreedomMod.plugin().ae.autoEject((Player) sender, "You used a prohibited command: " + command);
|
||||||
FUtil.bcastMsg(sender.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED);
|
FUtil.bcastMsg(sender.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import org.bukkit.entity.Entity;
|
|||||||
import org.bukkit.entity.AreaEffectCloud;
|
import org.bukkit.entity.AreaEffectCloud;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
|
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Clears lingering potion area effect clouds.", usage = "/<command>", aliases="aec")
|
@CommandParameters(description = "Clears lingering potion area effect clouds.", usage = "/<command>", aliases = "aec")
|
||||||
public class Command_aeclear extends FreedomCommand
|
public class Command_aeclear extends FreedomCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -17,7 +17,8 @@ import java.util.List;
|
|||||||
@CommandParameters(description = "Lists the real names of all online players.", usage = "/<command> [-a | -i | -f | -v]", aliases = "who")
|
@CommandParameters(description = "Lists the real names of all online players.", usage = "/<command> [-a | -i | -f | -v]", aliases = "who")
|
||||||
public class Command_list extends FreedomCommand
|
public class Command_list extends FreedomCommand
|
||||||
{
|
{
|
||||||
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole) {
|
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole)
|
||||||
|
{
|
||||||
if (args.length > 1)
|
if (args.length > 1)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -46,9 +46,9 @@ public class Command_onlinemode extends FreedomCommand
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
plugin.si.setOnlineMode(onlineMode);
|
plugin.si.setOnlineMode(onlineMode);
|
||||||
|
|
||||||
if (onlineMode)
|
if (onlineMode)
|
||||||
{
|
{
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
|
@ -160,9 +160,9 @@ public class Command_potion extends FreedomCommand
|
|||||||
target.addPotionEffect(new_effect, true);
|
target.addPotionEffect(new_effect, true);
|
||||||
msg(
|
msg(
|
||||||
"Added potion effect: " + new_effect.getType().getName()
|
"Added potion effect: " + new_effect.getType().getName()
|
||||||
+ ", Duration: " + new_effect.getDuration()
|
+ ", Duration: " + new_effect.getDuration()
|
||||||
+ ", Amplifier: " + new_effect.getAmplifier()
|
+ ", Amplifier: " + new_effect.getAmplifier()
|
||||||
+ (!target.equals(playerSender) ? " to player " + target.getName() + "." : " to yourself."), ChatColor.AQUA);
|
+ (!target.equals(playerSender) ? " to player " + target.getName() + "." : " to yourself."), ChatColor.AQUA);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public class Command_premium extends FreedomCommand
|
|||||||
final URLConnection urlConnection = getUrl.openConnection();
|
final URLConnection urlConnection = getUrl.openConnection();
|
||||||
final String message;
|
final String message;
|
||||||
try ( // Read the response
|
try ( // Read the response
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())))
|
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())))
|
||||||
{
|
{
|
||||||
message = (!"PREMIUM".equalsIgnoreCase(in.readLine()) ? ChatColor.RED + "No" : ChatColor.DARK_GREEN + "Yes");
|
message = (!"PREMIUM".equalsIgnoreCase(in.readLine()) ? ChatColor.RED + "No" : ChatColor.DARK_GREEN + "Yes");
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Spawn an entity.", usage = "/<command> <entitytype> [amount]", aliases="spawnentity")
|
@CommandParameters(description = "Spawn an entity.", usage = "/<command> <entitytype> [amount]", aliases = "spawnentity")
|
||||||
public class Command_spawnmob extends FreedomCommand
|
public class Command_spawnmob extends FreedomCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Quickly spectate someone.", usage = "/<command> <playername>", aliases="spec")
|
@CommandParameters(description = "Quickly spectate someone.", usage = "/<command> <playername>", aliases = "spec")
|
||||||
public class Command_spectate extends FreedomCommand
|
public class Command_spectate extends FreedomCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import static me.totalfreedom.totalfreedommod.util.FUtil.DEVELOPERS:
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
|
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Sets yourself a prefix", usage = "/<command> [-s[ave]] <set <tag..> | off | clear <player> | clearall>")
|
@CommandParameters(description = "Sets yourself a prefix", usage = "/<command> [-s[ave]] <set <tag..> | off | clear <player> | clearall>")
|
||||||
|
@ -17,9 +17,9 @@ public class Command_tagnyan extends FreedomCommand
|
|||||||
{
|
{
|
||||||
|
|
||||||
public static final List<String> FORBIDDEN_WORDS = Arrays.asList(new String[]
|
public static final List<String> FORBIDDEN_WORDS = Arrays.asList(new String[]
|
||||||
{
|
{
|
||||||
"admin", "owner", "moderator", "developer", "console", "SRA", "TCA", "SA"
|
"admin", "owner", "moderator", "developer", "console", "SRA", "TCA", "SA"
|
||||||
});
|
});
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
|
@ -20,7 +20,8 @@ public class Command_vanish extends FreedomCommand
|
|||||||
{
|
{
|
||||||
public static ArrayList<Player> VANISHED = new ArrayList<>();
|
public static ArrayList<Player> VANISHED = new ArrayList<>();
|
||||||
|
|
||||||
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole) {
|
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole)
|
||||||
|
{
|
||||||
Displayable display = plugin.rm.getDisplay(playerSender);
|
Displayable display = plugin.rm.getDisplay(playerSender);
|
||||||
String loginMsg = display.getColoredLoginMessage();
|
String loginMsg = display.getColoredLoginMessage();
|
||||||
String displayName = display.getColor() + playerSender.getName();
|
String displayName = display.getColor() + playerSender.getName();
|
||||||
|
@ -52,7 +52,8 @@ public class HTTPDaemon extends FreedomService
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
port = ConfigEntry.HTTPD_PORT.getInteger();;
|
port = ConfigEntry.HTTPD_PORT.getInteger();
|
||||||
|
;
|
||||||
httpd = new HTTPD(port);
|
httpd = new HTTPD(port);
|
||||||
|
|
||||||
// Modules
|
// Modules
|
||||||
|
@ -239,7 +239,8 @@ public abstract class NanoHTTPD
|
|||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
} while (!myServerSocket.isClosed());
|
}
|
||||||
|
while (!myServerSocket.isClosed());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
myThread.setDaemon(true);
|
myThread.setDaemon(true);
|
||||||
@ -284,15 +285,15 @@ public abstract class NanoHTTPD
|
|||||||
* <p/>
|
* <p/>
|
||||||
* (By default, this delegates to serveFile() and allows directory listing.)
|
* (By default, this delegates to serveFile() and allows directory listing.)
|
||||||
*
|
*
|
||||||
* @param uri Percent-decoded URI without parameters, for example "/index.cgi"
|
* @param uri Percent-decoded URI without parameters, for example "/index.cgi"
|
||||||
* @param method "GET", "POST" etc.
|
* @param method "GET", "POST" etc.
|
||||||
* @param parms Parsed, percent decoded parameters from URI and, in case of POST, data.
|
* @param parms Parsed, percent decoded parameters from URI and, in case of POST, data.
|
||||||
* @param headers Header entries, percent decoded
|
* @param headers Header entries, percent decoded
|
||||||
* @return HTTP response, see class Response for details
|
* @return HTTP response, see class Response for details
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Response serve(String uri, Method method, Map<String, String> headers, Map<String, String> parms,
|
public Response serve(String uri, Method method, Map<String, String> headers, Map<String, String> parms,
|
||||||
Map<String, String> files)
|
Map<String, String> files)
|
||||||
{
|
{
|
||||||
return new Response(Response.Status.NOT_FOUND, MIME_PLAINTEXT, "Not Found");
|
return new Response(Response.Status.NOT_FOUND, MIME_PLAINTEXT, "Not Found");
|
||||||
}
|
}
|
||||||
@ -397,6 +398,7 @@ public abstract class NanoHTTPD
|
|||||||
// Threading Strategy.
|
// Threading Strategy.
|
||||||
//
|
//
|
||||||
// ------------------------------------------------------------------------------- //
|
// ------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pluggable strategy for asynchronously executing requests.
|
* Pluggable strategy for asynchronously executing requests.
|
||||||
*
|
*
|
||||||
@ -412,6 +414,7 @@ public abstract class NanoHTTPD
|
|||||||
// Temp file handling strategy.
|
// Temp file handling strategy.
|
||||||
//
|
//
|
||||||
// ------------------------------------------------------------------------------- //
|
// ------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pluggable strategy for creating and cleaning up temporary files.
|
* Pluggable strategy for creating and cleaning up temporary files.
|
||||||
*
|
*
|
||||||
@ -462,6 +465,7 @@ public abstract class NanoHTTPD
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------- //
|
// ------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Temp file manager.
|
* Temp file manager.
|
||||||
* <p/>
|
* <p/>
|
||||||
@ -823,9 +827,9 @@ public abstract class NanoHTTPD
|
|||||||
{
|
{
|
||||||
|
|
||||||
OK(200, "OK"), CREATED(201, "Created"), ACCEPTED(202, "Accepted"), NO_CONTENT(204, "No Content"), PARTIAL_CONTENT(206, "Partial Content"), REDIRECT(301,
|
OK(200, "OK"), CREATED(201, "Created"), ACCEPTED(202, "Accepted"), NO_CONTENT(204, "No Content"), PARTIAL_CONTENT(206, "Partial Content"), REDIRECT(301,
|
||||||
"Moved Permanently"), NOT_MODIFIED(304, "Not Modified"), BAD_REQUEST(400, "Bad Request"), UNAUTHORIZED(401,
|
"Moved Permanently"), NOT_MODIFIED(304, "Not Modified"), BAD_REQUEST(400, "Bad Request"), UNAUTHORIZED(401,
|
||||||
"Unauthorized"), FORBIDDEN(403, "Forbidden"), NOT_FOUND(404, "Not Found"), RANGE_NOT_SATISFIABLE(416,
|
"Unauthorized"), FORBIDDEN(403, "Forbidden"), NOT_FOUND(404, "Not Found"), RANGE_NOT_SATISFIABLE(416,
|
||||||
"Requested Range Not Satisfiable"), INTERNAL_ERROR(500, "Internal Server Error");
|
"Requested Range Not Satisfiable"), INTERNAL_ERROR(500, "Internal Server Error");
|
||||||
private final int requestStatus;
|
private final int requestStatus;
|
||||||
private final String description;
|
private final String description;
|
||||||
|
|
||||||
@ -1181,7 +1185,7 @@ public abstract class NanoHTTPD
|
|||||||
* Decodes the Multipart Body data and put it into Key/Value pairs.
|
* Decodes the Multipart Body data and put it into Key/Value pairs.
|
||||||
*/
|
*/
|
||||||
private void decodeMultipartData(String boundary, ByteBuffer fbuf, BufferedReader in, Map<String, String> parms,
|
private void decodeMultipartData(String boundary, ByteBuffer fbuf, BufferedReader in, Map<String, String> parms,
|
||||||
Map<String, String> files) throws ResponseException
|
Map<String, String> files) throws ResponseException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -1261,7 +1265,8 @@ public abstract class NanoHTTPD
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
mpline = in.readLine();
|
mpline = in.readLine();
|
||||||
} while (mpline != null && !mpline.contains(boundary));
|
}
|
||||||
|
while (mpline != null && !mpline.contains(boundary));
|
||||||
}
|
}
|
||||||
parms.put(pname, value);
|
parms.put(pname, value);
|
||||||
}
|
}
|
||||||
@ -1544,8 +1549,8 @@ public abstract class NanoHTTPD
|
|||||||
/**
|
/**
|
||||||
* Sets a cookie.
|
* Sets a cookie.
|
||||||
*
|
*
|
||||||
* @param name The cookie's name.
|
* @param name The cookie's name.
|
||||||
* @param value The cookie's value.
|
* @param value The cookie's value.
|
||||||
* @param expires How many days until the cookie expires.
|
* @param expires How many days until the cookie expires.
|
||||||
*/
|
*/
|
||||||
public void set(String name, String value, int expires)
|
public void set(String name, String value, int expires)
|
||||||
|
@ -42,7 +42,7 @@ public class Module_help extends HTTPDModule
|
|||||||
final StringBuilder responseBody = new StringBuilder()
|
final StringBuilder responseBody = new StringBuilder()
|
||||||
.append(heading("Command Help", 1))
|
.append(heading("Command Help", 1))
|
||||||
.append(paragraph(
|
.append(paragraph(
|
||||||
"This page is an automatically generated listing of all plugin commands that are currently live on the server. "
|
"This page is an automatically generated listing of all plugin commands that are currently live on the server. "
|
||||||
+ "Please note that it does not include vanilla server commands."));
|
+ "Please note that it does not include vanilla server commands."));
|
||||||
|
|
||||||
final Collection<Command> knownCommands = ((SimpleCommandMap) map).getCommands();
|
final Collection<Command> knownCommands = ((SimpleCommandMap) map).getCommands();
|
||||||
@ -102,19 +102,19 @@ public class Module_help extends HTTPDModule
|
|||||||
|
|
||||||
sb.append(
|
sb.append(
|
||||||
"<li><span class=\"commandName\">{$CMD_NAME}</span> - Usage: <span class=\"commandUsage\">{$CMD_USAGE}</span>"
|
"<li><span class=\"commandName\">{$CMD_NAME}</span> - Usage: <span class=\"commandUsage\">{$CMD_USAGE}</span>"
|
||||||
.replace("{$CMD_NAME}", escapeHtml4(command.getName().trim()))
|
.replace("{$CMD_NAME}", escapeHtml4(command.getName().trim()))
|
||||||
.replace("{$CMD_USAGE}", escapeHtml4(command.getUsage().trim())));
|
.replace("{$CMD_USAGE}", escapeHtml4(command.getUsage().trim())));
|
||||||
|
|
||||||
if (!command.getAliases().isEmpty())
|
if (!command.getAliases().isEmpty())
|
||||||
{
|
{
|
||||||
sb.append(
|
sb.append(
|
||||||
" - Aliases: <span class=\"commandAliases\">{$CMD_ALIASES}</span>"
|
" - Aliases: <span class=\"commandAliases\">{$CMD_ALIASES}</span>"
|
||||||
.replace("{$CMD_ALIASES}", escapeHtml4(StringUtils.join(command.getAliases(), ", "))));
|
.replace("{$CMD_ALIASES}", escapeHtml4(StringUtils.join(command.getAliases(), ", "))));
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append(
|
sb.append(
|
||||||
"<br><span class=\"commandDescription\">{$CMD_DESC}</span></li>\r\n"
|
"<br><span class=\"commandDescription\">{$CMD_DESC}</span></li>\r\n"
|
||||||
.replace("{$CMD_DESC}", escapeHtml4(command.getDescription().trim())));
|
.replace("{$CMD_DESC}", escapeHtml4(command.getDescription().trim())));
|
||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,10 @@ public class Module_logfile extends HTTPDModule
|
|||||||
|
|
||||||
private static final File LOG_FOLDER = new File("./logs/");
|
private static final File LOG_FOLDER = new File("./logs/");
|
||||||
private static final String[] LOG_FILTER = new String[]
|
private static final String[] LOG_FILTER = new String[]
|
||||||
{
|
{
|
||||||
"log",
|
"log",
|
||||||
"gz"
|
"gz"
|
||||||
};
|
};
|
||||||
|
|
||||||
public Module_logfile(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
|
public Module_logfile(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
|
||||||
{
|
{
|
||||||
|
@ -30,9 +30,9 @@ public class Module_schematic extends HTTPDModule
|
|||||||
private static final String REQUEST_FORM_FILE_ELEMENT_NAME = "schematicFile";
|
private static final String REQUEST_FORM_FILE_ELEMENT_NAME = "schematicFile";
|
||||||
private static final Pattern SCHEMATIC_FILENAME_LC = Pattern.compile("^[a-z0-9_'!,\\-]{1,30}\\.schematic$");
|
private static final Pattern SCHEMATIC_FILENAME_LC = Pattern.compile("^[a-z0-9_'!,\\-]{1,30}\\.schematic$");
|
||||||
private static final String[] SCHEMATIC_FILTER = new String[]
|
private static final String[] SCHEMATIC_FILTER = new String[]
|
||||||
{
|
{
|
||||||
"schematic"
|
"schematic"
|
||||||
};
|
};
|
||||||
private static final String UPLOAD_FORM = "<form method=\"post\" name=\"schematicForm\" id=\"schematicForm\" action=\"/schematic/upload/\" enctype=\"multipart/form-data\">\n"
|
private static final String UPLOAD_FORM = "<form method=\"post\" name=\"schematicForm\" id=\"schematicForm\" action=\"/schematic/upload/\" enctype=\"multipart/form-data\">\n"
|
||||||
+ "<p>Select a schematic file to upload. Filenames must be alphanumeric, between 1 and 30 characters long (inclusive), and have a .schematic extension.</p>\n"
|
+ "<p>Select a schematic file to upload. Filenames must be alphanumeric, between 1 and 30 characters long (inclusive), and have a .schematic extension.</p>\n"
|
||||||
+ "<input type=\"file\" id=\"schematicFile\" name=\"schematicFile\" />\n"
|
+ "<input type=\"file\" id=\"schematicFile\" name=\"schematicFile\" />\n"
|
||||||
|
@ -81,7 +81,7 @@ public class MasterBuilderList extends FreedomService
|
|||||||
}
|
}
|
||||||
|
|
||||||
masterBuilders.put(key, masterBuilder);
|
masterBuilders.put(key, masterBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTables();
|
updateTables();
|
||||||
FLog.info("Loaded " + masterBuilders.size() + " master builders with " + ipTable.size() + " IPs)");
|
FLog.info("Loaded " + masterBuilders.size() + " master builders with " + ipTable.size() + " IPs)");
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
package me.totalfreedom.totalfreedommod.punishments;
|
package me.totalfreedom.totalfreedommod.punishments;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -163,12 +163,12 @@ public class FUtil
|
|||||||
{
|
{
|
||||||
Pattern timePattern = Pattern.compile(
|
Pattern timePattern = Pattern.compile(
|
||||||
"(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?"
|
"(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?"
|
||||||
+ "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?"
|
+ "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?"
|
||||||
+ "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?"
|
+ "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?"
|
||||||
+ "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?"
|
+ "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?"
|
||||||
+ "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?"
|
+ "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?"
|
||||||
+ "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?"
|
+ "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?"
|
||||||
+ "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE);
|
+ "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE);
|
||||||
Matcher m = timePattern.matcher(time);
|
Matcher m = timePattern.matcher(time);
|
||||||
int years = 0;
|
int years = 0;
|
||||||
int months = 0;
|
int months = 0;
|
||||||
@ -362,7 +362,8 @@ public class FUtil
|
|||||||
catch (NoSuchFieldException | IllegalAccessException ex)
|
catch (NoSuchFieldException | IllegalAccessException ex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
} while (checkClass.getSuperclass() != Object.class
|
}
|
||||||
|
while (checkClass.getSuperclass() != Object.class
|
||||||
&& ((checkClass = checkClass.getSuperclass()) != null));
|
&& ((checkClass = checkClass.getSuperclass()) != null));
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -64,7 +64,6 @@ public class Flatlands extends CustomWorld
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void wipeFlatlandsIfFlagged()
|
public void wipeFlatlandsIfFlagged()
|
||||||
{
|
{
|
||||||
boolean doFlatlandsWipe = false;
|
boolean doFlatlandsWipe = false;
|
||||||
|
@ -30,20 +30,24 @@ import java.util.zip.GZIPOutputStream;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* bStats collects some data for plugin authors.
|
* bStats collects some data for plugin authors.
|
||||||
*
|
* <p>
|
||||||
* Check out https://bStats.org/ to learn more about bStats!
|
* Check out https://bStats.org/ to learn more about bStats!
|
||||||
*/
|
*/
|
||||||
public class Metrics {
|
public class Metrics
|
||||||
|
{
|
||||||
|
|
||||||
static {
|
static
|
||||||
|
{
|
||||||
// You can use the property to disable the check in your test environment
|
// You can use the property to disable the check in your test environment
|
||||||
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
|
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false"))
|
||||||
|
{
|
||||||
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
|
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
|
||||||
final String defaultPackage = new String(
|
final String defaultPackage = new String(
|
||||||
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
|
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
|
||||||
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
||||||
// We want to make sure nobody just copy & pastes the example and use the wrong package names
|
// We want to make sure nobody just copy & pastes the example and use the wrong package names
|
||||||
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
|
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage))
|
||||||
|
{
|
||||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -72,8 +76,10 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @param plugin The plugin which stats should be submitted.
|
* @param plugin The plugin which stats should be submitted.
|
||||||
*/
|
*/
|
||||||
public Metrics(JavaPlugin plugin) {
|
public Metrics(JavaPlugin plugin)
|
||||||
if (plugin == null) {
|
{
|
||||||
|
if (plugin == null)
|
||||||
|
{
|
||||||
throw new IllegalArgumentException("Plugin cannot be null!");
|
throw new IllegalArgumentException("Plugin cannot be null!");
|
||||||
}
|
}
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -84,7 +90,8 @@ public class Metrics {
|
|||||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
|
||||||
// Check if the config file exists
|
// Check if the config file exists
|
||||||
if (!config.isSet("serverUuid")) {
|
if (!config.isSet("serverUuid"))
|
||||||
|
{
|
||||||
|
|
||||||
// Add default values
|
// Add default values
|
||||||
config.addDefault("enabled", true);
|
config.addDefault("enabled", true);
|
||||||
@ -100,27 +107,38 @@ public class Metrics {
|
|||||||
"This has nearly no effect on the server performance!\n" +
|
"This has nearly no effect on the server performance!\n" +
|
||||||
"Check out https://bStats.org/ to learn more :)"
|
"Check out https://bStats.org/ to learn more :)"
|
||||||
).copyDefaults(true);
|
).copyDefaults(true);
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
config.save(configFile);
|
config.save(configFile);
|
||||||
} catch (IOException ignored) { }
|
}
|
||||||
|
catch (IOException ignored)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the data
|
// Load the data
|
||||||
serverUUID = config.getString("serverUuid");
|
serverUUID = config.getString("serverUuid");
|
||||||
logFailedRequests = config.getBoolean("logFailedRequests", false);
|
logFailedRequests = config.getBoolean("logFailedRequests", false);
|
||||||
if (config.getBoolean("enabled", true)) {
|
if (config.getBoolean("enabled", true))
|
||||||
|
{
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
// Search for all other bStats Metrics classes to see if we are the first one
|
// Search for all other bStats Metrics classes to see if we are the first one
|
||||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
for (Class<?> service : Bukkit.getServicesManager().getKnownServices())
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||||
found = true; // We aren't the first
|
found = true; // We aren't the first
|
||||||
break;
|
break;
|
||||||
} catch (NoSuchFieldException ignored) { }
|
}
|
||||||
|
catch (NoSuchFieldException ignored)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Register our service
|
// Register our service
|
||||||
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
|
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
|
||||||
if (!found) {
|
if (!found)
|
||||||
|
{
|
||||||
// We are the first!
|
// We are the first!
|
||||||
startSubmitting();
|
startSubmitting();
|
||||||
}
|
}
|
||||||
@ -132,8 +150,10 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @param chart The chart to add.
|
* @param chart The chart to add.
|
||||||
*/
|
*/
|
||||||
public void addCustomChart(CustomChart chart) {
|
public void addCustomChart(CustomChart chart)
|
||||||
if (chart == null) {
|
{
|
||||||
|
if (chart == null)
|
||||||
|
{
|
||||||
throw new IllegalArgumentException("Chart cannot be null!");
|
throw new IllegalArgumentException("Chart cannot be null!");
|
||||||
}
|
}
|
||||||
charts.add(chart);
|
charts.add(chart);
|
||||||
@ -142,25 +162,31 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Starts the Scheduler which submits our data every 30 minutes.
|
* Starts the Scheduler which submits our data every 30 minutes.
|
||||||
*/
|
*/
|
||||||
private void startSubmitting() {
|
private void startSubmitting()
|
||||||
|
{
|
||||||
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
|
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
|
||||||
timer.scheduleAtFixedRate(new TimerTask() {
|
timer.scheduleAtFixedRate(new TimerTask()
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run()
|
||||||
if (!plugin.isEnabled()) { // Plugin was disabled
|
{
|
||||||
|
if (!plugin.isEnabled())
|
||||||
|
{ // Plugin was disabled
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
|
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
|
||||||
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
|
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
|
||||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
Bukkit.getScheduler().runTask(plugin, new Runnable()
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run()
|
||||||
|
{
|
||||||
submitData();
|
submitData();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, 1000*60*5, 1000*60*30);
|
}, 1000 * 60 * 5, 1000 * 60 * 30);
|
||||||
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
|
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
|
||||||
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
|
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
|
||||||
// WARNING: Just don't do it!
|
// WARNING: Just don't do it!
|
||||||
@ -172,7 +198,8 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @return The plugin specific data.
|
* @return The plugin specific data.
|
||||||
*/
|
*/
|
||||||
public JSONObject getPluginData() {
|
public JSONObject getPluginData()
|
||||||
|
{
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
|
|
||||||
String pluginName = plugin.getDescription().getName();
|
String pluginName = plugin.getDescription().getName();
|
||||||
@ -181,10 +208,12 @@ public class Metrics {
|
|||||||
data.put("pluginName", pluginName); // Append the name of the plugin
|
data.put("pluginName", pluginName); // Append the name of the plugin
|
||||||
data.put("pluginVersion", pluginVersion); // Append the version of the plugin
|
data.put("pluginVersion", pluginVersion); // Append the version of the plugin
|
||||||
JSONArray customCharts = new JSONArray();
|
JSONArray customCharts = new JSONArray();
|
||||||
for (CustomChart customChart : charts) {
|
for (CustomChart customChart : charts)
|
||||||
|
{
|
||||||
// Add the data of the custom charts
|
// Add the data of the custom charts
|
||||||
JSONObject chart = customChart.getRequestJsonObject();
|
JSONObject chart = customChart.getRequestJsonObject();
|
||||||
if (chart == null) { // If the chart is null, we skip it
|
if (chart == null)
|
||||||
|
{ // If the chart is null, we skip it
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
customCharts.add(chart);
|
customCharts.add(chart);
|
||||||
@ -199,17 +228,21 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @return The server specific data.
|
* @return The server specific data.
|
||||||
*/
|
*/
|
||||||
private JSONObject getServerData() {
|
private JSONObject getServerData()
|
||||||
|
{
|
||||||
// Minecraft specific data
|
// Minecraft specific data
|
||||||
int playerAmount;
|
int playerAmount;
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
// Around MC 1.8 the return type was changed to a collection from an array,
|
// Around MC 1.8 the return type was changed to a collection from an array,
|
||||||
// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
||||||
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
||||||
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
|
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
|
||||||
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
||||||
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
|
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
|
||||||
}
|
}
|
||||||
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
|
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
|
||||||
@ -243,35 +276,52 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Collects the data and sends it afterwards.
|
* Collects the data and sends it afterwards.
|
||||||
*/
|
*/
|
||||||
private void submitData() {
|
private void submitData()
|
||||||
|
{
|
||||||
final JSONObject data = getServerData();
|
final JSONObject data = getServerData();
|
||||||
|
|
||||||
JSONArray pluginData = new JSONArray();
|
JSONArray pluginData = new JSONArray();
|
||||||
// Search for all other bStats Metrics classes to get their plugin data
|
// Search for all other bStats Metrics classes to get their plugin data
|
||||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
for (Class<?> service : Bukkit.getServicesManager().getKnownServices())
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||||
|
|
||||||
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
|
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service))
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider()));
|
pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider()));
|
||||||
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
|
}
|
||||||
|
catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (NoSuchFieldException ignored) { }
|
}
|
||||||
|
catch (NoSuchFieldException ignored)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data.put("plugins", pluginData);
|
data.put("plugins", pluginData);
|
||||||
|
|
||||||
// Create a new thread for the connection to the bStats server
|
// Create a new thread for the connection to the bStats server
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable()
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run()
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
// Send the data
|
// Send the data
|
||||||
sendData(data);
|
sendData(data);
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
// Something went wrong! :(
|
// Something went wrong! :(
|
||||||
if (logFailedRequests) {
|
if (logFailedRequests)
|
||||||
|
{
|
||||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -285,11 +335,14 @@ public class Metrics {
|
|||||||
* @param data The data to send.
|
* @param data The data to send.
|
||||||
* @throws Exception If the request failed.
|
* @throws Exception If the request failed.
|
||||||
*/
|
*/
|
||||||
private static void sendData(JSONObject data) throws Exception {
|
private static void sendData(JSONObject data) throws Exception
|
||||||
if (data == null) {
|
{
|
||||||
|
if (data == null)
|
||||||
|
{
|
||||||
throw new IllegalArgumentException("Data cannot be null!");
|
throw new IllegalArgumentException("Data cannot be null!");
|
||||||
}
|
}
|
||||||
if (Bukkit.isPrimaryThread()) {
|
if (Bukkit.isPrimaryThread())
|
||||||
|
{
|
||||||
throw new IllegalAccessException("This method must not be called from the main thread!");
|
throw new IllegalAccessException("This method must not be called from the main thread!");
|
||||||
}
|
}
|
||||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||||
@ -323,8 +376,10 @@ public class Metrics {
|
|||||||
* @return The gzipped String.
|
* @return The gzipped String.
|
||||||
* @throws IOException If the compression failed.
|
* @throws IOException If the compression failed.
|
||||||
*/
|
*/
|
||||||
private static byte[] compress(final String str) throws IOException {
|
private static byte[] compress(final String str) throws IOException
|
||||||
if (str == null) {
|
{
|
||||||
|
if (str == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
@ -337,7 +392,8 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Represents a custom chart.
|
* Represents a custom chart.
|
||||||
*/
|
*/
|
||||||
public static abstract class CustomChart {
|
public static abstract class CustomChart
|
||||||
|
{
|
||||||
|
|
||||||
// The id of the chart
|
// The id of the chart
|
||||||
final String chartId;
|
final String chartId;
|
||||||
@ -347,25 +403,33 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @param chartId The id of the chart.
|
* @param chartId The id of the chart.
|
||||||
*/
|
*/
|
||||||
CustomChart(String chartId) {
|
CustomChart(String chartId)
|
||||||
if (chartId == null || chartId.isEmpty()) {
|
{
|
||||||
|
if (chartId == null || chartId.isEmpty())
|
||||||
|
{
|
||||||
throw new IllegalArgumentException("ChartId cannot be null or empty!");
|
throw new IllegalArgumentException("ChartId cannot be null or empty!");
|
||||||
}
|
}
|
||||||
this.chartId = chartId;
|
this.chartId = chartId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject getRequestJsonObject() {
|
private JSONObject getRequestJsonObject()
|
||||||
|
{
|
||||||
JSONObject chart = new JSONObject();
|
JSONObject chart = new JSONObject();
|
||||||
chart.put("chartId", chartId);
|
chart.put("chartId", chartId);
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
JSONObject data = getChartData();
|
JSONObject data = getChartData();
|
||||||
if (data == null) {
|
if (data == null)
|
||||||
|
{
|
||||||
// If the data is null we don't send the chart.
|
// If the data is null we don't send the chart.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
chart.put("data", data);
|
chart.put("data", data);
|
||||||
} catch (Throwable t) {
|
}
|
||||||
if (logFailedRequests) {
|
catch (Throwable t)
|
||||||
|
{
|
||||||
|
if (logFailedRequests)
|
||||||
|
{
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
|
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -380,26 +444,30 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Represents a custom simple pie.
|
* Represents a custom simple pie.
|
||||||
*/
|
*/
|
||||||
public static class SimplePie extends CustomChart {
|
public static class SimplePie extends CustomChart
|
||||||
|
{
|
||||||
|
|
||||||
private final Callable<String> callable;
|
private final Callable<String> callable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param chartId The id of the chart.
|
* @param chartId The id of the chart.
|
||||||
* @param callable The callable which is used to request the chart data.
|
* @param callable The callable which is used to request the chart data.
|
||||||
*/
|
*/
|
||||||
public SimplePie(String chartId, Callable<String> callable) {
|
public SimplePie(String chartId, Callable<String> callable)
|
||||||
|
{
|
||||||
super(chartId);
|
super(chartId);
|
||||||
this.callable = callable;
|
this.callable = callable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JSONObject getChartData() throws Exception {
|
protected JSONObject getChartData() throws Exception
|
||||||
|
{
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
String value = callable.call();
|
String value = callable.call();
|
||||||
if (value == null || value.isEmpty()) {
|
if (value == null || value.isEmpty())
|
||||||
|
{
|
||||||
// Null = skip the chart
|
// Null = skip the chart
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -411,39 +479,46 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Represents a custom advanced pie.
|
* Represents a custom advanced pie.
|
||||||
*/
|
*/
|
||||||
public static class AdvancedPie extends CustomChart {
|
public static class AdvancedPie extends CustomChart
|
||||||
|
{
|
||||||
|
|
||||||
private final Callable<Map<String, Integer>> callable;
|
private final Callable<Map<String, Integer>> callable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param chartId The id of the chart.
|
* @param chartId The id of the chart.
|
||||||
* @param callable The callable which is used to request the chart data.
|
* @param callable The callable which is used to request the chart data.
|
||||||
*/
|
*/
|
||||||
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
|
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable)
|
||||||
|
{
|
||||||
super(chartId);
|
super(chartId);
|
||||||
this.callable = callable;
|
this.callable = callable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JSONObject getChartData() throws Exception {
|
protected JSONObject getChartData() throws Exception
|
||||||
|
{
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
JSONObject values = new JSONObject();
|
JSONObject values = new JSONObject();
|
||||||
Map<String, Integer> map = callable.call();
|
Map<String, Integer> map = callable.call();
|
||||||
if (map == null || map.isEmpty()) {
|
if (map == null || map.isEmpty())
|
||||||
|
{
|
||||||
// Null = skip the chart
|
// Null = skip the chart
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
boolean allSkipped = true;
|
boolean allSkipped = true;
|
||||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
for (Map.Entry<String, Integer> entry : map.entrySet())
|
||||||
if (entry.getValue() == 0) {
|
{
|
||||||
|
if (entry.getValue() == 0)
|
||||||
|
{
|
||||||
continue; // Skip this invalid
|
continue; // Skip this invalid
|
||||||
}
|
}
|
||||||
allSkipped = false;
|
allSkipped = false;
|
||||||
values.put(entry.getKey(), entry.getValue());
|
values.put(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
if (allSkipped) {
|
if (allSkipped)
|
||||||
|
{
|
||||||
// Null = skip the chart
|
// Null = skip the chart
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -455,44 +530,52 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Represents a custom drilldown pie.
|
* Represents a custom drilldown pie.
|
||||||
*/
|
*/
|
||||||
public static class DrilldownPie extends CustomChart {
|
public static class DrilldownPie extends CustomChart
|
||||||
|
{
|
||||||
|
|
||||||
private final Callable<Map<String, Map<String, Integer>>> callable;
|
private final Callable<Map<String, Map<String, Integer>>> callable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param chartId The id of the chart.
|
* @param chartId The id of the chart.
|
||||||
* @param callable The callable which is used to request the chart data.
|
* @param callable The callable which is used to request the chart data.
|
||||||
*/
|
*/
|
||||||
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
|
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable)
|
||||||
|
{
|
||||||
super(chartId);
|
super(chartId);
|
||||||
this.callable = callable;
|
this.callable = callable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject getChartData() throws Exception {
|
public JSONObject getChartData() throws Exception
|
||||||
|
{
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
JSONObject values = new JSONObject();
|
JSONObject values = new JSONObject();
|
||||||
Map<String, Map<String, Integer>> map = callable.call();
|
Map<String, Map<String, Integer>> map = callable.call();
|
||||||
if (map == null || map.isEmpty()) {
|
if (map == null || map.isEmpty())
|
||||||
|
{
|
||||||
// Null = skip the chart
|
// Null = skip the chart
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
boolean reallyAllSkipped = true;
|
boolean reallyAllSkipped = true;
|
||||||
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
|
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet())
|
||||||
|
{
|
||||||
JSONObject value = new JSONObject();
|
JSONObject value = new JSONObject();
|
||||||
boolean allSkipped = true;
|
boolean allSkipped = true;
|
||||||
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
|
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet())
|
||||||
|
{
|
||||||
value.put(valueEntry.getKey(), valueEntry.getValue());
|
value.put(valueEntry.getKey(), valueEntry.getValue());
|
||||||
allSkipped = false;
|
allSkipped = false;
|
||||||
}
|
}
|
||||||
if (!allSkipped) {
|
if (!allSkipped)
|
||||||
|
{
|
||||||
reallyAllSkipped = false;
|
reallyAllSkipped = false;
|
||||||
values.put(entryValues.getKey(), value);
|
values.put(entryValues.getKey(), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (reallyAllSkipped) {
|
if (reallyAllSkipped)
|
||||||
|
{
|
||||||
// Null = skip the chart
|
// Null = skip the chart
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -504,26 +587,30 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Represents a custom single line chart.
|
* Represents a custom single line chart.
|
||||||
*/
|
*/
|
||||||
public static class SingleLineChart extends CustomChart {
|
public static class SingleLineChart extends CustomChart
|
||||||
|
{
|
||||||
|
|
||||||
private final Callable<Integer> callable;
|
private final Callable<Integer> callable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param chartId The id of the chart.
|
* @param chartId The id of the chart.
|
||||||
* @param callable The callable which is used to request the chart data.
|
* @param callable The callable which is used to request the chart data.
|
||||||
*/
|
*/
|
||||||
public SingleLineChart(String chartId, Callable<Integer> callable) {
|
public SingleLineChart(String chartId, Callable<Integer> callable)
|
||||||
|
{
|
||||||
super(chartId);
|
super(chartId);
|
||||||
this.callable = callable;
|
this.callable = callable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JSONObject getChartData() throws Exception {
|
protected JSONObject getChartData() throws Exception
|
||||||
|
{
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
int value = callable.call();
|
int value = callable.call();
|
||||||
if (value == 0) {
|
if (value == 0)
|
||||||
|
{
|
||||||
// Null = skip the chart
|
// Null = skip the chart
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -536,39 +623,46 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Represents a custom multi line chart.
|
* Represents a custom multi line chart.
|
||||||
*/
|
*/
|
||||||
public static class MultiLineChart extends CustomChart {
|
public static class MultiLineChart extends CustomChart
|
||||||
|
{
|
||||||
|
|
||||||
private final Callable<Map<String, Integer>> callable;
|
private final Callable<Map<String, Integer>> callable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param chartId The id of the chart.
|
* @param chartId The id of the chart.
|
||||||
* @param callable The callable which is used to request the chart data.
|
* @param callable The callable which is used to request the chart data.
|
||||||
*/
|
*/
|
||||||
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
|
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable)
|
||||||
|
{
|
||||||
super(chartId);
|
super(chartId);
|
||||||
this.callable = callable;
|
this.callable = callable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JSONObject getChartData() throws Exception {
|
protected JSONObject getChartData() throws Exception
|
||||||
|
{
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
JSONObject values = new JSONObject();
|
JSONObject values = new JSONObject();
|
||||||
Map<String, Integer> map = callable.call();
|
Map<String, Integer> map = callable.call();
|
||||||
if (map == null || map.isEmpty()) {
|
if (map == null || map.isEmpty())
|
||||||
|
{
|
||||||
// Null = skip the chart
|
// Null = skip the chart
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
boolean allSkipped = true;
|
boolean allSkipped = true;
|
||||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
for (Map.Entry<String, Integer> entry : map.entrySet())
|
||||||
if (entry.getValue() == 0) {
|
{
|
||||||
|
if (entry.getValue() == 0)
|
||||||
|
{
|
||||||
continue; // Skip this invalid
|
continue; // Skip this invalid
|
||||||
}
|
}
|
||||||
allSkipped = false;
|
allSkipped = false;
|
||||||
values.put(entry.getKey(), entry.getValue());
|
values.put(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
if (allSkipped) {
|
if (allSkipped)
|
||||||
|
{
|
||||||
// Null = skip the chart
|
// Null = skip the chart
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -581,31 +675,36 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Represents a custom simple bar chart.
|
* Represents a custom simple bar chart.
|
||||||
*/
|
*/
|
||||||
public static class SimpleBarChart extends CustomChart {
|
public static class SimpleBarChart extends CustomChart
|
||||||
|
{
|
||||||
|
|
||||||
private final Callable<Map<String, Integer>> callable;
|
private final Callable<Map<String, Integer>> callable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param chartId The id of the chart.
|
* @param chartId The id of the chart.
|
||||||
* @param callable The callable which is used to request the chart data.
|
* @param callable The callable which is used to request the chart data.
|
||||||
*/
|
*/
|
||||||
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
|
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable)
|
||||||
|
{
|
||||||
super(chartId);
|
super(chartId);
|
||||||
this.callable = callable;
|
this.callable = callable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JSONObject getChartData() throws Exception {
|
protected JSONObject getChartData() throws Exception
|
||||||
|
{
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
JSONObject values = new JSONObject();
|
JSONObject values = new JSONObject();
|
||||||
Map<String, Integer> map = callable.call();
|
Map<String, Integer> map = callable.call();
|
||||||
if (map == null || map.isEmpty()) {
|
if (map == null || map.isEmpty())
|
||||||
|
{
|
||||||
// Null = skip the chart
|
// Null = skip the chart
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
for (Map.Entry<String, Integer> entry : map.entrySet())
|
||||||
|
{
|
||||||
JSONArray categoryValues = new JSONArray();
|
JSONArray categoryValues = new JSONArray();
|
||||||
categoryValues.add(entry.getValue());
|
categoryValues.add(entry.getValue());
|
||||||
values.put(entry.getKey(), categoryValues);
|
values.put(entry.getKey(), categoryValues);
|
||||||
@ -619,43 +718,51 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Represents a custom advanced bar chart.
|
* Represents a custom advanced bar chart.
|
||||||
*/
|
*/
|
||||||
public static class AdvancedBarChart extends CustomChart {
|
public static class AdvancedBarChart extends CustomChart
|
||||||
|
{
|
||||||
|
|
||||||
private final Callable<Map<String, int[]>> callable;
|
private final Callable<Map<String, int[]>> callable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param chartId The id of the chart.
|
* @param chartId The id of the chart.
|
||||||
* @param callable The callable which is used to request the chart data.
|
* @param callable The callable which is used to request the chart data.
|
||||||
*/
|
*/
|
||||||
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
|
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable)
|
||||||
|
{
|
||||||
super(chartId);
|
super(chartId);
|
||||||
this.callable = callable;
|
this.callable = callable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JSONObject getChartData() throws Exception {
|
protected JSONObject getChartData() throws Exception
|
||||||
|
{
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
JSONObject values = new JSONObject();
|
JSONObject values = new JSONObject();
|
||||||
Map<String, int[]> map = callable.call();
|
Map<String, int[]> map = callable.call();
|
||||||
if (map == null || map.isEmpty()) {
|
if (map == null || map.isEmpty())
|
||||||
|
{
|
||||||
// Null = skip the chart
|
// Null = skip the chart
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
boolean allSkipped = true;
|
boolean allSkipped = true;
|
||||||
for (Map.Entry<String, int[]> entry : map.entrySet()) {
|
for (Map.Entry<String, int[]> entry : map.entrySet())
|
||||||
if (entry.getValue().length == 0) {
|
{
|
||||||
|
if (entry.getValue().length == 0)
|
||||||
|
{
|
||||||
continue; // Skip this invalid
|
continue; // Skip this invalid
|
||||||
}
|
}
|
||||||
allSkipped = false;
|
allSkipped = false;
|
||||||
JSONArray categoryValues = new JSONArray();
|
JSONArray categoryValues = new JSONArray();
|
||||||
for (int categoryValue : entry.getValue()) {
|
for (int categoryValue : entry.getValue())
|
||||||
|
{
|
||||||
categoryValues.add(categoryValue);
|
categoryValues.add(categoryValue);
|
||||||
}
|
}
|
||||||
values.put(entry.getKey(), categoryValues);
|
values.put(entry.getKey(), categoryValues);
|
||||||
}
|
}
|
||||||
if (allSkipped) {
|
if (allSkipped)
|
||||||
|
{
|
||||||
// Null = skip the chart
|
// Null = skip the chart
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
<!DOCTYPE suppressions PUBLIC
|
<!DOCTYPE suppressions PUBLIC
|
||||||
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
|
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
|
||||||
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
|
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
|
||||||
|
|
||||||
<suppressions>
|
<suppressions>
|
||||||
<suppress files="Metrics\.java" checks="[a-zA-Z0-9]*"/>
|
<suppress files="Metrics\.java" checks="[a-zA-Z0-9]*"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user