Add PlaceholderAPI integration

This commit is contained in:
Daniel Saukel 2019-03-07 21:22:40 +01:00
parent 74ac2d1221
commit f8fbeec9df
6 changed files with 122 additions and 4 deletions

10
pom.xml
View File

@ -111,6 +111,12 @@
<version>2.1.2</version> <version>2.1.2</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.9.2</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<repositories> <repositories>
<repository> <repository>
@ -136,6 +142,10 @@
<id>filoghost-repo</id> <id>filoghost-repo</id>
<url>https://ci.filoghost.me/plugin/repository/everything/</url> <url>https://ci.filoghost.me/plugin/repository/everything/</url>
</repository> </repository>
<repository>
<id>placeholderapi</id>
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository> <repository>
<id>dre-repo</id> <id>dre-repo</id>
<url>http://erethon.de/repo/</url> <url>http://erethon.de/repo/</url>

View File

@ -47,12 +47,14 @@ import de.erethon.dungeonsxl.sign.DSignTypeCache;
import de.erethon.dungeonsxl.sign.SignScriptCache; import de.erethon.dungeonsxl.sign.SignScriptCache;
import de.erethon.dungeonsxl.trigger.TriggerListener; import de.erethon.dungeonsxl.trigger.TriggerListener;
import de.erethon.dungeonsxl.trigger.TriggerTypeCache; import de.erethon.dungeonsxl.trigger.TriggerTypeCache;
import de.erethon.dungeonsxl.util.PlaceholderUtil;
import de.erethon.dungeonsxl.world.DWorldCache; import de.erethon.dungeonsxl.world.DWorldCache;
import java.io.File; import java.io.File;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
@ -122,6 +124,9 @@ public class DungeonsXL extends DREPlugin {
createCaches(); createCaches();
initCaches(); initCaches();
loadData(); loadData();
if (manager.isPluginEnabled("PlaceholderAPI")) {
PlaceholderAPI.registerPlaceholderHook("dxl", new PlaceholderUtil(this, "dxl"));
}
} }
@Override @Override

View File

@ -130,9 +130,7 @@ public class DGamePlayer extends DInstancePlayer {
return name; return name;
} }
/** @Override
* @return the DGroup of this player
*/
public DGroup getDGroup() { public DGroup getDGroup() {
if (dGroup == null) { if (dGroup == null) {
dGroup = DGroup.getByPlayer(player); dGroup = DGroup.getByPlayer(player);

View File

@ -142,6 +142,13 @@ public class DGlobalPlayer implements PlayerWrapper {
this.breakMode = breakMode; this.breakMode = breakMode;
} }
/**
* @return the DGroup of this player
*/
public DGroup getDGroup() {
return DGroup.getByPlayer(player);
}
/** /**
* @return if the player is in group chat * @return if the player is in group chat
*/ */

View File

@ -0,0 +1,98 @@
/*
* Copyright (C) 2012-2019 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.erethon.dungeonsxl.util;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.game.Game;
import de.erethon.dungeonsxl.player.DGroup;
import de.erethon.dungeonsxl.player.DPlayerCache;
import de.erethon.dungeonsxl.world.DGameWorld;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;
/**
* @author Daniel Saukel
*/
public class PlaceholderUtil extends PlaceholderExpansion {
private DungeonsXL plugin;
private DPlayerCache dPlayers;
private String identifier;
public PlaceholderUtil(DungeonsXL plugin, String identifier) {
this.plugin = plugin;
dPlayers = plugin.getDPlayerCache();
this.identifier = identifier;
}
@Override
public String getAuthor() {
return plugin.getDescription().getAuthors().toString();
}
@Override
public String getIdentifier() {
return identifier;
}
@Override
public String getRequiredPlugin() {
return plugin.getName();
}
@Override
public String getVersion() {
return plugin.getDescription().getVersion();
}
@Override
public String onPlaceholderRequest(Player player, String identifier) {
if (player == null) {
return "";
}
DGroup group = dPlayers.getByPlayer(player).getDGroup();
switch (identifier) {
case "group_members":
return group != null ? group.getPlayers().getNames().toString().substring(1, group.getPlayers().getNames().toString().length() - 2) : "";
case "group_name":
return group != null ? group.getName() : "";
case "group_name_raw":
return group != null ? group.getRawName() : "";
case "group_player_count":
return group != null ? String.valueOf(group.getPlayers().size()) : "";
case "game_player_count":
Game game = Game.getByPlayer(player);
return game != null ? String.valueOf(game.getPlayers().size()) : "";
case "floor_player_count":
DGameWorld gameWorld = group.getGameWorld();
return gameWorld != null ? String.valueOf(gameWorld.getPlayers().size()) : "";
case "dungeon_name":
return group != null ? group.getDungeonName() : "";
case "global_dungeon_count":
return String.valueOf(plugin.getDungeonCache().getDungeons().size());
case "global_floor_count":
return String.valueOf(plugin.getDWorldCache().getResources().size());
case "global_instance_count":
return String.valueOf(plugin.getDWorldCache().getInstances().size());
default:
return null;
}
}
}

View File

@ -4,7 +4,7 @@ version: ${project.version}${buildNo}
authors: [Frank Baumann, Milan Albrecht, Tobias Schmitz, Daniel Saukel] authors: [Frank Baumann, Milan Albrecht, Tobias Schmitz, Daniel Saukel]
description: ${project.description} description: ${project.description}
website: ${project.url} website: ${project.url}
softdepend: [CommandsXL, ItemsXL, Vault, Citizens, CustomMobs, InsaneMobs, MythicMobs, HolographicDisplays, LWC] softdepend: [CommandsXL, ItemsXL, Vault, Citizens, CustomMobs, InsaneMobs, MythicMobs, HolographicDisplays, LWC, PlaceholderAPI]
commands: commands:
dungeonsxl: dungeonsxl:
description: Reference command for DungeonsXL. description: Reference command for DungeonsXL.