Factor & Javadoc update

This commit is contained in:
Myles 2016-09-27 17:31:10 +01:00
parent ff3d76a387
commit 396998c7fc
82 changed files with 415 additions and 139 deletions

View File

@ -2,7 +2,7 @@ package us.myles.ViaVersion;
import us.myles.ViaVersion.api.ViaVersionConfig;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.util.Configuration;
import us.myles.ViaVersion.bukkit.util.Configuration;
import java.io.File;
import java.util.List;

View File

@ -14,10 +14,14 @@ import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.bukkit.*;
import us.myles.ViaVersion.classgenerator.ClassGenerator;
import us.myles.ViaVersion.bukkit.classgenerator.ClassGenerator;
import us.myles.ViaVersion.bukkit.commands.BukkitCommandHandler;
import us.myles.ViaVersion.bukkit.commands.BukkitCommandSender;
import us.myles.ViaVersion.bukkit.platform.BukkitViaAPI;
import us.myles.ViaVersion.bukkit.platform.BukkitViaInjector;
import us.myles.ViaVersion.bukkit.platform.BukkitViaLoader;
import us.myles.ViaVersion.dump.PluginInfo;
import us.myles.ViaVersion.util.NMSUtil;
import us.myles.ViaVersion.bukkit.util.NMSUtil;
import java.util.ArrayList;
import java.util.List;

View File

