Skip to content

Commit

Permalink
Refactor terminables - helper uses semver from now onwards.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucko committed Aug 27, 2017
1 parent 906a1d0 commit 7221c20
Show file tree
Hide file tree
Showing 21 changed files with 379 additions and 200 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ Then, you can add dependencies for each helper module.
<dependency>
<groupId>me.lucko</groupId>
<artifactId>helper</artifactId>
<version>1.7.0</version>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand All @@ -598,7 +598,7 @@ Then, you can add dependencies for each helper module.
#### Gradle
```gradle
dependencies {
compile ("me.lucko:helper:1.7.0")
compile ("me.lucko:helper:2.0.0")
}
```

Expand All @@ -609,7 +609,7 @@ dependencies {
<dependency>
<groupId>me.lucko</groupId>
<artifactId>helper-sql</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand All @@ -618,7 +618,7 @@ dependencies {
#### Gradle
```gradle
dependencies {
compile ("me.lucko:helper-sql:1.0.1")
compile ("me.lucko:helper-sql:1.0.2")
}
```

Expand All @@ -629,7 +629,7 @@ dependencies {
<dependency>
<groupId>me.lucko</groupId>
<artifactId>helper-redis</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand All @@ -638,6 +638,6 @@ dependencies {
#### Gradle
```gradle
dependencies {
compile ("me.lucko:helper-redis:1.0.2")
compile ("me.lucko:helper-redis:1.0.3")
}
```
4 changes: 2 additions & 2 deletions helper-redis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<artifactId>helper-redis</artifactId>
<packaging>jar</packaging>
<version>1.0.2</version>
<version>1.0.3</version>

<name>helper-redis</name>
<description>Provides Redis clients and implements the helper Messaging interface using Jedis.</description>
Expand Down Expand Up @@ -134,7 +134,7 @@
<dependency>
<groupId>me.lucko</groupId>
<artifactId>helper</artifactId>
<version>1.7.1</version>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import me.lucko.helper.messaging.Channel;
import me.lucko.helper.redis.HelperRedis;
import me.lucko.helper.redis.RedisCredentials;
import me.lucko.helper.terminable.TerminableRegistry;
import me.lucko.helper.terminable.registry.TerminableRegistry;
import me.lucko.helper.utils.Log;

import redis.clients.jedis.Jedis;
Expand Down Expand Up @@ -114,7 +114,7 @@ public void run() {
listener.subscribe(channel);
}

}, 2L, 2L).register(registry);
}, 2L, 2L).bindWith(registry);

messenger = new AbstractMessenger(
(channel, message) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public class RedisPlugin extends ExtendedJavaPlugin implements RedisProvider {
private HelperRedis globalRedis;

@Override
public void onEnable() {
protected void enable() {
this.globalCredentials = RedisCredentials.fromConfig(loadConfig("config.yml"));
this.globalRedis = getRedis(this.globalCredentials);
this.globalRedis.register(this);
this.globalRedis.bindWith(this);

// expose all instances as services.
provideService(RedisProvider.class, this);
Expand Down
4 changes: 2 additions & 2 deletions helper-sql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<artifactId>helper-sql</artifactId>
<packaging>jar</packaging>
<version>1.0.1</version>
<version>1.0.2</version>

<name>helper-sql</name>
<description>Provides SQL datasources using HikariCP.</description>
Expand Down Expand Up @@ -139,7 +139,7 @@
<dependency>
<groupId>me.lucko</groupId>
<artifactId>helper</artifactId>
<version>1.7.1</version>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package me.lucko.helper.sql.plugin;

import me.lucko.helper.maven.LibraryLoader;
import me.lucko.helper.maven.MavenLibrary;
import me.lucko.helper.plugin.ExtendedJavaPlugin;
import me.lucko.helper.sql.DatabaseCredentials;
Expand All @@ -38,15 +37,10 @@ public class SqlPlugin extends ExtendedJavaPlugin implements SqlProvider {
private HelperDataSource globalDataSource;

@Override
public void onLoad() {
LibraryLoader.loadAll(SqlPlugin.class);
}

@Override
public void onEnable() {
protected void enable() {
this.globalCredentials = DatabaseCredentials.fromConfig(loadConfig("config.yml"));
this.globalDataSource = getDataSource(this.globalCredentials);
this.globalDataSource.register(this);
this.globalDataSource.bindWith(this);

// expose all instances as services.
provideService(SqlProvider.class, this);
Expand Down
2 changes: 1 addition & 1 deletion helper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<artifactId>helper</artifactId>
<packaging>jar</packaging>
<version>1.7.1</version>
<version>2.0.0</version>

<name>helper</name>
<description>A utility to reduce boilerplate code in Bukkit plugins.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import me.lucko.helper.Events;
import me.lucko.helper.gson.JsonBuilder;
import me.lucko.helper.serialize.Position;
import me.lucko.helper.terminable.TerminableRegistry;
import me.lucko.helper.terminable.registry.TerminableRegistry;
import me.lucko.helper.utils.Color;

import org.bukkit.Location;
Expand Down Expand Up @@ -198,7 +198,7 @@ public void setClickCallback(Consumer<Player> clickCallback) {
}
}
})
.register(this.listeners);
.bindWith(this.listeners);

Events.subscribe(EntityDamageByEntityEvent.class)
.filter(e -> e.getEntity() instanceof ArmorStand)
Expand All @@ -215,7 +215,7 @@ public void setClickCallback(Consumer<Player> clickCallback) {
}
}
})
.register(this.listeners);
.bindWith(this.listeners);
}
}

