From 34655b8d4114ce6190d2974758becaebcc41308b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Tue, 14 Jul 2020 20:41:08 +0200 Subject: [PATCH] Add (untested) MVdWPlaceholderAPI support --- Bukkit/build.gradle | 2 + .../com/plotsquared/bukkit/BukkitMain.java | 10 ++- .../bukkit/placeholder/MVdWPlaceholders.java | 76 +++++++++++++++++++ ...laceholders.java => PAPIPlaceholders.java} | 4 +- Bukkit/src/main/resources/plugin.yml | 2 +- 5 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/MVdWPlaceholders.java rename Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/{Placeholders.java => PAPIPlaceholders.java} (97%) diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index e206fbe5b..fa23da2ff 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -14,6 +14,7 @@ repositories { maven { url = "https://ci.ender.zone/plugin/repository/everything/" } maven { url = "https://mvn.intellectualsites.com/content/repositories/snapshots" } maven { url = "https://repo.wea-ondara.net/repository/public/" } + maven { url = "http://repo.mvdw-software.be/content/groups/public/" } mavenLocal() } @@ -41,6 +42,7 @@ dependencies { implementation("net.alpenblock:BungeePerms:4.0-dev-106") compile("se.hyperver.hyperverse:Core:0.6.0-SNAPSHOT"){ transitive = false } compile('com.sk89q:squirrelid:1.0.0-SNAPSHOT'){ transitive = false } + compile('be.maximvdw:MVdWPlaceholderAPI:2.1.1-SNAPSHOT'){ transitive = false } } sourceCompatibility = 1.8 diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index c03cdd694..66bc5ed3c 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -36,8 +36,9 @@ import com.plotsquared.bukkit.listener.WorldEvents; import com.plotsquared.bukkit.managers.BukkitWorldManager; import com.plotsquared.bukkit.managers.HyperverseWorldManager; import com.plotsquared.bukkit.managers.MultiverseWorldManager; +import com.plotsquared.bukkit.placeholder.MVdWPlaceholders; import com.plotsquared.bukkit.placeholder.PlaceholderFormatter; -import com.plotsquared.bukkit.placeholder.Placeholders; +import com.plotsquared.bukkit.placeholder.PAPIPlaceholders; import com.plotsquared.bukkit.player.BukkitPlayerManager; import com.plotsquared.bukkit.queue.BukkitLocalQueue; import com.plotsquared.bukkit.schematic.BukkitSchematicHandler; @@ -363,7 +364,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { - new Placeholders().register(); + new PAPIPlaceholders().register(); if (Settings.Enabled_Components.EXTERNAL_PLACEHOLDERS) { ChatFormatter.formatters.add(new PlaceholderFormatter()); } @@ -373,6 +374,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< .debug(Captions.PREFIX + "&6PlaceholderAPI is not in use. Hook deactivated."); } + if (Bukkit.getPluginManager().isPluginEnabled("MVdWPlaceholderAPI")) { + new MVdWPlaceholders(this, PlotSquared.get().getPlaceholderRegistry()); + PlotSquared.log(Captions.PREFIX + "&cPlotSquared hooked into MVdWPlaceholderAPI"); + } + this.startMetrics(); if (Settings.Enabled_Components.WORLDS) { TaskManager.IMP.taskRepeat(this::unload, 20); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/MVdWPlaceholders.java b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/MVdWPlaceholders.java new file mode 100644 index 000000000..5bd835de0 --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/MVdWPlaceholders.java @@ -0,0 +1,76 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 IntellectualSites + * + * 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 com.plotsquared.bukkit.placeholder; + +import be.maximvdw.placeholderapi.PlaceholderAPI; +import com.google.common.eventbus.Subscribe; +import com.plotsquared.bukkit.util.BukkitUtil; +import com.plotsquared.core.PlotSquared; +import com.plotsquared.core.player.PlotPlayer; +import com.plotsquared.core.util.placeholders.Placeholder; +import com.plotsquared.core.util.placeholders.PlaceholderRegistry; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +/** + * Placeholder support for MVdWPlaceholderAPI + */ +public class MVdWPlaceholders { + + private final Plugin plugin; + private final PlaceholderRegistry registry; + + public MVdWPlaceholders(@NotNull final Plugin plugin, + @NotNull final PlaceholderRegistry registry) { + this.plugin = plugin; + this.registry = registry; + for (final Placeholder placeholder : registry.getPlaceholders()) { + this.addPlaceholder(placeholder); + } + PlotSquared.get().getEventDispatcher().registerListener(this); + } + + @Subscribe public void onNewPlaceholder(@NotNull final + PlaceholderRegistry.PlaceholderAddedEvent event) { + this.addPlaceholder(event.getPlaceholder()); + } + + private void addPlaceholder(@NotNull final Placeholder placeholder) { + PlaceholderAPI.registerPlaceholder(plugin, String.format("plotsquared_%s", placeholder.getKey()), + placeholderReplaceEvent -> { + if (!placeholderReplaceEvent.isOnline() || placeholderReplaceEvent.getPlayer() == null) { + return ""; + } + final PlotPlayer player = BukkitUtil.getPlayer(placeholderReplaceEvent.getPlayer()); + if (player == null) { + return ""; + } + return registry.getPlaceholderValue(placeholderReplaceEvent.getPlaceholder(), player); + }); + } + +} diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/PAPIPlaceholders.java similarity index 97% rename from Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java rename to Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/PAPIPlaceholders.java index 0c3b8bfad..52d30d5ed 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/PAPIPlaceholders.java @@ -31,9 +31,9 @@ import me.clip.placeholderapi.PlaceholderAPIPlugin; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import org.bukkit.entity.Player; -public class Placeholders extends PlaceholderExpansion { +public class PAPIPlaceholders extends PlaceholderExpansion { - public Placeholders() { + public PAPIPlaceholders() { } @Override public boolean persist() { diff --git a/Bukkit/src/main/resources/plugin.yml b/Bukkit/src/main/resources/plugin.yml index 41967220c..2dd7edbac 100644 --- a/Bukkit/src/main/resources/plugin.yml +++ b/Bukkit/src/main/resources/plugin.yml @@ -6,7 +6,7 @@ load: STARTUP description: "Easy, yet powerful Plot World generation and management." authors: [Citymonstret, Empire92, MattBDev, dordsor21, NotMyFault, SirYwell] website: https://www.spigotmc.org/resources/77506/ -softdepend: [Vault, PlaceholderAPI, Essentials, LuckPerms, BungeePerms] +softdepend: [Vault, PlaceholderAPI, Essentials, LuckPerms, BungeePerms, MVdWPlaceholderAPI] loadbefore: [MultiWorld, Multiverse-Core] depend: [WorldEdit] database: false