Search in sources :

Example 1 with CraftDetectEvent

use of net.countercraft.movecraft.events.CraftDetectEvent in project Movecraft by APDevTeam.

the class DetectionTask method get.

@Override
public Effect get() {
    frontier();
    if (!illegal.isEmpty())
        return null;
    var result = COMPLETION_VALIDATORS.stream().reduce(DetectionPredicate::and).orElse((a, b, c, d) -> Result.fail()).validate(materials, type, movecraftWorld, player);
    result = result.isSucess() ? VISITED_VALIDATORS.stream().reduce(DetectionPredicate::and).orElse((a, b, c, d) -> Result.fail()).validate(visitedMaterials, type, movecraftWorld, player) : result;
    if (!result.isSucess()) {
        String message = result.getMessage();
        return () -> audience.sendMessage(Component.text(message));
    }
    var hitbox = new BitmapHitBox(legal);
    var parents = findParents(hitbox);
    var supplied = supplier.apply(type, world, player, parents);
    result = supplied.getLeft();
    Craft craft = supplied.getRight();
    if (type.getBoolProperty(CraftType.MUST_BE_SUBCRAFT) && !(craft instanceof SubCraft)) {
        result = Result.failWithMessage(I18nSupport.getInternationalisedString("Detection - Must Be Subcraft"));
    }
    if (!result.isSucess()) {
        String message = result.getMessage();
        return () -> audience.sendMessage(Component.text(message));
    }
    craft.setAudience(audience);
    craft.setHitBox(hitbox);
    craft.setFluidLocations(new BitmapHitBox(fluid));
    craft.setOrigBlockCount(craft.getHitBox().size());
    final CraftDetectEvent event = new CraftDetectEvent(craft, startLocation);
    WorldManager.INSTANCE.executeMain(() -> Bukkit.getPluginManager().callEvent(event));
    if (event.isCancelled())
        return () -> craft.getAudience().sendMessage(Component.text(event.getFailMessage()));
    return ((Effect) () -> {
        // Notify player and console
        craft.getAudience().sendMessage(Component.text(String.format("%s Size: %s", I18nSupport.getInternationalisedString("Detection - Successfully piloted craft"), craft.getHitBox().size())));
        Movecraft.getInstance().getLogger().info(String.format(I18nSupport.getInternationalisedString("Detection - Success - Log Output"), player == null ? "null" : player.getName(), craft.getType().getStringProperty(CraftType.NAME), craft.getHitBox().size(), craft.getHitBox().getMinX(), craft.getHitBox().getMinZ()));
    }).andThen(// TODO: Remove
    water(craft)).andThen(// Fire off pilot event
    () -> Bukkit.getServer().getPluginManager().callEvent(new CraftPilotEvent(craft, CraftPilotEvent.Reason.PLAYER))).andThen(// Apply post detection effect
    postDetection.apply(craft)).andThen(// Add craft to CraftManager
    () -> CraftManager.getInstance().add(craft));
}
Also used : AllowedBlockValidator(net.countercraft.movecraft.processing.tasks.detection.validators.AllowedBlockValidator) Arrays(java.util.Arrays) CraftDetectEvent(net.countercraft.movecraft.events.CraftDetectEvent) MovecraftWorld(net.countercraft.movecraft.processing.MovecraftWorld) Player(org.bukkit.entity.Player) Location(org.bukkit.Location) World(org.bukkit.World) Map(java.util.Map) FlyBlockValidator(net.countercraft.movecraft.processing.tasks.detection.validators.FlyBlockValidator) CraftManager(net.countercraft.movecraft.craft.CraftManager) Material(org.bukkit.Material) Effect(net.countercraft.movecraft.processing.effects.Effect) Bukkit(org.bukkit.Bukkit) Result(net.countercraft.movecraft.processing.functions.Result) CraftType(net.countercraft.movecraft.craft.type.CraftType) PilotSignValidator(net.countercraft.movecraft.processing.tasks.detection.validators.PilotSignValidator) Craft(net.countercraft.movecraft.craft.Craft) BitmapHitBox(net.countercraft.movecraft.util.hitboxes.BitmapHitBox) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) AtomicLocationSet(net.countercraft.movecraft.util.AtomicLocationSet) Movecraft(net.countercraft.movecraft.Movecraft) I18nSupport(net.countercraft.movecraft.localisation.I18nSupport) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) CraftSupplier(net.countercraft.movecraft.processing.functions.CraftSupplier) WaterContactValidator(net.countercraft.movecraft.processing.tasks.detection.validators.WaterContactValidator) Queue(java.util.Queue) DetectionPredicate(net.countercraft.movecraft.processing.functions.DetectionPredicate) NotNull(org.jetbrains.annotations.NotNull) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) SubCraft(net.countercraft.movecraft.craft.SubCraft) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) LongAdder(java.util.concurrent.atomic.LongAdder) CollectionUtils(net.countercraft.movecraft.util.CollectionUtils) SolidHitBox(net.countercraft.movecraft.util.hitboxes.SolidHitBox) Deque(java.util.Deque) Function(java.util.function.Function) Supplier(java.util.function.Supplier) CraftPilotEvent(net.countercraft.movecraft.events.CraftPilotEvent) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) NameSignValidator(net.countercraft.movecraft.processing.tasks.detection.validators.NameSignValidator) Component(net.kyori.adventure.text.Component) WorldManager(net.countercraft.movecraft.processing.WorldManager) HitBox(net.countercraft.movecraft.util.hitboxes.HitBox) Functions(com.google.common.base.Functions) ForkJoinTask(java.util.concurrent.ForkJoinTask) ForbiddenSignStringValidator(net.countercraft.movecraft.processing.tasks.detection.validators.ForbiddenSignStringValidator) SetHitBox(net.countercraft.movecraft.util.hitboxes.SetHitBox) ForbiddenBlockValidator(net.countercraft.movecraft.processing.tasks.detection.validators.ForbiddenBlockValidator) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) Tags(net.countercraft.movecraft.util.Tags) Audience(net.kyori.adventure.audience.Audience) ForkJoinPool(java.util.concurrent.ForkJoinPool) SizeValidator(net.countercraft.movecraft.processing.tasks.detection.validators.SizeValidator) Comparator(java.util.Comparator) Collections(java.util.Collections) Craft(net.countercraft.movecraft.craft.Craft) SubCraft(net.countercraft.movecraft.craft.SubCraft) CraftDetectEvent(net.countercraft.movecraft.events.CraftDetectEvent) SubCraft(net.countercraft.movecraft.craft.SubCraft) DetectionPredicate(net.countercraft.movecraft.processing.functions.DetectionPredicate) BitmapHitBox(net.countercraft.movecraft.util.hitboxes.BitmapHitBox) CraftPilotEvent(net.countercraft.movecraft.events.CraftPilotEvent)

