Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: MineTrax/plugin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3.5.0
Choose a base ref
...
head repository: MineTrax/plugin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4.0.0
Choose a head ref
  • 5 commits
  • 13 files changed
  • 1 contributor

Commits on Jan 14, 2024

  1. Copy the full SHA
    35228cc View commit details

Commits on Feb 10, 2024

  1. wip skins restorer

    Xinecraft committed Feb 10, 2024
    Copy the full SHA
    11ae98d View commit details

Commits on Feb 11, 2024

  1. Copy the full SHA
    3ebfeb6 View commit details
  2. Copy the full SHA
    64552de View commit details
  3. Copy the full SHA
    8dc09a6 View commit details
8 changes: 8 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" ?>
<project name="Minetrax" default="Build">
<target name="Build">
<jar jarfile="D:\Wurky\MineTrax\Plugin Development\Servers\S1 Paper 1.20\plugins\${ant.project.name}.jar"
basedir="./target/classes/" includes="**/*">
</jar>
</target>
</project>
13 changes: 12 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

<groupId>Minetrax</groupId>
<artifactId>Minetrax</artifactId>
<version>3.5.0</version>
<version>4.0.0</version>
<packaging>jar</packaging>

<name>Minetrax</name>
@@ -89,6 +89,10 @@
<id>viaversion-repo</id>
<url>https://repo.viaversion.com</url>
</repository>
<repository>
<id>codemc</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
</repositories>

