Search in sources :

Example 1 with CraftType

use of net.countercraft.movecraft.craft.type.CraftType in project Movecraft by APDevTeam.

the class TranslationTask method isOnGround.

private boolean isOnGround(HitBox hitBox) {
    MutableHitBox bottomLocs = new SetHitBox();
    MutableHitBox translatedBottomLocs = new SetHitBox();
    if (hitBox.getMinY() <= (int) craft.getType().getPerWorldProperty(CraftType.PER_WORLD_MIN_HEIGHT_LIMIT, craft.getWorld())) {
        return true;
    }
    MovecraftLocation corner1 = new MovecraftLocation(hitBox.getMinX(), 0, hitBox.getMinZ());
    MovecraftLocation corner2 = new MovecraftLocation(hitBox.getMaxX(), 0, hitBox.getMaxZ());
    for (MovecraftLocation location : new SolidHitBox(corner1, corner2)) {
        int test = hitBox.getMinYAt(location.getX(), location.getZ());
        if (test == -1) {
            continue;
        }
        bottomLocs.add(new MovecraftLocation(location.getX(), test, location.getZ()));
    }
    boolean bottomLocsOnGround = false;
    for (MovecraftLocation bottomLoc : bottomLocs) {
        translatedBottomLocs.add(bottomLoc.translate(dx, dy, dz));
        Material testType = bottomLoc.translate(0, -1, 0).toBukkit(craft.getWorld()).getBlock().getType();
        // If the lowest part of the bottom locs touch the ground, return true anyways
        if (testType.isAir())
            continue;
        else if (craft.getType().getMaterialSetProperty(CraftType.PASSTHROUGH_BLOCKS).contains(testType))
            continue;
        else if (craft.getType().getMaterialSetProperty(CraftType.HARVEST_BLOCKS).contains(testType) && craft.getType().getMaterialSetProperty(CraftType.HARVESTER_BLADE_BLOCKS).contains(bottomLoc.toBukkit(craft.getWorld()).getBlock().getType()))
            continue;
        bottomLocsOnGround = true;
    }
    boolean translatedBottomLocsInAir = true;
    for (MovecraftLocation translatedBottomLoc : translatedBottomLocs) {
        MovecraftLocation beneath = translatedBottomLoc.translate(0, -1, 0);
        Material testType = beneath.toBukkit(craft.getWorld()).getBlock().getType();
        final CraftType type = craft.getType();
        if (hitBox.contains(beneath) || bottomLocs.contains(beneath) || testType.isAir() || type.getMaterialSetProperty(CraftType.PASSTHROUGH_BLOCKS).contains(testType) || (type.getMaterialSetProperty(CraftType.HARVEST_BLOCKS).contains(testType) && type.getMaterialSetProperty(CraftType.HARVESTER_BLADE_BLOCKS).contains(translatedBottomLoc.translate(-dx, -dy, -dz).toBukkit(craft.getWorld()).getBlock().getType()))) {
            continue;
        }
        translatedBottomLocsInAir = false;
        break;
    }
    if (Settings.Debug) {
        final Logger log = Movecraft.getInstance().getLogger();
        log.info("Translated bottom locs in air: " + translatedBottomLocsInAir);
        log.info("Bottom locs on ground: " + bottomLocsOnGround);
    }
    if (dy > 0) {
        return bottomLocsOnGround && translatedBottomLocsInAir;
    }
    return !translatedBottomLocsInAir;
}
Also used : MutableHitBox(net.countercraft.movecraft.util.hitboxes.MutableHitBox) SolidHitBox(net.countercraft.movecraft.util.hitboxes.SolidHitBox) SetHitBox(net.countercraft.movecraft.util.hitboxes.SetHitBox) Material(org.bukkit.Material) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) Logger(java.util.logging.Logger) CraftType(net.countercraft.movecraft.craft.type.CraftType)

Example 2 with CraftType

use of net.countercraft.movecraft.craft.type.CraftType in project Movecraft by APDevTeam.

the class CraftTypeCommand method onTabComplete.

@Nullable
@Override
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
    if (strings.length != 1 || !commandSender.hasPermission("movecraft.commands") || !commandSender.hasPermission("movecraft.commands.crafttype"))
        return Collections.emptyList();
    List<String> completions = new ArrayList<>();
    for (CraftType type : CraftManager.getInstance().getCraftTypes()) if (commandSender.hasPermission("movecraft." + type.getStringProperty(CraftType.NAME) + ".pilot"))
        completions.add(type.getStringProperty(CraftType.NAME));
    completions.add("list");
    List<String> returnValues = new ArrayList<>();
    for (String completion : completions) if (completion.toLowerCase().startsWith(strings[strings.length - 1].toLowerCase()))
        returnValues.add(completion);
    return returnValues;
}
Also used : ArrayList(java.util.ArrayList) CraftType(net.countercraft.movecraft.craft.type.CraftType) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with CraftType

use of net.countercraft.movecraft.craft.type.CraftType in project Movecraft by APDevTeam.

the class CraftTypeCommand method onCommand.

@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
    CraftType type;
    int page;
    if (args.length == 0 || (args.length == 1 && MathUtils.parseInt(args[0]).isPresent())) {
        Optional<CraftType> typeQuery = tryGetCraftFromPlayer(commandSender);
        if (typeQuery.isEmpty()) {
            commandSender.sendMessage("You must supply a craft type!");
            return true;
        }
        type = typeQuery.get();
        page = args.length == 0 ? 1 : MathUtils.parseInt(args[0]).getAsInt();
    } else {
        if (args.length > 1) {
            OptionalInt pageQuery = MathUtils.parseInt(args[1]);
            if (pageQuery.isEmpty()) {
                commandSender.sendMessage("Argument " + args[1] + " must be a page number");
                return true;
            }
            page = pageQuery.getAsInt();
        } else {
            page = 1;
        }
        if (args[0].equalsIgnoreCase("list")) {
            sendTypeListPage(page, commandSender);
            return true;
        }
        type = CraftManager.getInstance().getCraftTypeFromString(args[0]);
    }
    if (type == null) {
        commandSender.sendMessage("You must supply a craft type!");
        return true;
    }
    if (!commandSender.hasPermission("movecraft." + type.getStringProperty(CraftType.NAME) + ".pilot")) {
        commandSender.sendMessage("You don't have permission for that craft type!");
        return true;
    }
    sendTypePage(type, page, commandSender);
    return true;
}
Also used : OptionalInt(java.util.OptionalInt) CraftType(net.countercraft.movecraft.craft.type.CraftType)

Example 4 with CraftType

use of net.countercraft.movecraft.craft.type.CraftType in project Movecraft by APDevTeam.

the class PilotCommand method onCommand.

