mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-19 14:59:19 +00:00
WIP fauna implementation
This commit is contained in:
@@ -75,7 +75,7 @@ public interface IntegrationManager {
|
||||
List<String> discoveries = new ArrayList<>();
|
||||
try {
|
||||
RPGRegionsAccount account = RPGRegionsAPI.getAPI().getManagers().getStorageManager().getAccount(player.getUniqueId()).get();
|
||||
discoveries.addAll(account.getDiscoveredRegions().keySet());
|
||||
discoveries.addAll(account.getDiscoveries().keySet());
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package net.islandearth.rpgregions.fauna;
|
||||
|
||||
import net.islandearth.rpgregions.fauna.trigger.FaunaTrigger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class FaunaInstance<M> {
|
||||
|
||||
private final String identifier;
|
||||
private final String name;
|
||||
private final M type;
|
||||
private final List<FaunaTrigger> triggers;
|
||||
|
||||
public FaunaInstance(String identifier, String name, M type, List<FaunaTrigger> triggers) {
|
||||
this.identifier = identifier;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.triggers = triggers;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public M getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public List<FaunaTrigger> getTriggers() {
|
||||
return triggers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package net.islandearth.rpgregions.fauna.trigger;
|
||||
|
||||
import net.islandearth.rpgregions.fauna.FaunaInstance;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class FaunaTrigger {
|
||||
|
||||
/**
|
||||
* Tests whether this trigger is met by the specified player.
|
||||
* @param player the player to check
|
||||
* @return true if met, false otherwise
|
||||
*/
|
||||
public abstract boolean testRepeatable(Player player, FaunaInstance<?> instance);
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import net.islandearth.rpgregions.api.integrations.IntegrationManager;
|
||||
import net.islandearth.rpgregions.gui.element.IGuiFieldElementRegistry;
|
||||
import net.islandearth.rpgregions.managers.data.IRPGRegionsCache;
|
||||
import net.islandearth.rpgregions.managers.data.IStorageManager;
|
||||
import net.islandearth.rpgregions.managers.data.fauna.IFaunaCache;
|
||||
import net.islandearth.rpgregions.managers.registry.IRPGRegionsRegistry;
|
||||
|
||||
public interface IRPGRegionsManagers {
|
||||
@@ -12,6 +13,8 @@ public interface IRPGRegionsManagers {
|
||||
|
||||
IntegrationManager getIntegrationManager();
|
||||
|
||||
IFaunaCache getFaunaCache();
|
||||
|
||||
IRPGRegionsCache getRegionsCache();
|
||||
|
||||
IRegenerationManager getRegenerationManager();
|
||||
|
||||
@@ -13,13 +13,13 @@ import java.util.UUID;
|
||||
public class RPGRegionsAccount {
|
||||
|
||||
private final UUID uuid;
|
||||
private final Map<String, Discovery> discoveredRegions;
|
||||
private final Map<String, Discovery> discoveries;
|
||||
private final List<AccountCooldown> cooldowns;
|
||||
private final Map<String, TimeEntry> secondsInRegion;
|
||||
|
||||
public RPGRegionsAccount(UUID uuid, Map<String, Discovery> discoveredRegions) {
|
||||
public RPGRegionsAccount(UUID uuid, Map<String, Discovery> discoveries) {
|
||||
this.uuid = uuid;
|
||||
this.discoveredRegions = discoveredRegions;
|
||||
this.discoveries = discoveries;
|
||||
this.cooldowns = new ArrayList<>();
|
||||
this.secondsInRegion = new HashMap<>();
|
||||
}
|
||||
@@ -28,12 +28,16 @@ public class RPGRegionsAccount {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public Map<String, Discovery> getDiscoveredRegions() {
|
||||
return discoveredRegions;
|
||||
public Map<String, Discovery> getDiscoveries() {
|
||||
return discoveries;
|
||||
}
|
||||
|
||||
public boolean hasDiscovered(String discoveryName) {
|
||||
return discoveries.containsKey(discoveryName);
|
||||
}
|
||||
|
||||
public void addDiscovery(Discovery discovery) {
|
||||
discoveredRegions.put(discovery.getRegion(), discovery);
|
||||
discoveries.put(discovery.getDiscoveredName(), discovery);
|
||||
}
|
||||
|
||||
public List<AccountCooldown> getCooldowns() {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.islandearth.rpgregions.managers.data.fauna;
|
||||
|
||||
import net.islandearth.rpgregions.fauna.FaunaInstance;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IFaunaCache {
|
||||
|
||||
List<FaunaInstance<?>> getFauna();
|
||||
|
||||
void addFauna(FaunaInstance<?> instance);
|
||||
}
|
||||
@@ -1,16 +1,18 @@
|
||||
package net.islandearth.rpgregions.managers.data.region;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public interface Discovery {
|
||||
|
||||
/**
|
||||
* Gets the date this discovery was made.
|
||||
* @return date of discovery
|
||||
*/
|
||||
String getDate();
|
||||
LocalDateTime getDate();
|
||||
|
||||
/**
|
||||
* Gets the name of the region that was discovered.
|
||||
* @return name of region discovered
|
||||
* Gets the name of what was discovered.
|
||||
* @return name of discovered
|
||||
*/
|
||||
String getRegion();
|
||||
String getDiscoveredName();
|
||||
}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package net.islandearth.rpgregions.managers.data.region;
|
||||
|
||||
public record WorldDiscovery(String date, String region) implements Discovery {
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public record WorldDiscovery(LocalDateTime date, String region) implements Discovery {
|
||||
|
||||
@Override
|
||||
public String getDate() {
|
||||
public LocalDateTime getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRegion() {
|
||||
public String getDiscoveredName() {
|
||||
return region;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,10 @@ public enum Translations {
|
||||
DISCOVERING_AREA_PLACEHOLDER(TranslationKey.of("discovering_area_placeholder")),
|
||||
REQUIREMENT_MET(TranslationKey.of("requirement_met")),
|
||||
REQUIREMENT_NOT_MET(TranslationKey.of("requirement_not_met")),
|
||||
COORDINATES(TranslationKey.of("coordinates"));
|
||||
COORDINATES(TranslationKey.of("coordinates")),
|
||||
// Fauna
|
||||
FAUNA_DISCOVER_TITLE(TranslationKey.of("fauna_discover_title")),
|
||||
FAUNA_DISCOVER_SUBTITLE(TranslationKey.of("fauna_discover_subtitle"));
|
||||
|
||||
private final TranslationKey key;
|
||||
private final boolean isList;
|
||||
|
||||
@@ -30,3 +30,6 @@ discovering_area_placeholder: "<gold>Discovering a new area (%d%)..."
|
||||
requirement_met: "<gradient:dark_green:green>✔ %s"
|
||||
requirement_not_met: "<gradient:dark_red:red>✘ %s"
|
||||
coordinates: "<gray>Coordinates: %d, %d"
|
||||
# Fauna related settings
|
||||
fauna_discover_title: "<#F5AF2F>Bestiary Updated"
|
||||
fauna_discover_subtitle: "<white>%s <#04DB64>indexed"
|
||||
@@ -22,7 +22,7 @@ dependencies {
|
||||
exclude("net.kyori")
|
||||
}
|
||||
|
||||
implementation("net.wesjd:anvilgui:1.7.0-SNAPSHOT") // anvilgui
|
||||
implementation("net.wesjd:anvilgui:1.9.0-SNAPSHOT") // anvilgui
|
||||
implementation("com.github.stefvanschie.inventoryframework:IF:0.10.12") // inventory framework
|
||||
implementation("co.aikar:idb-core:1.0.0-SNAPSHOT") // database
|
||||
implementation("org.bstats:bstats-bukkit:3.0.2") // plugin stats
|
||||
|
||||
@@ -18,6 +18,7 @@ import net.islandearth.rpgregions.effects.RegionEffect;
|
||||
import net.islandearth.rpgregions.effects.RegionEffectRegistry;
|
||||
import net.islandearth.rpgregions.effects.VanishEffect;
|
||||
import net.islandearth.rpgregions.exception.CouldNotStartException;
|
||||
import net.islandearth.rpgregions.fauna.FaunaDiscoverer;
|
||||
import net.islandearth.rpgregions.folia.schedule.FoliaScheduler;
|
||||
import net.islandearth.rpgregions.gson.AbstractAdapter;
|
||||
import net.islandearth.rpgregions.gson.ItemStackAdapter;
|
||||
@@ -77,6 +78,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@@ -310,6 +312,7 @@ public final class RPGRegions extends JavaPlugin implements IRPGRegionsAPI {
|
||||
getScheduler().executeRepeating(new DynmapTask(this), 0L, 20L);
|
||||
getLogger().info("Registered support for Dynmap.");
|
||||
}
|
||||
getScheduler().executeRepeating(new FaunaDiscoverer(this), 0L, 10L);
|
||||
}
|
||||
|
||||
private void registerMetrics() {
|
||||
@@ -334,11 +337,19 @@ public final class RPGRegions extends JavaPlugin implements IRPGRegionsAPI {
|
||||
metrics.addCustomChart(new SimplePie("integration_type", () -> getConfig().getString("settings.integration.name")));
|
||||
}
|
||||
|
||||
private DateTimeFormatter formatter;
|
||||
|
||||
public DateTimeFormatter getDateFormatter() {
|
||||
if (formatter != null) return formatter;
|
||||
return formatter = DateTimeFormatter.ofPattern(getConfig().getString("settings.server.discoveries.date.format"));
|
||||
}
|
||||
|
||||
private Boolean debugEnabled;
|
||||
|
||||
// Called when the config is reloaded or the debug value was changed
|
||||
public void markDebugDirty() {
|
||||
this.debugEnabled = null;
|
||||
this.formatter = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -56,7 +56,7 @@ public class PlaceholderRegionHook extends PlaceholderExpansion implements Block
|
||||
try {
|
||||
RPGRegionsAccount account = plugin.getManagers().getStorageManager().getAccount(player.getUniqueId()).get();
|
||||
String region = identifier.replace("discovered_region_", "");
|
||||
boolean discovered = account.getDiscoveredRegions().containsKey(region);
|
||||
boolean discovered = account.getDiscoveries().containsKey(region);
|
||||
return String.valueOf(discovered);
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
@@ -75,7 +75,7 @@ public class PlaceholderRegionHook extends PlaceholderExpansion implements Block
|
||||
// We have to do a blocking operation :(
|
||||
try {
|
||||
RPGRegionsAccount account = plugin.getManagers().getStorageManager().getAccount(player.getUniqueId()).get();
|
||||
return String.valueOf(account.getDiscoveredRegions().size());
|
||||
return String.valueOf(account.getDiscoveries().size());
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public class PlaceholderRegionHook extends PlaceholderExpansion implements Block
|
||||
// We have to do a blocking operation :(
|
||||
try {
|
||||
RPGRegionsAccount account = plugin.getManagers().getStorageManager().getAccount(player.getUniqueId()).get();
|
||||
int percent = totalRegionsConfigured == 0 ? 0 : (account.getDiscoveredRegions().size() / totalRegionsConfigured) * 100;
|
||||
int percent = totalRegionsConfigured == 0 ? 0 : (account.getDiscoveries().size() / totalRegionsConfigured) * 100;
|
||||
return String.valueOf(percent);
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
@@ -102,7 +102,7 @@ public class PlaceholderRegionHook extends PlaceholderExpansion implements Block
|
||||
// We have to do a blocking operation :(
|
||||
try {
|
||||
RPGRegionsAccount account = plugin.getManagers().getStorageManager().getAccount(player.getUniqueId()).get();
|
||||
if (account.getDiscoveredRegions().containsKey(region.get().getId())) {
|
||||
if (account.getDiscoveries().containsKey(region.get().getId())) {
|
||||
return region.get().getCustomName();
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public class PlanRegionHook implements DataExtension {
|
||||
public long regionCount(UUID playerUUID) throws InterruptedException, ExecutionException {
|
||||
// Have to do blocking operation :(
|
||||
RPGRegionsAccount account = plugin.getManagers().getStorageManager().getAccount(playerUUID).get();
|
||||
return account.getDiscoveredRegions().size();
|
||||
return account.getDiscoveries().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,7 +16,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class DiscoveriesCommand {
|
||||
|
||||
@@ -41,10 +40,7 @@ public class DiscoveriesCommand {
|
||||
@Argument("player") OfflinePlayer target) {
|
||||
plugin.getManagers().getStorageManager().getAccount(target.getUniqueId()).thenAccept(account -> {
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
DateTimeFormatter format = DateTimeFormatter.ofPattern(plugin.getConfig().getString("settings.server.discoveries.date.format"));
|
||||
|
||||
String formattedDate = date.format(format);
|
||||
final WorldDiscovery worldDiscovery = new WorldDiscovery(formattedDate, configuredRegion.getId());
|
||||
final WorldDiscovery worldDiscovery = new WorldDiscovery(date, configuredRegion.getId());
|
||||
account.addDiscovery(worldDiscovery);
|
||||
if (target.getPlayer() != null) {
|
||||
Player player = target.getPlayer();
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package net.islandearth.rpgregions.fauna;
|
||||
|
||||
import com.google.common.base.Enums;
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import net.islandearth.rpgregions.fauna.trigger.FaunaTrigger;
|
||||
import net.islandearth.rpgregions.managers.data.fauna.IFaunaCache;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FaunaCache implements IFaunaCache {
|
||||
|
||||
private final List<FaunaInstance<?>> fauna = new ArrayList<>();
|
||||
|
||||
public FaunaCache(RPGRegions plugin) {
|
||||
plugin.saveResource("fauna/goat.yml", false);
|
||||
File faunaFolder = new File(plugin.getDataFolder() + File.separator + "fauna");
|
||||
for (File file : faunaFolder.listFiles()) {
|
||||
if (!file.getName().endsWith(".yml")) continue;
|
||||
final YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
final String typeName = config.getString("type", "");
|
||||
final String identifier = config.getString("identifier", "");
|
||||
final String name = config.getString("name", "");
|
||||
|
||||
List<FaunaTrigger> triggers = new ArrayList<>();
|
||||
final ConfigurationSection triggersSection = config.getConfigurationSection("triggers");
|
||||
for (String triggerId : triggersSection.getKeys(false)) {
|
||||
final ConfigurationSection triggerSection = triggersSection.getConfigurationSection(triggerId);
|
||||
if (triggerId.equals("nearby")) {
|
||||
final double radius = triggerSection.getDouble("radius");
|
||||
triggers.add(new NearbyFaunaTrigger(radius));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
final EntityType entityType = Enums.getIfPresent(EntityType.class, typeName).orNull();
|
||||
if (entityType != null) {
|
||||
this.addFauna(new VanillaMobFaunaInstance(identifier, name, entityType, triggers));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FaunaInstance<?>> getFauna() {
|
||||
return fauna;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFauna(FaunaInstance<?> instance) {
|
||||
fauna.add(instance);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.islandearth.rpgregions.fauna;
|
||||
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import net.islandearth.rpgregions.fauna.trigger.FaunaTrigger;
|
||||
import net.islandearth.rpgregions.managers.data.region.WorldDiscovery;
|
||||
import net.islandearth.rpgregions.translation.Translations;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class FaunaDiscoverer implements Runnable {
|
||||
|
||||
private final RPGRegions plugin;
|
||||
|
||||
public FaunaDiscoverer(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
final Audience audience = plugin.adventure().player(player);
|
||||
plugin.getManagers().getStorageManager().getAccount(player.getUniqueId()).thenAccept(account -> {
|
||||
for (FaunaInstance<?> fauna : plugin.getManagers().getFaunaCache().getFauna()) {
|
||||
if (account.hasDiscovered(fauna.getIdentifier())) continue;
|
||||
for (FaunaTrigger trigger : fauna.getTriggers()) {
|
||||
if (trigger.testRepeatable(player, fauna)) {
|
||||
WorldDiscovery discovery = new WorldDiscovery(LocalDateTime.now(), fauna.getIdentifier());
|
||||
account.addDiscovery(discovery);
|
||||
audience.showTitle(Title.title(Translations.FAUNA_DISCOVER_TITLE.get(player, fauna.getName()).get(0), Translations.FAUNA_DISCOVER_SUBTITLE.get(player, fauna.getName()).get(0)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package net.islandearth.rpgregions.fauna;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class FaunaListener implements Listener {
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package net.islandearth.rpgregions.fauna;
|
||||
|
||||
import net.islandearth.rpgregions.fauna.trigger.FaunaTrigger;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class NearbyFaunaTrigger extends FaunaTrigger {
|
||||
|
||||
private final double radius;
|
||||
|
||||
public NearbyFaunaTrigger(double radius) {
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
public double getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testRepeatable(Player player, FaunaInstance<?> instance) {
|
||||
for (Entity entity : player.getNearbyEntities(radius, radius, radius)) {
|
||||
if (instance instanceof VanillaMobFaunaInstance vanilla) {
|
||||
if (vanilla.getType() == entity.getType()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.islandearth.rpgregions.fauna;
|
||||
|
||||
import net.islandearth.rpgregions.fauna.trigger.FaunaTrigger;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class VanillaMobFaunaInstance extends FaunaInstance<EntityType> {
|
||||
|
||||
public VanillaMobFaunaInstance(String identifier, String name, EntityType type, List<FaunaTrigger> triggers) {
|
||||
super(identifier, name, type, triggers);
|
||||
}
|
||||
}
|
||||
@@ -186,16 +186,16 @@ public class DiscoveryGUI extends RPGRegionsGUI {
|
||||
plugin.getManagers().getStorageManager().getAccount(player.getUniqueId()).thenAcceptAsync(account -> {
|
||||
List<GuiItem> items = new ArrayList<>();
|
||||
for (ConfiguredRegion configuredRegion : plugin.getManagers().getRegionsCache().getConfiguredRegions().values()) {
|
||||
boolean hasDiscovered = account.getDiscoveredRegions().containsKey(configuredRegion.getId());
|
||||
boolean hasDiscovered = account.getDiscoveries().containsKey(configuredRegion.getId());
|
||||
if ((!hasDiscovered && !player.hasPermission("rpgregions.show"))
|
||||
|| configuredRegion.isHidden()) continue;
|
||||
|
||||
final String colour = hasDiscovered
|
||||
? plugin.getConfig().getString("settings.server.discoveries.discovered.name-colour")
|
||||
: plugin.getConfig().getString("settings.server.discoveries.undiscovered.name-colour");
|
||||
List<Component> lore = account.getDiscoveredRegions().containsKey(configuredRegion.getId())
|
||||
List<Component> lore = account.getDiscoveries().containsKey(configuredRegion.getId())
|
||||
? Translations.DISCOVERED_ON.get(player,
|
||||
account.getDiscoveredRegions().get(configuredRegion.getId()).getDate())
|
||||
plugin.getDateFormatter().format(account.getDiscoveries().get(configuredRegion.getId()).getDate()))
|
||||
: null;
|
||||
List<Component> coordsLore = configuredRegion.showCoords()
|
||||
&& player.hasPermission("rpgregions.showloc")
|
||||
@@ -222,7 +222,7 @@ public class DiscoveryGUI extends RPGRegionsGUI {
|
||||
for (RegionRequirement requirement : configuredRegion.getRequirements()) {
|
||||
boolean meets = requirement.meetsRequirements(player);
|
||||
if (requirement instanceof DependencyRequirement dependencyRequirement) {
|
||||
List<String> discoveries = new ArrayList<>(account.getDiscoveredRegions().keySet());
|
||||
List<String> discoveries = new ArrayList<>(account.getDiscoveries().keySet());
|
||||
meets = dependencyRequirement.meetsRequirements(discoveries);
|
||||
}
|
||||
if (!meets) {
|
||||
|
||||
@@ -20,7 +20,6 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -31,12 +30,10 @@ public class RegionListener implements Listener {
|
||||
|
||||
private final RPGRegions plugin;
|
||||
private final List<UUID> titleCooldown;
|
||||
private final DateTimeFormatter format;
|
||||
|
||||
public RegionListener(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
this.titleCooldown = new ArrayList<>();
|
||||
this.format = DateTimeFormatter.ofPattern(plugin.getConfig().getString("settings.server.discoveries.date.format"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,8 +63,8 @@ public class RegionListener implements Listener {
|
||||
final String regionId = configuredRegion.getId();
|
||||
boolean has = false;
|
||||
boolean prioritised = event.getPriority().equals(regionId);
|
||||
for (Discovery discoveredRegion : account.getDiscoveredRegions().values()) {
|
||||
if (discoveredRegion.getRegion().equals(regionId)) {
|
||||
for (Discovery discoveredRegion : account.getDiscoveries().values()) {
|
||||
if (discoveredRegion.getDiscoveredName().equals(regionId)) {
|
||||
has = true;
|
||||
break;
|
||||
}
|
||||
@@ -115,8 +112,7 @@ public class RegionListener implements Listener {
|
||||
|
||||
plugin.debug("Discovering region.");
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
String formattedDate = date.format(format);
|
||||
Discovery discovery = new WorldDiscovery(formattedDate, regionId);
|
||||
Discovery discovery = new WorldDiscovery(date, regionId);
|
||||
account.addDiscovery(discovery);
|
||||
Bukkit.getPluginManager().callEvent(new RegionDiscoverEvent(player, configuredRegion, discovery));
|
||||
} else if (prioritised && configuredRegion.isDiscoverable() && has) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.islandearth.rpgregions.effects.RegionEffect;
|
||||
import net.islandearth.rpgregions.effects.RegionEffectRegistry;
|
||||
import net.islandearth.rpgregions.effects.protocol.ProtocolCreator;
|
||||
import net.islandearth.rpgregions.exception.CouldNotStartException;
|
||||
import net.islandearth.rpgregions.fauna.FaunaCache;
|
||||
import net.islandearth.rpgregions.gui.element.BooleanGuiFieldElement;
|
||||
import net.islandearth.rpgregions.gui.element.CompareTypeGuiFieldElement;
|
||||
import net.islandearth.rpgregions.gui.element.GuiFieldElementRegistry;
|
||||
@@ -24,6 +25,7 @@ import net.islandearth.rpgregions.managers.data.IRPGRegionsCache;
|
||||
import net.islandearth.rpgregions.managers.data.IStorageManager;
|
||||
import net.islandearth.rpgregions.managers.data.RPGRegionsCache;
|
||||
import net.islandearth.rpgregions.managers.data.StorageType;
|
||||
import net.islandearth.rpgregions.managers.data.fauna.IFaunaCache;
|
||||
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
|
||||
import net.islandearth.rpgregions.managers.regeneration.RegenerationManager;
|
||||
import net.islandearth.rpgregions.managers.registry.IRPGRegionsRegistry;
|
||||
@@ -74,6 +76,7 @@ public class RPGRegionsManagers implements IRPGRegionsManagers {
|
||||
|
||||
private IStorageManager storageManager;
|
||||
private final IntegrationManager integrationManager;
|
||||
private final IFaunaCache faunaCache;
|
||||
private final IRPGRegionsCache regionsCache;
|
||||
private final IRegenerationManager regenerationManager;
|
||||
private final Map<Class<? extends RPGRegionsRegistry<?>>, RPGRegionsRegistry<?>> registry;
|
||||
@@ -93,6 +96,7 @@ public class RPGRegionsManagers implements IRPGRegionsManagers {
|
||||
throw new CouldNotStartException("Unable to load IntegrationManager. The requested plugin is not enabled.");
|
||||
}
|
||||
|
||||
this.faunaCache = new FaunaCache(plugin);
|
||||
this.regionsCache = new RPGRegionsCache(plugin);
|
||||
this.registry = new ConcurrentHashMap<>();
|
||||
registry.put(RegionRequirementRegistry.class, new RegionRequirementRegistry());
|
||||
@@ -216,6 +220,11 @@ public class RPGRegionsManagers implements IRPGRegionsManagers {
|
||||
return integrationManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFaunaCache getFaunaCache() {
|
||||
return faunaCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRPGRegionsCache getRegionsCache() {
|
||||
return regionsCache;
|
||||
|
||||
@@ -15,9 +15,10 @@ import org.bukkit.Bukkit;
|
||||
import org.flywaydb.core.Flyway;
|
||||
import org.flywaydb.core.api.output.ValidateOutput;
|
||||
import org.flywaydb.core.api.output.ValidateResult;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -128,7 +129,7 @@ public abstract class SQLCommonStorage implements IStorageManager {
|
||||
Map<String, Discovery> regions = new HashMap<>();
|
||||
for (DbRow row : results) {
|
||||
String region = row.getString("region");
|
||||
regions.put(region, new WorldDiscovery(row.getString("time"), region));
|
||||
regions.put(region, new WorldDiscovery(LocalDateTime.parse(row.getString("time")), region));
|
||||
}
|
||||
|
||||
plugin.debug("Created user account: " + uuid);
|
||||
@@ -149,7 +150,7 @@ public abstract class SQLCommonStorage implements IStorageManager {
|
||||
|
||||
@Override
|
||||
public void clearDiscoveries(UUID uuid) {
|
||||
getAccount(uuid).thenAccept(account -> account.getDiscoveredRegions().clear()).exceptionally(t -> {
|
||||
getAccount(uuid).thenAccept(account -> account.getDiscoveries().clear()).exceptionally(t -> {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
@@ -159,7 +160,7 @@ public abstract class SQLCommonStorage implements IStorageManager {
|
||||
|
||||
@Override
|
||||
public void clearDiscovery(UUID uuid, String regionId) {
|
||||
getAccount(uuid).thenAccept(account -> account.getDiscoveredRegions().remove(regionId)).exceptionally(t -> {
|
||||
getAccount(uuid).thenAccept(account -> account.getDiscoveries().remove(regionId)).exceptionally(t -> {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
@@ -198,9 +199,9 @@ public abstract class SQLCommonStorage implements IStorageManager {
|
||||
current.add(row.getString("region"));
|
||||
}
|
||||
|
||||
for (Discovery region : account.getDiscoveredRegions().values()) {
|
||||
if (!current.contains(region.getRegion())) {
|
||||
executeInsert(INSERT_DISCOVERY, getDatabaseUuid(uuid), region.getRegion(), region.getDate());
|
||||
for (Discovery region : account.getDiscoveries().values()) {
|
||||
if (!current.contains(region.getDiscoveredName())) {
|
||||
executeInsert(INSERT_DISCOVERY, getDatabaseUuid(uuid), region.getDiscoveredName(), DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(region.getDate()));
|
||||
}
|
||||
}
|
||||
}).exceptionally(t -> {
|
||||
@@ -209,7 +210,7 @@ public abstract class SQLCommonStorage implements IStorageManager {
|
||||
});
|
||||
}
|
||||
|
||||
protected void executeInsert(@Language("SQL") String query, Object... params) {
|
||||
protected void executeInsert(String query, Object... params) {
|
||||
try {
|
||||
DB.executeInsert(query, params);
|
||||
} catch (SQLException e) {
|
||||
|
||||
@@ -17,6 +17,8 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -74,7 +76,7 @@ public class YamlStorage implements IStorageManager {
|
||||
String[] data = results.split(";");
|
||||
String time = data[0];
|
||||
String region = data[1];
|
||||
regions.put(region, new WorldDiscovery(time, region));
|
||||
regions.put(region, new WorldDiscovery(LocalDateTime.parse(time), region));
|
||||
}
|
||||
|
||||
plugin.debug("Created user account: " + uuid);
|
||||
@@ -92,7 +94,7 @@ public class YamlStorage implements IStorageManager {
|
||||
@Override
|
||||
public void clearDiscoveries(UUID uuid) {
|
||||
getAccount(uuid).thenAccept(account -> {
|
||||
account.getDiscoveredRegions().clear();
|
||||
account.getDiscoveries().clear();
|
||||
}).exceptionally(t -> {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
@@ -111,7 +113,7 @@ public class YamlStorage implements IStorageManager {
|
||||
@Override
|
||||
public void clearDiscovery(UUID uuid, String regionId) {
|
||||
getAccount(uuid).thenAccept(account -> {
|
||||
account.getDiscoveredRegions().remove(regionId);
|
||||
account.getDiscoveries().remove(regionId);
|
||||
}).exceptionally(t -> {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
@@ -124,7 +126,7 @@ public class YamlStorage implements IStorageManager {
|
||||
String[] data = results.split(";");
|
||||
String time = data[0];
|
||||
String region = data[1];
|
||||
regions.put(region, new WorldDiscovery(time, region));
|
||||
regions.put(region, new WorldDiscovery(LocalDateTime.parse(time), region));
|
||||
}
|
||||
|
||||
regions.remove(regionId);
|
||||
@@ -132,7 +134,7 @@ public class YamlStorage implements IStorageManager {
|
||||
List<String> newData = config.getStringList("Discoveries");
|
||||
newData.clear();
|
||||
for (Discovery region : regions.values()) {
|
||||
newData.add(region.getDate() + ";" + region.getRegion());
|
||||
newData.add(region.getDate() + ";" + region.getDiscoveredName());
|
||||
}
|
||||
|
||||
config.set("Discoveries", newData);
|
||||
@@ -171,8 +173,8 @@ public class YamlStorage implements IStorageManager {
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
List<String> newData = new ArrayList<>();
|
||||
for (Discovery region : account.getDiscoveredRegions().values()) {
|
||||
newData.add(region.getDate() + ";" + region.getRegion());
|
||||
for (Discovery region : account.getDiscoveries().values()) {
|
||||
newData.add(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(region.getDate()) + ";" + region.getDiscoveredName());
|
||||
}
|
||||
|
||||
config.set("Discoveries", newData);
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Optional;
|
||||
|
||||
public class RegionDiscoverReward extends DiscoveryReward {
|
||||
@@ -38,10 +37,7 @@ public class RegionDiscoverReward extends DiscoveryReward {
|
||||
|
||||
api.getManagers().getStorageManager().getAccount(player.getUniqueId()).thenAccept(account -> {
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
DateTimeFormatter format = DateTimeFormatter.ofPattern(api.getConfig().getString("settings.server.discoveries.date.format"));
|
||||
|
||||
String formattedDate = date.format(format);
|
||||
final WorldDiscovery worldDiscovery = new WorldDiscovery(formattedDate, this.region);
|
||||
final WorldDiscovery worldDiscovery = new WorldDiscovery(date, this.region);
|
||||
account.addDiscovery(worldDiscovery);
|
||||
Bukkit.getPluginManager().callEvent(new RegionDiscoverEvent(player, region.get(), worldDiscovery));
|
||||
this.updateAwardTime();
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE rpgregions_discoveries RENAME COLUMN region to discovery_id;
|
||||
19
rpgregions/src/main/resources/fauna/goat.yml
Normal file
19
rpgregions/src/main/resources/fauna/goat.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
# The type can either be of a vanilla entity type, or a MythicMob
|
||||
type: GOAT
|
||||
# A unique identifier for this fauna. Must not be the same name as a region, either.
|
||||
identifier: goat
|
||||
# Name shown in placeholder
|
||||
display_name: "Goat"
|
||||
|
||||
# Description shown in bestiary book
|
||||
description:
|
||||
- "The Goat is a fluffy, cute mob found in cold mountainous areas."
|
||||
- "Goats are well-known for their milk that they produce."
|
||||
- " "
|
||||
- "But beware! Turn your back, and out of spite you shall find yourself rammed into the air."
|
||||
|
||||
# Triggers that define when this entity is discovered
|
||||
triggers:
|
||||
# Will be discovered when nearby to a goat in a radius of 5.
|
||||
nearby:
|
||||
radius: 5.0
|
||||
Reference in New Issue
Block a user