mirror of https://github.com/Minestom/Minestom.git
Dead code
This commit is contained in:
parent
b54ab55efe
commit
e7253488c6
|
@ -1,41 +0,0 @@
|
|||
package net.minestom.server.utils;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.translation.GlobalTranslator;
|
||||
import net.minestom.server.adventure.MinestomAdventure;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* {@link Component} utilities.
|
||||
*/
|
||||
public final class ComponentUtils {
|
||||
/**
|
||||
* Checks if a component can be translated server-side. This is done by running the
|
||||
* component through the translator and seeing if the translated component is equal
|
||||
* to the non translated component.
|
||||
*
|
||||
* @param component the component
|
||||
* @return {@code true} if the component can be translated server-side, {@code false} otherwise
|
||||
*/
|
||||
public static boolean isTranslatable(@NotNull Component component) {
|
||||
return !component.equals(GlobalTranslator.render(component, MinestomAdventure.getDefaultLocale()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if any of a series of components are translatable server-side.
|
||||
*
|
||||
* @param components the components
|
||||
* @return {@code true} if any of the components can be translated server-side, {@code false} otherwise
|
||||
*/
|
||||
public static boolean areAnyTranslatable(@NotNull Collection<Component> components) {
|
||||
for (Component component : components) {
|
||||
if (isTranslatable(component)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ import java.time.Duration;
|
|||
/**
|
||||
* Tick related utilities.
|
||||
*/
|
||||
public class TickUtils {
|
||||
public final class TickUtils {
|
||||
/**
|
||||
* Number of ticks per second for the default Java-edition client.
|
||||
*/
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
package net.minestom.server.utils;
|
||||
|
||||
import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
|
||||
import it.unimi.dsi.fastutil.doubles.DoubleList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Produces a random element from a given set, with weights applied.
|
||||
*
|
||||
* @param <E>
|
||||
*/
|
||||
public class WeightedRandom<E extends WeightedRandomItem> {
|
||||
|
||||
private final List<E> entries;
|
||||
private final DoubleList weightSums;
|
||||
private final double totalWeight;
|
||||
|
||||
public WeightedRandom(Collection<E> items) {
|
||||
if (items.isEmpty())
|
||||
throw new IllegalArgumentException("items must not be empty");
|
||||
this.entries = new ArrayList<>(items);
|
||||
this.weightSums = new DoubleArrayList(items.size());
|
||||
double sum = 0.0;
|
||||
for (E item : items) {
|
||||
sum += item.getWeight();
|
||||
weightSums.add(sum);
|
||||
}
|
||||
this.totalWeight = sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a random element from this set.
|
||||
*
|
||||
* @param rng Random Number Generator to generate random numbers with
|
||||
* @return a random element from this set
|
||||
*/
|
||||
public E get(Random rng) {
|
||||
final double p = rng.nextDouble() * totalWeight;
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
final double weightSum = weightSums.getDouble(i);
|
||||
if (weightSum >= p) {
|
||||
return entries.get(i);
|
||||
}
|
||||
}
|
||||
return entries.get(entries.size() - 1);
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package net.minestom.server.utils;
|
||||
|
||||
public interface WeightedRandomItem {
|
||||
|
||||
double getWeight();
|
||||
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package net.minestom.server.utils.clone;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.function.IntFunction;
|
||||
|
||||
/**
|
||||
* Convenient interface to deep-copy single object or collections.
|
||||
* <p>
|
||||
* Most of the methods require object to implement the {@link PublicCloneable} interface.
|
||||
*/
|
||||
public final class CloneUtils {
|
||||
|
||||
@Nullable
|
||||
public static <T extends PublicCloneable<T>> T optionalClone(@Nullable T object) {
|
||||
return object != null ? object.clone() : null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T extends PublicCloneable<T>> CopyOnWriteArrayList<T> cloneCopyOnWriteArrayList(@NotNull List<T> list) {
|
||||
CopyOnWriteArrayList<T> result = new CopyOnWriteArrayList<>();
|
||||
for (T element : list) {
|
||||
result.add(element.clone());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T extends PublicCloneable<T>> T[] cloneArray(@NotNull T[] array, IntFunction<T[]> arraySupplier) {
|
||||
T[] result = arraySupplier.apply(array.length);
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = optionalClone(array[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package net.minestom.server.utils.clone;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Convenient interface to expose {@link Object#clone()} publicly with a generic.
|
||||
*
|
||||
* @param <T> the type to clone
|
||||
*/
|
||||
public interface PublicCloneable<T> extends Cloneable {
|
||||
|
||||
/**
|
||||
* Creates and returns a copy of this object.
|
||||
*
|
||||
* @return A clone of this instance.
|
||||
*/
|
||||
@NotNull
|
||||
T clone();
|
||||
}
|
|
@ -3,7 +3,7 @@ package net.minestom.server.utils.time;
|
|||
import java.time.temporal.ChronoUnit;
|
||||
import java.time.temporal.TemporalUnit;
|
||||
|
||||
public class TimeUnit {
|
||||
public final class TimeUnit {
|
||||
public static final TemporalUnit DAY = ChronoUnit.DAYS;
|
||||
public static final TemporalUnit HOUR = ChronoUnit.HOURS;
|
||||
public static final TemporalUnit MINUTE = ChronoUnit.MINUTES;
|
||||
|
|
Loading…
Reference in New Issue