@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
    if (!command.getName().equalsIgnoreCase("pilot"))
        return false;
    if (!(commandSender instanceof Player)) {
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Pilot - Must Be Player"));
        return true;
    }
    Player player = (Player) commandSender;
    if (!player.hasPermission("movecraft.commands") || !player.hasPermission("movecraft.commands.pilot")) {
        player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions"));
        return true;
    }
    if (args.length < 1) {
        player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Pilot - No Craft Type"));
        return true;
    }
    if (!player.hasPermission("movecraft." + args[0] + ".pilot")) {
        player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions"));
        return true;
    }
    CraftType craftType = CraftManager.getInstance().getCraftTypeFromString(args[0]);
    if (craftType == null) {
        player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Pilot - Invalid Craft Type"));
        return true;
    }
    final World world = player.getWorld();
    MovecraftLocation startPoint = MathUtils.bukkit2MovecraftLoc(player.getLocation());
    CraftManager.getInstance().detect(startPoint, craftType, (type, w, p, parents) -> {
        // Note: This only passes in a non-null player.
        assert p != null;
        if (parents.size() > 0)
            return new Pair<>(Result.failWithMessage(I18nSupport.getInternationalisedString("Detection - Failed - Already commanding a craft")), null);
        return new Pair<>(Result.succeed(), new PlayerCraftImpl(type, w, p));
    }, world, player, Movecraft.getAdventure().player(player), craft -> () -> {
        // Release old craft if it exists
        Craft oldCraft = CraftManager.getInstance().getCraftByPlayer(player);
        if (oldCraft != null)
            CraftManager.getInstance().release(oldCraft, CraftReleaseEvent.Reason.PLAYER, false);
    });
    return true;
}
Also used : Player(org.bukkit.entity.Player) PlayerCraftImpl(net.countercraft.movecraft.craft.PlayerCraftImpl) CruiseOnPilotCraft(net.countercraft.movecraft.craft.CruiseOnPilotCraft) CruiseOnPilotSubCraft(net.countercraft.movecraft.craft.CruiseOnPilotSubCraft) Craft(net.countercraft.movecraft.craft.Craft) World(org.bukkit.World) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) CraftType(net.countercraft.movecraft.craft.type.CraftType) Pair(net.countercraft.movecraft.util.Pair)

Example 5 with CraftType

use of net.countercraft.movecraft.craft.type.CraftType in project Movecraft by APDevTeam.

