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,6 +130,9 @@ 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) {
try {
Preconditions.checkState(flag.getName().length() <= 64,
"flag name may not be more than 64 characters. Check: " + flag.getName());
final PlotFlag<?, ?> oldInstance = this.flagMap.put(flag.getClass(), flag); final PlotFlag<?, ?> oldInstance = this.flagMap.put(flag.getClass(), flag);
final PlotFlagUpdateType plotFlagUpdateType; final PlotFlagUpdateType plotFlagUpdateType;
if (oldInstance != null) { if (oldInstance != null) {
@ -138,7 +143,13 @@ public class FlagContainer {
if (this.plotFlagUpdateHandler != null) { if (this.plotFlagUpdateHandler != null) {
this.plotFlagUpdateHandler.handle(flag, plotFlagUpdateType); this.plotFlagUpdateHandler.handle(flag, plotFlagUpdateType);
} }
this.updateSubscribers.forEach(subscriber -> subscriber.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();
}
} }
/** /**

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