Skip to content

Commit

Permalink
Merge pull request #291 from lokka30/3.1-dev
Browse files Browse the repository at this point in the history
3.1 dev
  • Loading branch information
lokka30 authored Aug 29, 2021
2 parents d2b61f0 + 7486432 commit d252d69
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 56 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>me.lokka30</groupId>
<artifactId>LevelledMobs</artifactId>
<version>3.1.4 b502</version>
<version>3.1.6 b506</version>
<packaging>jar</packaging>

<name>LevelledMobs</name>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/me/lokka30/levelledmobs/Companion.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ public boolean loadFiles(final boolean isReload) {

}

final List<String> debugsEnabled = main.settingsCfg.getStringList(main.helperSettings.getKeyNameFromConfig(main.settingsCfg, "debug-misc"));
if (!debugsEnabled.isEmpty())
Utils.logger.info("misc debugs enabled: &b" + debugsEnabled);

main.configUtils.load();
main.playerLevellingDistance = main.helperSettings.getDouble(main.settingsCfg, "player-levelling-mob-distance-squared", 150);
main.playerLevellingMinRelevelTime = main.helperSettings.getInt(main.settingsCfg, "player-levelling-relevel-min-time", 5000);
Expand Down Expand Up @@ -257,6 +261,7 @@ void setupMetrics() {
metrics.addCustomChart(new SimplePie("check_mobs_on_chunk_load", metricsInfo::checkMobsOnChunkLoad));
metrics.addCustomChart(new SimplePie("custom-entity-names", metricsInfo::customEntityNamesCount));
metrics.addCustomChart(new SimplePie("utilizes-nbtdata", metricsInfo::usesNbtData));
metrics.addCustomChart(new SimplePie("utilizes_player_levelling", metricsInfo::usesPlayerLevelling));
metrics.addCustomChart(new SimpleBarChart("enabled-compatibility", metricsInfo::enabledCompats));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import me.lokka30.levelledmobs.managers.ExternalCompatibilityManager;
import me.lokka30.levelledmobs.misc.CachedModalList;
import me.lokka30.levelledmobs.misc.LivingEntityWrapper;
import me.lokka30.levelledmobs.misc.QueueItem;
import me.lokka30.levelledmobs.misc.Utils;
import me.lokka30.levelledmobs.rules.RuleInfo;
import me.lokka30.microlib.MessageUtils;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.chat.hover.content.Text;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.World;
Expand Down Expand Up @@ -112,10 +114,33 @@ else if ("help_wiki".equalsIgnoreCase(args[1]))
showHyperlink(sender, "Click to open the wiki","https://github.com/lokka30/LevelledMobs/wiki");
else if ("reset".equalsIgnoreCase(args[1]))
resetRules(sender, label, args);
else if ("force_all".equalsIgnoreCase(args[1]))
forceRelevel(sender, label, args);
else
sender.sendMessage(MessageUtils.colorizeAll("&b&lLevelledMobs: &7Invalid command"));
}

private void forceRelevel(final CommandSender sender, final String label, @NotNull final String[] args){
int worldCount = 0;
int entityCount = 0;

for (final World world : Bukkit.getWorlds()) {
worldCount++;
for (final Entity entity : world.getEntities()) {
if (!(entity instanceof LivingEntity)) continue;

entityCount++;
final LivingEntityWrapper lmEntity = new LivingEntityWrapper((LivingEntity) entity, main);
lmEntity.reEvaluateLevel = true;
main._mobsQueueManager.addToQueue(new QueueItem(lmEntity, null));
}
}

sender.sendMessage(MessageUtils.colorizeAll(String.format(
"%s Checked &b%s&7 mobs in &b%s&7 world(s)",
label, entityCount, worldCount)));
}

