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();
}
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);
}
}
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;
}
Aggregations