Code Monkey home page Code Monkey logo

antivillagerlag's Introduction

AntiVillagerLag

SpigotMC: Link

This is a simple plugin that allows your players to optimize their own villagers and does not effect anything vanilla wise. I am making this plugin due to massive trading halls tanking mspt on my servers and others. This will allow trading halls to keep their twice a day villager restocks but won't affect any farms villagers will be used in, such as Iron Golem Farms, Villager Breeders, Raid Farms, Etc.

How the plugin works

You name a villager with a nametag that matches the name set in config.yml under "NameThatDisables:" and disables the villagers ai. If you wish to re-enable the villager ai all you have to do is rename it to anything else. In addition or instead of you can use a block a villager stands on to enable/disable villager ai (after interaction with the villager), you can set "BlockThatDisables:" to the block you want and change "useblocks:" to true. Disabled villagers get restocked at two configurable times of day, when the player right clicks the villager. During this right click it checks the custom time stored on the villager of when it was last restocked compared to the current server time. The plugin checks if villagers are ready to Levelup and re-enables their ai for 5 seconds to let them levelup their trades.

Please Note

While the villagers are optimized they will not sleep in beds, or breed while ai is disabled. Players will have to re-enable ai to do so. NPC plugins using villagers usually already disable their ai. Make sure not to disable and then re-enable the NPC with AVL, as that will cause the NPC ai to reactivate.

Features of the Plugin

Nametags will not be used when renaming villagers. This is just to allow easy renaming of all villagers and not have to spend a bunch of resources getting nametags which will discourage players from using this plugin. You can turn it off in the config.

There is a cooldown between renaming villagers to prevent exploiting vanilla restocking and the plugin restocking from both happening in a single day.

Automatically restocks villagers at two set times which are configurable.

Automatically levels up disabled villagers.

Bugs and Support

If you encounter any bugs please open a github issue. I will try to solve it as soon as possible!

For support, you can join the Discord Server

antivillagerlag's People

Contributors

d-vr avatar evidentsinger14 avatar rebelmythik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

antivillagerlag's Issues

Villagers not un-optimizing on 1.20.4

Describe the bug
Villagers aren't un-optimizing when you name them something else.
Server Info
Server Version (Ex. 1.18.2): 1.20.4

Type of Server Software (Ex. Paper):
To Reproduce
Steps to reproduce the behavior:

  1. Optimize a villager (we use the nametag method)
  2. Un-optimize a villager
  3. Attempt to infect villager with a zombie

Expected behavior
A clear and concise description of what you expected to happen.
Villager should regain its normal AI, including the ability to be re-infected.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Moving villagers too far from origin restores vanilla behavior

Is your feature request related to a problem? Please describe.
On our vanilla server, one of the complaints I've encountered when brining up this plugin is that players will be able to lobotomize villagers and use this to easily move them in their dumb state, which of course is not vanilla.

Describe the solution you'd like
I would like a configurable distance, where the origin point of a lobotomized villager is saved, and if it has deviated from that origin point by the distance configured it strips the nametag and reverts it to a vanilla villager with AI.

Additional context
Requiring standing on a certain block is an option, but not an ideal one as we're looking for easy conversion of existing halls and to make it easy for new players to come back and optimize later if they didn't know about it when they made their halls. We don't want to enforce use of this plugin, but encourage it and allow people who do use it to have halls that bypass our villager limit rules.

Chat message of when next restock is

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Not knowing when the next cooldown is
Describe the solution you'd like
A clear and concise description of what you want to happen.
Chat message with time until next restock
Additional context
Add any other context or screenshots about the feature request here.

Cooldown not working 1.20.4

Describe the bug
Restocks don't work on server version 1.20.4, the timer/cooldown stays at max time.

Server Info
Purpur 1.20.4

Type of Server Software (Ex. Paper):
To Reproduce
Title says it all

Expected behavior
Restocking works.

Screenshots

Additional context

Add option to config to allow villagers to roam while optimized

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

