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:
Rsl1122 2018-09-09 13:50:38 +03:00
parent 18be484c0d
commit 26f64990d3
3 changed files with 30 additions and 15 deletions

View File

@ -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();
}
}

View File

@ -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) {

View File

@ -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);
}
}