Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat-villager-cap-flag #4357

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.plotsquared.core.plot.flag.implementations.PvpFlag;
import com.plotsquared.core.plot.flag.implementations.TamedAttackFlag;
import com.plotsquared.core.plot.flag.implementations.VehicleCapFlag;
import com.plotsquared.core.plot.flag.implementations.VillagerCapFlag;
import com.plotsquared.core.util.EntityUtil;
import com.plotsquared.core.util.entity.EntityCategories;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
Expand Down Expand Up @@ -373,16 +374,23 @@ public static boolean checkEntity(Entity entity, Plot plot) {
);
}

// Has to go go before vehicle as horses are both
// Has to go before vehicle as horses are both
// animals and vehicles
if (EntityCategories.ANIMAL.contains(entityType) || EntityCategories.VILLAGER
.contains(entityType) || EntityCategories.TAMEABLE.contains(entityType)) {
if (EntityCategories.ANIMAL.contains(entityType)
|| EntityCategories.TAMEABLE.contains(entityType)) {
return EntityUtil
.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED, MobCapFlag.MOB_CAP_UNLIMITED,
AnimalCapFlag.ANIMAL_CAP_UNLIMITED
);
}

if(EntityCategories.VILLAGER.contains(entityType)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code style

return EntityUtil
.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED, MobCapFlag.MOB_CAP_UNLIMITED,
VillagerCapFlag.VILLAGER_CAP_UNLIMITED
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure we should remove villagers from the animal cap?

}

if (EntityCategories.HOSTILE.contains(entityType)) {
return EntityUtil
.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED, MobCapFlag.MOB_CAP_UNLIMITED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import static com.plotsquared.core.util.entity.EntityCategories.CAP_ANIMAL;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_ENTITY;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MISC;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_VILLAGER;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MOB;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MONSTER;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
Expand Down Expand Up @@ -122,7 +123,7 @@ public int[] countEntities(@NonNull Plot plot) {
}
}

