Skip to content

Commit

Permalink
Added support for Clip's placeholder API
Browse files Browse the repository at this point in the history
  • Loading branch information
bramhaag committed Jan 13, 2017
1 parent 77fad4a commit bd68eaa
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 40 deletions.
1 change: 1 addition & 0 deletions guilds.iml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot:1.10-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: be.maximvdw:MVdWPlaceholderAPI:1.0.2-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.8-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: me.clip:placeholderapi:2.0.8" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:2.5.1" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.21" level="project" />
Expand Down
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
<name>MVdW Public Repositories</name>
<url>http://repo.mvdw-software.be/content/groups/public/</url>
</repository>

<repository>
<id>placeholderapi</id>
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -36,6 +41,13 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.0.8</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
Expand Down
64 changes: 25 additions & 39 deletions src/main/java/me/bramhaag/guilds/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@
import co.aikar.taskchain.TaskChainFactory;
import me.bramhaag.guilds.commands.*;
import me.bramhaag.guilds.commands.base.CommandHandler;
import me.bramhaag.guilds.database.Callback;
import me.bramhaag.guilds.database.DatabaseProvider;
import me.bramhaag.guilds.database.databases.json.Json;
import me.bramhaag.guilds.database.databases.mysql.MySql;
import me.bramhaag.guilds.guild.Guild;
import me.bramhaag.guilds.guild.GuildHandler;
import me.bramhaag.guilds.listeners.ChatListener;
import me.bramhaag.guilds.listeners.JoinListener;
import me.bramhaag.guilds.placeholders.mvdwplaceholderapi.MVdWGuild;
import me.bramhaag.guilds.placeholders.mvdwplaceholderapi.MVdWGuildMaster;
import me.bramhaag.guilds.placeholders.mvdwplaceholderapi.MVdWGuildMemberCount;
import me.bramhaag.guilds.placeholders.mvdwplaceholderapi.MVdWGuildPrefix;
import me.bramhaag.guilds.placeholders.placeholderapi.ClipGuild;
import me.bramhaag.guilds.placeholders.placeholderapi.ClipGuildMaster;
import me.bramhaag.guilds.placeholders.placeholderapi.ClipGuildMemberCount;
import me.bramhaag.guilds.placeholders.placeholderapi.ClipGuildPrefix;
import me.bramhaag.guilds.scoreboard.GuildScoreboardHandler;
import me.bramhaag.guilds.updater.Updater;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -61,43 +67,7 @@ public void onEnable() {
//scoreboardHandler is enabled after the guilds are loaded
scoreboardHandler = new GuildScoreboardHandler();

if (Bukkit.getPluginManager().isPluginEnabled("MVdWPlaceholderAPI")) {
PlaceholderAPI.registerPlaceholder(this, "guild", event -> {
Guild guild = Guild.getGuild(event.getPlayer().getUniqueId());
if (guild == null) {
return "N/A";
}

return guild.getName();
});

PlaceholderAPI.registerPlaceholder(this, "guild-prefix", event -> {
Guild guild = Guild.getGuild(event.getPlayer().getUniqueId());
if (guild == null) {
return "N/A";
}

return guild.getPrefix();
});

PlaceholderAPI.registerPlaceholder(this, "guild-master", event -> {
Guild guild = Guild.getGuild(event.getPlayer().getUniqueId());
if (guild == null) {
return "N/A";
}

return Bukkit.getPlayer(guild.getGuildMaster().getUniqueId()).getName();
});

PlaceholderAPI.registerPlaceholder(this, "member-count", event -> {
Guild guild = Guild.getGuild(event.getPlayer().getUniqueId());
if (guild == null) {
return "N/A";
}

return String.valueOf(guild.getMembers().size());
});
}
initializePlaceholder();

getCommand("guild").setExecutor(commandHandler);

Expand Down Expand Up @@ -209,4 +179,20 @@ public static long getCreationTime() {
public static Main getInstance() {
return instance;
}

private void initializePlaceholder() {
if (Bukkit.getPluginManager().isPluginEnabled("MVdWPlaceholderAPI")) {
PlaceholderAPI.registerPlaceholder(this, "guild", new MVdWGuild());
PlaceholderAPI.registerPlaceholder(this, "guild-master", new MVdWGuildMaster());
PlaceholderAPI.registerPlaceholder(this, "guild-member-count", new MVdWGuildMemberCount());
PlaceholderAPI.registerPlaceholder(this, "guild-prefix", new MVdWGuildPrefix());
}

if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
new ClipGuild(this).hook();
new ClipGuildMaster(this).hook();
new ClipGuildMemberCount(this).hook();
new ClipGuildPrefix(this).hook();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package me.bramhaag.guilds.placeholders.mvdwplaceholderapi;

import be.maximvdw.placeholderapi.PlaceholderReplaceEvent;
import be.maximvdw.placeholderapi.PlaceholderReplacer;
import me.bramhaag.guilds.guild.Guild;

public class MVdWGuild implements PlaceholderReplacer {

@Override
public String onPlaceholderReplace(PlaceholderReplaceEvent event) {
Guild guild = Guild.getGuild(event.getPlayer().getUniqueId());
if (guild == null) {
return "N/A";
}

return guild.getPrefix();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package me.bramhaag.guilds.placeholders.mvdwplaceholderapi;

import be.maximvdw.placeholderapi.PlaceholderReplaceEvent;
import be.maximvdw.placeholderapi.PlaceholderReplacer;
import me.bramhaag.guilds.guild.Guild;
import org.bukkit.Bukkit;

public class MVdWGuildMaster implements PlaceholderReplacer {
@Override
public String onPlaceholderReplace(PlaceholderReplaceEvent event) {
Guild guild = Guild.getGuild(event.getPlayer().getUniqueId());
if (guild == null) {
return "N/A";
}

return Bukkit.getPlayer(guild.getGuildMaster().getUniqueId()).getName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package me.bramhaag.guilds.placeholders.mvdwplaceholderapi;

import be.maximvdw.placeholderapi.PlaceholderReplaceEvent;
import be.maximvdw.placeholderapi.PlaceholderReplacer;
import me.bramhaag.guilds.guild.Guild;

public class MVdWGuildMemberCount implements PlaceholderReplacer {

@Override
public String onPlaceholderReplace(PlaceholderReplaceEvent event) {
Guild guild = Guild.getGuild(event.getPlayer().getUniqueId());
if (guild == null) {
return "N/A";
}

return String.valueOf(guild.getMembers().size());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package me.bramhaag.guilds.placeholders.mvdwplaceholderapi;

import be.maximvdw.placeholderapi.PlaceholderReplaceEvent;
import be.maximvdw.placeholderapi.PlaceholderReplacer;
import me.bramhaag.guilds.guild.Guild;

public class MVdWGuildPrefix implements PlaceholderReplacer {

@Override
public String onPlaceholderReplace(PlaceholderReplaceEvent event) {
Guild guild = Guild.getGuild(event.getPlayer().getUniqueId());
if (guild == null) {
return "N/A";
}

return guild.getPrefix();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package me.bramhaag.guilds.placeholders.placeholderapi;

import me.bramhaag.guilds.guild.Guild;
import me.clip.placeholderapi.external.EZPlaceholderHook;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

public class ClipGuild extends EZPlaceholderHook {

public ClipGuild(Plugin plugin) {
super(plugin, "guild");
}

@Override
public String onPlaceholderRequest(Player player, String s) {
Guild guild = Guild.getGuild(player.getUniqueId());
if (guild == null) {
return "N/A";
}

return guild.getName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package me.bramhaag.guilds.placeholders.placeholderapi;

import me.bramhaag.guilds.guild.Guild;
import me.clip.placeholderapi.external.EZPlaceholderHook;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

public class ClipGuildMaster extends EZPlaceholderHook {

public ClipGuildMaster(Plugin plugin) {
super(plugin, "guild-master");
}

@Override
public String onPlaceholderRequest(Player player, String s) {
Guild guild = Guild.getGuild(player.getUniqueId());
if (guild == null) {
return "N/A";
}

return Bukkit.getPlayer(guild.getGuildMaster().getUniqueId()).getName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package me.bramhaag.guilds.placeholders.placeholderapi;

import me.bramhaag.guilds.guild.Guild;
import me.clip.placeholderapi.external.EZPlaceholderHook;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

public class ClipGuildMemberCount extends EZPlaceholderHook {

public ClipGuildMemberCount(Plugin plugin) {
super(plugin, "guild-member-count");
}

@Override
public String onPlaceholderRequest(Player player, String s) {
Guild guild = Guild.getGuild(player.getUniqueId());
if (guild == null) {
return "N/A";
}

return String.valueOf(guild.getMembers().size());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package me.bramhaag.guilds.placeholders.placeholderapi;

import me.bramhaag.guilds.guild.Guild;
import me.clip.placeholderapi.external.EZPlaceholderHook;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

public class ClipGuildPrefix extends EZPlaceholderHook {

public ClipGuildPrefix(Plugin plugin) {
super(plugin, "guild-prefix");
}

@Override
public String onPlaceholderRequest(Player player, String s) {
Guild guild = Guild.getGuild(player.getUniqueId());
if (guild == null) {
return "N/A";
}

return guild.getPrefix(); }
}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: ${project.name}
version: ${project.version}
main: me.bramhaag.guilds.Main
softdepends: [MVdWPlaceholderAPI]
softdepends: [MVdWPlaceholderAPI, PlaceholderAPI]
author: bramhaag

commands:
Expand Down

0 comments on commit bd68eaa

Please sign in to comment.