This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@EventHandler(priority = EventPriority.HIGHEST) | |
public void onMove(PlayerMoveEvent event) { | |
Location from = event.getFrom(); | |
Location to = event.getTo(); | |
if(!from.getWorld().getName().equalsIgnoreCase(to.getWorld().getName())) { | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.ParameterizedType; | |
import java.lang.reflect.Type; | |
public class GenericClass<T> { | |
public GenericClass() { | |
Type superclass = this.getClass().getGenericSuperclass(); | |
Type genericClass = ((ParameterizedType) superclass).getActualTypeArguments()[0]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Optional; | |
import java.util.function.Consumer; | |
@SuppressWarnings("all") | |
public class SwitchClass { | |
static public <T> void cswitch(Object object, Consumer... consumers) { | |
for (Consumer consumer : consumers) { | |
consumer.accept(object); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.crypto.Cipher; | |
import javax.crypto.SecretKey; | |
import javax.crypto.spec.SecretKeySpec; | |
import java.nio.charset.StandardCharsets; | |
import java.security.MessageDigest; | |
public class EncryptUtils { | |
private static final String ALGORITHM = "AES"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Pagifier<T> { | |
private final int maxItemsPerPage; | |
private final List<List<T>> allPages; | |
public Pagifier(int maxItemsPerPage) { | |
this.maxItemsPerPage = maxItemsPerPage; | |
allPages = new LinkedList<>(); | |
allPages.add(new LinkedList<>()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.TimeUnit; | |
public class TimeStamp { | |
private static final String ZERO = "0"; | |
private static final String MILLIS = "ms"; | |
private static final String NANOS = "ns"; | |
private static final String SECONDS = "s"; | |
private static final String ZERO_MILLIS = ZERO + MILLIS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StringGenerator { | |
public static String createRandomString(int length, String characters) { | |
StringBuilder stringBuilder = new StringBuilder(length); | |
for (int i = 0; i < length; i++) { | |
int index = (int) (characters.length() * Math.random()); | |
stringBuilder.append(characters.charAt(index)); | |
} | |
return stringBuilder.toString(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.vaadin.flow.component.UI; | |
import com.vaadin.flow.component.notification.Notification; | |
import com.vaadin.flow.component.notification.NotificationVariant; | |
public class Clipboard { | |
public Clipboard() { | |
String javaScriptFunction = "window.copyToClipboard = (str) => {\n" | |
+ " const textarea = document.createElement(\"textarea\");\n" | |
+ " textarea.value = str;\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.atomic.AtomicLong; | |
import java.util.function.Predicate; | |
public class LongId { | |
private final AtomicLong atomicLong = new AtomicLong(0); | |
public long generateId(Predicate<Long> exists) { | |
if(this.atomicLong.get() == Integer.MAX_VALUE) { | |
this.atomicLong.set(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.bson.BsonBinaryReader; | |
import org.bson.BsonBinaryWriter; | |
import org.bson.Document; | |
import org.bson.codecs.Codec; | |
import org.bson.codecs.DecoderContext; | |
import org.bson.codecs.DocumentCodec; | |
import org.bson.codecs.EncoderContext; | |
import org.bson.io.BasicOutputBuffer; | |
import java.nio.ByteBuffer; |
NewerOlder