Fixed: Enabled living shops specified inside the config would previously not get enabled if they were not perfectly matching the entity type name.

The enabled living shop types get validated and cached as part of the derived settings now.

Also: Removed the 1.16 'PIG_ZOMBIE' migration. We no longer automatically remove this mob type from the config, but only log a warning and then ignore it.

Also refactoring: Moved the validation of settings into a separate method.
master
blablubbabc 2020-11-25 03:08:41 +01:00
parent d50bfaa4d1
commit 685fd96586
4 changed files with 38 additions and 37 deletions

View File

@ -19,6 +19,7 @@ Date format: (YYYY-MM-DD)
* Config: A value of '0' for the 'max-shops-per-player' setting no longer indicates no limit, but can be used to disable the creation and hiring of player shops. 'No limit' is indicated by a value of '-1' now. Any previous limit of '0' is automatically migrated.
* The permissions specified inside the config get cached and checked in decreasing order now. We abort checking permissions if they cannot further increase the player's current shops limit. An effect of this is that it is only possible to increase the default limit, not decrease it.
* Added permission node 'shopkeeper.maxshops.unlimited' (default: op), which disables the max shops limit for a player.
* Fixed: Enabled living shops specified inside the config would previously not get enabled if they were not perfectly matching the entity type name.
API:
* PlayerCreatePlayerShopkeeperEvent and PlayerShopkeeperHireEvent: The meaning of the max shops limit has changed. A value of 0 or less no longer indicates 'no limit'.
@ -31,6 +32,7 @@ Migration notes:
* The save file and trading logs (if enabled) are stored inside a new 'data' folder now.
* If no save file exists at the new location and a previous save file is found at the old location, it is automatically moved.
* Language files are located inside a new 'lang' folder now. Existing custom language files need to be manually moved!
* Removed the 1.16 'PIG_ZOMBIE' migration. We no longer automatically remove this mob type from the config, but only log a warning and then ignore it.
Messages:
* All message keys were changed to no longer start with the 'msg' prefix.

View File

