mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-11-04 03:03:43 +01:00 
			
		
		
		
	Extract duplicated switch statement in EntityUtil
This commit is contained in:
		@@ -4,6 +4,7 @@ import com.github.intellectualsites.plotsquared.plot.config.Settings;
 | 
				
			|||||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
 | 
					import com.github.intellectualsites.plotsquared.plot.flag.Flags;
 | 
				
			||||||
import com.github.intellectualsites.plotsquared.plot.flag.IntegerFlag;
 | 
					import com.github.intellectualsites.plotsquared.plot.flag.IntegerFlag;
 | 
				
			||||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
 | 
					import com.github.intellectualsites.plotsquared.plot.object.Plot;
 | 
				
			||||||
 | 
					import lombok.NonNull;
 | 
				
			||||||
import lombok.experimental.UtilityClass;
 | 
					import lombok.experimental.UtilityClass;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@@ -12,14 +13,9 @@ import lombok.experimental.UtilityClass;
 | 
				
			|||||||
@UtilityClass
 | 
					@UtilityClass
 | 
				
			||||||
public final class EntityUtil {
 | 
					public final class EntityUtil {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static boolean checkEntity(Plot plot, IntegerFlag... flags) {
 | 
					    private static int capNumeral(@NonNull final String flagName) {
 | 
				
			||||||
        if (Settings.Done.RESTRICT_BUILDING && Flags.DONE.isSet(plot)) {
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        int[] mobs = null;
 | 
					 | 
				
			||||||
        for (IntegerFlag flag : flags) {
 | 
					 | 
				
			||||||
        int i;
 | 
					        int i;
 | 
				
			||||||
            switch (flag.getName()) {
 | 
					        switch (flagName) {
 | 
				
			||||||
            case "entity-cap":
 | 
					            case "entity-cap":
 | 
				
			||||||
                i = 0;
 | 
					                i = 0;
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
@@ -41,6 +37,16 @@ public final class EntityUtil {
 | 
				
			|||||||
            default:
 | 
					            default:
 | 
				
			||||||
                i = 0;
 | 
					                i = 0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        return i;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static boolean checkEntity(Plot plot, IntegerFlag... flags) {
 | 
				
			||||||
 | 
					        if (Settings.Done.RESTRICT_BUILDING && Flags.DONE.isSet(plot)) {
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        int[] mobs = null;
 | 
				
			||||||
 | 
					        for (IntegerFlag flag : flags) {
 | 
				
			||||||
 | 
					            final int i = capNumeral(flag.getName());
 | 
				
			||||||
            int cap = plot.getFlag(flag, Integer.MAX_VALUE);
 | 
					            int cap = plot.getFlag(flag, Integer.MAX_VALUE);
 | 
				
			||||||
            if (cap == Integer.MAX_VALUE) {
 | 
					            if (cap == Integer.MAX_VALUE) {
 | 
				
			||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
@@ -59,29 +65,7 @@ public final class EntityUtil {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        if (mobs != null) {
 | 
					        if (mobs != null) {
 | 
				
			||||||
            for (IntegerFlag flag : flags) {
 | 
					            for (IntegerFlag flag : flags) {
 | 
				
			||||||
                int i;
 | 
					                final int i = capNumeral(flag.getName());
 | 
				
			||||||
                switch (flag.getName()) {
 | 
					 | 
				
			||||||
                    case "entity-cap":
 | 
					 | 
				
			||||||
                        i = 0;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    case "mob-cap":
 | 
					 | 
				
			||||||
                        i = 3;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    case "hostile-cap":
 | 
					 | 
				
			||||||
                        i = 2;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    case "animal-cap":
 | 
					 | 
				
			||||||
                        i = 1;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    case "vehicle-cap":
 | 
					 | 
				
			||||||
                        i = 4;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    case "misc-cap":
 | 
					 | 
				
			||||||
                        i = 5;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    default:
 | 
					 | 
				
			||||||
                        i = 0;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                mobs[i]++;
 | 
					                mobs[i]++;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            plot.setMeta("EntityCount", mobs);
 | 
					            plot.setMeta("EntityCount", mobs);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user