Search in sources :

Example 6 with PilotedCraft

use of net.countercraft.movecraft.craft.PilotedCraft 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

Craft (net.countercraft.movecraft.craft.Craft)6 PilotedCraft (net.countercraft.movecraft.craft.PilotedCraft)6 SinkingCraft (net.countercraft.movecraft.craft.SinkingCraft)4 MovecraftLocation (net.countercraft.movecraft.MovecraftLocation)3 PlayerCraft (net.countercraft.movecraft.craft.PlayerCraft)2 TopicPaginator (net.countercraft.movecraft.util.TopicPaginator)2 HitBox (net.countercraft.movecraft.util.hitboxes.HitBox)2 World (org.bukkit.World)2 Player (org.bukkit.entity.Player)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 WeakHashMap (java.util.WeakHashMap)1 Collectors (java.util.stream.Collectors)1 Settings (net.countercraft.movecraft.config.Settings)1 CraftDetectEvent (net.countercraft.movecraft.events.CraftDetectEvent)1 ChatUtils (net.countercraft.movecraft.util.ChatUtils)1 Sound (net.kyori.adventure.sound.Sound)1 Component (net.kyori.adventure.text.Component)1 Tag (org.bukkit.Tag)1