diff --git a/pom.xml b/pom.xml index 0c86289b..7a84e801 100644 --- a/pom.xml +++ b/pom.xml @@ -111,6 +111,12 @@ 2.1.2 provided + + me.clip + placeholderapi + 2.9.2 + provided + @@ -136,6 +142,10 @@ filoghost-repo https://ci.filoghost.me/plugin/repository/everything/ + + placeholderapi + http://repo.extendedclip.com/content/repositories/placeholderapi/ + dre-repo http://erethon.de/repo/ diff --git a/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java b/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java index 45ed214c..1821ea2c 100644 --- a/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java +++ b/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java @@ -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 diff --git a/src/main/java/de/erethon/dungeonsxl/player/DGamePlayer.java b/src/main/java/de/erethon/dungeonsxl/player/DGamePlayer.java index 983ae019..6b3403ad 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DGamePlayer.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DGamePlayer.java @@ -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); diff --git a/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java b/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java index ff4ad17c..17486976 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java @@ -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 */ diff --git a/src/main/java/de/erethon/dungeonsxl/util/PlaceholderUtil.java b/src/main/java/de/erethon/dungeonsxl/util/PlaceholderUtil.java new file mode 100644 index 00000000..54b4af66 --- /dev/null +++ b/src/main/java/de/erethon/dungeonsxl/util/PlaceholderUtil.java @@ -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 . + */ +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; + } + } + +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 12b47d05..efb69a65 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -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.