-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1) Drop Java 7 support 2) Implement GriefPreventionPlus support 3) Implement new utilities
- Loading branch information
1 parent
08613dc
commit ca94fc2
Showing
40 changed files
with
2,084 additions
and
235 deletions.
There are no files selected for viewing
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
Binary file not shown.
Binary file not shown.
74 changes: 48 additions & 26 deletions
74
src/main/java/com/gamerforea/eventhelper/EventHelper.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,87 @@ | ||
package com.gamerforea.eventhelper; | ||
|
||
import static net.minecraftforge.common.config.Configuration.CATEGORY_GENERAL; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.plugin.PluginManager; | ||
import org.bukkit.plugin.RegisteredListener; | ||
|
||
import com.gamerforea.eventhelper.util.FastUtils; | ||
import com.gamerforea.eventhelper.wg.WGReflection; | ||
import com.gamerforea.eventhelper.config.ConfigUtils; | ||
import com.gamerforea.eventhelper.inject.InjectionManager; | ||
import com.google.common.collect.Lists; | ||
|
||
import cpw.mods.fml.common.Loader; | ||
import cpw.mods.fml.common.Mod; | ||
import cpw.mods.fml.common.Mod.EventHandler; | ||
import cpw.mods.fml.common.event.FMLServerStartedEvent; | ||
import cpw.mods.fml.relauncher.Side; | ||
import cpw.mods.fml.relauncher.SideOnly; | ||
import net.minecraftforge.common.config.Configuration; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.message.FormattedMessage; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.plugin.Plugin; | ||
import org.bukkit.plugin.PluginManager; | ||
import org.bukkit.plugin.RegisteredListener; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
import static net.minecraftforge.common.config.Configuration.CATEGORY_GENERAL; | ||
|
||
@SideOnly(Side.SERVER) | ||
@Mod(modid = "EventHelper", name = "EventHelper", version = "@VERSION@", acceptableRemoteVersions = "*") | ||
public final class EventHelper | ||
{ | ||
public static final Logger LOGGER = LogManager.getLogger("EventHelper"); | ||
public static final File cfgDir = new File(Loader.instance().getConfigDir(), "Events"); | ||
public static final List<RegisteredListener> listeners = Lists.newArrayList(); | ||
public static String craftPackage = "org/bukkit/craftbukkit/v1_7_R4"; | ||
public static boolean debug = false; | ||
public static String craftPackage = "org.bukkit.craftbukkit.v1_7_R4"; | ||
public static boolean explosions = true; | ||
public static boolean debug = true; | ||
|
||
@EventHandler | ||
public final void serverStarted(FMLServerStartedEvent event) | ||
{ | ||
Configuration cfg = FastUtils.getConfig("EventHelper"); | ||
String[] plugins = cfg.getStringList("plugins", CATEGORY_GENERAL, new String[] { "WorldGuard" }, "Plugins for sending events"); | ||
boolean wgHooking = cfg.getBoolean("wgHooking", CATEGORY_GENERAL, true, "Hooking WorldGuard plugin (allow checking regions)"); | ||
craftPackage = cfg.getString("craftPackage", CATEGORY_GENERAL, craftPackage, "CraftBukkit package (for reflection)"); | ||
debug = cfg.getBoolean("debug", CATEGORY_GENERAL, debug, "Debugging enabled"); | ||
Configuration cfg = ConfigUtils.getConfig("EventHelper"); | ||
String c = CATEGORY_GENERAL; | ||
String[] plugins = cfg.getStringList("plugins", c, new String[] { "WorldGuard", "GriefPreventionPlus" }, "Plugins for sending events"); | ||
boolean pluginHooking = cfg.getBoolean("pluginHooking", c, true, "Hooking plugins (allow checking regions)"); | ||
craftPackage = cfg.getString("craftPackage", c, craftPackage, "CraftBukkit package (for reflection)"); | ||
explosions = cfg.getBoolean("explosions", c, explosions, "Explosions enabled"); | ||
debug = cfg.getBoolean("debug", c, debug, "Debugging enabled"); | ||
cfg.save(); | ||
|
||
PluginManager plManager = Bukkit.getPluginManager(); | ||
for (String plName : plugins) | ||
listeners.addAll(HandlerList.getRegisteredListeners(plManager.getPlugin(plName))); | ||
if (wgHooking) | ||
WGReflection.setWG(plManager.getPlugin("WorldGuard")); | ||
{ | ||
Plugin plugin = plManager.getPlugin(plName); | ||
if (plugin == null) | ||
LOGGER.warn("Plugin {} not found!", plName); | ||
else | ||
listeners.addAll(HandlerList.getRegisteredListeners(plugin)); | ||
} | ||
if (pluginHooking) | ||
InjectionManager.init(); | ||
} | ||
|
||
public static final void callEvent(Event event) | ||
public static void callEvent(Event event) | ||
{ | ||
for (RegisteredListener listener : listeners) | ||
{ | ||
try | ||
{ | ||
listener.callEvent(event); | ||
} | ||
catch (Throwable throwable) | ||
{ | ||
if (debug) | ||
throwable.printStackTrace(); | ||
LOGGER.error("Failed event call", throwable); | ||
} | ||
} | ||
} | ||
|
||
public static void error(Throwable throwable, String message, Object... args) | ||
{ | ||
if (debug) | ||
LOGGER.error(new FormattedMessage(message, args), throwable); | ||
else | ||
LOGGER.error(message, args); | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
src/main/java/com/gamerforea/eventhelper/config/ClassSet.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.gamerforea.eventhelper.config; | ||
|
||
import com.gamerforea.eventhelper.EventHelper; | ||
import com.google.common.base.Preconditions; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public final class ClassSet<T> implements Iterable<Class<? extends T>> | ||
{ | ||
private final Set<Class<? extends T>> classes = new HashSet<>(); | ||
private final Class<T> baseClass; | ||
|
||
public ClassSet(@Nonnull Class<T> baseClass) | ||
{ | ||
this.baseClass = baseClass; | ||
Preconditions.checkArgument(baseClass != Class.class, "baseClass must not be java.lang.Class"); | ||
} | ||
|
||
public boolean isEmpty() | ||
{ | ||
return this.classes.isEmpty(); | ||
} | ||
|
||
public boolean contains(@Nullable T instance) | ||
{ | ||
return instance != null && this.contains((Class<? extends T>) instance.getClass()); | ||
} | ||
|
||
public boolean contains(@Nonnull Class<? extends T> clazz) | ||
{ | ||
return this.contains(clazz, true); | ||
} | ||
|
||
public boolean contains(@Nullable T instance, boolean checkHierarchy) | ||
{ | ||
return instance != null && this.contains((Class<? extends T>) instance.getClass(), checkHierarchy); | ||
} | ||
|
||
public boolean contains(@Nonnull Class<? extends T> clazz, boolean checkHierarchy) | ||
{ | ||
if (this.baseClass.isAssignableFrom(clazz)) | ||
{ | ||
if (this.classes.contains(clazz)) | ||
return true; | ||
|
||
if (checkHierarchy) | ||
for (Class<? extends T> aClass : this.classes) | ||
{ | ||
if (aClass.isAssignableFrom(clazz)) | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public Iterator<Class<? extends T>> iterator() | ||
{ | ||
return this.classes.iterator(); | ||
} | ||
|
||
public void clear() | ||
{ | ||
this.classes.clear(); | ||
} | ||
|
||
public boolean add(@Nonnull Class<? extends T> clazz) | ||
{ | ||
return this.baseClass.isAssignableFrom(clazz) && this.classes.add(clazz); | ||
} | ||
|
||
public void addRaw(@Nonnull Collection<String> classNames) | ||
{ | ||
for (String className : classNames) | ||
{ | ||
try | ||
{ | ||
Class<?> clazz = Class.forName(className); | ||
if (this.baseClass.isAssignableFrom(clazz)) | ||
this.add((Class<? extends T>) clazz); | ||
else if (EventHelper.debug) | ||
EventHelper.LOGGER.warn("Class {} is not assignable from {}", className, this.baseClass.getName()); | ||
} | ||
catch (ClassNotFoundException e) | ||
{ | ||
if (EventHelper.debug) | ||
EventHelper.LOGGER.warn("Class {} not found", className); | ||
} | ||
} | ||
} | ||
|
||
public Set<String> getRaw() | ||
{ | ||
return this.classes.stream().map(Class::getName).collect(Collectors.toSet()); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/gamerforea/eventhelper/config/Config.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.gamerforea.eventhelper.config; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface Config | ||
{ | ||
String name() default ""; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/gamerforea/eventhelper/config/ConfigBoolean.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.gamerforea.eventhelper.config; | ||
|
||
import net.minecraftforge.common.config.Configuration; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.FIELD) | ||
public @interface ConfigBoolean | ||
{ | ||
String name() default ""; | ||
|
||
String category() default Configuration.CATEGORY_GENERAL; | ||
|
||
String comment() default ""; | ||
|
||
String oldName() default ""; | ||
|
||
String oldCategory() default ""; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/gamerforea/eventhelper/config/ConfigClassSet.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.gamerforea.eventhelper.config; | ||
|
||
import net.minecraftforge.common.config.Configuration; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.FIELD) | ||
public @interface ConfigClassSet | ||
{ | ||
String name() default ""; | ||
|
||
String category() default Configuration.CATEGORY_GENERAL; | ||
|
||
String comment() default ""; | ||
|
||
String oldName() default ""; | ||
|
||
String oldCategory() default ""; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/gamerforea/eventhelper/config/ConfigEnum.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.gamerforea.eventhelper.config; | ||
|
||
import net.minecraftforge.common.config.Configuration; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.FIELD) | ||
public @interface ConfigEnum | ||
{ | ||
String name() default ""; | ||
|
||
String category() default Configuration.CATEGORY_GENERAL; | ||
|
||
String comment() default ""; | ||
|
||
String oldName() default ""; | ||
|
||
String oldCategory() default ""; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/gamerforea/eventhelper/config/ConfigFloat.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.gamerforea.eventhelper.config; | ||
|
||
import net.minecraftforge.common.config.Configuration; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.FIELD) | ||
public @interface ConfigFloat | ||
{ | ||
String name() default ""; | ||
|
||
String category() default Configuration.CATEGORY_GENERAL; | ||
|
||
String comment() default ""; | ||
|
||
float min() default Float.MIN_VALUE; | ||
|
||
float max() default Float.MAX_VALUE; | ||
|
||
String oldName() default ""; | ||
|
||
String oldCategory() default ""; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/gamerforea/eventhelper/config/ConfigInt.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.gamerforea.eventhelper.config; | ||
|
||
import net.minecraftforge.common.config.Configuration; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.FIELD) | ||
public @interface ConfigInt | ||
{ | ||
String name() default ""; | ||
|
||
String category() default Configuration.CATEGORY_GENERAL; | ||
|
||
String comment() default ""; | ||
|
||
int min() default Integer.MIN_VALUE; | ||
|
||
int max() default Integer.MAX_VALUE; | ||
|
||
String oldName() default ""; | ||
|
||
String oldCategory() default ""; | ||
} |
Oops, something went wrong.