Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-08 04:20:06 +01:00
Removed use of Guava's Cache because Bukkit uses an ancient version of Guava.
Dieser Commit ist enthalten in:
Ursprung
24f8fbc92a
Commit
e0a2873c99
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit.util.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.Documented;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks features that should be replaced with Google Guava but cannot
|
||||||
|
* yet because Bukkit uses such an old version of Guava.
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
|
@Documented
|
||||||
|
public @interface RequiresNewerGuava {
|
||||||
|
}
|
@ -20,16 +20,14 @@
|
|||||||
package com.sk89q.worldedit.util.eventbus;
|
package com.sk89q.worldedit.util.eventbus;
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.cache.Cache;
|
import com.google.common.collect.Multimaps;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.collect.SetMultimap;
|
||||||
import com.google.common.cache.CacheLoader;
|
|
||||||
import com.google.common.collect.*;
|
|
||||||
import com.google.common.eventbus.DeadEvent;
|
import com.google.common.eventbus.DeadEvent;
|
||||||
|
import com.sk89q.worldedit.util.annotation.RequiresNewerGuava;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -66,35 +64,8 @@ public class EventBus {
|
|||||||
*/
|
*/
|
||||||
private final SubscriberFindingStrategy finder = new AnnotatedSubscriberFinder();
|
private final SubscriberFindingStrategy finder = new AnnotatedSubscriberFinder();
|
||||||
|
|
||||||
/**
|
@RequiresNewerGuava
|
||||||
* A thread-safe cache for flattenHierarchy(). The Class class is immutable.
|
private HierarchyCache flattenHierarchyCache = new HierarchyCache();
|
||||||
*/
|
|
||||||
private Cache<Class<?>, Set<Class<?>>> flattenHierarchyCache =
|
|
||||||
CacheBuilder.newBuilder()
|
|
||||||
.weakKeys()
|
|
||||||
.build(new CacheLoader<Class<?>, Set<Class<?>>>() {
|
|
||||||
@Override
|
|
||||||
public Set<Class<?>> load(Class<?> concreteClass) throws Exception {
|
|
||||||
List<Class<?>> parents = Lists.newLinkedList();
|
|
||||||
Set<Class<?>> classes = Sets.newHashSet();
|
|
||||||
|
|
||||||
parents.add(concreteClass);
|
|
||||||
|
|
||||||
while (!parents.isEmpty()) {
|
|
||||||
Class<?> clazz = parents.remove(0);
|
|
||||||
classes.add(clazz);
|
|
||||||
|
|
||||||
Class<?> parent = clazz.getSuperclass();
|
|
||||||
if (parent != null) {
|
|
||||||
parents.add(parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.addAll(parents, clazz.getInterfaces());
|
|
||||||
}
|
|
||||||
|
|
||||||
return classes;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the given handler for the given class to receive events.
|
* Registers the given handler for the given class to receive events.
|
||||||
@ -251,11 +222,7 @@ public class EventBus {
|
|||||||
* @return {@code clazz}'s complete type hierarchy, flattened and uniqued.
|
* @return {@code clazz}'s complete type hierarchy, flattened and uniqued.
|
||||||
*/
|
*/
|
||||||
Set<Class<?>> flattenHierarchy(Class<?> concreteClass) {
|
Set<Class<?>> flattenHierarchy(Class<?> concreteClass) {
|
||||||
try {
|
|
||||||
return flattenHierarchyCache.get(concreteClass);
|
return flattenHierarchyCache.get(concreteClass);
|
||||||
} catch (ExecutionException e) {
|
|
||||||
throw Throwables.propagate(e.getCause());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
69
src/main/java/com/sk89q/worldedit/util/eventbus/HierarchyCache.java
Normale Datei
69
src/main/java/com/sk89q/worldedit/util/eventbus/HierarchyCache.java
Normale Datei
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit.util.eventbus;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import com.sk89q.worldedit.util.annotation.RequiresNewerGuava;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds a cache of class hierarcy.
|
||||||
|
* </p>
|
||||||
|
* This exists because Bukkit has an ancient version of Guava and the cache
|
||||||
|
* library in Guava has since changed.
|
||||||
|
*/
|
||||||
|
@RequiresNewerGuava
|
||||||
|
class HierarchyCache {
|
||||||
|
|
||||||
|
private final Map<Class<?>, Set<Class<?>>> cache = new WeakHashMap<Class<?>, Set<Class<?>>>();
|
||||||
|
|
||||||
|
public Set<Class<?>> get(Class<?> concreteClass) {
|
||||||
|
Set<Class<?>> ret = cache.get(concreteClass);
|
||||||
|
if (ret == null) {
|
||||||
|
ret = build(concreteClass);
|
||||||
|
cache.put(concreteClass, ret);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Set<Class<?>> build(Class<?> concreteClass) {
|
||||||
|
List<Class<?>> parents = Lists.newLinkedList();
|
||||||
|
Set<Class<?>> classes = Sets.newHashSet();
|
||||||
|
|
||||||
|
parents.add(concreteClass);
|
||||||
|
|
||||||
|
while (!parents.isEmpty()) {
|
||||||
|
Class<?> clazz = parents.remove(0);
|
||||||
|
classes.add(clazz);
|
||||||
|
|
||||||
|
Class<?> parent = clazz.getSuperclass();
|
||||||
|
if (parent != null) {
|
||||||
|
parents.add(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.addAll(parents, clazz.getInterfaces());
|
||||||
|
}
|
||||||
|
|
||||||
|
return classes;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren