Removes Cluster Flags

Signed-off-by: matt <4009945+MattBDev@users.noreply.github.com>
This commit is contained in:
matt 2019-02-04 12:46:27 -05:00
parent cf82bc5efb
commit dfbcecb081
9 changed files with 0 additions and 187 deletions

View File

@ -1,63 +0,0 @@
package com.github.intellectualsites.plotsquared.bukkit.events;
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.object.PlotCluster;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Called when a flag is removed from a plot.
*/
public class ClusterFlagRemoveEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final PlotCluster cluster;
private final Flag flag;
private boolean cancelled;
/**
* PlotFlagRemoveEvent: Called when a flag is removed from a plot.
*
* @param flag Flag that was removed
* @param cluster PlotCluster from which the flag was removed
*/
public ClusterFlagRemoveEvent(Flag flag, PlotCluster cluster) {
this.cluster = cluster;
this.flag = flag;
}
public static HandlerList getHandlerList() {
return handlers;
}
/**
* Get the cluster involved.
*
* @return PlotCluster
*/
public PlotCluster getCluster() {
return this.cluster;
}
/**
* Get the flag involved.
*
* @return Flag
*/
public Flag getFlag() {
return this.flag;
}
@Override public HandlerList getHandlers() {
return handlers;
}
@Override public boolean isCancelled() {
return this.cancelled;
}
@Override public void setCancelled(boolean b) {
this.cancelled = b;
}
}

View File

