Skip to content

Commit

Permalink
Lets start the papi expansion update
Browse files Browse the repository at this point in the history
This will supports the dev. version of PlaceholderAPI, not tested
  • Loading branch information
montlikadani committed May 6, 2019
1 parent eace433 commit 2147c27
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/com/gamingmesh/jobs/Jobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.gamingmesh.jobs.MythicMobs.MythicMobInterface;
import com.gamingmesh.jobs.MythicMobs.MythicMobs2;
import com.gamingmesh.jobs.MythicMobs.MythicMobs4;
import com.gamingmesh.jobs.Placeholders.NewPlaceholderAPIHook;
import com.gamingmesh.jobs.Placeholders.Placeholder;
import com.gamingmesh.jobs.Placeholders.PlaceholderAPIHook;
import com.gamingmesh.jobs.Signs.SignUtil;
Expand Down Expand Up @@ -226,8 +227,14 @@ public Placeholder getPlaceholderAPIManager() {
private boolean setupPlaceHolderAPI() {
if (!getServer().getPluginManager().isPluginEnabled("PlaceholderAPI"))
return false;
if ((new PlaceholderAPIHook(this)).hook())
consoleMsg("&e[Jobs] PlaceholderAPI hooked.");
if (!getServer().getPluginManager().getPlugin("PlaceholderAPI").getDescription().getVersion().contains("2.10.0")) {
if ((new NewPlaceholderAPIHook(this)).register())
consoleMsg("&e[Jobs] PlaceholderAPI hooked.");
} else {
if ((new PlaceholderAPIHook(this)).hook())
consoleMsg("&e[Jobs] PlaceholderAPI hooked. This is a deprecated version. In the PlaceholderAPI"
+ " new version has removed the extension and we using the latest.");
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.gamingmesh.jobs.Placeholders;

import org.bukkit.OfflinePlayer;

import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.Placeholders.Placeholder.JobsPlaceHolders;

import me.clip.placeholderapi.expansion.PlaceholderExpansion;

public class NewPlaceholderAPIHook extends PlaceholderExpansion {

private Jobs plugin;

public NewPlaceholderAPIHook(Jobs plugin) {
this.plugin = plugin;
}

@Override
public String onRequest(OfflinePlayer player, String identifier) {
JobsPlaceHolders placeHolder = JobsPlaceHolders.getByName(identifier);
if (placeHolder == null)
return null;

return plugin.getPlaceholderAPIManager().getValue(player, placeHolder, "%" + Placeholder.pref + "_" + identifier + "%");
}

@Override
public String getAuthor() {
return null;
}

@Override
public String getIdentifier() {
return Placeholder.pref;
}

@Override
public String getVersion() {
return plugin.getDescription().getVersion();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;

import com.gamingmesh.jobs.Jobs;
Expand Down Expand Up @@ -332,9 +333,16 @@ private String translateOwnPlaceHolder(Player player, String message) {
return message;
}

public String getValue(OfflinePlayer player, JobsPlaceHolders placeHolder) {
return getValue(player.getPlayer(), placeHolder, null);
}

public String getValue(Player player, JobsPlaceHolders placeHolder) {
return getValue(player, placeHolder, null);
}

public String getValue(OfflinePlayer player, JobsPlaceHolders placeHolder, String value) {
return getValue(player != null ? player.getUniqueId() : null, placeHolder, value);
}

public String getValue(Player player, JobsPlaceHolders placeHolder, String value) {
Expand Down

0 comments on commit 2147c27

Please sign in to comment.