mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-08-26 22:49:51 +02:00
Fixed new code smells in development branch
- static final class variable names in PingCountTimerBukkit - plugin field hiding protected variable in SpongeTaskSystem - InspectPageResponse not overriding equals method
This commit is contained in:
parent
18be484c0d
commit
26f64990d3
|
@ -10,19 +10,19 @@ import org.spongepowered.api.Sponge;
|
|||
import org.spongepowered.api.scheduler.Task;
|
||||
|
||||
public class SpongeTaskSystem extends ServerTaskSystem {
|
||||
|
||||
private final PlanSponge plugin;
|
||||
|
||||
private final PlanSponge planSponge;
|
||||
|
||||
public SpongeTaskSystem(PlanSponge plugin) {
|
||||
super(plugin, new SpongeTPSCountTimer(plugin));
|
||||
this.plugin = plugin;
|
||||
this.planSponge = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
super.enable();
|
||||
PingCountTimerSponge pingCountTimer = new PingCountTimerSponge();
|
||||
plugin.registerListener(pingCountTimer);
|
||||
planSponge.registerListener(pingCountTimer);
|
||||
long startDelay = TimeAmount.SECOND.ticks() * (long) Settings.PING_SERVER_ENABLE_DELAY.getNumber();
|
||||
RunnableFactory.createNew("PingCountTimer", pingCountTimer)
|
||||
.runTaskTimer(startDelay, PingCountTimerSponge.PING_INTERVAL);
|
||||
|
@ -31,7 +31,7 @@ public class SpongeTaskSystem extends ServerTaskSystem {
|
|||
@Override
|
||||
public void disable() {
|
||||
super.disable();
|
||||
for (Task task : Sponge.getScheduler().getScheduledTasks(plugin)) {
|
||||
for (Task task : Sponge.getScheduler().getScheduledTasks(planSponge)) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,17 +59,17 @@ public class PingCountTimerBukkit extends AbsRunnable implements Listener {
|
|||
//https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/PlayerConnection.java#L178
|
||||
public static final int PING_INTERVAL = 2 * 20;
|
||||
|
||||
private static final boolean pingMethodAvailable;
|
||||
private static final boolean PING_METHOD_AVAILABLE;
|
||||
|
||||
private static final MethodHandle pingField;
|
||||
private static final MethodHandle getHandleMethod;
|
||||
private static final MethodHandle PING_FIELD;
|
||||
private static final MethodHandle GET_HANDLE_METHOD;
|
||||
|
||||
static {
|
||||
pingMethodAvailable = isPingMethodAvailable();
|
||||
PING_METHOD_AVAILABLE = isPingMethodAvailable();
|
||||
|
||||
MethodHandle localHandle = null;
|
||||
MethodHandle localPing = null;
|
||||
if (!pingMethodAvailable) {
|
||||
if (!PING_METHOD_AVAILABLE) {
|
||||
Class<?> craftPlayerClass = Reflection.getCraftBukkitClass("entity.CraftPlayer");
|
||||
Class<?> entityPlayer = Reflection.getMinecraftClass("EntityPlayer");
|
||||
|
||||
|
@ -84,8 +84,8 @@ public class PingCountTimerBukkit extends AbsRunnable implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
getHandleMethod = localHandle;
|
||||
pingField = localPing;
|
||||
GET_HANDLE_METHOD = localHandle;
|
||||
PING_FIELD = localPing;
|
||||
}
|
||||
|
||||
private final Map<UUID, List<DateObj<Integer>>> playerHistory = new HashMap<>();
|
||||
|
@ -133,7 +133,7 @@ public class PingCountTimerBukkit extends AbsRunnable implements Listener {
|
|||
}
|
||||
|
||||
private int getPing(Player player) {
|
||||
if (pingMethodAvailable) {
|
||||
if (PING_METHOD_AVAILABLE) {
|
||||
return player.spigot().getPing();
|
||||
}
|
||||
|
||||
|
@ -142,8 +142,8 @@ public class PingCountTimerBukkit extends AbsRunnable implements Listener {
|
|||
|
||||
private int getReflectionPing(Player player) {
|
||||
try {
|
||||
Object entityPlayer = getHandleMethod.invoke(player);
|
||||
return (int) pingField.invoke(entityPlayer);
|
||||
Object entityPlayer = GET_HANDLE_METHOD.invoke(player);
|
||||
return (int) PING_FIELD.invoke(entityPlayer);
|
||||
} catch (Exception ex) {
|
||||
return -1;
|
||||
} catch (Throwable throwable) {
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.apache.commons.text.StringSubstitutor;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -48,4 +49,18 @@ public class InspectPageResponse extends PageResponse {
|
|||
refreshPage.replacePlaceholders();
|
||||
return new InspectPageResponse(null, refreshPage.getContent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof InspectPageResponse)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
InspectPageResponse that = (InspectPageResponse) o;
|
||||
return Objects.equals(uuid, that.uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), uuid);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user