Search in sources :

Example 6 with Handler

use of me.botsko.prism.api.actions.Handler in project Prism-Bukkit by prism.

the class ActionFactory method createEntity.

/**
 * Entity Handler.
 *
 * @param actionType type
 * @param entity     entity
 * @param nonPlayer  nonPlayer
 * @param dyeUsed    string
 * @return Handler
 */
@SuppressWarnings("WeakerAccess")
public static Handler createEntity(String actionType, Entity entity, String nonPlayer, String dyeUsed) {
    final Handler a = createEntity(actionType, entity, (OfflinePlayer) null, dyeUsed);
    a.setSourceName(nonPlayer);
    return a;
}
Also used : Handler(me.botsko.prism.api.actions.Handler)

Example 7 with Handler

use of me.botsko.prism.api.actions.Handler in project Prism-Bukkit by prism.

the class ActionFactory method createVehicle.

/**
 * Create a vehicle.
 *
 * @param actionType type
 * @param vehicle    vehicle
 * @param nonPlayer  nonplayer
 * @return Handler
 */
public static Handler createVehicle(String actionType, Vehicle vehicle, String nonPlayer) {
    final Handler a = createVehicle(actionType, vehicle, (OfflinePlayer) null);
    a.setSourceName(nonPlayer);
    return a;
}
Also used : Handler(me.botsko.prism.api.actions.Handler)

Example 8 with Handler

use of me.botsko.prism.api.actions.Handler in project Prism-Bukkit by prism.

the class PrismInventoryEvents method onItemBreak.

/**
 * Tracks item breakage. Cant be rolled back.  At this point the item damage is not 0 however it will be set 0 after
 * event completes - Reported item durability will be the durability before the event.
 * @param event PlayerItemBreakEvent.
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onItemBreak(PlayerItemBreakEvent event) {
    if (!trackingBreaks) {
        return;
    }
    ItemStack item = event.getBrokenItem();
    Handler h = ActionFactory.createItemStack(BREAK, item, null, event.getPlayer().getLocation(), event.getPlayer());
    RecordingQueue.addToQueue(h);
}
Also used : EventHandler(org.bukkit.event.EventHandler) Handler(me.botsko.prism.api.actions.Handler) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 9 with Handler

use of me.botsko.prism.api.actions.Handler in project Prism-Bukkit by prism.

the class PrismPlayerEvents method onPlayerBucketFill.

/**
 * PlayerBucketFillEvent.
 *
 * @param event PlayerBucketFillEvent
 */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerBucketFill(final PlayerBucketFillEvent event) {
    final Player player = event.getPlayer();
    if (!Prism.getIgnore().event("bucket-fill", player)) {
        return;
    }
    final Block spot = event.getBlock();
    String liquidType = "milk";
    if (spot.getType() == Material.WATER) {
        liquidType = "water";
    } else if (spot.getBlockData() instanceof Waterlogged && ((Waterlogged) spot.getBlockData()).isWaterlogged()) {
        liquidType = "water";
    } else if (spot.getType() == Material.LAVA) {
        liquidType = "lava";
    }
    final Handler pa = ActionFactory.createPlayer("bucket-fill", player, liquidType);
    // Override the location with the area taken
    pa.setX(spot.getX());
    pa.setY(spot.getY());
    pa.setZ(spot.getZ());
    RecordingQueue.addToQueue(pa);
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler) Handler(me.botsko.prism.api.actions.Handler) Waterlogged(org.bukkit.block.data.Waterlogged) EventHandler(org.bukkit.event.EventHandler)

Example 10 with Handler

use of me.botsko.prism.api.actions.Handler in project Prism-Bukkit by prism.

the class LookupCommand method handle.

/**
 * Handle the command.
 */
