Search in sources :

Example 1 with PrismProcessAction

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

the class ActionsQuery method getPrismProcessRecord.

/**
     * 
     * @param id
     */
public PrismProcessAction getPrismProcessRecord(int id) {
    String prefix = plugin.getConfig().getString("prism.mysql.prefix");
    PrismProcessAction process = null;
    Connection conn = null;
    PreparedStatement s = null;
    ResultSet rs = null;
    try {
        String sql = "SELECT id, action, epoch, world, player, x, y, z, data FROM " + prefix + "data d";
        // Joins
        sql += " INNER JOIN " + prefix + "players p ON p.player_id = d.player_id ";
        sql += " INNER JOIN " + prefix + "actions a ON a.action_id = d.action_id ";
        sql += " INNER JOIN " + prefix + "worlds w ON w.world_id = d.world_id ";
        sql += " LEFT JOIN " + prefix + "data_extra ex ON ex.data_id = d.id ";
        sql += " WHERE d.id = ?";
        conn = Prism.dbc();
        if (conn != null && !conn.isClosed()) {
            s = conn.prepareStatement(sql);
            s.setInt(1, id);
            s.executeQuery();
            rs = s.getResultSet();
            if (rs.first()) {
                process = new PrismProcessAction();
                // Set all shared values
                process.setId(rs.getInt("id"));
                process.setType(Prism.getActionRegistry().getAction(rs.getString("action")));
                process.setUnixEpoch(rs.getString("epoch"));
                process.setWorldName(rs.getString("world"));
                process.setPlayerName(rs.getString("player"));
                process.setX(rs.getInt("x"));
                process.setY(rs.getInt("y"));
                process.setZ(rs.getInt("z"));
                process.setData(rs.getString("data"));
            }
        } else {
            Prism.log("Prism database error. getPrismProcessRecord cannot continue.");
        }
    } catch (final SQLException e) {
        plugin.handleDatabaseException(e);
    } finally {
        if (rs != null)
            try {
                rs.close();
            } catch (final SQLException ignored) {
            }
        if (s != null)
            try {
                s.close();
            } catch (final SQLException ignored) {
            }
        if (conn != null)
            try {
                conn.close();
            } catch (final SQLException ignored) {
            }
    }
    return process;
}
Also used : PrismProcessAction(me.botsko.prism.actions.PrismProcessAction) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 2 with PrismProcessAction

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

the class ActionFactory method create.

@Deprecated
public static Handler create(String action_type, PrismProcessType processType, Player player, String parameters) {
    final PrismProcessAction a = new PrismProcessAction();
    a.setActionType(action_type);
    a.setPlayerName(player);
    a.setLoc(player.getLocation());
    a.setProcessData(processType, parameters);
    return a;
}
Also used : PrismProcessAction(me.botsko.prism.actions.PrismProcessAction)

Example 3 with PrismProcessAction

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

the class ActionFactory method createPrismProcess.

/**
 * PrismProcessActionData.
 *
 * @param actionType  type
 * @param processType process
 * @param player      player
 * @param parameters  parameters
 * @return Handler
 */
public static Handler createPrismProcess(String actionType, PrismProcessType processType, Player player, String parameters) {
    final PrismProcessAction a = new PrismProcessAction();
    a.setActionType(actionType);
    a.setPlayer(player);
    a.setLoc(player.getLocation());
    a.setProcessData(processType, parameters);
    return a;
}
Also used : PrismProcessAction(me.botsko.prism.actions.PrismProcessAction)

Example 4 with PrismProcessAction

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

the class UndoCommand method handle.

