Remove old wm reference in bstats, tests and placeholders

This commit is contained in:
Ben Woo 2023-09-04 10:34:32 +08:00
parent 4eb8dfbc67
commit 891f7ca136
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
5 changed files with 82 additions and 49 deletions

View File

@ -1,6 +1,5 @@
package com.onarandombox.MultiverseCore.commands;
import co.aikar.commands.BukkitCommandIssuer;
import co.aikar.commands.MessageType;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
@ -11,7 +10,6 @@ import co.aikar.commands.annotation.Single;
import co.aikar.commands.annotation.Subcommand;
import co.aikar.commands.annotation.Syntax;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.commandtools.MVCommandIssuer;
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand;

View File

@ -1,15 +1,15 @@
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 com.onarandombox.MultiverseCore.worldnew.MVWorld;
import com.onarandombox.MultiverseCore.worldnew.WorldManager;
import io.vavr.control.Option;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Inject;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -19,11 +19,11 @@ import org.jvnet.hk2.annotations.Service;
public class MultiverseCorePlaceholders extends PlaceholderExpansion {
private final MultiverseCore plugin;
private final MVWorldManager worldManager;
private final WorldManager worldManager;
private final MVEconomist economist;
@Inject
public MultiverseCorePlaceholders(MultiverseCore plugin, MVWorldManager worldManager, MVEconomist economist) {
public MultiverseCorePlaceholders(MultiverseCore plugin, WorldManager worldManager, MVEconomist economist) {
this.plugin = plugin;
this.worldManager = worldManager;
this.economist = economist;
@ -74,31 +74,30 @@ public class MultiverseCorePlaceholders extends PlaceholderExpansion {
}
final var placeholder = paramsArray[0];
Optional<MVWorld> targetWorld;
Option<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()));
targetWorld = worldManager.getMVWorld(((Player)offlinePlayer).getWorld());
} else {
targetWorld = Optional.ofNullable(worldManager.getMVWorld(paramsArray[1]));
targetWorld = worldManager.getMVWorld(paramsArray[1]);
}
// Fail if world is null
return targetWorld.map(world -> getWorldPlaceHolderValue(placeholder, world))
.orElse(null);
return targetWorld.map(world -> getWorldPlaceHolderValue(placeholder, world)).getOrNull();
}
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();
return world.getAlias();
}
case "animalspawn" -> {
return String.valueOf(world.canAnimalsSpawn());
return String.valueOf(world.getSpawningAnimals());
}
case "autoheal" -> {
return String.valueOf(world.getAutoHeal());
@ -131,7 +130,7 @@ public class MultiverseCorePlaceholders extends PlaceholderExpansion {
return String.valueOf(world.getHunger());
}
case "monstersspawn" -> {
return String.valueOf(world.canMonstersSpawn());
return String.valueOf(world.getSpawningMonsters());
}
case "name" -> {
return world.getName();
@ -143,19 +142,20 @@ public class MultiverseCorePlaceholders extends PlaceholderExpansion {
return String.valueOf(world.getPrice());
}
case "pvp" -> {
return String.valueOf(world.isPVPEnabled());
return String.valueOf(world.getPvp());
}
case "seed" -> {
return String.valueOf(world.getSeed());
}
case "time" -> {
return world.getTime();
}
// TODO: Time is removed, not sure if it's worth adding back
// case "time" -> {
// return world.getTime();
// }
case "type" -> {
return world.getWorldType().toString().toLowerCase();
return world.getBukkitWorld().map(World::getWorldType).map(Enum::name).getOrElse("null");
}
case "weather" -> {
return String.valueOf(world.isWeatherEnabled());
return String.valueOf(world.getAllowWeather());
}
default -> {
warning("Unknown placeholder: " + placeholder);

View File

@ -1,13 +1,9 @@
package com.onarandombox.MultiverseCore.utils.metrics;
import java.util.Collection;
import java.util.Map;
import java.util.function.Consumer;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MVWorld;
import com.onarandombox.MultiverseCore.worldnew.MVWorld;
import com.onarandombox.MultiverseCore.worldnew.WorldManager;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Inject;
import org.apache.commons.lang.WordUtils;
@ -15,29 +11,24 @@ import org.bstats.bukkit.Metrics;
import org.bukkit.World;
import org.jvnet.hk2.annotations.Service;
import java.util.Map;
import java.util.function.Consumer;
@Service
public class MetricsConfigurator {
private static final int PLUGIN_ID = 7765;
private static final String NO_GENERATOR_NAME = "N/A";
private final MVWorldManager worldManager;
private final WorldManager worldManager;
private final Metrics metrics;
@Inject
private MetricsConfigurator(MultiverseCore plugin, MVWorldManager worldManager) {
private MetricsConfigurator(MultiverseCore plugin, WorldManager worldManager) {
this.worldManager = worldManager;
this.metrics = new Metrics(plugin, PLUGIN_ID);
}
private MVWorldManager getWorldManager() {
return worldManager;
}
private Collection<MVWorld> getMVWorlds() {
return getWorldManager().getMVWorlds();
}
@PostConstruct
private void initMetrics() {
try {
@ -54,7 +45,7 @@ public class MetricsConfigurator {
private void addCustomGeneratorsMetric() {
addAdvancedPieMetric("custom_generators", map -> {
for (MVWorld w : getMVWorlds()) {
for (MVWorld w : worldManager.getMVWorlds()) {
MetricsHelper.incrementCount(map, getGeneratorName(w));
}
});
@ -67,7 +58,7 @@ public class MetricsConfigurator {
private void addEnvironmentsMetric() {
addAdvancedPieMetric("environments", map -> {
for (MVWorld w : getMVWorlds()) {
for (MVWorld w : worldManager.getMVWorlds()) {
MetricsHelper.incrementCount(map, titleCaseEnv(w.getEnvironment()));
}
});
@ -80,9 +71,8 @@ public class MetricsConfigurator {
private void addWorldCountMetric() {
addMultiLineMetric("world_count", map -> {
int loadedWorldsCount = getMVWorlds().size();
map.put("Loaded worlds", loadedWorldsCount);
map.put("Total number of worlds", loadedWorldsCount + getWorldManager().getUnloadedWorlds().size());
map.put("Loaded worlds", worldManager.getMVWorlds().size());
map.put("Total number of worlds", worldManager.getOfflineWorlds().size());
});
}

View File

@ -224,6 +224,54 @@ public class OfflineWorld {
return worldConfig.setSpawnLocation(spawnLocation);
}
public boolean getSpawningAnimals() {
return worldConfig.getSpawningAnimals();
}
public Try<Void> setSpawningAnimals(boolean spawningAnimals) {
return worldConfig.setSpawningAnimals(spawningAnimals);
}
public int getSpawningAnimalsAmount() {
return worldConfig.getSpawningAnimalsAmount();
}
public Try<Void> setSpawningAnimalsAmount(int spawningAnimalsAmount) {
return worldConfig.setSpawningAnimalsAmount(spawningAnimalsAmount);
}
public List<String> getSpawningAnimalsExceptions() {
return worldConfig.getSpawningAnimalsExceptions();
}
public Try<Void> setSpawningAnimalsExceptions(List<String> spawningAnimalsExceptions) {
return worldConfig.setSpawningAnimalsExceptions(spawningAnimalsExceptions);
}
public boolean getSpawningMonsters() {
return worldConfig.getSpawningMonsters();
}
public Try<Void> setSpawningMonsters(boolean spawningMonsters) {
return worldConfig.setSpawningMonsters(spawningMonsters);
}
public int getSpawningMonstersAmount() {
return worldConfig.getSpawningMonstersAmount();
}
public Try<Void> setSpawningMonstersAmount(int spawningMonstersAmount) {
return worldConfig.setSpawningMonstersAmount(spawningMonstersAmount);
}
public List<String> getSpawningMonstersExceptions() {
return worldConfig.getSpawningMonstersExceptions();
}
public Try<Void> setSpawningMonstersExceptions(List<String> spawningMonstersExceptions) {
return worldConfig.setSpawningMonstersExceptions(spawningMonstersExceptions);
}
public List<String> getWorldBlacklist() {
return worldConfig.getWorldBlacklist();
}

View File

@ -4,8 +4,6 @@ import com.onarandombox.MultiverseCore.anchor.AnchorManager
import com.onarandombox.MultiverseCore.api.BlockSafety
import com.onarandombox.MultiverseCore.api.Destination
import com.onarandombox.MultiverseCore.api.LocationManipulation
import com.onarandombox.MultiverseCore.api.MVConfig
import com.onarandombox.MultiverseCore.api.MVWorldManager
import com.onarandombox.MultiverseCore.api.SafeTTeleporter
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager
import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand
@ -25,11 +23,11 @@ import com.onarandombox.MultiverseCore.teleportation.SimpleSafeTTeleporter
import com.onarandombox.MultiverseCore.teleportation.TeleportQueue
import com.onarandombox.MultiverseCore.utils.UnsafeCallWrapper
import com.onarandombox.MultiverseCore.utils.metrics.MetricsConfigurator
import com.onarandombox.MultiverseCore.world.SimpleMVWorldManager
import com.onarandombox.MultiverseCore.worldnew.WorldManager
import org.mvplugins.multiverse.core.TestWithMockBukkit
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.Test
import kotlin.test.assertNull
class InjectionTest : TestWithMockBukkit() {
@ -79,8 +77,7 @@ class InjectionTest : TestWithMockBukkit() {
@Test
fun `MVWorldManager is available as a service`() {
assertNotNull(multiverseCore.getService(MVWorldManager::class.java))
assertNotNull(multiverseCore.getService(SimpleMVWorldManager::class.java))
assertNotNull(multiverseCore.getService(WorldManager::class.java))
}
@Test