Merge remote-tracking branch 'origin/MV5' into dumptruckman/inject

# Conflicts:
#	src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java
This commit is contained in:
Jeremy Wood 2023-03-25 08:42:20 -04:00
commit 93ac4fffcc
No known key found for this signature in database
GPG Key ID: C5BAD04C77B91B4B
5 changed files with 173 additions and 2 deletions

View File

@ -55,6 +55,10 @@ repositories {
name = 'glaremasters repo'
url = 'https://repo.glaremasters.me/repository/towny/'
}
maven {
name = 'PlaceholderAPI'
url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/'
}
}
configurations {
@ -77,6 +81,9 @@ dependencies {
exclude group: 'org.bukkit', module: 'bukkit'
}
// PlaceholderAPI
compileOnly 'me.clip:placeholderapi:2.11.2'
// Command Framework
relocatedApi 'co.aikar:acf-paper:0.5.1-SNAPSHOT'

View File

@ -26,6 +26,7 @@ import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
import com.onarandombox.MultiverseCore.destination.DestinationsProvider;
import com.onarandombox.MultiverseCore.inject.InjectableListener;
import com.onarandombox.MultiverseCore.inject.PluginInjection;
import com.onarandombox.MultiverseCore.placeholders.MultiverseCorePlaceholders;
import com.onarandombox.MultiverseCore.utils.TestingMode;
import com.onarandombox.MultiverseCore.utils.metrics.MetricsConfigurator;
import com.onarandombox.MultiverseCore.world.WorldProperties;
@ -124,6 +125,7 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
this.setUpLocales();
this.registerDestinations();
this.setupMetrics();
this.setupPlaceholderAPI();
this.saveMVConfig();
this.logEnableMessage();
}
@ -183,7 +185,7 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
*/
private void setUpLocales() {
var commandManager = serviceLocator.getService(MVCommandManager.class);
commandManager.usePerIssuerLocale(true, true);
commandManager.getLocales().addFileResClassLoader(this);
commandManager.getLocales().addMessageBundles("multiverse-core");
@ -219,6 +221,12 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
}
}
private void setupPlaceholderAPI() {
if(getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
new MultiverseCorePlaceholders(this).register();
}
}
private MVCoreConfigProvider getConfigProvider() {
return configProvider;
}

View File

@ -0,0 +1,155 @@
package com.onarandombox.MultiverseCore.placeholders;
import java.util.Optional;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorld;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.economy.MVEconomist;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class MultiverseCorePlaceholders extends PlaceholderExpansion {
private final MultiverseCore plugin;
private final MVWorldManager worldManager;
private final MVEconomist economist;
public MultiverseCorePlaceholders(MultiverseCore plugin) {
this.plugin = plugin;
this.worldManager = plugin.getMVWorldManager();
this.economist = plugin.getEconomist();
}
@Override
public @NotNull String getIdentifier() {
return "multiverse-core";
}
@Override
public @NotNull String getAuthor() {
return plugin.getAuthors();
}
@Override
public @NotNull String getVersion() {
return plugin.getDescription().getVersion();
}
@Override
public boolean persist() {
return true;
}
/**
* Placeholder implementation, format: %multiverse-core_<placeholder>_[world]% world is optional.
*
* @param offlinePlayer Player to get the placeholder for
* @param params Placeholder to get
* @return Placeholder value
*/
@Override
public @Nullable String onRequest(OfflinePlayer offlinePlayer, @NotNull String params) {
// Split string in to an Array with underscores
String[] paramsArray = params.split("_", 2);
// No placeholder defined
if (paramsArray.length < 1) {
warning("No placeholder defined");
return null;
}
final var placeholder = paramsArray[0];
Optional<MVWorld> targetWorld;
// If no world is defined, use the player's world
if (paramsArray.length == 1) {
if (!offlinePlayer.isOnline()) {
return null;
}
targetWorld = Optional.ofNullable(worldManager.getMVWorld(((Player)offlinePlayer).getWorld()));
} else {
targetWorld = Optional.ofNullable(worldManager.getMVWorld(paramsArray[1]));
}
// Fail if world is null
return targetWorld.map(world -> getWorldPlaceHolderValue(placeholder, world))
.orElse(null);
}
private @Nullable String getWorldPlaceHolderValue(@NotNull String placeholder, @NotNull MVWorld world) {
// Switch to find what specific placeholder we want
switch (placeholder.toLowerCase()) {
case "alias" -> {
return world.getColoredWorldString();
}
case "animalspawn" -> {
return String.valueOf(world.canAnimalsSpawn());
}
case "autoheal" -> {
return String.valueOf(world.getAutoHeal());
}
case "blacklist" -> {
return String.join(", ", world.getWorldBlacklist());
}
case "currency" -> {
return String.valueOf(world.getCurrency());
}
case "difficulty" -> {
return world.getDifficulty().toString();
}
case "entryfee" -> {
return economist.formatPrice(world.getPrice(), world.getCurrency());
}
case "environment" -> {
return world.getEnvironment().toString().toLowerCase();
}
case "flight" -> {
return String.valueOf(world.getAllowFlight());
}
case "gamemode" -> {
return world.getGameMode().toString().toLowerCase();
}
case "generator" -> {
return world.getGenerator();
}
case "hunger" -> {
return String.valueOf(world.getHunger());
}
case "monstersspawn" -> {
return String.valueOf(world.canMonstersSpawn());
}
case "name" -> {
return world.getName();
}
case "playerlimit" -> {
return String.valueOf(world.getPlayerLimit());
}
case "price" -> {
return String.valueOf(world.getPrice());
}
case "pvp" -> {
return String.valueOf(world.isPVPEnabled());
}
case "seed" -> {
return String.valueOf(world.getSeed());
}
case "time" -> {
return world.getTime();
}
case "type" -> {
return world.getWorldType().toString().toLowerCase();
}
case "weather" -> {
return String.valueOf(world.isWeatherEnabled());
}
default -> {
warning("Unknown placeholder: " + placeholder);
return null;
}
}
}
}

View File

@ -113,3 +113,4 @@ mv-core.unload.success=&aUnloaded world '{world}'!
# /mv usage
mv-core.usage.description=Show Multiverse-Core command usage.

View File

@ -2,6 +2,6 @@ name: Multiverse-Core
main: com.onarandombox.MultiverseCore.MultiverseCore
authors: ['dumptruckman', 'Rigby', 'fernferret', 'lithium3141', 'main--']
website: 'https://dev.bukkit.org/projects/multiverse-core'
softdepend: ['Vault']
softdepend: ['Vault', 'PlaceholderAPI']
api-version: 1.13
version: ${version}