1Krokko3213
Пользователь
- Сообщения
- 13
Всем привет, такой прикол возник, мне нужно командой поменять в конфиге значение. как мне это сделать? попробовал через yamlconfiguration, config.set("pitch", Integer.parseInt(args[2])) не получается, в консе ошибка
код конкретно класса команды нижe
Форматирование (BB-код):
[06:58:17 ERROR]: null
org.bukkit.command.CommandException: Unhandled exception executing command 'spit' in plugin SpitX v1.1
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[patched_1.16.5.jar:git-Paper-794]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:159) ~[patched_1.16.5.jar:git-Paper-794]
at org.bukkit.craftbukkit.v1_16_R3.CraftServer.dispatchCommand(CraftServer.java:826) ~[patched_1.16.5.jar:git-Paper-794]
at net.minecraft.server.v1_16_R3.PlayerConnection.handleCommand(PlayerConnection.java:2185) ~[patched_1.16.5.jar:git-Paper-794]
at net.minecraft.server.v1_16_R3.PlayerConnection.c(PlayerConnection.java:2000) ~[patched_1.16.5.jar:git-Paper-794]
at net.minecraft.server.v1_16_R3.PlayerConnection.a(PlayerConnection.java:1953) ~[patched_1.16.5.jar:git-Paper-794]
at net.minecraft.server.v1_16_R3.PacketPlayInChat.a(PacketPlayInChat.java:49) ~[patched_1.16.5.jar:git-Paper-794]
at net.minecraft.server.v1_16_R3.PacketPlayInChat.a(PacketPlayInChat.java:7) ~[patched_1.16.5.jar:git-Paper-794]
at net.minecraft.server.v1_16_R3.PlayerConnectionUtils.lambda$ensureMainThread$1(PlayerConnectionUtils.java:35) ~[patched_1.16.5.jar:git-Paper-794]
at net.minecraft.server.v1_16_R3.TickTask.run(SourceFile:18) ~[patched_1.16.5.jar:git-Paper-794]
at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeTask(IAsyncTaskHandler.java:136) ~[patched_1.16.5.jar:git-Paper-794]
at net.minecraft.server.v1_16_R3.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[patched_1.16.5.jar:git-Paper-794]
at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeNext(IAsyncTaskHandler.java:109) ~[patched_1.16.5.jar:git-Paper-794]
at net.minecraft.server.v1_16_R3.MinecraftServer.bb(MinecraftServer.java:1271) ~[patched_1.16.5.jar:git-Paper-794]
at net.minecraft.server.v1_16_R3.MinecraftServer.executeNext(MinecraftServer.java:1264) ~[patched_1.16.5.jar:git-Paper-794]
at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeAll(IAsyncTaskHandler.java:95) ~[patched_1.16.5.jar:git-Paper-794]
at net.minecraft.server.v1_16_R3.MinecraftServer.a(MinecraftServer.java:1400) ~[patched_1.16.5.jar:git-Paper-794]
at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:1135) ~[patched_1.16.5.jar:git-Paper-794]
at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(MinecraftServer.java:291) ~[patched_1.16.5.jar:git-Paper-794]
at java.lang.Thread.run(Thread.java:831) [?:?]
Caused by: java.lang.NullPointerException: Cannot invoke "org.bukkit.configuration.file.YamlConfiguration.set(String, Object)" because "this.config" is null
at org.example.pl.spitx.SpitCMD.onCommand(SpitCMD.java:41) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[patched_1.16.5.jar:git-Paper-794]
... 19 more
Java:
package org.example.pl.spitx;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LlamaSpit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
import static org.bukkit.Bukkit.dispatchCommand;
import static org.bukkit.Bukkit.spigot;
public class SpitCMD implements TabExecutor{
YamlConfiguration config;
@Override
public boolean onCommand(@NotNull CommandSender commandSender, Command command, String s, String[] args) {
if (commandSender instanceof Player) {
if (args.length == 0) {
if (commandSender.hasPermission("spit.launch")) {
Player player = (Player) commandSender;
Entity Pluvok = player.launchProjectile(LlamaSpit.class);
Pluvok.setVelocity(player.getLocation().getDirection().multiply(1f));
World world = player.getWorld();
world.playSound(player.getLocation(), Sound.ENTITY_LLAMA_SPIT, 20f, (float) SpitX.getInstance().getConfig().getInt("pitch"));
return true;
} else commandSender.sendMessage(ChatColor.RED + "Нет! Для выполенения этого действия вам нужен пермишен spit.launch");
} else if (args.length == 1 && commandSender.hasPermission("spit.set")) commandSender.sendMessage(ChatColor.RED + "Нет! Укажите второй аргумент в качестве того что вы хотите поменять (pitch/volume)"); else if (!commandSender.hasPermission("spit.set")) commandSender.sendMessage(ChatColor.RED + "Нет! Для выполнения этого действия вам нужен пермишен: spit.set");
else if (args.length == 2 && args[1].equals("volume") && commandSender.hasPermission("spit.set.volume") || args.length == 2 && args[1].equals("pitch") && commandSender.hasPermission("spit.set.pitch")) commandSender.sendMessage(ChatColor.RED + "Нет! Укажите в качестве третьего аргумента число");
else if (args.length == 3 && args[1].equals("volume")) {
config.set("pitch", Integer.parseInt(args[2]));
}
} else commandSender.sendMessage(ChatColor.RED + "Нет! Данную команду может использовать только игрок");
return false;
}
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
if (args.length == 1 && sender.hasPermission("spit.set")) return List.of("set"); else if (!sender.hasPermission("spit.set") || !sender.hasPermission("spit.set.volume") || !sender.hasPermission("spit.set.pitch")) return Collections.emptyList();
else if (args.length == 2 && args[0].equals("set") && sender.hasPermission("spit.set")) return List.of("volume", "pitch");
else if (args.length == 3 && args[1].equals("volume") && sender.hasPermission("spit.set.volume")) return List.of("Громкость (число)");
else return args.length == 3 && args[1].equals("pitch") && sender.hasPermission("spit.set.pitch") ? List.of("Питч звука (число)") : null;
}
}