<commit_before>From cc4c98370431ee750b7f0cf3f96dc2a5dc4b1263 Mon Sep 17 00:00:00 2001
From: stonar96 <<EMAIL>>
Date: Sun, 9 Sep 2018 03:39:59 +0200
Subject: [PATCH] Add basic event system


diff --git a/sources/minecraft_server/com/vanillage/minecraftalphaserver/event/TestEvent.java b/sources/minecraft_server/com/vanillage/minecraftalphaserver/event/TestEvent.java
new file mode 100644
index 0000000..4754f54
--- /dev/null
+++ b/sources/minecraft_server/com/vanillage/minecraftalphaserver/event/TestEvent.java
@@ -0,0 +1,22 @@
+package com.vanillage.minecraftalphaserver.event;
+
+import com.vanillage.utils.event.Event;
+
+import net.minecraft.server.MinecraftServer;
+
+public final class TestEvent implements Event<TestListener, TestEvent> {
+    private final MinecraftServer minecraftServer;
+
+    public TestEvent(MinecraftServer minecraftServer) {
+        this.minecraftServer = minecraftServer;
+    }
+
+    public MinecraftServer getMinecraftServer() {
+        return minecraftServer;
+    }
+
+    @Override
+    public Class<TestListener> getListenerClass() {
+        return TestListener.class;
+    }
+}
diff --git a/sources/minecraft_server/com/vanillage/minecraftalphaserver/event/TestListener.java b/sources/minecraft_server/com/vanillage/minecraftalphaserver/event/TestListener.java
new file mode 100644
index 0000000..eaf8e69
--- /dev/null
+++ b/sources/minecraft_server/com/vanillage/minecraftalphaserver/event/TestListener.java
@@ -0,0 +1,10 @@
+package com.vanillage.minecraftalphaserver.event;
+
+import com.vanillage.utils.event.Listener;
+
+public abstract class TestListener extends Listener<TestListener, TestEvent> {
+    @Override
+    protected final Class<TestListener> getListenerClass() {
+        return TestListener.class;
+    }
+}
diff --git a/sources/minecraft_server/com/vanillage/minecraftalphaserver/plugin/PluginManager.java b/sources/minecraft_server/com/vanillage/minecraftalphaserver/plugin/PluginManager.java
index 37eb483..cddb7df 100644
--- a/sources/minecraft_server/com/vanillage/minecraftalphaserver/plugin/PluginManager.java
+++ b/sources/minecraft_server/com/vanillage/minecraftalphaserver/plugin/PluginManager.java
@@ -1,5 +1,6 @@
 package com.vanillage.minecraftalphaserver.plugin;
 
+import com.vanillage.utils.event.EventManager;
 import com.vanillage.utils.plugin.SimplePluginLoader;
 import com.vanillage.utils.plugin.SimplePluginManager;
 
