diff --git a/pom.xml b/pom.xml
index 00f9e42..5e8b769 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
xyz.etztech
QoL
- 1.11
+ 1.12
jar
diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java
index 1dc5317..e1ee728 100644
--- a/src/main/java/xyz/etztech/qol/QoL.java
+++ b/src/main/java/xyz/etztech/qol/QoL.java
@@ -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);
diff --git a/src/main/java/xyz/etztech/qol/commands/WikiCommand.java b/src/main/java/xyz/etztech/qol/commands/WikiCommand.java
new file mode 100644
index 0000000..c8d4742
--- /dev/null
+++ b/src/main/java/xyz/etztech/qol/commands/WikiCommand.java
@@ -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;
+ }
+}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 5762949..7753706 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -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