Skip to content

Instantly share code, notes, and snippets.

View Koboo's full-sized avatar
powered by coffee

Koboo

powered by coffee
View GitHub Profile
@Koboo
Koboo / SwitchClass.java
Last active August 22, 2022 09:47
Switch and case class of an object
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);
@Koboo
Koboo / GenericClass.java
Created August 23, 2022 09:08
Get class of generic object from java class
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];
}
@Koboo
Koboo / PlayerMoveEvent.java
Created September 18, 2022 13:45
"Infinite" room in bukkit through player move event
@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;
}