Skip to content

Instantly share code, notes, and snippets.

View TuxCoding's full-sized avatar

Alex (TuxCoding) TuxCoding

  • [::1]
View GitHub Profile
@TuxCoding
TuxCoding / SkinData.java
Created December 9, 2016 14:55
Decoded Minecraft skin properties
package com.github.games647.changeskin.core.model;
import com.github.games647.changeskin.core.ChangeSkinCore;
import com.github.games647.changeskin.core.model.mojang.skin.DataModel;
import com.github.games647.changeskin.core.model.mojang.skin.MetadataModel;
import com.github.games647.changeskin.core.model.mojang.skin.SkinModel;
import com.github.games647.changeskin.core.model.mojang.skin.TextureSourceModel;
import com.google.gson.Gson;
import java.nio.charset.StandardCharsets;
@TuxCoding
TuxCoding / Account.java
Created December 9, 2016 14:54
Upload a Minecraft skin automatically
package com.github.games647.changeskin.core.model.mojang.auth;
import com.github.games647.changeskin.core.model.PlayerProfile;
public class Account {
private final PlayerProfile profile;
private final String accessToken;
public Account(PlayerProfile profile, String accessToken) {
@TuxCoding
TuxCoding / MethodMeasurement.java
Created December 9, 2016 14:49
Gives stats about the execution time of a stacktrace element compared to it's parent
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import java.util.Collections;
import java.util.Map;
public class MethodMeasurement implements Comparable<MethodMeasurement> {
private final String id;
private final String className;
@TuxCoding
TuxCoding / RollingOverHistory.java
Created December 9, 2016 14:44
Rolling over history that discards the oldest entry if the maximum size was reached.
public class RollingOverHistory {
private final float[] samples;
private float total;
private int currentPosition = 1;
private int currentSize = 1;
public RollingOverHistory(int size, float firstValue) {
this.samples = new float[size];
@TuxCoding
TuxCoding / PluginUtil.java
Created December 9, 2016 14:42
Finds the plugin instance by a stacktrace element or class
package com.github.games647.lagmonitor;
import com.google.common.collect.Maps;
import java.util.HashMap;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
@TuxCoding
TuxCoding / BlockingSecurityManager.java
Created December 9, 2016 14:41
Attach a new security manager in order to listen to File and Socket operations on the main thread.
package com.github.games647.lagmonitor;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import java.io.FilePermission;
import java.net.SocketPermission;
import java.security.Permission;
import java.util.Arrays;
import java.util.Map.Entry;
@TuxCoding
TuxCoding / ConnectionListener.java
Created December 9, 2016 14:38
Listens to socket connections and checks if there is a blocking connection attempt on the main thread.
package com.github.games647.lagmonitor.listeners;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.io.IOException;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.SocketAddress;
import java.net.URI;
@TuxCoding
TuxCoding / GraphRenderer.java
Created December 9, 2016 14:36
Renders a graph on a Minecraft map and automatically discards old data
import org.bukkit.entity.Player;
import org.bukkit.map.MapCanvas;
import org.bukkit.map.MapPalette;
import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView;
import org.bukkit.map.MinecraftFont;
public abstract class GraphRenderer extends MapRenderer {
//max height and width = 128 (index from 0-127)
@TuxCoding
TuxCoding / parse-uuid.java
Created December 9, 2016 14:34
Parses a Java-UUID from a string without dashed to a UUID object
public static UUID parseId(String withoutDashes) {
return UUID.fromString(withoutDashes.substring(0, 8)
+ "-" + withoutDashes.substring(8, 12)
+ "-" + withoutDashes.substring(12, 16)
+ "-" + withoutDashes.substring(16, 20)
+ "-" + withoutDashes.substring(20, 32));
}
@TuxCoding
TuxCoding / SkinUpdater.java
Created December 9, 2016 14:32
Instant updates the player skin without reconnecting.
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.FieldAccessException;
import com.comphenix.protocol.wrappers.EnumWrappers.Difficulty;
import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.comphenix.protocol.wrappers.WrappedChatComponent;