Search in sources :

Example 1 with PrismDrainEvent

use of me.botsko.prism.events.PrismDrainEvent in project Prism-Bukkit by prism.

the class DrainCommand method handle.

@Override
public void handle(CallInfo call) {
    String drainType = "";
    int radius = plugin.getConfig().getInt("prism.drain.default-radius");
    if (call.getArgs().length == 3) {
        if (call.getArg(1).equalsIgnoreCase("water") || call.getArg(1).equalsIgnoreCase("lava")) {
            drainType = call.getArg(1);
        } else {
            Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Invalid drain type. Must be lava, water, or left out."));
            return;
        }
        // Validate radius
        radius = validateRadius(call, call.getArg(2));
    } else if (call.getArgs().length == 2) {
        if (TypeUtils.isNumeric(call.getArg(1))) {
            radius = validateRadius(call, call.getArg(1));
        } else {
            if (call.getArg(1).equalsIgnoreCase("water") || call.getArg(1).equalsIgnoreCase("lava")) {
                drainType = call.getArg(1);
            } else {
                Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Invalid drain type. Must be lava, water, or left out."));
                return;
            }
        }
    }
    if (radius == 0) {
        return;
    }
    TextComponent.Builder builder = Component.text().append(Il8nHelper.formatMessage("command-drain-lookup", drainType, radius));
    String key = "command-drain-lookup-water";
    if (drainType.equals("lava")) {
        key = "command-drain-lookup-lava";
    }
    builder.append(Component.text(" ")).append(Il8nHelper.getMessage(key).color(NamedTextColor.GRAY));
    Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerHeaderMsg(builder.build()));
    ArrayList<BlockStateChange> blockStateChanges = null;
    if (drainType.isEmpty()) {
        blockStateChanges = Utilities.drain(call.getPlayer().getLocation(), radius);
    } else if (drainType.equals("water")) {
        blockStateChanges = Utilities.drainWater(call.getPlayer().getLocation(), radius);
    } else if (drainType.equals("lava")) {
        blockStateChanges = Utilities.drainLava(call.getPlayer().getLocation(), radius);
    }
    if (blockStateChanges != null && !blockStateChanges.isEmpty()) {
        // @todo remove the extra space in msg
        Component out = Prism.messenger.playerHeaderMsg(Il8nHelper.formatMessage("command-drain-lookup-result", blockStateChanges.size(), drainType)).append(Component.newline()).append(Prism.messenger.playerSubduedHeaderMsg(Il8nHelper.getMessage("command-drain-result-undo")));
        Prism.messenger.sendMessage(call.getSender(), out);
        // Trigger the event
        final PrismDrainEvent event = EventHelper.createDrainEvent(blockStateChanges, call.getPlayer(), radius);
        plugin.getServer().getPluginManager().callEvent(event);
    } else {
        Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("command-drain-result-empty")));
    }
}
Also used : TextComponent(net.kyori.adventure.text.TextComponent) BlockStateChange(me.botsko.prism.api.BlockStateChange) PrismDrainEvent(me.botsko.prism.events.PrismDrainEvent) TextComponent(net.kyori.adventure.text.TextComponent) Component(net.kyori.adventure.text.Component)

Aggregations

BlockStateChange (me.botsko.prism.api.BlockStateChange)1 PrismDrainEvent (me.botsko.prism.events.PrismDrainEvent)1 Component (net.kyori.adventure.text.Component)1 TextComponent (net.kyori.adventure.text.TextComponent)1