Modify this plugin to change potion efficacy

Discussion in 'Plugin Development' started by Infraction, Jun 26, 2020.

Thread Status:
Not open for further replies.
  1. Offline



    I would like to change the amplifier of Regeneration II potions to make them more effective. I also want to change their duration. I am using the plugin anyway, so that lets me change the duration. However, I was hoping someone could help me modify this code to also change the amplifier. Note that this should be for all potions, whether brewed or spawned in etc. I have a good understanding of code (Python), but am very confused about using Java with Spigot/Bukkit. I tried modifying this file around line 86

    if (potionType == "REGEN") { // how to check for regen 2?
        final intamplifier = x; // value set by me
    else {
        final int amplifier = potionData.isUpgraded() ? 1 : 0;
    Although, I am kind of confused about their logic and maybe I need to change this later, such as in setNewPotionEffect? I would really appreciate some help with this.
    Last edited: Jun 27, 2020
  2. Offline


    why you don't use:

    p.addPotionEffect(new PotionEffect(PotionEffectType.yourpotioneffect, your duration, your amplifier));
    You can also do an event that when consume a potion (wherever type it is) change duration and amplifier (there might be an idea of a plugin)
  3. Offline


    I don't understand enough of that to implement it. Can you help me put that into their plugin?
  4. Offline


    For the first case i elencated, there would be:

        private String command;
        public Prova(Main main) {
            this.command = "examplecommand";
        public boolean onCommand(CommandSender s, Command cmd, String lb, String[] args) {
            //the part where the player does the command (1 case)
            if (cmd.getName().equalsIgnoreCase(command)) {
                Player p = (Player) s;
                //the part where i give a player the effect
                //the Integer.MAX_VALUE defines that the potion have an infinite amount of time
                // 3 is the amplifier, for this case 3 stays at regeneration IV
                p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, Integer.MAX_VALUE, 3));
            return false;
    For the second case it's a little more difficult, beacuse i personally do for every case to work on every single potion:

    public class Prova implements Listener{
        public void onConsume(PlayerItemConsumeEvent e) {
            Player p = e.getPlayer();
            ItemStack consumed = e.getItem();
            if (consumed.getType() == Material.POTION || consumed.getType() == Material.SPLASH_POTION) {
                //personally i do for every single case and in a config i would change everithing
                //then check every case of potion and make it configurable
    now, in your case you haven't specificated a lot, so i can't help anymore
  5. Offline


    I appreciate your help, but to be honest I don't think this really gets me anywhere. I don't want any commands to be added, the plugin should only run for consumed potions.

    Do you think you could take a look at the GitHub I linked, specifically this file. I believe that onPlayerDrinksPotion() and maybe setNewPotionEffect() are the relevant functions.
  6. Offline


    Ok, i just watched, in this line:

    public void onPlayerDrinksPotion(PlayerItemConsumeEvent event){
    he use the event i used in my second case but in another way, (take a look beacuse he use an event also for splash potions), after in setNewPotionEffect(), he have created the method (if you look down in the page you'll see it)
    then this it is the metod for newPotionEffect() (that he use):

    private void setNewPotionEffect(LivingEntity livingEntity, PotionEffect potionEffect){
                PotionEffect activeEffect = PotionEffects.getOrNull(livingEntity, potionEffect.getType());
                int remainingDuration = activeEffect.getDuration();
                // If new effect it type II while old wasn't, or
                // new would last longer than remaining time but isn't a level downgrade (eg II -> I), set it
                int newAmplifier = potionEffect.getAmplifier();
                int activeAmplifier = activeEffect.getAmplifier();
                if(newAmplifier < activeAmplifier)
                if(newAmplifier > activeAmplifier || remainingDuration < potionEffect.getDuration()){
                    livingEntity.addPotionEffect(potionEffect, true);
            } else {
                livingEntity.addPotionEffect(potionEffect, false);
    but I suggest you also see the other methods as they are used in events for information regarding potions. Now whit this material it would be easy to you do what you want
  7. Offline


    Sorry but I don't really understand how I can use this to make Regen II into Regen III etc
  8. Offline


    Ok now we suppose you copy and paste the whole class (this is the part for normal potion(drinks):

    final ItemStack potionItem = event.getItem();
            if (potionItem.getType() != Material.POTION) return;
            final PotionMeta potionMeta = (PotionMeta) potionItem.getItemMeta();
            if (potionMeta == null) return;
            final PotionData potionData = potionMeta.getBasePotionData();
            final PotionType potionType = potionData.getType();
    final PotionEffectType effectType = requireNonNull(potionType.getEffectType());
            final PotionEffect potionEffect = new PotionEffect(effectType, duration, amplifier);
            final Player player = event.getPlayer();
            setNewPotionEffect(player, potionEffect);
            // Remove item from hand since we cancelled the event
            if (player.getGameMode() == GameMode.CREATIVE) return;
            final PlayerInventory playerInventory = player.getInventory();
            final int amount = potionItem.getAmount();
            ItemStack toSet = new ItemStack(Material.GLASS_BOTTLE);
            boolean isInMainHand = potionItem.equals(playerInventory.getItemInMainHand());
            //There was more than one potion in the stack
            if(amount > 1){
                toSet = potionItem;
                toSet.setAmount(amount - 1);
              // If potion was in main hand
             if (isInMainHand){
    now for the effect with the new amplifier:

         setNewPotionEffect(player, potionEffect)
Thread Status:
Not open for further replies.

Share This Page