int[] count = new int[6];
int[] count = new int[7];
if (doWhole) {
for (Entity entity : entities) {
org.bukkit.Location location = entity.getLocation();
Expand Down Expand Up @@ -330,7 +331,10 @@ private void count(int[] count, @NonNull Entity entity) {
} else if (EntityCategories.PROJECTILE.contains(entityType) || EntityCategories.OTHER.contains(entityType) || EntityCategories.HANGING
.contains(entityType)) {
count[CAP_MISC]++;
} else if (EntityCategories.ANIMAL.contains(entityType) || EntityCategories.VILLAGER.contains(entityType) || EntityCategories.TAMEABLE
} else if (EntityCategories.VILLAGER.contains(entityType)) {
count[CAP_MOB]++;
count[CAP_VILLAGER]++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here for animal cap

} else if (EntityCategories.ANIMAL.contains(entityType) || EntityCategories.TAMEABLE
.contains(entityType)) {
count[CAP_MOB]++;
count[CAP_ANIMAL]++;
Expand Down
3 changes: 3 additions & 0 deletions Core/src/main/java/com/plotsquared/core/command/Caps.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.plotsquared.core.plot.flag.implementations.MiscCapFlag;
import com.plotsquared.core.plot.flag.implementations.MobCapFlag;
import com.plotsquared.core.plot.flag.implementations.VehicleCapFlag;
import com.plotsquared.core.plot.flag.implementations.VillagerCapFlag;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.minimessage.tag.Tag;
Expand All @@ -40,6 +41,7 @@
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MOB;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MONSTER;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_VILLAGER;

@CommandDeclaration(command = "caps",
category = CommandCategory.INFO,
Expand Down Expand Up @@ -71,6 +73,7 @@ public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
sendFormatted(plot, player, AnimalCapFlag.class, countedEntities, "animals", CAP_ANIMAL);
sendFormatted(plot, player, VehicleCapFlag.class, countedEntities, "vehicle", CAP_VEHICLE);
sendFormatted(plot, player, MiscCapFlag.class, countedEntities, "misc", CAP_MISC);
sendFormatted(plot, player, VillagerCapFlag.class, countedEntities, "villagers", CAP_VILLAGER);
sendFormatted(plot, player, EntityCapFlag.class, countedEntities, "entities", CAP_ENTITY);
return true;
}
Expand Down
4 changes: 3 additions & 1 deletion Core/src/main/java/com/plotsquared/core/plot/Plot.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MOB;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MONSTER;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_VILLAGER;

/**
* The plot class<br>
Expand Down Expand Up @@ -1219,7 +1220,7 @@ public boolean removeFlag(final @NonNull PlotFlag<?, ?> flag) {
* @see RegionManager#countEntities(Plot)
*/
public int[] countEntities() {
int[] count = new int[6];
int[] count = new int[7];
for (Plot current : this.getConnectedPlots()) {
int[] result = this.regionManager.countEntities(current);
count[CAP_ENTITY] += result[CAP_ENTITY];
Expand All @@ -1228,6 +1229,7 @@ public int[] countEntities() {
count[CAP_MOB] += result[CAP_MOB];
count[CAP_VEHICLE] += result[CAP_VEHICLE];
count[CAP_MISC] += result[CAP_MISC];
count[CAP_VILLAGER] += result[CAP_VILLAGER];
}
return count;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
import com.plotsquared.core.plot.flag.implementations.VehicleCapFlag;
import com.plotsquared.core.plot.flag.implementations.VehiclePlaceFlag;
import com.plotsquared.core.plot.flag.implementations.VehicleUseFlag;
import com.plotsquared.core.plot.flag.implementations.VillagerCapFlag;
import com.plotsquared.core.plot.flag.implementations.VillagerInteractFlag;
import com.plotsquared.core.plot.flag.implementations.VineGrowFlag;
import com.plotsquared.core.plot.flag.implementations.WeatherFlag;
Expand Down Expand Up @@ -223,6 +224,7 @@ private GlobalFlagContainer() {
this.addFlag(EntityCapFlag.ENTITY_CAP_UNLIMITED);
this.addFlag(HostileCapFlag.HOSTILE_CAP_UNLIMITED);
this.addFlag(MiscCapFlag.MISC_CAP_UNLIMITED);
this.addFlag(VillagerCapFlag.VILLAGER_CAP_UNLIMITED);
this.addFlag(MobCapFlag.MOB_CAP_UNLIMITED);
this.addFlag(TimeFlag.TIME_DISABLED);
this.addFlag(VehicleCapFlag.VEHICLE_CAP_UNLIMITED);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.plot.flag.implementations;

import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.plot.flag.types.NonNegativeIntegerFlag;
import org.checkerframework.checker.nullness.qual.NonNull;

public class VillagerCapFlag extends NonNegativeIntegerFlag<VillagerCapFlag> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@since TODO tag


public static final VillagerCapFlag VILLAGER_CAP_UNLIMITED = new VillagerCapFlag(Integer.MAX_VALUE);

protected VillagerCapFlag(int value) {
super(value, TranslatableCaption.of("flags.flag_description_villager_cap"));
}

@Override
protected VillagerCapFlag flagOf(@NonNull Integer value) {
return new VillagerCapFlag(value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MOB;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MONSTER;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_VILLAGER;

/**
* Entity related general utility methods
Expand All @@ -48,6 +49,7 @@ private static int capNumeral(final @NonNull String flagName) {
case "animal-cap" -> CAP_ANIMAL;
case "vehicle-cap" -> CAP_VEHICLE;
case "misc-cap" -> CAP_MISC;
case "villager-cap" -> CAP_VILLAGER;
default -> CAP_ENTITY;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class EntityCategories {
public static final int CAP_MOB = 3;
public static final int CAP_VEHICLE = 4;
public static final int CAP_MISC = 5;
public static final int CAP_VILLAGER = 6;

public static final EntityCategory ANIMAL = register("animal");
public static final EntityCategory TAMEABLE = register("tameable");
Expand Down
1 change: 1 addition & 0 deletions Core/src/main/resources/lang/messages_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@
"flags.flag_description_misc_break": "<gray>Set to `true` to allow guests to break miscellaneous items.</gray>",
"flags.flag_description_misc_cap": "<gray>Set to an integer value to limit the amount of miscellaneous entities on the plot.</gray>",
"flags.flag_description_misc_interact": "<gray>Set to `true` to allow guests to interact with miscellaneous items.</gray>",
"flags.flag_description_villager_cap": "<gray>Set to an integer value to limit the amount of villagers on the plot.</gray>",
"flags.flag_description_sculk_sensor_interact": "<gray>Set to `true` to allow guests to interact with sculk sensors.</gray>",
"flags.flag_description_misc_place": "<gray>Set to `true` to allow guests to place miscellaneous items.</gray>",
"flags.flag_description_mob_break": "<gray>Set to `true` to allow mobs to break blocks within the plot.</gray>",
Expand Down
Loading