add config option for auto renaming
This commit is contained in:
parent
896e412a0e
commit
b3ce2b2dbd
@ -11,6 +11,7 @@ import net.kyori.adventure.text.Component;
|
|||||||
import net.kyori.adventure.text.TextReplacementConfig;
|
import net.kyori.adventure.text.TextReplacementConfig;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.format.TextDecoration;
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
@ -27,8 +28,10 @@ import java.util.List;
|
|||||||
public class OptVillagersRadius implements VillagerOptimizerCommand, TabCompleter {
|
public class OptVillagersRadius implements VillagerOptimizerCommand, TabCompleter {
|
||||||
|
|
||||||
private final List<String> tabCompletes = List.of("5", "10", "25", "50");
|
private final List<String> tabCompletes = List.of("5", "10", "25", "50");
|
||||||
|
private final Component optimizeName;
|
||||||
private final long cooldown;
|
private final long cooldown;
|
||||||
private final int maxRadius;
|
private final int maxRadius;
|
||||||
|
private final boolean shouldRename, overwrite_name;
|
||||||
|
|
||||||
public OptVillagersRadius() {
|
public OptVillagersRadius() {
|
||||||
Config config = VillagerOptimizer.getConfiguration();
|
Config config = VillagerOptimizer.getConfiguration();
|
||||||
@ -36,6 +39,12 @@ public class OptVillagersRadius implements VillagerOptimizerCommand, TabComplete
|
|||||||
this.cooldown = config.getInt("optimization-methods.commands.optimizevillagers.cooldown-seconds", 600, """
|
this.cooldown = config.getInt("optimization-methods.commands.optimizevillagers.cooldown-seconds", 600, """
|
||||||
Cooldown in seconds until a villager can be optimized again using the command.\s
|
Cooldown in seconds until a villager can be optimized again using the command.\s
|
||||||
Here for configuration freedom. Recommended to leave as is to not enable any exploitable behavior.""") * 1000L;
|
Here for configuration freedom. Recommended to leave as is to not enable any exploitable behavior.""") * 1000L;
|
||||||
|
this.shouldRename = config.getBoolean("optimization-methods.commands.optimizevillagers.rename-optimized-villagers.enable", true,
|
||||||
|
"Renames villagers to what you configure below when they're optimized.");
|
||||||
|
this.overwrite_name = config.getBoolean("optimization-methods.commands.optimizevillagers.rename-optimized-villagers.overwrite-previous-name", false,
|
||||||
|
"Whether to overwrite the previous name or not.");
|
||||||
|
this.optimizeName = MiniMessage.miniMessage().deserialize(config.getString("optimization-methods.commands.optimizevillagers.name-villager.name", "<gray>Optimize",
|
||||||
|
"The MiniMessage formatted name to give optimized villagers."));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -89,6 +98,16 @@ public class OptVillagersRadius implements VillagerOptimizerCommand, TabComplete
|
|||||||
if (wVillager.canOptimize(cooldown)) {
|
if (wVillager.canOptimize(cooldown)) {
|
||||||
wVillager.setOptimization(OptimizationType.COMMAND);
|
wVillager.setOptimization(OptimizationType.COMMAND);
|
||||||
wVillager.saveOptimizeTime();
|
wVillager.saveOptimizeTime();
|
||||||
|
|
||||||
|
if (shouldRename) {
|
||||||
|
if (overwrite_name) {
|
||||||
|
villager.customName(optimizeName);
|
||||||
|
} else {
|
||||||
|
if (villager.customName() == null)
|
||||||
|
villager.customName(optimizeName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
successCount++;
|
successCount++;
|
||||||
} else {
|
} else {
|
||||||
failCount++;
|
failCount++;
|
||||||
|
@ -9,7 +9,9 @@ import me.xginko.villageroptimizer.enums.Permissions;
|
|||||||
import me.xginko.villageroptimizer.modules.VillagerOptimizerModule;
|
import me.xginko.villageroptimizer.modules.VillagerOptimizerModule;
|
||||||
import me.xginko.villageroptimizer.utils.CommonUtil;
|
import me.xginko.villageroptimizer.utils.CommonUtil;
|
||||||
import me.xginko.villageroptimizer.utils.LogUtil;
|
import me.xginko.villageroptimizer.utils.LogUtil;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextReplacementConfig;
|
import net.kyori.adventure.text.TextReplacementConfig;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -31,9 +33,10 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener {
|
|||||||
|
|
||||||
private final VillagerCache villagerCache;
|
private final VillagerCache villagerCache;
|
||||||
private final HashSet<Material> blocks_that_disable = new HashSet<>(4);
|
private final HashSet<Material> blocks_that_disable = new HashSet<>(4);
|
||||||
|
private final Component optimizeName;
|
||||||
private final long cooldown;
|
private final long cooldown;
|
||||||
private final double search_radius;
|
private final double search_radius;
|
||||||
private final boolean onlyWhileSneaking, shouldLog, shouldNotifyPlayer;
|
private final boolean onlyWhileSneaking, shouldRename, overwrite_name, shouldLog, shouldNotifyPlayer;
|
||||||
|
|
||||||
public OptimizeByBlock() {
|
public OptimizeByBlock() {
|
||||||
shouldEnable();
|
shouldEnable();
|
||||||
@ -63,6 +66,12 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener {
|
|||||||
"Only optimize/unoptimize by workstation when player is sneaking during place or break.");
|
"Only optimize/unoptimize by workstation when player is sneaking during place or break.");
|
||||||
this.shouldNotifyPlayer = config.getBoolean("optimization-methods.block-optimization.notify-player", true,
|
this.shouldNotifyPlayer = config.getBoolean("optimization-methods.block-optimization.notify-player", true,
|
||||||
"Sends players a message when they successfully optimized or unoptimized a villager.");
|
"Sends players a message when they successfully optimized or unoptimized a villager.");
|
||||||
|
this.shouldRename = config.getBoolean("optimization-methods.block-optimization.rename-optimized-villagers.enable", true,
|
||||||
|
"Renames villagers to what you configure below when they're optimized.");
|
||||||
|
this.overwrite_name = config.getBoolean("optimization-methods.block-optimization.rename-optimized-villagers.overwrite-previous-name", false,
|
||||||
|
"Whether to overwrite the previous name or not.");
|
||||||
|
this.optimizeName = MiniMessage.miniMessage().deserialize(config.getString("optimization-methods.block-optimization.name-villager.name", "<gray>Optimize",
|
||||||
|
"The MiniMessage formatted name to give optimized villagers."));
|
||||||
this.shouldLog = config.getBoolean("optimization-methods.block-optimization.log", false);
|
this.shouldLog = config.getBoolean("optimization-methods.block-optimization.log", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,6 +123,16 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener {
|
|||||||
if (closestOptimizableVillager.canOptimize(cooldown) || player.hasPermission(Permissions.Bypass.BLOCK_COOLDOWN.get())) {
|
if (closestOptimizableVillager.canOptimize(cooldown) || player.hasPermission(Permissions.Bypass.BLOCK_COOLDOWN.get())) {
|
||||||
closestOptimizableVillager.setOptimization(OptimizationType.BLOCK);
|
closestOptimizableVillager.setOptimization(OptimizationType.BLOCK);
|
||||||
closestOptimizableVillager.saveOptimizeTime();
|
closestOptimizableVillager.saveOptimizeTime();
|
||||||
|
|
||||||
|
if (shouldRename) {
|
||||||
|
if (overwrite_name) {
|
||||||
|
closestOptimizableVillager.villager().customName(optimizeName);
|
||||||
|
} else {
|
||||||
|
Villager villager = closestOptimizableVillager.villager();
|
||||||
|
if (villager.customName() == null) villager.customName(optimizeName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (shouldNotifyPlayer) {
|
if (shouldNotifyPlayer) {
|
||||||
final TextReplacementConfig vilProfession = TextReplacementConfig.builder()
|
final TextReplacementConfig vilProfession = TextReplacementConfig.builder()
|
||||||
.matchLiteral("%vil_profession%")
|
.matchLiteral("%vil_profession%")
|
||||||
|
@ -8,7 +8,9 @@ import me.xginko.villageroptimizer.enums.OptimizationType;
|
|||||||
import me.xginko.villageroptimizer.enums.Permissions;
|
import me.xginko.villageroptimizer.enums.Permissions;
|
||||||
import me.xginko.villageroptimizer.modules.VillagerOptimizerModule;
|
import me.xginko.villageroptimizer.modules.VillagerOptimizerModule;
|
||||||
import me.xginko.villageroptimizer.utils.CommonUtil;
|
import me.xginko.villageroptimizer.utils.CommonUtil;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextReplacementConfig;
|
import net.kyori.adventure.text.TextReplacementConfig;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -26,9 +28,10 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
|||||||
public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener {
|
public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener {
|
||||||
|
|
||||||
private final VillagerCache villagerCache;
|
private final VillagerCache villagerCache;
|
||||||
|
private final Component optimizeName;
|
||||||
private final long cooldown;
|
private final long cooldown;
|
||||||
private final double search_radius;
|
private final double search_radius;
|
||||||
private final boolean onlyWhileSneaking, shouldLog, shouldNotifyPlayer;
|
private final boolean onlyWhileSneaking, shouldRename, overwrite_name, shouldLog, shouldNotifyPlayer;
|
||||||
|
|
||||||
public OptimizeByWorkstation() {
|
public OptimizeByWorkstation() {
|
||||||
shouldEnable();
|
shouldEnable();
|
||||||
@ -47,6 +50,12 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener
|
|||||||
"Only optimize/unoptimize by workstation when player is sneaking during place or break");
|
"Only optimize/unoptimize by workstation when player is sneaking during place or break");
|
||||||
this.shouldNotifyPlayer = config.getBoolean("optimization-methods.workstation-optimization.notify-player", true,
|
this.shouldNotifyPlayer = config.getBoolean("optimization-methods.workstation-optimization.notify-player", true,
|
||||||
"Sends players a message when they successfully optimized a villager.");
|
"Sends players a message when they successfully optimized a villager.");
|
||||||
|
this.shouldRename = config.getBoolean("optimization-methods.workstation-optimization.rename-optimized-villagers.enable", true,
|
||||||
|
"Renames villagers to what you configure below when they're optimized.");
|
||||||
|
this.overwrite_name = config.getBoolean("optimization-methods.workstation-optimization.rename-optimized-villagers.overwrite-previous-name", false,
|
||||||
|
"Whether to overwrite the previous name or not.");
|
||||||
|
this.optimizeName = MiniMessage.miniMessage().deserialize(config.getString("optimization-methods.workstation-optimization.name-villager.name", "<gray>Optimize",
|
||||||
|
"The MiniMessage formatted name to give optimized villagers."));
|
||||||
this.shouldLog = config.getBoolean("optimization-methods.workstation-optimization.log", false);
|
this.shouldLog = config.getBoolean("optimization-methods.workstation-optimization.log", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,6 +107,16 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener
|
|||||||
if (closestOptimizableVillager.canOptimize(cooldown) || player.hasPermission(Permissions.Bypass.WORKSTATION_COOLDOWN.get())) {
|
if (closestOptimizableVillager.canOptimize(cooldown) || player.hasPermission(Permissions.Bypass.WORKSTATION_COOLDOWN.get())) {
|
||||||
closestOptimizableVillager.setOptimization(OptimizationType.WORKSTATION);
|
closestOptimizableVillager.setOptimization(OptimizationType.WORKSTATION);
|
||||||
closestOptimizableVillager.saveOptimizeTime();
|
closestOptimizableVillager.saveOptimizeTime();
|
||||||
|
|
||||||
|
if (shouldRename) {
|
||||||
|
if (overwrite_name) {
|
||||||
|
closestOptimizableVillager.villager().customName(optimizeName);
|
||||||
|
} else {
|
||||||
|
Villager villager = closestOptimizableVillager.villager();
|
||||||
|
if (villager.customName() == null) villager.customName(optimizeName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (shouldNotifyPlayer) {
|
if (shouldNotifyPlayer) {
|
||||||
final TextReplacementConfig vilProfession = TextReplacementConfig.builder()
|
final TextReplacementConfig vilProfession = TextReplacementConfig.builder()
|
||||||
.matchLiteral("%vil_profession%")
|
.matchLiteral("%vil_profession%")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user