mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
flag fixes.
This commit is contained in:
parent
90d327d80c
commit
1a9f10951d
@ -65,7 +65,7 @@ public class Plot implements Cloneable {
|
||||
* Has the plot changed since the last save cycle?
|
||||
*/
|
||||
public boolean hasChanged = false;
|
||||
public boolean countsTowardsMax = true;
|
||||
public boolean countsTowardsMax = true ;
|
||||
|
||||
/**
|
||||
* Primary constructor
|
||||
|
@ -22,6 +22,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.Biome;
|
||||
@ -431,21 +432,28 @@ public class SQLManager extends AbstractDB {
|
||||
else {
|
||||
flags_string = ((String) settings.get("flags")).split(",");
|
||||
}
|
||||
Flag[] flags = new Flag[flags_string.length];
|
||||
for (int i = 0; i < flags.length; i++) {
|
||||
ArrayList<Flag> flags = new ArrayList<Flag>();
|
||||
boolean exception = false;
|
||||
for (int i = 0; i < flags_string.length; i++) {
|
||||
if (flags_string[i].contains(":")) {
|
||||
String[] split = flags_string[i].split(":");
|
||||
try {
|
||||
flags[i] = new Flag(FlagManager.getFlag(split[0], true), split[1]);
|
||||
flags.add(new Flag(FlagManager.getFlag(split[0], true), split[1]));
|
||||
}
|
||||
catch (Exception e) {
|
||||
exception = true;
|
||||
// invalid flag... ignoring it for now.
|
||||
}
|
||||
}
|
||||
else {
|
||||
flags[i] = new Flag(FlagManager.getFlag(flags_string[i], true), "");
|
||||
flags.add(new Flag(FlagManager.getFlag(flags_string[i], true), ""));
|
||||
}
|
||||
}
|
||||
|
||||
if (exception) {
|
||||
setFlags(worldname, id, flags.toArray(new Flag[0]));
|
||||
}
|
||||
|
||||
ArrayList<UUID> helpers = plotHelpers(id);
|
||||
ArrayList<UUID> trusted = plotTrusted(id);
|
||||
ArrayList<UUID> denied = plotDenied(id);
|
||||
@ -473,8 +481,7 @@ public class SQLManager extends AbstractDB {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
merged[3 - i] = (merged_int & (1 << i)) != 0;
|
||||
}
|
||||
p =
|
||||
new Plot(plot_id, owner, plotBiome, helpers, trusted, denied, alias, position, flags, worldname, merged);
|
||||
p = new Plot(plot_id, owner, plotBiome, helpers, trusted, denied, alias, position, flags.toArray(new Flag[0]), worldname, merged);
|
||||
if (plots.containsKey(worldname)) {
|
||||
plots.get(worldname).put((plot_id), p);
|
||||
}
|
||||
@ -561,6 +568,33 @@ public class SQLManager extends AbstractDB {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setFlags(final String world, final int id, final Flag[] flags) {
|
||||
ArrayList<Flag> newflags = new ArrayList<Flag>();
|
||||
for (Flag flag : flags) {
|
||||
if (flag!=null && flag.getKey()!=null && !flag.getKey().equals("")) {
|
||||
newflags.add(flag);
|
||||
}
|
||||
}
|
||||
final String flag_string = StringUtils.join(newflags,",");
|
||||
runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
PreparedStatement stmt =
|
||||
connection.prepareStatement("UPDATE `plot_settings` SET `flags` = ? WHERE `plot_plot_id` = ?");
|
||||
stmt.setString(1, flag_string);
|
||||
stmt.setInt(2, id);
|
||||
stmt.execute();
|
||||
stmt.close();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.add(LogLevel.WARNING, "Could not set flag for plot " + id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
|
@ -3,9 +3,12 @@ package com.intellectualcrafters.plot.listeners;
|
||||
import com.intellectualcrafters.plot.*;
|
||||
import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent;
|
||||
import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -45,6 +48,21 @@ public class PlotListener {
|
||||
public static UUID getUUID(String name) {
|
||||
return UUIDHandler.getUUID(name);
|
||||
}
|
||||
|
||||
// unused
|
||||
public static void blockChange(Block block, Cancellable event) {
|
||||
Location loc = block.getLocation();
|
||||
String world = loc.getWorld().getName();
|
||||
PlotManager manager = PlotMain.getPlotManager(world);
|
||||
if (manager!=null) {
|
||||
PlotWorld plotworld = PlotMain.getWorldSettings(world);
|
||||
PlotId id = manager.getPlotId(plotworld, loc);
|
||||
if (id==null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public static boolean enteredPlot(Location l1, Location l2) {
|
||||
PlotId p1 = PlayerFunctions.getPlot(new Location(l1.getWorld(), l1.getBlockX(), 64, l1.getBlockZ()));
|
||||
|
Loading…
Reference in New Issue
Block a user