Compare commits
12
Commits
fb2bbb70d4
...
test
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3da2b37aed | ||
|
|
e8b926ab41 | ||
|
|
f36bc6fc7f | ||
|
|
f3fa8563e6 | ||
|
|
07b5010f74 | ||
|
|
153543fb1f | ||
|
|
d29c3eb3c3 | ||
|
|
4937b6e337 | ||
|
|
77f9cfe0a6 | ||
|
|
c8cb2309f6 | ||
|
|
73cfb772b1 | ||
|
|
941b7d0d8f |
@@ -30,7 +30,7 @@ public class Main extends JavaPlugin {
|
|||||||
public void reloadConfigs() {
|
public void reloadConfigs() {
|
||||||
Config.reload();
|
Config.reload();
|
||||||
Messages.reload();
|
Messages.reload();
|
||||||
MobTypes.reload();
|
MobTypes.reload(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
package com.alttd.custommobs.abilities.modifiers;
|
|
||||||
|
|
||||||
import com.alttd.custommobs.abilities.EntityModifier;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.bukkit.attribute.Attribute;
|
|
||||||
import org.bukkit.attribute.AttributeInstance;
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
public class AttributeModifier implements EntityModifier {
|
|
||||||
|
|
||||||
private final double value;
|
|
||||||
private final Attribute attribute;
|
|
||||||
|
|
||||||
public AttributeModifier(Attribute attribute, double value) {
|
|
||||||
this.value = value;
|
|
||||||
this.attribute = attribute;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply(LivingEntity entity) {
|
|
||||||
AttributeInstance attributeInstance = entity.getAttribute(attribute);
|
|
||||||
if (attributeInstance == null) {
|
|
||||||
log.warn("Entity {} has no {} attribute", entity.getName(), attribute.name());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
attributeInstance.setBaseValue(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return attribute.name();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.alttd.custommobs.abilities.modifiers;
|
||||||
|
|
||||||
|
import com.alttd.custommobs.Main;
|
||||||
|
import com.alttd.custommobs.abilities.EntityModifier;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
|
import org.bukkit.attribute.AttributeModifier;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class EntityAttributeModifier implements EntityModifier {
|
||||||
|
|
||||||
|
private final double value;
|
||||||
|
private final Attribute attribute;
|
||||||
|
private final Main main;
|
||||||
|
|
||||||
|
public EntityAttributeModifier(Main main, Attribute attribute, double value) {
|
||||||
|
this.main = main;
|
||||||
|
this.value = value;
|
||||||
|
this.attribute = attribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(LivingEntity entity) {
|
||||||
|
log.info("DEBUG: Setting attribute {} to {}", attribute.name(), value);
|
||||||
|
AttributeInstance attributeInstance = entity.getAttribute(attribute);
|
||||||
|
if (attributeInstance == null) {
|
||||||
|
log.warn("Entity {} has no {} attribute", entity.getName(), attribute.name());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.info("DEBUG: Setting attribute {} to {}", attribute.name(), value);
|
||||||
|
NamespacedKey namespacedKey = NamespacedKey.fromString("cm", main);
|
||||||
|
if (namespacedKey == null) {
|
||||||
|
log.error("Namespaced key was null when applying attribute modifier");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AttributeModifier attributeModifier = new AttributeModifier(namespacedKey,
|
||||||
|
attributeInstance.getValue() - value,
|
||||||
|
AttributeModifier.Operation.ADD_NUMBER);
|
||||||
|
attributeInstance.addModifier(attributeModifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return attribute.name();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -44,7 +44,7 @@ public class AbilityMob implements Runnable {
|
|||||||
if (mob.isDead()) {
|
if (mob.isDead()) {
|
||||||
cancelTask();
|
cancelTask();
|
||||||
if (Config.SETTINGS.DEBUG) {
|
if (Config.SETTINGS.DEBUG) {
|
||||||
log.debug("Entity died, cancelling ability task");
|
log.info("DEBUG: Entity died, cancelling ability task");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class AbilityThread {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (tasksMap.containsKey(identifier)) {
|
if (tasksMap.containsKey(identifier)) {
|
||||||
log.debug("Already scheduled task with identifier {}, skipping", identifier);
|
log.info("DEBUG: Already scheduled task with identifier {}, skipping", identifier);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Future<?> future = executorService.submit(() -> {
|
Future<?> future = executorService.submit(() -> {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.alttd.custommobs.commands.subcommands;
|
package com.alttd.custommobs.commands.subcommands;
|
||||||
|
|
||||||
import com.alttd.custommobs.Main;
|
import com.alttd.custommobs.Main;
|
||||||
|
import com.alttd.custommobs.abilities.EntityModifier;
|
||||||
import com.alttd.custommobs.abilities.MobType;
|
import com.alttd.custommobs.abilities.MobType;
|
||||||
import com.alttd.custommobs.abilities.MobTypeApplier;
|
import com.alttd.custommobs.abilities.MobTypeApplier;
|
||||||
import com.alttd.custommobs.commands.SubCommand;
|
import com.alttd.custommobs.commands.SubCommand;
|
||||||
@@ -17,6 +18,7 @@ import org.bukkit.entity.*;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class Spawn extends SubCommand {
|
public class Spawn extends SubCommand {
|
||||||
@@ -30,7 +32,7 @@ public class Spawn extends SubCommand {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||||
if (args.length != 3 && args.length != 7) {
|
if (args.length != 3 && args.length != 7) {
|
||||||
log.debug("Invalid argument length: {} expected 2 or 6", args.length);
|
log.info("DEBUG: Invalid argument length: {} expected 2 or 6", args.length);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Optional<MobType> optionalMobType = MobTypes.MOB_TYPES.get(args[1]);
|
Optional<MobType> optionalMobType = MobTypes.MOB_TYPES.get(args[1]);
|
||||||
@@ -43,7 +45,7 @@ public class Spawn extends SubCommand {
|
|||||||
try {
|
try {
|
||||||
entityType = EntityType.valueOf(args[2]);
|
entityType = EntityType.valueOf(args[2]);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
log.debug("Invalid mob type {}", args[2]);
|
log.info("DEBUG: Invalid mob type {}", args[2]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!entityType.isSpawnable() || !isMob(entityType)) {
|
if (!entityType.isSpawnable() || !isMob(entityType)) {
|
||||||
@@ -66,7 +68,7 @@ public class Spawn extends SubCommand {
|
|||||||
} else if (args.length == 7) {
|
} else if (args.length == 7) {
|
||||||
return getLocation(args);
|
return getLocation(args);
|
||||||
} else {
|
} else {
|
||||||
log.debug("Expected player with argument length of 2");
|
log.info("DEBUG: Expected player with argument length of 2");
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,7 +84,7 @@ public class Spawn extends SubCommand {
|
|||||||
double z = Double.parseDouble(args[6]);
|
double z = Double.parseDouble(args[6]);
|
||||||
return Optional.of(new Location(world, x, y, z));
|
return Optional.of(new Location(world, x, y, z));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
log.debug("Invalid coordinates x: {}, y: {}, z: {}", args[4], args[5], args[6]);
|
log.info("DEBUG: Invalid coordinates x: {}, y: {}, z: {}", args[4], args[5], args[6]);
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,16 +106,23 @@ public class Spawn extends SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void spawnMob(World world, Location location, EntityType entityType, MobType mobType) {
|
private void spawnMob(World world, Location location, EntityType entityType, MobType mobType) {
|
||||||
|
log.info("one");
|
||||||
|
log.info(mobType.toString());
|
||||||
|
log.info(mobType.entityModifiers().stream().map(EntityModifier::getName).collect(Collectors.joining(", ")));
|
||||||
if (entityType.getEntityClass() == null) {
|
if (entityType.getEntityClass() == null) {
|
||||||
log.warn("Tried to spawn entity with null entity class {}", entityType.name());
|
log.warn("Tried to spawn entity with null entity class {}", entityType.name());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
log.info("two");
|
||||||
Entity entity = world.spawn(location, entityType.getEntityClass());
|
Entity entity = world.spawn(location, entityType.getEntityClass());
|
||||||
|
log.info("three");
|
||||||
if (!(entity instanceof LivingEntity livingEntity)) {
|
if (!(entity instanceof LivingEntity livingEntity)) {
|
||||||
log.warn("Spawned entity is not a living entity? {}", entityType.name());
|
log.warn("Spawned entity is not a living entity? {}", entityType.name());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
log.info("four");
|
||||||
mobTypeApplier.apply(livingEntity, mobType);
|
mobTypeApplier.apply(livingEntity, mobType);
|
||||||
|
log.info("five");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package com.alttd.custommobs.config;
|
package com.alttd.custommobs.config;
|
||||||
|
|
||||||
|
import com.alttd.custommobs.Main;
|
||||||
import com.alttd.custommobs.abilities.Ability;
|
import com.alttd.custommobs.abilities.Ability;
|
||||||
import com.alttd.custommobs.abilities.modifiers.AttributeModifier;
|
import com.alttd.custommobs.abilities.modifiers.EntityAttributeModifier;
|
||||||
import com.alttd.custommobs.abilities.EntityModifier;
|
import com.alttd.custommobs.abilities.EntityModifier;
|
||||||
import com.alttd.custommobs.abilities.MobType;
|
import com.alttd.custommobs.abilities.MobType;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
@@ -16,19 +17,21 @@ import java.util.*;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class MobTypes extends AbstractConfig {
|
public class MobTypes extends AbstractConfig {
|
||||||
static MobTypes config;
|
static MobTypes config;
|
||||||
|
private final Main main;
|
||||||
|
|
||||||
MobTypes() {
|
MobTypes(Main main) {
|
||||||
super(
|
super(
|
||||||
new File(File.separator
|
new File(File.separator
|
||||||
+ "mnt" + File.separator
|
+ "mnt" + File.separator
|
||||||
+ "configs" + File.separator
|
+ "configs" + File.separator
|
||||||
+ "custommobs"),
|
+ "custommobs"),
|
||||||
"mob-types.yml");
|
"mob-types.yml");
|
||||||
|
this.main = main;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reload() {
|
public static void reload(Main main) {
|
||||||
log.info("Reloading mob types");
|
log.info("Reloading mob types");
|
||||||
config = new MobTypes();
|
config = new MobTypes(main);
|
||||||
config.readConfig(MobTypes.class, null);
|
config.readConfig(MobTypes.class, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,37 +53,56 @@ public class MobTypes extends AbstractConfig {
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static void load() {
|
private static void load() {
|
||||||
MOB_TYPES.clear();
|
MOB_TYPES.clear();
|
||||||
|
log.info("Loading mob types");
|
||||||
ConfigurationSection configurationSection = config.getConfigurationSection(prefix.substring(0, prefix.length() - 1));
|
ConfigurationSection configurationSection = config.getConfigurationSection(prefix.substring(0, prefix.length() - 1));
|
||||||
if (configurationSection == null) {
|
if (configurationSection == null) {
|
||||||
log.warn("No config section found for {}", prefix.substring(0, prefix.length() - 1));
|
log.warn("No config section found for {}", prefix.substring(0, prefix.length() - 1));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
log.info("1");
|
||||||
Set<String> keys = configurationSection.getKeys(false);
|
Set<String> keys = configurationSection.getKeys(false);
|
||||||
|
log.info("2");
|
||||||
keys.forEach(key -> {
|
keys.forEach(key -> {
|
||||||
List<Ability> abilities = config.getStringList(prefix + key, ".abilities", List.of()).stream()
|
List<Ability> abilities = config.getStringList(prefix + key, ".abilities", List.of()).stream()
|
||||||
.map(MobTypes.MOB_TYPES::getAbility)
|
.map(MobTypes.MOB_TYPES::getAbility)
|
||||||
.filter(Optional::isPresent)
|
.filter(Optional::isPresent)
|
||||||
.map(Optional::get)
|
.map(Optional::get)
|
||||||
.toList();
|
.toList();
|
||||||
|
log.info("3");
|
||||||
List<EntityModifier> entityModifiers = new ArrayList<>();
|
List<EntityModifier> entityModifiers = new ArrayList<>();
|
||||||
|
log.info("4");
|
||||||
config.getConfigurationSection(prefix + key + ".modifiers").getKeys(false).forEach(modifier -> {
|
config.getConfigurationSection(prefix + key + ".modifiers").getKeys(false).forEach(modifier -> {
|
||||||
String attribute = config.getString(prefix + key + ".modifiers." + modifier, "attribute", null);
|
log.info("{}{}.modifiers.{}", prefix, key, modifier);
|
||||||
|
log.info("5 {}", modifier);
|
||||||
|
String attribute = config.getString(String.format("%s%s.modifiers.%s.", prefix, key, modifier), "attribute", null);
|
||||||
|
log.info("6");
|
||||||
if (attribute == null) {
|
if (attribute == null) {
|
||||||
|
log.info("RETURN (7)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EntityModifier value = getAttribute(attribute, config.getDouble(prefix + key + ".modifiers." + modifier, "value", 1));
|
log.info("8");
|
||||||
if (value == null)
|
EntityModifier value = getAttribute(attribute, config.getDouble(String.format("%s%s.modifiers.%s.", prefix, key, modifier), "value", 1));
|
||||||
|
log.info("9");
|
||||||
|
if (value == null) {
|
||||||
|
log.info("RETURN (10)");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
log.info("11");
|
||||||
entityModifiers.add(value);
|
entityModifiers.add(value);
|
||||||
});
|
});
|
||||||
|
log.info("12");
|
||||||
MOB_TYPES.put(key, new MobType(abilities, entityModifiers));
|
MOB_TYPES.put(key, new MobType(abilities, entityModifiers));
|
||||||
|
log.info("13");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static EntityModifier getAttribute(String attributeName, double value) {
|
private static EntityModifier getAttribute(String attributeName, double value) {
|
||||||
try {
|
try {
|
||||||
Attribute attribute = Attribute.valueOf(attributeName);
|
Attribute attribute = Attribute.valueOf(attributeName);
|
||||||
return new AttributeModifier(attribute, value);
|
log.info("DEBUG in case replacements break");
|
||||||
|
log.info("DEBUG: {}", attributeName);
|
||||||
|
log.info("DEBUG: {}", attribute.name());
|
||||||
|
return new EntityAttributeModifier(config.main, attribute, value);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
log.error("Invalid attribute {}", attributeName, e);
|
log.error("Invalid attribute {}", attributeName, e);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class SpawnableTargetBlock {
|
|||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Block block = iter.next();
|
Block block = iter.next();
|
||||||
if (isSpawnable(block)) {
|
if (isSpawnable(block)) {
|
||||||
return Optional.of(block.getLocation());
|
return Optional.of(block.getLocation().add(0, 1, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|||||||
Reference in New Issue
Block a user