9
0
mirror of https://gitlab.com/SamB440/rpgregions-2.git synced 2026-01-06 15:41:35 +00:00

Pass ConfiguredRegion to RegionDiscoverEvent, update XSound, cleanup

This commit is contained in:
SamB440
2023-04-24 15:51:02 +01:00
parent 98658c7f48
commit 9876076ef7
11 changed files with 442 additions and 180 deletions

View File

@@ -1,20 +1,19 @@
package net.islandearth.rpgregions.api.events;
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
import net.islandearth.rpgregions.managers.data.region.Discovery;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import java.util.List;
public class RegionDiscoverEvent extends Event {
private static final HandlerList HANDLER_LIST = new HandlerList();
private final Player player;
private final String region;
private final ConfiguredRegion region;
private final Discovery discovery;
public RegionDiscoverEvent(Player player, String region, Discovery discovery) {
public RegionDiscoverEvent(Player player, ConfiguredRegion region, Discovery discovery) {
this.player = player;
this.region = region;
this.discovery = discovery;
@@ -30,9 +29,9 @@ public class RegionDiscoverEvent extends Event {
/**
* Gets the region that has been discovered.
* @return {@link List} of regions
* @return {@link ConfiguredRegion} that was discovered
*/
public String getRegion() {
public ConfiguredRegion getRegion() {
return region;
}

View File

@@ -1,20 +1,25 @@
package net.islandearth.rpgregions.api.events;
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import java.util.List;
public class RegionsEffectEvent extends Event {
/**
* @deprecated This event is currently not implemented and is under consideration
*/
@Deprecated
public class RegionEffectEvent extends Event {
private static final HandlerList HANDLER_LIST = new HandlerList();
private final Player player;
private final List<String> regions;
private final ConfiguredRegion region;
public RegionsEffectEvent(Player player, List<String> regions) {
public RegionEffectEvent(Player player, ConfiguredRegion region) {
this.player = player;
this.regions = regions;
this.region = region;
}
/**
@@ -26,11 +31,11 @@ public class RegionsEffectEvent extends Event {
}
/**
* Gets a list of all regions that will give effects to the player.
* Gets the region that will give effects to the player.
* @return {@link List} of regions
*/
public List<String> getRegions() {
return regions;
public ConfiguredRegion getRegion() {
return region;
}
@Override

View File

@@ -1,29 +1,7 @@
package net.islandearth.rpgregions.command;
public class IconCommand {
public record IconCommand(String command, CommandClickType clickType, int cooldown) {
private final String command;
private final CommandClickType clickType;
private final int cooldown;
public IconCommand(String command, CommandClickType clickType, int cooldown) {
this.command = command;
this.clickType = clickType;
this.cooldown = cooldown;
}
public String getCommand() {
return command;
}
public CommandClickType getClickType() {
return clickType;
}
public int getCooldown() {
return cooldown;
}
public enum CommandClickType {
DISCOVERED,
UNDISCOVERED

View File

@@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
public class DependencyRequirement extends RegionRequirement {
@@ -32,7 +33,7 @@ public class DependencyRequirement extends RegionRequirement {
}
public boolean meetsRequirements(List<String> discoveries) {
return discoveries.containsAll(requiredRegions);
return new HashSet<>(discoveries).containsAll(requiredRegions);
}
@Override

View File

@@ -1,35 +0,0 @@
package net.islandearth.rpgregions.utils;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
public class TextComponentBuilder {
private final TextComponent text;
public TextComponentBuilder(final String text) {
this.text = new TextComponent(text);
}
public TextComponentBuilder setCommand(final String command) {
text.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + command));
return this;
}
public TextComponentBuilder setHover(final String hover) {
text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hover).create()));
return this;
}
public TextComponentBuilder setLink(final String link) {
text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, link));
return this;
}
public TextComponent build() {
return text;
}
}

View File

@@ -23,16 +23,13 @@ package net.islandearth.rpgregions.utils;
import com.google.common.base.Enums;
import com.google.common.base.Strings;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Instrument;
import org.bukkit.Location;
import org.bukkit.Note;
import org.bukkit.Sound;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
@@ -40,6 +37,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
/**
* <b>XSound</b> - Universal Minecraft Sound Support<br>
@@ -57,7 +55,7 @@ import java.util.concurrent.CompletableFuture;
* play command: https://minecraft.gamepedia.com/Commands/play
*
* @author Crypto Morin
* @version 7.0.2
* @version 9.1.0
* @see Sound
*/
public enum XSound {
@@ -125,6 +123,26 @@ public enum XSound {
BLOCK_BAMBOO_SAPLING_HIT,
BLOCK_BAMBOO_SAPLING_PLACE,
BLOCK_BAMBOO_STEP,
BLOCK_BAMBOO_WOOD_BREAK,
BLOCK_BAMBOO_WOOD_BUTTON_CLICK_OFF,
BLOCK_BAMBOO_WOOD_BUTTON_CLICK_ON,
BLOCK_BAMBOO_WOOD_DOOR_CLOSE,
BLOCK_BAMBOO_WOOD_DOOR_OPEN,
BLOCK_BAMBOO_WOOD_FALL,
BLOCK_BAMBOO_WOOD_FENCE_GATE_CLOSE,
BLOCK_BAMBOO_WOOD_FENCE_GATE_OPEN,
BLOCK_BAMBOO_WOOD_HANGING_SIGN_BREAK,
BLOCK_BAMBOO_WOOD_HANGING_SIGN_FALL,
BLOCK_BAMBOO_WOOD_HANGING_SIGN_HIT,
BLOCK_BAMBOO_WOOD_HANGING_SIGN_PLACE,
BLOCK_BAMBOO_WOOD_HANGING_SIGN_STEP,
BLOCK_BAMBOO_WOOD_HIT,
BLOCK_BAMBOO_WOOD_PLACE,
BLOCK_BAMBOO_WOOD_PRESSURE_PLATE_CLICK_OFF,
BLOCK_BAMBOO_WOOD_PRESSURE_PLATE_CLICK_ON,
BLOCK_BAMBOO_WOOD_STEP,
BLOCK_BAMBOO_WOOD_TRAPDOOR_CLOSE,
BLOCK_BAMBOO_WOOD_TRAPDOOR_OPEN,
BLOCK_BARREL_CLOSE,
BLOCK_BARREL_OPEN,
BLOCK_BASALT_BREAK,
@@ -187,9 +205,48 @@ public enum XSound {
BLOCK_CHAIN_HIT,
BLOCK_CHAIN_PLACE,
BLOCK_CHAIN_STEP,
BLOCK_CHERRY_LEAVES_BREAK,
BLOCK_CHERRY_LEAVES_FALL,
BLOCK_CHERRY_LEAVES_HIT,
BLOCK_CHERRY_LEAVES_PLACE,
BLOCK_CHERRY_LEAVES_STEP,
BLOCK_CHERRY_SAPLING_BREAK,
BLOCK_CHERRY_SAPLING_FALL,
BLOCK_CHERRY_SAPLING_HIT,
BLOCK_CHERRY_SAPLING_PLACE,
BLOCK_CHERRY_SAPLING_STEP,
BLOCK_CHERRY_WOOD_BREAK,
BLOCK_CHERRY_WOOD_BUTTON_CLICK_OFF,
BLOCK_CHERRY_WOOD_BUTTON_CLICK_ON,
BLOCK_CHERRY_WOOD_DOOR_CLOSE,
BLOCK_CHERRY_WOOD_DOOR_OPEN,
BLOCK_CHERRY_WOOD_FALL,
BLOCK_CHERRY_WOOD_FENCE_GATE_CLOSE,
BLOCK_CHERRY_WOOD_FENCE_GATE_OPEN,
BLOCK_CHERRY_WOOD_HANGING_SIGN_BREAK,
BLOCK_CHERRY_WOOD_HANGING_SIGN_FALL,
BLOCK_CHERRY_WOOD_HANGING_SIGN_HIT,
BLOCK_CHERRY_WOOD_HANGING_SIGN_PLACE,
BLOCK_CHERRY_WOOD_HANGING_SIGN_STEP,
BLOCK_CHERRY_WOOD_HIT,
BLOCK_CHERRY_WOOD_PLACE,
BLOCK_CHERRY_WOOD_PRESSURE_PLATE_CLICK_OFF,
BLOCK_CHERRY_WOOD_PRESSURE_PLATE_CLICK_ON,
BLOCK_CHERRY_WOOD_STEP,
BLOCK_CHERRY_WOOD_TRAPDOOR_CLOSE,
BLOCK_CHERRY_WOOD_TRAPDOOR_OPEN,
BLOCK_CHEST_CLOSE("CHEST_CLOSE", "ENTITY_CHEST_CLOSE"),
BLOCK_CHEST_LOCKED,
BLOCK_CHEST_OPEN("CHEST_OPEN", "ENTITY_CHEST_OPEN"),
BLOCK_CHISELED_BOOKSHELF_BREAK,
BLOCK_CHISELED_BOOKSHELF_FALL,
BLOCK_CHISELED_BOOKSHELF_HIT,
BLOCK_CHISELED_BOOKSHELF_INSERT,
BLOCK_CHISELED_BOOKSHELF_INSERT_ENCHANTED,
BLOCK_CHISELED_BOOKSHELF_PICKUP,
BLOCK_CHISELED_BOOKSHELF_PICKUP_ENCHANTED,
BLOCK_CHISELED_BOOKSHELF_PLACE,
BLOCK_CHISELED_BOOKSHELF_STEP,
BLOCK_CHORUS_FLOWER_DEATH,
BLOCK_CHORUS_FLOWER_GROW,
BLOCK_COMPARATOR_CLICK,
@@ -213,6 +270,12 @@ public enum XSound {
BLOCK_CORAL_BLOCK_PLACE,
BLOCK_CORAL_BLOCK_STEP,
BLOCK_CROP_BREAK,
BLOCK_DECORATED_POT_BREAK,
BLOCK_DECORATED_POT_FALL,
BLOCK_DECORATED_POT_HIT,
BLOCK_DECORATED_POT_PLACE,
BLOCK_DECORATED_POT_SHATTER,
BLOCK_DECORATED_POT_STEP,
BLOCK_DEEPSLATE_BREAK,
BLOCK_DEEPSLATE_BRICKS_BREAK,
BLOCK_DEEPSLATE_BRICKS_FALL,
@@ -251,6 +314,17 @@ public enum XSound {
BLOCK_FLOWERING_AZALEA_HIT,
BLOCK_FLOWERING_AZALEA_PLACE,
BLOCK_FLOWERING_AZALEA_STEP,
BLOCK_FROGLIGHT_BREAK,
BLOCK_FROGLIGHT_FALL,
BLOCK_FROGLIGHT_HIT,
BLOCK_FROGLIGHT_PLACE,
BLOCK_FROGLIGHT_STEP,
BLOCK_FROGSPAWN_BREAK,
BLOCK_FROGSPAWN_FALL,
BLOCK_FROGSPAWN_HATCH,
BLOCK_FROGSPAWN_HIT,
BLOCK_FROGSPAWN_PLACE,
BLOCK_FROGSPAWN_STEP,
BLOCK_FUNGUS_BREAK,
BLOCK_FUNGUS_FALL,
BLOCK_FUNGUS_HIT,
@@ -284,6 +358,11 @@ public enum XSound {
BLOCK_HANGING_ROOTS_HIT,
BLOCK_HANGING_ROOTS_PLACE,
BLOCK_HANGING_ROOTS_STEP,
BLOCK_HANGING_SIGN_BREAK,
BLOCK_HANGING_SIGN_FALL,
BLOCK_HANGING_SIGN_HIT,
BLOCK_HANGING_SIGN_PLACE,
BLOCK_HANGING_SIGN_STEP,
BLOCK_HONEY_BLOCK_BREAK,
BLOCK_HONEY_BLOCK_FALL,
BLOCK_HONEY_BLOCK_HIT,
@@ -316,6 +395,11 @@ public enum XSound {
BLOCK_LODESTONE_HIT,
BLOCK_LODESTONE_PLACE,
BLOCK_LODESTONE_STEP,
BLOCK_MANGROVE_ROOTS_BREAK,
BLOCK_MANGROVE_ROOTS_FALL,
BLOCK_MANGROVE_ROOTS_HIT,
BLOCK_MANGROVE_ROOTS_PLACE,
BLOCK_MANGROVE_ROOTS_STEP,
BLOCK_MEDIUM_AMETHYST_BUD_BREAK,
BLOCK_MEDIUM_AMETHYST_BUD_PLACE,
BLOCK_METAL_BREAK,
@@ -335,6 +419,21 @@ public enum XSound {
BLOCK_MOSS_HIT,
BLOCK_MOSS_PLACE,
BLOCK_MOSS_STEP,
BLOCK_MUDDY_MANGROVE_ROOTS_BREAK,
BLOCK_MUDDY_MANGROVE_ROOTS_FALL,
BLOCK_MUDDY_MANGROVE_ROOTS_HIT,
BLOCK_MUDDY_MANGROVE_ROOTS_PLACE,
BLOCK_MUDDY_MANGROVE_ROOTS_STEP,
BLOCK_MUD_BREAK,
BLOCK_MUD_BRICKS_BREAK,
BLOCK_MUD_BRICKS_FALL,
BLOCK_MUD_BRICKS_HIT,
BLOCK_MUD_BRICKS_PLACE,
BLOCK_MUD_BRICKS_STEP,
BLOCK_MUD_FALL,
BLOCK_MUD_HIT,
BLOCK_MUD_PLACE,
BLOCK_MUD_STEP,
BLOCK_NETHERITE_BLOCK_BREAK,
BLOCK_NETHERITE_BLOCK_FALL,
BLOCK_NETHERITE_BLOCK_HIT,
@@ -366,6 +465,26 @@ public enum XSound {
BLOCK_NETHER_SPROUTS_PLACE,
BLOCK_NETHER_SPROUTS_STEP,
BLOCK_NETHER_WART_BREAK,
BLOCK_NETHER_WOOD_BREAK,
BLOCK_NETHER_WOOD_BUTTON_CLICK_OFF,
BLOCK_NETHER_WOOD_BUTTON_CLICK_ON,
BLOCK_NETHER_WOOD_DOOR_CLOSE,
BLOCK_NETHER_WOOD_DOOR_OPEN,
BLOCK_NETHER_WOOD_FALL,
BLOCK_NETHER_WOOD_FENCE_GATE_CLOSE,
BLOCK_NETHER_WOOD_FENCE_GATE_OPEN,
BLOCK_NETHER_WOOD_HANGING_SIGN_BREAK,
BLOCK_NETHER_WOOD_HANGING_SIGN_FALL,
BLOCK_NETHER_WOOD_HANGING_SIGN_HIT,
BLOCK_NETHER_WOOD_HANGING_SIGN_PLACE,
BLOCK_NETHER_WOOD_HANGING_SIGN_STEP,
BLOCK_NETHER_WOOD_HIT,
BLOCK_NETHER_WOOD_PLACE,
BLOCK_NETHER_WOOD_PRESSURE_PLATE_CLICK_OFF,
BLOCK_NETHER_WOOD_PRESSURE_PLATE_CLICK_ON,
BLOCK_NETHER_WOOD_STEP,
BLOCK_NETHER_WOOD_TRAPDOOR_CLOSE,
BLOCK_NETHER_WOOD_TRAPDOOR_OPEN,
BLOCK_NOTE_BLOCK_BANJO,
BLOCK_NOTE_BLOCK_BASEDRUM("NOTE_BASS_DRUM", "BLOCK_NOTE_BASEDRUM"),
BLOCK_NOTE_BLOCK_BASS("NOTE_BASS", "BLOCK_NOTE_BASS"),
@@ -378,6 +497,12 @@ public enum XSound {
BLOCK_NOTE_BLOCK_GUITAR("NOTE_BASS_GUITAR", "BLOCK_NOTE_GUITAR"),
BLOCK_NOTE_BLOCK_HARP("NOTE_PIANO", "BLOCK_NOTE_HARP"),
BLOCK_NOTE_BLOCK_HAT("NOTE_STICKS", "BLOCK_NOTE_HAT"),
BLOCK_NOTE_BLOCK_IMITATE_CREEPER,
BLOCK_NOTE_BLOCK_IMITATE_ENDER_DRAGON,
BLOCK_NOTE_BLOCK_IMITATE_PIGLIN,
BLOCK_NOTE_BLOCK_IMITATE_SKELETON,
BLOCK_NOTE_BLOCK_IMITATE_WITHER_SKELETON,
BLOCK_NOTE_BLOCK_IMITATE_ZOMBIE,
BLOCK_NOTE_BLOCK_IRON_XYLOPHONE,
BLOCK_NOTE_BLOCK_PLING("NOTE_PLING", "BLOCK_NOTE_PLING"),
BLOCK_NOTE_BLOCK_SNARE("NOTE_SNARE_DRUM", "BLOCK_NOTE_SNARE"),
@@ -387,6 +512,16 @@ public enum XSound {
BLOCK_NYLIUM_HIT,
BLOCK_NYLIUM_PLACE,
BLOCK_NYLIUM_STEP,
BLOCK_PACKED_MUD_BREAK,
BLOCK_PACKED_MUD_FALL,
BLOCK_PACKED_MUD_HIT,
BLOCK_PACKED_MUD_PLACE,
BLOCK_PACKED_MUD_STEP,
BLOCK_PINK_PETALS_BREAK,
BLOCK_PINK_PETALS_FALL,
BLOCK_PINK_PETALS_HIT,
BLOCK_PINK_PETALS_PLACE,
BLOCK_PINK_PETALS_STEP,
BLOCK_PISTON_CONTRACT("PISTON_RETRACT"),
BLOCK_PISTON_EXTEND("PISTON_EXTEND"),
BLOCK_POINTED_DRIPSTONE_BREAK,
@@ -438,6 +573,17 @@ public enum XSound {
BLOCK_SCAFFOLDING_HIT,
BLOCK_SCAFFOLDING_PLACE,
BLOCK_SCAFFOLDING_STEP,
BLOCK_SCULK_BREAK,
BLOCK_SCULK_CATALYST_BLOOM,
BLOCK_SCULK_CATALYST_BREAK,
BLOCK_SCULK_CATALYST_FALL,
BLOCK_SCULK_CATALYST_HIT,
BLOCK_SCULK_CATALYST_PLACE,
BLOCK_SCULK_CATALYST_STEP,
BLOCK_SCULK_CHARGE,
BLOCK_SCULK_FALL,
BLOCK_SCULK_HIT,
BLOCK_SCULK_PLACE,
BLOCK_SCULK_SENSOR_BREAK,
BLOCK_SCULK_SENSOR_CLICKING,
BLOCK_SCULK_SENSOR_CLICKING_STOP,
@@ -445,6 +591,19 @@ public enum XSound {
BLOCK_SCULK_SENSOR_HIT,
BLOCK_SCULK_SENSOR_PLACE,
BLOCK_SCULK_SENSOR_STEP,
BLOCK_SCULK_SHRIEKER_BREAK,
BLOCK_SCULK_SHRIEKER_FALL,
BLOCK_SCULK_SHRIEKER_HIT,
BLOCK_SCULK_SHRIEKER_PLACE,
BLOCK_SCULK_SHRIEKER_SHRIEK,
BLOCK_SCULK_SHRIEKER_STEP,
BLOCK_SCULK_SPREAD,
BLOCK_SCULK_STEP,
BLOCK_SCULK_VEIN_BREAK,
BLOCK_SCULK_VEIN_FALL,
BLOCK_SCULK_VEIN_HIT,
BLOCK_SCULK_VEIN_PLACE,
BLOCK_SCULK_VEIN_STEP,
BLOCK_SHROOMLIGHT_BREAK,
BLOCK_SHROOMLIGHT_FALL,
BLOCK_SHROOMLIGHT_HIT,
@@ -500,6 +659,11 @@ public enum XSound {
BLOCK_STONE_PRESSURE_PLATE_CLICK_OFF("BLOCK_STONE_PRESSUREPLATE_CLICK_OFF"),
BLOCK_STONE_PRESSURE_PLATE_CLICK_ON("BLOCK_STONE_PRESSUREPLATE_CLICK_ON"),
BLOCK_STONE_STEP("STEP_STONE"),
BLOCK_SUSPICIOUS_SAND_BREAK,
BLOCK_SUSPICIOUS_SAND_FALL,
BLOCK_SUSPICIOUS_SAND_HIT,
BLOCK_SUSPICIOUS_SAND_PLACE,
BLOCK_SUSPICIOUS_SAND_STEP,
BLOCK_SWEET_BERRY_BUSH_BREAK,
BLOCK_SWEET_BERRY_BUSH_PICK_BERRIES("ITEM_SWEET_BERRIES_PICK_FROM_BUSH"),
BLOCK_SWEET_BERRY_BUSH_PLACE,
@@ -552,6 +716,13 @@ public enum XSound {
BLOCK_WOOL_PLACE("BLOCK_WOOL_FALL"),
BLOCK_WOOL_STEP("STEP_WOOL", "BLOCK_CLOTH_STEP"),
ENCHANT_THORNS_HIT,
ENTITY_ALLAY_AMBIENT_WITHOUT_ITEM,
ENTITY_ALLAY_AMBIENT_WITH_ITEM,
ENTITY_ALLAY_DEATH,
ENTITY_ALLAY_HURT,
ENTITY_ALLAY_ITEM_GIVEN,
ENTITY_ALLAY_ITEM_TAKEN,
ENTITY_ALLAY_ITEM_THROWN,
ENTITY_ARMOR_STAND_BREAK("ENTITY_ARMORSTAND_BREAK"),
ENTITY_ARMOR_STAND_FALL("ENTITY_ARMORSTAND_FALL"),
ENTITY_ARMOR_STAND_HIT("ENTITY_ARMORSTAND_HIT"),
@@ -584,6 +755,17 @@ public enum XSound {
ENTITY_BLAZE_SHOOT,
ENTITY_BOAT_PADDLE_LAND,
ENTITY_BOAT_PADDLE_WATER,
ENTITY_CAMEL_AMBIENT,
ENTITY_CAMEL_DASH,
ENTITY_CAMEL_DASH_READY,
ENTITY_CAMEL_DEATH,
ENTITY_CAMEL_EAT,
ENTITY_CAMEL_HURT,
ENTITY_CAMEL_SADDLE,
ENTITY_CAMEL_SIT,
ENTITY_CAMEL_STAND,
ENTITY_CAMEL_STEP,
ENTITY_CAMEL_STEP_SAND,
ENTITY_CAT_AMBIENT("CAT_MEOW"),
ENTITY_CAT_BEG_FOR_FOOD,
ENTITY_CAT_DEATH,
@@ -698,6 +880,14 @@ public enum XSound {
ENTITY_FOX_SNIFF,
ENTITY_FOX_SPIT,
ENTITY_FOX_TELEPORT,
ENTITY_FROG_AMBIENT,
ENTITY_FROG_DEATH,
ENTITY_FROG_EAT,
ENTITY_FROG_HURT,
ENTITY_FROG_LAY_SPAWN,
ENTITY_FROG_LONG_JUMP,
ENTITY_FROG_STEP,
ENTITY_FROG_TONGUE,
ENTITY_GENERIC_BIG_FALL("FALL_BIG"),
ENTITY_GENERIC_BURN,
ENTITY_GENERIC_DEATH,
@@ -727,6 +917,7 @@ public enum XSound {
ENTITY_GOAT_AMBIENT,
ENTITY_GOAT_DEATH,
ENTITY_GOAT_EAT,
ENTITY_GOAT_HORN_BREAK,
ENTITY_GOAT_HURT,
ENTITY_GOAT_LONG_JUMP,
ENTITY_GOAT_MILK,
@@ -735,6 +926,7 @@ public enum XSound {
ENTITY_GOAT_SCREAMING_AMBIENT,
ENTITY_GOAT_SCREAMING_DEATH,
ENTITY_GOAT_SCREAMING_EAT,
ENTITY_GOAT_SCREAMING_HORN_BREAK,
ENTITY_GOAT_SCREAMING_HURT,
ENTITY_GOAT_SCREAMING_LONG_JUMP,
ENTITY_GOAT_SCREAMING_MILK,
@@ -891,6 +1083,7 @@ public enum XSound {
ENTITY_PARROT_IMITATE_STRAY,
ENTITY_PARROT_IMITATE_VEX,
ENTITY_PARROT_IMITATE_VINDICATOR,
ENTITY_PARROT_IMITATE_WARDEN,
ENTITY_PARROT_IMITATE_WITCH,
ENTITY_PARROT_IMITATE_WITHER,
ENTITY_PARROT_IMITATE_WITHER_SKELETON,
@@ -1025,6 +1218,18 @@ public enum XSound {
ENTITY_SLIME_JUMP_SMALL("SLIME_WALK2", "ENTITY_SMALL_SLIME_SQUISH"),
ENTITY_SLIME_SQUISH("SLIME_WALK2"),
ENTITY_SLIME_SQUISH_SMALL("ENTITY_SMALL_SLIME_SQUISH"),
ENTITY_SNIFFER_DEATH,
ENTITY_SNIFFER_DIGGING,
ENTITY_SNIFFER_DIGGING_STOP,
ENTITY_SNIFFER_DROP_SEED,
ENTITY_SNIFFER_EAT,
ENTITY_SNIFFER_HAPPY,
ENTITY_SNIFFER_HURT,
ENTITY_SNIFFER_IDLE,
ENTITY_SNIFFER_SCENTING,
ENTITY_SNIFFER_SEARCHING,
ENTITY_SNIFFER_SNIFFING,
ENTITY_SNIFFER_STEP,
ENTITY_SNOWBALL_THROW,
ENTITY_SNOW_GOLEM_AMBIENT("ENTITY_SNOWMAN_AMBIENT"),
ENTITY_SNOW_GOLEM_DEATH("ENTITY_SNOWMAN_DEATH"),
@@ -1054,6 +1259,10 @@ public enum XSound {
ENTITY_STRIDER_SADDLE,
ENTITY_STRIDER_STEP,
ENTITY_STRIDER_STEP_LAVA,
ENTITY_TADPOLE_DEATH,
ENTITY_TADPOLE_FLOP,
ENTITY_TADPOLE_GROW_UP,
ENTITY_TADPOLE_HURT,
ENTITY_TNT_PRIMED("FUSE"),
ENTITY_TROPICAL_FISH_AMBIENT,
ENTITY_TROPICAL_FISH_DEATH,
@@ -1109,6 +1318,26 @@ public enum XSound {
ENTITY_WANDERING_TRADER_REAPPEARED,
ENTITY_WANDERING_TRADER_TRADE,
ENTITY_WANDERING_TRADER_YES,
ENTITY_WARDEN_AGITATED,
ENTITY_WARDEN_AMBIENT,
ENTITY_WARDEN_ANGRY,
ENTITY_WARDEN_ATTACK_IMPACT,
ENTITY_WARDEN_DEATH,
ENTITY_WARDEN_DIG,
ENTITY_WARDEN_EMERGE,
ENTITY_WARDEN_HEARTBEAT,
ENTITY_WARDEN_HURT,
ENTITY_WARDEN_LISTENING,
ENTITY_WARDEN_LISTENING_ANGRY,
ENTITY_WARDEN_NEARBY_CLOSE,
ENTITY_WARDEN_NEARBY_CLOSER,
ENTITY_WARDEN_NEARBY_CLOSEST,
ENTITY_WARDEN_ROAR,
ENTITY_WARDEN_SNIFF,
ENTITY_WARDEN_SONIC_BOOM,
ENTITY_WARDEN_SONIC_CHARGE,
ENTITY_WARDEN_STEP,
ENTITY_WARDEN_TENDRIL_CLICKS,
ENTITY_WITCH_AMBIENT,
ENTITY_WITCH_CELEBRATE,
ENTITY_WITCH_DEATH,
@@ -1164,6 +1393,7 @@ public enum XSound {
ENTITY_ZOMBIFIED_PIGLIN_DEATH("ZOMBIE_PIG_DEATH", "ENTITY_ZOMBIE_PIG_DEATH", "ENTITY_ZOMBIE_PIGMAN_DEATH"),
ENTITY_ZOMBIFIED_PIGLIN_HURT("ZOMBIE_PIG_HURT", "ENTITY_ZOMBIE_PIG_HURT", "ENTITY_ZOMBIE_PIGMAN_HURT"),
EVENT_RAID_HORN,
INTENTIONALLY_EMPTY,
ITEM_ARMOR_EQUIP_CHAIN,
ITEM_ARMOR_EQUIP_DIAMOND,
ITEM_ARMOR_EQUIP_ELYTRA,
@@ -1182,16 +1412,20 @@ public enum XSound {
ITEM_BOTTLE_EMPTY,
ITEM_BOTTLE_FILL,
ITEM_BOTTLE_FILL_DRAGONBREATH,
ITEM_BRUSH_BRUSHING,
ITEM_BRUSH_BRUSH_SAND_COMPLETED,
ITEM_BUCKET_EMPTY,
ITEM_BUCKET_EMPTY_AXOLOTL,
ITEM_BUCKET_EMPTY_FISH,
ITEM_BUCKET_EMPTY_LAVA,
ITEM_BUCKET_EMPTY_POWDER_SNOW,
ITEM_BUCKET_EMPTY_TADPOLE,
ITEM_BUCKET_FILL,
ITEM_BUCKET_FILL_AXOLOTL,
ITEM_BUCKET_FILL_FISH,
ITEM_BUCKET_FILL_LAVA,
ITEM_BUCKET_FILL_POWDER_SNOW,
ITEM_BUCKET_FILL_TADPOLE,
ITEM_BUNDLE_DROP_CONTENTS,
ITEM_BUNDLE_INSERT,
ITEM_BUNDLE_REMOVE_ONE,
@@ -1210,6 +1444,15 @@ public enum XSound {
ITEM_FIRECHARGE_USE,
ITEM_FLINTANDSTEEL_USE("FIRE_IGNITE"),
ITEM_GLOW_INK_SAC_USE,
ITEM_GOAT_HORN_PLAY,
ITEM_GOAT_HORN_SOUND_0,
ITEM_GOAT_HORN_SOUND_1,
ITEM_GOAT_HORN_SOUND_2,
ITEM_GOAT_HORN_SOUND_3,
ITEM_GOAT_HORN_SOUND_4,
ITEM_GOAT_HORN_SOUND_5,
ITEM_GOAT_HORN_SOUND_6,
ITEM_GOAT_HORN_SOUND_7,
ITEM_HOE_TILL,
ITEM_HONEYCOMB_WAX_ON,
ITEM_HONEY_BOTTLE_DRINK,
@@ -1234,6 +1477,7 @@ public enum XSound {
MUSIC_CREDITS,
MUSIC_DISC_11("RECORD_11"),
MUSIC_DISC_13("RECORD_13"),
MUSIC_DISC_5,
MUSIC_DISC_BLOCKS("RECORD_BLOCKS"),
MUSIC_DISC_CAT("RECORD_CAT"),
MUSIC_DISC_CHIRP("RECORD_CHIRP"),
@@ -1255,14 +1499,19 @@ public enum XSound {
MUSIC_NETHER_NETHER_WASTES,
MUSIC_NETHER_SOUL_SAND_VALLEY,
MUSIC_NETHER_WARPED_FOREST,
MUSIC_OVERWORLD_CHERRY_GROVE,
MUSIC_OVERWORLD_DEEP_DARK,
MUSIC_OVERWORLD_DRIPSTONE_CAVES,
MUSIC_OVERWORLD_FROZEN_PEAKS,
MUSIC_OVERWORLD_GROVE,
MUSIC_OVERWORLD_JAGGED_PEAKS,
MUSIC_OVERWORLD_JUNGLE_AND_FOREST,
MUSIC_OVERWORLD_LUSH_CAVES,
MUSIC_OVERWORLD_MEADOW,
MUSIC_OVERWORLD_OLD_GROWTH_TAIGA,
MUSIC_OVERWORLD_SNOWY_SLOPES,
MUSIC_OVERWORLD_STONY_PEAKS,
MUSIC_OVERWORLD_SWAMP,
MUSIC_UNDER_WATER,
PARTICLE_SOUL_ESCAPE,
UI_BUTTON_CLICK("CLICK"),
@@ -1356,7 +1605,7 @@ public enum XSound {
*/
@Nonnull
public static Optional<XSound> matchXSound(@Nonnull String sound) {
Validate.notEmpty(sound, "Cannot match XSound of a null or empty sound name");
if (sound == null || sound.isEmpty()) throw new IllegalArgumentException("Cannot match XSound of a null or empty sound name");
return Optional.ofNullable(Data.NAMES.get(format(sound)));
}
@@ -1375,47 +1624,33 @@ public enum XSound {
return Objects.requireNonNull(Data.NAMES.get(sound.name()), () -> "Unsupported sound: " + sound.name());
}
/**
* A quick async way to play a sound from the config.
*
* @param player the player to play the sound to.
* @param sound the sound to play to the player.
*
* @see #play(Location, String)
* @since 1.0.0
*/
@Nonnull
public static CompletableFuture<Record> play(@Nonnull Player player, @Nullable String sound) {
Objects.requireNonNull(player, "Cannot play sound to null player");
return CompletableFuture.supplyAsync(() -> {
Record record = parse(sound);
if (record == null) return null;
record.forPlayer(player).play();
return record;
}).exceptionally(x -> {
x.printStackTrace();
return null;
});
}
private static List<String> split(@Nonnull String str, @SuppressWarnings("SameParameterValue") char separatorChar) {
List<String> list = new ArrayList<>(5);
boolean match = false, lastMatch = false;
int len = str.length();
int start = 0;
/**
* A quick async way to play a sound from the config.
*
* @see #play(Location, String)
* @since 3.0.0
*/
@Nonnull
public static CompletableFuture<Record> play(@Nonnull Location location, @Nullable String sound) {
Objects.requireNonNull(location, "Cannot play sound to null location");
return CompletableFuture.supplyAsync(() -> {
Record record = parse(sound);
if (record == null) return null;
record.atLocation(location).play();
return record;
}).exceptionally(x -> {
x.printStackTrace();
return null;
});
for (int i = 0; i < len; i++) {
if (str.charAt(i) == separatorChar) {
if (match) {
list.add(str.substring(start, i));
match = false;
lastMatch = true;
}
// This is important, it should not be i++
start = i + 1;
continue;
}
lastMatch = false;
match = true;
}
if (match || lastMatch) {
list.add(str.substring(start, len));
}
return list;
}
/**
@@ -1458,27 +1693,31 @@ public enum XSound {
@Nullable
public static Record parse(@Nullable String sound) {
if (Strings.isNullOrEmpty(sound) || sound.equalsIgnoreCase("none")) return null;
String[] split = StringUtils.split(StringUtils.deleteWhitespace(sound), ',');
List<String> split = split(sound.replace(" ", ""), ',');
String name = split[0];
String name = split.get(0);
boolean playAtLocation;
if (name.charAt(0) == '~') {
name = name.substring(1);
playAtLocation = true;
} else playAtLocation = false;
if (name.isEmpty()) throw new IllegalArgumentException("No sound name specified: " + sound);
Optional<XSound> soundType = matchXSound(name);
if (!soundType.isPresent()) return null;
if (!soundType.isPresent()) throw new IllegalArgumentException("Unknown sound: " + name);
float volume = DEFAULT_VOLUME;
float pitch = DEFAULT_PITCH;
try {
if (split.length > 1) {
volume = Float.parseFloat(split[1]);
if (split.length > 2) pitch = Float.parseFloat(split[2]);
}
} catch (NumberFormatException ignored) {
if (split.size() > 1) volume = Float.parseFloat(split.get(1));
} catch (NumberFormatException ex) {
throw new NumberFormatException("Invalid number '" + split.get(1) + "' for sound volume '" + sound + '\'');
}
try {
if (split.size() > 2) pitch = Float.parseFloat(split.get(2));
} catch (NumberFormatException ex) {
throw new NumberFormatException("Invalid number '" + split.get(2) + "' for sound pitch '" + sound + '\'');
}
return new Record(soundType.get(), null, null, volume, pitch, playAtLocation);
@@ -1531,14 +1770,14 @@ public enum XSound {
* @since 2.0.0
*/
@Nonnull
public static BukkitTask playAscendingNote(@Nonnull JavaPlugin plugin, @Nonnull Player player, @Nonnull Entity playTo, @Nonnull Instrument instrument,
public static BukkitTask playAscendingNote(@Nonnull Plugin plugin, @Nonnull Player player, @Nonnull Entity playTo, @Nonnull Instrument instrument,
int ascendLevel, int delay) {
Objects.requireNonNull(player, "Cannot play note from null player");
Objects.requireNonNull(playTo, "Cannot play note to null entity");
Validate.isTrue(ascendLevel > 0, "Note ascend level cannot be lower than 1");
Validate.isTrue(ascendLevel <= 7, "Note ascend level cannot be greater than 7");
Validate.isTrue(delay > 0, "Delay ticks must be at least 1");
if (ascendLevel <= 0) throw new IllegalArgumentException("Note ascend level cannot be lower than 1");
if (ascendLevel > 7) throw new IllegalArgumentException("Note ascend level cannot be greater than 7");
if (delay <= 0) throw new IllegalArgumentException("Delay ticks must be at least 1");
return new BukkitRunnable() {
int repeating = ascendLevel;
@@ -1558,7 +1797,9 @@ public enum XSound {
*/
@Override
public String toString() {
return WordUtils.capitalize(this.name().replace('_', ' ').toLowerCase(Locale.ENGLISH));
return Arrays.stream(name().split("_"))
.map(t -> t.charAt(0) + t.substring(1).toLowerCase())
.collect(Collectors.joining(" "));
}
/**
@@ -1603,12 +1844,12 @@ public enum XSound {
* @since 2.0.0
*/
@Nonnull
public BukkitTask playRepeatedly(@Nonnull JavaPlugin plugin, @Nonnull Entity entity, float volume, float pitch, int repeat, int delay) {
public BukkitTask playRepeatedly(@Nonnull Plugin plugin, @Nonnull Entity entity, float volume, float pitch, int repeat, int delay) {
Objects.requireNonNull(plugin, "Cannot play repeating sound from null plugin");
Objects.requireNonNull(entity, "Cannot play repeating sound at null location");
Validate.isTrue(repeat > 0, "Cannot repeat playing sound " + repeat + " times");
Validate.isTrue(delay > 0, "Delay ticks must be at least 1");
if (repeat <= 0) throw new IllegalArgumentException("Cannot repeat playing sound " + repeat + " times");
if (delay <= 0) throw new IllegalArgumentException("Delay ticks must be at least 1");
return new BukkitRunnable() {
int repeating = repeat;
@@ -1635,6 +1876,50 @@ public enum XSound {
if (sound != null) player.stopSound(sound);
}
/**
* A quick async way to play a sound from the config.
*
* @param player the player to play the sound to.
* @param sound the sound to play to the player.
*
* @see #play(Location, String)
* @since 1.0.0
*/
@Nonnull
@Deprecated
public static CompletableFuture<Record> play(@Nonnull Player player, @Nullable String sound) {
Objects.requireNonNull(player, "Cannot play sound to null player");
return CompletableFuture.supplyAsync(() -> {
Record record;
try {
record = parse(sound);
} catch (Throwable ex) {
return null;
}
if (record == null) return null;
record.forPlayer(player).play();
return record;
}).exceptionally(x -> {
x.printStackTrace();
return null;
});
}
/**
* A quick async way to play a sound from the config.
*
* @see #play(Location, String)
* @since 3.0.0
*/
@Nullable
public static Record play(@Nonnull Location location, @Nullable String sound) {
Objects.requireNonNull(location, "Cannot play sound to null location");
Record record = parse(sound);
if (record == null) return null;
record.atLocation(location).play();
return record;
}
/**
* Plays a normal sound to an entity.
*
@@ -1720,13 +2005,21 @@ public enum XSound {
*
* @since 3.0.0
*/
public static class Record {
public static class Record implements Cloneable {
@Nonnull public final XSound sound;
public final float volume, pitch;
public boolean playAtLocation;
@Nullable public Player player;
@Nullable public Location location;
public Record(@Nonnull XSound sound) {
this(sound, DEFAULT_VOLUME, DEFAULT_PITCH);
}
public Record(@Nonnull XSound sound, float volume, float pitch) {
this(sound, null, null, volume, pitch, false);
}
public Record(@Nonnull XSound sound, @Nullable Player player, @Nullable Location location, float volume, float pitch, boolean playAtLocation) {
this.sound = Objects.requireNonNull(sound, "Sound cannot be null");
this.player = player;
@@ -1804,5 +2097,21 @@ public enum XSound {
}
if (player != null) player.stopSound(sound.parseSound());
}
public String rebuild() {
return (playAtLocation ? "~" : "") + sound.sound + ", " + volume + ", " + pitch;
}
@Override
public Record clone() {
return new Record(
sound,
player,
location,
volume,
pitch,
playAtLocation
);
}
}
}

View File

@@ -49,7 +49,7 @@ public class DiscoveriesCommand {
if (target.getPlayer() != null) {
Player player = target.getPlayer();
player.sendMessage(ChatColor.GREEN + "An administrator added a discovery to your account.");
Bukkit.getPluginManager().callEvent(new RegionDiscoverEvent(player, configuredRegion.getId(), worldDiscovery));
Bukkit.getPluginManager().callEvent(new RegionDiscoverEvent(player, configuredRegion, worldDiscovery));
}
plugin.getManagers().getStorageManager().removeCachedAccount(target.getUniqueId());

View File

@@ -291,8 +291,8 @@ public class DiscoveryGUI extends RPGRegionsGUI {
if (!configuredRegion.getIconCommand().isEmpty()) {
configuredRegion.getIconCommand().forEach(iconCommand -> {
if (iconCommand.getClickType() != IconCommand.CommandClickType.DISCOVERED && hasDiscovered
|| iconCommand.getClickType() != IconCommand.CommandClickType.UNDISCOVERED && !hasDiscovered) {
if (iconCommand.clickType() != IconCommand.CommandClickType.DISCOVERED && hasDiscovered
|| iconCommand.clickType() != IconCommand.CommandClickType.UNDISCOVERED && !hasDiscovered) {
return;
}
@@ -301,15 +301,15 @@ public class DiscoveryGUI extends RPGRegionsGUI {
return;
}
player.performCommand(iconCommand.getCommand()
player.performCommand(iconCommand.command()
.replace("%region%", configuredRegion.getId())
.replace("%player%", player.getName()));
if (iconCommand.getCooldown() != 0) {
if (iconCommand.cooldown() != 0) {
account.getCooldowns().add(RPGRegionsAccount.AccountCooldown.ICON_COMMAND);
plugin.getScheduler().executeDelayed(() -> {
account.getCooldowns().remove(RPGRegionsAccount.AccountCooldown.ICON_COMMAND);
}, iconCommand.getCooldown());
}, iconCommand.cooldown());
}
});
}

View File

@@ -3,7 +3,6 @@ package net.islandearth.rpgregions.listener;
import net.islandearth.rpgregions.RPGRegions;
import net.islandearth.rpgregions.api.events.RegionDiscoverEvent;
import net.islandearth.rpgregions.api.events.RegionsEnterEvent;
import net.islandearth.rpgregions.managers.data.IRPGRegionsCache;
import net.islandearth.rpgregions.managers.data.account.RPGRegionsAccount;
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
import net.islandearth.rpgregions.managers.data.region.Discovery;
@@ -50,24 +49,25 @@ public class RegionListener implements Listener {
final Optional<ConfiguredRegion> prioritised = plugin.getManagers().getRegionsCache().getConfiguredRegion(event.getPriority());
if (prioritised.isPresent() && prioritised.get().disablesPassthrough()) {
plugin.debug("Checking prioritised region only: " + event.getPriority());
runRegionCheck(player, event.getPriority(), prioritised.get(), event, account);
runRegionCheck(player, prioritised.get(), event, account);
return;
}
for (String region : event.getRegions()) {
plugin.debug("Checking region: " + region);
plugin.getManagers().getRegionsCache().getConfiguredRegion(region).ifPresent(configuredRegion -> {
runRegionCheck(player, region, configuredRegion, event, account);
runRegionCheck(player, configuredRegion, event, account);
});
}
});
}
private void runRegionCheck(Player player, String region, ConfiguredRegion configuredRegion, RegionsEnterEvent event, RPGRegionsAccount account) {
private void runRegionCheck(Player player, ConfiguredRegion configuredRegion, RegionsEnterEvent event, RPGRegionsAccount account) {
final String regionId = configuredRegion.getId();
boolean has = false;
boolean prioritised = event.getPriority().equals(region);
boolean prioritised = event.getPriority().equals(regionId);
for (Discovery discoveredRegion : account.getDiscoveredRegions().values()) {
if (discoveredRegion.getRegion().equals(region)) {
if (discoveredRegion.getRegion().equals(regionId)) {
has = true;
break;
}
@@ -88,11 +88,11 @@ public class RegionListener implements Listener {
if (!has && configuredRegion.isDiscoverable() && prioritised) {
if (configuredRegion.isTimedRegion()) {
final long currentTimeMillis = System.currentTimeMillis();
if (account.getTimeEntryInRegion(region).isEmpty()) {
account.addTimeEntryInRegion(region, currentTimeMillis);
if (account.getTimeEntryInRegion(regionId).isEmpty()) {
account.addTimeEntryInRegion(regionId, currentTimeMillis);
}
final TimeEntry entry = account.getTimeEntryInRegion(region).get();
final TimeEntry entry = account.getTimeEntryInRegion(regionId).get();
long lostTime = System.currentTimeMillis() - entry.getLatestEntry();
if (lostTime >= 1000) {
entry.setStart(entry.getStart() + lostTime);
@@ -111,14 +111,14 @@ public class RegionListener implements Listener {
}
// Remove as we are now discovering it.
account.removeStartTimeInRegion(region);
account.removeStartTimeInRegion(regionId);
plugin.debug("Discovering region.");
LocalDateTime date = LocalDateTime.now();
String formattedDate = date.format(format);
Discovery discovery = new WorldDiscovery(formattedDate, region);
Discovery discovery = new WorldDiscovery(formattedDate, regionId);
account.addDiscovery(discovery);
Bukkit.getPluginManager().callEvent(new RegionDiscoverEvent(player, region, discovery));
Bukkit.getPluginManager().callEvent(new RegionDiscoverEvent(player, configuredRegion, discovery));
} else if (prioritised && configuredRegion.isDiscoverable() && has) {
if (configuredRegion.getRewards() != null) configuredRegion.getRewards().forEach(reward -> {
if (reward.isAlwaysAward() && reward.canAward()) {
@@ -131,34 +131,31 @@ public class RegionListener implements Listener {
@EventHandler
public void onDiscover(RegionDiscoverEvent rde) {
Player player = rde.getPlayer();
String region = rde.getRegion();
IRPGRegionsCache regionsCache = plugin.getManagers().getRegionsCache();
regionsCache.getConfiguredRegion(region).ifPresent(configuredRegion -> {
this.sendTitles(player, configuredRegion, true);
ConfiguredRegion region = rde.getRegion();
this.sendTitles(player, region, true);
if (configuredRegion.getSound() == null) {
player.playSound(
player.getLocation(),
XSound.valueOf(plugin.getConfig().getString("settings.server.discoveries.discovered.sound.name")).parseSound(),
1,
plugin.getConfig().getInt("settings.server.discoveries.discovered.sound.pitch")
);
} else {
player.playSound(
player.getLocation(),
configuredRegion.getSound(),
1,
plugin.getConfig().getInt("settings.server.discoveries.discovered.sound.pitch")
);
}
if (region.getSound() == null) {
player.playSound(
player.getLocation(),
XSound.valueOf(plugin.getConfig().getString("settings.server.discoveries.discovered.sound.name")).parseSound(),
1,
plugin.getConfig().getInt("settings.server.discoveries.discovered.sound.pitch")
);
} else {
player.playSound(
player.getLocation(),
region.getSound(),
1,
plugin.getConfig().getInt("settings.server.discoveries.discovered.sound.pitch")
);
}
if (configuredRegion.getRewards() != null) configuredRegion.getRewards().forEach(reward -> reward.award(player));
if (region.getRewards() != null) region.getRewards().forEach(reward -> reward.award(player));
if (configuredRegion.getRegenerate() != null
&& configuredRegion.getRegenerate().isOnDiscover()) {
RegenUtils.regenerate(configuredRegion);
}
});
if (region.getRegenerate() != null
&& region.getRegenerate().isOnDiscover()) {
RegenUtils.regenerate(region);
}
}
private void sendTitles(Player player, ConfiguredRegion configuredRegion, boolean discovered) {

View File

@@ -4,12 +4,14 @@ import net.islandearth.rpgregions.api.IRPGRegionsAPI;
import net.islandearth.rpgregions.api.RPGRegionsAPI;
import net.islandearth.rpgregions.api.events.RegionDiscoverEvent;
import net.islandearth.rpgregions.gui.GuiEditable;
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
import net.islandearth.rpgregions.managers.data.region.WorldDiscovery;
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 {
@@ -28,14 +30,20 @@ public class RegionDiscoverReward extends DiscoveryReward {
@Override
public void award(Player player) {
IRPGRegionsAPI api = RPGRegionsAPI.getAPI();
final Optional<ConfiguredRegion> region = api.getManagers().getRegionsCache().getConfiguredRegion(this.region);
if (region.isEmpty()) {
api.getLogger().warning("Unable to find region '" + region + "' for discover reward.");
return;
}
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, region);
final WorldDiscovery worldDiscovery = new WorldDiscovery(formattedDate, this.region);
account.addDiscovery(worldDiscovery);
Bukkit.getPluginManager().callEvent(new RegionDiscoverEvent(player, region, worldDiscovery));
Bukkit.getPluginManager().callEvent(new RegionDiscoverEvent(player, region.get(), worldDiscovery));
this.updateAwardTime();
});
}