Search in sources :

Example 1 with FlagContainer

use of com.plotsquared.core.plot.flag.FlagContainer in project PlotSquared by IntellectualSites.

the class SQLManager method createFlags.

public void createFlags(Map<PlotId, Integer> ids, List<Plot> plots, Runnable whenDone) {
    try (final PreparedStatement preparedStatement = this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_flags`(`plot_id`, `flag`, `value`) VALUES(?, ?, ?)")) {
        for (final Plot plot : plots) {
            final FlagContainer flagContainer = plot.getFlagContainer();
            for (final PlotFlag<?, ?> flagEntry : flagContainer.getFlagMap().values()) {
                preparedStatement.setInt(1, ids.get(plot.getId()));
                preparedStatement.setString(2, flagEntry.getName());
                preparedStatement.setString(3, flagEntry.toString());
                preparedStatement.addBatch();
            }
            try {
                preparedStatement.executeBatch();
            } catch (final Exception e) {
                LOGGER.error("Failed to store flag values for plot with entry ID: {}", plot);
                e.printStackTrace();
                continue;
            }
            LOGGER.info("- Finished converting flag values for plot with entry ID: {}", plot.getId());
        }
    } catch (final Exception e) {
        LOGGER.error("Failed to store flag values", e);
    }
    LOGGER.info("Finished converting flags ({} plots processed)", plots.size());
    whenDone.run();
}
Also used : Plot(com.plotsquared.core.plot.Plot) FlagContainer(com.plotsquared.core.plot.flag.FlagContainer) GlobalFlagContainer(com.plotsquared.core.plot.flag.GlobalFlagContainer) PreparedStatement(java.sql.PreparedStatement) ParseException(java.text.ParseException) FlagParseException(com.plotsquared.core.plot.flag.FlagParseException) SQLException(java.sql.SQLException)

Example 2 with FlagContainer

use of com.plotsquared.core.plot.flag.FlagContainer in project PlotSquared by IntellectualSites.

the class Plot method mergeData.

/**
 * Merge the plot settings<br>
 * - Used when a plot is merged<br>
 *
 * @param plot plot to merge the data from
 */
public void mergeData(Plot plot) {
    final FlagContainer flagContainer1 = this.getFlagContainer();
    final FlagContainer flagContainer2 = plot.getFlagContainer();
    if (!flagContainer1.equals(flagContainer2)) {
        boolean greater = flagContainer1.getFlagMap().size() > flagContainer2.getFlagMap().size();
        if (greater) {
            flagContainer1.addAll(flagContainer2.getFlagMap().values());
        } else {
            flagContainer2.addAll(flagContainer1.getFlagMap().values());
        }
        if (!greater) {
            this.flagContainer.clearLocal();
            this.flagContainer.addAll(flagContainer2.getFlagMap().values());
        }
        plot.flagContainer.clearLocal();
        plot.flagContainer.addAll(this.flagContainer.getFlagMap().values());
    }
    if (!this.getAlias().isEmpty()) {
        plot.setAlias(this.getAlias());
    } else if (!plot.getAlias().isEmpty()) {
        this.setAlias(plot.getAlias());
    }
    for (UUID uuid : this.getTrusted()) {
        plot.addTrusted(uuid);
    }
    for (UUID uuid : plot.getTrusted()) {
        this.addTrusted(uuid);
    }
    for (UUID uuid : this.getMembers()) {
        plot.addMember(uuid);
    }
    for (UUID uuid : plot.getMembers()) {
        this.addMember(uuid);
    }
    for (UUID uuid : this.getDenied()) {
        plot.addDenied(uuid);
    }
    for (UUID uuid : plot.getDenied()) {
        this.addDenied(uuid);
    }
}
Also used : FlagContainer(com.plotsquared.core.plot.flag.FlagContainer) GlobalFlagContainer(com.plotsquared.core.plot.flag.GlobalFlagContainer) UUID(java.util.UUID)

Example 3 with FlagContainer

use of com.plotsquared.core.plot.flag.FlagContainer in project PlotSquared by IntellectualSites.

the class SinglePlotArea method adapt.

@SuppressWarnings("deprecation")
protected Plot adapt(Plot p) {
    if (p instanceof SinglePlot) {
        return p;
    }
    PlotSettings s = p.getSettings();
    final FlagContainer oldContainer = p.getFlagContainer();
    p = new SinglePlot(p.getId(), p.getOwnerAbs(), p.getTrusted(), p.getMembers(), p.getDenied(), s.getAlias(), s.getPosition(), null, this, s.getMerged(), p.getTimestamp(), p.temp);
    p.getFlagContainer().addAll(oldContainer);
    return p;
}
Also used : PlotSettings(com.plotsquared.core.plot.PlotSettings) FlagContainer(com.plotsquared.core.plot.flag.FlagContainer)

Aggregations

FlagContainer (com.plotsquared.core.plot.flag.FlagContainer)3 GlobalFlagContainer (com.plotsquared.core.plot.flag.GlobalFlagContainer)2 Plot (com.plotsquared.core.plot.Plot)1 PlotSettings (com.plotsquared.core.plot.PlotSettings)1 FlagParseException (com.plotsquared.core.plot.flag.FlagParseException)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 ParseException (java.text.ParseException)1 UUID (java.util.UUID)1