private void resetRules(final CommandSender sender, final String label, @NotNull final String[] args){
final String prefix = main.configUtils.getPrefix();

Expand Down Expand Up @@ -461,7 +486,7 @@ public List<String> parseTabCompletions(final LevelledMobs main, final CommandSe
final List<String> suggestions = new LinkedList<>();

if (args.length == 2)
return Arrays.asList("help_discord", "help_wiki", "reset", "show_all", "show_effective", "show_rule");
return Arrays.asList("force_all", "help_discord", "help_wiki", "reset", "show_all", "show_effective", "show_rule");
else if (args.length >= 3) {
if ("reset".equalsIgnoreCase(args[1]) && args.length == 3) {
suggestions.add("easy");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,15 @@ private void summonMobs(@NotNull final LivingEntityPlaceHolder lmPlaceHolder, in
final LevelledMobs main = lmPlaceHolder.getMainInstance();
Location location = lmPlaceHolder.getLocation();

if (main.levelManager.FORCED_BLOCKED_ENTITY_TYPES.contains(lmPlaceHolder.getTypeName())) {
List<String> messages = main.messagesCfg.getStringList("command.levelledmobs.summon.not-levellable");
messages = Utils.replaceAllInList(messages, "%prefix%", main.configUtils.getPrefix());
messages = Utils.replaceAllInList(messages, "%entity%", lmPlaceHolder.getTypeName());
messages = Utils.colorizeAllInList(messages);
messages.forEach(sender::sendMessage);
return;
}

if (!sender.isOp() && !override && main.levelInterface.getLevellableState(lmPlaceHolder) != LevellableState.ALLOWED) {
List<String> messages = main.messagesCfg.getStringList("command.levelledmobs.summon.not-levellable");
messages = Utils.replaceAllInList(messages, "%prefix%", main.configUtils.getPrefix());
Expand Down
27 changes: 19 additions & 8 deletions src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
/**
* Generates levels and manages other functions related to levelling mobs
*
* @author lokka30, CoolBoy, Esophose, 7smile7,
* wShevchik, Hugo5551, limzikiki
* @author lokka30, stumper66, CoolBoy, Esophose, 7smile7, Shevchik, Hugo5551, limzikiki
* @since 2.4.0
*/
public class LevelManager implements LevelInterface {
Expand Down Expand Up @@ -72,10 +71,19 @@ public class LevelManager implements LevelInterface {
public EntitySpawnListener entitySpawnListener;

/**
* The following entity types MUST be not levellable.
* The following entity types *MUST NOT* be levellable.
* Stored as Strings since older versions may not contain certain entity type constants
*/
public final HashSet<String> FORCED_BLOCKED_ENTITY_TYPES = new HashSet<>(Arrays.asList("PLAYER", "UNKNOWN", "ARMOR_STAND", "NPC"));
public final HashSet<String> FORCED_BLOCKED_ENTITY_TYPES = new HashSet<>(Arrays.asList(
"AREA_EFFECT_CLOUD", "ARMOR_STAND", "ARROW", "BOAT", "DRAGON_FIREBALL", "DROPPED_ITEM",
"EGG", "ENDER_CRYSTAL", "ENDER_PEARL", "ENDER_SIGNAL", "EXPERIENCE_ORB",
"FALLING_BLOCK", "FIREBALL", "FIREWORK", "FISHING_HOOK", "GLOW_ITEM_FRAME",
"ITEM_FRAME", "LEASH_HITCH", "LIGHTNING", "LLAMA_SPIT", "MARKER", "MINECART",
"MINECART_CHEST", "MINECART_COMMAND", "MINECART_FURNACE", "MINECART_HOPPER",
"MINECART_MOB_SPAWNER", "MINECART_TNT", "NPC", "PAINTING", "PLAYER", "PRIMED_TNT",
"SMALL_FIREBALL", "SNOWBALL", "SPECTRAL_ARROW", "SPLASH_POTION", "THROWN_EXP_BOTTLE",
"TRIDENT", "UNKNOWN", "WITHER_SKULL"
));

/**
* The following entity types must be manually ALLOWED in 'getLevellableState',
Expand Down Expand Up @@ -624,9 +632,10 @@ public void startNametagAutoUpdateTask() {
@Override
public void run() {
final Map<Player, List<Entity>> entitiesPerPlayer = new LinkedHashMap<>();
final int checkDistance = main.helperSettings.getInt(main.settingsCfg,"async-task-update-period", 100);

for (final Player player : Bukkit.getOnlinePlayers()) {
final List<Entity> entities = player.getNearbyEntities(50, 50, 50);
final List<Entity> entities = player.getNearbyEntities(checkDistance, checkDistance, checkDistance);
entitiesPerPlayer.put(player, entities);
}

Expand Down Expand Up @@ -669,15 +678,17 @@ private void runNametagCheck_aSync(final Map<Player,List<Entity>> entitiesPerPla
synchronized (lmEntity.getLivingEntity().getPersistentDataContainer()) {
wasBabyMob = lmEntity.getPDC().has(main.levelManager.wasBabyMobKey, PersistentDataType.INTEGER);
}
if (
!lmEntity.isBabyMob() &&
final LevellableState levellableState = main.levelInterface.getLevellableState(lmEntity);
if (!lmEntity.isBabyMob() &&
wasBabyMob &&
main.levelInterface.getLevellableState(lmEntity) == LevellableState.ALLOWED) {
levellableState == LevellableState.ALLOWED) {
// if the mob was a baby at some point, aged and now is eligable for levelling, we'll apply a level to it now
Utils.debugLog(main, DebugType.ENTITY_MISC, "&b" + lmEntity.getTypeName() + " &7was a baby and is now an adult, applying levelling rules");

main._mobsQueueManager.addToQueue(new QueueItem(lmEntity, null));
}
else if (levellableState == LevellableState.ALLOWED)
main._mobsQueueManager.addToQueue(new QueueItem(lmEntity, null));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ public void setAdditionsForLevel(@NotNull final LivingEntityWrapper lmEntity, fi
double newHealth = attrib.getValue() - existingDamage;
if (newHealth < 0.0) newHealth = 0.0;
try {
if (lmEntity.getLivingEntity().getHealth() <= 0.0) return;
lmEntity.getLivingEntity().setHealth(newHealth);
} catch (IllegalArgumentException ignored) {
}
} catch (IllegalArgumentException ignored) { }

}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/lokka30/levelledmobs/misc/FileLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
public final class FileLoader {

public static final int SETTINGS_FILE_VERSION = 31; // Last changed: v3.1.0 b474
public static final int SETTINGS_FILE_VERSION = 32; // Last changed: v3.1.5 b503
public static final int MESSAGES_FILE_VERSION = 6; // Last changed: v3.1.2 b485
public static final int CUSTOMDROPS_FILE_VERSION = 10; // Last changed: v3.1.0 b474
public static final int RULES_FILE_VERSION = 2; // Last changed: v3.1.0 b474
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/me/lokka30/levelledmobs/misc/FileMigrator.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ protected static void copyYmlValues(File from, @NotNull File to, int oldVersion)
boolean hasValues = line.length() > firstColon + 1;
String key = line.substring(0, firstColon).replace("\t", "").trim();
final String keyOnly = key;
String oldKey = key;
if (isSettings && oldVersion < 32 && key.equalsIgnoreCase("async-task-update-period"))
oldKey = "nametag-auto-update-task-period";

if (depth == 0)
currentKey.clear();
Expand All @@ -395,8 +398,8 @@ else if (currentKey.size() > depth) {
if (isSettings && oldVersion <= 20 && !version20KeysToKeep.contains(key)) continue;
if (isMessages && oldVersion <= 5 && messagesExempt_v5.contains(key)) continue;

if (oldConfigMap.containsKey(key) && newConfigMap.containsKey(key)) {
final FileMigrator.FieldInfo fiOld = oldConfigMap.get(key);
if (oldConfigMap.containsKey(oldKey) && newConfigMap.containsKey(key)) {
final FileMigrator.FieldInfo fiOld = oldConfigMap.get(oldKey);
final FileMigrator.FieldInfo fiNew = newConfigMap.get(key);
final String padding = getPadding((depth + 1) * 2);
// arrays go here:
Expand Down Expand Up @@ -434,10 +437,10 @@ else if (currentKey.size() > depth) {
}
}
}
} else if (oldConfigMap.containsKey(key)) {
} else if (oldConfigMap.containsKey(oldKey)) {
keysMatched++;
final String value = line.substring(firstColon + 1).trim();
final FileMigrator.FieldInfo fi = oldConfigMap.get(key);
final FileMigrator.FieldInfo fi = oldConfigMap.get(oldKey);
final String migratedValue = fi.simpleValue;

if (isSettings && oldVersion <= 20 && !version20KeysToKeep.contains(key)) continue;
Expand Down Expand Up @@ -495,6 +498,12 @@ else if (currentKey.size() > depth) {
} else
valuesMatched++;
}
else {
// keys present in the new config but not the old one fall here
if (isSettings && oldVersion < 32 && keyOnly.equalsIgnoreCase("async-task-update-period")){

}
}
} else if (line.trim().startsWith("-")) {
final String key = getKeyFromList(currentKey, null);
final String value = line.trim().substring(1).trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ private void buildCache(){
if (isBuildingCache || this.hasCache) return;

try{
if (!this.cacheLock.tryLock(1000, TimeUnit.MILLISECONDS)) return;
if (!this.cacheLock.tryLock(1000, TimeUnit.MILLISECONDS)) {
Utils.logger.warning("lock timed out building cache");
return;
}

if (this.hasCache) return;
isBuildingCache = true;
Expand Down
52 changes: 24 additions & 28 deletions src/main/java/me/lokka30/levelledmobs/misc/YmlParsingHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,20 @@ public boolean getBoolean(final ConfigurationSection cs, @NotNull final String n

public boolean getBoolean(final ConfigurationSection cs, @NotNull final String name, final boolean defaultValue){
if (cs == null) return defaultValue;
for (final String key : cs.getKeys(false)){
if (name.equalsIgnoreCase(key)) return cs.getBoolean(key, defaultValue);
}
final String useName = getKeyNameFromConfig(cs, name);

return defaultValue;
return cs.getBoolean(useName, defaultValue);
}

@Nullable
public Boolean getBoolean2(final ConfigurationSection cs, @NotNull final String name, final Boolean defaultValue){
if (cs == null) return defaultValue;
for (final String key : cs.getKeys(false)){
if (name.equalsIgnoreCase(key)) return cs.getBoolean(key);
}
final String useName = getKeyNameFromConfig(cs, name);

return defaultValue;
if (cs.get(useName) != null)
return cs.getBoolean(useName);
else
return defaultValue;
}

@Nullable
Expand All @@ -49,11 +48,9 @@ public String getString(final ConfigurationSection cs, @NotNull final String nam
@Nullable
public String getString(final ConfigurationSection cs, @NotNull final String name, final String defaultValue){
if (cs == null) return defaultValue;
for (final String key : cs.getKeys(false)){
if (name.equalsIgnoreCase(key)) return cs.getString(key, defaultValue);
}
final String useName = getKeyNameFromConfig(cs, name);

return defaultValue;
return cs.getString(name, defaultValue);
}

@NotNull
Expand All @@ -71,21 +68,21 @@ public int getInt(final ConfigurationSection cs, @NotNull final String name){

public int getInt(final ConfigurationSection cs, @NotNull final String name, final int defaultValue){
if (cs == null) return defaultValue;
for (final String key : cs.getKeys(false)){
if (name.equalsIgnoreCase(key)) return cs.getInt(key, defaultValue);
}

return defaultValue;
final String useName = getKeyNameFromConfig(cs, name);
return cs.getInt(useName, defaultValue);
}

@Nullable
public Integer getInt2(final ConfigurationSection cs, @NotNull final String name, final Integer defaultValue){
if (cs == null) return defaultValue;
for (final String key : cs.getKeys(false)){
if (name.equalsIgnoreCase(key)) return cs.getInt(key);
}

return defaultValue;
final String useName = getKeyNameFromConfig(cs, name);

if (cs.get(useName) != null)
return cs.getInt(useName);
else
return defaultValue;
}

public double getDouble(final ConfigurationSection cs, @NotNull final String name){
Expand All @@ -94,21 +91,20 @@ public double getDouble(final ConfigurationSection cs, @NotNull final String nam

public double getDouble(final ConfigurationSection cs, @NotNull final String name, final double defaultValue){
if (cs == null) return defaultValue;
for (final String key : cs.getKeys(false)){
if (name.equalsIgnoreCase(key)) return cs.getDouble(key, defaultValue);
}
final String useName = getKeyNameFromConfig(cs, name);

return defaultValue;
return cs.getDouble(useName, defaultValue);
}

@Nullable
public Double getDouble2(final ConfigurationSection cs, @NotNull final String name, final Double defaultValue){
if (cs == null) return defaultValue;
for (final String key : cs.getKeys(false)){
if (name.equalsIgnoreCase(key)) return cs.getDouble(key);
}
final String useName = getKeyNameFromConfig(cs, name);

return defaultValue;
if (cs.get(useName) != null)
return cs.getDouble(useName);
else
return defaultValue;
}

@NotNull
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/me/lokka30/levelledmobs/rules/MetricsInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ else if (defaultRule.levellingStrategy instanceof RandomLevellingStrategy) {
return "Random";
}

public String usesPlayerLevelling(){
return convertBooleanToString(main.rulesManager.isPlayerLevellingEnabled());
}

public String usesAutoUpdateChecker(){
return convertBooleanToString(main.helperSettings.getBoolean(main.settingsCfg, "use-update-checker", true));
}
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/me/lokka30/levelledmobs/rules/RulesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,15 @@ private boolean isRuleApplicable_Entity(final LivingEntityWrapper lmEntity, @Not
return false;
}

if (ri.conditions_CustomNames != null && lmEntity.getLivingEntity().getCustomName() != null &&
!ri.conditions_CustomNames.isEnabledInList(lmEntity.getLivingEntity().getCustomName(), lmEntity)) {
Utils.debugLog(main, DebugType.DENIED_RULE_CUSTOM_NAME, String.format("&b%s&7, mob: &b%s&7, name: &b%s&7",
ri.getRuleName(), lmEntity.getTypeName(), lmEntity.getLivingEntity().getCustomName()));
return false;
if (ri.conditions_CustomNames != null){
final String customName = lmEntity.getLivingEntity().getCustomName() != null ?
lmEntity.getLivingEntity().getCustomName() : "(none)";

if (!ri.conditions_CustomNames.isEnabledInList(customName, lmEntity)){
Utils.debugLog(main, DebugType.DENIED_RULE_CUSTOM_NAME, String.format("&b%s&7, mob: &b%s&7, name: &b%s&7",
ri.getRuleName(), lmEntity.getTypeName(), customName));
return false;
}
}

if (ri.conditions_SpawnReasons != null && !ri.conditions_SpawnReasons.isEnabledInList(lmEntity.getSpawnReason(), lmEntity)){
Expand Down
Loading

0 comments on commit d252d69

Please sign in to comment.