@@ -7,11 +8,16 @@ import net.minecraft.server.MinecraftServer;
 
 public final class PluginManager extends SimplePluginManager<Plugin> {
     private final MinecraftServer minecraftServer;
+    private final EventManager eventManager = new EventManager();
 
     public PluginManager(MinecraftServer minecraftServer) {
         this.minecraftServer = minecraftServer;
     }
 
+    public EventManager getEventManager() {
+        return eventManager;
+    }
+
     @Override
     protected void enablePlugin(Plugin plugin) {
         plugin.setMinecraftServer(minecraftServer);
diff --git a/sources/minecraft_server/com/vanillage/utils/ClassToInstanceListHashMap.java b/sources/minecraft_server/com/vanillage/utils/ClassToInstanceListHashMap.java
new file mode 100644
index 0000000..20917dd
--- /dev/null
+++ b/sources/minecraft_server/com/vanillage/utils/ClassToInstanceListHashMap.java
@@ -0,0 +1,19 @@
+package com.vanillage.utils;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ClassToInstanceListHashMap {
+    private final Map<Class<?>, List<?>> map = new HashMap<>();
+
+    @SuppressWarnings("unchecked")
+    public <T> List<T> put(Class<T> key, List<T> value) {
+        return (List<T>) map.put(key, value);
+    }
+
+    @SuppressWarnings("unchecked")
+    public <T> List<T> get(Class<T> key) {
+        return (List<T>) map.get(key);
+    }
+}
diff --git a/sources/minecraft_server/com/vanillage/utils/event/Event.java b/sources/minecraft_server/com/vanillage/utils/event/Event.java
new file mode 100644
index 0000000..52d9218
--- /dev/null
+++ b/sources/minecraft_server/com/vanillage/utils/event/Event.java
@@ -0,0 +1,5 @@
+package com.vanillage.utils.event;
+
+public interface Event<L extends Listener<L, SELF>, SELF extends Event<L, SELF>> {
+    Class<L> getListenerClass();
+}
diff --git a/sources/minecraft_server/com/vanillage/utils/event/EventManager.java b/sources/minecraft_server/com/vanillage/utils/event/EventManager.java
new file mode 100644
index 0000000..25716b3
--- /dev/null
+++ b/sources/minecraft_server/com/vanillage/utils/event/EventManager.java
@@ -0,0 +1,50 @@
+package com.vanillage.utils.event;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+
+import com.vanillage.utils.ClassToInstanceListHashMap;
+
+public class EventManager {
+    private final ClassToInstanceListHashMap listeners = new ClassToInstanceListHashMap();
+
+    public <L extends Listener<L, E>, E extends Event<L, E>> void registerListener(L listener) {
+        List<L> listeners = this.listeners.get(listener.getListenerClass());
+
+        if (listeners == null) {<commit_msg>Change event interface to abstract class<commit_after>From 67a5b53f727e05b1855dfc538832a4396b7a4227 Mon Sep 17 00:00:00 2001
From: stonar96 <<EMAIL>>
Date: Sun, 9 Sep 2018 03:39:59 +0200
Subject: [PATCH] Add basic event system


diff --git a/sources/minecraft_server/com/vanillage/minecraftalphaserver/event/TestEvent.java b/sources/minecraft_server/com/vanillage/minecraftalphaserver/event/TestEvent.java
new file mode 100644
index 0000000..0b7d8f4
--- /dev/null
+++ b/sources/minecraft_server/com/vanillage/minecraftalphaserver/event/TestEvent.java
@@ -0,0 +1,22 @@
+package com.vanillage.minecraftalphaserver.event;
+
+import com.vanillage.utils.event.Event;
+
+import net.minecraft.server.MinecraftServer;
+
+public final class TestEvent extends Event<TestListener, TestEvent> {
+    private final MinecraftServer minecraftServer;
+
+    public TestEvent(MinecraftServer minecraftServer) {
+        this.minecraftServer = minecraftServer;
+    }
+
+    public MinecraftServer getMinecraftServer() {
+        return minecraftServer;
+    }
+
+    @Override
+    public Class<TestListener> getListenerClass() {
+        return TestListener.class;
+    }
+}
diff --git a/sources/minecraft_server/com/vanillage/minecraftalphaserver/event/TestListener.java b/sources/minecraft_server/com/vanillage/minecraftalphaserver/event/TestListener.java
new file mode 100644
index 0000000..eaf8e69
--- /dev/null
+++ b/sources/minecraft_server/com/vanillage/minecraftalphaserver/event/TestListener.java
@@ -0,0 +1,10 @@
+package com.vanillage.minecraftalphaserver.event;
+
+import com.vanillage.utils.event.Listener;
+
+public abstract class TestListener extends Listener<TestListener, TestEvent> {
+    @Override
+    protected final Class<TestListener> getListenerClass() {
+        return TestListener.class;
+    }
+}
diff --git a/sources/minecraft_server/com/vanillage/minecraftalphaserver/plugin/PluginManager.java b/sources/minecraft_server/com/vanillage/minecraftalphaserver/plugin/PluginManager.java
index 37eb483..cddb7df 100644
--- a/sources/minecraft_server/com/vanillage/minecraftalphaserver/plugin/PluginManager.java
+++ b/sources/minecraft_server/com/vanillage/minecraftalphaserver/plugin/PluginManager.java
@@ -1,5 +1,6 @@
 package com.vanillage.minecraftalphaserver.plugin;
 
+import com.vanillage.utils.event.EventManager;
 import com.vanillage.utils.plugin.SimplePluginLoader;
 import com.vanillage.utils.plugin.SimplePluginManager;
 
@@ -7,11 +8,16 @@ import net.minecraft.server.MinecraftServer;
 
 public final class PluginManager extends SimplePluginManager<Plugin> {
     private final MinecraftServer minecraftServer;
+    private final EventManager eventManager = new EventManager();
 
     public PluginManager(MinecraftServer minecraftServer) {
         this.minecraftServer = minecraftServer;
     }
 
+    public EventManager getEventManager() {
+        return eventManager;
+    }
+
     @Override
     protected void enablePlugin(Plugin plugin) {
         plugin.setMinecraftServer(minecraftServer);
diff --git a/sources/minecraft_server/com/vanillage/utils/ClassToInstanceListHashMap.java b/sources/minecraft_server/com/vanillage/utils/ClassToInstanceListHashMap.java
new file mode 100644
index 0000000..20917dd
--- /dev/null
+++ b/sources/minecraft_server/com/vanillage/utils/ClassToInstanceListHashMap.java
@@ -0,0 +1,19 @@
+package com.vanillage.utils;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ClassToInstanceListHashMap {
+    private final Map<Class<?>, List<?>> map = new HashMap<>();
+
+    @SuppressWarnings("unchecked")
+    public <T> List<T> put(Class<T> key, List<T> value) {
+        return (List<T>) map.put(key, value);
+    }
+
+    @SuppressWarnings("unchecked")
+    public <T> List<T> get(Class<T> key) {
+        return (List<T>) map.get(key);
+    }
+}
diff --git a/sources/minecraft_server/com/vanillage/utils/event/Event.java b/sources/minecraft_server/com/vanillage/utils/event/Event.java
new file mode 100644
index 0000000..8809ec2
--- /dev/null
+++ b/sources/minecraft_server/com/vanillage/utils/event/Event.java
@@ -0,0 +1,5 @@
+package com.vanillage.utils.event;
+
+public abstract class Event<L extends Listener<L, SELF>, SELF extends Event<L, SELF>> {
+    protected abstract Class<L> getListenerClass();
+}
diff --git a/sources/minecraft_server/com/vanillage/utils/event/EventManager.java b/sources/minecraft_server/com/vanillage/utils/event/EventManager.java
new file mode 100644
index 0000000..25716b3
--- /dev/null
+++ b/sources/minecraft_server/com/vanillage/utils/event/EventManager.java
@@ -0,0 +1,50 @@
+package com.vanillage.utils.event;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+
+import com.vanillage.utils.ClassToInstanceListHashMap;
+
+public class EventManager {
+    private final ClassToInstanceListHashMap listeners = new ClassToInstanceListHashMap();
+
+    public <L extends Listener<L, E>, E extends Event<L, E>> void registerListener(L listener) {
+        List<L> listeners = this.listeners.get(listener.getListenerClass());
+
+        if (listeners == null) {
{'fraction_non_alphanumeric': 0.12394752300763658, 'fraction_numerical': 0.03739964754258861, 'mean_word_length': 4.827153451226469, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 10, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1775569', 'n_tokens_mistral': 3573, 'n_tokens_neox': 3370, 'n_words': 586}