A lot of my players like to have villagers wandering their town, because it give a little bit of life and activity to their towns, but it lags the server very badly to have unoptimized villagers.

Describe the solution you'd like
A clear and concise description of what you want to happen.

I was wondering if you could add an option to the configuration that disables all of the worst issues of the villager AI, but allows them to still wander around. Have an option to turn this off in the config too, if it ends up being the straw that breaks the camel's back in that it still causes lag for the server, but then if it doesn't cause lag, it could be enabled on a case by case basis for each server and their owner and players to decide.

Additional context
Add any other context or screenshots about the feature request here.

Thanks for your work on this issue. The plugin has really resolved a lot of issues with lag for many servers. You're brilliant, and wonderful.

Villagers trade price reset on restock

Is your feature request related to a problem? Please describe.
Title explains it well, prices never return to normal once a player has traded with a villager a lot causing prices to go up.
Describe the solution you'd like
The vanilla behavior of prices increases lowering after the villager has restocked their trades for the day.

Explicit AI re-enablement

Is your feature request related to a problem? Please describe.
Currently re-enabling AI happens as a toggle due to the absence of a condition, e.g. renamed something other than configured name, standing on a block other than configured blocks.

Describe the solution you'd like
Add the ability to re-enable AI by naming a configured name or standing on a configured block.

Additional context
Add any other context or screenshots about the feature request here.

Restock Villager

Server: 1.19.2
Software: Purpur #1784

The bug I'm getting is that villagers don't reset their trades. It happens a few weeks ago but since few of my users have this active, it was not noticeable.

Console error:
[18:36:55 ERROR]: Could not pass event PlayerInteractEntityEvent to AntiVillagerLag v2.1.1
java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 78
at java.lang.String.checkBoundsBeginEnd(String.java:4601) ~[?:?]
at java.lang.String.substring(String.java:2704) ~[?:?]
at rebelmythik.antivillagerlag.utils.VillagerUtilities.replaceText(VillagerUtilities.java:59) ~[AntiVillagerLag-2.1.1.jar:?]
at rebelmythik.antivillagerlag.events.RestockVillager.restockMessage(RestockVillager.java:35) ~[AntiVillagerLag-2.1.1.jar:?]
at rebelmythik.antivillagerlag.events.RestockVillager.call(RestockVillager.java:94) ~[AntiVillagerLag-2.1.1.jar:?]
at rebelmythik.antivillagerlag.events.EventListenerHandler.rightClick(EventListenerHandler.java:101) ~[AntiVillagerLag-2.1.1.jar:?]
at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor56.execute(Unknown Source) ~[?:?]
at org.bukkit.plugin.EventExecutor.lambda$create$1(EventExecutor.java:75) ~[purpur-api-1.19.2-R0.1-SNAPSHOT.jar:?]
at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:76) ~[purpur-api-1.19.2-R0.1-SNAPSHOT.jar:git-Purpur-1784]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[purpur-api-1.19.2-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:678) ~[purpur-api-1.19.2-R0.1-SNAPSHOT.jar:?]
at net.minecraft.server.network.ServerGamePacketListenerImpl$6.performInteraction(ServerGamePacketListenerImpl.java:3006) ~[?:?]
at net.minecraft.server.network.ServerGamePacketListenerImpl$6.a(ServerGamePacketListenerImpl.java:3063) ~[?:?]
at net.minecraft.network.protocol.game.ServerboundInteractPacket$InteractionAction.dispatch(ServerboundInteractPacket.java:131) ~[?:?]
at net.minecraft.network.protocol.game.ServerboundInteractPacket.dispatch(ServerboundInteractPacket.java:80) ~[?:?]
at net.minecraft.server.network.ServerGamePacketListenerImpl.handleInteract(ServerGamePacketListenerImpl.java:2998) ~[?:?]
at net.minecraft.network.protocol.game.ServerboundInteractPacket.handle(ServerboundInteractPacket.java:67) ~[?:?]
at net.minecraft.network.protocol.game.ServerboundInteractPacket.handle(ServerboundInteractPacket.java:12) ~[?:?]
at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$0(PacketUtils.java:51) ~[?:?]
at net.minecraft.server.TickTask.run(TickTask.java:18) ~[purpur-1.19.2.jar:git-Purpur-1784]
at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:153) ~[?:?]
at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[?:?]
at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1388) ~[purpur-1.19.2.jar:git-Purpur-1784]
at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:185) ~[purpur-1.19.2.jar:git-Purpur-1784]
at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:126) ~[?:?]
at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1365) ~[purpur-1.19.2.jar:git-Purpur-1784]
at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1358) ~[purpur-1.19.2.jar:git-Purpur-1784]
at net.minecraft.util.thread.BlockableEventLoop.runAllTasks(BlockableEventLoop.java:114) ~[?:?]
at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1492) ~[purpur-1.19.2.jar:git-Purpur-1784]
at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1214) ~[purpur-1.19.2.jar:git-Purpur-1784]
at net.minecraft.server.MinecraftServer.lambda$spin$1(MinecraftServer.java:310) ~[purpur-1.19.2.jar:git-Purpur-1784]
at java.lang.Thread.run(Thread.java:833) ~[?:?]