@ -11,8 +11,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
@ -325,6 +325,8 @@ public class Settings {
// Sorted in descending order:
public static final List<MaxShopsPermission> maxShopsPermissions = new ArrayList<>();
public static final Set<EntityType> enabledLivingShops = new LinkedHashSet<>();
static {
// Initial setup of default values:
setup();
@ -370,6 +372,27 @@ public class Settings {
maxShopsPermissions.add(new MaxShopsPermission(maxShops, permission));
}
Collections.sort(maxShopsPermissions, Collections.reverseOrder()); // Descending order
// Enabled living shop types:
enabledLivingShops.clear();
boolean foundInvalidEntityType = false;
for (String entityTypeId : Settings.enabledLivingShops) {
EntityType entityType = EntityUtils.matchEntityType(entityTypeId);
if (entityType == null || !entityType.isAlive() || !entityType.isSpawnable()) {
foundInvalidEntityType = true;
if ("PIG_ZOMBIE".equals(entityTypeId)) {
// Migration note for MC 1.16 TODO Remove this again at some point?
Log.warning("Config: Ignoring mob type 'PIG_ZOMBIE' in setting 'enabled-living-shops'. This mob no longer exist since MC 1.16. Consider replacing it with 'ZOMBIFIED_PIGLIN'.");
} else {
Log.warning("Config: Invalid living entity type name in 'enabled-living-shops': " + entityTypeId);
}
} else {
enabledLivingShops.add(entityType);
}
}
if (foundInvalidEntityType) {
Log.warning("Config: All existing entity type names can be found here: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/EntityType.html");
}
}
private DerivedSettings() {
@ -614,31 +637,13 @@ public class Settings {
}
// Validation:
validateSettings();
boolean foundInvalidEntityType = false;
boolean removePigZombie = false;
for (String entityTypeId : enabledLivingShops) {
EntityType entityType = EntityUtils.matchEntityType(entityTypeId);
if (entityType == null || !entityType.isAlive() || !entityType.isSpawnable()) {
foundInvalidEntityType = true;
if ("PIG_ZOMBIE".equals(entityTypeId)) {
removePigZombie = true;
} else {
Log.warning("Config: Invalid living entity type name in 'enabled-living-shops': " + entityTypeId);
}
}
}
// Migration for MC 1.16 TODO remove this again at some point
if (removePigZombie) {
Log.warning("Config: The mob type 'PIG_ZOMBIE' no longer exist since MC 1.16 and has therefore been removed from the 'enabled-living-shops'. Consider replacing it with 'ZOMBIFIED_PIGLIN'.");
enabledLivingShops.removeIf(e -> Objects.equals(e, "PIG_ZOMBIE"));
config.set(toConfigKey("enabledLivingShops"), enabledLivingShops);
configChanged = true;
}
if (foundInvalidEntityType) {
Log.warning("Config: All existing entity type names can be found here: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/EntityType.html");
}
onSettingsChanged();
return configChanged;
}
private static void validateSettings() {
if (maxContainerDistance > 50) {
Log.warning("Config: 'max-container-distance' can be at most 50.");
maxContainerDistance = 50;
@ -680,9 +685,6 @@ public class Settings {
Log.warning("Config: 'tax-rate' can not be larger than 100!");
taxRate = 100;
}
onSettingsChanged();
return configChanged;
}
/////

View File

@ -6,7 +6,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import com.nisovin.shopkeepers.Messages;
import com.nisovin.shopkeepers.Settings;
import com.nisovin.shopkeepers.Settings.DerivedSettings;
import com.nisovin.shopkeepers.api.shopkeeper.ShopCreationData;
import com.nisovin.shopkeepers.api.shopobjects.living.LivingShopObjectType;
import com.nisovin.shopkeepers.shopkeeper.AbstractShopkeeper;
@ -48,6 +48,6 @@ public abstract class SKLivingShopObjectType<T extends SKLivingShopObject<?>> ex
@Override
public boolean isEnabled() {
return Settings.enabledLivingShops.contains(entityType.name());
return DerivedSettings.enabledLivingShops.contains(entityType);
}
}

View File

@ -17,7 +17,7 @@ import org.bukkit.entity.Llama;
import org.bukkit.entity.TraderLlama;
import org.bukkit.entity.Zombie;
import com.nisovin.shopkeepers.Settings;
import com.nisovin.shopkeepers.Settings.DerivedSettings;
import com.nisovin.shopkeepers.api.shopkeeper.ShopCreationData;
import com.nisovin.shopkeepers.api.shopobjects.living.LivingShopObjectTypes;
import com.nisovin.shopkeepers.shopkeeper.AbstractShopkeeper;
@ -40,7 +40,6 @@ import com.nisovin.shopkeepers.shopobjects.living.types.VillagerShop;
import com.nisovin.shopkeepers.shopobjects.living.types.WolfShop;
import com.nisovin.shopkeepers.shopobjects.living.types.ZombieShop;
import com.nisovin.shopkeepers.shopobjects.living.types.ZombieVillagerShop;
import com.nisovin.shopkeepers.util.EntityUtils;
import com.nisovin.shopkeepers.util.StringUtils;
public class SKLivingShopObjectTypes implements LivingShopObjectTypes {
@ -154,12 +153,10 @@ public class SKLivingShopObjectTypes implements LivingShopObjectTypes {
public SKLivingShopObjectTypes(LivingShops livingShops) {
this.livingShops = livingShops;
// First, create the enabled living object types, in the same order as specified in the config:
for (String entityTypeId : Settings.enabledLivingShops) {
EntityType entityType = EntityUtils.matchEntityType(entityTypeId);
if (entityType != null && entityType.isAlive() && entityType.isSpawnable() && !objectTypes.containsKey(entityType)) {
// Not using aliases (yet?)
objectTypes.put(entityType, this.createLivingEntityObjectType(entityType, this.getAliases(entityType)));
}
for (EntityType entityType : DerivedSettings.enabledLivingShops) {
assert entityType != null && entityType.isAlive() && entityType.isSpawnable() && !objectTypes.containsKey(entityType);
// Not using aliases (yet?)
objectTypes.put(entityType, this.createLivingEntityObjectType(entityType, this.getAliases(entityType)));
}
// Register object types for all other remaining living entity types: