Merge branch 'features/v5/placeholders' into v5

This commit is contained in:
N0tMyFaultOG
2020-07-16 18:48:45 +02:00
18 changed files with 702 additions and 225 deletions

View File

@ -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:3.1.1-SNAPSHOT'){ transitive = false }
}
sourceCompatibility = 1.8

View File

@ -21,7 +21,7 @@
<dependency>
<groupId>com.plotsquared</groupId>
<artifactId>PlotSquared-Core</artifactId>
<version>5.12.5</version>
<version>5.13.0</version>
<scope>compile</scope>
</dependency>
<dependency>
@ -84,6 +84,18 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>be.maximvdw</groupId>
<artifactId>MVdWPlaceholderAPI</artifactId>
<version>3.1.1-SNAPSHOT</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>*</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-core</artifactId>

View File

@ -34,13 +34,14 @@ import com.plotsquared.bukkit.listener.EntitySpawnListener;
import com.plotsquared.bukkit.listener.PaperListener;
import com.plotsquared.bukkit.listener.PlayerEventListener;
import com.plotsquared.bukkit.listener.ProjectileEventListener;
import com.plotsquared.bukkit.listener.ServerListener;
import com.plotsquared.bukkit.listener.SingleWorldListener;
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.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;
@ -366,14 +367,11 @@ 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());
}
PlotSquared.log(Captions.PREFIX + "&6PlotSquared hooked into PlaceholderAPI");
} else {
PlotSquared
.debug(Captions.PREFIX + "&6PlaceholderAPI is not in use. Hook deactivated.");
}
this.startMetrics();
@ -1054,6 +1052,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
getServer().getPluginManager().registerEvents(new WorldEvents(), this);
}
@Override
public void registerServerEvents() {
getServer().getPluginManager().registerEvents(new ServerListener(this), this);
}
@NotNull @Override public IndependentPlotGenerator getDefaultGenerator() {
return new HybridGen();
}

View File

@ -0,0 +1,51 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* 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 <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.bukkit.listener;
import com.plotsquared.bukkit.BukkitMain;
import com.plotsquared.bukkit.placeholder.MVdWPlaceholders;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerLoadEvent;
public class ServerListener implements Listener {
private final BukkitMain plugin;
public ServerListener(BukkitMain plugin) {
this.plugin = plugin;
}
@EventHandler public void onServerLoad(ServerLoadEvent event) {
if (Bukkit.getPluginManager().getPlugin("MVdWPlaceholderAPI") != null) {
new MVdWPlaceholders(this.plugin, PlotSquared.get().getPlaceholderRegistry());
PlotSquared.log(Captions.PREFIX + "&6PlotSquared hooked into MVdWPlaceholderAPI");
}
}
}

View File

@ -0,0 +1,78 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* 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 <http://www.gnu.org/licenses/>.
*/
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 static final String PREFIX = "plotsquared_";
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, PREFIX + String.format("%s", placeholder.getKey()),
placeholderReplaceEvent -> {
if (!placeholderReplaceEvent.isOnline() || placeholderReplaceEvent.getPlayer() == null) {
return "";
}
final PlotPlayer<Player> player = BukkitUtil.getPlayer(placeholderReplaceEvent.getPlayer());
if (player == null) {
return "";
}
String key = placeholderReplaceEvent.getPlaceholder().substring(PREFIX.length());
return registry.getPlaceholderValue(key, player);
});
}
}

View File

@ -0,0 +1,89 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* 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 <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.bukkit.placeholder;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.player.PlotPlayer;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;
public class PAPIPlaceholders extends PlaceholderExpansion {
public PAPIPlaceholders() {
}
@Override public boolean persist() {
return true;
}
@Override public boolean canRegister() {
return true;
}
@Override public String getAuthor() {
return "IntellectualSites";
}
@Override public String getIdentifier() {
return "plotsquared";
}
@Override public String getVersion() {
return "3";
}
@Override public String onPlaceholderRequest(Player p, String identifier) {
final PlotPlayer<?> pl = PlotSquared.imp().getPlayerManager().getPlayerIfExists(p.getUniqueId());
if (pl == null) {
return "";
}
// PAPI specific ones that don't translate well over into other placeholder APIs
if (identifier.startsWith("has_plot_")) {
identifier = identifier.substring("has_plot_".length());
if (identifier.isEmpty())
return "";
return pl.getPlotCount(identifier) > 0 ?
PlaceholderAPIPlugin.booleanTrue() :
PlaceholderAPIPlugin.booleanFalse();
}
if (identifier.startsWith("plot_count_")) {
identifier = identifier.substring("plot_count_".length());
if (identifier.isEmpty())
return "";
return String.valueOf(pl.getPlotCount(identifier));
}
// PlotSquared placeholders
return PlotSquared.get().getPlaceholderRegistry().getPlaceholderValue(identifier, pl);
}
}