Disable sleeping

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

When players have villagers in pens if there is any kind of difficulty in pathfinding to a bed it causes high tick times. This is with 4 villagers.

https://prnt.sc/15SMRpBYto6F

Describe the solution you'd like

Disable villager sleeping.

Folia Support

Is your feature request related to a problem? Please describe.

No.

Describe the solution you'd like

Numerous server plugin projects are starting to support Folia, as its growing popularity and performance-centric nature are intriguing to many operators. These operators are interested in migrating to Folia to enhance metrics like MSPT, TPS, and the overall player experience.

AntiVillagerLag serves as a fundamental tool for operators tackling these very issues - MSPT, TPS, and the general player experience. I believe there is a significant opportunity for positive synergy if Folia and AntiVillagerLag are used in tandem.

The requested solution/feature is to add explicit Folia support to AntiVillagerLag.

Emerald block doesn't optimize villagers

Describe the bug
A clear and concise description of what the bug is.

Server Info
Server Version: 1.19
Type of Server Software: Paper

To Reproduce
Steps to reproduce the behavior:

  1. I added the plugin to my server.
  2. I updated the config, setting "userenaming" and "useblocks" to true.
  3. I started the server.
  4. I put an emerald block under several villagers.
  5. The villagers continued to look around and interact with their blocks of interest.
  6. I can tell the plugin is loaded correctly because "/avlreload 50" renames all the villagers within a certain radius with the name I specified in the config "stillager."

Expected behavior
I expect both changing the villagers names and changing what block is under them to change them to no AI.

Additional context
Here is my current config file:

NameThatDisables: stillager

# This needs to be a valid block ID to work.
BlockThatDisables: EMERALD_BLOCK

# Please do the time in ticks or it will break the plugin. There is 24,000 ticks in a single day.
# See https://minecraft.fandom.com/wiki/Daylight_cycle for more info
RestockTimes:
  time1: 1000
  time2: 5000
  time3: 9000
  time4: 13000

# This time is in seconds. This cooldown for renaming is to prevent possible abuse
# of people repeatedly disabling ai and re-enabling it to get double trades. I would keep this
# at the minimum time of 10 minutes or 600 seconds due anything less allowing for the double trades to happen.
cooldown: 600

# The maximum radius in blocks the /avloptimize command can search
RadiusLimit: 50

toggleableoptions:
  # If set to true, nametags will be used instead of being infinite.
  usenametags: false
  
  # One of these following options needs to be true for the plugin to work.
  # This will allow nametags to disable and renable the Villager AI.
  userenaming: true
  
  # This will allow a block to disable and renable the Villager AI.
  useblocks: true

