Apparently we need to recover from bad flags

This commit is contained in:
dordsor21 2020-04-30 12:15:42 +01:00
parent cbe46539ca
commit a263fe2f2d
2 changed files with 21 additions and 12 deletions

View File

@ -25,7 +25,9 @@
*/ */
package com.plotsquared.core.plot.flag; package com.plotsquared.core.plot.flag;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.plotsquared.core.PlotSquared;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Setter; import lombok.Setter;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -128,17 +130,26 @@ public class FlagContainer {
* @see #addAll(Collection) to add multiple flags * @see #addAll(Collection) to add multiple flags
*/ */
public <V, T extends PlotFlag<V, ?>> void addFlag(final T flag) { public <V, T extends PlotFlag<V, ?>> void addFlag(final T flag) {
final PlotFlag<?, ?> oldInstance = this.flagMap.put(flag.getClass(), flag); try {
final PlotFlagUpdateType plotFlagUpdateType; Preconditions.checkState(flag.getName().length() <= 64,
if (oldInstance != null) { "flag name may not be more than 64 characters. Check: " + flag.getName());
plotFlagUpdateType = PlotFlagUpdateType.FLAG_UPDATED; final PlotFlag<?, ?> oldInstance = this.flagMap.put(flag.getClass(), flag);
} else { final PlotFlagUpdateType plotFlagUpdateType;
plotFlagUpdateType = PlotFlagUpdateType.FLAG_ADDED; if (oldInstance != null) {
plotFlagUpdateType = PlotFlagUpdateType.FLAG_UPDATED;
} else {
plotFlagUpdateType = PlotFlagUpdateType.FLAG_ADDED;
}
if (this.plotFlagUpdateHandler != null) {
this.plotFlagUpdateHandler.handle(flag, plotFlagUpdateType);
}
this.updateSubscribers
.forEach(subscriber -> subscriber.handle(flag, plotFlagUpdateType));
} catch (IllegalStateException e) {
PlotSquared.log(
"yo look at this dumb fuck trying to add this thicc flag lol, nah mate, ain't having none of that");
e.printStackTrace();
} }
if (this.plotFlagUpdateHandler != null) {
this.plotFlagUpdateHandler.handle(flag, plotFlagUpdateType);
}
this.updateSubscribers.forEach(subscriber -> subscriber.handle(flag, plotFlagUpdateType));
} }
/** /**

View File

@ -75,8 +75,6 @@ public abstract class PlotFlag<T, F extends PlotFlag<T, F>> {
flagName.append(chars[i]); flagName.append(chars[i]);
} }
} }
Preconditions.checkState(flagName.length() <= 64,
"flag name may not be more than 64 characters. Check: " + flagName.toString());
this.flagName = flagName.toString(); this.flagName = flagName.toString();
} }