View File

@ -1,213 +0,0 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* 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 <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.bukkit.placeholder;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.util.MainUtil;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.UUID;
public class Placeholders extends PlaceholderExpansion {
public Placeholders() {
}
@Override public boolean persist() {
return true;
}
@Override public boolean canRegister() {
return true;
}
@Override public String getAuthor() {
return "NotMyFault";
}
@Override public String getIdentifier() {
return "plotsquared";
}
@Override public String getVersion() {
return "2.5";
}
@Override public String onPlaceholderRequest(Player p, String identifier) {
final PlotPlayer pl = PlotSquared.imp().getPlayerManager().getPlayerIfExists(p.getUniqueId());
if (pl == null) {
return "";
}
if (identifier.startsWith("has_plot_")) {
identifier = identifier.substring("has_plot_".length());
if (identifier.isEmpty())
return "";
return pl.getPlotCount(identifier) > 0 ?
PlaceholderAPIPlugin.booleanTrue() :
PlaceholderAPIPlugin.booleanFalse();
}
if (identifier.startsWith("plot_count_")) {
identifier = identifier.substring("plot_count_".length());
if (identifier.isEmpty())
return "";
return String.valueOf(pl.getPlotCount(identifier));
}
switch (identifier) {
case "currentplot_world": {
return p.getWorld().getName();
}
case "has_plot": {
return (pl.getPlotCount() > 0) ?
PlaceholderAPIPlugin.booleanTrue() :
PlaceholderAPIPlugin.booleanFalse();
}
case "allowed_plot_count": {
return String.valueOf(pl.getAllowedPlots());
}
case "plot_count": {
return String.valueOf(pl.getPlotCount());
}
}
Plot plot = pl.getCurrentPlot();
if (plot == null) {
return "";
}
switch (identifier) {
case "currentplot_alias": {
return plot.getAlias();
}
case "currentplot_owner": {
final UUID plotOwner = plot.getOwnerAbs();
if (plotOwner == null) {
return "";
}
try {
return MainUtil.getName(plotOwner, false);
} catch (final Exception ignored) {}
final String name = Bukkit.getOfflinePlayer(plotOwner).getName();
return name != null ? name : "unknown";
}
case "currentplot_members": {
if (plot.getMembers() == null && plot.getTrusted() == null) {
return "0";
}
return String.valueOf(plot.getMembers().size() + plot.getTrusted().size());
}
case "currentplot_members_added": {
if (plot.getMembers() == null) {
return "0";
}
return String.valueOf(plot.getMembers().size());
}
case "currentplot_members_trusted": {
if (plot.getTrusted() == null) {
return "0";
}
return String.valueOf(plot.getTrusted().size());
}
case "currentplot_members_denied": {
if (plot.getDenied() == null) {
return "0";
}
return String.valueOf(plot.getDenied().size());
}
case "has_build_rights": {
return plot.isAdded(pl.getUUID()) ?
PlaceholderAPIPlugin.booleanTrue() :
PlaceholderAPIPlugin.booleanFalse();
}
case "currentplot_x": {
return String.valueOf(plot.getId().getX());
}
case "currentplot_y": {
return String.valueOf(plot.getId().getY());
}
case "currentplot_xy": {
return plot.getId().getX() + ";" + plot.getId().getY();
}
case "currentplot_rating": {
return String.valueOf(plot.getAverageRating());
}
case "currentplot_biome": {
return plot.getBiomeSynchronous() + "";
}
default:
break;
}
if (identifier.startsWith("currentplot_localflag_")) {
return getFlagValue(plot, identifier.substring("currentplot_localflag_".length()),
false);
}
if (identifier.startsWith("currentplot_flag_")) {
return getFlagValue(plot, identifier.substring("currentplot_flag_".length()), true);
}
return "";
}
/**
* Return the flag value from its name on the current plot.
* If the flag doesn't exist it returns an empty string.
* If the flag exists but it is not set on current plot and the parameter inherit is set to true,
* it returns the default value.
*
* @param plot Current plot where the player is
* @param flagName Name of flag to get from current plot
* @param inherit Define if it returns only the flag set on currentplot or also inherited flag
* @return The value of flag serialized in string
*/
private String getFlagValue(final Plot plot, final String flagName, final boolean inherit) {
if (flagName.isEmpty())
return "";
final PlotFlag<?, ?> flag = GlobalFlagContainer.getInstance().getFlagFromString(flagName);
if (flag == null)
return "";
if (inherit) {
return plot.getFlag(flag).toString();
} else {
final PlotFlag<?, ?> plotFlag = plot.getFlagContainer().queryLocal(flag.getClass());
return (plotFlag != null) ? plotFlag.getValue().toString() : "";
}
}
}

View File

@ -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