Fix java 7 support

This commit is contained in:
Lennart ten Wolde 2016-04-21 09:39:59 +02:00
parent d7d6d220bf
commit fb505e404a
22 changed files with 105 additions and 138 deletions

View file

@ -1,10 +1,9 @@
package com.lenis0012.bukkit.marriage2;
import java.util.UUID;
import org.bukkit.Location;
import javax.annotation.Nullable;
import org.bukkit.Location;
import java.util.UUID;
public interface MData {

View file

@ -1,8 +1,7 @@
package com.lenis0012.bukkit.marriage2;
import java.util.UUID;
import javax.annotation.Nullable;
import java.util.UUID;
public interface MPlayer {

View file

@ -1,15 +1,14 @@
package com.lenis0012.bukkit.marriage2;
import java.util.UUID;
import java.util.logging.Logger;
import com.lenis0012.bukkit.marriage2.commands.Command;
import com.lenis0012.bukkit.marriage2.internal.Dependencies;
import com.lenis0012.bukkit.marriage2.misc.BConfig;
import com.lenis0012.bukkit.marriage2.misc.ListQuery;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import com.lenis0012.bukkit.marriage2.commands.Command;
import com.lenis0012.bukkit.marriage2.misc.BConfig;
import com.lenis0012.bukkit.marriage2.misc.ListQuery;
import java.util.UUID;
import java.util.logging.Logger;
public interface Marriage {
/**

View file

@ -1,6 +1,8 @@
package com.lenis0012.bukkit.marriage2.commands;
import com.google.common.collect.Lists;
import com.lenis0012.bukkit.marriage2.Marriage;
import com.lenis0012.bukkit.marriage2.config.Message;
import com.lenis0012.bukkit.marriage2.config.Permissions;
import com.lenis0012.bukkit.marriage2.config.Settings;
import com.lenis0012.bukkit.marriage2.internal.Dependencies;
@ -11,9 +13,6 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.lenis0012.bukkit.marriage2.Marriage;
import com.lenis0012.bukkit.marriage2.config.Message;
public abstract class Command {
protected final Marriage marriage;
private final String[] aliases;

View file

@ -1,13 +1,11 @@
package com.lenis0012.bukkit.marriage2.commands;
import com.lenis0012.bukkit.marriage2.config.Settings;
import org.bukkit.Bukkit;
import com.lenis0012.bukkit.marriage2.MPlayer;
import com.lenis0012.bukkit.marriage2.Marriage;
import com.lenis0012.bukkit.marriage2.config.Message;
import com.lenis0012.bukkit.marriage2.config.Settings;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
public class CommandDivorce extends Command {

View file

@ -1,14 +1,13 @@
package com.lenis0012.bukkit.marriage2.commands;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.lenis0012.bukkit.marriage2.MData;
import com.lenis0012.bukkit.marriage2.MPlayer;
import com.lenis0012.bukkit.marriage2.Marriage;
import com.lenis0012.bukkit.marriage2.config.Message;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class CommandGift extends Command {

View file

@ -1,9 +1,7 @@
package com.lenis0012.bukkit.marriage2.commands;
import com.lenis0012.bukkit.marriage2.MPlayer;
import com.lenis0012.bukkit.marriage2.Marriage;
import com.lenis0012.bukkit.marriage2.config.Message;
import com.lenis0012.bukkit.marriage2.config.Settings;
import com.lenis0012.bukkit.marriage2.internal.MarriageBase;
import com.lenis0012.bukkit.marriage2.internal.MarriageCommandExecutor;
import mkremins.fanciful.FancyMessage;

View file

@ -1,11 +1,10 @@
package com.lenis0012.bukkit.marriage2.commands;
import org.bukkit.Location;
import com.lenis0012.bukkit.marriage2.MData;
import com.lenis0012.bukkit.marriage2.MPlayer;
import com.lenis0012.bukkit.marriage2.Marriage;
import com.lenis0012.bukkit.marriage2.config.Message;
import org.bukkit.Location;
public class CommandHome extends Command {

View file

@ -1,10 +1,9 @@
package com.lenis0012.bukkit.marriage2.commands;
import org.bukkit.Bukkit;
import com.lenis0012.bukkit.marriage2.Marriage;
import com.lenis0012.bukkit.marriage2.config.Message;
import com.lenis0012.bukkit.marriage2.misc.ListQuery;
import org.bukkit.Bukkit;
public class CommandList extends Command {

View file

@ -1,17 +1,14 @@
package com.lenis0012.bukkit.marriage2.commands;
import com.lenis0012.bukkit.marriage2.config.Settings;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.lenis0012.bukkit.marriage2.MPlayer;
import com.lenis0012.bukkit.marriage2.Marriage;
import com.lenis0012.bukkit.marriage2.config.Message;
import com.lenis0012.bukkit.marriage2.config.Settings;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import java.util.UUID;
public class CommandMarry extends Command {
public CommandMarry(Marriage marriage) {

View file

@ -1,20 +1,19 @@
package com.lenis0012.bukkit.marriage2.internal;
import com.google.common.collect.Lists;
import com.google.common.reflect.ClassPath;
import com.lenis0012.bukkit.marriage2.Marriage;
import com.lenis0012.bukkit.marriage2.commands.Command;
import com.lenis0012.bukkit.marriage2.misc.BConfig;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.common.reflect.ClassPath;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import com.google.common.collect.Lists;
import com.lenis0012.bukkit.marriage2.Marriage;
import com.lenis0012.bukkit.marriage2.commands.Command;
import com.lenis0012.bukkit.marriage2.misc.BConfig;
public abstract class MarriageBase implements Marriage {
protected final MarriagePlugin plugin;
private final ClassPath classPath;

View file

@ -1,17 +1,16 @@
package com.lenis0012.bukkit.marriage2.internal;
import java.util.Collection;
import java.util.Map;
import java.util.logging.Level;
import com.google.common.collect.Maps;
import com.lenis0012.bukkit.marriage2.Marriage;
import com.lenis0012.bukkit.marriage2.commands.Command;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.lenis0012.bukkit.marriage2.Marriage;
import com.lenis0012.bukkit.marriage2.commands.Command;
import java.util.Collection;
import java.util.Map;
import java.util.logging.Level;
public class MarriageCommandExecutor implements CommandExecutor {
private final MarriageCore core;

View file

@ -1,14 +1,17 @@
package com.lenis0012.bukkit.marriage2.internal;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import com.lenis0012.bukkit.marriage2.MData;
import com.lenis0012.bukkit.marriage2.MPlayer;
import com.lenis0012.bukkit.marriage2.commands.Command;
import com.lenis0012.bukkit.marriage2.config.Message;
import com.lenis0012.bukkit.marriage2.config.Permissions;
import com.lenis0012.bukkit.marriage2.config.Settings;
import com.lenis0012.bukkit.marriage2.internal.Register.Type;
import com.lenis0012.bukkit.marriage2.internal.data.DataConverter;
import com.lenis0012.bukkit.marriage2.internal.data.DataManager;
import com.lenis0012.bukkit.marriage2.internal.data.MarriageData;
import com.lenis0012.bukkit.marriage2.internal.data.MarriagePlayer;
import com.lenis0012.bukkit.marriage2.misc.ListQuery;
import com.lenis0012.pluginutils.modules.configuration.ConfigurationModule;
import com.lenis0012.updater.api.ReleaseType;
import com.lenis0012.updater.api.Updater;
@ -17,14 +20,10 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import com.lenis0012.bukkit.marriage2.MPlayer;
import com.lenis0012.bukkit.marriage2.commands.Command;
import com.lenis0012.bukkit.marriage2.config.Message;
import com.lenis0012.bukkit.marriage2.config.Settings;
import com.lenis0012.bukkit.marriage2.internal.data.DataManager;
import com.lenis0012.bukkit.marriage2.internal.data.MarriageData;
import com.lenis0012.bukkit.marriage2.internal.data.MarriagePlayer;
import com.lenis0012.bukkit.marriage2.misc.ListQuery;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class MarriageCore extends MarriageBase {
private final Map<UUID, MarriagePlayer> players = Collections.synchronizedMap(new HashMap<UUID, MarriagePlayer>());

View file

@ -1,20 +1,15 @@
package com.lenis0012.bukkit.marriage2.internal;
import java.io.File;
import java.lang.reflect.Method;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.lenis0012.bukkit.marriage2.Marriage;
import com.lenis0012.pluginutils.PluginHolder;
import com.lenis0012.pluginutils.modules.configuration.ConfigurationModule;
import com.lenis0012.pluginutils.modules.packets.PacketModule;
import com.lenis0012.bukkit.marriage2.Marriage;
import org.yaml.snakeyaml.Yaml;
import java.io.File;
import java.lang.reflect.Method;
import java.util.List;
import java.util.logging.Level;
public class MarriagePlugin extends PluginHolder {
private static MarriageCore core;

View file

@ -2,7 +2,6 @@ package com.lenis0012.bukkit.marriage2.internal.data;
import com.google.common.collect.Maps;
import com.lenis0012.bukkit.marriage2.MData;
import com.lenis0012.bukkit.marriage2.MPlayer;
import com.lenis0012.bukkit.marriage2.internal.MarriageCore;
import com.lenis0012.bukkit.marriage2.misc.UUIDFetcher;
import org.bukkit.Bukkit;
@ -11,10 +10,8 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.craftbukkit.v1_9_R1.CraftServer;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import java.util.UUID;

View file

@ -1,30 +1,30 @@
package com.lenis0012.bukkit.marriage2.internal.data;
import java.io.File;
import java.sql.*;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.logging.Level;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.lenis0012.bukkit.marriage2.MData;
import com.lenis0012.bukkit.marriage2.internal.MarriageCore;
import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
import com.lenis0012.bukkit.marriage2.misc.BConfig;
import com.lenis0012.bukkit.marriage2.misc.ListQuery;
import com.lenis0012.bukkit.marriage2.misc.LockedReference;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import com.lenis0012.bukkit.marriage2.MData;
import com.lenis0012.bukkit.marriage2.internal.MarriageCore;
import com.lenis0012.bukkit.marriage2.misc.ListQuery;
import org.bukkit.entity.Player;
import java.io.File;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
public class DataManager {
private static final ExecutorService executorService = Executors.newCachedThreadPool();
@ -35,7 +35,7 @@ public class DataManager {
// Create a data cache to overlap with the pre join event cache
private final Cache<UUID, MarriageData> marriageDataCache = CacheBuilder.newBuilder().expireAfterWrite(60L, TimeUnit.SECONDS).build();
private final MarriageCore core;
private LockedReference<Connection> supplier;
private LockedReference supplier;
private String prefix;
public DataManager(MarriageCore core) {
@ -99,7 +99,7 @@ public class DataManager {
}
// Create cached connection supplier.
this.supplier = new LockedReference<>(new ConnectionSupplier(url), 30L, TimeUnit.SECONDS, new ConnectionInvalidator());
this.supplier = new LockedReference(new ConnectionSupplier(url), 30L, TimeUnit.SECONDS, new ConnectionInvalidator());
DBUpgrade upgrade = new DBUpgrade();
Connection connection = supplier.access();
@ -383,14 +383,13 @@ public class DataManager {
return false;
}
private static final class ConnectionSupplier implements Supplier<Connection> {
public static final class ConnectionSupplier {
private final String url;
private ConnectionSupplier(String url) {
this.url = url;
}
@Override
public Connection get() {
try {
return DriverManager.getConnection(url);
@ -400,9 +399,8 @@ public class DataManager {
}
}
private static final class ConnectionInvalidator implements Consumer<Connection> {
public static final class ConnectionInvalidator {
@Override
public void accept(Connection connection) {
// Try to close connection
try {

View file

@ -1,16 +1,15 @@
package com.lenis0012.bukkit.marriage2.internal.data;
import com.lenis0012.bukkit.marriage2.MData;
import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import com.lenis0012.bukkit.marriage2.MData;
public class MarriageData implements MData {
private final DataManager dataManager;
private final UUID player1;

View file

@ -1,11 +1,5 @@
package com.lenis0012.bukkit.marriage2.internal.data;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import com.lenis0012.bukkit.marriage2.Gender;
import com.lenis0012.bukkit.marriage2.MData;
import com.lenis0012.bukkit.marriage2.MPlayer;
@ -15,6 +9,12 @@ import com.lenis0012.bukkit.marriage2.internal.MarriageCore;
import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
import com.lenis0012.bukkit.marriage2.misc.Cooldown;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
public class MarriagePlayer implements MPlayer {
private final Cooldown<UUID> requests;
private final UUID uuid;

View file

@ -2,9 +2,8 @@ package com.lenis0012.bukkit.marriage2.listeners;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.lenis0012.bukkit.marriage2.MPlayer;
import com.lenis0012.bukkit.marriage2.internal.MarriageCore;
import com.lenis0012.bukkit.marriage2.internal.data.DataManager;
import com.lenis0012.bukkit.marriage2.internal.data.MarriagePlayer;
import com.lenis0012.bukkit.marriage2.misc.ListQuery;
@ -17,13 +16,9 @@ import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import com.lenis0012.bukkit.marriage2.internal.MarriageCore;
import org.bukkit.metadata.FixedMetadataValue;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;

View file

@ -1,16 +1,15 @@
package com.lenis0012.bukkit.marriage2.misc;
import com.lenis0012.bukkit.marriage2.internal.MarriageBase;
import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
import org.bukkit.configuration.file.YamlConfiguration;
import com.lenis0012.bukkit.marriage2.internal.MarriageBase;
/**
* Represents a more easy version of FileConfiguration
* Allows saving and reloading without throwing exceptions or needing the specify a file.

View file

@ -1,17 +1,11 @@
package com.lenis0012.bukkit.marriage2.misc;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import com.google.common.collect.Maps;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.lenis0012.bukkit.marriage2.MData;
import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
import com.lenis0012.bukkit.marriage2.internal.data.DataManager;
import com.lenis0012.bukkit.marriage2.internal.data.MarriagePlayer;
import org.bukkit.Bukkit;
@ -20,8 +14,13 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
import com.lenis0012.bukkit.marriage2.MData;
import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class ListQuery {
private static final JsonParser JSON_PARSER = new JsonParser();

View file

@ -1,27 +1,29 @@
package com.lenis0012.bukkit.marriage2.misc;
import com.lenis0012.bukkit.marriage2.internal.data.DataManager.ConnectionInvalidator;
import com.lenis0012.bukkit.marriage2.internal.data.DataManager.ConnectionSupplier;
import java.sql.Connection;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
import java.util.function.Supplier;
public class LockedReference<T> {
public class LockedReference {
private final Lock lock = new ReentrantLock();
private final Supplier<T> supplier;
private final Consumer<T> invalidator;
private final ConnectionSupplier supplier;
private final ConnectionInvalidator invalidator;
private final long expiryTime;
private T object;
private Connection object;
private long timeClaimed;
public LockedReference(Supplier<T> supplier, long expiryTime, TimeUnit unit, Consumer<T> invalidator) {
public LockedReference(ConnectionSupplier supplier, long expiryTime, TimeUnit unit, ConnectionInvalidator invalidator) {
this.supplier = supplier;
this.invalidator = invalidator;
this.expiryTime = unit.toMillis(expiryTime);
}
public T access() {
public Connection access() {
lock.lock();
// Check if object not defined or expired.