Initial version of wiki command (#13)

Version 1.12

Initial version of wiki command

Co-authored-by: Mighty_Squid <103967@gmail.com>
Reviewed-on: https://git.canopymc.net/Canopy/QoL/pulls/13
Reviewed-by: Etzelia <etzelia@hotmail.com>
Co-Authored-By: Mighty_Squid <mighty_squid@noreply.git.canopymc.net>
Co-Committed-By: Mighty_Squid <mighty_squid@noreply.git.canopymc.net>
benamaurer-chatchatDiscod
Mighty_Squid 2021-07-19 17:30:59 +00:00 committed by Etzelia
parent 3c54c249a1
commit 2e72736571
4 changed files with 67 additions and 1 deletions

View File

@ -3,7 +3,7 @@
<groupId>xyz.etztech</groupId>
<artifactId>QoL</artifactId>
<!-- Version is used in plugin.yml -->
<version>1.11</version>
<version>1.12</version>
<packaging>jar</packaging>
<!-- Plugin Information -->

View File

@ -120,6 +120,7 @@ public class QoL extends JavaPlugin {
new DeathMuteCommand(this);
new CheckupCommand(this);
new DynmapLinkCommand(this);
new WikiCommand(this);
if (dynmap != null) {
new MarkerCommand(this);

View File

@ -0,0 +1,60 @@
package xyz.etztech.qol.commands;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import xyz.etztech.qol.QoL;
import xyz.etztech.qol.EtzTechUtil;
import xyz.etztech.qol.Lang;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Date;
public class WikiCommand implements CommandExecutor {
QoL plugin;
public WikiCommand(QoL paramQoL) {
this.plugin = paramQoL;
plugin.getCommand("wiki").setExecutor(this);
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if (!commandSender.hasPermission("qol.wiki")) {
EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef());
return true;
}
if (args.length < 1) {
EtzTechUtil.sms(commandSender, ChatColor.RED + "Please give a search argument.");
return true;
}
try {
Date changedToAt;
JsonObject obj;
InputStream response = new URL(String.format("https://minecraft.gamepedia.com/api.php?action=opensearch&format=json&formatversion=2&search=%s&namespace=0&limit=1", args[0])).openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(response));
JsonArray jsonArray = new JsonParser().parse(reader.readLine()).getAsJsonArray();
StringBuilder message = new StringBuilder(ChatColor.GREEN + jsonArray.get(1).getAsJsonArray().get(0).getAsString());
message.append(": ");
message.append(ChatColor.WHITE + jsonArray.get(3).getAsJsonArray().get(0).getAsString());
EtzTechUtil.sms(commandSender, message.toString());
} catch (IOException e) {
EtzTechUtil.sms(commandSender, ChatColor.RED + "Minecraft wiki API returned nothing.");
} catch (IndexOutOfBoundsException e) {
EtzTechUtil.sms(commandSender, ChatColor.RED + String.format("Nothing was found on the wiki using: %s", args[0]));
}
return true;
}
}

View File

@ -46,6 +46,8 @@ commands:
marker:
description: Dynmap marker command
aliases: [mark]
wiki:
description: Search the Minecraft wiki
permissions:
qol.admin:
description: Ability to reload the plugin
@ -116,3 +118,6 @@ permissions:
default: op
children:
qol.marker.limit: true
qol.wiki:
description: Ability to use the wiki command
default: op