Skip to content

Commit

Permalink
Merge pull request #15 from ClubObsidian/2.0.0
Browse files Browse the repository at this point in the history
2.0.0
  • Loading branch information
virustotalop authored Jul 7, 2019
2 parents 1ed3027 + a29fec2 commit e888648
Show file tree
Hide file tree
Showing 44 changed files with 639 additions and 415 deletions.
43 changes: 34 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
language: java
jdk:
- oraclejdk8
- openjdk8
- oraclejdk9
- openjdk10
dist: trusty

before_install:
- chmod +x gradlew
script:
- ./gradlew test
- ./gradlew jacocoTestReport
before_script:
- wget https://github.com/sormuras/bach/raw/master/install-jdk.sh

jobs:
include:
- stage: jdk.java.net - OpenJDK - GPL
env: JDK=8
script:
- jdk_switcher use openjdk8
- ./gradlew test
- ./gradlew jacocoTestReport
- # stage: ...
env: JDK=9
script:
- source install-jdk.sh -C -F 9
- ./gradlew test
- ./gradlew jacocoTestReport
- # stage: ...
env: JDK=10
script:
- source install-jdk.sh -C -F 10
- ./gradlew test
- ./gradlew jacocoTestReport


after_success:
- bash <(curl -s https://codecov.io/bash)
- bash <(curl -s https://codecov.io/bash)

after_script:
- echo JAVA_HOME = ${JAVA_HOME}
- echo PATH = ${PATH}
- ls ${JAVA_HOME}
- java -version
2 changes: 1 addition & 1 deletion LICENSE_HEADER
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2018 Club Obsidian and contributors.
Copyright 2019 Club Obsidian and contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
![trident](/img/trident_logo.png)
# Trident

[![Build Status](https://api.travis-ci.org/ClubObsidian/trident.svg?branch=master)](https://travis-ci.org/ClubObsidian/trident)
[![build artifacts](https://jitpack.io/v/clubobsidian/trident.svg)](https://jitpack.io/#clubobsidian/trident)
[![codecov](https://codecov.io/gh/ClubObsidian/trident/branch/master/graph/badge.svg)](https://codecov.io/gh/ClubObsidian/trident)
[![Known Vulnerabilities](https://snyk.io//test/github/ClubObsidian/trident/badge.svg?targetFile=build.gradle)](https://snyk.io//test/github/ClubObsidian/trident?targetFile=build.gradle)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![discord](https://discordapp.com/api/guilds/482823104905609248/widget.png)](https://discord.gg/EY5Tq6r)
[Javadocs](https://jitpack.io/com/github/clubobsidian/trident/1.0.8/javadoc/)
[![Discord](https://img.shields.io/discord/482823104905609248.svg?logo=discord)](https://discord.gg/EY5Tq6r)
[![javadocs](https://img.shields.io/badge/Javadocs-2.0.0-success.svg)](https://jitpack.io/com/github/clubobsidian/trident/2.0.0/javadoc/)

A dead simpile annotation event system that allows different event executor implementations.
A dead simpile annotation-based event bus that allows different event executor implementations.

Trident implements reflection and generated Javassist method executors.

## Inspiration

Inspiration for Trident.

* [Event4j](https://github.com/Techcable/Event4J)
* [Guava](https://github.com/google/guava)
* [mbassador](https://github.com/bennidi/mbassador)

## Build Artifacts

Build artifacts are hosted via [Jitpack.](https://jitpack.io/#clubobsidian/Trident/)
Expand All @@ -24,7 +33,7 @@ repositories {
maven { url 'https://jitpack.io' }
}
compile 'com.github.clubobsidian:trident:1.1.0'
compile 'com.github.clubobsidian:trident:2.0.0'
```

### Maven
Expand All @@ -40,13 +49,13 @@ compile 'com.github.clubobsidian:trident:1.1.0'
<dependency>
<groupId>com.github.clubobsidian</groupId>
<artifactId>trident</artifactId>
<version>1.1.0</version>
<version>2.0.0</version>
</dependency>
```

## Dependencies

* Javassist
* [Javassist](https://github.com/jboss-javassist/javassist)

## Development

Expand Down
38 changes: 19 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.4'
}
plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '5.0.0'
id 'jacoco'
id 'eclipse'
id 'idea'
}


apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'jacoco'
apply plugin: 'eclipse'
apply plugin: 'idea'


sourceCompatibility = 1.8
targetCompatibility = 1.8


group = 'com.clubobsidian'
version = '2.0.0'

repositories {
mavenCentral()
jcenter()
}

configurations {
shade
compile.extendsFrom shade
}

shadowJar {
baseName = 'trident'
classifier = null
version = null
relocate 'javassist', 'com.clubobsidian.trident.javassist'
}

Expand All @@ -38,10 +37,11 @@ dependencies {
}

jacocoTestReport {
reports {
xml.enabled true
html.enabled false
}
reports {
xml.enabled true
html.enabled false
html.destination file("${buildDir}/jacocoHtml")
}
}

task javadocJar(type: Jar, dependsOn: javadoc) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion src/main/java/com/clubobsidian/trident/Cancelable.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2018 Club Obsidian and contributors.
Copyright 2019 Club Obsidian and contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/clubobsidian/trident/Event.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2018 Club Obsidian and contributors.
Copyright 2019 Club Obsidian and contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2018 Club Obsidian and contributors.
Copyright 2019 Club Obsidian and contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -22,21 +22,22 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;

import com.clubobsidian.trident.event.DeadEvent;
import com.clubobsidian.trident.util.ClassUtil;
import com.clubobsidian.trident.util.EventDoublyLinkedList;
import com.clubobsidian.trident.util.EventNode;

/**
* Abstract class for implementing EventManager
* classes. For an example see @see com.clubobsidian.trident.impl.javaassist.JavaAssistEventManager
* Abstract class for implementing EventBus
* classes. For an example see @see com.clubobsidian.trident.impl.javaassist.JavaAssistEventBus
*
* @author virustotalop
*/
public abstract class EventManager {
public abstract class EventBus {

private Map<Listener, Queue<MethodExecutor>> registeredEventListeners;
private Map<Object, Queue<MethodExecutor>> registeredEventListeners;
private Map<Class<?>, EventDoublyLinkedList> registeredExecutors;
public EventManager()
public EventBus()
{
this.registeredEventListeners = new ConcurrentHashMap<>();
this.registeredExecutors = new ConcurrentHashMap<>();
Expand All @@ -51,7 +52,13 @@ public boolean callEvent(final Event event)
EventDoublyLinkedList executors = this.registeredExecutors.get(event.getClass());

if(executors == null)
{
if(!(event instanceof DeadEvent))
{
this.callEvent(new DeadEvent(event));
}
return false;
}

boolean ran = false;
EventNode node = executors.getHead();
Expand All @@ -74,16 +81,21 @@ public boolean callEvent(final Event event)
executor.execute(event);
node = node.getNext();
}

return ran;
}

/**
* @param listener listener to be registered
* @return if the listener was registered
*/
public boolean registerEvents(final Listener listener)
public boolean registerEvents(final Object listener)
{
if(this.registeredEventListeners.keySet().contains(listener))
if(listener == null)
{
return false;
}
else if(this.registeredEventListeners.keySet().contains(listener))
{
return false;
}
Expand All @@ -109,6 +121,10 @@ public boolean registerEvents(final Listener listener)

boolean ignoreCanceled = handler.ignoreCanceled();
MethodExecutor executor = this.createMethodExecutor(listener, method, ignoreCanceled);

if(executor == null)
return false;

this.registeredExecutors.get(eventClass).insert(executor, handler.priority());
this.registeredEventListeners.get(listener).add(executor);
}
Expand All @@ -118,14 +134,14 @@ public boolean registerEvents(final Listener listener)
return true;
}

protected abstract MethodExecutor createMethodExecutor(Listener listener, Method method, boolean ignoreCanceled);
protected abstract MethodExecutor createMethodExecutor(Object listener, Method method, boolean ignoreCanceled);

/**
*
* @param listener listener to be unregistered
* @return if the listener was unregistered
*/
public boolean unregisterEvents(Listener listener)
public boolean unregisterEvents(Object listener)
{
Queue<MethodExecutor> executors = this.registeredEventListeners.remove(listener);
if(executors == null)
Expand All @@ -142,5 +158,4 @@ public boolean unregisterEvents(Listener listener)
}
return true;
}

}
}
2 changes: 1 addition & 1 deletion src/main/java/com/clubobsidian/trident/EventHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2018 Club Obsidian and contributors.
Copyright 2019 Club Obsidian and contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/clubobsidian/trident/EventPriority.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2018 Club Obsidian and contributors.
Copyright 2019 Club Obsidian and contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/clubobsidian/trident/MethodExecutor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2018 Club Obsidian and contributors.
Copyright 2019 Club Obsidian and contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -26,10 +26,10 @@
*/
public abstract class MethodExecutor {

private Listener listener;
private Object listener;
private Method method;
private boolean ignoreCanceled;
public MethodExecutor(Listener listener, Method method, boolean ignoreCanceled)
public MethodExecutor(Object listener, Method method, boolean ignoreCanceled)
{
this.listener = listener;
this.method = method;
Expand All @@ -39,7 +39,7 @@ public MethodExecutor(Listener listener, Method method, boolean ignoreCanceled)
/**
* @return listener to execute events on
*/
public Listener getListener()
public Object getListener()
{
return this.listener;
}
Expand Down
Loading

0 comments on commit e888648

Please sign in to comment.