Skip to content

Commit

Permalink
Merge pull request #6 from HimaJyun/vault-init-bug
Browse files Browse the repository at this point in the history
fix: Vault initialize
  • Loading branch information
HimaJyun authored Apr 20, 2019
2 parents 540062a + de02ff6 commit 5cd8d39
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Economy base plugin for Bukkit/Spigot
<dependency>
<groupId>jp.jyn</groupId>
<artifactId>Jecon</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>jp.jyn</groupId>
<artifactId>Jecon</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<url>https://github.com/HimaJyun/Jecon</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
30 changes: 17 additions & 13 deletions src/main/java/jp/jyn/jecon/Jecon.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class Jecon extends JavaPlugin {

private ConfigLoader config;
private BalanceRepository repository;
private VaultEconomy economy;

// Stack(LIFO)
private final Deque<Runnable> destructor = new ArrayDeque<>();
Expand Down Expand Up @@ -74,13 +75,17 @@ public void onEnable() {
});

// register vault
Plugin vault = getServer().getPluginManager().getPlugin("Vault");
if (vault != null) {
if (vault.isEnabled()) {
vaultHook(registry);
} else {
getServer().getPluginManager().registerEvents(new VaultRegister(registry), this);
if (economy == null) {
Plugin vault = getServer().getPluginManager().getPlugin("Vault");
if (vault != null) {
if (vault.isEnabled()) {
vaultHook(registry);
} else {
getServer().getPluginManager().registerEvents(new VaultRegister(registry), this);
}
}
} else {
economy.init(main, registry, repository);
}

// register events
Expand Down Expand Up @@ -112,13 +117,12 @@ public void onEnable() {
}

private void vaultHook(UUIDRegistry registry) {
getServer().getServicesManager().register(
Economy.class,
new VaultEconomy(config.getMainConfig(), registry, repository),
this,
ServicePriority.Normal
);
this.destructor.addFirst(() -> getServer().getServicesManager().unregisterAll(this));
if (economy != null) {
return;
}

economy = new VaultEconomy(config.getMainConfig(), registry, repository);
getServer().getServicesManager().register(Economy.class, economy, this, ServicePriority.Normal);
getLogger().info("Hooked Vault");
}

Expand Down
13 changes: 9 additions & 4 deletions src/main/java/jp/jyn/jecon/VaultEconomy.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@

@PackagePrivate
class VaultEconomy implements Economy {
private final BigDecimal defaultBalance;
private BigDecimal defaultBalance;

private final UUIDRegistry registry;
private final MainConfig config;
private final BalanceRepository repository;
private UUIDRegistry registry;
private MainConfig config;
private BalanceRepository repository;

@PackagePrivate
VaultEconomy(MainConfig config, UUIDRegistry registry, BalanceRepository repository) {
this.init(config, registry, repository);
}

@PackagePrivate
void init(MainConfig config, UUIDRegistry registry, BalanceRepository repository) {
this.registry = registry;
this.config = config;
this.repository = repository;
Expand Down

0 comments on commit 5cd8d39

Please sign in to comment.