messages:
  no-permission: '&cYou don''t have permission to use this command.'
  reload-message: '&aPlugin successfully reloaded.'
  cooldown-message: '&cYou can rename the villager again in %avlminutes% minutes and
    %avlseconds% seconds.'
  cooldown-block-message: '&cYou can toggle this villager''s AI again in %avlminutes%
    minutes and %avlseconds% seconds.'
  cooldown-levelup-message: '&cThe villager is currently leveling up! You can use
    the villager again in %avlseconds% seconds.'
  next-restock: '&cThe next restock for the villager will be in %avlrestockmin% minutes
    and %avlrestocksec% seconds.'
  correct-usage: '&cCorrect Usage is /avloptimize <radius>'
  radius-limit: '&cThe radius you tried is to big. Radius limit is 50 blocks.'

Disabling the ability to bargain for villagers with AI

Is your feature request related to a problem? Please describe.
Players often do not want to lose their comfort for the sake of server performance, so let's make them

Describe the solution you'd like
Prevent trading with villagers without disabling AI for them

Re-Rolling Optimized Villagers

Is your feature request related to a problem? Please describe.
Villagers can't re-roll when under Optimize, which is the entire point of the plugin I fully understand, but I have a small solution that might be neat to see configurable.

Describe the solution you'd like
Possibly a command such as /rollvillager or /roll or something similar, or a certain item you can use to immediately re-roll the villager and randomize its trades. This would be disable-able in the config for players who don't want it.

Additional context
My server uses a custom enchanting system that adds a ton of new enchantments to the game, so people use tons and tons of villagers to get them in a reasonable way. The process to get the villagers typically involves re-rolling librarians until they give the deal you want. This command might remove some of the work needed to get them, so maybe a configurable exp cost, or item cost to use the command, or something similar.

Permission to bypass restock cooldown

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Additional context
Add any other context or screenshots about the feature request here.

Wandering Trader triggers error in afterTrade()

closing inventory of a wandering trader results in the plug-in trying to cast it to a Villager, which results in a error.

Result:
ugly error in console but no other bad effects

Fix:
add a check if inventory belongs to a wandering trader before casting, or handle exception?

Nametag getting used during cooldown

Describe the bug
A clear and concise description of what the bug is.
Nametag getting used during cooldown
Server Info
Server Version (Ex. 1.18.2):
1.18.2

Type of Server Software (Ex. Paper):
To Reproduce
Steps to reproduce the behavior:

  1. Name villager once
  2. Name a second time a cooldown and nametag gets used

Expected behavior
A clear and concise description of what you expected to happen.
Nametag not being used
Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Allow to add tags to villagers in addition to names

Is your feature request related to a problem? Please describe.
I'm not a huge fan of always seeing optimize, the default name, over every villager's head. It would be a nice feature if you could add a tag instead, and have the same effect as giving a villager a specific name.

Describe the solution you'd like
Adding Tags to villagers is a little tedious, but via commands you can call /tag @e[type=villager] add noAI

Add Block to disable villager

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Same effect of when a villager is named.

Describe the solution you'd like
A clear and concise description of what you want to happen.

Additional context
Add any other context or screenshots about the feature request here.

Multiple block that can disable villager

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
a option
BlockThatDisables:

  • 'EMERALD_BLOCK'
  • 'STONE'

to have multiple block to disable the villager

Additional context
Add any other context or screenshots about the feature request here.

Work automatically without invoking command

It would be great if this plugin could work automatically with workstation + radius without a player having to invoke the command.

Meaning it will check if a villager is close to a workstation and then automatically optimize.

villagers move through water

Server Info
Server Version 1.19.2 paper

allow the villager to be pushed by water and players, this would be very useful if players want to move the villager

Villager not losing his job.

Describe the bug
If you give the Villager a Job interact with him and then remove his job table he won't lose his job.

Server Info
Server Version (Ex. 1.18.2): 1.19.0
Type of Server Software (Ex. Paper): Paper Spigot

