fixes from first testrun
This commit is contained in:
parent
64c0ce3a0a
commit
e47794ab07
1
pom.xml
1
pom.xml
@ -40,7 +40,6 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<minimizeJar>true</minimizeJar>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
@ -10,7 +10,6 @@ import net.kyori.adventure.text.format.TextColor;
|
|||||||
import net.kyori.adventure.text.format.TextDecoration;
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@ -38,25 +37,25 @@ public final class VillagerOptimizer extends JavaPlugin {
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
instance = this;
|
||||||
logger = getLogger();
|
logger = getLogger();
|
||||||
ConsoleCommandSender console = getServer().getConsoleSender();
|
getServer().getConsoleSender().sendMessage(Component.text(
|
||||||
console.sendMessage(Component.text(
|
|
||||||
"""
|
"""
|
||||||
\s
|
\s
|
||||||
_ __ _ __ __ ____ __ _ _ \s
|
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
||||||
| | / /(_)/ // /____ _ ____ _ ___ _____ / __ \\ ____ / /_ (_)____ ___ (_)____ ___ _____
|
┃ _ __ _ __ __ ____ __ _ _ ┃\s
|
||||||
| | / // // // // __ `// __ `// _ \\ / ___// / / // __ \\ / __// // __ `__ \\ / //_ / / _ \\ / ___/
|
┃ | | / /(_)/ // /____ _ ____ _ ___ _____ / __ \\ ____ / /_ (_)____ ___ (_)____ ___ _____ ┃\s
|
||||||
| |/ // // // // /_/ // /_/ // __// / / /_/ // /_/ // /_ / // / / / / // / / /_/ __// / \s
|
┃ | | / // // // // __ `// __ `// _ \\ / ___// / / // __ \\ / __// // __ `__ \\ / //_ / / _ \\ / ___/ ┃\s
|
||||||
|___//_//_//_/ \\__,_/ \\__, / \\___//_/ \\____// .___/ \\__//_//_/ /_/ /_//_/ /___/\\___//_/ \s
|
┃ | |/ // // // // /_/ // /_/ // __// / / /_/ // /_/ // /_ / // / / / / // / / /_/ __// / ┃\s
|
||||||
/____/ /_/ by xGinko \s
|
┃ |___//_//_//_/ \\__,_/ \\__, / \\___//_/ \\____// .___/ \\__//_//_/ /_/ /_//_/ /___/\\___//_/ ┃\s
|
||||||
"""
|
┃ /____/ /_/ by xGinko ┃\s
|
||||||
|
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"""
|
||||||
).color(TextColor.color(102,255,230)).decorate(TextDecoration.BOLD));
|
).color(TextColor.color(102,255,230)).decorate(TextDecoration.BOLD));
|
||||||
console.sendMessage(Component.text("Loading Translations...").color(TextColor.color(102,255,230)));
|
logger.info("Loading Translations...");
|
||||||
reloadLang();
|
reloadLang();
|
||||||
console.sendMessage(Component.text("Loading Config...").color(TextColor.color(102,255,230)));
|
logger.info("Loading Config...");
|
||||||
reloadConfiguration();
|
reloadConfiguration();
|
||||||
console.sendMessage(Component.text("Registering Commands...").color(TextColor.color(102,255,230)));
|
logger.info("Registering Commands...");
|
||||||
VillagerOptimizerCommand.reloadCommands();
|
VillagerOptimizerCommand.reloadCommands();
|
||||||
console.sendMessage(Component.text("Done.").color(TextColor.color(102,255,230)));
|
logger.info("Done.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static VillagerOptimizer getInstance() {
|
public static VillagerOptimizer getInstance() {
|
||||||
|
@ -43,7 +43,7 @@ public class OptVillagersRadius implements VillagerOptimizerCommand, TabComplete
|
|||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||||
if (sender.hasPermission(Permissions.Commands.OPTIMIZE_RADIUS.get())) {
|
if (sender.hasPermission(Permissions.Commands.OPTIMIZE_RADIUS.get())) {
|
||||||
if (!(sender instanceof Player player)) {
|
if (!(sender instanceof Player player)) {
|
||||||
sender.sendMessage(Component.text("This command can only be executed as a player.")
|
sender.sendMessage(Component.text("This command can only be executed by a player.")
|
||||||
.color(NamedTextColor.RED).decorate(TextDecoration.BOLD));
|
.color(NamedTextColor.RED).decorate(TextDecoration.BOLD));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -77,12 +77,14 @@ public class OptVillagersRadius implements VillagerOptimizerCommand, TabComplete
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final String success = Integer.toString(successCount);
|
if (successCount > 0) {
|
||||||
final String radius = Integer.toString(specifiedRadius);
|
final String success = Integer.toString(successCount);
|
||||||
VillagerOptimizer.getLang(player.locale()).command_optimize_success.forEach(line -> player.sendMessage(line
|
final String radius = Integer.toString(specifiedRadius);
|
||||||
.replaceText(TextReplacementConfig.builder().matchLiteral("%amount%").replacement(success).build())
|
VillagerOptimizer.getLang(player.locale()).command_optimize_success.forEach(line -> player.sendMessage(line
|
||||||
.replaceText(TextReplacementConfig.builder().matchLiteral("%radius%").replacement(radius).build())
|
.replaceText(TextReplacementConfig.builder().matchLiteral("%amount%").replacement(success).build())
|
||||||
));
|
.replaceText(TextReplacementConfig.builder().matchLiteral("%radius%").replacement(radius).build())
|
||||||
|
));
|
||||||
|
}
|
||||||
if (failCount > 0) {
|
if (failCount > 0) {
|
||||||
final String alreadyOptimized = Integer.toString(failCount);
|
final String alreadyOptimized = Integer.toString(failCount);
|
||||||
VillagerOptimizer.getLang(player.locale()).command_optimize_fail.forEach(line -> player.sendMessage(line
|
VillagerOptimizer.getLang(player.locale()).command_optimize_fail.forEach(line -> player.sendMessage(line
|
||||||
|
@ -34,7 +34,7 @@ public class UnOptVillagersRadius implements VillagerOptimizerCommand {
|
|||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||||
if (sender.hasPermission(Permissions.Commands.UNOPTIMIZE_RADIUS.get())) {
|
if (sender.hasPermission(Permissions.Commands.UNOPTIMIZE_RADIUS.get())) {
|
||||||
if (!(sender instanceof Player player)) {
|
if (!(sender instanceof Player player)) {
|
||||||
sender.sendMessage(Component.text("This command can only be executed as a player.")
|
sender.sendMessage(Component.text("This command can only be executed by a player.")
|
||||||
.color(NamedTextColor.RED).decorate(TextDecoration.BOLD));
|
.color(NamedTextColor.RED).decorate(TextDecoration.BOLD));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -63,12 +63,12 @@ public class VillagerOptimizerCmd implements TabCompleter, VillagerOptimizerComm
|
|||||||
subCommands.forEach(subCommand -> sender.sendMessage(
|
subCommands.forEach(subCommand -> sender.sendMessage(
|
||||||
subCommand.getSyntax().append(Component.text(" - ").color(NamedTextColor.DARK_GRAY)).append(subCommand.getDescription())));
|
subCommand.getSyntax().append(Component.text(" - ").color(NamedTextColor.DARK_GRAY)).append(subCommand.getDescription())));
|
||||||
sender.sendMessage(
|
sender.sendMessage(
|
||||||
Component.text("/optimizevillagers <message>").color(NamedTextColor.BLUE)
|
Component.text("/optimizevillagers <blockradius>").color(NamedTextColor.BLUE)
|
||||||
.append(Component.text(" - ").color(NamedTextColor.DARK_GRAY))
|
.append(Component.text(" - ").color(NamedTextColor.DARK_GRAY))
|
||||||
.append(Component.text("Optimize villagers in a radius").color(NamedTextColor.GRAY))
|
.append(Component.text("Optimize villagers in a radius").color(NamedTextColor.GRAY))
|
||||||
);
|
);
|
||||||
sender.sendMessage(
|
sender.sendMessage(
|
||||||
Component.text("/unoptmizevillagers").color(NamedTextColor.BLUE)
|
Component.text("/unoptmizevillagers <blockradius>").color(NamedTextColor.BLUE)
|
||||||
.append(Component.text(" - ").color(NamedTextColor.DARK_GRAY))
|
.append(Component.text(" - ").color(NamedTextColor.DARK_GRAY))
|
||||||
.append(Component.text("Unoptimize villagers in a radius").color(NamedTextColor.GRAY))
|
.append(Component.text("Unoptimize villagers in a radius").color(NamedTextColor.GRAY))
|
||||||
);
|
);
|
||||||
|
@ -22,19 +22,23 @@ public class VersionSubCmd extends SubCommand {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public TextComponent getSyntax() {
|
public TextComponent getSyntax() {
|
||||||
return Component.text("/villageroptimizer version").color(NamedTextColor.GOLD);
|
return Component.text("/villageroptimizer version").color(NamedTextColor.BLUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void perform(CommandSender sender, String[] args) {
|
public void perform(CommandSender sender, String[] args) {
|
||||||
if (sender.hasPermission(Permissions.Commands.VERSION.get())) {
|
if (sender.hasPermission(Permissions.Commands.VERSION.get())) {
|
||||||
PluginMeta pluginMeta = VillagerOptimizer.getInstance().getPluginMeta();
|
final PluginMeta pluginMeta = VillagerOptimizer.getInstance().getPluginMeta();
|
||||||
sender.sendMessage(
|
sender.sendMessage(
|
||||||
Component.newline()
|
Component.newline()
|
||||||
.append(Component.text(pluginMeta.getName()+" "+pluginMeta.getVersion()).color(NamedTextColor.BLUE).decorate(TextDecoration.BOLD)
|
.append(Component.text(pluginMeta.getName()+" "+pluginMeta.getVersion())
|
||||||
.append(Component.text(" by ").color(NamedTextColor.GRAY))
|
.color(NamedTextColor.BLUE).decorate(TextDecoration.BOLD)
|
||||||
.append(Component.text(pluginMeta.getAuthors().get(0)).color(NamedTextColor.WHITE))
|
.clickEvent(ClickEvent.openUrl(pluginMeta.getWebsite())))
|
||||||
.clickEvent(ClickEvent.openUrl(pluginMeta.getWebsite())))
|
.append(Component.text(" by ")
|
||||||
|
.color(NamedTextColor.GRAY))
|
||||||
|
.append(Component.text(pluginMeta.getAuthors().get(0))
|
||||||
|
.color(NamedTextColor.WHITE)
|
||||||
|
.clickEvent(ClickEvent.openUrl("https://github.com/xGinko")))
|
||||||
.append(Component.newline())
|
.append(Component.newline())
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -50,6 +50,13 @@ public class Config {
|
|||||||
config.addDefault("config-version", 1.00);
|
config.addDefault("config-version", 1.00);
|
||||||
createTitledSection("General", "general");
|
createTitledSection("General", "general");
|
||||||
createTitledSection("Optimization", "optimization");
|
createTitledSection("Optimization", "optimization");
|
||||||
|
config.addDefault("optimization.villager-chunk-limit.enable", false);
|
||||||
|
config.addDefault("optimization.prevent-trading-with-unoptimized.enable", false);
|
||||||
|
config.addDefault("optimization.methods.by-nametag.enable", true);
|
||||||
|
config.addDefault("optimization.behavior.villager-leveling.enable", true);
|
||||||
|
config.addDefault("optimization.behavior.trade-restocking.enable", true);
|
||||||
|
config.addDefault("optimization.behavior.prevent-targeting.enable", true);
|
||||||
|
config.addDefault("optimization.behavior.prevent-damage.enable", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createTitledSection(String title, String path) {
|
public void createTitledSection(String title, String path) {
|
||||||
|
@ -37,6 +37,7 @@ public class BlockOptimization implements VillagerOptimizerModule, Listener {
|
|||||||
private final long cooldown;
|
private final long cooldown;
|
||||||
|
|
||||||
protected BlockOptimization() {
|
protected BlockOptimization() {
|
||||||
|
shouldEnable();
|
||||||
this.villagerManager = VillagerOptimizer.getVillagerManager();
|
this.villagerManager = VillagerOptimizer.getVillagerManager();
|
||||||
Config config = VillagerOptimizer.getConfiguration();
|
Config config = VillagerOptimizer.getConfiguration();
|
||||||
config.addComment("optimization.methods.by-specific-block.enable", """
|
config.addComment("optimization.methods.by-specific-block.enable", """
|
||||||
@ -61,7 +62,8 @@ public class BlockOptimization implements VillagerOptimizerModule, Listener {
|
|||||||
""") * 1000L;
|
""") * 1000L;
|
||||||
this.maxVillagers = config.getInt("optimization.methods.by-specific-block.max-villagers-per-block", 3,
|
this.maxVillagers = config.getInt("optimization.methods.by-specific-block.max-villagers-per-block", 3,
|
||||||
"How many villagers can be optimized at once by placing a block under them.");
|
"How many villagers can be optimized at once by placing a block under them.");
|
||||||
this.shouldNotifyPlayer = config.getBoolean("optimization.methods.by-specific-block.notify-player", true);
|
this.shouldNotifyPlayer = config.getBoolean("optimization.methods.by-specific-block.notify-player", true,
|
||||||
|
"Sends players a message when they successfully optimized a villager.");
|
||||||
this.shouldLog = config.getBoolean("optimization.methods.by-specific-block.log", false);
|
this.shouldLog = config.getBoolean("optimization.methods.by-specific-block.log", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,18 +25,17 @@ public class LevelVillagers implements VillagerOptimizerModule, Listener {
|
|||||||
private final long cooldown;
|
private final long cooldown;
|
||||||
|
|
||||||
public LevelVillagers() {
|
public LevelVillagers() {
|
||||||
|
shouldEnable();
|
||||||
this.plugin = VillagerOptimizer.getInstance();
|
this.plugin = VillagerOptimizer.getInstance();
|
||||||
this.villagerManager = VillagerOptimizer.getVillagerManager();
|
this.villagerManager = VillagerOptimizer.getVillagerManager();
|
||||||
Config config = VillagerOptimizer.getConfiguration();
|
Config config = VillagerOptimizer.getConfiguration();
|
||||||
config.addComment("optimization.villager-leveling.enable", """
|
config.addComment("optimization.behavior.villager-leveling.enable", """
|
||||||
This is needed to allow optimized villagers to level up. s\
|
This is needed to allow optimized villagers to level up.\s
|
||||||
Temporarily enables the villagers AI to allow it to level up and then disables it again.
|
Temporarily enables the villagers AI to allow it to level up and then disables it again.""");
|
||||||
""");
|
this.cooldown = config.getInt("optimization.behavior.villager-leveling.level-check-cooldown-seconds", 5, """
|
||||||
this.cooldown = config.getInt("optimization.villager-leveling.level-check-cooldown-seconds", 5, """
|
Cooldown in seconds until the level of a villager will be checked and updated again.\s
|
||||||
Cooldown in seconds until the level of a villager will be checked and updated again. \s
|
Recommended to leave as is.""") * 1000L;
|
||||||
Recommended to leave as is.
|
this.shouldNotify = config.getBoolean("optimization.behavior.villager-leveling.notify-player", true,
|
||||||
""") * 1000L;
|
|
||||||
this.shouldNotify = config.getBoolean("optimization.villager-leveling.notify-player", true,
|
|
||||||
"Tell players to wait when a villager is leveling up.");
|
"Tell players to wait when a villager is leveling up.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +52,7 @@ public class LevelVillagers implements VillagerOptimizerModule, Listener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldEnable() {
|
public boolean shouldEnable() {
|
||||||
return VillagerOptimizer.getConfiguration().getBoolean("optimization.villager-leveling.enable", true);
|
return VillagerOptimizer.getConfiguration().getBoolean("optimization.behavior.villager-leveling.enable", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
|
@ -32,21 +32,21 @@ public class NametagOptimization implements VillagerOptimizerModule, Listener {
|
|||||||
private final long cooldown;
|
private final long cooldown;
|
||||||
|
|
||||||
protected NametagOptimization() {
|
protected NametagOptimization() {
|
||||||
|
shouldEnable();
|
||||||
this.villagerManager = VillagerOptimizer.getVillagerManager();
|
this.villagerManager = VillagerOptimizer.getVillagerManager();
|
||||||
Config config = VillagerOptimizer.getConfiguration();
|
Config config = VillagerOptimizer.getConfiguration();
|
||||||
config.addComment("optimization.methods.by-nametag.enable", """
|
config.addComment("optimization.methods.by-nametag.enable", """
|
||||||
Enable optimization by naming villagers to one of the names configured below.\s
|
Enable optimization by naming villagers to one of the names configured below.\s
|
||||||
Nametag optimized villagers will be unoptimized again when they are renamed to something else.
|
Nametag optimized villagers will be unoptimized again when they are renamed to something else.""");
|
||||||
""");
|
|
||||||
this.nametags.addAll(config.getList("optimization.methods.by-nametag.names", List.of("Optimize", "DisableAI"),
|
this.nametags.addAll(config.getList("optimization.methods.by-nametag.names", List.of("Optimize", "DisableAI"),
|
||||||
"Names are case insensitive, capital letters won't matter.").stream().map(String::toLowerCase).toList());
|
"Names are case insensitive, capital letters won't matter.").stream().map(String::toLowerCase).toList());
|
||||||
this.consumeNametag = config.getBoolean("optimization.methods.by-nametag.nametags-get-consumed", true,
|
this.consumeNametag = config.getBoolean("optimization.methods.by-nametag.nametags-get-consumed", true,
|
||||||
"Enable or disable consumption of the used nametag item.");
|
"Enable or disable consumption of the used nametag item.");
|
||||||
this.cooldown = config.getInt("optimization.methods.by-workstation.optimize-cooldown-seconds", 600, """
|
this.cooldown = config.getInt("optimization.methods.by-nametag.optimize-cooldown-seconds", 600, """
|
||||||
Cooldown in seconds until a villager can be optimized again using a nametag. \s
|
Cooldown in seconds until a villager can be optimized again using a nametag.\s
|
||||||
Here for configuration freedom. Recommended to leave as is to not enable any exploitable behavior.
|
Here for configuration freedom. Recommended to leave as is to not enable any exploitable behavior.""") * 1000L;
|
||||||
""") * 1000L;
|
this.shouldNotifyPlayer = config.getBoolean("optimization.methods.by-nametag.notify-player", true,
|
||||||
this.shouldNotifyPlayer = config.getBoolean("optimization.methods.by-nametag.notify-player", true);
|
"Sends players a message when they successfully optimized a villager.");
|
||||||
this.shouldLog = config.getBoolean("optimization.methods.by-nametag.log", false);
|
this.shouldLog = config.getBoolean("optimization.methods.by-nametag.log", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,14 +20,15 @@ public class PreventUnoptimizedTrading implements VillagerOptimizerModule, Liste
|
|||||||
private final boolean notifyPlayer;
|
private final boolean notifyPlayer;
|
||||||
|
|
||||||
protected PreventUnoptimizedTrading() {
|
protected PreventUnoptimizedTrading() {
|
||||||
|
shouldEnable();
|
||||||
this.villagerManager = VillagerOptimizer.getVillagerManager();
|
this.villagerManager = VillagerOptimizer.getVillagerManager();
|
||||||
Config config = VillagerOptimizer.getConfiguration();
|
Config config = VillagerOptimizer.getConfiguration();
|
||||||
config.addComment("optimization.prevent-trading-with-unoptimized-villagers.enable", """
|
config.addComment("optimization.prevent-trading-with-unoptimized.enable", """
|
||||||
Will prevent players from selecting and using trades of unoptimized villagers. s\
|
Will prevent players from selecting and using trades of unoptimized villagers.\s
|
||||||
Use this if you have a lot of villagers and therefore want to force your players to optimize them. s\
|
Use this if you have a lot of villagers and therefore want to force your players to optimize them.\s
|
||||||
Inventories can still be opened so players can move villagers around.
|
Inventories can still be opened so players can move villagers around.""");
|
||||||
""");
|
this.notifyPlayer = config.getBoolean("optimization.prevent-trading-with-unoptimized.notify-player", true,
|
||||||
this.notifyPlayer = config.getBoolean("optimization.prevent-trading-with-unoptimized-villagers.notify-player", true);
|
"Sends players a message when they try to trade with an unoptimized villager.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -43,7 +44,7 @@ public class PreventUnoptimizedTrading implements VillagerOptimizerModule, Liste
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldEnable() {
|
public boolean shouldEnable() {
|
||||||
return VillagerOptimizer.getConfiguration().getBoolean("optimization.prevent-trading-with-unoptimized-villagers.enable", false);
|
return VillagerOptimizer.getConfiguration().getBoolean("optimization.prevent-trading-with-unoptimized.enable", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
|
@ -3,20 +3,39 @@ package me.xginko.villageroptimizer.modules;
|
|||||||
import io.papermc.paper.event.entity.EntityPushedByEntityAttackEvent;
|
import io.papermc.paper.event.entity.EntityPushedByEntityAttackEvent;
|
||||||
import me.xginko.villageroptimizer.VillagerOptimizer;
|
import me.xginko.villageroptimizer.VillagerOptimizer;
|
||||||
import me.xginko.villageroptimizer.cache.VillagerManager;
|
import me.xginko.villageroptimizer.cache.VillagerManager;
|
||||||
|
import me.xginko.villageroptimizer.config.Config;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Mob;
|
||||||
import org.bukkit.entity.Villager;
|
import org.bukkit.entity.Villager;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
|
||||||
public class PreventVillagerDamage implements VillagerOptimizerModule, Listener {
|
public class PreventVillagerDamage implements VillagerOptimizerModule, Listener {
|
||||||
|
|
||||||
private final VillagerManager villagerManager;
|
private final VillagerManager villagerManager;
|
||||||
|
private final boolean block, player, mob, other, push;
|
||||||
|
|
||||||
protected PreventVillagerDamage() {
|
protected PreventVillagerDamage() {
|
||||||
|
shouldEnable();
|
||||||
this.villagerManager = VillagerOptimizer.getVillagerManager();
|
this.villagerManager = VillagerOptimizer.getVillagerManager();
|
||||||
|
Config config = VillagerOptimizer.getConfiguration();
|
||||||
|
config.addComment("optimization.behavior.prevent-damage.enable",
|
||||||
|
"Configure what kind of damage you want to cancel for optimized villagers here.");
|
||||||
|
this.block = config.getBoolean("optimization.behavior.prevent-damage.block", false,
|
||||||
|
"Prevents damage from blocks like lava, tnt, respawn anchors, etc.");
|
||||||
|
this.player = config.getBoolean("optimization.behavior.prevent-damage.player", false,
|
||||||
|
"Prevents damage from getting hit by players.");
|
||||||
|
this.mob = config.getBoolean("optimization.behavior.prevent-damage.mob", true,
|
||||||
|
"Prevents damage from hostile mobs.");
|
||||||
|
this.other = config.getBoolean("optimization.behavior.prevent-damage.other", true,
|
||||||
|
"Prevents damage from all other entities.");
|
||||||
|
this.push = config.getBoolean("optimization.behavior.prevent-damage.prevent-push-from-attack", true,
|
||||||
|
"Prevents optimized villagers from getting pushed by an attacking entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -32,13 +51,37 @@ public class PreventVillagerDamage implements VillagerOptimizerModule, Listener
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldEnable() {
|
public boolean shouldEnable() {
|
||||||
return VillagerOptimizer.getConfiguration().getBoolean("optimization.behavior.optimized-villagers-dont-take-damage", true);
|
return VillagerOptimizer.getConfiguration().getBoolean("optimization.behavior.prevent-damage.enable", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
private void onDamageReceive(EntityDamageEvent event) {
|
private void onDamageReceive(EntityDamageByEntityEvent event) {
|
||||||
if (
|
if (
|
||||||
!event.getEntityType().equals(EntityType.VILLAGER)
|
event.getEntityType().equals(EntityType.VILLAGER)
|
||||||
|
&& villagerManager.getOrAdd((Villager) event.getEntity()).isOptimized()
|
||||||
|
) {
|
||||||
|
Entity damager = event.getDamager();
|
||||||
|
if (damager.getType().equals(EntityType.PLAYER)) {
|
||||||
|
if (player) event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (damager instanceof Mob) {
|
||||||
|
if (mob) event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
private void onDamageReceive(EntityDamageByBlockEvent event) {
|
||||||
|
if (
|
||||||
|
block
|
||||||
|
&& event.getEntityType().equals(EntityType.VILLAGER)
|
||||||
&& villagerManager.getOrAdd((Villager) event.getEntity()).isOptimized()
|
&& villagerManager.getOrAdd((Villager) event.getEntity()).isOptimized()
|
||||||
) {
|
) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -48,7 +91,8 @@ public class PreventVillagerDamage implements VillagerOptimizerModule, Listener
|
|||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
private void onPushByEntityAttack(EntityPushedByEntityAttackEvent event) {
|
private void onPushByEntityAttack(EntityPushedByEntityAttackEvent event) {
|
||||||
if (
|
if (
|
||||||
!event.getEntityType().equals(EntityType.VILLAGER)
|
push
|
||||||
|
&& event.getEntityType().equals(EntityType.VILLAGER)
|
||||||
&& villagerManager.getOrAdd((Villager) event.getEntity()).isOptimized()
|
&& villagerManager.getOrAdd((Villager) event.getEntity()).isOptimized()
|
||||||
) {
|
) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
@ -35,7 +35,8 @@ public class PreventVillagerTargetting implements VillagerOptimizerModule, Liste
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldEnable() {
|
public boolean shouldEnable() {
|
||||||
return VillagerOptimizer.getConfiguration().getBoolean("optimization.behavior.optimized-villagers-dont-get-targeted", true);
|
return VillagerOptimizer.getConfiguration().getBoolean("optimization.behavior.prevent-targeting.enable", true,
|
||||||
|
"Prevents hostile entities from targeting optimized villagers.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
@ -23,17 +23,17 @@ public class RestockTrades implements VillagerOptimizerModule, Listener {
|
|||||||
private final boolean shouldLog, notifyPlayer;
|
private final boolean shouldLog, notifyPlayer;
|
||||||
|
|
||||||
protected RestockTrades() {
|
protected RestockTrades() {
|
||||||
|
shouldEnable();
|
||||||
this.villagerManager = VillagerOptimizer.getVillagerManager();
|
this.villagerManager = VillagerOptimizer.getVillagerManager();
|
||||||
Config config = VillagerOptimizer.getConfiguration();
|
Config config = VillagerOptimizer.getConfiguration();
|
||||||
config.addComment("optimization.trade-restocking.enable", """
|
config.addComment("optimization.behavior.trade-restocking.enable", """
|
||||||
This is for automatic restocking of trades for optimized villagers. Optimized Villagers\s
|
This is for automatic restocking of trades for optimized villagers. Optimized Villagers\s
|
||||||
Don't have enough AI to do trade restocks themselves, so this needs to always be enabled.
|
Don't have enough AI to do trade restocks themselves, so this needs to always be enabled.""");
|
||||||
""");
|
this.restock_delay_millis = config.getInt("optimization.behavior.trade-restocking.delay-in-ticks", 1000,
|
||||||
this.restock_delay_millis = config.getInt("optimization.trade-restocking.delay-in-ticks", 1000,
|
|
||||||
"1 second = 20 ticks. There are 24.000 ticks in a single minecraft day.") * 50L;
|
"1 second = 20 ticks. There are 24.000 ticks in a single minecraft day.") * 50L;
|
||||||
this.shouldLog = config.getBoolean("optimization.trade-restocking.log", false);
|
this.notifyPlayer = config.getBoolean("optimization.behavior.trade-restocking.notify-player", true,
|
||||||
this.notifyPlayer = config.getBoolean("optimization.trade-restocking.notify-player", true,
|
|
||||||
"Sends the player a message when the trades were restocked on a clicked villager.");
|
"Sends the player a message when the trades were restocked on a clicked villager.");
|
||||||
|
this.shouldLog = config.getBoolean("optimization.behavior.trade-restocking.log", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -49,7 +49,7 @@ public class RestockTrades implements VillagerOptimizerModule, Listener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldEnable() {
|
public boolean shouldEnable() {
|
||||||
return VillagerOptimizer.getConfiguration().getBoolean("optimization.trade-restocking.enable", true);
|
return VillagerOptimizer.getConfiguration().getBoolean("optimization.behavior.trade-restocking.enable", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
|
@ -36,10 +36,11 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener {
|
|||||||
this.plugin = VillagerOptimizer.getInstance();
|
this.plugin = VillagerOptimizer.getInstance();
|
||||||
this.villagerManager = VillagerOptimizer.getVillagerManager();
|
this.villagerManager = VillagerOptimizer.getVillagerManager();
|
||||||
Config config = VillagerOptimizer.getConfiguration();
|
Config config = VillagerOptimizer.getConfiguration();
|
||||||
this.maxVillagersPerChunk = config.getInt("villager-chunk-limit.max-villagers-per-chunk", 25);
|
this.maxVillagersPerChunk = config.getInt("optimization.villager-chunk-limit.max-villagers-per-chunk", 25);
|
||||||
this.logIsEnabled = config.getBoolean("villager-chunk-limit.log-removals", false);
|
this.logIsEnabled = config.getBoolean("optimization.villager-chunk-limit.log-removals", false);
|
||||||
this.checkPeriod = config.getInt("villager-chunk-limit.check-period-in-ticks", 600, "check all chunks every x ticks.");
|
this.checkPeriod = config.getInt("optimization.villager-chunk-limit.check-period-in-ticks", 600,
|
||||||
config.getList("villager-chunk-limit.removal-priority", List.of(
|
"Check all loaded chunks every X ticks. 1 second = 20 ticks");
|
||||||
|
config.getList("optimization.villager-chunk-limit.removal-priority", List.of(
|
||||||
"NONE", "NITWIT", "SHEPHERD", "FISHERMAN", "BUTCHER", "CARTOGRAPHER", "LEATHERWORKER",
|
"NONE", "NITWIT", "SHEPHERD", "FISHERMAN", "BUTCHER", "CARTOGRAPHER", "LEATHERWORKER",
|
||||||
"FLETCHER", "MASON", "FARMER", "ARMORER", "TOOLSMITH", "WEAPONSMITH", "CLERIC", "LIBRARIAN"
|
"FLETCHER", "MASON", "FARMER", "ARMORER", "TOOLSMITH", "WEAPONSMITH", "CLERIC", "LIBRARIAN"
|
||||||
),
|
),
|
||||||
@ -50,7 +51,8 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener {
|
|||||||
Villager.Profession profession = Villager.Profession.valueOf(configuredProfession);
|
Villager.Profession profession = Villager.Profession.valueOf(configuredProfession);
|
||||||
this.removalPriority.add(profession);
|
this.removalPriority.add(profession);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
LogUtils.moduleLog(Level.WARNING, "villager-chunk-limit", "Villager profession '"+configuredProfession+"' not recognized. Make sure you're using the correct profession enums.");
|
LogUtils.moduleLog(Level.WARNING, "optimization.villager-chunk-limit",
|
||||||
|
"Villager profession '"+configuredProfession+"' not recognized. Make sure you're using the correct profession enums.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -63,7 +65,7 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldEnable() {
|
public boolean shouldEnable() {
|
||||||
return VillagerOptimizer.getConfiguration().getBoolean("villager-chunk-limit.enable", false);
|
return VillagerOptimizer.getConfiguration().getBoolean("optimization.villager-chunk-limit.enable", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -116,7 +118,7 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener {
|
|||||||
for (int i = 0; i < amount_over_the_limit; i++) {
|
for (int i = 0; i < amount_over_the_limit; i++) {
|
||||||
Villager villager = villagers_in_chunk.get(i);
|
Villager villager = villagers_in_chunk.get(i);
|
||||||
villager.remove();
|
villager.remove();
|
||||||
if (logIsEnabled) LogUtils.moduleLog(Level.INFO, "villager-chunk-limit",
|
if (logIsEnabled) LogUtils.moduleLog(Level.INFO, "optimization.villager-chunk-limit",
|
||||||
"Removed villager of profession type '"+villager.getProfession()+"' at "+villager.getLocation());
|
"Removed villager of profession type '"+villager.getProfession()+"' at "+villager.getLocation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,12 +35,12 @@ public class WorkstationOptimization implements VillagerOptimizerModule, Listene
|
|||||||
private final double search_radius;
|
private final double search_radius;
|
||||||
|
|
||||||
protected WorkstationOptimization() {
|
protected WorkstationOptimization() {
|
||||||
|
shouldEnable();
|
||||||
this.villagerManager = VillagerOptimizer.getVillagerManager();
|
this.villagerManager = VillagerOptimizer.getVillagerManager();
|
||||||
Config config = VillagerOptimizer.getConfiguration();
|
Config config = VillagerOptimizer.getConfiguration();
|
||||||
config.addComment("optimization.methods.by-workstation.enable", """
|
config.addComment("optimization.methods.by-workstation.enable", """
|
||||||
When enabled, villagers near a configured radius to a workstation specific to your config\s
|
When enabled, villagers near a configured radius to a workstation specific to your config\s
|
||||||
will be optimized.
|
will be optimized.""");
|
||||||
""");
|
|
||||||
config.getList("optimization.methods.by-workstation.workstation-materials", List.of(
|
config.getList("optimization.methods.by-workstation.workstation-materials", List.of(
|
||||||
"COMPOSTER", "SMOKER", "BARREL", "LOOM", "BLAST_FURNACE", "BREWING_STAND", "CAULDRON",
|
"COMPOSTER", "SMOKER", "BARREL", "LOOM", "BLAST_FURNACE", "BREWING_STAND", "CAULDRON",
|
||||||
"FLETCHING_TABLE", "CARTOGRAPHY_TABLE", "LECTERN", "SMITHING_TABLE", "STONECUTTER", "GRINDSTONE"
|
"FLETCHING_TABLE", "CARTOGRAPHY_TABLE", "LECTERN", "SMITHING_TABLE", "STONECUTTER", "GRINDSTONE"
|
||||||
@ -55,13 +55,12 @@ public class WorkstationOptimization implements VillagerOptimizerModule, Listene
|
|||||||
});
|
});
|
||||||
this.search_radius = config.getDouble("optimization.methods.by-workstation.search-radius-in-blocks", 4.0, """
|
this.search_radius = config.getDouble("optimization.methods.by-workstation.search-radius-in-blocks", 4.0, """
|
||||||
The radius in blocks a villager can be away from the player when he places a workstation.\s
|
The radius in blocks a villager can be away from the player when he places a workstation.\s
|
||||||
The closest unoptimized villager to the player will be optimized.
|
The closest unoptimized villager to the player will be optimized.""");
|
||||||
""");
|
|
||||||
this.cooldown = config.getInt("optimization.methods.by-workstation.optimize-cooldown-seconds", 600, """
|
this.cooldown = config.getInt("optimization.methods.by-workstation.optimize-cooldown-seconds", 600, """
|
||||||
Cooldown in seconds until a villager can be optimized again using this method.\s
|
Cooldown in seconds until a villager can be optimized again using this method.\s
|
||||||
Here for configuration freedom. Recommended to leave as is to not enable any exploitable behavior.
|
Here for configuration freedom. Recommended to leave as is to not enable any exploitable behavior.""") * 1000L;
|
||||||
""") * 1000L;
|
this.shouldNotifyPlayer = config.getBoolean("optimization.methods.by-workstation.notify-player", true,
|
||||||
this.shouldNotifyPlayer = config.getBoolean("optimization.methods.by-workstation.notify-player", true);
|
"Sends players a message when they successfully optimized a villager.");
|
||||||
this.shouldLog = config.getBoolean("optimization.methods.by-workstation.log", false);
|
this.shouldLog = config.getBoolean("optimization.methods.by-workstation.log", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +114,7 @@ public class WorkstationOptimization implements VillagerOptimizerModule, Listene
|
|||||||
if (shouldNotifyPlayer) {
|
if (shouldNotifyPlayer) {
|
||||||
final String villagerType = closestOptimizableVillager.villager().getProfession().toString().toLowerCase();
|
final String villagerType = closestOptimizableVillager.villager().getProfession().toString().toLowerCase();
|
||||||
final String workstation = placed.getType().toString().toLowerCase();
|
final String workstation = placed.getType().toString().toLowerCase();
|
||||||
VillagerOptimizer.getLang(player.locale()).workstation_unoptimize_success.forEach(line -> player.sendMessage(line
|
VillagerOptimizer.getLang(player.locale()).workstation_optimize_success.forEach(line -> player.sendMessage(line
|
||||||
.replaceText(TextReplacementConfig.builder().matchLiteral("%villagertype%").replacement(villagerType).build())
|
.replaceText(TextReplacementConfig.builder().matchLiteral("%villagertype%").replacement(villagerType).build())
|
||||||
.replaceText(TextReplacementConfig.builder().matchLiteral("%workstation%").replacement(workstation).build())
|
.replaceText(TextReplacementConfig.builder().matchLiteral("%workstation%").replacement(workstation).build())
|
||||||
));
|
));
|
||||||
@ -147,8 +146,6 @@ public class WorkstationOptimization implements VillagerOptimizerModule, Listene
|
|||||||
for (Entity entity : workstationLoc.getNearbyEntities(search_radius, search_radius, search_radius)) {
|
for (Entity entity : workstationLoc.getNearbyEntities(search_radius, search_radius, search_radius)) {
|
||||||
if (!entity.getType().equals(EntityType.VILLAGER)) continue;
|
if (!entity.getType().equals(EntityType.VILLAGER)) continue;
|
||||||
Villager villager = (Villager) entity;
|
Villager villager = (Villager) entity;
|
||||||
final Villager.Profession profession = villager.getProfession();
|
|
||||||
if (profession.equals(Villager.Profession.NONE) || profession.equals(Villager.Profession.NITWIT)) continue;
|
|
||||||
|
|
||||||
WrappedVillager wVillager = villagerManager.getOrAdd(villager);
|
WrappedVillager wVillager = villagerManager.getOrAdd(villager);
|
||||||
final double distance = entity.getLocation().distance(workstationLoc);
|
final double distance = entity.getLocation().distance(workstationLoc);
|
||||||
|
@ -18,7 +18,7 @@ commands:
|
|||||||
description: Optmize villagers in a radius around you
|
description: Optmize villagers in a radius around you
|
||||||
aliases:
|
aliases:
|
||||||
- optvils
|
- optvils
|
||||||
unoptmizevillagers:
|
unoptimizevillagers:
|
||||||
usage: /unoptimizevillagers <blockradius>
|
usage: /unoptimizevillagers <blockradius>
|
||||||
description: Unoptmize villagers in a radius around you
|
description: Unoptmize villagers in a radius around you
|
||||||
aliases:
|
aliases:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user