PlotSquared/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/MVdWPlaceholders.java

74 lines
3.1 KiB
Java
Raw Normal View History

/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* 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;
Merge branch 'v6' into feature/v6/json. It builds! # Conflicts: # Bukkit/build.gradle # Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java # Bukkit/src/main/java/com/plotsquared/bukkit/generator/DelegatePlotGenerator.java # Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java # Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java # Bukkit/src/main/java/com/plotsquared/bukkit/queue/ChunkCoordinator.java # Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java # Core/src/main/java/com/plotsquared/core/PlotSquared.java # Core/src/main/java/com/plotsquared/core/command/Area.java # Core/src/main/java/com/plotsquared/core/command/Clear.java # Core/src/main/java/com/plotsquared/core/command/Debug.java # Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java # Core/src/main/java/com/plotsquared/core/command/Relight.java # Core/src/main/java/com/plotsquared/core/command/Set.java # Core/src/main/java/com/plotsquared/core/command/Template.java # Core/src/main/java/com/plotsquared/core/command/Trim.java # Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java # Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java # Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java # Core/src/main/java/com/plotsquared/core/plot/Plot.java # Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java # Core/src/main/java/com/plotsquared/core/queue/AreaBoundDelegateQueueCoordinator.java # Core/src/main/java/com/plotsquared/core/queue/ChunkQueueCoordinator.java # Core/src/main/java/com/plotsquared/core/queue/LocalBlockQueue.java # Core/src/main/java/com/plotsquared/core/util/ChunkUtil.java # Core/src/main/java/com/plotsquared/core/util/EntityUtil.java # Core/src/main/java/com/plotsquared/core/util/RegionManager.java # Core/src/main/java/com/plotsquared/core/util/WorldUtil.java # Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java # build.gradle
2020-08-08 14:20:30 +02:00
import javax.annotation.Nonnull;
/**
* Placeholder support for MVdWPlaceholderAPI
*/
public class MVdWPlaceholders {
2020-07-16 18:04:17 +02:00
private static final String PREFIX = "plotsquared_";
private final Plugin plugin;
private final PlaceholderRegistry registry;
Merge branch 'v6' into feature/v6/json. It builds! # Conflicts: # Bukkit/build.gradle # Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java # Bukkit/src/main/java/com/plotsquared/bukkit/generator/DelegatePlotGenerator.java # Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java # Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java # Bukkit/src/main/java/com/plotsquared/bukkit/queue/ChunkCoordinator.java # Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java # Core/src/main/java/com/plotsquared/core/PlotSquared.java # Core/src/main/java/com/plotsquared/core/command/Area.java # Core/src/main/java/com/plotsquared/core/command/Clear.java # Core/src/main/java/com/plotsquared/core/command/Debug.java # Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java # Core/src/main/java/com/plotsquared/core/command/Relight.java # Core/src/main/java/com/plotsquared/core/command/Set.java # Core/src/main/java/com/plotsquared/core/command/Template.java # Core/src/main/java/com/plotsquared/core/command/Trim.java # Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java # Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java # Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java # Core/src/main/java/com/plotsquared/core/plot/Plot.java # Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java # Core/src/main/java/com/plotsquared/core/queue/AreaBoundDelegateQueueCoordinator.java # Core/src/main/java/com/plotsquared/core/queue/ChunkQueueCoordinator.java # Core/src/main/java/com/plotsquared/core/queue/LocalBlockQueue.java # Core/src/main/java/com/plotsquared/core/util/ChunkUtil.java # Core/src/main/java/com/plotsquared/core/util/EntityUtil.java # Core/src/main/java/com/plotsquared/core/util/RegionManager.java # Core/src/main/java/com/plotsquared/core/util/WorldUtil.java # Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java # build.gradle
2020-08-08 14:20:30 +02:00
public MVdWPlaceholders(@Nonnull final Plugin plugin, @Nonnull final PlaceholderRegistry registry) {
this.plugin = plugin;
this.registry = registry;
for (final Placeholder placeholder : registry.getPlaceholders()) {
this.addPlaceholder(placeholder);
}
PlotSquared.get().getEventDispatcher().registerListener(this);
}
Merge branch 'v6' into feature/v6/json. It builds! # Conflicts: # Bukkit/build.gradle # Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java # Bukkit/src/main/java/com/plotsquared/bukkit/generator/DelegatePlotGenerator.java # Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java # Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java # Bukkit/src/main/java/com/plotsquared/bukkit/queue/ChunkCoordinator.java # Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java # Core/src/main/java/com/plotsquared/core/PlotSquared.java # Core/src/main/java/com/plotsquared/core/command/Area.java # Core/src/main/java/com/plotsquared/core/command/Clear.java # Core/src/main/java/com/plotsquared/core/command/Debug.java # Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java # Core/src/main/java/com/plotsquared/core/command/Relight.java # Core/src/main/java/com/plotsquared/core/command/Set.java # Core/src/main/java/com/plotsquared/core/command/Template.java # Core/src/main/java/com/plotsquared/core/command/Trim.java # Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java # Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java # Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java # Core/src/main/java/com/plotsquared/core/plot/Plot.java # Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java # Core/src/main/java/com/plotsquared/core/queue/AreaBoundDelegateQueueCoordinator.java # Core/src/main/java/com/plotsquared/core/queue/ChunkQueueCoordinator.java # Core/src/main/java/com/plotsquared/core/queue/LocalBlockQueue.java # Core/src/main/java/com/plotsquared/core/util/ChunkUtil.java # Core/src/main/java/com/plotsquared/core/util/EntityUtil.java # Core/src/main/java/com/plotsquared/core/util/RegionManager.java # Core/src/main/java/com/plotsquared/core/util/WorldUtil.java # Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java # build.gradle
2020-08-08 14:20:30 +02:00
@Subscribe public void onNewPlaceholder(@Nonnull final PlaceholderRegistry.PlaceholderAddedEvent event) {
this.addPlaceholder(event.getPlaceholder());
}
Merge branch 'v6' into feature/v6/json. It builds! # Conflicts: # Bukkit/build.gradle # Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java # Bukkit/src/main/java/com/plotsquared/bukkit/generator/DelegatePlotGenerator.java # Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java # Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java # Bukkit/src/main/java/com/plotsquared/bukkit/queue/ChunkCoordinator.java # Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java # Core/src/main/java/com/plotsquared/core/PlotSquared.java # Core/src/main/java/com/plotsquared/core/command/Area.java # Core/src/main/java/com/plotsquared/core/command/Clear.java # Core/src/main/java/com/plotsquared/core/command/Debug.java # Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java # Core/src/main/java/com/plotsquared/core/command/Relight.java # Core/src/main/java/com/plotsquared/core/command/Set.java # Core/src/main/java/com/plotsquared/core/command/Template.java # Core/src/main/java/com/plotsquared/core/command/Trim.java # Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java # Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java # Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java # Core/src/main/java/com/plotsquared/core/plot/Plot.java # Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java # Core/src/main/java/com/plotsquared/core/queue/AreaBoundDelegateQueueCoordinator.java # Core/src/main/java/com/plotsquared/core/queue/ChunkQueueCoordinator.java # Core/src/main/java/com/plotsquared/core/queue/LocalBlockQueue.java # Core/src/main/java/com/plotsquared/core/util/ChunkUtil.java # Core/src/main/java/com/plotsquared/core/util/EntityUtil.java # Core/src/main/java/com/plotsquared/core/util/RegionManager.java # Core/src/main/java/com/plotsquared/core/util/WorldUtil.java # Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java # build.gradle
2020-08-08 14:20:30 +02:00
private void addPlaceholder(@Nonnull 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.adapt(placeholderReplaceEvent.getPlayer());
String key = placeholderReplaceEvent.getPlaceholder().substring(PREFIX.length());
return registry.getPlaceholderValue(key, player);
});
}
}