Skip to content

Commit

Permalink
PAPI Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Avalanche7CZ committed Oct 19, 2024
1 parent bfd9d34 commit eb477f7
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = 'eu.avalanche7'
version = '1.0.4'
version = '1.0.5'

apply plugin: 'java'

Expand All @@ -21,6 +21,9 @@ repositories {
name = 'spigotmc-repo'
url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
}
maven {
url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/'
}
maven {
name = 'craftbukkit-repo'
url = 'https://dl.bintray.com/mbax/craftbukkit-repo'
Expand All @@ -32,5 +35,6 @@ dependencies {
compileOnly files('libs/BCLForgeLib-1.0.jar')
compileOnly files('libs/VaultAPI-1.5.jar')
compileOnly files('libs/forge-1.7.10-10.13.4.1614-1.7.10-universal.jar')
compileOnly files('libs/PlaceholderAPI-2.11.6.jar')

}
7 changes: 7 additions & 0 deletions src/main/java/eu/avalanche7/BetterChunkLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public void onEnable() {
throw new RuntimeException("BCLForgeLib is needed to run this plugin!");
}

if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new PlaceHolderIntegration(this).register();
getLogger().info("PlaceholderAPI found and integrated.");
} else {
getLogger().warning("PlaceholderAPI not found. Placeholders will not be available.");
}

Bukkit.getConsoleSender().sendMessage("=========================");
Bukkit.getConsoleSender().sendMessage("BetterChunkLoader");
Bukkit.getConsoleSender().sendMessage("Version " + getDescription().getVersion());
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/eu/avalanche7/PlaceHolderIntegration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package eu.avalanche7;

import eu.avalanche7.datastore.DataStoreManager;
import eu.avalanche7.datastore.IDataStore;
import eu.avalanche7.datastore.PlayerData;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer;


public class PlaceHolderIntegration extends PlaceholderExpansion {

private final BetterChunkLoader plugin;

public PlaceHolderIntegration(BetterChunkLoader plugin) {
this.plugin = plugin;
}

@Override
public boolean canRegister() {
return true;
}

@Override
public String getIdentifier() {
return "chunkloader";
}

@Override
public String getAuthor() {
return plugin.getDescription().getAuthors().toString();
}

@Override
public String getVersion() {
return plugin.getDescription().getVersion();
}

@Override
public String onRequest(OfflinePlayer player, String identifier) {
if (player == null) {
return null;
}

IDataStore dataStore = DataStoreManager.getDataStore();
PlayerData playerData = dataStore.getPlayerData(player.getUniqueId());

switch (identifier) {
case "chunks_total":
return String.valueOf(playerData.getAlwaysOnChunksAmount() + playerData.getOnlineOnlyChunksAmount());
case "chunks_active":
return String.valueOf(dataStore.getChunkLoaders(player.getUniqueId()).size());
case "chunks_onlineonly_active":
return String.valueOf(dataStore.getOnlineOnlyFreeChunksAmount(player.getUniqueId()));
case "chunks_alwayson_active":
return String.valueOf(dataStore.getAlwaysOnFreeChunksAmount(player.getUniqueId()));
case "chunks_alwaysonly":
return String.valueOf(playerData.getAlwaysOnChunksAmount());
case "chunks_onlineonly":
return String.valueOf(playerData.getOnlineOnlyChunksAmount());
default:
return null;
}
}
}
4 changes: 2 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: BetterChunkLoader
main: eu.avalanche7.BetterChunkLoader
version: 1.0.4

version: 1.0.5
softdepend: [PlaceholderAPI]
commands:
betterchunkloader:
description: OP commands
Expand Down

0 comments on commit eb477f7

Please sign in to comment.