@Override
public void handle(CallInfo call) {
    final Audience audience = Prism.getAudiences().player(call.getPlayer());
    if (call.getArgs().length > 1) {
        final ActionsQuery aq = new ActionsQuery(plugin);
        long recordId = 0;
        if (TypeUtils.isNumeric(call.getArg(1))) {
            recordId = Long.parseLong(call.getArg(1));
            if (recordId <= 0) {
                Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Record ID must be greater than zero."));
                return;
            }
        } else {
            if (call.getArg(1).equals("last")) {
                recordId = aq.getUsersLastPrismProcessId(call.getPlayer().getName());
            }
        }
        // Invalid id
        if (recordId == 0) {
            Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Either you have no last process or an invalid ID."));
            return;
        }
        final PrismProcessAction process = aq.getPrismProcessRecord(recordId);
        if (process == null) {
            Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("A process does not exists with that value."));
            return;
        }
        // We only support this for drains
        if (!process.getProcessChildActionType().equals("prism-drain")) {
            Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("You can't currently undo anything other than a drain process."));
            return;
        }
        // Pull the actual block change data for this undo event
        final QueryParameters parameters = new QueryParameters();
        parameters.setWorld(call.getPlayer().getWorld().getName());
        parameters.addActionType(process.getProcessChildActionType());
        parameters.addPlayerName(call.getPlayer().getName());
        parameters.setParentId(recordId);
        parameters.setProcessType(PrismProcessType.UNDO);
        // make sure the distance isn't too far away
        final QueryResult results = aq.lookup(parameters, call.getPlayer());
        if (!results.getActionResults().isEmpty()) {
            Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("command-undo-complete")));
            final Previewable rb = new Undo(plugin, call.getPlayer(), results.getActionResults(), parameters, new PrismApplierCallback());
            rb.apply();
        } else {
            Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Nothing found to undo. Must be a problem with Prism."));
        }
    } else {
        // Show the list
        // Process and validate all of the arguments
        final QueryParameters parameters = new QueryParameters();
        parameters.setAllowNoRadius(true);
        parameters.addActionType("prism-process");
        parameters.addPlayerName(call.getPlayer().getName());
        // @todo config this, and move the logic
        parameters.setLimit(5);
        // to queryparams
        final ActionsQuery aq = new ActionsQuery(plugin);
        final QueryResult results = aq.lookup(parameters, call.getPlayer());
        if (!results.getActionResults().isEmpty()) {
            Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerHeaderMsg(Il8nHelper.formatMessage("lookup-header-message", results.getTotalResults(), 1, results.getTotalPages())));
            Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerSubduedHeaderMsg(Il8nHelper.getMessage("command-undo-help")));
            final List<Handler> paginated = results.getPaginatedActionResults();
            if (paginated != null) {
                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();
                    }
                    Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerMsg(am.getMessage()));
                }
            } else {
                Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Pagination can't find anything. Do you have the right page number?"));
            }
        } else {
            Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Nothing found." + ChatColor.GRAY + " Either you're missing something, or we are."));
        }
    }
}
Also used : PrismProcessAction(me.botsko.prism.actions.PrismProcessAction) QueryResult(me.botsko.prism.actionlibs.QueryResult) PrismApplierCallback(me.botsko.prism.appliers.PrismApplierCallback) Audience(net.kyori.adventure.audience.Audience) ActionsQuery(me.botsko.prism.actionlibs.ActionsQuery) ActionMessage(me.botsko.prism.actionlibs.ActionMessage) Handler(me.botsko.prism.api.actions.Handler) SubHandler(me.botsko.prism.commandlibs.SubHandler) Previewable(me.botsko.prism.appliers.Previewable) QueryParameters(me.botsko.prism.actionlibs.QueryParameters) Undo(me.botsko.prism.appliers.Undo)

Example 5 with PrismProcessAction

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

the class SqlSelectProcessQuery method executeProcessQuery.

@Override
public PrismProcessAction executeProcessQuery() {
    if (getLastID) {
        return null;
    }
    final String query = getQuery(parameters, false);
    PrismProcessAction process = null;
    try (Connection conn = dataSource.getDataSource().getConnection();
        PreparedStatement s = conn.prepareStatement(query);
        ResultSet rs = s.executeQuery()) {
        if (rs.next()) {
            process = new PrismProcessAction();
            // Set all shared values
            process.setId(rs.getLong("id"));
            process.setActionType(rs.getString("action"));
            process.setUnixEpoch(rs.getLong("epoch"));
            process.setWorld(Bukkit.getWorld(rs.getString("world")));
            process.setSourceName(rs.getString("player"));
            process.setUuid(SqlPlayerIdentificationHelper.uuidFromDbString(rs.getString("HEX(player_uuid)")));
            process.setX(rs.getInt("x"));
            process.setY(rs.getInt("y"));
            process.setZ(rs.getInt("z"));
            process.deserialize(rs.getString("data"));
        }
    } catch (SQLException e) {
        dataSource.handleDataSourceException(e);
    }
    return process;
}
Also used : PrismProcessAction(me.botsko.prism.actions.PrismProcessAction) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

PrismProcessAction (me.botsko.prism.actions.PrismProcessAction)5 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ActionMessage (me.botsko.prism.actionlibs.ActionMessage)1 ActionsQuery (me.botsko.prism.actionlibs.ActionsQuery)1 QueryParameters (me.botsko.prism.actionlibs.QueryParameters)1 QueryResult (me.botsko.prism.actionlibs.QueryResult)1 Handler (me.botsko.prism.api.actions.Handler)1 Previewable (me.botsko.prism.appliers.Previewable)1 PrismApplierCallback (me.botsko.prism.appliers.PrismApplierCallback)1 Undo (me.botsko.prism.appliers.Undo)1 SubHandler (me.botsko.prism.commandlibs.SubHandler)1 Audience (net.kyori.adventure.audience.Audience)1