Code Monkey home page Code Monkey logo

Comments (10)

RebelMythik avatar RebelMythik commented on July 28, 2024 1

Will look into adding a label to the villagers when AVL disables the villager so it will only work with villagers the plugin changed

from antivillagerlag.

apatuka avatar apatuka commented on July 28, 2024 1

`

@EventHandler(priority = EventPriority.MONITOR)
public void RightClick(PlayerInteractEntityEvent e) {
    if(e.isCancelled())
        return;
    
    boolean right = true;
    boolean useblock = false;
    Player player = e.getPlayer();
    Entity entity = e.getRightClicked();
    PlayerInventory inv = player.getInventory();
    if (!(entity.getType().equals(EntityType.VILLAGER))) return;
    Villager vil = (Villager) entity;

    ItemStack item;
    currenttime = System.currentTimeMillis() / 1000;
    //If he doesn't have a cooldown, add it?
    if (!VilUtil.hasCooldown(vil, plugin)) {
        VilUtil.setNewCooldown(vil, plugin, cooldown);
        return;
    }

    long vilCooldown = VilUtil.getCooldown(vil, plugin);

    if (!plugin.getConfig().getBoolean("toggleableoptions.userenaming")) return;

    if (e.getHand().equals(EquipmentSlot.HAND)) {
        if (!inv.getItemInMainHand().getType().equals(Material.NAME_TAG)) {
            return;
        }
        item = inv.getItemInMainHand();
    } else {
        if (!inv.getItemInOffHand().getType().equals(Material.NAME_TAG)) {
            return;
        }
        item = inv.getItemInOffHand();
        right = false;
    }
    if (!item.getItemMeta().getDisplayName().equalsIgnoreCase(plugin.getConfig().getString("NameThatDisables"))) return;

    if (!player.hasPermission("avl.renamecooldown.bypass")) {
        if (vilCooldown >= currenttime) {
            Long totalseconds = vilCooldown - currenttime;
            Long sec = totalseconds % 60;
            Long min = (totalseconds - sec) / 60;

            String message = plugin.getConfig().getString("messages.cooldown-message");
            if (message.contains("%avlminutes%")) {
                message = VilUtil.replaceText(message, "%avlminutes%", Long.toString(min));
            }
            message = VilUtil.replaceText(message, "%avlseconds%", Long.toString(sec));
            player.sendMessage(colorcodes.cm(message));
            e.setCancelled(true);
            return;
        }
    }

    if (!plugin.getConfig().getBoolean("toggleableoptions.usenametags")) {
        if (right) {
            inv.getItemInMainHand().setAmount(inv.getItemInMainHand().getAmount() + 1);
        } else {
            inv.getItemInOffHand().setAmount(inv.getItemInOffHand().getAmount() + 1);
        }
    }

    vil.setAI(false);
    VilUtil.setNewCooldown(vil, plugin, cooldown);
}

`

I ended doing this and now works perfect !
Most antigriefing / worldguard plugins handles event cancellation on interacts inside some areas.

from antivillagerlag.

D-VR avatar D-VR commented on July 28, 2024

So the issue is that nametags are messing up EliteMobs?
possible work around is not to use nametags and instead use a block to disable villagers?
If that's not the issue please tell me.

Checking again i think i understand the issue now:
EliteMobs spawns villagers with disabled AI, when right clicking with AVL, since villagers are not name tagged or on a block, AVL will re-enable the AI again, cue pandemonium.

Possible fix to this:

add a flag to check if Villager Ai was disabled by AVL AND ( if villager is not on block OR villager doesn't have the right name ), before enabling AI.

As a note to possible feature request implementation:

Don't know how easy it is to implement, a plugin is loaded in a server for all worlds.

Generally Plugins seem to give perms which can then be enabled by world, which should be the angle to address this, if this feature should be integrated (having a blacklist in config seems a lot more complicated than adding a permission).

External ways to address this issue:

There is a plugin to try and handle this: https://github.com/FormallyMyles/PerWorldPlugins
But questionable how well it works.

Bigger servers use proxies which solves the problem by running different servers with different plugins.

from antivillagerlag.

D-VR avatar D-VR commented on July 28, 2024

checking Elite Mobs, it seems they disable AI for villagers they spawn as NPC:
https://github.com/MagmaGuy/EliteMobs/blob/384ad3a2cf3bbf644f47ddd79c1327b8da9c457c/src/main/java/com/magmaguy/elitemobs/npcs/NPCEntity.java#L88

from antivillagerlag.

D-VR avatar D-VR commented on July 28, 2024

yeah that's the true fix to this issue. Will also help with other plugins which might mess with villagers, might be a good idea to update the ReadMe after it's added to highlight potential issues (i.e. keep NPCs away from blocks or name tags).

I think enabling on a per world basis is a low priority feature.

from antivillagerlag.

D-VR avatar D-VR commented on July 28, 2024

The only problem is that this will not fix your existing problem, since the villager AI of the NPCs is now enabled. You need to either spawn the NPCs again (without avl enabled until a fix is pushed) or place them on blocks to deactivate their AI with avl. @apatuka

from antivillagerlag.

D-VR avatar D-VR commented on July 28, 2024

created a new issue to track root cause, this issue can stay open as a low priority feature request (add permissions for plugin use to allow restriction per world / player)

from antivillagerlag.

D-VR avatar D-VR commented on July 28, 2024

very good!
I think adding this would be good (maybe make it configurable? I don't know if this might have unintended consequences)

adding a permission check at the same position would enable the disable per world option.

from antivillagerlag.

D-VR avatar D-VR commented on July 28, 2024

2.0.0 should fix the core issue, please try it out (just don't leave NPC on the disabling block / name)

only try it out once it's hit the spigot plugin page

from antivillagerlag.

D-VR avatar D-VR commented on July 28, 2024

plugin now has a permission to disable the plug-in for users or worlds, using a permission plugin. config option may be added in the future.

from antivillagerlag.

Related Issues (20)

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.