gpt4 book ai didi

java - 在 Bukkit 插件中从网页获取 HTML 字符串

转载 作者:可可西里 更新时间:2023-11-01 16:34:27 26 4
gpt4 key购买 nike

我正在尝试为 minecraft bukkit 服务器创建一个插件。目标是读取 html 页面第一行的字符串。如果结果为真,它将执行命令。

这是我现在的代码:

import java.net.URLConnection;
import java.util.Scanner;
import java.util.logging.Logger;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class main extends JavaPlugin{
public final Logger logger = Logger.getLogger("Minecraft");

public void onEnable(){
logger.info("[First] Has Been Enabled.");
}

public void onDisable(){
logger.info("[First] Has Been Disabled.");
}

public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
Player player = (Player) sender;
if(commandLabel.equalsIgnoreCase("hello")){
player.sendMessage(ChatColor.GOLD + "Hello");
}
else if(commandLabel.equalsIgnoreCase("world")){
player.sendMessage(ChatColor.GOLD + "World");
}
else if(commandLabel.equalsIgnoreCase("coolman")){
player.setPlayerListName("coolman");
}
else if(commandLabel.equalsIgnoreCase("vote")){
String sourceLine = null;

// The URL address of the page to open.
URL address = new URL("http://www.koolflashgames.com/test.php");

// Open the address and create a BufferedReader with the source code.
InputStreamReader pageInput = new InputStreamReader(address.openStream());
BufferedReader source = new BufferedReader(pageInput);

// Append each new HTML line into one string. Add a tab character.
try {
sourceLine = source.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(sourceLine == "False"){
player.sendMessage("Thanks for voting!");
}

}
return false;

}

在日志中创建以下错误:

2012-11-02 16:18:30 [SEVERE] null
org.bukkit.command.CommandException: Unhandled exception executing command 'vote' in plugin first v1.0
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180)
at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:502)
at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:915)
at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:828)
at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:810)
at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:44)
at net.minecraft.server.NetworkManager.b(NetworkManager.java:282)
at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:111)
at net.minecraft.server.ServerConnection.b(SourceFile:35)
at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:561)
at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:213)
at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:474)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:406)
at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
Caused by: java.lang.NullPointerException
at java.io.Reader.<init>(Unknown Source)
at java.io.InputStreamReader.<init>(Unknown Source)
at me.storminmormon30.first.main.onCommand(main.java:43)
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
... 15 more

最佳答案

看起来错误出在其他地方:执行命令“投票”时出现未处理的异常
我在您提供的代码片段中没有看到该命令

关于java - 在 Bukkit 插件中从网页获取 HTML 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13204577/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com