do more scheduling for folia
This commit is contained in:
parent
6fe1330038
commit
42a1bdec57
@ -92,58 +92,62 @@ public class OptimizeByWorkstation extends VillagerOptimizerModule implements Li
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Villager villager : workstationLoc.getNearbyEntitiesByType(Villager.class, search_radius)) {
|
for (Villager villager : workstationLoc.getNearbyEntitiesByType(Villager.class, search_radius)) {
|
||||||
if (villager.getProfession() != workstationProfession) continue;
|
villager.getScheduler().execute(plugin, () -> {
|
||||||
WrappedVillager wrapped = wrapperCache.get(villager);
|
if (villager.getProfession() != workstationProfession) return;
|
||||||
if (wrapped.getJobSite() == null) continue;
|
WrappedVillager wrapped = wrapperCache.get(villager);
|
||||||
if (wrapped.getJobSite().getWorld().getUID() != workstationLoc.getWorld().getUID()) continue;
|
|
||||||
if (LocationUtil.relDistance3DSquared(wrapped.getJobSite(), workstationLoc) > 1) continue;
|
|
||||||
|
|
||||||
if (!wrapped.canOptimize(cooldown_millis) && !player.hasPermission(Permissions.Bypass.WORKSTATION_COOLDOWN.get())) {
|
Location jobSite = wrapped.getJobSite();
|
||||||
wrapped.sayNo();
|
if (jobSite == null || jobSite.getWorld().getUID() != workstationLoc.getWorld().getUID()) return;
|
||||||
if (notify_player) {
|
if (LocationUtil.relDistance3DSquared(jobSite, workstationLoc) > 1) return;
|
||||||
final TextReplacementConfig timeLeft = TextReplacementConfig.builder()
|
|
||||||
.matchLiteral("%time%")
|
if (!wrapped.canOptimize(cooldown_millis) && !player.hasPermission(Permissions.Bypass.WORKSTATION_COOLDOWN.get())) {
|
||||||
.replacement(Util.formatDuration(Duration.ofMillis(wrapped.getOptimizeCooldownMillis(cooldown_millis))))
|
wrapped.sayNo();
|
||||||
.build();
|
|
||||||
VillagerOptimizer.getLang(player.locale()).nametag_on_optimize_cooldown
|
if (notify_player) {
|
||||||
.forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(timeLeft)));
|
final TextReplacementConfig timeLeft = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%time%")
|
||||||
|
.replacement(Util.formatDuration(Duration.ofMillis(wrapped.getOptimizeCooldownMillis(cooldown_millis))))
|
||||||
|
.build();
|
||||||
|
VillagerOptimizer.getLang(player.locale()).nametag_on_optimize_cooldown
|
||||||
|
.forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(timeLeft)));
|
||||||
|
}
|
||||||
|
|
||||||
|
taskComplete.set(true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VillagerOptimizeEvent optimizeEvent = new VillagerOptimizeEvent(
|
||||||
|
wrapped,
|
||||||
|
OptimizationType.WORKSTATION,
|
||||||
|
player,
|
||||||
|
event.isAsynchronous()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!optimizeEvent.callEvent()) return;
|
||||||
|
|
||||||
|
wrapped.setOptimizationType(optimizeEvent.getOptimizationType());
|
||||||
|
wrapped.saveOptimizeTime();
|
||||||
|
|
||||||
|
if (notify_player) {
|
||||||
|
final TextReplacementConfig vilProfession = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%vil_profession%")
|
||||||
|
.replacement(Util.toNiceString(wrapped.villager().getProfession()))
|
||||||
|
.build();
|
||||||
|
final TextReplacementConfig placedWorkstation = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%blocktype%")
|
||||||
|
.replacement(Util.toNiceString(placed.getType()))
|
||||||
|
.build();
|
||||||
|
VillagerOptimizer.getLang(player.locale()).workstation_optimize_success
|
||||||
|
.forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(vilProfession).replaceText(placedWorkstation)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (log_enabled) {
|
||||||
|
info(player.getName() + " optimized villager using workstation " + Util.toNiceString(placed.getType()) + " at " +
|
||||||
|
LocationUtil.toString(wrapped.villager().getLocation()));
|
||||||
|
}
|
||||||
|
|
||||||
taskComplete.set(true);
|
taskComplete.set(true);
|
||||||
return;
|
}, null, 1L);
|
||||||
}
|
|
||||||
|
|
||||||
VillagerOptimizeEvent optimizeEvent = new VillagerOptimizeEvent(
|
|
||||||
wrapped,
|
|
||||||
OptimizationType.WORKSTATION,
|
|
||||||
player,
|
|
||||||
event.isAsynchronous()
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!optimizeEvent.callEvent()) return;
|
|
||||||
|
|
||||||
wrapped.setOptimizationType(optimizeEvent.getOptimizationType());
|
|
||||||
wrapped.saveOptimizeTime();
|
|
||||||
|
|
||||||
if (notify_player) {
|
|
||||||
final TextReplacementConfig vilProfession = TextReplacementConfig.builder()
|
|
||||||
.matchLiteral("%vil_profession%")
|
|
||||||
.replacement(Util.toNiceString(wrapped.villager().getProfession()))
|
|
||||||
.build();
|
|
||||||
final TextReplacementConfig placedWorkstation = TextReplacementConfig.builder()
|
|
||||||
.matchLiteral("%blocktype%")
|
|
||||||
.replacement(Util.toNiceString(placed.getType()))
|
|
||||||
.build();
|
|
||||||
VillagerOptimizer.getLang(player.locale()).workstation_optimize_success
|
|
||||||
.forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(vilProfession).replaceText(placedWorkstation)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (log_enabled) {
|
|
||||||
info(player.getName() + " optimized villager using workstation " + Util.toNiceString(placed.getType()) + " at " +
|
|
||||||
LocationUtil.toString(wrapped.villager().getLocation()));
|
|
||||||
}
|
|
||||||
|
|
||||||
taskComplete.set(true);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}, 1L, 10L);
|
}, 1L, 10L);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user