<dependencies>
@@ -165,5 +169,12 @@
<version>4.7.0</version>
<scope>provided</scope>
</dependency>
<!-- SkinsRestorer API -->
<dependency>
<groupId>net.skinsrestorer</groupId>
<artifactId>skinsrestorer-api</artifactId>
<version>15.0.6</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
44 changes: 36 additions & 8 deletions src/main/java/com/xinecraft/Minetrax.java
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
import com.xinecraft.hooks.chat.EpicCoreChatHook;
import com.xinecraft.hooks.chat.VentureChatHook;
import com.xinecraft.hooks.placeholderapi.MinetraxPlaceholderExpansion;
import com.xinecraft.hooks.skinsrestorer.SkinsRestorerHook;
import com.xinecraft.listeners.*;
import com.xinecraft.log4j.ConsoleAppender;
import com.xinecraft.log4j.ConsoleMessage;
@@ -26,8 +27,11 @@
import lombok.Getter;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import net.skinsrestorer.api.SkinsRestorer;
import net.skinsrestorer.api.SkinsRestorerProvider;
import net.skinsrestorer.api.VersionProvider;
import net.skinsrestorer.api.event.SkinApplyEvent;
import org.apache.commons.lang.StringUtils;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
@@ -102,6 +106,8 @@ public final class Minetrax extends JavaPlugin implements Listener {
@Getter
private Boolean isRemindPlayerToLinkEnabled;
@Getter
private Boolean isShortenAccountLinkUrl;
@Getter
private Boolean isServerIntelEnabled;
@Getter
private Boolean isPlayerIntelEnabled;
@@ -134,10 +140,16 @@ public final class Minetrax extends JavaPlugin implements Listener {
@Getter
public List<String> whitelistedCommandsFromWeb;
@Getter
public HashMap<String, String> joinAddressCache = new HashMap<String, String>();
public HashMap<String, String> joinAddressCache = new HashMap<>();
@Getter
public boolean hasViaVersion;
@Getter
public Boolean hasSkinRestorer = false;
@Getter
public SkinsRestorer skinsRestorerApi;
@Getter
public HashMap<String, String> skinRestorerValueCache = new HashMap<>();
@Getter
public Gson gson = null;

private static Permission perms = null;
@@ -159,12 +171,13 @@ public void onEnable() {
.disableHtmlEscaping()
.create();

// bStats Metric
int pluginId = 15485;
Metrics metrics = new Metrics(this, pluginId);
// bStats Metric,
// NOTE: Need to comment out if using Ant build for testing.
// int pluginId = 15485;
// Metrics metrics = new Metrics(this, pluginId);

playersDataMap = new HashMap<String, PlayerData>();
playerSessionIntelDataMap = new HashMap<String, PlayerSessionIntelData>();
playersDataMap = new HashMap<>();
playerSessionIntelDataMap = new HashMap<>();

// Config
this.saveDefaultConfig();
@@ -200,6 +213,7 @@ public void onEnable() {
whoisMultiplePlayersTitleMessage = this.getConfig().getString("whois-multiple-players-title-message");
whoisMultiplePlayersListMessage = this.getConfig().getString("whois-multiple-players-list-message");
isRemindPlayerToLinkEnabled = this.getConfig().getBoolean("remind-player-to-link");
isShortenAccountLinkUrl = this.getConfig().getBoolean("shorten-account-link-url");
isServerIntelEnabled = this.getConfig().getBoolean("report-server-intel");
isPlayerIntelEnabled = this.getConfig().getBoolean("report-player-intel");
remindPlayerToLinkInterval = this.getConfig().getLong("remind-player-interval");
@@ -217,7 +231,6 @@ public void onEnable() {
whitelistedCommandsFromWeb = this.getConfig().getStringList("whitelisted-commands-from-web");
isSendInventoryDataToPlayerIntel = this.getConfig().getBoolean("send-inventory-data-to-player-intel");
serverSessionId = UUID.randomUUID().toString();

// Disable plugin if host, key, secret or server-id is not there
if (
apiHost == null || apiKey == null || apiSecret == null || apiServerId == null ||
@@ -329,6 +342,21 @@ public void onEnable() {
hasViaVersion = true;
}

// Check if SkinsRestorer is installed
if (PluginUtil.checkIfPluginEnabled("SkinsRestorer")) {
hasSkinRestorer = true;
getLogger().info("Hooking into SkinsRestorer.");

// Add SkinsRestorerHook
skinsRestorerApi = SkinsRestorerProvider.get();
skinsRestorerApi.getEventBus().subscribe(this, SkinApplyEvent.class, new SkinsRestorerHook());

// Warn if SkinsRestorer is not compatible with v15
if (!VersionProvider.isCompatibleWith("15")) {
getLogger().warning("MineTrax supports SkinsRestorer v15, but " + VersionProvider.getVersionInfo() + " is installed. There may be errors!");
}
}

// Update Checker
checkForPluginUpdates();
}
3 changes: 3 additions & 0 deletions src/main/java/com/xinecraft/commands/AccountLinkCommand.java
Original file line number Diff line number Diff line change
@@ -84,6 +84,9 @@ else if (errorType.equals("player-already-linked")) {
// Return the URL to user to click
if (responseObj.get("status").getAsString().equals("success")) {
String url = responseObj.get("data").getAsString();
if (Minetrax.getPlugin().getIsShortenAccountLinkUrl()) {
url = HttpUtil.shortenUrl(url);
}
for (String line : Minetrax.getPlugin().getPlayerLinkFinalActionMessage()) {
line = line.replace("{WEB_URL}", Minetrax.getPlugin().getApiHost());
line = line.replace("{LINK_URL}", url);
7 changes: 5 additions & 2 deletions src/main/java/com/xinecraft/data/PlayerSessionIntelData.java
Original file line number Diff line number Diff line change
@@ -5,8 +5,7 @@
import java.util.HashMap;

@Data
public class PlayerSessionIntelData
{
public class PlayerSessionIntelData {
public String uuid; // player uuid
public String username;
public String player_id; // id of player in website
@@ -70,6 +69,10 @@ public class PlayerSessionIntelData
public double vault_balance;
public String[] vault_groups;

// Skin JSON object
public String skin_property;
public String skin_texture_id;

public void resetXminKeys() {
this.mob_kills_xmin = 0;
this.player_kills_xmin = 0;
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.xinecraft.hooks.skinsrestorer;

import com.xinecraft.Minetrax;
import com.xinecraft.data.PlayerData;
import com.xinecraft.data.PlayerSessionIntelData;
import com.xinecraft.utils.LoggingUtil;
import net.skinsrestorer.api.PropertyUtils;
import net.skinsrestorer.api.event.SkinApplyEvent;
import net.skinsrestorer.api.property.SkinProperty;
import org.bukkit.entity.Player;

import java.util.function.Consumer;

public class SkinsRestorerHook implements Consumer<SkinApplyEvent> {
@Override
public void accept(SkinApplyEvent event) {
LoggingUtil.info("SkinsRestorerHook.onSkinApplyEvent");
if (event.isCancelled()) {
return;
}
Player player = event.getPlayer(Player.class);
SkinProperty skinProperty = event.getProperty();

PlayerData playerData = Minetrax.getPlugin().playersDataMap.get(player.getUniqueId().toString());
if (playerData == null) {
LoggingUtil.warning("PlayerData not found while listening to SkinApplyEvent");
return;
}

PlayerSessionIntelData playerSessionIntelData = Minetrax.getPlugin().playerSessionIntelDataMap.get(playerData.session_uuid);
if (skinProperty.getValue().isEmpty()) {
playerSessionIntelData.skin_property = null;
playerSessionIntelData.skin_texture_id = null;
} else {
playerSessionIntelData.skin_property = Minetrax.getPlugin().getGson().toJson(skinProperty);
playerSessionIntelData.skin_texture_id = PropertyUtils.getSkinTextureUrlStripped(skinProperty);
}
}
}
38 changes: 30 additions & 8 deletions src/main/java/com/xinecraft/listeners/PlayerJoinLeaveListener.java
Original file line number Diff line number Diff line change
@@ -10,6 +10,11 @@
import com.xinecraft.utils.LoggingUtil;
import com.xinecraft.utils.VersionUtil;
import com.xinecraft.utils.WhoisUtil;
import net.skinsrestorer.api.PropertyUtils;
import net.skinsrestorer.api.SkinsRestorer;
import net.skinsrestorer.api.SkinsRestorerProvider;
import net.skinsrestorer.api.property.SkinProperty;
import net.skinsrestorer.api.storage.PlayerStorage;
import org.bukkit.*;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
@@ -69,7 +74,7 @@ private void postSendChatlog(PlayerEvent event) {
return;
}

Map<String, String> params = new HashMap<String, String>();
Map<String, String> params = new HashMap<>();
params.put("api_key", Minetrax.getPlugin().getApiKey());
params.put("api_secret", Minetrax.getPlugin().getApiSecret());
if (event instanceof PlayerJoinEvent) {
@@ -106,7 +111,7 @@ private void broadcastWhoisForPlayer(Player player) {
}

private void addPlayerToPlayerDataMapAndStartSession(PlayerJoinEvent event) {
Map<String, String> params = new HashMap<String, String>();
Map<String, String> params = new HashMap<>();
params.put("api_key", Minetrax.getPlugin().getApiKey());
params.put("api_secret", Minetrax.getPlugin().getApiSecret());
params.put("username", event.getPlayer().getName());
@@ -131,7 +136,7 @@ public void run() {
playerSessionIntelData.is_op = event.getPlayer().isOp();
try {
playerSessionIntelData.join_address = Minetrax.getPlugin().joinAddressCache.get(event.getPlayer().getUniqueId().toString());
} catch(Exception e) {
} catch (Exception e) {
playerSessionIntelData.join_address = null;
}

@@ -143,15 +148,18 @@ public void run() {
}
playerSessionIntelData.player_ping = playerPing;

if(Minetrax.getPlugin().hasViaVersion) {
if (Minetrax.getPlugin().hasViaVersion) {
int playerProtocolVersion = Via.getAPI().getPlayerVersion(event.getPlayer().getUniqueId());
playerSessionIntelData.minecraft_version = VersionUtil.getMinecraftVersionFromProtoId(playerProtocolVersion);
}
if (Minetrax.getPlugin().hasSkinRestorer) {
updateSkinDataInPlayerIntel(playerSessionIntelData, event.getPlayer());
}

playerSessionIntelData.server_id = Minetrax.getPlugin().getApiServerId();
// Init world stats hashmap for each world
playerSessionIntelData.players_world_stat_intel = new HashMap<String, PlayerWorldStatsIntelData>();
for(World world : Minetrax.getPlugin().getServer().getWorlds()) {
playerSessionIntelData.players_world_stat_intel = new HashMap<>();
for (World world : Minetrax.getPlugin().getServer().getWorlds()) {
playerSessionIntelData.players_world_stat_intel.put(world.getName(), new PlayerWorldStatsIntelData(world.getName()));
}

@@ -172,6 +180,20 @@ public void run() {
});
}

private void updateSkinDataInPlayerIntel(PlayerSessionIntelData playerSessionIntelData, Player player) {
SkinsRestorer skinsRestorerAPI = SkinsRestorerProvider.get();
PlayerStorage playerStorage = skinsRestorerAPI.getPlayerStorage();
try {
Optional<SkinProperty> skin = playerStorage.getSkinForPlayer(player.getUniqueId(), player.getName());
if (skin.isPresent()) {
playerSessionIntelData.skin_property = Minetrax.getPlugin().getGson().toJson(skin.get());
playerSessionIntelData.skin_texture_id = PropertyUtils.getSkinTextureUrlStripped(skin.get());
}
} catch (Exception e) {
Minetrax.getPlugin().getLogger().warning(e.getMessage());
}
}

private void removePlayerAndSessionFromDataMap(PlayerQuitEvent event) {
Gson gson = Minetrax.getPlugin().getGson();
String key = event.getPlayer().getUniqueId().toString();
@@ -233,9 +255,9 @@ private static void spawnFireworks(Player p, Integer amount) {
fw.setFireworkMeta(fwm);

for (int i = 0; i < amount; i++) {
Location newLocation = p.getLocation().add(new Vector(Math.random()-0.5, 0, Math.random()-0.5).multiply(diameter));
Location newLocation = p.getLocation().add(new Vector(Math.random() - 0.5, 0, Math.random() - 0.5).multiply(diameter));
Firework fw2 = (Firework) Objects.requireNonNull(p.getLocation().getWorld()).spawnEntity(newLocation, EntityType.FIREWORK);
fw2.setFireworkMeta(fwm);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.xinecraft.threads.webquery;

import com.xinecraft.utils.LoggingUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

@@ -10,6 +11,7 @@ protected void channelRead0(ChannelHandlerContext ctx, String s) throws Exceptio
try {
output = WebQueryProtocol.processInput(s);
} catch (Exception e) {
LoggingUtil.warning("Error processing input: " + e.getMessage());
output = "err";
}
if (output == null) {
Loading