create module to handle villager leveling

This commit is contained in:
xGinko 2023-09-08 22:22:13 +02:00
parent e089a416ea
commit 5610b5b929
4 changed files with 55 additions and 6 deletions

View File

@ -24,7 +24,7 @@ public class LanguageCache {
this.miniMessage = MiniMessage.miniMessage(); this.miniMessage = MiniMessage.miniMessage();
this.no_permission = getTranslation("messages.no-permission", "<red>You don't have permission to use this command."); this.no_permission = getTranslation("messages.no-permission", "<red>You don't have permission to use this command.");
this.trades_restocked = getListTranslation("messages.restock-success", List.of("<green>All trades restocked!")); this.trades_restocked = getListTranslation("messages.trade-restock.success", List.of("<green>All trades restocked!"));
this.nametag_optimize_success = getListTranslation("messages.nametag.optimize-success", List.of("<green>Successfully optimized villager by using a nametag.")); this.nametag_optimize_success = getListTranslation("messages.nametag.optimize-success", List.of("<green>Successfully optimized villager by using a nametag."));
this.nametag_on_optimize_cooldown = getListTranslation("messages.nametag.optimize-on-cooldown", List.of("<gray>You need to wait %time% until you can optimize this villager again.")); this.nametag_on_optimize_cooldown = getListTranslation("messages.nametag.optimize-on-cooldown", List.of("<gray>You need to wait %time% until you can optimize this villager again."));
this.nametag_unoptimize_success = getListTranslation("messages.nametag.unoptimize-success", List.of("<green>Successfully unoptimized villager by using a nametag.")); this.nametag_unoptimize_success = getListTranslation("messages.nametag.unoptimize-success", List.of("<green>Successfully unoptimized villager by using a nametag."));

View File

@ -0,0 +1,41 @@
package me.xginko.villageroptimizer.modules;
import me.xginko.villageroptimizer.VillagerOptimizer;
import me.xginko.villageroptimizer.cache.VillagerManager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
public class LevelVillagers implements VillagerOptimizerModule, Listener {
private final VillagerOptimizer plugin;
private final VillagerManager villagerManager;
public LevelVillagers() {
this.plugin = VillagerOptimizer.getInstance();
this.villagerManager = VillagerOptimizer.getVillagerManager();
}
@Override
public void enable() {
VillagerOptimizer plugin = VillagerOptimizer.getInstance();
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@Override
public void disable() {
HandlerList.unregisterAll(this);
}
@Override
public boolean shouldEnable() {
return false;
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onSomething() {
}
}

View File

@ -53,10 +53,10 @@ public class RestockTrades implements VillagerOptimizerModule, Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onInteract(PlayerInteractEntityEvent event) { private void onInteract(PlayerInteractEntityEvent event) {
if (!event.getRightClicked().getType().equals(EntityType.VILLAGER)) return; if (!event.getRightClicked().getType().equals(EntityType.VILLAGER)) return;
WrappedVillager wVillager = villagerManager.getOrAdd((Villager) event.getRightClicked()); WrappedVillager wVillager = villagerManager.getOrAdd((Villager) event.getRightClicked());
if (!wVillager.isOptimized()) return;
if (wVillager.isOptimized() && wVillager.canRestock(restock_delay)) { if (wVillager.canRestock(restock_delay)) {
wVillager.restock(); wVillager.restock();
if (notifyPlayer) { if (notifyPlayer) {
Player player = event.getPlayer(); Player player = event.getPlayer();

View File

@ -1,7 +1,8 @@
messages: messages:
no-permission: "<red>You don't have permission to use this command." no-permission: "<red>You don't have permission to use this command."
restock-success: trade-restock:
- "<green>All trades restocked! Next restock in %time%" success:
- "<green>All trades restocked! Next restock in %time%"
nametag: nametag:
optimize-success: optimize-success:
- "<green>Successfully optimized villager by using a nametag." - "<green>Successfully optimized villager by using a nametag."
@ -23,3 +24,10 @@ messages:
- "<gray>You need to wait %time% until you can optimize this villager again." - "<gray>You need to wait %time% until you can optimize this villager again."
unoptimize-success: unoptimize-success:
- "<green>Successfully unoptimized villager by removing workstation block %blocktype%." - "<green>Successfully unoptimized villager by removing workstation block %blocktype%."
command:
optimize-success:
- "<green>Successfully optimized %amount% villager(s) in a radius of %radius% blocks."
command-on-cooldown:
- "<gray>You need to wait %time% until you can use this command again."
unoptimize-success:
- "<green>Successfully unoptimized %amount% villager(s) in a radius of %radius% blocks."