@ -101,10 +101,6 @@ public final class BukkitEventUtil extends EventUtil {
new PlotChangeOwnerEvent(getPlayer(initiator), plot, oldOwner, newOwner, hasOldOwner)); new PlotChangeOwnerEvent(getPlayer(initiator), plot, oldOwner, newOwner, hasOldOwner));
} }
@Override public boolean callFlagRemove(Flag flag, Object object, PlotCluster cluster) {
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
}
@Override @Nullable public Rating callRating(PlotPlayer player, Plot plot, Rating rating) { @Override @Nullable public Rating callRating(PlotPlayer player, Plot plot, Rating rating) {
PlotRateEvent event = new PlotRateEvent(player, rating, plot); PlotRateEvent event = new PlotRateEvent(player, rating, plot);
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);

View File

@ -143,14 +143,6 @@ public interface AbstractDB {
*/ */
void setFlags(Plot plot, HashMap<Flag<?>, Object> flags); void setFlags(Plot plot, HashMap<Flag<?>, Object> flags);
/**
* Set cluster flags.
*
* @param cluster PlotCluster Object
* @param flags flags to set (flag[])
*/
void setFlags(PlotCluster cluster, HashMap<Flag<?>, Object> flags);
/** /**
* Rename a cluster to the given name. * Rename a cluster to the given name.
* *

View File

@ -298,13 +298,6 @@ public class DBFunc {
DBFunc.dbManager.setFlags(plot, flags); DBFunc.dbManager.setFlags(plot, flags);
} }
public static void setFlags(PlotCluster cluster, HashMap<Flag<?>, Object> flags) {
if (dbManager == null) {
return;
}
DBFunc.dbManager.setFlags(cluster, flags);
}
/** /**
* @param plot * @param plot
* @param alias * @param alias

View File

@ -2666,41 +2666,6 @@ import java.util.concurrent.atomic.AtomicInteger;
merged[3 - i] = (m & 1 << i) != 0; merged[3 - i] = (m & 1 << i) != 0;
} }
cluster.settings.setMerged(merged); cluster.settings.setMerged(merged);
String[] flags_string;
String myflags = resultSet.getString("flags");
if (myflags == null || myflags.isEmpty()) {
flags_string = new String[] {};
} else {
flags_string = myflags.split(",");
}
HashMap<Flag<?>, Object> flags = new HashMap<>();
for (String element : flags_string) {
if (element.contains(":")) {
String[] split = element.split(":");
String flag_str =
split[1].replaceAll("\u00AF", ":").replaceAll("´", ",");
Flag flag = FlagManager.getOrCreateFlag(split[0]);
if (flag == null) {
flag = new StringFlag(split[0]) {
@Override public String getValueDescription() {
return "Generic Filler Flag";
}
};
}
flags.put(flag, flag.parseValue(flag_str));
} else {
Flag flag = FlagManager.getOrCreateFlag(element);
if (flag == null) {
flag = new StringFlag(element) {
@Override public String getValueDescription() {
return "Generic Filler Flag";
}
};
}
flags.put(flag, flag.parseValue(""));
}
}
cluster.settings.flags = flags;
} else { } else {
PlotSquared.debug("&cCluster #" + id + "(" + cluster PlotSquared.debug("&cCluster #" + id + "(" + cluster
+ ") in cluster_settings does not exist. Please create the cluster or remove this entry."); + ") in cluster_settings does not exist. Please create the cluster or remove this entry.");
@ -2726,32 +2691,6 @@ import java.util.concurrent.atomic.AtomicInteger;
return newClusters; return newClusters;
} }
@Override public void setFlags(final PlotCluster cluster, HashMap<Flag<?>, Object> flags) {
final StringBuilder flag_string = new StringBuilder();
int i = 0;
for (Entry<Flag<?>, Object> flag : flags.entrySet()) {
if (i != 0) {
flag_string.append(',');
}
flag_string.append(flag.getKey().getName()).append(':').append(
flag.getKey().valueToString(flag.getValue()).replaceAll(":", "\u00AF")
.replaceAll(",", "´"));
i++;
}
addClusterTask(cluster, new UniqueStatement("setFlags") {
@Override public void set(PreparedStatement stmt) throws SQLException {
stmt.setString(1, flag_string.toString());
stmt.setInt(2, getClusterId(cluster));
}
@Override public PreparedStatement get() throws SQLException {
return SQLManager.this.connection.prepareStatement(
"UPDATE `" + SQLManager.this.prefix
+ "cluster_settings` SET `flags` = ? WHERE `cluster_id` = ?");
}
});
}
@Override public void setClusterName(final PlotCluster cluster, final String name) { @Override public void setClusterName(final PlotCluster cluster, final String name) {
addClusterTask(cluster, new UniqueStatement("setClusterName") { addClusterTask(cluster, new UniqueStatement("setClusterName") {
@Override public void set(PreparedStatement stmt) throws SQLException { @Override public void set(PreparedStatement stmt) throws SQLException {

View File

@ -141,13 +141,6 @@ public class FlagManager {
return true; return true;
} }
public static <V> boolean addClusterFlag(PlotCluster cluster, Flag<V> flag, V value) {
getSettingFlag(cluster.area, cluster.settings, flag);
cluster.settings.flags.put(flag, value);
DBFunc.setFlags(cluster, cluster.settings.flags);
return true;
}
/** /**
* Returns a map of the {@link Flag}s and their values for the specified plot. * Returns a map of the {@link Flag}s and their values for the specified plot.
* *
@ -217,20 +210,6 @@ public class FlagManager {
return true; return true;
} }
public static boolean removeClusterFlag(PlotCluster cluster, Flag id) {
Object object = cluster.settings.flags.remove(id);
if (object == null) {
return false;
}
boolean result = EventUtil.manager.callFlagRemove(id, object, cluster);
if (!result) {
cluster.settings.flags.put(id, object);
return false;
}
DBFunc.setFlags(cluster, cluster.settings.flags);
return true;
}
public static void setPlotFlags(Plot origin, HashMap<Flag<?>, Object> flags) { public static void setPlotFlags(Plot origin, HashMap<Flag<?>, Object> flags) {
for (Plot plot : origin.getConnectedPlots()) { for (Plot plot : origin.getConnectedPlots()) {
if (flags != null && !flags.isEmpty()) { if (flags != null && !flags.isEmpty()) {
@ -248,20 +227,6 @@ public class FlagManager {
} }
} }
public static void setClusterFlags(PlotCluster cluster, Set<Flag> flags) {
if (flags != null && !flags.isEmpty()) {
cluster.settings.flags.clear();
for (Flag flag : flags) {
cluster.settings.flags.put(flag, flag);
}
} else if (cluster.settings.flags.isEmpty()) {
return;
} else {
cluster.settings.flags.clear();
}
DBFunc.setFlags(cluster, cluster.settings.flags);
}
/** /**
* Get a list of registered {@link Flag} objects based on player permissions. * Get a list of registered {@link Flag} objects based on player permissions.
* *

View File

@ -43,8 +43,6 @@ public abstract class EventUtil {
public abstract boolean callFlagRemove(Flag<?> flag, Plot plot, Object value); public abstract boolean callFlagRemove(Flag<?> flag, Plot plot, Object value);
public abstract boolean callFlagRemove(Flag<?> flag, Object value, PlotCluster cluster);
public abstract boolean callMerge(Plot plot, int dir, int max); public abstract boolean callMerge(Plot plot, int dir, int max);
public abstract boolean callAutoMerge(Plot plot, List<PlotId> plots); public abstract boolean callAutoMerge(Plot plot, List<PlotId> plots);

View File

@ -84,9 +84,6 @@ public class AbstractDBTest implements AbstractDB {
@Override public void setFlags(Plot plot, HashMap<Flag<?>, Object> flags) { @Override public void setFlags(Plot plot, HashMap<Flag<?>, Object> flags) {
} }
@Override public void setFlags(PlotCluster cluster, HashMap<Flag<?>, Object> flags) {
}
@Override public void setClusterName(PlotCluster cluster, String name) { @Override public void setClusterName(PlotCluster cluster, String name) {
} }

View File

@ -40,10 +40,6 @@ public class EventUtilTest extends EventUtil {
return true; return true;
} }
@Override public boolean callFlagRemove(Flag<?> flag, Object value, PlotCluster cluster) {
return true;
}
@Override public boolean callMerge(Plot plot, int dir, int max) { @Override public boolean callMerge(Plot plot, int dir, int max) {
return false; return false;
} }