forked from Minecraft/QoL
Compare commits
1 Commits
main
...
benamaurer
Author | SHA1 | Date |
---|---|---|
benamaurer | 85eeeccc79 |
10
pom.xml
10
pom.xml
|
@ -3,7 +3,7 @@
|
||||||
<groupId>xyz.etztech</groupId>
|
<groupId>xyz.etztech</groupId>
|
||||||
<artifactId>QoL</artifactId>
|
<artifactId>QoL</artifactId>
|
||||||
<!-- Version is used in plugin.yml -->
|
<!-- Version is used in plugin.yml -->
|
||||||
<version>1.17</version>
|
<version>1.16</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<!-- Plugin Information -->
|
<!-- Plugin Information -->
|
||||||
|
@ -42,7 +42,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>us.dynmap</groupId>
|
<groupId>us.dynmap</groupId>
|
||||||
<artifactId>dynmap-api</artifactId>
|
<artifactId>dynmap-api</artifactId>
|
||||||
<version>3.5</version>
|
<version>1.9.4</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.discordsrv</groupId>
|
<groupId>com.discordsrv</groupId>
|
||||||
<artifactId>discordsrv</artifactId>
|
<artifactId>discordsrv</artifactId>
|
||||||
<version>1.27.0</version>
|
<version>1.23.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -81,7 +81,7 @@
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>birbmc-repo</id>
|
<id>birbmc-repo</id>
|
||||||
<url>https://mvn.jojodev.com</url>
|
<url>https://mvn.birbmc.com</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>dynmap-repo</id>
|
<id>dynmap-repo</id>
|
||||||
|
@ -105,7 +105,7 @@
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>shopkeepers-repo</id>
|
<id>shopkeepers-repo</id>
|
||||||
<url>https://repo.projectshard.dev/repository/releases/</url>
|
<url>https://nexus.lichtspiele.org/repository/releases/</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,25 @@
|
||||||
package xyz.etztech.qol.commands;
|
package xyz.etztech.qol.commands;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.TabExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import xyz.etztech.qol.QoL;
|
import xyz.etztech.qol.QoL;
|
||||||
import xyz.etztech.qol.EtzTechUtil;
|
import xyz.etztech.qol.EtzTechUtil;
|
||||||
import xyz.etztech.qol.Lang;
|
import xyz.etztech.qol.Lang;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.Date;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class WikiCommand implements TabExecutor {
|
public class WikiCommand implements CommandExecutor {
|
||||||
QoL plugin;
|
QoL plugin;
|
||||||
|
|
||||||
public WikiCommand(QoL paramQoL) {
|
public WikiCommand(QoL paramQoL) {
|
||||||
|
@ -27,7 +28,7 @@ public class WikiCommand implements TabExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
|
||||||
if (!commandSender.hasPermission("qol.wiki")) {
|
if (!commandSender.hasPermission("qol.wiki")) {
|
||||||
EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef());
|
EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef());
|
||||||
return true;
|
return true;
|
||||||
|
@ -37,61 +38,23 @@ public class WikiCommand implements TabExecutor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String query = String.join(" ", args);
|
|
||||||
List<List<String>> result = getWikiResults(query, 1);
|
|
||||||
|
|
||||||
if (result.isEmpty())
|
|
||||||
{
|
|
||||||
EtzTechUtil.sms(commandSender, ChatColor.RED + String.format("Nothing was found on the wiki using: %s", query));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String message = ChatColor.GREEN + result.get(0).get(0) + ": " + ChatColor.WHITE + result.get(0).get(1);
|
|
||||||
EtzTechUtil.sms(commandSender, message);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> onTabComplete(CommandSender commandSender, Command command, String label, String[] args) {
|
|
||||||
String query = String.join(" ", args);
|
|
||||||
|
|
||||||
if (query.isEmpty()) return null;
|
|
||||||
|
|
||||||
List<List<String>> results = getWikiResults(query, 10);
|
|
||||||
|
|
||||||
if (results.isEmpty()) return null;
|
|
||||||
|
|
||||||
List<String> completions = new ArrayList<>();
|
|
||||||
results.forEach((result) -> completions.add(result.get(0)));
|
|
||||||
return completions;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<List<String>> getWikiResults(String query, Integer numOfResults) {
|
|
||||||
try {
|
try {
|
||||||
InputStream response = new URL(String.format(plugin.getConfig().getString("wiki-base-url", "https://minecraft.wiki:") + "/api.php?action=opensearch&format=json&formatversion=2&search=%s&namespace=0&limit=%d", query, numOfResults)).openStream();
|
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));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(response));
|
||||||
JsonArray jsonArray = new JsonParser().parse(reader.readLine()).getAsJsonArray();
|
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());
|
||||||
|
|
||||||
JsonArray names = jsonArray.get(1).getAsJsonArray();
|
EtzTechUtil.sms(commandSender, message.toString());
|
||||||
JsonArray links = jsonArray.get(3).getAsJsonArray();
|
} catch (IOException e) {
|
||||||
|
EtzTechUtil.sms(commandSender, ChatColor.RED + "Minecraft wiki API returned nothing.");
|
||||||
// Check if we got any result
|
} catch (IndexOutOfBoundsException e) {
|
||||||
if (names.size() < 1)
|
EtzTechUtil.sms(commandSender, ChatColor.RED + String.format("Nothing was found on the wiki using: %s", args[0]));
|
||||||
return Collections.emptyList();
|
|
||||||
|
|
||||||
List<List<String>> results = new ArrayList<>();
|
|
||||||
for (int i = 0; i < names.size(); i++)
|
|
||||||
{
|
|
||||||
List<String> e = new ArrayList<>();
|
|
||||||
e.add(names.get(i).getAsString());
|
|
||||||
e.add(links.get(i).getAsString());
|
|
||||||
results.add(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return true;
|
||||||
} catch(Exception e) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,17 +67,17 @@ public class AsyncPlayerChatListener implements Listener {
|
||||||
matcher = syntax.matcher(chat);
|
matcher = syntax.matcher(chat);
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
chat = matcher.replaceAll("&n$1&r");
|
chat = matcher.replaceAll("<underlined>$1</underlined>");
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
case 3:
|
case 3:
|
||||||
chat = matcher.replaceAll("&o$1&r");
|
chat = matcher.replaceAll("<italic>$1</italic>");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
chat = matcher.replaceAll("&l$1&r");
|
chat = matcher.replaceAll("<bold>$1</bold>");
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
chat = matcher.replaceAll("&m$1&r");
|
chat = matcher.replaceAll("<strikethrough>$1</strikethrough>");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -124,5 +124,3 @@ head_shop:
|
||||||
# Diamond price of a head in the shop, default is 2 diamonds
|
# Diamond price of a head in the shop, default is 2 diamonds
|
||||||
price: 2
|
price: 2
|
||||||
|
|
||||||
# Base URL for the /wiki command. Should support a https://www.mediawiki.org/wiki/API:Opensearch request
|
|
||||||
wiki-base-url: 'https://minecraft.wiki'
|
|
||||||
|
|
Loading…
Reference in New Issue