Search in sources :

Example 11 with MovecraftLocation

use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.

the class CraftRotateCommand method sendSignEvents.

private void sendSignEvents() {
    Object2ObjectMap<String[], List<MovecraftLocation>> signs = new Object2ObjectOpenCustomHashMap<>(new Hash.Strategy<String[]>() {

        @Override
        public int hashCode(String[] strings) {
            return Arrays.hashCode(strings);
        }

        @Override
        public boolean equals(String[] a, String[] b) {
            return Arrays.equals(a, b);
        }
    });
    Map<MovecraftLocation, Sign> signStates = new HashMap<>();
    for (MovecraftLocation location : craft.getHitBox()) {
        Block block = location.toBukkit(craft.getWorld()).getBlock();
        BlockState state = block.getState();
        if (state instanceof Sign) {
            Sign sign = (Sign) block.getState();
            if (!signs.containsKey(sign.getLines()))
                signs.put(sign.getLines(), new ArrayList<>());
            signs.get(sign.getLines()).add(location);
            signStates.put(location, sign);
        }
    }
    for (Map.Entry<String[], List<MovecraftLocation>> entry : signs.entrySet()) {
        SignTranslateEvent event = new SignTranslateEvent(craft, entry.getKey(), entry.getValue());
        Bukkit.getServer().getPluginManager().callEvent(event);
        if (!event.isUpdated()) {
            continue;
        }
        for (MovecraftLocation location : entry.getValue()) {
            Block block = location.toBukkit(craft.getWorld()).getBlock();
            BlockState state = block.getState();
            BlockData data = block.getBlockData();
            if (!(state instanceof Sign)) {
                continue;
            }
            Sign sign = signStates.get(location);
            for (int i = 0; i < 4; i++) {
                sign.setLine(i, entry.getKey()[i]);
            }
            sign.update(false, false);
            block.setBlockData(data);
        }
    }
}
Also used : Object2ObjectOpenCustomHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap) HashMap(java.util.HashMap) Object2ObjectOpenCustomHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap) ArrayList(java.util.ArrayList) SignTranslateEvent(net.countercraft.movecraft.events.SignTranslateEvent) Hash(it.unimi.dsi.fastutil.Hash) BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Sign(org.bukkit.block.Sign) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) BlockData(org.bukkit.block.data.BlockData) Object2ObjectMap(it.unimi.dsi.fastutil.objects.Object2ObjectMap) HashMap(java.util.HashMap) Map(java.util.Map) Object2ObjectOpenCustomHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap)

Example 12 with MovecraftLocation

use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.

the class CraftTranslateCommand method sendSignEvents.

private void sendSignEvents() {
    Object2ObjectMap<String[], List<MovecraftLocation>> signs = new Object2ObjectOpenCustomHashMap<>(new Hash.Strategy<String[]>() {

        @Override
        public int hashCode(String[] strings) {
            return Arrays.hashCode(strings);
        }

        @Override
        public boolean equals(String[] a, String[] b) {
            return Arrays.equals(a, b);
        }
    });
    Map<MovecraftLocation, Sign> signStates = new HashMap<>();
    for (MovecraftLocation location : craft.getHitBox()) {
        Block block = location.toBukkit(craft.getWorld()).getBlock();
        if (!Tag.SIGNS.isTagged(block.getType())) {
            continue;
        }
        BlockState state = block.getState();
        if (state instanceof Sign) {
            Sign sign = (Sign) state;
            if (!signs.containsKey(sign.getLines()))
                signs.put(sign.getLines(), new ArrayList<>());
            signs.get(sign.getLines()).add(location);
            signStates.put(location, sign);
        }
    }
    for (Map.Entry<String[], List<MovecraftLocation>> entry : signs.entrySet()) {
        SignTranslateEvent event = new SignTranslateEvent(craft, entry.getKey(), entry.getValue());
        Bukkit.getServer().getPluginManager().callEvent(event);
        if (!event.isUpdated()) {
            continue;
        }
        for (MovecraftLocation location : entry.getValue()) {
            Block block = location.toBukkit(craft.getWorld()).getBlock();
            BlockState state = block.getState();
            if (!(state instanceof Sign)) {
                continue;
            }
            Sign sign = signStates.get(location);
            for (int i = 0; i < 4; i++) {
                sign.setLine(i, entry.getKey()[i]);
            }
            sign.update(false, false);
        }
    }
}
Also used : Object2ObjectOpenCustomHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap) HashMap(java.util.HashMap) Object2ObjectOpenCustomHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap) ArrayList(java.util.ArrayList) SignTranslateEvent(net.countercraft.movecraft.events.SignTranslateEvent) Hash(it.unimi.dsi.fastutil.Hash) BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Sign(org.bukkit.block.Sign) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) Object2ObjectMap(it.unimi.dsi.fastutil.objects.Object2ObjectMap) HashMap(java.util.HashMap) Map(java.util.Map) Object2ObjectOpenCustomHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap)

