minecraft-src/net/minecraft/server/level/Ticket.java
2025-07-04 01:41:11 +03:00

61 lines
1.6 KiB
Java

package net.minecraft.server.level;
import java.util.Objects;
public final class Ticket<T> implements Comparable<Ticket<?>> {
private final TicketType<T> type;
private final int ticketLevel;
private final T key;
private long createdTick;
protected Ticket(TicketType<T> type, int ticketLevel, T key) {
this.type = type;
this.ticketLevel = ticketLevel;
this.key = key;
}
public int compareTo(Ticket<?> other) {
int i = Integer.compare(this.ticketLevel, other.ticketLevel);
if (i != 0) {
return i;
} else {
int j = Integer.compare(System.identityHashCode(this.type), System.identityHashCode(other.type));
return j != 0 ? j : this.type.getComparator().compare(this.key, other.key);
}
}
public boolean equals(Object object) {
if (this == object) {
return true;
} else {
return !(object instanceof Ticket<?> ticket)
? false
: this.ticketLevel == ticket.ticketLevel && Objects.equals(this.type, ticket.type) && Objects.equals(this.key, ticket.key);
}
}
public int hashCode() {
return Objects.hash(new Object[]{this.type, this.ticketLevel, this.key});
}
public String toString() {
return "Ticket[" + this.type + " " + this.ticketLevel + " (" + this.key + ")] at " + this.createdTick;
}
public TicketType<T> getType() {
return this.type;
}
public int getTicketLevel() {
return this.ticketLevel;
}
protected void setCreatedTick(long timestamp) {
this.createdTick = timestamp;
}
protected boolean timedOut(long currentTime) {
long l = this.type.timeout();
return l != 0L && currentTime - this.createdTick > l;
}
}