Skip to content

Commit

Permalink
v1.16.20.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
CryptoMorin committed Jan 25, 2024
1 parent 5d5566c commit 937728e
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ public boolean isVanished(Player player) {
return CMI.getInstance().getVanishManager().getAllVanished().contains(player.getUniqueId());
}

private CMIUser getUser(Player player) {
return CMI.getInstance().getPlayerManager().getUser(player);
}

@Override
public boolean isInGodMode(Player player) {
// "This can return NULL in some rare situations, so perform NPE check."
CMIUser user = CMI.getInstance().getPlayerManager().getUser(player);
CMIUser user = getUser(player);
try {
return user != null && user.isGod();
} catch (NoSuchMethodError ex) {
Expand All @@ -27,4 +31,10 @@ public boolean isInGodMode(Player player) {
return false;
}
}

@Override
public boolean isIgnoring(Player ignorant, Player ignoring) {
CMIUser user = getUser(ignorant);
return user != null && user.isIgnoring(ignoring.getUniqueId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public interface ServiceCommons extends Service {
boolean isVanished(Player player);

boolean isInGodMode(Player player);

boolean isIgnoring(Player ignorant, Player ignoring);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public boolean isVanished(Player player) {
public boolean isInGodMode(Player player) {
return ESS.getUser(player).isGodModeEnabled();
}

@Override
public boolean isIgnoring(Player ignorant, Player ignoring) {
return ESS.getUser(ignorant).isIgnoredPlayer(ESS.getUser(ignoring));
}
}
2 changes: 1 addition & 1 deletion core/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ placeholders:
# Please just be care not to use recursive variables or your servers console will blow up.
channel: '&8[&9%kingdoms_chat_channel_color%%kingdoms_chat_channel_short%&8]'
kingdomPrefix:
kingdoms_has_kingdom: '&8[%kingdoms_rank_color%%kingdoms_rank_symbol% %kingdoms_kingdom_color@hex%%kingdoms_kingdom_name%&8] '
kingdoms_has_kingdom: '&8[%kingdoms_rank_color%%kingdoms_rank_symbol% %kingdoms_kingdom_color@hex%%kingdoms_kingdom_name%&8]&r '
else: ''
nationPrefix:
kingdoms_has_nation: '&8[%kingdoms_nation_rank_color%%kingdoms_nation_rank_symbol%&8 %kingdoms_nation_color@hex%%kingdoms_nation_name%&8]&7|'
Expand Down
33 changes: 33 additions & 0 deletions shared/src/main/java/org/kingdoms/utils/AverageStats.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.kingdoms.utils

import java.util.concurrent.ConcurrentHashMap

class AverageStats<K : Any, V : Number> {
private val data: MutableMap<K, Avg> = ConcurrentHashMap()

/**
* Instead of keeping all the data set, we update the
* values we need in order to take an average from
* a data set with a much, much smaller memory.
*/
private class Avg(var sum: Double, var count: Long)

fun addData(key: K, data: V) {
val avg = this.data.getOrPut(key) { Avg(0.0, 0L) }
avg.apply {
sum += data.toDouble()
count++

if (sum >= Double.MAX_VALUE) {
// Time to free up some memory.
sum = Double.MAX_VALUE / count
count = 1
}
}
}

@Suppress("UNCHECKED_CAST") fun getAverage(key: K): V? {
val avg = this.data[key] ?: return null
return (avg.sum / avg.count) as V
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.kingdoms.utils.internal.iterator;

import org.jetbrains.annotations.NotNull;

import java.util.Iterator;

public class SharedSubIterable<E> implements Iterable<E> {
private final SubIterator<E> subIterable;

public SharedSubIterable(Iterable<E> iterable, int limit) {
this.subIterable = new SubIterator<>(iterable.iterator(), limit);
}

public SubIterator<E> getSharedIterator() {
return subIterable;
}

public boolean hasRemaining() {
return subIterable.hasNext();
}

@NotNull
@Override
public Iterator<E> iterator() {
return subIterable;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.kingdoms.utils.internal.iterator;

import org.jetbrains.annotations.NotNull;

import java.util.Iterator;

public class SubIterable<E> implements Iterable<E> {
private final Iterable<E> iterable;
private final int limit;

public SubIterable(Iterable<E> iterable, int limit) {
this.iterable = iterable;
this.limit = limit;
}

@NotNull
@Override
public Iterator<E> iterator() {
return new SubIterator<>(iterable.iterator(), limit);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.kingdoms.utils.internal.iterator;

import java.util.Iterator;
import java.util.function.Consumer;

public class SubIterator<E> implements Iterator<E> {
private final Iterator<E> iterator;
private final int limit;
private int counted;

public SubIterator(Iterator<E> iterator, int limit) {
this.iterator = iterator;
this.limit = limit;
}

public void resetIndex() {
this.counted = 0;
}

@Override
public boolean hasNext() {
return counted < limit && iterator.hasNext();
}

@Override
public E next() {
counted++;
return iterator.next();
}

@Override
public void remove() {
iterator.remove();
}

@Override
public void forEachRemaining(Consumer<? super E> action) {
iterator.forEachRemaining(action);
}
}

0 comments on commit 937728e

Please sign in to comment.