Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

Quality of life changes #256

Merged
merged 9 commits into from Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Expand Up @@ -57,8 +57,13 @@ Since this plugin is GPL and entirely opensource, we cannot be sure how you will
You'll need the WordPress plugin for this MC Plugin to work - you can [get it here](https://github.com/WooMinecraft/woominecraft-wp).

## Changelog
## 1.4.0
* edit RestApi Url to fix alot of user issues
* extend compatibility for mc versions 1.10 - 1.18.1
* added debug command( /woo debug )
* added mojang auth to the plugin side, [jerzean](https://github.com/WooMinecraft/WooMinecraft/pull/256)

## 1.3
## 1.3.0
* Added polish translation props [YouHaveTrouble](https://github.com/WooMinecraft/WooMinecraft/pull/233)
* 1.16.x support props [jerzean](https://github.com/WooMinecraft/WooMinecraft/pull/237)
* Cleanup various readme sections.
Expand Down
176 changes: 88 additions & 88 deletions pom.xml
@@ -1,89 +1,89 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.plugish.woominecraft</groupId>
<artifactId>WooMinecraft</artifactId>
<version>1.3.0</version>
<name>WooMinecraft</name>
<description>A WooCommerce Minecraft Bridge</description>
<properties>
<spigotVersion>1.16.5</spigotVersion>
<mainClass>${project.groupId}.${project.artifactId}</mainClass>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<defaultGoal>clean install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>${project.name}-${project.version}rc-${spigotVersion}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>${spigotVersion}-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.13.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.plugish.woominecraft</groupId>
<artifactId>WooMinecraft</artifactId>

<version>1.3.1-${spigotVersion}</version>

<name>WooMinecraft</name>
<description>A WooCommerce Minecraft Bridge</description>
<properties>
<spigotVersion>1.18</spigotVersion>
<mainClass>${project.groupId}.${project.artifactId}</mainClass>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<defaultGoal>clean install</defaultGoal>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>${project.name}-${project.version}rc</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>

<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>

</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>

<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.13.1</version>
<scope>compile</scope>
</dependency>

</dependencies>
</project>
16 changes: 14 additions & 2 deletions src/main/java/com/plugish/woominecraft/WooCommand.java
@@ -1,15 +1,17 @@
package com.plugish.woominecraft;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.Configuration;

public class WooCommand implements CommandExecutor {

public static WooMinecraft plugin = WooMinecraft.instance;
private static String chatPrefix = ChatColor.DARK_PURPLE + "[" + ChatColor.WHITE + "WooMinecraft" + ChatColor.DARK_PURPLE + "] " + ChatColor.DARK_PURPLE + "";

@Override
public boolean onCommand( CommandSender sender, Command command, String label, String[] args ) {
if ( command.getName().equalsIgnoreCase( "woo" ) && args.length == 0 ) {
Expand All @@ -18,7 +20,7 @@ public boolean onCommand( CommandSender sender, Command command, String label, S
} else {
sender.sendMessage( chatPrefix + " " + plugin.getLang( "general.not_authorized" ) );
}
} else if ( command.getName().equalsIgnoreCase( "woo" ) && args.length == 1 ) {
} else if ( command.getName().equalsIgnoreCase( "woo" ) && args.length <= 1 ) {
if ( args[ 0 ].equalsIgnoreCase( "check" ) ) {
if ( sender.hasPermission( "woo.admin" ) || sender.isOp() ) {

Expand All @@ -41,6 +43,16 @@ public boolean onCommand( CommandSender sender, Command command, String label, S
String msg = plugin.getLang( "general.not_authorized" ).replace( "&", "\u00A7" );
sender.sendMessage( msg );
}
//added support for on the fly debug enable/disable
} else if ( args[ 0 ].equalsIgnoreCase( "debug" ) ) {
if (plugin.getConfig().getBoolean("debug")) {
plugin.getConfig().set("debug", false);
sender.sendMessage(chatPrefix + "Debug Disabled");
return true;
} else {
plugin.getConfig().set("debug", true);
sender.sendMessage(chatPrefix + "Debug enabled");
}
} else {
sender.sendMessage( "Usage: /woo check" );
}
Expand Down
97 changes: 85 additions & 12 deletions src/main/java/com/plugish/woominecraft/WooMinecraft.java
Expand Up @@ -16,29 +16,35 @@
import com.plugish.woominecraft.pojo.WMCProcessedOrders;
import okhttp3.*;
import org.bukkit.Bukkit;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Scanner;

public final class WooMinecraft extends JavaPlugin {

static WooMinecraft instance;

private YamlConfiguration l10n;
private File rawfile;
//make a list and store each user's name:uuid:True/false(and if they are cracked or not)
//to cut down on api calls from the server, list clears upon reboot/reload
private List<String> Players = new ArrayList<>();

@Override
public void onEnable() {
instance = this;
YamlConfiguration config = (YamlConfiguration) getConfig();

// Save the default config.yml
try{
saveDefaultConfig();
Expand All @@ -63,6 +69,13 @@ public void onEnable() {

// Log when plugin is fully enabled ( setup complete ).
getLogger().info( this.getLang( "log.enabled" ) );
//check bungeecord mode/offline mode
if (!Bukkit.getOnlineMode() && !Bukkit.spigot().getConfig().getBoolean("settings.bungeecord")) {
getLogger().severe(String.valueOf(Bukkit.spigot().getConfig().getBoolean("settings.bungeecord")));
getLogger().severe("WooMinecraft doesn't support offLine mode");
Bukkit.getPluginManager().disablePlugin(this);
}

}

@Override
Expand Down Expand Up @@ -114,7 +127,8 @@ private void validateConfig() throws Exception {
* @throws Exception Why the URL failed.
*/
private URL getSiteURL() throws Exception {
return new URL( getConfig().getString( "url" ) + "/wp-json/wmc/v1/server/" + getConfig().getString( "key" ) );
//Enable use of non pretty permlink support / custom post url / should also help with debugging other users issues
return new URL( getConfig().getString( "url" ) + "/index.php?rest_route=/wmc/v1/server/" + getConfig().getString( "key" ) );
}

/**
Expand Down Expand Up @@ -177,8 +191,12 @@ boolean check() throws Exception {

// Walk over all commands and run them at the next available tick.
for ( String command : order.getCommands() ) {
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
scheduler.scheduleSyncDelayedTask( instance, () -> Bukkit.getServer().dispatchCommand( Bukkit.getServer().getConsoleSender(), command ), 20L );
//Auth player against Mojang api
if (AuCh(player)) {
jerzean marked this conversation as resolved.
Show resolved Hide resolved
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
scheduler.scheduleSyncDelayedTask(instance, () -> Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command), 20L);
}

}

wmc_log( "Adding item to list - " + order.getOrderId() );
Expand Down Expand Up @@ -248,12 +266,18 @@ private boolean isDebug() {
*/
private String getPendingOrders() throws Exception {
URL baseURL = getSiteURL();
BufferedReader in;
// java was yelling about this var
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(baseURL.openStream()));
} catch( FileNotFoundException e ) {
String msg = e.getMessage().replace( getConfig().getString( "key" ), "privateKey" );
throw new FileNotFoundException( msg );
try {
in = new BufferedReader(new InputStreamReader(baseURL.openStream()));
} catch (IOException e) {
// this can throw either exception depending on the setup, this should fix that
throw new FileNotFoundException(e.toString());
}
} catch (FileNotFoundException e) {
String msg = e.getMessage().replace(getConfig().getString("key"), "privateKey");
WooMinecraft.instance.wmc_log(msg);
jerzean marked this conversation as resolved.
Show resolved Hide resolved
}

StringBuilder buffer = new StringBuilder();
Expand Down Expand Up @@ -302,4 +326,53 @@ private void wmc_log(String message, Integer level) {
break;
}
}
//Mojang api check
private boolean AuCh(Player p) {
jerzean marked this conversation as resolved.
Show resolved Hide resolved
//check if server is in online/offline mode
if (Bukkit.getServer().getOnlineMode()) {
return true;
//check if the server is connected to a bungee network
} else if (Bukkit.spigot().getConfig().getBoolean("settings.bungeecord")) {
jerzean marked this conversation as resolved.
Show resolved Hide resolved
if (!Players.contains(p.getName() + ':' + p.getUniqueId() + ':' + true)) {
if (Players.contains(p.getName() + ':' + p.getUniqueId() + ':' + false)) {
p.sendMessage("Mojang Auth: Please Speak with a admin about your purchase");
wmc_log("Offline mode not supported");
return false;
}
Bukkit.getScheduler().runTaskAsynchronously(WooMinecraft.instance, () -> {
try (InputStream inputStream = new URL("https://api.mojang.com/users/profiles/minecraft/" + p.getName()).openStream(); Scanner scanner = new Scanner(inputStream)) {
//if User doesn't exist throws IOException
String a = scanner.next();
if (isDebug()) {
wmc_log(inputStream.toString());
wmc_log(a);
}
if (a.contains(p.getName())) {
if (a.contains(p.getUniqueId().toString())) {
Players.add(p.getName() + ':' + p.getUniqueId() + ':' + true);
} else {
//if Username exists but is using the offline uuid(doesn't match mojang records) throw IOException and add player to the list as cracked
Players.add(p.getName() + ':' + p.getUniqueId() + ':' + false);
throw new IOException("Mojang Auth: PlayerName doesn't match uuid for account");
}
} else {
//add username to the Players list, but as cracked, throws IOE
Players.add(p.getName() + ':' + p.getUniqueId() + ':' + false);
throw new IOException("Mojang Auth: PlayerName doesn't exist");
}
} catch (IOException e) {
wmc_log(e.getMessage(), 3);
p.sendMessage("Mojang Auth:Please Speak with a admin about your purchase");
if (isDebug()) {
wmc_log(Players.toString());
}
}
});
}
} else {
wmc_log("Server in offline Mode");
jerzean marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
return true;
}
}