Хостинг серверов Minecraft playvds.com
  1. Этот сайт использует файлы cookie. Продолжая пользоваться данным сайтом, Вы соглашаетесь на использование нами Ваших файлов cookie. Узнать больше.
  2. Вы находитесь в русском сообществе Bukkit. Мы - администраторы серверов Minecraft, разрабатываем собственные плагины и переводим на русский язык плагины наших собратьев из других стран.
    Скрыть объявление

Помогите Как сделать кастомный PotionEffectType

Тема в разделе "Разработка плагинов для новичков", создана пользователем IlyaHaker, 6 авг 2019.

  1. Автор темы
    IlyaHaker

    IlyaHaker Активный участник Пользователь

    Баллы:
    66
    Понадобилось мне сделать кастомный эффект. Столкнулся с проблемами, что массив PotionEffectType[] переполняется при добавлении нового эффекта и еще был "запрет" регистрации новых эффектов. Эти проблемы решил, но при наложении этого эффекта на игрока сервер крашится. Можно ли это как-то решить? Может, кто сталкивался

    Класс Effect.java:
    Код:
    public class Effect extends PotionEffectType {
        public static Effect CUSTOM_EFFECT = new Effect(28);
    
        public Effect(int id) {
            super(id);
        }
    
        @Override
        public double getDurationModifier() {
            return 1;
        }
    
        @Override
        public String getName() {
            return "custom effect";
        }
    
        @Override
        public boolean isInstant() {
            return false;
        }
    
        @Override
        public Color getColor() {
            return Color.RED;
        }
    }
    

    Регистрация еффекта:
    Код:
    private void setFinalStaticValue(Field field, Object newValue) throws Exception {
       field.setAccessible(true);
    
       Field modifiersField = Field.class.getDeclaredField("modifiers");
       modifiersField.setAccessible(true);
       modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
    
       field.set(null, newValue);
    }
    
    private void setStaticValue(Field field, Object newValue) throws Exception {
       field.setAccessible(true);
    
       field.set(null, newValue);
    }
    
    @Override
    public void onLoad() {
       try {
          PotionEffectType[] defPotions = PotionEffectType.values();
          PotionEffectType[] potions = new PotionEffectType[29];
          System.arraycopy(defPotions, 0, potions, 0, defPotions.length);
          setFinalStaticValue(PotionEffectType.class.getDeclaredField("byId"), potions);
          setStaticValue(PotionEffectType.class.getDeclaredField("acceptingNew"), true);
       } catch (Exception e) {
          e.printStackTrace();
       }
       PotionEffectType.registerPotionEffectType(Effect.CUSTOM_EFFECT);
    }
    

    Краш-репорт:
    Код:
    [18:11:22] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'custompotion' in plugin Dungeons v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:648) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1397) [minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1232) [minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_221]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_221]
        at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]
    Caused by: java.lang.NullPointerException
        at net.minecraft.server.v1_12_R1.EntityLiving.a(EntityLiving.java:740) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.EntityPlayer.a(EntityPlayer.java:1098) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.EntityLiving.addEffect(EntityLiving.java:692) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity.addPotionEffect(CraftLivingEntity.java:263) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity.addPotionEffect(CraftLivingEntity.java:253) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at io.ilyahaker.CustomPotion.onCommand(CustomPotion.java:16) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        ... 15 more
    [18:11:22] [Server thread/WARN]: Failed to handle packet for /127.0.0.1:51161
    net.minecraft.server.v1_12_R1.ReportedException: Ticking player
        at net.minecraft.server.v1_12_R1.EntityPlayer.playerTick(EntityPlayer.java:394) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.PlayerConnection.e(PlayerConnection.java:139) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.NetworkManager.a(NetworkManager.java:233) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.ServerConnection.c(ServerConnection.java:140) [minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:845) [minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]
    Caused by: java.lang.NullPointerException
        at net.minecraft.server.v1_12_R1.MobEffect.tick(SourceFile:97) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.EntityLiving.tickPotionEffects(EntityLiving.java:556) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.EntityLiving.Y(EntityLiving.java:305) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.Entity.B_(Entity.java:320) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.EntityLiving.B_(EntityLiving.java:1873) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.EntityHuman.B_(EntityHuman.java:145) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.EntityPlayer.playerTick(EntityPlayer.java:313) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        ... 8 more
    [18:11:22] [Server thread/INFO]: Top9ine lost connection: Internal server error
    [18:11:22] [Server thread/ERROR]: Encountered an unexpected exception
    net.minecraft.server.v1_12_R1.ReportedException: Ticking player
        at net.minecraft.server.v1_12_R1.EntityPlayer.playerTick(EntityPlayer.java:394) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.PlayerList.disconnect(PlayerList.java:408) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1102) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.NetworkManager.handleDisconnection(NetworkManager.java:319) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.ServerConnection.c(ServerConnection.java:174) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:845) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]
    Caused by: java.lang.NullPointerException
        at net.minecraft.server.v1_12_R1.MobEffect.tick(SourceFile:97) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.EntityLiving.tickPotionEffects(EntityLiving.java:556) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.EntityLiving.Y(EntityLiving.java:305) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.Entity.B_(Entity.java:320) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.EntityLiving.B_(EntityLiving.java:1873) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.EntityHuman.B_(EntityHuman.java:145) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.EntityPlayer.playerTick(EntityPlayer.java:313) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        ... 9 more
    [18:11:22] [Server thread/ERROR]:     Cause of unexpected exception was
    java.lang.NullPointerException: null
        at net.minecraft.server.v1_12_R1.MobEffect.tick(SourceFile:97) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.EntityLiving.tickPotionEffects(EntityLiving.java:556) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.EntityLiving.Y(EntityLiving.java:305) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.Entity.B_(Entity.java:320) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.EntityLiving.B_(EntityLiving.java:1873) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.EntityHuman.B_(EntityHuman.java:145) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.EntityPlayer.playerTick(EntityPlayer.java:313) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.PlayerList.disconnect(PlayerList.java:408) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1102) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.NetworkManager.handleDisconnection(NetworkManager.java:319) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.ServerConnection.c(ServerConnection.java:174) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:845) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) ~[minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [minecraft.jar:git-Spigot-eb3d921-b9f1615]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]
    
     
  2. Mr Hosting
  3. Dymeth

    Dymeth Активный участник Пользователь

    Баллы:
    96
    Имя в Minecraft:
    Dymeth
    Ты никак не сделаешь кастомный PotionEffectType без модификации клиента.
    Ну, по крайней мере клиент никогда не узнает, что на него такой эффект наложили.
    Берёшь и делаешь на сервере какие-то действия без использования PotionEffectType...
     

Поделиться этой страницей