Expand Down
21 changes: 11 additions & 10 deletions helper/src/main/java/me/lucko/helper/menu/Gui.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
import me.lucko.helper.metadata.MetadataKey;
import me.lucko.helper.metadata.MetadataMap;
import me.lucko.helper.terminable.Terminable;
import me.lucko.helper.terminable.TerminableRegistry;
import me.lucko.helper.terminable.TerminableConsumer;
import me.lucko.helper.terminable.registry.TerminableRegistry;
import me.lucko.helper.timings.Timings;
import me.lucko.helper.utils.Color;

Expand All @@ -55,7 +56,7 @@
/**
* A simple GUI abstraction
*/
public abstract class Gui implements Consumer<Terminable> {
public abstract class Gui implements TerminableConsumer {
public static final MetadataKey<Gui> OPEN_GUI_KEY = MetadataKey.create("open-gui", Gui.class);

/**
Expand Down Expand Up @@ -134,14 +135,14 @@ public void setFallbackGui(Function<Player, Gui> fallbackGui) {
this.fallbackGui = fallbackGui;
}

public void addInvalidationCallback(Runnable runnable) {
Preconditions.checkNotNull(runnable, "runnable");
terminableRegistry.accept(Terminable.of(runnable));
@Override
public <T extends Terminable> T bind(T terminable) {
return terminableRegistry.bind(terminable);
}

@Override
public void accept(Terminable terminable) {
terminableRegistry.accept(terminable);
public <T extends Runnable> T bindRunnable(T runnable) {
return terminableRegistry.bindRunnable(runnable);
}

public boolean isFirstDraw() {
Expand Down Expand Up @@ -306,13 +307,13 @@ private void startListening() {
}
}
})
.register(this);
.bindWith(this);

Events.subscribe(PlayerQuitEvent.class)
.filter(e -> e.getPlayer().equals(player))
.filter(e -> isValid())
.handler(e -> invalidate())
.register(this);
.bindWith(this);

Events.subscribe(InventoryCloseEvent.class)
.filter(e -> e.getPlayer().equals(player))
Expand All @@ -335,7 +336,7 @@ private void startListening() {
fallback.apply(player).open();
}, 1L);
})
.register(this);
.bindWith(this);
}

private static String getHandlerName(Consumer consumer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@

import me.lucko.helper.Scheduler;
import me.lucko.helper.plugin.ExtendedJavaPlugin;
import me.lucko.helper.terminable.Terminable;
import me.lucko.helper.terminable.TerminableRegistry;
import me.lucko.helper.terminable.registry.TerminableRegistry;
import me.lucko.helper.utils.LoaderUtils;
import me.lucko.helper.utils.Players;

Expand Down Expand Up @@ -305,17 +304,17 @@ private BungeeMessaging() {

if (plugin instanceof ExtendedJavaPlugin) {
ExtendedJavaPlugin ejp = (ExtendedJavaPlugin) plugin;
ejp.registerTerminable(Terminable.of(() -> {
ejp.bindRunnable(() -> {
BungeeMessaging.instance = null;
terminableRegistry.terminate();
}));
});
}

plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, CHANNEL);
terminableRegistry.accept(Terminable.of(() -> plugin.getServer().getMessenger().unregisterOutgoingPluginChannel(plugin, CHANNEL)));
terminableRegistry.bindRunnable(() -> plugin.getServer().getMessenger().unregisterOutgoingPluginChannel(plugin, CHANNEL));

plugin.getServer().getMessenger().registerIncomingPluginChannel(plugin, CHANNEL, this);
terminableRegistry.accept(Terminable.of(() -> plugin.getServer().getMessenger().unregisterIncomingPluginChannel(plugin, CHANNEL, this)));
terminableRegistry.bindRunnable(() -> plugin.getServer().getMessenger().unregisterIncomingPluginChannel(plugin, CHANNEL, this));

Scheduler.runTaskRepeatingSync(() -> {
if (queuedMessages.isEmpty()) {
Expand All @@ -329,7 +328,7 @@ private BungeeMessaging() {
return true;
});
}
}, 60L, 60L).register(terminableRegistry);
}, 60L, 60L).bindWith(terminableRegistry);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@

package me.lucko.helper.plugin;

import me.lucko.helper.Commands;
import me.lucko.helper.Helper;
import me.lucko.helper.utils.LoaderUtils;
import me.lucko.helper.utils.Players;

import org.bukkit.plugin.Plugin;

/**
* Dummy plugin to make the server load this lib.
Expand All @@ -38,7 +43,23 @@ public DummyHelperPlugin() {
}

@Override
public void onEnable() {
protected void enable() {
// cache the loader plugin
LoaderUtils.getPlugin();

// provide an info command
Commands.create()
.handler(c -> {
Players.msg(c.getSender(), "&7[&6helper&7] &7Running &6helper v" + getDescription().getVersion() + "&7.");
if (Helper.plugins().isPluginEnabled("helper-sql")) {
Plugin sqlPlugin = getPlugin("helper-sql", Plugin.class);
Players.msg(c.getSender(), "&7[&6helper&7] &7Running &6helper-sql v" + sqlPlugin.getDescription().getVersion() + "&7.");
}
if (Helper.plugins().isPluginEnabled("helper-redis")) {
Plugin sqlPlugin = getPlugin("helper-redis", Plugin.class);
Players.msg(c.getSender(), "&7[&6helper&7] &7Running &6helper-redis " + sqlPlugin.getDescription().getVersion() + "&7.");
}
})
.register(this, "helper");
}
}
Loading

0 comments on commit 7221c20

Please sign in to comment.