@Override
public void handle(final CallInfo call) {
    // Process and validate all of the arguments
    final QueryParameters parameters = PreprocessArgs.process(plugin, call.getSender(), call.getArgs(), PrismProcessType.LOOKUP, 1, !plugin.getConfig().getBoolean("prism.queries.never-use-defaults"));
    if (parameters == null) {
        return;
    }
    // Run the lookup itself in an async task so the lookup query isn't done on the main thread
    plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
        // determine if defaults were used
        final List<String> defaultsUsed = parameters.getDefaultsUsed();
        StringBuilder defaultsReminder = new StringBuilder();
        if (!defaultsUsed.isEmpty()) {
            defaultsReminder.append(Il8nHelper.getRawMessage("queryparameter.defaults.prefix"));
            for (final String d : defaultsUsed) {
                defaultsReminder.append(" ").append(d);
            }
        }
        final ActionsQuery aq = new ActionsQuery(plugin);
        final QueryResult results = aq.lookup(parameters, call.getSender());
        final StringBuilder sharingWithPlayers = new StringBuilder();
        for (final CommandSender shareWith : parameters.getSharedPlayers()) {
            sharingWithPlayers.append(shareWith.getName()).append(", ");
        }
        if (sharingWithPlayers.length() > 0) {
            sharingWithPlayers.delete(sharingWithPlayers.lastIndexOf(","), sharingWithPlayers.length());
        }
        final String playersList = sharingWithPlayers.toString();
        // Add current sender
        parameters.addSharedPlayer(call.getSender());
        for (final CommandSender player : parameters.getSharedPlayers()) {
            final boolean isSender = player.getName().equals(call.getSender().getName());
            if (!isSender) {
                Prism.messenger.sendMessage(player, Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("lookup-share-message").color(NamedTextColor.GOLD).replaceText(Pattern.compile("<sender>"), builder -> Component.text().content(call.getSender().getName()).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, TextDecoration.State.TRUE), 1)));
            } else if (sharingWithPlayers.length() > 0) {
                Component component = Il8nHelper.getMessage("lookup-share-to-message").color(NamedTextColor.GOLD).replaceText(Pattern.compile("<players>"), builder -> Component.text().content(playersList).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, TextDecoration.State.TRUE), 1);
                Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerHeaderMsg(component));
            }
            if (!results.getActionResults().isEmpty()) {
                Prism.messenger.sendMessage(player, Prism.messenger.playerHeaderMsg(Il8nHelper.formatMessage("lookup-header-message", results.getTotalResults(), 1, results.getTotalPages())));
                if ((defaultsReminder.length() > 0) && isSender) {
                    Prism.messenger.sendMessage(player, Prism.messenger.playerSubduedHeaderMsg(Component.text(defaultsReminder.toString())));
                }
                final List<Handler> paginated = results.getPaginatedActionResults();
                if (paginated != null) {
                    int resultCount = results.getIndexOfFirstResult();
                    for (final Handler a : paginated) {
                        final ActionMessage am = new ActionMessage(a);
                        if (parameters.hasFlag(Flag.EXTENDED) || plugin.getConfig().getBoolean("prism.messenger.always-show-extended")) {
                            am.showExtended();
                        }
                        am.setResultIndex(resultCount);
                        MiscUtils.sendClickableTpRecord(am, player);
                        resultCount++;
                    }
                    MiscUtils.sendPageButtons(results, player);
                } else {
                    Prism.messenger.sendMessage(player, Prism.messenger.playerError(Il8nHelper.getMessage("no-pagination-found")));
                }
                if (parameters.hasFlag(Flag.PASTE)) {
                    StringBuilder paste = new StringBuilder();
                    for (final Handler a : results.getActionResults()) {
                        paste.append(new ActionMessage(a).getRawMessage()).append("\r\n");
                    }
                    MiscUtils.paste_results(player, paste.toString());
                }
            } else {
                if (defaultsReminder.length() > 0) {
                    if (isSender) {
                        Prism.messenger.sendMessage(player, Prism.messenger.playerSubduedHeaderMsg(Component.text(defaultsReminder.toString())));
                    }
                }
                if (isSender) {
                    Prism.messenger.sendMessage(player, Prism.messenger.playerError("Nothing found." + ChatColor.GRAY + " Either you're missing something, or we are."));
                }
            }
        }
        // Flush timed data
        plugin.eventTimer.printTimeRecord();
    });
}
Also used : Prism(me.botsko.prism.Prism) CommandSender(org.bukkit.command.CommandSender) CallInfo(me.botsko.prism.commandlibs.CallInfo) PreprocessArgs(me.botsko.prism.commandlibs.PreprocessArgs) TextDecoration(net.kyori.adventure.text.format.TextDecoration) Handler(me.botsko.prism.api.actions.Handler) QueryResult(me.botsko.prism.actionlibs.QueryResult) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) ActionsQuery(me.botsko.prism.actionlibs.ActionsQuery) List(java.util.List) SubHandler(me.botsko.prism.commandlibs.SubHandler) Flag(me.botsko.prism.api.commands.Flag) MiscUtils(me.botsko.prism.utils.MiscUtils) Component(net.kyori.adventure.text.Component) Il8nHelper(me.botsko.prism.Il8nHelper) PrismProcessType(me.botsko.prism.api.actions.PrismProcessType) ChatColor(org.bukkit.ChatColor) Pattern(java.util.regex.Pattern) QueryParameters(me.botsko.prism.actionlibs.QueryParameters) ActionMessage(me.botsko.prism.actionlibs.ActionMessage) Handler(me.botsko.prism.api.actions.Handler) SubHandler(me.botsko.prism.commandlibs.SubHandler) QueryParameters(me.botsko.prism.actionlibs.QueryParameters) QueryResult(me.botsko.prism.actionlibs.QueryResult) ActionsQuery(me.botsko.prism.actionlibs.ActionsQuery) ActionMessage(me.botsko.prism.actionlibs.ActionMessage) CommandSender(org.bukkit.command.CommandSender) Component(net.kyori.adventure.text.Component)

Aggregations

Handler (me.botsko.prism.api.actions.Handler)20 QueryResult (me.botsko.prism.actionlibs.QueryResult)6 SubHandler (me.botsko.prism.commandlibs.SubHandler)5 ActionMessage (me.botsko.prism.actionlibs.ActionMessage)4 ActionsQuery (me.botsko.prism.actionlibs.ActionsQuery)4 QueryParameters (me.botsko.prism.actionlibs.QueryParameters)4 EventHandler (org.bukkit.event.EventHandler)4 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 Player (org.bukkit.entity.Player)3 PreparedStatement (java.sql.PreparedStatement)2 BlockStateChange (me.botsko.prism.api.BlockStateChange)2 BlockState (org.bukkit.block.BlockState)2 ItemStack (org.bukkit.inventory.ItemStack)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Pattern (java.util.regex.Pattern)1