the class SubcraftRotateSign method onSignClick.

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onSignClick(@NotNull PlayerInteractEvent event) {
    MovecraftRotation rotation;
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK)
        rotation = MovecraftRotation.CLOCKWISE;
    else if (event.getAction() == Action.LEFT_CLICK_BLOCK)
        rotation = MovecraftRotation.ANTICLOCKWISE;
    else
        return;
    BlockState state = event.getClickedBlock().getState();
    if (!(state instanceof Sign))
        return;
    Sign sign = (Sign) state;
    if (!ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase(HEADER))
        return;
    Location loc = event.getClickedBlock().getLocation();
    MovecraftLocation startPoint = new MovecraftLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
    if (rotating.contains(startPoint)) {
        event.getPlayer().sendMessage(I18nSupport.getInternationalisedString("Rotation - Already Rotating"));
        event.setCancelled(true);
        return;
    }
    // rotate subcraft
    String craftTypeStr = ChatColor.stripColor(sign.getLine(1));
    CraftType craftType = CraftManager.getInstance().getCraftTypeFromString(craftTypeStr);
    if (craftType == null)
        return;
    if (ChatColor.stripColor(sign.getLine(2)).equals("") && ChatColor.stripColor(sign.getLine(3)).equals("")) {
        sign.setLine(2, "_\\ /_");
        sign.setLine(3, "/ \\");
        sign.update(false, false);
    }
    if (!event.getPlayer().hasPermission("movecraft." + craftTypeStr + ".pilot") || !event.getPlayer().hasPermission("movecraft." + craftTypeStr + ".rotate")) {
        event.getPlayer().sendMessage(I18nSupport.getInternationalisedString("Insufficient Permissions"));
        return;
    }
    Craft playerCraft = CraftManager.getInstance().getCraftByPlayer(event.getPlayer());
    if (playerCraft != null) {
        if (!playerCraft.isNotProcessing()) {
            event.getPlayer().sendMessage(I18nSupport.getInternationalisedString("Detection - Parent Craft is busy"));
            return;
        }
        // prevent the parent craft from moving or updating until the subcraft is done
        playerCraft.setProcessing(true);
        new BukkitRunnable() {

            @Override
            public void run() {
                playerCraft.setProcessing(false);
            }
        }.runTaskLater(Movecraft.getInstance(), (10));
    }
    rotating.add(startPoint);
    Player player = event.getPlayer();
    World world = event.getClickedBlock().getWorld();
    CraftManager.getInstance().detect(startPoint, craftType, (type, w, p, parents) -> {
        if (parents.size() > 1)
            return new Pair<>(Result.failWithMessage(I18nSupport.getInternationalisedString("Detection - Failed - Already commanding a craft")), null);
        if (parents.size() < 1)
            return new Pair<>(Result.succeed(), new SubcraftRotateCraft(type, w, p));
        Craft parent = parents.iterator().next();
        return new Pair<>(Result.succeed(), new SubCraftImpl(type, w, parent));
    }, world, player, Movecraft.getAdventure().player(player), craft -> () -> {
        Bukkit.getServer().getPluginManager().callEvent(new CraftPilotEvent(craft, CraftPilotEvent.Reason.SUB_CRAFT));
        if (craft instanceof SubCraft) {
            // Subtract craft from the parent
            Craft parent = ((SubCraft) craft).getParent();
            var newHitbox = parent.getHitBox().difference(craft.getHitBox());
            ;
            parent.setHitBox(newHitbox);
        }
        new BukkitRunnable() {

            @Override
            public void run() {
                craft.rotate(rotation, startPoint, true);
                if (craft instanceof SubCraft) {
                    Craft parent = ((SubCraft) craft).getParent();
                    var newHitbox = parent.getHitBox().union(craft.getHitBox());
                    parent.setHitBox(newHitbox);
                }
                CraftManager.getInstance().release(craft, CraftReleaseEvent.Reason.SUB_CRAFT, false);
            }
        }.runTaskLater(Movecraft.getInstance(), 3);
    });
    event.setCancelled(true);
    new BukkitRunnable() {

        @Override
        public void run() {
            rotating.remove(startPoint);
        }
    }.runTaskLater(Movecraft.getInstance(), 4);
}
Also used : Player(org.bukkit.entity.Player) SubcraftRotateCraft(net.countercraft.movecraft.craft.SubcraftRotateCraft) Craft(net.countercraft.movecraft.craft.Craft) SubCraft(net.countercraft.movecraft.craft.SubCraft) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) World(org.bukkit.World) SubcraftRotateCraft(net.countercraft.movecraft.craft.SubcraftRotateCraft) CraftPilotEvent(net.countercraft.movecraft.events.CraftPilotEvent) MovecraftRotation(net.countercraft.movecraft.MovecraftRotation) BlockState(org.bukkit.block.BlockState) Sign(org.bukkit.block.Sign) SubCraftImpl(net.countercraft.movecraft.craft.SubCraftImpl) SubCraft(net.countercraft.movecraft.craft.SubCraft) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) CraftType(net.countercraft.movecraft.craft.type.CraftType) Location(org.bukkit.Location) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) Pair(net.countercraft.movecraft.util.Pair) EventHandler(org.bukkit.event.EventHandler)

Aggregations

CraftType (net.countercraft.movecraft.craft.type.CraftType)9 MovecraftLocation (net.countercraft.movecraft.MovecraftLocation)4 Player (org.bukkit.entity.Player)4 Craft (net.countercraft.movecraft.craft.Craft)3 Pair (net.countercraft.movecraft.util.Pair)3 World (org.bukkit.World)3 BlockState (org.bukkit.block.BlockState)3 EventHandler (org.bukkit.event.EventHandler)3 ArrayList (java.util.ArrayList)2 CruiseOnPilotCraft (net.countercraft.movecraft.craft.CruiseOnPilotCraft)2 CruiseOnPilotSubCraft (net.countercraft.movecraft.craft.CruiseOnPilotSubCraft)2 PlayerCraftImpl (net.countercraft.movecraft.craft.PlayerCraftImpl)2 SubCraft (net.countercraft.movecraft.craft.SubCraft)2 CraftPilotEvent (net.countercraft.movecraft.events.CraftPilotEvent)2 Location (org.bukkit.Location)2 Sign (org.bukkit.block.Sign)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 File (java.io.File)1 HashSet (java.util.HashSet)1 OptionalInt (java.util.OptionalInt)1