Перезарядка не работает [плагин Minecraft Bukkit] - PullRequest
0 голосов
/ 10 февраля 2020

поэтому у меня возникла проблема с перезарядкой в ​​моей команде. Команда работает отлично, но когда я пытаюсь поставить перезарядку, она не работает. В чате отправляется это сообщение об ошибке: Произошла внутренняя ошибка при попытке выполнить эту команду. В консоли говорится, что:

    > [14:50:33 INFO]: EvilestVirus7 issued server command: /rtpPlayer
> [14:50:33 ERROR]: null
org.bukkit.command.CommandException: Unhandled exception executing command 'rtpplayer' in plugin RandomTP v1.0
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.PlayerConnection.chat(PlayerConnection.java:1078) [spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer.chat(CraftPlayer.java:237) [spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at can.evilestvirus.randomtp.MenuHandler.onMenuClick(MenuHandler.java:20) [RandomTpPlugin.jar:git-Spigot-21fe707-e1ebe52]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_212]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_212]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_212]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_212]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) [spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) [spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1630) [spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:31) [spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:9) [spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_212]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_212]
at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_212]
Caused by: java.lang.NullPointerException
at can.evilestvirus.randomtp.CooldownManager.checkCooldowns(CooldownManager.java:26) ~[?:?]
at can.evilestvirus.randomtp.CommandRtpPlayer.onCommand(CommandRtpPlayer.java:22) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot1.8.8.jar:git-Spigot-21fe707-e1ebe52]
... 26 more

Это мой основной класс:

package can.evilestvirus.randomtp;

import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin{

    @Override
    public void onEnable() {
        getCommand("rtpplayer").setExecutor(new CommandRtpPlayer());
        getCommand("rtp").setExecutor(new CommandRtp());
        Bukkit.getPluginManager().registerEvents(new MenuHandler(), this);
    }
}

Там класс cooldownManager:

package can.evilestvirus.randomtp;
import org.bukkit.entity.Player;

import java.util.HashMap;
import java.util.UUID;

public class CooldownManager {

    public static HashMap<UUID, Double> cooldowns;

    public static void setupCooldown(){
        cooldowns = new HashMap<>();
    }

    public static void setCooldowns(Player player, int secondes){
        double delay = System.currentTimeMillis() + (secondes * 1000);
        cooldowns.put(player.getUniqueId(), delay);

    }

    public static int getCooldowns(Player player){
        return Math.toIntExact(Math.round((cooldowns.get(player.getUniqueId()) - System.currentTimeMillis()/1000)));
    }

    public static boolean checkCooldowns(Player player){
        if(!cooldowns.containsKey(player.getUniqueId()) || cooldowns.get(player.getUniqueId()) <= System.currentTimeMillis()){
            return true;
        }
        return false;
    }
}

И это класс команды:

    package can.evilestvirus.randomtp;

import java.util.HashMap;
import java.util.Random;


import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

public class CommandRtpPlayer implements CommandExecutor {


    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (sender instanceof Player) {
            Player player = (Player) sender;
            if(CooldownManager.checkCooldowns(player.getPlayer())){
                CooldownManager.setCooldowns(player.getPlayer(), 10);


                Location rtp, rtp2, rtp3, rtp4, rtp5;

                Random random = new Random();
                int nbrandom = (int) (Math.random() * 4.0D) + 1;
                switch (nbrandom) {
                    case 1:
                        rtp = new Location(player.getWorld(), random.nextInt(2500), 90.0D,
                                random.nextInt(2500), 1.8F, 7.4F);
                        player.teleport(rtp);
                        player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 200, 99));
                        player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 200, 99));
                        break;
                    case 2:
                        rtp2 = new Location(player.getWorld(), -random.nextInt(2500), 90.0D,
                                -random.nextInt(2500), 1.8F, 7.4F);
                        player.teleport(rtp2);
                        player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 200, 99));
                        player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 200, 99));
                        break;
                    case 3:
                        rtp3 = new Location(player.getWorld(), -random.nextInt(2500), 90.0D,
                                random.nextInt(2500), 1.8F, 7.4F);
                        player.teleport(rtp3);
                        player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 200, 99));
                        player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 200, 99));
                        break;
                    case 4:
                        rtp4 = new Location(player.getWorld(), random.nextInt(2500), 90.0D,
                                -random.nextInt(2500), 1.8F, 7.4F);
                        player.teleport(rtp4);
                        player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 200, 99));
                        player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 200, 99));
                        break;
                    default:
                        rtp5 = new Location(player.getWorld(), random.nextInt(2500), 90.0D,
                                -random.nextInt(2500), 1.8F, 7.4F);
                        player.teleport(rtp5);
                        player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 200, 99));
                        player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 200, 99));
                        break;
                }
                player.sendMessage("§a§lVous venez d'être téléporté aléatoirement!");
            }else{
                player.getPlayer().sendMessage("Vous pourez utiliser la commandes dans " + CooldownManager.getCooldowns(player.getPlayer()) + " seconds");
            }

            }
            return true;
        }
    }

1 Ответ

1 голос
/ 10 февраля 2020

Вы никогда не запускаете метод setupCooldowns(), который есть в вашем классе CooldownManager. Я бы порекомендовал вам удалить этот метод в любом случае и просто создать время восстановления с помощью Map<UUID, Double> cooldowns = new HashMap<>();

Причина, по которой вы получаете исключение NullPointerException, заключается в том, что ваш HashMap не был создан (не существует)

...