flag fixes.

This commit is contained in:
boy0001 2014-10-25 11:16:15 +11:00
parent 90d327d80c
commit 1a9f10951d
3 changed files with 59 additions and 7 deletions

View File

@ -22,6 +22,7 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
@ -431,21 +432,28 @@ public class SQLManager extends AbstractDB {
else { else {
flags_string = ((String) settings.get("flags")).split(","); flags_string = ((String) settings.get("flags")).split(",");
} }
Flag[] flags = new Flag[flags_string.length]; ArrayList<Flag> flags = new ArrayList<Flag>();
for (int i = 0; i < flags.length; i++) { boolean exception = false;
for (int i = 0; i < flags_string.length; i++) {
if (flags_string[i].contains(":")) { if (flags_string[i].contains(":")) {
String[] split = flags_string[i].split(":"); String[] split = flags_string[i].split(":");
try { 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) { catch (Exception e) {
exception = true;
// invalid flag... ignoring it for now. // invalid flag... ignoring it for now.
} }
} }
else { 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> helpers = plotHelpers(id);
ArrayList<UUID> trusted = plotTrusted(id); ArrayList<UUID> trusted = plotTrusted(id);
ArrayList<UUID> denied = plotDenied(id); ArrayList<UUID> denied = plotDenied(id);
@ -473,8 +481,7 @@ public class SQLManager extends AbstractDB {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
merged[3 - i] = (merged_int & (1 << i)) != 0; merged[3 - i] = (merged_int & (1 << i)) != 0;
} }
p = p = new Plot(plot_id, owner, plotBiome, helpers, trusted, denied, alias, position, flags.toArray(new Flag[0]), worldname, merged);
new Plot(plot_id, owner, plotBiome, helpers, trusted, denied, alias, position, flags, worldname, merged);
if (plots.containsKey(worldname)) { if (plots.containsKey(worldname)) {
plots.get(worldname).put((plot_id), p); plots.get(worldname).put((plot_id), p);
} }
@ -562,6 +569,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 * @param plot
* @param alias * @param alias

View File

@ -3,9 +3,12 @@ package com.intellectualcrafters.plot.listeners;
import com.intellectualcrafters.plot.*; import com.intellectualcrafters.plot.*;
import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent; import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent;
import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -46,6 +49,21 @@ public class PlotListener {
return UUIDHandler.getUUID(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) { public static boolean enteredPlot(Location l1, Location l2) {
PlotId p1 = PlayerFunctions.getPlot(new Location(l1.getWorld(), l1.getBlockX(), 64, l1.getBlockZ())); PlotId p1 = PlayerFunctions.getPlot(new Location(l1.getWorld(), l1.getBlockX(), 64, l1.getBlockZ()));
PlotId p2 = PlayerFunctions.getPlot(new Location(l2.getWorld(), l2.getBlockX(), 64, l2.getBlockZ())); PlotId p2 = PlayerFunctions.getPlot(new Location(l2.getWorld(), l2.getBlockX(), 64, l2.getBlockZ()));