Skip to content

Instantly share code, notes, and snippets.

View TuxCoding's full-sized avatar

Alex (TuxCoding) TuxCoding

  • [::1]
View GitHub Profile
@TuxCoding
TuxCoding / TransparentImage.php
Last active December 9, 2016 13:03
Creates a transparent image with the given width and height
<?php
class TransparentImage {
protected static function createTransparent($width, $height) {
$canvas = imagecreatetruecolor($width, $height);
imagealphablending($canvas, true);
imagesavealpha($canvas, true);
$transparent = imagecolorallocatealpha($canvas, 255, 255, 255, 127);
imagefill($canvas, 0, 0, $transparent);
@TuxCoding
TuxCoding / UUIDDeserialize.java
Created December 9, 2016 12:58
Deserialize a UUID based on the 2 x 8 bit arrays
public class UUIDDeserialize {
public static void main(String[] args) throws SQLException {
byte[] mostBits = ArrayUtils.subarray(uuidBytes, 0, 8);
byte[] leastBits = ArrayUtils.subarray(uuidBytes, 8, 16);
long mostByte = Longs.fromByteArray(mostBits);
long leastByte = Longs.fromByteArray(leastBits);
new UUID(mostByte, leastByte);
}
@TuxCoding
TuxCoding / .travis.yml
Created December 9, 2016 12:50
Basic travis template for Maven (Java)
# Use https://travis-ci.org/ for automatic testing
# This is a java project
language: java
script: mvn compile test
jdk: [oraclejdk8]
# if one build failed, exit testing
@TuxCoding
TuxCoding / diff_match_patch.java
Created December 9, 2016 12:46
Functions for diff, match and patch. Computes the difference between two texts to create a patch. Applies the patch onto another text, allowing for errors.
/*
* Diff Match and Patch
*
* Copyright 2006 Google Inc.
* http://code.google.com/p/google-diff-match-patch/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
@TuxCoding
TuxCoding / TicksPerSecond.java
Last active January 23, 2017 11:23
A bukkit (Minecraft) task that should run every tick and then it returns the amount of ticks the server passed from the most recent second.
/**
* This task should run every second
*/
public class TicksPerSecond implements Runnable {
private static final int INTERVAL_CHECK = 1;
private static float lastTicks = 20.0F;
/**
@TuxCoding
TuxCoding / TargetPlayerLook.java
Created December 9, 2016 12:41
Get's the player, the given player is looking at in Bukkit (Minecraft)
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
/**
* Source: https://www.spigotmc.org/threads/code-snippet-helpful-snippets-for-bukkit-plugins.35124/
*/
public class TargetPlayerLook {
@TuxCoding
TuxCoding / OnlinePlayersBackwardsCompatible.java
Created December 9, 2016 12:40
Backwards compatible getOnlinePlayers method in Bukkit (Minecraft). - They changed the return type from array to a collection.
package com.github.games647.minecraft.bukkit;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@TuxCoding
TuxCoding / FastOfflinePlayer.java
Created December 9, 2016 12:39
Get's a fake OfflinePlayer instance based on the given name. Since 1.7 servers makes resource intensive requests on getOfflinePlayer, but that's unnecessary if we only need a instance with the player name
import com.google.common.base.Charsets;
import com.google.common.base.Objects;
import com.google.common.collect.Maps;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
@TuxCoding
TuxCoding / CardinalDirection.java
Created December 9, 2016 12:34
Get the cardinal direction a given player is targeting (Bukkit -> Minecraft)
import org.bukkit.entity.Player;
public class CardinalDirection {
public enum Direction {
NW,
N,
NE,
E,
SE,
@TuxCoding
TuxCoding / EmptyInventoryCheck.java
Last active December 9, 2016 12:34
Checks if the given player has an empty inventory in Bukkit (Minecraft)
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
public class EmptyInventoryCheck {
public static boolean isIventoryEmpty(PlayerInventory playerInventory) {
if (isIventoryEmpty((Inventory) playerInventory)) {