Example 2 with CraftDetectEvent

use of net.countercraft.movecraft.events.CraftDetectEvent in project Movecraft by APDevTeam.

the class NameSign method onCraftDetect.

@EventHandler
public void onCraftDetect(@NotNull CraftDetectEvent event) {
    Craft c = event.getCraft();
    if (c instanceof PilotedCraft) {
        PilotedCraft pilotedCraft = (PilotedCraft) c;
        if (Settings.RequireNamePerm && !pilotedCraft.getPilot().hasPermission("movecraft.name.place"))
            return;
    }
    World w = c.getWorld();
    for (MovecraftLocation location : c.getHitBox()) {
        var block = location.toBukkit(w).getBlock();
        if (!Tag.SIGNS.isTagged(block.getType())) {
            continue;
        }
        BlockState state = block.getState();
        if (!(state instanceof Sign)) {
            return;
        }
        Sign sign = (Sign) state;
        if (sign.getLine(0).equalsIgnoreCase(HEADER)) {
            String name = Arrays.stream(sign.getLines()).skip(1).filter(f -> f != null && !f.trim().isEmpty()).collect(Collectors.joining(" "));
            c.setName(name);
            return;
        }
    }
}
Also used : Sign(org.bukkit.block.Sign) Arrays(java.util.Arrays) Tag(org.bukkit.Tag) Craft(net.countercraft.movecraft.craft.Craft) BlockState(org.bukkit.block.BlockState) CraftDetectEvent(net.countercraft.movecraft.events.CraftDetectEvent) Collectors(java.util.stream.Collectors) SignChangeEvent(org.bukkit.event.block.SignChangeEvent) Settings(net.countercraft.movecraft.config.Settings) EventHandler(org.bukkit.event.EventHandler) World(org.bukkit.World) PilotedCraft(net.countercraft.movecraft.craft.PilotedCraft) NotNull(org.jetbrains.annotations.NotNull) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) ChatUtils(net.countercraft.movecraft.util.ChatUtils) Listener(org.bukkit.event.Listener) BlockState(org.bukkit.block.BlockState) Craft(net.countercraft.movecraft.craft.Craft) PilotedCraft(net.countercraft.movecraft.craft.PilotedCraft) PilotedCraft(net.countercraft.movecraft.craft.PilotedCraft) Sign(org.bukkit.block.Sign) World(org.bukkit.World) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Arrays (java.util.Arrays)2 Collectors (java.util.stream.Collectors)2 MovecraftLocation (net.countercraft.movecraft.MovecraftLocation)2 Craft (net.countercraft.movecraft.craft.Craft)2 CraftDetectEvent (net.countercraft.movecraft.events.CraftDetectEvent)2 Functions (com.google.common.base.Functions)1 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Deque (java.util.Deque)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Queue (java.util.Queue)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentLinkedDeque (java.util.concurrent.ConcurrentLinkedDeque)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1