Example 13 with MovecraftLocation

use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.

the class HoverValidator method validate.

@Override
@Contract(pure = true)
@NotNull
public Result validate(@NotNull MovecraftLocation translation, @NotNull MovecraftWorld world, @NotNull HitBox hitBox, @NotNull CraftType type) {
    if (type.getMaterialSetProperty(CraftType.FORBIDDEN_HOVER_OVER_BLOCKS).size() > 0) {
        MovecraftLocation test = new MovecraftLocation(hitBox.getMidPoint().getX(), hitBox.getMinY(), hitBox.getMidPoint().getZ());
        test = test.translate(0, -1, 0);
        while (world.getMaterial(test).isAir()) {
            test = test.translate(0, -1, 0);
        }
        Material testType = world.getMaterial(test);
        if (type.getMaterialSetProperty(CraftType.FORBIDDEN_HOVER_OVER_BLOCKS).contains(testType)) {
            return Result.failWithMessage(String.format(I18nSupport.getInternationalisedString("Translation - Failed Craft over block"), testType.name().toLowerCase().replace("_", " ")));
        }
    }
    return Result.succeed();
}
Also used : Material(org.bukkit.Material) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with MovecraftLocation

use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.

the class AscendSign method onCraftDetect.

@EventHandler
public void onCraftDetect(CraftDetectEvent event) {
    World world = event.getCraft().getWorld();
    for (MovecraftLocation location : event.getCraft().getHitBox()) {
        var block = location.toBukkit(world).getBlock();
        if (!Tag.SIGNS.isTagged(block.getType())) {
            continue;
        }
        BlockState state = block.getState();
        if (block.getState() instanceof Sign) {
            Sign sign = (Sign) block.getState();
            if (ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("Ascend: ON")) {
                sign.setLine(0, "Ascend: OFF");
                sign.update();
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Sign(org.bukkit.block.Sign) World(org.bukkit.World) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) EventHandler(org.bukkit.event.EventHandler)

Example 15 with MovecraftLocation

use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.

the class ContactsSign method onSignTranslateEvent.

@EventHandler
public final void onSignTranslateEvent(SignTranslateEvent event) {
    String[] lines = event.getLines();
    Craft craft = event.getCraft();
    if (!ChatColor.stripColor(lines[0]).equalsIgnoreCase("Contacts:")) {
        return;
    }
    int signLine = 1;
    for (Craft tcraft : craft.getContacts()) {
        MovecraftLocation center = craft.getHitBox().getMidPoint();
        MovecraftLocation tcenter = tcraft.getHitBox().getMidPoint();
        int distsquared = center.distanceSquared(tcenter);
        // craft has been detected
        String notification = ChatColor.BLUE + tcraft.getType().getStringProperty(CraftType.NAME);
        if (notification.length() > 9) {
            notification = notification.substring(0, 7);
        }
        notification += " " + (int) Math.sqrt(distsquared);
        int diffx = center.getX() - tcenter.getX();
        int diffz = center.getZ() - tcenter.getZ();
        if (Math.abs(diffx) > Math.abs(diffz)) {
            if (diffx < 0) {
                notification += " E";
            } else {
                notification += " W";
            }
        } else {
            if (diffz < 0) {
                notification += " S";
            } else {
                notification += " N";
            }
        }
        lines[signLine++] = notification;
        if (signLine >= 4) {
            break;
        }
    }
    if (signLine < 4) {
        for (int i = signLine; i < 4; i++) {
            lines[signLine] = "";
        }
    }
}
Also used : Craft(net.countercraft.movecraft.craft.Craft) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) EventHandler(org.bukkit.event.EventHandler)

Aggregations

MovecraftLocation (net.countercraft.movecraft.MovecraftLocation)60 Craft (net.countercraft.movecraft.craft.Craft)18 EventHandler (org.bukkit.event.EventHandler)18 Material (org.bukkit.Material)17 World (org.bukkit.World)15 Sign (org.bukkit.block.Sign)14 BlockState (org.bukkit.block.BlockState)13 Block (org.bukkit.block.Block)12 ArrayList (java.util.ArrayList)11 Location (org.bukkit.Location)11 Map (java.util.Map)10 HashMap (java.util.HashMap)9 SetHitBox (net.countercraft.movecraft.util.hitboxes.SetHitBox)9 HashSet (java.util.HashSet)8 SinkingCraft (net.countercraft.movecraft.craft.SinkingCraft)8 NotNull (org.jetbrains.annotations.NotNull)8 MovecraftRotation (net.countercraft.movecraft.MovecraftRotation)6 HitBox (net.countercraft.movecraft.util.hitboxes.HitBox)6 SolidHitBox (net.countercraft.movecraft.util.hitboxes.SolidHitBox)6 LinkedList (java.util.LinkedList)5