mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-04-18 18:30:31 +08:00
IntelliJ code smells
This commit is contained in:
parent
5a69797552
commit
d9fc8cb842
@ -3,7 +3,10 @@ package com.djrapitops.plan.data.store.mutators.formatting;
|
||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.utilities.Format;
|
||||
import org.apache.commons.text.TextStringBuilder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.function.Function;
|
||||
|
||||
@ -79,4 +82,13 @@ public class Formatters {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Formatter<String> itemName() {
|
||||
return name -> {
|
||||
String[] parts = name.split("_");
|
||||
TextStringBuilder builder = new TextStringBuilder();
|
||||
builder.appendWithSeparators(Arrays.stream(parts).map(part -> new Format(part).capitalize()).iterator(), " ");
|
||||
return builder.toString();
|
||||
};
|
||||
}
|
||||
}
|
@ -239,7 +239,6 @@ public abstract class SQLDB extends Database {
|
||||
private void clean() {
|
||||
tpsTable.clean();
|
||||
transferTable.clean();
|
||||
geoInfoTable.clean();
|
||||
pingTable.clean();
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
@ -59,10 +59,6 @@ public class GeoInfoTable extends UserIDTable {
|
||||
);
|
||||
}
|
||||
|
||||
public void clean() {
|
||||
|
||||
}
|
||||
|
||||
public List<GeoInfo> getGeoInfo(UUID uuid) {
|
||||
String sql = "SELECT DISTINCT * FROM " + tableName +
|
||||
" WHERE " + Col.USER_ID + "=" + usersTable.statementSelectID;
|
||||
|
@ -116,7 +116,7 @@ public class ConnectionOut {
|
||||
}
|
||||
}
|
||||
|
||||
private String prepareRequest(HttpPost post, String parameters) {
|
||||
private void prepareRequest(HttpPost post, String parameters) {
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
.setConnectionRequestTimeout(10000)
|
||||
.setRelativeRedirectsAllowed(true)
|
||||
@ -130,7 +130,6 @@ public class ConnectionOut {
|
||||
|
||||
byte[] toSend = parameters.getBytes();
|
||||
post.setEntity(new ByteArrayEntity(toSend));
|
||||
return parameters;
|
||||
}
|
||||
|
||||
private CloseableHttpClient getHttpClient(String address) throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.djrapitops.plan.system.listeners.bukkit;
|
||||
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.processing.processors.player.KillProcessor;
|
||||
@ -80,7 +81,7 @@ public class DeathEventListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
return new KillProcessor(killer.getUniqueId(), time, dead, normalizeMaterialName(itemInHand));
|
||||
return new KillProcessor(killer.getUniqueId(), time, dead, Formatters.itemName().apply(itemInHand.name()));
|
||||
}
|
||||
|
||||
private KillProcessor handlePetKill(long time, LivingEntity dead, Tameable tameable) {
|
||||
@ -118,26 +119,5 @@ public class DeathEventListener implements Listener {
|
||||
new Format(projectile.getType().name()).capitalize().toString()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a material name
|
||||
*
|
||||
* @param material The material
|
||||
* @return The normalized material name
|
||||
*/
|
||||
private String normalizeMaterialName(Material material) {
|
||||
String[] parts = material.name().split("_");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < parts.length; i++) {
|
||||
String part = new Format(parts[i]).capitalize().toString();
|
||||
builder.append(part);
|
||||
if (i < parts.length - 1) {
|
||||
builder.append(" ");
|
||||
}
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.djrapitops.plan.system.listeners.sponge;
|
||||
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.processing.processors.player.SpongeKillProcessor;
|
||||
@ -73,7 +74,7 @@ public class SpongeDeathListener {
|
||||
ItemStack inHand = inMainHand.orElse(killer.getItemInHand(HandTypes.OFF_HAND).orElse(ItemStack.empty()));
|
||||
ItemType type = inHand.isEmpty() ? ItemTypes.AIR : inHand.getType();
|
||||
|
||||
return new SpongeKillProcessor(killer.getUniqueId(), time, getUUID(dead), normalizeItemName(type));
|
||||
return new SpongeKillProcessor(killer.getUniqueId(), time, getUUID(dead), Formatters.itemName().apply(type.getName()));
|
||||
}
|
||||
|
||||
private UUID getUUID(Living dead) {
|
||||
@ -86,13 +87,10 @@ public class SpongeDeathListener {
|
||||
private SpongeKillProcessor handleWolfKill(long time, Living dead, Wolf wolf) {
|
||||
Optional<Optional<UUID>> owner = wolf.get(Keys.TAMED_OWNER);
|
||||
|
||||
if (!owner.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return owner.get().map(
|
||||
return owner.map(ownerUUID -> ownerUUID.map(
|
||||
uuid -> new SpongeKillProcessor(uuid, time, getUUID(dead), "Wolf")
|
||||
).orElse(null);
|
||||
).orElse(null)).orElse(null);
|
||||
|
||||
}
|
||||
|
||||
private SpongeKillProcessor handleProjectileKill(long time, Living dead, Projectile projectile) {
|
||||
@ -108,25 +106,4 @@ public class SpongeDeathListener {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes an item name
|
||||
*
|
||||
* @param type The type of the item
|
||||
* @return The normalized item name
|
||||
*/
|
||||
private String normalizeItemName(ItemType type) {
|
||||
String[] parts = type.getName().split("_");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < parts.length; i++) {
|
||||
String part = new Format(parts[i]).capitalize().toString();
|
||||
builder.append(part);
|
||||
if (i < parts.length - 1) {
|
||||
builder.append(" ");
|
||||
}
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
package com.djrapitops.plan.system.settings.network;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.connection.UnsupportedTransferDatabaseException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
@ -59,7 +59,7 @@ public class NetworkSettings {
|
||||
Processing.submitCritical(() -> {
|
||||
try {
|
||||
new NetworkSettings().placeToDatabase();
|
||||
} catch (DBException | UnsupportedTransferDatabaseException e) {
|
||||
} catch (DBOpException | UnsupportedTransferDatabaseException e) {
|
||||
Log.toLog(NetworkSettings.class, e);
|
||||
}
|
||||
});
|
||||
@ -108,7 +108,7 @@ public class NetworkSettings {
|
||||
return pathValueMap;
|
||||
}
|
||||
|
||||
public void placeToDatabase() throws DBException, UnsupportedTransferDatabaseException {
|
||||
public void placeToDatabase() throws UnsupportedTransferDatabaseException {
|
||||
Map<String, Object> configValues = getConfigValues();
|
||||
|
||||
Log.debug("NetworkSettings: Building Base64 String..");
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.djrapitops.plan.utilities;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Base64;
|
||||
@ -13,9 +13,9 @@ public class SHA256Hash {
|
||||
this.original = original;
|
||||
}
|
||||
|
||||
public String create() throws NoSuchAlgorithmException, UnsupportedEncodingException {
|
||||
public String create() throws NoSuchAlgorithmException {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
digest.update(original.getBytes("UTF-8"));
|
||||
digest.update(original.getBytes(StandardCharsets.UTF_8));
|
||||
return Base64.getEncoder().encodeToString(digest.digest());
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,20 @@
|
||||
package com.djrapitops.plan.utilities.html.icon;
|
||||
|
||||
public enum Family {
|
||||
SOLID("<i class=\"", " fa fa-", "\"></i>"),
|
||||
REGULAR("<i class=\"", " far fa-", "\"></i>"),
|
||||
BRAND("<i class=\"", " fab fa-", "\"></i>"),
|
||||
LINE("<i class=\"", " material-icons\">", "</i>");
|
||||
SOLID(" fa fa-", "\"></i>"),
|
||||
REGULAR(" far fa-", "\"></i>"),
|
||||
BRAND(" fab fa-", "\"></i>"),
|
||||
LINE(" material-icons\">", "</i>");
|
||||
|
||||
private final String prefix;
|
||||
private final String middle;
|
||||
private final String suffix;
|
||||
|
||||
Family(String prefix, String middle, String suffix) {
|
||||
this.prefix = prefix;
|
||||
Family(String middle, String suffix) {
|
||||
this.middle = middle;
|
||||
this.suffix = suffix;
|
||||
}
|
||||
|
||||
public String appendAround(String color, String name) {
|
||||
return prefix + color + middle + name + suffix;
|
||||
return "<i class=\"" + color + middle + name + suffix;
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.logging.Level;
|
||||
@ -169,7 +170,7 @@ public class Metrics {
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
|
||||
gzip.write(str.getBytes("UTF-8"));
|
||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||
gzip.close();
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user