// Path: src/main/java/wdl/range/ProtectionRange.java
// public final class ProtectionRange {
// 	public ProtectionRange(String tag, int x1, int z1, int x2, int z2) {
// 		if (tag == null) {
// 			tag = "";
// 		}
// 		this.tag = tag;
// 		this.x1 = x1;
// 		this.z1 = z1;
// 		this.x2 = x2;
// 		this.z2 = z2;
// 	}
// 	
// 	/**
// 	 * "Tag" for this chunk.  Multiple {@link ProtectionRange}s can share the
// 	 * same tag; this is used to identify sub groups.  May be empty.  If null
// 	 * is passed to the constructor for tag, an empty string is used instead.
// 	 */
// 	public final String tag;
// 	/**
// 	 * Range of coordinates.  If x1 is greater than x2, they will be swapped
// 	 * (and the same for y).  These are chunk coordinates.
// 	 */
// 	public final int x1, z1, x2, z2;
// 	
// 	@Override
// 	public String toString() {
// 		return "Chunks from (" + x1 + ", " + z1 + ") to (" + x2 + ", " + z2
// 				+ ") (tagged " + tag + ")";
// 	}
// }
// 
// Path: src/main/java/wdl/request/PermissionRequest.java
// public class PermissionRequest {
// 	/**
// 	 * Different states a request can be in.
// 	 */
// 	public static enum State {
// 		/**
// 		 * The request is waiting on moderator action.
// 		 */
// 		WAITING(ChatColor.YELLOW),
// 		/**
// 		 * The request has been accepted and the player granted the right permissions.
// 		 */
// 		ACCEPTED(ChatColor.GREEN),
// 		/**
// 		 * The request has been rejected by a moderator.
// 		 */
// 		REJECTED(ChatColor.RED),
// 		/**
// 		 * The request has been withdrawn by the submitting player (either
// 		 * directly or by creating a new request).
// 		 */
// 		WITHDRAWN(ChatColor.GRAY, ChatColor.ITALIC, ChatColor.STRIKETHROUGH),
// 		/**
// 		 * The request has been revoked by a moderator after previously being
// 		 * accepted.
// 		 */
// 		REVOKED(ChatColor.GRAY, ChatColor.STRIKETHROUGH),
// 		/**
// 		 * The request was accepted and has expired after being used.
// 		 */
// 		EXPIRED(ChatColor.GRAY, ChatColor.ITALIC);
// 		
// 		public final String prefix;
// 		
// 		private State(ChatColor... colors) {
// 			StringBuilder builder = new StringBuilder();
// 			for (ChatColor color : colors) {
// 				builder.append(color);
// 			}
// 			prefix = builder.toString();
// 		}
// 	}
// 	
// 	/**
// 	 * Current state of this permission request.
// 	 */
// 	public State state;
// 	/**
// 	 * Unique ID of the requesting player.
// 	 */
// 	public final UUID playerId;
// 	/**
// 	 * Name of the requesting player.
// 	 */
// 	public final String playerName;
// 	/**
// 	 * The reason for the request from the given player.
// 	 */
// 	public final String requestReason;
// 	/**
// 	 * The permissions that were requested.
// 	 */
// 	public final Map<String, String> requestedPerms;
// 	/**
// 	 * The ranges that were requested.
// 	 */
// 	public final List<ProtectionRange> rangeRequests;
// 	/**
// 	 * The time at which this request expires (in the format returned by
// 	 * {@link System#currentTimeMillis()}).
// 	 */
// 	public long expirationTime;
// 	/**
// 	 * {@link BukkitTask} used to mark this request as expired.
// 	 */
// 	public BukkitTask expireTask;
// 	
// 	public PermissionRequest(Player player, String requestReason,
// 			Map<String, String> requestedPerms,
// 			List<ProtectionRange> rangeRequests) {
// 		this.state = State.WAITING;
// 		
// 		this.playerId = player.getUniqueId();
// 		this.playerName = player.getName();
// 		this.requestReason = requestReason;
// 		this.requestedPerms = ImmutableMap.copyOf(requestedPerms);
// 		this.rangeRequests = ImmutableList.copyOf(rangeRequests);
// 	}
// 	
// 	@Override
// 	public String toString() {
// 		return playerName + ": " + requestedPerms.size() + " perm(s), " + rangeRequests.size() + " range(s)";
// 	}
// }


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.entity.Player;
import wdl.range.ProtectionRange;
import wdl.request.PermissionRequest;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;

	 * 
	 * This packet replaces all of the ranges with the given tag with a new set
	 * of ranges.
	 *
	 * This packet starts with a String stating the group, then a second string
	 * that specifies the tag to replace. After that, there is an int stating
	 * the number of ranges, and then each range as formated by
	 * {@link #writeProtectionRange(ProtectionRange, ByteArrayDataOutput)}.
	 */
	public static byte[] createWDLPacket7(String group,
			String tag, List<ProtectionRange> newRanges) {
		ByteArrayDataOutput output = ByteStreams.newDataOutput();
		
		output.writeInt(7);
		
		output.writeUTF(group);
		output.writeUTF(tag);
		
		output.writeInt(newRanges.size());
		
		for (ProtectionRange range : newRanges) {
			writeProtectionRange(range, output);
		}
		
		return output.toByteArray();
	}
	
	/**
	 * Reads a permission request.
	 */

// Path: src/main/java/wdl/range/ProtectionRange.java
// public final class ProtectionRange {
// 	public ProtectionRange(String tag, int x1, int z1, int x2, int z2) {
// 		if (tag == null) {
// 			tag = "";
// 		}
// 		this.tag = tag;
// 		this.x1 = x1;
// 		this.z1 = z1;
// 		this.x2 = x2;
// 		this.z2 = z2;
// 	}
// 	
// 	/**
// 	 * "Tag" for this chunk.  Multiple {@link ProtectionRange}s can share the
// 	 * same tag; this is used to identify sub groups.  May be empty.  If null
// 	 * is passed to the constructor for tag, an empty string is used instead.
// 	 */
// 	public final String tag;
// 	/**
// 	 * Range of coordinates.  If x1 is greater than x2, they will be swapped
// 	 * (and the same for y).  These are chunk coordinates.
// 	 */
// 	public final int x1, z1, x2, z2;
// 	
// 	@Override
// 	public String toString() {
// 		return "Chunks from (" + x1 + ", " + z1 + ") to (" + x2 + ", " + z2
// 				+ ") (tagged " + tag + ")";
// 	}
// }
// 
// Path: src/main/java/wdl/request/PermissionRequest.java
// public class PermissionRequest {
// 	/**
// 	 * Different states a request can be in.
// 	 */
// 	public static enum State {
// 		/**
// 		 * The request is waiting on moderator action.
// 		 */
// 		WAITING(ChatColor.YELLOW),
// 		/**
// 		 * The request has been accepted and the player granted the right permissions.
// 		 */
// 		ACCEPTED(ChatColor.GREEN),
// 		/**
// 		 * The request has been rejected by a moderator.
// 		 */
// 		REJECTED(ChatColor.RED),
// 		/**
// 		 * The request has been withdrawn by the submitting player (either
// 		 * directly or by creating a new request).
// 		 */
// 		WITHDRAWN(ChatColor.GRAY, ChatColor.ITALIC, ChatColor.STRIKETHROUGH),
// 		/**
// 		 * The request has been revoked by a moderator after previously being
// 		 * accepted.
// 		 */
// 		REVOKED(ChatColor.GRAY, ChatColor.STRIKETHROUGH),
// 		/**
// 		 * The request was accepted and has expired after being used.
// 		 */
// 		EXPIRED(ChatColor.GRAY, ChatColor.ITALIC);
// 		
// 		public final String prefix;
// 		
// 		private State(ChatColor... colors) {
// 			StringBuilder builder = new StringBuilder();
// 			for (ChatColor color : colors) {
// 				builder.append(color);
// 			}
// 			prefix = builder.toString();
// 		}
// 	}
// 	
// 	/**
// 	 * Current state of this permission request.
// 	 */
// 	public State state;
// 	/**
// 	 * Unique ID of the requesting player.
// 	 */
// 	public final UUID playerId;
// 	/**
// 	 * Name of the requesting player.
// 	 */
// 	public final String playerName;
// 	/**
// 	 * The reason for the request from the given player.
// 	 */
// 	public final String requestReason;
// 	/**
// 	 * The permissions that were requested.
// 	 */
// 	public final Map<String, String> requestedPerms;
// 	/**
// 	 * The ranges that were requested.
// 	 */
// 	public final List<ProtectionRange> rangeRequests;
// 	/**
// 	 * The time at which this request expires (in the format returned by
// 	 * {@link System#currentTimeMillis()}).
// 	 */
// 	public long expirationTime;
// 	/**
// 	 * {@link BukkitTask} used to mark this request as expired.
// 	 */
// 	public BukkitTask expireTask;
// 	
// 	public PermissionRequest(Player player, String requestReason,
// 			Map<String, String> requestedPerms,
// 			List<ProtectionRange> rangeRequests) {
// 		this.state = State.WAITING;
// 		
// 		this.playerId = player.getUniqueId();
// 		this.playerName = player.getName();
// 		this.requestReason = requestReason;
// 		this.requestedPerms = ImmutableMap.copyOf(requestedPerms);
// 		this.rangeRequests = ImmutableList.copyOf(rangeRequests);
// 	}
// 	
// 	@Override
// 	public String toString() {
// 		return playerName + ": " + requestedPerms.size() + " perm(s), " + rangeRequests.size() + " range(s)";
// 	}
// }


// Path: src/main/java/wdl/WDLPackets.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.entity.Player;
import wdl.range.ProtectionRange;
import wdl.request.PermissionRequest;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;

	 * 
	 * This packet replaces all of the ranges with the given tag with a new set
	 * of ranges.
	 *
	 * This packet starts with a String stating the group, then a second string
	 * that specifies the tag to replace. After that, there is an int stating
	 * the number of ranges, and then each range as formated by
	 * {@link #writeProtectionRange(ProtectionRange, ByteArrayDataOutput)}.
	 */
	public static byte[] createWDLPacket7(String group,
			String tag, List<ProtectionRange> newRanges) {
		ByteArrayDataOutput output = ByteStreams.newDataOutput();
		
		output.writeInt(7);
		
		output.writeUTF(group);
		output.writeUTF(tag);
		
		output.writeInt(newRanges.size());
		
		for (ProtectionRange range : newRanges) {
			writeProtectionRange(range, output);
		}
		
		return output.toByteArray();
	}
	
	/**
	 * Reads a permission request.
	 */

	public static PermissionRequest readPermissionRequest(
