mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-28 13:36:33 +01:00
Add PlaceholderAPI integration
This commit is contained in:
parent
74ac2d1221
commit
f8fbeec9df
10
pom.xml
10
pom.xml
@ -111,6 +111,12 @@
|
||||
<version>2.1.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.9.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
@ -136,6 +142,10 @@
|
||||
<id>filoghost-repo</id>
|
||||
<url>https://ci.filoghost.me/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>dre-repo</id>
|
||||
<url>http://erethon.de/repo/</url>
|
||||
|
@ -47,12 +47,14 @@ import de.erethon.dungeonsxl.sign.DSignTypeCache;
|
||||
import de.erethon.dungeonsxl.sign.SignScriptCache;
|
||||
import de.erethon.dungeonsxl.trigger.TriggerListener;
|
||||
import de.erethon.dungeonsxl.trigger.TriggerTypeCache;
|
||||
import de.erethon.dungeonsxl.util.PlaceholderUtil;
|
||||
import de.erethon.dungeonsxl.world.DWorldCache;
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@ -122,6 +124,9 @@ public class DungeonsXL extends DREPlugin {
|
||||
createCaches();
|
||||
initCaches();
|
||||
loadData();
|
||||
if (manager.isPluginEnabled("PlaceholderAPI")) {
|
||||
PlaceholderAPI.registerPlaceholderHook("dxl", new PlaceholderUtil(this, "dxl"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -130,9 +130,7 @@ public class DGamePlayer extends DInstancePlayer {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the DGroup of this player
|
||||
*/
|
||||
@Override
|
||||
public DGroup getDGroup() {
|
||||
if (dGroup == null) {
|
||||
dGroup = DGroup.getByPlayer(player);
|
||||
|
@ -142,6 +142,13 @@ public class DGlobalPlayer implements PlayerWrapper {
|
||||
this.breakMode = breakMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the DGroup of this player
|
||||
*/
|
||||
public DGroup getDGroup() {
|
||||
return DGroup.getByPlayer(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the player is in group chat
|
||||
*/
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -4,7 +4,7 @@ version: ${project.version}${buildNo}
|
||||
authors: [Frank Baumann, Milan Albrecht, Tobias Schmitz, Daniel Saukel]
|
||||
description: ${project.description}
|
||||
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:
|
||||
dungeonsxl:
|
||||
description: Reference command for DungeonsXL.
|
||||
|
Loading…
Reference in New Issue
Block a user