Added palceholderAPI supprt

This commit is contained in:
Magnus Ulf
2019-01-20 00:19:00 +01:00
parent da5df54b62
commit bb9a72dbf6
4 changed files with 97 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
package com.massivecraft.factions.integration.placeholderapi;
import com.massivecraft.massivecore.Integration;
public class IntegrationPlaceholderAPI extends Integration
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static IntegrationPlaceholderAPI i = new IntegrationPlaceholderAPI();
public static IntegrationPlaceholderAPI get() { return i; }
private IntegrationPlaceholderAPI()
{
this.setPluginName("PlaceholderAPI");
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void setIntegrationActiveInner(boolean active)
{
PlaceholderFactions.get().register();
}
}

View File

@@ -0,0 +1,62 @@
package com.massivecraft.factions.integration.placeholderapi;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.MPlayer;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;
public class PlaceholderFactions extends PlaceholderExpansion
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static PlaceholderFactions i = new PlaceholderFactions();
public static PlaceholderFactions get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
public String getIdentifier()
{
return "factions";
}
public String getAuthor()
{
return "Madus";
}
public String getVersion()
{
return Factions.get().getDescription().getVersion();
}
@Override
public String onPlaceholderRequest(Player player, String params)
{
System.out.println("A");
if (player == null) return null;
System.out.println("B");
MPlayer mplayer = MPlayer.get(player);
if ("role".equals(params)) params = "rank";
switch (params)
{
case "faction": return mplayer.getFaction().describeTo(mplayer);
case "power": return Double.toString(mplayer.getPower());
case "powermax": return Double.toString(mplayer.getPowerMax());
case "factionpower": return Double.toString(mplayer.getFaction().getPower());
case "factionpowermax": return Double.toString(mplayer.getFaction().getPowerMax());
case "title": return mplayer.getTitle();
case "rank": return mplayer.getRank().getName();
case "claims": return Long.toString(BoardColl.get().getAll().stream().mapToInt(board -> board.getCount(mplayer.getFaction())).sum());
case "onlinemembers": return Integer.toString(mplayer.getFaction().getMPlayersWhereOnlineTo(mplayer).size());
case "allmembers": return Integer.toString(mplayer.getFaction().getMPlayers().size());
}
return null;
}
}