@ -103,9 +103,9 @@ public interface ViaVersionAPI extends ViaAPI<Player> {
boolean isDebug();
/**
* Get ViaVersions command handler
* Get ViaVersions commands handler
*
* @return command handler
* @return commands handler
*/
ViaVersionCommand getCommandHandler();

View File

@ -1,10 +1,10 @@
package us.myles.ViaVersion.classgenerator;
package us.myles.ViaVersion.bukkit.classgenerator;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.handlers.ViaDecodeHandler;
import us.myles.ViaVersion.handlers.ViaEncodeHandler;
import us.myles.ViaVersion.bukkit.handlers.ViaDecodeHandler;
import us.myles.ViaVersion.bukkit.handlers.ViaEncodeHandler;
public class BasicHandlerConstructor implements HandlerConstructor {
@Override

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.classgenerator;
package us.myles.ViaVersion.bukkit.classgenerator;
import javassist.*;
import javassist.expr.ConstructorCall;
@ -6,9 +6,9 @@ import javassist.expr.ExprEditor;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.handlers.ViaDecodeHandler;
import us.myles.ViaVersion.handlers.ViaEncodeHandler;
import us.myles.ViaVersion.util.NMSUtil;
import us.myles.ViaVersion.bukkit.handlers.ViaDecodeHandler;
import us.myles.ViaVersion.bukkit.handlers.ViaEncodeHandler;
import us.myles.ViaVersion.bukkit.util.NMSUtil;
public class ClassGenerator {
private static HandlerConstructor constructor = new BasicHandlerConstructor();

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.classgenerator;
package us.myles.ViaVersion.bukkit.classgenerator;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.bukkit;
package us.myles.ViaVersion.bukkit.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.bukkit;
package us.myles.ViaVersion.bukkit.commands;
import lombok.AllArgsConstructor;
import org.bukkit.command.CommandSender;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.handlers;
package us.myles.ViaVersion.bukkit.handlers;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.handlers;
package us.myles.ViaVersion.bukkit.handlers;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.handlers;
package us.myles.ViaVersion.bukkit.handlers;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.handlers;
package us.myles.ViaVersion.bukkit.handlers;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
@ -7,8 +7,8 @@ import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
import us.myles.ViaVersion.classgenerator.ClassGenerator;
import us.myles.ViaVersion.classgenerator.HandlerConstructor;
import us.myles.ViaVersion.bukkit.classgenerator.ClassGenerator;
import us.myles.ViaVersion.bukkit.classgenerator.HandlerConstructor;
import java.lang.reflect.Method;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.listeners;
package us.myles.ViaVersion.bukkit.listeners;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.listeners;
package us.myles.ViaVersion.bukkit.listeners;
import lombok.AccessLevel;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.listeners.protocol1_9to1_8;
package us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8;
import org.bukkit.Bukkit;
import org.bukkit.entity.HumanEntity;
@ -17,7 +17,7 @@ import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.listeners.ViaBukkitListener;
import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ArmorType;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.listeners.protocol1_9to1_8;
package us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
@ -6,7 +6,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockPlaceEvent;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.listeners.ViaBukkitListener;
import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.listeners.protocol1_9to1_8;
package us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufOutputStream;
@ -21,9 +21,9 @@ import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.listeners.ViaBukkitListener;
import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.util.NMSUtil;
import us.myles.ViaVersion.bukkit.util.NMSUtil;
import us.myles.ViaVersion.util.ReflectionUtil;
import java.io.DataOutput;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.listeners.protocol1_9to1_8;
package us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8;
import org.bukkit.World;
import org.bukkit.entity.Player;
@ -10,7 +10,7 @@ import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.listeners.ViaBukkitListener;
import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
public class DeathListener extends ViaBukkitListener {

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.listeners.protocol1_9to1_8;
package us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.listeners.protocol1_9to1_8;
package us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8;
import org.bukkit.Location;
import org.bukkit.Material;
@ -6,7 +6,7 @@ import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockPlaceEvent;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.listeners.ViaBukkitListener;
import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
public class PaperPatch extends ViaBukkitListener {

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.bukkit;
package us.myles.ViaVersion.bukkit.platform;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
@ -17,7 +17,7 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.boss.ViaBossBar;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.util.ProtocolSupportUtil;
import us.myles.ViaVersion.bukkit.util.ProtocolSupportUtil;
import java.util.Map;
import java.util.SortedSet;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.bukkit;
package us.myles.ViaVersion.bukkit.platform;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler;
@ -8,10 +8,10 @@ import org.bukkit.plugin.PluginDescriptionFile;
import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.platform.ViaInjector;
import us.myles.ViaVersion.handlers.ViaVersionInitializer;
import us.myles.ViaVersion.bukkit.handlers.ViaVersionInitializer;
import us.myles.ViaVersion.util.ConcurrentList;
import us.myles.ViaVersion.util.ListWrapper;
import us.myles.ViaVersion.util.NMSUtil;
import us.myles.ViaVersion.bukkit.util.NMSUtil;
import us.myles.ViaVersion.util.ReflectionUtil;
import java.lang.reflect.Field;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.bukkit;
package us.myles.ViaVersion.bukkit.platform;
import lombok.AllArgsConstructor;
import org.bukkit.Bukkit;
@ -10,8 +10,10 @@ import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
import us.myles.ViaVersion.listeners.UpdateListener;
import us.myles.ViaVersion.listeners.protocol1_9to1_8.*;
import us.myles.ViaVersion.bukkit.listeners.UpdateListener;
import us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8.*;
import us.myles.ViaVersion.bukkit.providers.BukkitViaBulkChunkTranslator;
import us.myles.ViaVersion.bukkit.providers.BukkitViaMovementTransmitter;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider;

View File

@ -1,11 +1,11 @@
package us.myles.ViaVersion.bukkit;
package us.myles.ViaVersion.bukkit.providers;
import com.google.common.collect.Lists;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
import us.myles.ViaVersion.util.NMSUtil;
import us.myles.ViaVersion.bukkit.util.NMSUtil;
import us.myles.ViaVersion.util.ReflectionUtil;
import java.lang.reflect.Method;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.bukkit;
package us.myles.ViaVersion.bukkit.providers;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -7,7 +7,7 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker;
import us.myles.ViaVersion.util.NMSUtil;
import us.myles.ViaVersion.bukkit.util.NMSUtil;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.util;
package us.myles.ViaVersion.bukkit.util;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.util;
package us.myles.ViaVersion.bukkit.util;
import org.bukkit.Bukkit;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.util;
package us.myles.ViaVersion.bukkit.util;
import org.bukkit.entity.Player;

View File

@ -11,13 +11,13 @@ import us.myles.ViaVersion.api.ViaVersionConfig;
import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.bungee.BungeeViaAPI;
import us.myles.ViaVersion.bungee.BungeeViaInjector;
import us.myles.ViaVersion.bungee.BungeeViaLoader;
import us.myles.ViaVersion.bungee.command.BungeeCommand;
import us.myles.ViaVersion.bungee.command.BungeeCommandHandler;
import us.myles.ViaVersion.bungee.command.BungeeCommandSender;
import us.myles.ViaVersion.bungee.config.BungeeConfigAPI;
import us.myles.ViaVersion.bungee.platform.BungeeViaAPI;
import us.myles.ViaVersion.bungee.platform.BungeeViaInjector;
import us.myles.ViaVersion.bungee.platform.BungeeViaLoader;
import us.myles.ViaVersion.bungee.commands.BungeeCommand;
import us.myles.ViaVersion.bungee.commands.BungeeCommandHandler;
import us.myles.ViaVersion.bungee.commands.BungeeCommandSender;
import us.myles.ViaVersion.bungee.platform.BungeeConfigAPI;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.bungee.command;
package us.myles.ViaVersion.bungee.commands;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Command;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.bungee.command;
package us.myles.ViaVersion.bungee.commands;
import us.myles.ViaVersion.commands.ViaCommandHandler;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.bungee.command;
package us.myles.ViaVersion.bungee.commands;
import lombok.AllArgsConstructor;
import net.md_5.bungee.api.CommandSender;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.bungee;
package us.myles.ViaVersion.bungee.platform;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import us.myles.ViaVersion.api.boss.BossBar;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.bungee.config;
package us.myles.ViaVersion.bungee.platform;
import us.myles.ViaVersion.api.ViaVersionConfig;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.bungee;
package us.myles.ViaVersion.bungee.platform;
import io.netty.buffer.ByteBuf;
import lombok.NonNull;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.bungee;
package us.myles.ViaVersion.bungee.platform;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.bungee;
package us.myles.ViaVersion.bungee.platform;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;

View File

@ -24,7 +24,7 @@ import java.util.LinkedList;
import java.util.List;
public class PacketWrapper {
public static int PASSTHROUGH_ID = 1000;
public static final int PASSTHROUGH_ID = 1000;
private final ByteBuf inputBuffer;
private final UserConnection userConnection;
@ -32,8 +32,8 @@ public class PacketWrapper {
@Setter
@Getter
private int id = -1;
private LinkedList<Pair<Type, Object>> readableObjects = new LinkedList<>();
private List<Pair<Type, Object>> packetValues = new ArrayList<>();
private final LinkedList<Pair<Type, Object>> readableObjects = new LinkedList<>();
private final List<Pair<Type, Object>> packetValues = new ArrayList<>();
public PacketWrapper(int packetID, ByteBuf inputBuffer, UserConnection userConnection) {
this.id = packetID;
@ -404,7 +404,7 @@ public class PacketWrapper {
* @param index The index to start from
* @param pipeline The pipeline
* @return The current packetwrapper
* @throws Exception
* @throws Exception If it fails to transform a packet, exception will be thrown
*/
public PacketWrapper apply(Direction direction, State state, int index, List<Protocol> pipeline) throws Exception {
for (int i = index; i < pipeline.size(); i++) { // Copy to prevent from removal.

View File

@ -11,6 +11,11 @@ public class Via {
@Getter
private static ViaManager manager;
/**
* Register the ViaManager associated with the platform.
*
* @param viaManager The ViaManager
*/
public static void init(ViaManager viaManager) {
Validate.isTrue(manager == null, "ViaManager is already set");
@ -18,11 +23,21 @@ public class Via {
Via.manager = viaManager;
}
/**
* Get the API associated with the current platform.
*
* @return API instance
*/
public static ViaAPI getAPI() {
Validate.isTrue(platform != null, "ViaVersion has not loaded the Platform");
return Via.platform.getApi();
}
/**
* Get the config associated with the current platform.
*
* @return Config instance
*/
public static ViaVersionConfig getConfig() {
Validate.isTrue(platform != null, "ViaVersion has not loaded the Platform");
return Via.platform.getConf();

View File

@ -21,7 +21,6 @@ public abstract class ViaListener {
* @return The UserConnection
*/
protected UserConnection getUserConnection(@NonNull UUID uuid) {
if (!Via.getAPI().isPorted(uuid)) return null;
return Via.getManager().getConnection(uuid);
}

View File

@ -111,6 +111,12 @@ public abstract class BossBar<T> {
throw new NotImplementedException("This method is not implemented for the platform " + Via.getPlatform().getPlatformName());
}
/**
* Removes the bossbar from a player
*
* @param uuid The platers YYUD
* @return The BossBar object
*/
public abstract BossBar removePlayer(UUID uuid);
/**

View File

@ -3,11 +3,32 @@ package us.myles.ViaVersion.api.command;
import java.util.UUID;
public interface ViaCommandSender {
public boolean hasPermission(String permission);
/**
* Check if the sender has a permission.
*
* @param permission Permission string eg. viaversion.admin
* @return True if the sender has the permission
*/
boolean hasPermission(String permission);
public void sendMessage(String msg);
/**
* Send a message to the sender
*
* @param msg The message to send
*/
void sendMessage(String msg);
public UUID getUUID();
/**
* Get the senders UUID.
*
* @return The senders UUID
*/
UUID getUUID();
public String getName();
/**
* Get the senders name.
*
* @return The senders name
*/
String getName();
}

View File

@ -9,14 +9,14 @@ public abstract class ViaSubCommand {
/**
* Subcommand name
*
* @return The command name
* @return The commands name
*/
public abstract String name();
/**
* subcommand description, this'll show in /viaversion list
*
* @return The command description
* @return The commands description
*/
public abstract String description();
@ -24,7 +24,7 @@ public abstract class ViaSubCommand {
* Usage example:
* "playerversion [name]"
*
* @return The command usage
* @return The commands usage
*/
public String usage() {
return name();
@ -33,7 +33,7 @@ public abstract class ViaSubCommand {
/**
* Permission, null for everyone
*
* @return The permission required to use the command
* @return The permission required to use the commands
*/
public String permission() {
return "viaversion.admin";
@ -44,7 +44,7 @@ public abstract class ViaSubCommand {
*
* @param sender Command sender
* @param args Arguments
* @return command executed succesfully if false, show usage
* @return commands executed succesfully if false, show usage
*/
public abstract boolean execute(ViaCommandSender sender, String[] args);
@ -66,7 +66,7 @@ public abstract class ViaSubCommand {
/**
* Send message formatted / colored
*
* @param sender command sender
* @param sender commands sender
* @param message string message
* @param args optional objects
*/

View File

@ -28,7 +28,7 @@ public interface ViaVersionCommand {
ViaSubCommand getSubCommand(String name);
/**
* Executed when the Command sender executes the command
* Executed when the Command sender executes the commands
*
* @param sender Sender object
* @param args arguments provided

View File

@ -1,11 +1,32 @@
package us.myles.ViaVersion.api.platform;
public interface ViaInjector {
public void inject() throws Exception;
/**
* Inject into the current Platform
*
* @throws Exception If there is an error with injecting
*/
void inject() throws Exception;
public void uninject() throws Exception;
/**
* Uninject into the current Platform
*
* @throws Exception If there is an error with uninjecting
*/
void uninject() throws Exception;
public int getServerProtocolVersion() throws Exception;
/**
* Get the server protocol version
*
* @return The server protocol integer
* @throws Exception If there is an error with getting this info, eg. not binded.
*/
int getServerProtocolVersion() throws Exception;
public String getEncoderName();
/**
* Get the name of the encoder for then netty pipeline for this platform.
*
* @return The name
*/
String getEncoderName();
}

View File

@ -15,35 +15,122 @@ import java.util.logging.Logger;
* @param <T> - The player type for the platform, used for API related methods
*/
public interface ViaPlatform<T> {
/**
* Get the logger for this platform
*
* @return Java Logger (may be a wrapper)
*/
Logger getLogger();
/**
* Get the platform name
*
* @return Platform Name (simply its name)
*/
String getPlatformName();
/**
* Get the plugin version
*
* @return Plugin version as a semver string
*/
String getPluginVersion();
/**
* Run a task Async
*
* @param runnable The task to run
* @return The Task ID
*/
int runAsync(Runnable runnable);
/**
* Run a task Sync
*
* @param runnable The task to run
* @return The Task ID
*/
int runSync(Runnable runnable);
/**
* Run a task at a repeating interval.
* Initial interval is the same as repeat.
*
* @param runnable The task to run
* @param ticks The interval to run it at
* @return The Task ID
*/
int runRepeatingSync(Runnable runnable, Long ticks);
/**
* Cancel a task
*
* @param taskId The task ID to cancel
*/
void cancelTask(int taskId);
/**
* Get the online players
*
* @return Array of ViaCommandSender
*/
ViaCommandSender[] getOnlinePlayers();
/**
* Send a message to a player
*
* @param uuid The player's UUID
* @param message The message to send
*/
void sendMessage(UUID uuid, String message);
/**
* Kick a player for a reason
*
* @param uuid The player's UUID
* @param message The message to kick them with
* @return True if it was successful
*/
boolean kickPlayer(UUID uuid, String message);
/**
* Check if the plugin is enabled.
*
* @return True if it is enabled
*/
boolean isPluginEnabled();
/**
* Get the API for this platform
*
* @return The API for the platform
*/
ViaAPI<T> getApi();
/**
* Get the config API for this platform
*
* @return The config API
*/
ViaVersionConfig getConf();
/**
* Get the backend configuration provider for this platform.
* (On some platforms this returns the same as getConf())
*
* @return The configuration provider
*/
ConfigurationProvider getConfigurationProvider();
/**
* Called when a reload happens
*/
void onReload();
/**
* Get the JSON data required for /viaversion dump
*
* @return The json data
*/
JsonObject getDump();
}

View File

@ -1,5 +1,8 @@
package us.myles.ViaVersion.api.platform;
public interface ViaPlatformLoader {
public void load();
/**
* Initialise the loading for a platform, eg. registering listeners / providers / events etc.
*/
void load();
}

View File

@ -6,8 +6,8 @@ import java.util.List;
import java.util.Map;
public class ViaProviders {
private Map<Class<? extends Provider>, Provider> providers = new HashMap<>();
private List<Class<? extends Provider>> lonelyProviders = new ArrayList<>();
private final Map<Class<? extends Provider>, Provider> providers = new HashMap<>();
private final List<Class<? extends Provider>> lonelyProviders = new ArrayList<>();
public void require(Class<? extends Provider> provider) {
lonelyProviders.add(provider);

View File

@ -16,8 +16,8 @@ import java.util.List;
import java.util.Map;
public abstract class Protocol {
private Map<Pair<State, Integer>, ProtocolPacket> incoming = new HashMap<>();
private Map<Pair<State, Integer>, ProtocolPacket> outgoing = new HashMap<>();
private final Map<Pair<State, Integer>, ProtocolPacket> incoming = new HashMap<>();
private final Map<Pair<State, Integer>, ProtocolPacket> outgoing = new HashMap<>();
public Protocol() {
registerPackets();

View File

@ -20,10 +20,10 @@ public class ProtocolRegistry {
public static final Protocol BASE_PROTOCOL = new BaseProtocol();
public static int SERVER_PROTOCOL = -1;
// Input Version -> Output Version & Protocol (Allows fast lookup)
private static Map<Integer, Map<Integer, Protocol>> registryMap = new ConcurrentHashMap<>();
private static Map<Pair<Integer, Integer>, List<Pair<Integer, Protocol>>> pathCache = new ConcurrentHashMap<>();
private static List<Protocol> registerList = Lists.newCopyOnWriteArrayList();
private static Set<Integer> supportedVersions = Sets.newConcurrentHashSet();
private static final Map<Integer, Map<Integer, Protocol>> registryMap = new ConcurrentHashMap<>();
private static final Map<Pair<Integer, Integer>, List<Pair<Integer, Protocol>>> pathCache = new ConcurrentHashMap<>();
private static final List<Protocol> registerList = Lists.newCopyOnWriteArrayList();
private static final Set<Integer> supportedVersions = Sets.newConcurrentHashSet();
static {
// Base Protocol

View File

@ -9,7 +9,7 @@ import java.util.ArrayList;
import java.util.List;
public abstract class PacketRemapper {
private List<Pair<ValueReader, ValueWriter>> valueRemappers = new ArrayList<>();
private final List<Pair<ValueReader, ValueWriter>> valueRemappers = new ArrayList<>();
public PacketRemapper() {
registerMap();

View File

@ -9,10 +9,10 @@ public class Types1_8 {
/**
* Metadata list type for 1.8
*/
public static Type<List<Metadata>> METADATA_LIST = new MetadataList1_8Type();
public static final Type<List<Metadata>> METADATA_LIST = new MetadataList1_8Type();
/**
* Metadata type for 1.8
*/
public static Type<Metadata> METADATA = new Metadata1_8Type();
public static final Type<Metadata> METADATA = new Metadata1_8Type();
}

View File

@ -12,7 +12,7 @@ import us.myles.ViaVersion.commands.defaultsubs.*;
import java.util.*;
public abstract class ViaCommandHandler implements ViaVersionCommand {
private Map<String, ViaSubCommand> commandMap;
private final Map<String, ViaSubCommand> commandMap;
public ViaCommandHandler() {
commandMap = new HashMap<>();
@ -49,14 +49,14 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
}
if (!hasSubCommand(args[0])) {
sender.sendMessage(color("&cThis command is not found"));
sender.sendMessage(color("&cThis commands is not found"));
showHelp(sender);
return false;
}
ViaSubCommand handler = getSubCommand(args[0]);
if (!hasPermission(sender, handler.permission())) {
sender.sendMessage(color("&cYou are not allowed to use this command!"));
sender.sendMessage(color("&cYou are not allowed to use this commands!"));
return false;
}
@ -100,10 +100,14 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
return output;
}
/**
* Shows the ViaVersion help to a sender
* @param sender The sender to send the help to
*/
public void showHelp(ViaCommandSender sender) {
Set<ViaSubCommand> allowed = calculateAllowedCommands(sender);
if (allowed.size() == 0) {
sender.sendMessage(color("&cYou are not allowed to use this command!"));
sender.sendMessage(color("&cYou are not allowed to use this commands!"));
return;
}
sender.sendMessage(color("&aViaVersion &c" + Via.getPlatform().getPluginVersion()));
@ -137,6 +141,12 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
registerSubCommand(new ReloadSubCmd());
}
/**
* Replaces colour codes in a string
*
* @param string String to replace
* @return The output String
*/
public static String color(String string) {
try {
string = ChatColor.translateAlternateColorCodes('&', string); //Dont replace all & with $ like we did before.
@ -145,6 +155,13 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
return string;
}
/**
* Send a colour coded string with replacements to a user
*
* @param sender The target to send the message to
* @param message The message
* @param args The objects to replace
*/
public static void sendMessage(@NonNull ViaCommandSender sender, String message, Object... args) {
sender.sendMessage(color(args == null ? message : String.format(message, args)));
}

View File

@ -32,8 +32,6 @@ public class PPSSubCmd extends ViaSubCommand {
long max = 0;
for (ViaCommandSender p : Via.getPlatform().getOnlinePlayers()) {
if (!Via.getAPI().isPorted(p.getUUID()))
continue;
int playerVersion = Via.getAPI().getPlayerVersion(p.getUUID());
if (!playerVersions.containsKey(playerVersion))
playerVersions.put(playerVersion, new HashSet<String>());

View File

@ -4,7 +4,7 @@ import java.util.HashMap;
import java.util.Map;
public class InformativeException extends Exception {
Map<String, Object> info = new HashMap<>();
final Map<String, Object> info = new HashMap<>();
int sources = 0;
public InformativeException(Throwable cause) {

View File

@ -140,8 +140,8 @@ public enum PacketType {
PLAY_SET_COMPRESSION(State.PLAY, Direction.OUTGOING, 0x46, -1),
PLAY_UPDATE_ENTITY_NBT(State.PLAY, Direction.OUTGOING, 0x49, -1);
private static HashMap<Short, PacketType> oldids = new HashMap<>();
private static HashMap<Short, PacketType> newids = new HashMap<>();
private static final HashMap<Short, PacketType> oldids = new HashMap<>();
private static final HashMap<Short, PacketType> newids = new HashMap<>();
static {
for (PacketType pt : PacketType.values()) {

View File

@ -28,7 +28,7 @@ import java.util.UUID;
import java.util.logging.Level;
public class BaseProtocol extends Protocol {
private static Gson gson = new GsonBuilder().create(); // TODO: Possibly global gson provider?
private final static Gson gson = new GsonBuilder().create(); // TODO: Possibly global gson provider?
@Override
protected void registerPackets() {
@ -198,11 +198,6 @@ public class BaseProtocol extends Protocol {
// Nothing gets added, ProtocolPipeline handles ProtocolInfo
}
@Override
protected void registerListeners() {
}
@Override
public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception {
super.transform(direction, state, packetWrapper);

View File

@ -23,13 +23,13 @@ public class Protocol1_10To1_9_3_4 extends Protocol {
@Deprecated
public static final Type<Metadata> METADATA = new Metadata1_9Type();
public static ValueTransformer<Short, Float> toNewPitch = new ValueTransformer<Short, Float>(Type.FLOAT) {
public static final ValueTransformer<Short, Float> toNewPitch = new ValueTransformer<Short, Float>(Type.FLOAT) {
@Override
public Float transform(PacketWrapper wrapper, Short inputValue) throws Exception {
return inputValue / 63.5F;
}
};
public static ValueTransformer<List<Metadata>, List<Metadata>> transformMetadata = new ValueTransformer<List<Metadata>, List<Metadata>>(Types1_9.METADATA_LIST) {
public static final ValueTransformer<List<Metadata>, List<Metadata>> transformMetadata = new ValueTransformer<List<Metadata>, List<Metadata>>(Types1_9.METADATA_LIST) {
@Override
public List<Metadata> transform(PacketWrapper wrapper, List<Metadata> inputValue) throws Exception {
List<Metadata> metaList = new CopyOnWriteArrayList<>(inputValue);

View File

@ -103,7 +103,7 @@ public class ChunkSection1_9_3_4 implements ChunkSection {
* </ul>
*
* @param input The buffer to read from.
* @throws Exception
* @throws Exception If it fails to read
*/
public void readBlocks(ByteBuf input) throws Exception {
palette.clear();

View File

@ -103,7 +103,7 @@ public class ChunkSection1_9_1_2 implements ChunkSection {
* </ul>
*
* @param input The buffer to read from.
* @throws Exception
* @throws Exception If it failed to read properly
*/
public void readBlocks(ByteBuf input) throws Exception {
palette.clear();

View File

@ -14,7 +14,7 @@ import java.util.concurrent.ConcurrentHashMap;
* It requires now to have all tile entity data included in the chunk packet, otherwise it'll crash.
*/
public class FakeTileEntity {
private static Map<Integer, CompoundTag> tileEntities = new ConcurrentHashMap<>();
private static final Map<Integer, CompoundTag> tileEntities = new ConcurrentHashMap<>();
static {
register(Arrays.asList(61, 62), "Furnace");

View File

@ -72,9 +72,7 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
}
@Override
public void write(ByteBuf output, ClientWorld world, Chunk input) throws Exception {
Chunk chunk = input;
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
output.writeInt(chunk.getX());
output.writeInt(chunk.getZ());

View File

@ -44,6 +44,12 @@ public enum ArmorType {
private final int id;
private final String type;
/**
* Find an armour type by the item id
* @param id ID of the item
*
* @return Return the ArmourType, ArmourType.NONE if not found
*/
public static ArmorType findById(int id) {
for (ArmorType a : ArmorType.values())
if (a.getId() == id)
@ -51,6 +57,12 @@ public enum ArmorType {
return ArmorType.NONE;
}
/**
* Find an armour type by the item string
* @param type String name for the item
*
* @return Return the ArmourType, ArmourType.NONE if not found
*/
public static ArmorType findByType(String type) {
for (ArmorType a : ArmorType.values())
if (a.getType().equals(type))
@ -58,6 +70,11 @@ public enum ArmorType {
return NONE;
}
/**
* Check if an item id is armour
* @param id The item ID
* @return True if the item is a piece of armour
*/
public static boolean isArmor(int id) {
for (ArmorType a : ArmorType.values())
if (a.getId() == id)
@ -65,6 +82,11 @@ public enum ArmorType {
return false;
}
/**
* Check if an item id is armour
* @param type The item material name
* @return True if the item is a piece of armour
*/
public static boolean isArmor(String type) {
for (ArmorType a : ArmorType.values())
if (a.getType().equals(type))
@ -72,6 +94,10 @@ public enum ArmorType {
return false;
}
/**
* Get the Minecraft ID for the Armour Type
* @return The ID
*/
public int getId() {
return this.id;
}

View File

@ -28,8 +28,8 @@ public class Protocol1_9TO1_8 extends Protocol {
@Deprecated
public static Type<Metadata> METADATA = new Metadata1_8Type();
private static Gson gson = new GsonBuilder().create();
public static ValueTransformer<String, String> FIX_JSON = new ValueTransformer<String, String>(Type.STRING) {
private static final Gson gson = new GsonBuilder().create();
public static final ValueTransformer<String, String> FIX_JSON = new ValueTransformer<String, String>(Type.STRING) {
@Override
public String transform(PacketWrapper wrapper, String line) {
return fixJson(line);

View File

@ -6,6 +6,12 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
public class ChatRewriter {
/**
* Rewrite chat being sent to the client so that gamemode issues don't occur.
*
* @param obj The json object being sent by the server
* @param user The player involved. (Required for Gamemode info)
*/
public static void toClient(JsonObject obj, UserConnection user) {
//Check gamemode change
if (obj.get("translate") != null && obj.get("translate").getAsString().equals("gameMode.changed")) {

View File

@ -20,7 +20,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
import java.util.List;
public class EntityPackets {
public static ValueTransformer<Byte, Short> toNewShort = new ValueTransformer<Byte, Short>(Type.SHORT) {
public static final ValueTransformer<Byte, Short> toNewShort = new ValueTransformer<Byte, Short>(Type.SHORT) {
@Override
public Short transform(PacketWrapper wrapper, Byte inputValue) {
return (short) (inputValue * 128);

View File

@ -23,7 +23,7 @@ import java.util.ArrayList;
import java.util.List;
public class SpawnPackets {
public static ValueTransformer<Integer, Double> toNewDouble = new ValueTransformer<Integer, Double>(Type.DOUBLE) {
public static final ValueTransformer<Integer, Double> toNewDouble = new ValueTransformer<Integer, Double>(Type.DOUBLE) {
@Override
public Double transform(PacketWrapper wrapper, Integer inputValue) {
return inputValue / 32D;

View File

@ -7,10 +7,23 @@ import java.util.Arrays;
import java.util.List;
public class BulkChunkTranslatorProvider implements Provider {
/**
* Transforms a Bulk Chunk packet into Chunk Packets
*
* @param packet The NMS Packet
* @param clientChunks The ClientChunks object for the current player
* @return A List of all the output packets
*/
public List<Object> transformMapChunkBulk(Object packet, ClientChunks clientChunks) {
return Arrays.asList(packet);
}
/**
* Check if a packet of a class should be filtered
*
* @param packet NMS Packet
* @return True if it should be filtered into transformmapChunkBulk
*/
public boolean isFiltered(Class<?> packet) {
return false;
}

View File

@ -4,7 +4,7 @@ import java.util.HashMap;
public class Effect {
private static HashMap<Integer, Integer> effects;
private final static HashMap<Integer, Integer> effects;
static {
effects = new HashMap<>();

View File

@ -98,9 +98,7 @@ public class EntityTracker extends StoredObject {
public boolean interactedBlockRecently(int x, int y, int z) {
if (blockInteractions.size() == 0)
return false;
Iterator<Position> it = blockInteractions.asMap().keySet().iterator();
while (it.hasNext()) {
Position p = it.next();
for (Position p : blockInteractions.asMap().keySet()) {
if (p.getX() == x)
if (p.getY() == y)
if (p.getZ() == z)

View File

@ -16,10 +16,19 @@ public class PlaceBlockTracker extends StoredObject {
super(user);
}
/**
* Check if a certain amount of time has passed
*
* @param ms The amount of time in MS
* @return True if it has passed
*/
public boolean isExpired(int ms) {
return System.currentTimeMillis() > (lastPlaceTimestamp + ms);
}
/**
* Set the last place time to the current time
*/
public void updateTime() {
lastPlaceTimestamp = System.currentTimeMillis();
}

View File

@ -6,8 +6,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Version implements Comparable<Version> {
private static Pattern semVer = Pattern.compile("(?<a>0|[1-9]\\d*)\\.(?<b>0|[1-9]\\d*)(?:\\.(?<c>0|[1-9]\\d*))?(?:-(?<tag>[A-z0-9.-]*))?");
private int[] parts = new int[3];
private static final Pattern semVer = Pattern.compile("(?<a>0|[1-9]\\d*)\\.(?<b>0|[1-9]\\d*)(?:\\.(?<c>0|[1-9]\\d*))?(?:-(?<tag>[A-z0-9.-]*))?");
private final int[] parts = new int[3];
private String tag;
public Version(String value) {
@ -24,6 +24,13 @@ public class Version implements Comparable<Version> {
tag = matcher.group("tag") == null ? "" : matcher.group("tag");
}
/**
* Compare two versions
*
* @param verA The first version
* @param verB The second
* @return 0 if they are the same, 1 if versionA is newer, -1 if versionA is older
*/
public static int compare(Version verA, Version verB) {
if (verA == verB) return 0;
if (verA == null) return -1;
@ -47,6 +54,13 @@ public class Version implements Comparable<Version> {
return 0;
}
/**
* Check if a version is the same
*
* @param verA The first
* @param verB The second
* @return True if they are the same
*/
public static boolean equals(Version verA, Version verB) {
return verA == verB || verA != null && verB != null && compare(verA, verB) == 0;
}
@ -71,6 +85,11 @@ public class Version implements Comparable<Version> {
return that instanceof Version && equals(this, (Version) that);
}
/**
* Get the tag, eg. -ALPHA
*
* @return The version tag
*/
public String getTag() {
return tag;
}

View File

@ -32,6 +32,15 @@ public class PipelineUtil {
}
}
/**
* Call the decode method on a netty ByteToMessageDecoder
*
* @param decoder The decoder
* @param ctx The current context
* @param input The packet to decode
* @return A list of the decoders output
* @throws InvocationTargetException If an exception happens while executing
*/
public static List<Object> callDecode(ByteToMessageDecoder decoder, ChannelHandlerContext ctx, Object input) throws InvocationTargetException {
List<Object> output = new ArrayList<>();
try {
@ -42,6 +51,15 @@ public class PipelineUtil {
return output;
}
/**
* Call the encode method on a netty MessageToByteEncoder
*
* @param encoder The encoder
* @param ctx The current context
* @param msg The packet to encode
* @param output The bytebuf to write the output to
* @throws InvocationTargetException If an exception happens while executing
*/
public static void callEncode(MessageToByteEncoder encoder, ChannelHandlerContext ctx, Object msg, ByteBuf output) throws InvocationTargetException {
try {
PipelineUtil.ENCODE_METHOD.invoke(encoder, ctx, msg, output);
@ -50,6 +68,13 @@ public class PipelineUtil {
}
}
/**
* Check if a stack trace contains a certain exception
*
* @param t The throwable
* @param c The exception to look for
* @return True if the stack trace contained it as its cause.
*/
public static boolean containsCause(Throwable t, Class<? extends Throwable> c) {
while (t != null) {
t = t.getCause();
@ -59,6 +84,13 @@ public class PipelineUtil {
return false;
}
/**
* Get the context for a the channel handler before a certain name.
*
* @param name The name of the channel handler
* @param pipeline The pipeline to target
* @return The ChannelHandler before the one requested.
*/
public static ChannelHandlerContext getContextBefore(String name, ChannelPipeline pipeline) {
boolean mark = false;
for (String s : pipeline.names()) {

View File

@ -20,6 +20,13 @@ import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.dump.PluginInfo;
import us.myles.ViaVersion.sponge.*;
import us.myles.ViaVersion.sponge.commands.SpongeCommandHandler;
import us.myles.ViaVersion.sponge.commands.SpongeCommandSender;
import us.myles.ViaVersion.sponge.platform.SpongeConfigAPI;
import us.myles.ViaVersion.sponge.platform.SpongeViaAPI;
import us.myles.ViaVersion.sponge.platform.SpongeViaInjector;
import us.myles.ViaVersion.sponge.platform.SpongeViaLoader;
import us.myles.ViaVersion.sponge.util.LoggerWrapper;
import java.io.File;
import java.util.ArrayList;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.sponge;
package us.myles.ViaVersion.sponge.commands;
import org.spongepowered.api.command.CommandCallable;
import org.spongepowered.api.command.CommandException;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.sponge;
package us.myles.ViaVersion.sponge.commands;
import lombok.AllArgsConstructor;
import org.spongepowered.api.command.CommandSource;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.sponge;
package us.myles.ViaVersion.sponge.platform;
import lombok.Getter;
import org.spongepowered.api.entity.living.player.Player;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.sponge;
package us.myles.ViaVersion.sponge.platform;
import org.yaml.snakeyaml.Yaml;
import us.myles.ViaVersion.api.ViaVersionConfig;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.sponge;
package us.myles.ViaVersion.sponge.platform;
import io.netty.buffer.ByteBuf;
import lombok.NonNull;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.sponge;
package us.myles.ViaVersion.sponge.platform;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.sponge;
package us.myles.ViaVersion.sponge.platform;
import lombok.AllArgsConstructor;
import org.spongepowered.api.Sponge;

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.sponge;
package us.myles.ViaVersion.sponge.util;
import org.slf4j.Logger;