Adds an option to enable that all command usages (e.g. /tp and /teleport are combined to one usage)

Clarifies an if-clause
Adds JavaDoc to the MathUtils and makes the return method more compact
Updates JavaDoc in the GeolocationCacheHandler due to the commit b466edf777
Removes some unused variables
This commit is contained in:
Fuzzlemann 2017-07-25 14:40:29 +02:00
parent 29e3f18725
commit d4a524f300
7 changed files with 94 additions and 70 deletions

View File

@ -24,6 +24,7 @@ public enum Settings {
GATHERGMTIMES("Settings.Data.GamemodeChangeListener"),
GATHERCOMMANDS("Settings.Data.GatherCommandUsage"),
DO_NOT_LOG_UNKNOWN_COMMANDS("Customization.Data.DoNotLogUnknownCommands"),
COMBINE_COMMAND_ALIASES_TO_MAIN_COMMAND("Customization.Data.CombineCommandAliasesToMainCommand"),
SECURITY_IP_UUID("Settings.WebServer.Security.DisplayIPsAndUUIDs"),
GRAPH_PLAYERS_USEMAXPLAYERS_SCALE("Customization.Graphs.PlayersOnlineGraph.UseMaxPlayersAsScale"),
PLAYERLIST_SHOW_IMAGES("Customization.SmallHeadImagesOnAnalysisPlayerlist"),

View File

@ -18,6 +18,7 @@ import java.util.Map;
* This cache uses the Google Guava {@link Cache} and has a capacity of 10.000 entries.
*
* @author Fuzzlemann
* @since 3.5.5
*/
public class GeolocationCacheHandler {
private static final Cache<String, String> geolocationCache = CacheBuilder.newBuilder()
@ -33,7 +34,7 @@ public class GeolocationCacheHandler {
* @return The name of the country in full length.
* <p>
* An exception from that rule is when the country is unknown or the retrieval of the country failed in any way,
* if that happens, the phrase for unknown country set in the config will be returned.
* if that happens, "Not Known" will be returned.
* @see #getUncachedCountry(String)
*/
public static String getCountry(String ipAddress) {
@ -64,7 +65,7 @@ public class GeolocationCacheHandler {
* @return The name of the country in full length.
* <p>
* An exception from that rule is when the country is unknown or the retrieval of the country failed in any way,
* if that happens, the phrase for unknown country set in the config will be returned.
* if that happens, "Not Known" will be returned.
* @see <a href="http://freegeoip.net">http://freegeoip.net</a>
* @see #getCountry(String)
*/

View File

@ -5,12 +5,12 @@ import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.help.HelpMap;
/**
* Event Listener for PlayerCommandPreprocessEvents.
@ -43,14 +43,21 @@ public class PlanCommandPreprocessListener implements Listener {
return;
}
String cmd = event.getMessage().split(" ")[0].toLowerCase();
String commandName = event.getMessage().split(" ")[0].toLowerCase();
if (Settings.DO_NOT_LOG_UNKNOWN_COMMANDS.isTrue()) {
HelpMap helpMap = plugin.getServer().getHelpMap();
if (helpMap.getHelpTopic(cmd) == null) {
boolean doNotLogUnknownCommands = Settings.DO_NOT_LOG_UNKNOWN_COMMANDS.isTrue();
boolean combineCommandAliasesToMainCommand = Settings.COMBINE_COMMAND_ALIASES_TO_MAIN_COMMAND.isTrue();
if (doNotLogUnknownCommands || combineCommandAliasesToMainCommand) {
Command command = plugin.getServer().getPluginCommand(commandName);
if (command == null) {
if (doNotLogUnknownCommands) {
Log.debug("Ignored command, command is unknown");
return;
}
} else if (combineCommandAliasesToMainCommand) {
commandName = command.getName();
}
}
Player player = event.getPlayer();
@ -59,6 +66,6 @@ public class PlanCommandPreprocessListener implements Listener {
Log.debug("Ignored command, player had ignore permission.");
return;
}
handler.handleCommand(cmd);
handler.handleCommand(commandName);
}
}

View File

@ -47,7 +47,7 @@ public class PunchCardGraphCreator {
continue;
}
arrayBuilder.append("{").append("x:").append(j).append(", y:").append(i).append(", r:").append(value).append("}");
if (!(i == 6 && j == 23)) {
if (i != 6 || j != 23) {
arrayBuilder.append(",");
}
}

View File

@ -1,16 +1,10 @@
package main.java.com.djrapitops.plan.ui.text;
import java.util.UUID;
import main.java.com.djrapitops.plan.Phrase;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.AnalysisData;
import main.java.com.djrapitops.plan.data.UserData;
import main.java.com.djrapitops.plan.data.analysis.ActivityPart;
import main.java.com.djrapitops.plan.data.analysis.JoinInfoPart;
import main.java.com.djrapitops.plan.data.analysis.KillPart;
import main.java.com.djrapitops.plan.data.analysis.PlayerCountPart;
import main.java.com.djrapitops.plan.data.analysis.PlaytimePart;
import main.java.com.djrapitops.plan.data.analysis.TPSPart;
import main.java.com.djrapitops.plan.data.analysis.*;
import main.java.com.djrapitops.plan.data.cache.AnalysisCacheHandler;
import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler;
import main.java.com.djrapitops.plan.utilities.FormatUtils;
@ -19,6 +13,8 @@ import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
import org.bukkit.ChatColor;
import java.util.UUID;
/**
*
* @author Rsl1122
@ -68,7 +64,6 @@ public class TextUI {
AnalysisData d = analysisCache.getData();
ChatColor main = Phrase.COLOR_MAIN.color();
ChatColor sec = Phrase.COLOR_SEC.color();
ChatColor ter = Phrase.COLOR_TER.color();
String ball = sec + " " + Phrase.BALL + main;
final ActivityPart activity = d.getActivityPart();
final JoinInfoPart join = d.getJoinInfoPart();

View File

@ -8,89 +8,104 @@ import java.util.OptionalLong;
import java.util.stream.Stream;
/**
*
* @author Rsl1122
*/
public class MathUtils {
/**
* Gets the average of a Stream of Integers.
* If there are no components in the Stream, it will return 0.
*
* @param values
* @return
* @param values The Stream of Integers.
* @return The average
*/
public static double averageInt(Stream<Integer> values) {
OptionalDouble average = values.mapToInt(i -> i).average();
if (average.isPresent()) {
return average.getAsDouble();
} else {
return 0;
}
return average.isPresent() ? average.getAsDouble() : 0;
}
/**
* Gets the average of a Collection with Long as Entry.
* If the collection is empty, it will return 0.
*
* @param values
* @return
* @param values The Collection with Long as the Entry.
* @return The average
* @see #averageLong(Stream)
*/
public static long averageLong(Collection<Long> values) {
return averageLong(values.stream());
}
/**
* Gets the average of a Stream of Longs.
* If there are no components in the Stream, it will return 0.
*
* @param values
* @return
* @param values The Stream of Longs.
* @return The average
* @see #averageLong(Collection)
*/
public static long averageLong(Stream<Long> values) {
OptionalDouble average = values.mapToLong(i -> i).average();
if (average.isPresent()) {
return (long) average.getAsDouble();
} else {
return 0L;
}
return average.isPresent() ? (long) average.getAsDouble() : 0L;
}
/**
* Gets the average of a Stream of Double.
* If there are no components in the Stream, it will return 0.
*
* @param values
* @return
* @param values The Stream of Double.
* @return The average
*/
public static double averageDouble(Stream<Double> values) {
OptionalDouble average = values.mapToDouble(i -> i).average();
if (average.isPresent()) {
return average.getAsDouble();
} else {
return 0;
}
return average.isPresent() ? average.getAsDouble() : 0;
}
/**
* Calculates the average
*
* @param total
* @param size
* @return
* @param total The total summed amount of all Integers
* @param size The amount of all Integers that were summed
* @return The average
* @see #averageLong(long, long)
*/
public static double average(int total, int size) {
return 1.0 * total / size;
return (double) total / size;
}
/**
* Calculates the average
*
* @param total The total summed amount of all Longs
* @param size The amount of all Longs that were summed
* @return The average
* @see #average(int, int)
*/
public static long averageLong(long total, long size) {
return total / size;
}
/**
* Counts all Booleans that are true in the Stream of Booleans
*
* @param values
* @return
* @param values The Stream of Booleans
* @return The amount of Booleans that are true
*/
public static long countTrueBoolean(Stream<Boolean> values) {
return values.filter(i -> i).count();
return values.filter(value -> value).count();
}
/**
* Sums all Integers in a Stream of Serializable
*
* @param values
* @return
* @param values The Stream of Serializable
* @return The sum
* @see #sumLong(Stream)
* @see #sumDouble(Stream)
*/
public static int sumInt(Stream<Serializable> values) {
return values
@ -99,9 +114,12 @@ public class MathUtils {
}
/**
* Sums all Longs in a Stream of Serializable
*
* @param values
* @return
* @param values The Stream of Serializable
* @return The sum
* @see #sumInt(Stream)
* @see #sumDouble(Stream)
*/
public static long sumLong(Stream<Serializable> values) {
return values
@ -110,9 +128,12 @@ public class MathUtils {
}
/**
* Sums all Doubles in a Stream of Serializable
*
* @param values
* @return
* @param values The Stream of Serializable
* @return The sum
* @see #sumLong(Stream)
* @see #sumInt(Stream)
*/
public static double sumDouble(Stream<Serializable> values) {
return values
@ -121,32 +142,30 @@ public class MathUtils {
}
/**
* Gets the biggest Integer in a Collection with Integer as Entry
* If the Collection is empty, it will return 0.
*
* @param values
* @return
* @param values The Collection with Integer as the Entry
* @return The biggest Integer
* @see #getBiggestLong(Collection)
*/
public static int getBiggest(Collection<Integer> values) {
OptionalInt biggest = values.stream().mapToInt(i -> i).max();
if (biggest.isPresent()) {
return biggest.getAsInt();
} else {
return 1;
}
return biggest.isPresent() ? biggest.getAsInt() : 1;
}
/**
* Gets the biggest Long in a Collection with Long as Entry
* If the Collection is empty, it will return 0.
*
* @param values
* @return
* @param values The Collection with Long as the Entry
* @return The biggest Integer
* @see #getBiggest(Collection)
*/
public static long getBiggestLong(Collection<Long> values) {
OptionalLong biggest = values.stream().mapToLong(i -> i).max();
if (biggest.isPresent()) {
return biggest.getAsLong();
} else {
return 1;
}
return biggest.isPresent() ? biggest.getAsLong() : 1;
}
}

View File

@ -43,6 +43,7 @@ Customization:
SmallHeadImagesOnAnalysisPlayerlist: true
Data:
DoNotLogUnknownCommands: false
CombineCommandAliasesToMainCommand: false
Graphs:
PlayersOnlineGraph:
UseMaxPlayersAsScale: true