mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2026-01-06 15:41:35 +00:00
Mostly finish fauna
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package net.islandearth.rpgregions.api.events;
|
||||
|
||||
import net.islandearth.rpgregions.fauna.FaunaInstance;
|
||||
import net.islandearth.rpgregions.managers.data.region.Discovery;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class FaunaDiscoverEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
private final Player player;
|
||||
private final FaunaInstance<?> fauna;
|
||||
private final Discovery discovery;
|
||||
|
||||
public FaunaDiscoverEvent(Player player, FaunaInstance<?> fauna, Discovery discovery) {
|
||||
this.player = player;
|
||||
this.fauna = fauna;
|
||||
this.discovery = discovery;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player involved in this event.
|
||||
* @return the player involved
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fauna that has been discovered.
|
||||
* @return {@link FaunaInstance} that was discovered
|
||||
*/
|
||||
public FaunaInstance<?> getFauna() {
|
||||
return fauna;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the discovery involved. Contains useful information such as the date.
|
||||
* @return the fauna {@link Discovery}
|
||||
*/
|
||||
public Discovery getDiscovery() {
|
||||
return discovery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +1,30 @@
|
||||
package net.islandearth.rpgregions.fauna;
|
||||
|
||||
import net.islandearth.rpgregions.api.IRPGRegionsAPI;
|
||||
import net.islandearth.rpgregions.api.RPGRegionsAPI;
|
||||
import net.islandearth.rpgregions.fauna.trigger.FaunaTrigger;
|
||||
import net.kyori.adventure.inventory.Book;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class FaunaInstance<M> {
|
||||
|
||||
private final String identifier;
|
||||
private final String name;
|
||||
private final List<String> description;
|
||||
private final M type;
|
||||
private final List<FaunaTrigger> triggers;
|
||||
|
||||
public FaunaInstance(String identifier, String name, M type, List<FaunaTrigger> triggers) {
|
||||
public FaunaInstance(String identifier, String name, List<String> description, M type, List<FaunaTrigger> triggers) {
|
||||
this.identifier = identifier;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.type = type;
|
||||
this.triggers = triggers;
|
||||
}
|
||||
@@ -22,10 +33,38 @@ public abstract class FaunaInstance<M> {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
public String getDisplayName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<String> getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void openDescription(Player player) {
|
||||
player.playSound(player.getEyeLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1f, 1f);
|
||||
final IRPGRegionsAPI plugin = RPGRegionsAPI.getAPI();
|
||||
final Book.Builder builder = Book.builder();
|
||||
builder.title(Component.text("Bestiary", NamedTextColor.DARK_PURPLE));
|
||||
// Lol, I wonder if some redistribution sites will auto-remove this line?
|
||||
// Would cause errors.
|
||||
builder.author(Component.text("RPGRegions %%__USER__%%"));
|
||||
List<Component> pages = new ArrayList<>();
|
||||
TextComponent.Builder pageBuilder = Component.text();
|
||||
for (String line : description) {
|
||||
if (line.equals("<newpage>")) {
|
||||
pages.add(pageBuilder.build());
|
||||
pageBuilder = Component.text();
|
||||
continue;
|
||||
}
|
||||
pageBuilder.append(plugin.miniMessage().deserialize(line));
|
||||
pageBuilder.appendNewline();
|
||||
}
|
||||
pages.add(pageBuilder.build());
|
||||
builder.pages(pages);
|
||||
plugin.adventure().player(player).openBook(builder.build());
|
||||
}
|
||||
|
||||
public M getType() {
|
||||
return type;
|
||||
}
|
||||
@@ -33,4 +72,8 @@ public abstract class FaunaInstance<M> {
|
||||
public List<FaunaTrigger> getTriggers() {
|
||||
return triggers;
|
||||
}
|
||||
|
||||
public boolean hasTrigger(Class<? extends FaunaTrigger> type) {
|
||||
return triggers.stream().anyMatch(trigger -> trigger.getClass().isAssignableFrom(type));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,15 @@ package net.islandearth.rpgregions.managers.data.fauna;
|
||||
import net.islandearth.rpgregions.fauna.FaunaInstance;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface IFaunaCache {
|
||||
|
||||
void reload();
|
||||
|
||||
List<FaunaInstance<?>> getFauna();
|
||||
|
||||
Optional<FaunaInstance<?>> getFauna(String id);
|
||||
|
||||
void addFauna(FaunaInstance<?> instance);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,9 @@ public enum Translations {
|
||||
COORDINATES(TranslationKey.of("coordinates")),
|
||||
// Fauna
|
||||
FAUNA_DISCOVER_TITLE(TranslationKey.of("fauna_discover_title")),
|
||||
FAUNA_DISCOVER_SUBTITLE(TranslationKey.of("fauna_discover_subtitle"));
|
||||
FAUNA_DISCOVER_SUBTITLE(TranslationKey.of("fauna_discover_subtitle")),
|
||||
BESTIARY_DEFAULT_HOVER(TranslationKey.of("bestiary_default_hover")),
|
||||
BESTIARY_PAGE_HEADER(TranslationKey.of("bestiary_page_header"));
|
||||
|
||||
private final TranslationKey key;
|
||||
private final boolean isList;
|
||||
|
||||
@@ -30,6 +30,13 @@ 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/flora related settings
|
||||
fauna_discover_title: "<#F5AF2F>Bestiary Updated"
|
||||
fauna_discover_subtitle: "<white>%s <#04DB64>indexed"
|
||||
fauna_discover_subtitle: "<#04DB64>%s indexed"
|
||||
bestiary_default_hover:
|
||||
- "<gradient:gold:yellow>Click to find out more!"
|
||||
bestiary_page_header:
|
||||
- " <gradient:gold:yellow>A compendium of fauna and flora"
|
||||
- " ------------------"
|
||||
- " <#04DB64>Explore the world to discover entries."
|
||||
- " "
|
||||
Reference in New Issue
Block a user