Skip to content

Commit

Permalink
5.7 (#231)
Browse files Browse the repository at this point in the history
* Add TagTask raytracing.

* Add nag about console logging on named mob death

* Return boolean rather than ConfigList where possible

* Add EntityGrouping enum

* Implement entity type groups

* Move paper check for spawn reason to config method

* Add stacking tool INFO mode

* Change config defaults

* Might help with #230

* Add paper check

* Increment version
  • Loading branch information
ploppyperson authored Sep 5, 2021
1 parent 066eaed commit 1001b47
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 62 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>uk.antiperson.stackmob</groupId>
<artifactId>StackMob</artifactId>
<version>5.6.2</version>
<version>5.7.0</version>

<build>
<sourceDirectory>src/main/java</sourceDirectory>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/uk/antiperson/stackmob/StackMob.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public void onEnable() {
temporaryCompat.runTaskTimer(this, 20, 100);
getServer().getPluginManager().registerEvents(temporaryCompat, this);
}
if (Utilities.isPaper() && getServer().spigot().getPaperConfig().getBoolean("settings.log-named-entity-deaths", false)) {
getLogger().warning("The paper.yml option settings.log-named-entity-deaths is enabled." +
" You will get messages in console every time a named mob is killed." +
" You should probably disable this, unless you like console spam?");
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public boolean onCommand(User sender, String[] args) {
if (predicate != null && !predicate.test(entity)) {
continue;
}
CreatureSpawnEvent.SpawnReason reason = Utilities.isPaper() ? entity.getEntitySpawnReason() : CreatureSpawnEvent.SpawnReason.DEFAULT;
if (sm.getMainConfig().isEntityBlacklisted(entity, reason)) {
if (sm.getMainConfig().isEntityBlacklisted(entity)) {
continue;
}
sm.getEntityManager().registerStackedEntity(entity).setSize(1);
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/uk/antiperson/stackmob/config/ConfigFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ public boolean getBoolean(String path) {
}

public ConfigList getList(String path) {
return ConfigList.getConfigList(this, new ConfigValue(path, get(path)));
List<?> list = fileCon.getList(path);
if (list == null) {
throw new UnsupportedOperationException(path + " list is null!");
}
boolean inverted = getBoolean(path + "-invert");
return new ConfigList(this, list, path, inverted);
}

public ConfigurationSection getConfigurationSection(String path) {
Expand Down Expand Up @@ -109,7 +114,7 @@ public void createFile() throws IOException {
// The files copy below will throw an error if the directories are not pre existing.
file = new File(sm.getDataFolder(), filePath);
File parentFile = file.getParentFile();
if(!parentFile.exists()){
if (!parentFile.exists()) {
Files.createDirectories(parentFile.toPath());
}
// Open the file and copy it to the plugin folder.
Expand Down Expand Up @@ -146,8 +151,7 @@ public void updateFile() throws IOException {
return;
}
fileCon.options().header(includedConfig.options().header());
sm.getLogger().info("Config file " + file.getName() + " has been updated.");
sm.getLogger().info("Unfortunately, this means that comments have been removed.");
sm.getLogger().warning("Config file " + file.getName() + " has been updated. This means that comments have been removed.");
sm.getLogger().info("If you need comments, you access a version with them at " + Utilities.GITHUB_DEFAULT_CONFIG);
save();
}
Expand Down
11 changes: 1 addition & 10 deletions src/main/java/uk/antiperson/stackmob/config/ConfigList.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class ConfigList {
private final String path;
private final boolean inverted;
private final ConfigFile configFile;

public ConfigList(ConfigFile configFile, List<?> list, String path, boolean inverted) {
this.configFile = configFile;
this.list = list;
Expand All @@ -31,15 +32,5 @@ public List<Integer> asIntList() {
return configFile.getIntegerList(path);
}

public static ConfigList getConfigList(ConfigFile configFile, ConfigValue value) {
List<?> list = (List<?>) value.getValue();
String path = value.getPath();
if (list == null) {
throw new UnsupportedOperationException(path + " list is null!");
}
boolean inverted = configFile.getBoolean(value.getPath() + "-invert");
return new ConfigList(configFile, list, path, inverted);
}


}
88 changes: 70 additions & 18 deletions src/main/java/uk/antiperson/stackmob/config/MainConfig.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package uk.antiperson.stackmob.config;

import org.bukkit.World;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Boss;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Phantom;
import org.bukkit.entity.Raider;
import org.bukkit.entity.WaterMob;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import uk.antiperson.stackmob.StackMob;
import uk.antiperson.stackmob.entity.StackEntity;
import uk.antiperson.stackmob.entity.death.DeathType;
Expand Down Expand Up @@ -70,6 +79,10 @@ public int getTagNearbyInterval() {
return getInt("display-name.nearby.interval");
}

public boolean isTagNearbyRayTrace() {
return getBoolean("display-name.nearby.ray-trace");
}

public boolean isTraitEnabled(String traitKey) {
return getBoolean("traits." + traitKey);
}
Expand All @@ -90,12 +103,12 @@ public boolean isSlimeMultiEnabled(EntityType type) {
return getBoolean(type, "multiply.slime-split");
}

public ConfigList getDropTypeBlacklist(EntityType type) {
return getList(type, "drops.type-blacklist");
public boolean isDropTypeBlacklist(EntityType type) {
return isEntityTypeInList(type, "drops.type-blacklist");
}

public ConfigList getDropReasonBlacklist(EntityType type) {
return getList(type, "drops.reason-blacklist");
public boolean isDropReasonBlacklist(EntityType type, EntityDamageEvent.DamageCause damageCause) {
return getList(type, "drops.reason-blacklist").contains(damageCause.toString());
}

public ConfigList getDropItemBlacklist(EntityType type) {
Expand All @@ -110,8 +123,8 @@ public boolean isExpMultiEnabled(EntityType type) {
return getBoolean(type, "experience.enabled");
}

public ConfigList getExpTypeBlacklist(EntityType type) {
return getList(type, "experience.type-blacklist");
public boolean isExpTypeBlacklist(EntityType type) {
return getList(type, "experience.type-blacklist").contains(type.toString());
}

public double getExpMinBound(EntityType type) {
Expand All @@ -130,12 +143,12 @@ public boolean isWaitingEnabled(EntityType type) {
return getBoolean(type, "wait-to-stack.enabled");
}

public ConfigList getWaitingTypes(EntityType type) {
return getList(type, "wait-to-stack.types-whitelist");
public boolean isWaitingTypes(EntityType type) {
return isEntityTypeInList(type, "wait-to-stack.types-whitelist");
}

public ConfigList getWaitingReasons(EntityType type) {
return getList(type, "wait-to-stack.reasons-whitelist");
public boolean isWaitingReasons(EntityType type, CreatureSpawnEvent.SpawnReason spawnReason) {
return getList(type, "wait-to-stack.reasons-whitelist").contains(spawnReason.toString());
}

public int getWaitingTime(EntityType type) {
Expand All @@ -160,29 +173,34 @@ public boolean isTargetingDisabled(EntityType type) {
return getBoolean(type, "disable-targeting.enabled");
}

public ConfigList getTargetingDisabledTypes(EntityType type) {
return getList(type, "disable-targeting.type-blacklist");
public boolean isTargetingDisabledTypes(EntityType type) {
return isEntityTypeInList(type, "disable-targeting.type-blacklist");
}

public ConfigList getTargetingDisabledReasons(EntityType type) {
return getList(type, "disable-targeting.reason-blacklist");
public boolean isTargetingDisabledReasons(EntityType type, CreatureSpawnEvent.SpawnReason spawnReason) {
return getList(type, "disable-targeting.reason-blacklist").contains(spawnReason.toString());
}

public ListenerMode getListenerMode(EntityType type, String eventKey) {
return ListenerMode.valueOf(getString(type, "events." + eventKey + ".mode"));
}

public int getEventMultiplyLimit(EntityType type, String eventKey, int stackSize) {
int limit = getInt(type, "events." + eventKey + ".limit");
int limit = getInt(type, "events." + eventKey + ".limit");
return limit == -1 ? stackSize : Math.min(stackSize, limit);
}

public boolean isWorldBlacklisted(EntityType type, World world) {
return getList(type, "worlds-blacklist").contains(world.getName());
}

public boolean isEntityBlacklisted(LivingEntity entity) {
CreatureSpawnEvent.SpawnReason reason = Utilities.isPaper() ? entity.getEntitySpawnReason() : CreatureSpawnEvent.SpawnReason.DEFAULT;
return isEntityBlacklisted(entity, reason);
}

public boolean isEntityBlacklisted(LivingEntity entity, CreatureSpawnEvent.SpawnReason reason) {
if (getList(entity.getType(), "types-blacklist").contains(entity.getType().toString())) {
if (isEntityTypeInList(entity.getType(), "types-blacklist")) {
return true;
}
if (getList(entity.getType(), "reason-blacklist").contains(reason.toString())) {
Expand All @@ -201,8 +219,7 @@ public DeathType getDeathType(LivingEntity dead) {
if (Utilities.isPaper() && spawnReasons.contains(dead.getEntitySpawnReason())) {
continue;
}
ConfigList types = getList(dead.getType(), "death." + type + ".type-blacklist");
if (types.contains(dead.getType().toString())) {
if (isEntityTypeInList(dead.getType(), "death." + type + ".type-blacklist")) {
continue;
}
return type;
Expand Down Expand Up @@ -230,6 +247,19 @@ public boolean isStackOnSpawn() {
return getBoolean("stack.on-spawn");
}

private boolean isEntityTypeInList(EntityType type, String path) {
ConfigList list = getList(type, path);
for (EntityGrouping entityGrouping : EntityGrouping.values()) {
if (!list.contains(entityGrouping.toString())) {
continue;
}
if (entityGrouping.isEntityMemberOf(type.getEntityClass())) {
return true;
}
}
return list.contains(type);
}

@Override
public void updateFile() throws IOException {
if (isSet("check-area.x")) {
Expand All @@ -241,4 +271,26 @@ public void updateFile() throws IOException {
super.updateFile();
}

enum EntityGrouping {
HOSTILE(Monster.class, Ghast.class, Phantom.class),
ANIMALS(Animals.class),
WATER(WaterMob.class),
RAIDER(Raider.class),
BOSS(Boss.class);

Class<? extends Entity>[] classes;
EntityGrouping(Class<? extends Entity>... classes) {
this.classes = classes;
}

public boolean isEntityMemberOf(Class<? extends Entity> entity) {
for (Class<? extends Entity> entityClass : classes) {
if (entityClass.isAssignableFrom(entity)) {
return true;
}
}
return false;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public SpecialConfigFile(StackMob sm, String filePath) {
public ConfigList getList(EntityType type, String path) {
ConfigValue configValue = get(type, path);
configValue = configValue.getValue() instanceof List<?> ? configValue : new ConfigValue(path, Collections.emptyList());
return ConfigList.getConfigList(this, configValue);
boolean inverted = getBoolean(path + "-invert");
return new ConfigList(this, (List<?>) configValue.getValue(), path, inverted);
}

public boolean getBoolean(EntityType type, String path) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/uk/antiperson/stackmob/entity/Drops.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public Map<ItemStack, Integer> calculateDrops(int deathAmount, List<ItemStack> o
if (!sm.getMainConfig().isDropMultiEnabled(dead.getType())) {
return items;
}
if (sm.getMainConfig().getDropTypeBlacklist(dead.getType()).contains(dead.getType().toString())) {
if (sm.getMainConfig().isDropTypeBlacklist(dead.getType())) {
return items;
}
EntityDamageEvent lastDamageCause = dead.getLastDamageCause();
if (lastDamageCause == null || sm.getMainConfig().getDropReasonBlacklist(dead.getType()).contains(lastDamageCause.getCause().toString())) {
if (lastDamageCause == null || sm.getMainConfig().isDropReasonBlacklist(dead.getType(), lastDamageCause.getCause())) {
return items;
}
boolean useLootTables = sm.getMainConfig().isDropLootTables(dead.getType());
Expand Down Expand Up @@ -102,7 +102,7 @@ public int calculateDeathExperience(int deadCount, int exp) {
if (!sm.getMainConfig().isExpMultiEnabled(dead.getType())) {
return exp;
}
if (sm.getMainConfig().getExpTypeBlacklist(dead.getType()).contains(dead.getType())) {
if (sm.getMainConfig().isExpTypeBlacklist(dead.getType())) {
return exp;
}
double minMulti = sm.getMainConfig().getExpMinBound(dead.getType()) * exp;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/uk/antiperson/stackmob/entity/StackEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ public boolean shouldWait(CreatureSpawnEvent.SpawnReason spawnReason) {
if (!sm.getMainConfig().isWaitingEnabled(getEntity().getType())) {
return false;
}
if (!sm.getMainConfig().getWaitingTypes(getEntity().getType()).contains(getEntity().getType().toString())) {
if (!sm.getMainConfig().isWaitingTypes(getEntity().getType())) {
return false;
}
return sm.getMainConfig().getWaitingReasons(getEntity().getType()).contains(spawnReason.toString());
return sm.getMainConfig().isWaitingReasons(getEntity().getType(), spawnReason);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public int calculateStep() {
public void onSpawn(StackEntity spawned) {
AttributeInstance attribute = getEntity().getAttribute(Attribute.GENERIC_MAX_HEALTH);
AttributeInstance spawnedAttribute = spawned.getEntity().getAttribute(Attribute.GENERIC_MAX_HEALTH);
double maxHealth = attribute.getValue();
double maxHealth = Math.min(attribute.getValue(), attribute.getDefaultValue());
StackableMobHook smh = sm.getHookManager().getApplicableHook(spawned);
if (smh instanceof MythicMobsStackHook) {
sm.getServer().getScheduler().runTaskLater(sm, bukkitTask -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public void onMobTarget(EntityTargetEvent event) {
if (!sm.getEntityManager().isStackedEntity((LivingEntity) event.getEntity())){
return;
}
if (sm.getMainConfig().getTargetingDisabledTypes(event.getEntityType()).contains(event.getEntityType().toString())) {
if (sm.getMainConfig().isTargetingDisabledTypes(event.getEntityType())) {
return;
}
if (Utilities.isPaper() && sm.getMainConfig().getTargetingDisabledReasons(event.getEntityType()).contains(event.getEntity().getEntitySpawnReason())){
if (Utilities.isPaper() && sm.getMainConfig().isTargetingDisabledReasons(event.getEntityType(), event.getEntity().getEntitySpawnReason())){
return;
}
event.setCancelled(true);
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/uk/antiperson/stackmob/tasks/TagTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void run() {
double searchX = searchRadius[0];
double searchY = searchRadius[1];
double searchZ = searchRadius[2];
boolean rayTrace = sm.getMainConfig().isTagNearbyRayTrace();
for (Player player : Bukkit.getOnlinePlayers()) {
List<Entity> entities = player.getNearbyEntities(searchX * 1.5, searchY * 1.5, searchZ * 1.5);
for (Entity entity : entities) {
Expand All @@ -52,13 +53,22 @@ public void run() {
double zDiff = Math.abs(player.getLocation().getZ() - entity.getLocation().getZ());
if (xDiff < searchX && yDiff < searchY && zDiff < searchZ) {
// Player should be shown tag
stackEntity.getTag().sendPacket(player, true);
continue;
if (!rayTrace || rayTrace((Mob) entity, player)) {
stackEntity.getTag().sendPacket(player, true);
continue;
}
}
// Player should not be shown tag
stackEntity.getTag().sendPacket(player, false);
}
}
}

private boolean rayTrace(Mob entity, Player player) {
Vector resultant = entity.getEyeLocation().toVector().subtract(player.getEyeLocation().toVector());
double distance = player.getEyeLocation().distance(entity.getEyeLocation());
RayTraceResult result = player.getWorld().rayTraceBlocks(player.getEyeLocation(), resultant, distance, FluidCollisionMode.NEVER, true);
return result == null || result.getHitBlock() == null;
}

}
12 changes: 8 additions & 4 deletions src/main/java/uk/antiperson/stackmob/utils/ItemTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@
import uk.antiperson.stackmob.StackMob;

import java.util.Arrays;
import java.util.List;

public class ItemTools {

public static final String ITEM_NAME = ChatColor.GOLD + "The Stick Of Stacking";
public static final List<String> ITEM_LORE = Arrays.asList(ChatColor.GREEN + "A useful tool for modifying stacked mobs.",
ChatColor.GOLD + "Right click to perform action" ,
ChatColor.GOLD + "Shift-right click to change mode.");

private final StackMob sm;
public ItemTools(StackMob sm) {
this.sm = sm;
Expand All @@ -22,10 +28,8 @@ public ItemStack createStackingTool() {
ItemStack is = new ItemStack(Material.BONE, 1);
is.addUnsafeEnchantment(Enchantment.ARROW_KNOCKBACK, 100);
ItemMeta itemMeta = is.getItemMeta();
itemMeta.setDisplayName(ChatColor.GOLD + "The Stick Of Stacking");
itemMeta.setLore(Arrays.asList(ChatColor.GREEN + "A useful tool for modifying stacked mobs.",
ChatColor.GOLD + "Right click to perform action" ,
ChatColor.GOLD + "Shift-right click to change mode."));
itemMeta.setDisplayName(ITEM_NAME);
itemMeta.setLore(ITEM_LORE);
itemMeta.getPersistentDataContainer().set(sm.getToolKey(), PersistentDataType.INTEGER, 1);
is.setItemMeta(itemMeta);
return is;
Expand Down
Loading

0 comments on commit 1001b47

Please sign in to comment.