To Reproduce
Steps to reproduce the behavior:

  1. Spawn a Villager and give him a Job
  2. Interact with him (do not buy/trade)
  3. Remove his job table
  4. Interact with him again and he still has his job and trades

Expected behavior
He should lose his Job and be an unoptimized villager again

Screenshots
https://cdn.discordapp.com/attachments/990400054193954839/1096920188609376336/2023-04-16_00-08-43.mp4

Permission to bypass rename cooldown

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Additional context
Add any other context or screenshots about the feature request here.

[Feature Request] Send message to player when they try to interact with villager

Is your feature request related to a problem? Please describe.
Nope, definitely not related to a problem :)

Describe the solution you'd like
I would love for the plugin to be a little more transparent. The way I imagine this is by sending the player that tries to trade a message in chat and also temporarily preventing them from trading with villagers that aren't named Optimize or whatever name you picked.

So in chronological order:

  • Player right clicks villager that isn't named Optimize

  • Trading is cancelled and instead they get a message that tells them "Please make sure to rename your villagers to 'Optimize' if you only use them for trading!"

  • Now you're granted a 1 minute (configurable duration) to trade with them without the message happening again

  • Player right clicks villager that is named Optimize

  • They can trade without any messages or cancels

What the config could look like for this

MessagingFeature:
  enabled: false #Lets you toggle this feature in general and is false by default
  message: "Please make sure to rename your villagers to 'Optimize' if you only use them for trading!"
  cooldown: 60000 #in milliseconds

Make both options true or false statements

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Make both name tags or block option toggleable
Describe the solution you'd like
A clear and concise description of what you want to happen.

Additional context
Add any other context or screenshots about the feature request here.

Add Valid Worlds as option

Describe the bug
We are starting to use this, and it works flawless, except, those Villagers considered as NPC with EliteMobs plugin. And since they use a unique name instead of the Disabled one, all goes randomly.

So instead of going deeper on API, enabling some worlds where the Villager IA can be enabled or disabled will be nice.

Server Info
1.19

Type of Server Software (Ex. Paper):
To Reproduce

  1. Have Elitemobs and their Adventure Guilds installed.
  2. Install AVL plugin
  3. Now all npc villagers wanders around the area.

Expected behavior
Only villagers from the main world should be have the behavior flag (on/off)

Screenshots
Dont have any right now.

Additional context
Nothing else

Cannot un optimize after converting to zombie

Describe the bug
When converting a (NoAI, Optimize) villager to a zombie and cure the villager Their (NoAI, Optimize) tag still exist but when using a name tag to rename them they doesn't turn back to normal

Server Info
Server Version: 1.19.2

Type of Server Software (Ex. Paper): Purpur (b1819)
To Reproduce
Steps to reproduce the behavior:

  1. Get villager a job
  2. Nametag (Optimize)
  3. Convert the villager to a zombie villager and cure it
  4. Trading with them will be fine.
  5. name tag them with something else
  6. Their doesn't convert back to normal villager (WithAI)

Expected behavior
They regain their AI when nametag after converting back from zombie villager

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

After removing the plugin, villagers are not restocking

Describe the bug
When I remove the plugin and restart the server, villagers still appear to have their AI disabled and won't restock.

Server Info
Server Version (Ex. 1.18.2): 1.20.1

Type of Server Software (Ex. Paper): Purpur

To Reproduce
Steps to reproduce the behavior:

  1. Remove AntiVillagerLag-2.3.1.jar from plugins.
  2. Start server.
  3. Players have reported that villagers are not restocking.

1.20.2 Refill and Nametag problems

Describe the bug
The Villager dosent refill and the nametags disaper when you use them.

Server Info
Paper 1.20.2

Type of Server Software (Ex. Paper):
Paper
To Reproduce
Steps to reproduce the behavior:

  1. Place a Villager
  2. Optimize them with a Nametag (the nametag disaper)
  3. Trade the Villager to out off stock and he dosent refill

Expected behavior

  1. The Nametag dosent disaper
  2. The Villager refill

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.